Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
4.2 KiB

  1. #ifndef _STRUTIL_H_
  2. #define _STRUTIL_H_
  3. #include <nmutil.h>
  4. #include <stock.h>
  5. #include <wincrypt.h>
  6. INLINE BOOL
  7. IsEmptyStringA(LPCSTR pcsz)
  8. {
  9. return (NULL == pcsz) || ('\0' == *pcsz);
  10. }
  11. INLINE BOOL
  12. IsEmptyStringW(LPCWSTR pcwsz)
  13. {
  14. return (NULL == pcwsz) || (L'\0' == *pcwsz);
  15. }
  16. #if defined(UNICODE)
  17. #define IsEmptyString IsEmptyStringW
  18. #else // defined(UNICODE)
  19. #define IsEmptyString IsEmptyStringA
  20. #endif // defined(UNICODE)
  21. #define IS_EMPTY_STRING(s) (IsEmptyString(s))
  22. #define FEmptySz(psz) (IsEmptyString(psz))
  23. #define SetEmptySz(psz) (*(psz) = _T('\0'))
  24. // global helper functions for Unicode support in a DBCS environment
  25. int NMINTERNAL UnicodeCompare(PCWSTR s, PCWSTR t);
  26. PWSTR NMINTERNAL NewUnicodeString(PCWSTR wszText);
  27. BOOL NMINTERNAL UnicodeIsNumber(PCWSTR wszText);
  28. PWSTR NMINTERNAL DBCSToUnicode(UINT uCodePage, PCSTR szText);
  29. PSTR NMINTERNAL UnicodeToDBCS(UINT uCodePage, PCWSTR wszText);
  30. INLINE PWSTR AnsiToUnicode(PCSTR szText)
  31. {
  32. return DBCSToUnicode(CP_ACP, szText);
  33. }
  34. INLINE PWSTR OEMToUnicode(PCSTR szText)
  35. {
  36. return DBCSToUnicode(CP_OEMCP, szText);
  37. }
  38. INLINE PSTR UnicodeToAnsi(PCWSTR wszText)
  39. {
  40. return UnicodeToDBCS(CP_ACP, wszText);
  41. }
  42. INLINE PSTR UnicodeToOEM(PCWSTR wszText)
  43. {
  44. return UnicodeToDBCS(CP_OEMCP, wszText);
  45. }
  46. // Functions to convert between Quad Words (expressed as ULARGE_INTEGERs)
  47. // and ANSI strings.
  48. BOOL NMINTERNAL HexStringToQWordA(LPCSTR pcszString, ULARGE_INTEGER* pqw);
  49. int NMINTERNAL QWordToHexStringA(ULARGE_INTEGER qw, LPSTR pszString);
  50. // Function to convert from a hex string to a DWORD.
  51. DWORD NMINTERNAL DwFromHex(LPCTSTR pchHex);
  52. // CCHMAX_HEX_ULARGE_INTEGER - defines the minimum string buffer size needed
  53. // for the second parameter of QWordToHexStringA().
  54. #define CCHMAX_HEX_ULARGE_INTEGER 17 // 16 characters + n.t.
  55. #define CCH_HEX_DWORD 8
  56. #define CCH_HEX_QWORD 16
  57. #define BITS_PER_HEX_CHAR 4
  58. // Other Random string functions
  59. VOID NMINTERNAL GuidToSz(GUID * pguid, LPTSTR lpchDest);
  60. /* sizeof(GUID)*2 + 7 (includes NULL terminator) characters (see GuidToSz) */
  61. #define LENGTH_SZGUID_FORMATTED 39
  62. int WINAPI RtStrToInt(LPCTSTR lpSrc); // atoi()
  63. #define ATOI RtStrToInt
  64. #ifdef __cplusplus
  65. extern "C"{
  66. #endif
  67. UINT NMINTERNAL DecimalStringToUINT(LPCTSTR pcszString);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #ifdef __cplusplus
  72. extern "C"{
  73. #endif
  74. LPCTSTR NMINTERNAL _StrChr(LPCTSTR psz, TCHAR c);
  75. int NMINTERNAL _StrCmpN(LPCTSTR psz1, LPCTSTR psz2, UINT maxChars);
  76. #ifdef __cplusplus
  77. }
  78. #endif
  79. LPCTSTR NMINTERNAL _StrStr(LPCTSTR pcsz1, LPCTSTR pcsz2);
  80. LPCWSTR NMINTERNAL _StrStrW(LPCWSTR pcsz1, LPCWSTR pcsz2);
  81. LPSTR NMINTERNAL _StrPbrkA(LPCSTR pcszString, LPCSTR pcszSearch);
  82. LPWSTR NMINTERNAL _StrPbrkW(LPCWSTR pcszString, LPCWSTR pcszSearch);
  83. // To be used instead of lstrcmpi when comparing with a constant string
  84. // using a case/locale insensitive comparison (Prefast warning)
  85. #ifdef lstrcmpi
  86. #undef lstrcmpi
  87. #endif
  88. #define lstrcmpi(s1, s2) (CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, (s1), -1, (s2), -1) - CSTR_EQUAL)
  89. #if defined(UNICODE)
  90. #define _StrPbrk _StrPbrkW
  91. #else // defined(UNICODE)
  92. #define _StrPbrk _StrPbrkA
  93. #endif // defined(UNICODE)
  94. LPTSTR NMINTERNAL SzFindLastCh(LPTSTR lpsz, TCHAR ch);
  95. UINT NMINTERNAL TrimSz(PTCHAR psz);
  96. // Local LStrLenW function is unnecessary, since Windows 95 supports
  97. // lstrlenW natively
  98. #define LStrLenW lstrlenW
  99. // Map LStrCpyW to its Win32 equivalent for Unicode builds
  100. #if defined UNICODE
  101. #define LStrCpyW lstrcpyW
  102. #define LStrCpyNW lstrcpyn
  103. #else // defined UNICODE
  104. LPWSTR NMINTERNAL LStrCpyW(LPWSTR pszDest, LPWSTR pszSrc);
  105. LPWSTR NMINTERNAL LStrCpyNW(LPWSTR pszDest, LPCWSTR pszSrc, INT iMaxLength);
  106. #endif // defined UNICODE
  107. LPWSTR NMINTERNAL _StrLwrW(LPWSTR pwszSrc);
  108. #ifdef __cplusplus
  109. class CHash
  110. {
  111. public:
  112. CHash();
  113. ~CHash();
  114. DWORD GetHashedData(PBYTE pbData, DWORD cbData, void ** ppvHashedData);
  115. private:
  116. HCRYPTPROV m_hProv;
  117. HCRYPTHASH m_hHash;
  118. PBYTE m_pbHashedData;
  119. DWORD m_cbHashedData;
  120. BOOL m_fReady;
  121. };
  122. #endif
  123. DWORD NMINTERNAL HashPasswd(PBYTE pbPasswd, DWORD cbPasswd, void **ppvData);
  124. #endif // ndef STRUTIL_H