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.

75 lines
2.1 KiB

  1. #include "encode.h"
  2. NTSTATUS SxspUCS2StringToUTF8String(
  3. IN DWORD dwFlags,
  4. IN PCWSTR Ucs2String,
  5. IN DWORD CchUcs2Str,
  6. IN OUT PBYTE Buf,
  7. IN OUT DWORD *chBuf
  8. )
  9. {
  10. NTSTATUS Status = STATUS_SUCCESS;
  11. FN_TRACE_NTSTATUS(Status);
  12. PARAMETER_CHECK(chBuf != NULL); // if *chBuf == 0, this function will return the length in BYTE;
  13. // else, it specifies the capacity of byte buffer;
  14. int iRet;
  15. IF_ZERO_EXIT(iRet = WideCharToMultiByte(CP_UTF8, 0, Ucs2String, CchUcs2Str, (PSTR)Buf, *chBuf, NULL, NULL));
  16. *chBuf = iRet;
  17. FN_EPILOG;
  18. }
  19. NTSTATUS SxspUTF82StringToUCS2String(
  20. IN DWORD dwFlags,
  21. IN PBYTE Buf,
  22. IN DWORD chBuf, // size in byte
  23. IN OUT PWSTR Ucs2String,
  24. IN OUT DWORD *chUcs2String
  25. )
  26. {
  27. NTSTATUS Status = STATUS_SUCCESS;
  28. FN_TRACE_NTSTATUS(Status);
  29. PARAMETER_CHECK(chUcs2String != NULL); // if *chUcs2String == 0, this function will return the length in WCHAR;
  30. // else, it specifies the capacity of wchar buffer;
  31. int iRet;
  32. IF_ZERO_EXIT(iRet = MultiByteToWideChar(CP_UTF8, 0, (PSTR)Buf, chBuf, Ucs2String, *chUcs2String));
  33. *chUcs2String = iRet;
  34. FN_EPILOG;
  35. }
  36. NTSTATUS SxspHashString(
  37. PCWSTR String,
  38. SIZE_T cch,
  39. PULONG HashValue,
  40. bool CaseInsensitive = true
  41. )
  42. {
  43. NTSTATUS Status = STATUS_SUCCESS;
  44. FN_TRACE_NTSTATUS(Status);
  45. UNICODE_STRING s;
  46. s.MaximumLength = static_cast<USHORT>(cch * sizeof(WCHAR));
  47. // check for overflow
  48. ASSERT(s.MaximumLength == (cch * sizeof(WCHAR)));
  49. s.Length = s.MaximumLength;
  50. s.Buffer = const_cast<PWSTR>(String);
  51. IF_NOT_NTSTATUS_SUCCESS_EXIT(::RtlHashUnicodeString(&s, CaseInsensitive, FUSION_HASH_ALGORITHM, HashValue));
  52. FN_EPILOG;
  53. }
  54. /*
  55. sxs hash algorithm for GUID
  56. */
  57. NTSTATUS SxspHashGUID(REFGUID rguid, ULONG &rulPseudoKey)
  58. {
  59. const ULONG *p = (const ULONG *) &rguid;
  60. rulPseudoKey = p[0] + p[1] + p[2] + p[3];
  61. return STATUS_SUCCESS;
  62. }