libwinpr-crt: expand string functions
This commit is contained in:
parent
90dcef3178
commit
fbcce67cd8
@ -23,11 +23,84 @@
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
char* _strdup(const char* strSource);
|
||||
wchar_t* _wcsdup(const wchar_t *strSource);
|
||||
WINPR_API char* _strdup(const char* strSource);
|
||||
WINPR_API wchar_t* _wcsdup(const wchar_t* strSource);
|
||||
|
||||
WINPR_API LPSTR CharUpperA(LPSTR lpsz);
|
||||
WINPR_API LPWSTR CharUpperW(LPWSTR lpsz);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define CharUpper CharUpperW
|
||||
#else
|
||||
#define CharUpper CharUpperA
|
||||
#endif
|
||||
|
||||
WINPR_API DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength);
|
||||
WINPR_API DWORD CharUpperBuffW(LPWSTR lpsz, DWORD cchLength);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define CharUpperBuff CharUpperBuffW
|
||||
#else
|
||||
#define CharUpperBuff CharUpperBuffA
|
||||
#endif
|
||||
|
||||
WINPR_API LPSTR CharLowerA(LPSTR lpsz);
|
||||
WINPR_API LPWSTR CharLowerW(LPWSTR lpsz);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define CharLower CharLowerW
|
||||
#else
|
||||
#define CharLower CharLowerA
|
||||
#endif
|
||||
|
||||
WINPR_API DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength);
|
||||
WINPR_API DWORD CharLowerBuffW(LPWSTR lpsz, DWORD cchLength);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define CharLowerBuff CharLowerBuffW
|
||||
#else
|
||||
#define CharLowerBuff CharLowerBuffA
|
||||
#endif
|
||||
|
||||
WINPR_API BOOL IsCharAlphaA(CHAR ch);
|
||||
WINPR_API BOOL IsCharAlphaW(WCHAR ch);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define IsCharAlpha IsCharAlphaW
|
||||
#else
|
||||
#define IsCharAlpha IsCharAlphaA
|
||||
#endif
|
||||
|
||||
WINPR_API BOOL IsCharAlphaNumericA(CHAR ch);
|
||||
WINPR_API BOOL IsCharAlphaNumericW(WCHAR ch);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define IsCharAlphaNumeric IsCharAlphaNumericW
|
||||
#else
|
||||
#define IsCharAlphaNumeric IsCharAlphaNumericA
|
||||
#endif
|
||||
|
||||
WINPR_API BOOL IsCharUpperA(CHAR ch);
|
||||
WINPR_API BOOL IsCharUpperW(WCHAR ch);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define IsCharUpper IsCharUpperW
|
||||
#else
|
||||
#define IsCharUpper IsCharUpperA
|
||||
#endif
|
||||
|
||||
WINPR_API BOOL IsCharLowerA(CHAR ch);
|
||||
WINPR_API BOOL IsCharLowerW(WCHAR ch);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define IsCharLower IsCharLowerW
|
||||
#else
|
||||
#define IsCharLower IsCharLowerA
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -532,9 +532,9 @@ struct rdp_ntlm
|
||||
{
|
||||
UNICONV* uniconv;
|
||||
CtxtHandle context;
|
||||
uint32 cbMaxToken;
|
||||
ULONG cbMaxToken;
|
||||
ULONG fContextReq;
|
||||
uint32 pfContextAttr;
|
||||
ULONG pfContextAttr;
|
||||
TimeStamp expiration;
|
||||
PSecBuffer pBuffer;
|
||||
SecBuffer inputBuffer;
|
||||
|
@ -191,17 +191,21 @@ void freerdp_uniconv_uppercase(UNICONV *uniconv, char *wstr, int length)
|
||||
unsigned char* p;
|
||||
unsigned int wc, uwc;
|
||||
|
||||
p = (unsigned char*)wstr;
|
||||
p = (unsigned char*) wstr;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
wc = (unsigned int)(*p);
|
||||
wc += (unsigned int)(*(p + 1)) << 8;
|
||||
|
||||
uwc = towupper(wc);
|
||||
|
||||
if (uwc != wc)
|
||||
{
|
||||
*p = uwc & 0xFF;
|
||||
*(p + 1) = (uwc >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
p += 2;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
|
||||
/* String Manipulation (CRT): http://msdn.microsoft.com/en-us/library/f0151s4x.aspx */
|
||||
@ -57,4 +60,229 @@ wchar_t* _wcsdup(const wchar_t* strSource)
|
||||
return strDestination;
|
||||
}
|
||||
|
||||
/* Windows API Sets - api-ms-win-core-string-l2-1-0.dll
|
||||
* http://msdn.microsoft.com/en-us/library/hh802935/
|
||||
*/
|
||||
|
||||
LPSTR CharUpperA(LPSTR lpsz)
|
||||
{
|
||||
int i;
|
||||
int length;
|
||||
|
||||
length = strlen(lpsz);
|
||||
|
||||
if (length < 1)
|
||||
return (LPSTR) NULL;
|
||||
|
||||
if (length == 1)
|
||||
{
|
||||
LPSTR pc = NULL;
|
||||
char c = *lpsz;
|
||||
|
||||
if ((c >= 'a') && (c <= 'z'))
|
||||
c = c - 32;
|
||||
|
||||
*pc = c;
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if ((lpsz[i] >= 'a') && (lpsz[i] <= 'z'))
|
||||
lpsz[i] = lpsz[i] - 32;
|
||||
}
|
||||
|
||||
return lpsz;
|
||||
}
|
||||
|
||||
LPWSTR CharUpperW(LPWSTR lpsz)
|
||||
{
|
||||
printf("CharUpperW unimplemented!\n");
|
||||
|
||||
return (LPWSTR) NULL;
|
||||
}
|
||||
|
||||
DWORD CharUpperBuffA(LPSTR lpsz, DWORD cchLength)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (cchLength < 1)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < cchLength; i++)
|
||||
{
|
||||
if ((lpsz[i] >= 'a') && (lpsz[i] <= 'z'))
|
||||
lpsz[i] = lpsz[i] - 32;
|
||||
}
|
||||
|
||||
return cchLength;
|
||||
}
|
||||
|
||||
DWORD CharUpperBuffW(LPWSTR lpsz, DWORD cchLength)
|
||||
{
|
||||
DWORD i;
|
||||
unsigned char* p;
|
||||
unsigned int wc, uwc;
|
||||
|
||||
p = (unsigned char*) lpsz;
|
||||
|
||||
for (i = 0; i < cchLength; i++)
|
||||
{
|
||||
wc = (unsigned int) (*p);
|
||||
wc += (unsigned int) (*(p + 1)) << 8;
|
||||
|
||||
uwc = towupper(wc);
|
||||
|
||||
if (uwc != wc)
|
||||
{
|
||||
*p = uwc & 0xFF;
|
||||
*(p + 1) = (uwc >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
p += 2;
|
||||
}
|
||||
|
||||
return cchLength;
|
||||
}
|
||||
|
||||
LPSTR CharLowerA(LPSTR lpsz)
|
||||
{
|
||||
int i;
|
||||
int length;
|
||||
|
||||
length = strlen(lpsz);
|
||||
|
||||
if (length < 1)
|
||||
return (LPSTR) NULL;
|
||||
|
||||
if (length == 1)
|
||||
{
|
||||
LPSTR pc = NULL;
|
||||
char c = *lpsz;
|
||||
|
||||
if ((c >= 'A') && (c <= 'Z'))
|
||||
c = c + 32;
|
||||
|
||||
*pc = c;
|
||||
|
||||
return pc;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if ((lpsz[i] >= 'A') && (lpsz[i] <= 'Z'))
|
||||
lpsz[i] = lpsz[i] + 32;
|
||||
}
|
||||
|
||||
return lpsz;
|
||||
}
|
||||
|
||||
LPWSTR CharLowerW(LPWSTR lpsz)
|
||||
{
|
||||
printf("CharLowerW unimplemented!\n");
|
||||
|
||||
return (LPWSTR) NULL;
|
||||
}
|
||||
|
||||
DWORD CharLowerBuffA(LPSTR lpsz, DWORD cchLength)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (cchLength < 1)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < cchLength; i++)
|
||||
{
|
||||
if ((lpsz[i] >= 'A') && (lpsz[i] <= 'Z'))
|
||||
lpsz[i] = lpsz[i] + 32;
|
||||
}
|
||||
|
||||
return cchLength;
|
||||
}
|
||||
|
||||
DWORD CharLowerBuffW(LPWSTR lpsz, DWORD cchLength)
|
||||
{
|
||||
DWORD i;
|
||||
unsigned char* p;
|
||||
unsigned int wc, uwc;
|
||||
|
||||
p = (unsigned char*) lpsz;
|
||||
|
||||
for (i = 0; i < cchLength; i++)
|
||||
{
|
||||
wc = (unsigned int) (*p);
|
||||
wc += (unsigned int) (*(p + 1)) << 8;
|
||||
|
||||
uwc = towlower(wc);
|
||||
|
||||
if (uwc != wc)
|
||||
{
|
||||
*p = uwc & 0xFF;
|
||||
*(p + 1) = (uwc >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
p += 2;
|
||||
}
|
||||
|
||||
return cchLength;
|
||||
}
|
||||
|
||||
BOOL IsCharAlphaA(CHAR ch)
|
||||
{
|
||||
if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL IsCharAlphaW(WCHAR ch)
|
||||
{
|
||||
printf("IsCharAlphaW unimplemented!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL IsCharAlphaNumericA(CHAR ch)
|
||||
{
|
||||
if (((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z')) ||
|
||||
((ch >= '0') && (ch <= '9')))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL IsCharAlphaNumericW(WCHAR ch)
|
||||
{
|
||||
printf("IsCharAlphaNumericW unimplemented!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL IsCharUpperA(CHAR ch)
|
||||
{
|
||||
if ((ch >= 'A') && (ch <= 'Z'))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL IsCharUpperW(WCHAR ch)
|
||||
{
|
||||
printf("IsCharUpperW unimplemented!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL IsCharLowerA(CHAR ch)
|
||||
{
|
||||
if ((ch >= 'a') && (ch <= 'z'))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL IsCharLowerW(WCHAR ch)
|
||||
{
|
||||
printf("IsCharLowerW unimplemented!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <openssl/engine.h>
|
||||
#include <freerdp/crypto/crypto.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/hexdump.h>
|
||||
|
||||
@ -185,26 +186,12 @@ void ntlm_compute_ntlm_hash(uint16* password, uint32 length, char* hash)
|
||||
MD4_Final((void*) hash, &md4_ctx);
|
||||
}
|
||||
|
||||
static void ascii_uppercase(char* str)
|
||||
{
|
||||
int i;
|
||||
int length;
|
||||
|
||||
length = strlen(str);
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
if ((str[i] >= 'a') && (str[i] <= 'z'))
|
||||
str[i] = str[i] - 32;
|
||||
}
|
||||
}
|
||||
|
||||
static void ascii_hex_string_to_binary(char* str, unsigned char* hex)
|
||||
{
|
||||
int i;
|
||||
int length;
|
||||
|
||||
ascii_uppercase(str);
|
||||
CharUpperA(str);
|
||||
|
||||
length = strlen(str);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user