Source code of Windows XP (NT5)
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.

169 lines
4.0 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. String.hxx
  5. Abstract:
  6. Inline Helper functions for DUALSTRINGARRAY's
  7. Author:
  8. Mario Goertzel [MarioGo]
  9. Revision History:
  10. MarioGo 02-22-95 Bits 'n pieces
  11. --*/
  12. #ifndef __STRING_HXX
  13. #define __STRING_HXX
  14. //
  15. // CDualStringArray -- a refcounted wrapper object for DUALSTRINGARRAY's
  16. //
  17. class CDualStringArray
  18. {
  19. public:
  20. CDualStringArray( DUALSTRINGARRAY *pdsa ) { ASSERT(pdsa); _cRef = 1; _pdsa = pdsa; }
  21. ~CDualStringArray();
  22. DWORD AddRef();
  23. DWORD Release();
  24. DUALSTRINGARRAY* DSA() { ASSERT(_pdsa); return _pdsa; };
  25. private:
  26. DUALSTRINGARRAY* _pdsa;
  27. LONG _cRef;
  28. };
  29. inline void dsaCopy(DUALSTRINGARRAY *pdsaDest, DUALSTRINGARRAY *pdsaSrc)
  30. {
  31. pdsaDest->wNumEntries = pdsaSrc->wNumEntries;
  32. pdsaDest->wSecurityOffset = pdsaSrc->wSecurityOffset;
  33. OrMemoryCopy(pdsaDest->aStringArray,
  34. pdsaSrc->aStringArray,
  35. pdsaSrc->wNumEntries*sizeof(USHORT));
  36. }
  37. HRESULT dsaAllocateAndCopy(DUALSTRINGARRAY** ppdsaDest, DUALSTRINGARRAY* pdsaSrc);
  38. inline BOOL dsaValid(DUALSTRINGARRAY *pdsa)
  39. {
  40. DWORD reason = 1;
  41. // keep track of what was wrong with the string using the
  42. // reason variable so a diagnostic message can be printed
  43. if ( pdsa
  44. && (reason++, pdsa->wNumEntries >= 4)
  45. && (reason++, FALSE == IsBadWritePtr(pdsa->aStringArray, pdsa->wNumEntries * sizeof(WCHAR)))
  46. && (reason++, pdsa->wSecurityOffset <= (pdsa->wNumEntries - 2))
  47. && (reason++, pdsa->aStringArray[(pdsa->wNumEntries - 1)] == 0)
  48. && (reason++, pdsa->aStringArray[(pdsa->wNumEntries - 2)] == 0)
  49. && (reason++, pdsa->aStringArray[(pdsa->wSecurityOffset - 1)] == 0)
  50. && (reason++, pdsa->aStringArray[(pdsa->wSecurityOffset - 2)] == 0)
  51. )
  52. {
  53. return(TRUE);
  54. }
  55. KdPrintEx((DPFLTR_DCOMSS_ID,
  56. DPFLTR_WARNING_LEVEL,
  57. "OR::dsaValid: string at 0x%x is invalid for reason %d\n",
  58. pdsa,
  59. reason));
  60. return(FALSE);
  61. }
  62. inline DWORD dsaHash(DUALSTRINGARRAY *pdsa)
  63. // PERF WORK: Make sure the hash looks good in real world usage.
  64. {
  65. int i, count;
  66. DWORD hash, t;
  67. count = i = hash = pdsa->wNumEntries;
  68. hash |= pdsa->wSecurityOffset << 16;
  69. for(count = 0; count < i/2; count++)
  70. {
  71. t = *(PDWORD)&pdsa->aStringArray[count * 2];
  72. hash += hash ^ t;
  73. }
  74. // we may miss the last word, but it is null anyway.
  75. return(hash);
  76. }
  77. inline DWORD dsaCompare(DUALSTRINGARRAY *pdsa, DUALSTRINGARRAY *pdsa2)
  78. {
  79. return ( pdsa->wNumEntries == pdsa2->wNumEntries
  80. && pdsa->wSecurityOffset == pdsa2->wSecurityOffset
  81. && 0 == OrMemoryCompare(pdsa->aStringArray,
  82. pdsa2->aStringArray,
  83. pdsa->wNumEntries * sizeof(WCHAR)) );
  84. }
  85. inline PWSTR OrStringSearch(PWSTR string, USHORT value)
  86. {
  87. // Faster and smaller then wcschr() for value == 0
  88. if (value == 0)
  89. {
  90. while(*string)
  91. string++;
  92. return(string);
  93. }
  94. return(wcschr(string, value));
  95. }
  96. RPC_BINDING_HANDLE GetBinding(
  97. IN PWSTR pCompressedBinding
  98. );
  99. RPC_BINDING_HANDLE GetBindingToOr(
  100. IN PWSTR pCompressedBinding
  101. );
  102. DUALSTRINGARRAY *GetStringBinding(
  103. IN PWSTR pwstrCompressed,
  104. IN PWSTR pwstrSecurityBindings
  105. );
  106. ORSTATUS ConvertToRemote(
  107. IN DUALSTRINGARRAY *psaLocal,
  108. OUT DUALSTRINGARRAY **ppsaRemote
  109. );
  110. DUALSTRINGARRAY *CompressStringArrayAndAddIPAddrs(
  111. IN DUALSTRINGARRAY *psaExpanded
  112. );
  113. USHORT FindMatchingProtseq(
  114. IN USHORT cClientProtseqs,
  115. IN USHORT aClientProtseqs[],
  116. IN PWSTR pwstrServerBindings
  117. );
  118. PWSTR FindMatchingProtseq(
  119. IN USHORT protseq,
  120. IN PWSTR pswstrBindings
  121. );
  122. PWSTR FindMatchingProtseq(
  123. IN PWSTR pMachine,
  124. IN USHORT protseq,
  125. IN PWSTR pwstrCompressedBindings
  126. );
  127. PWSTR
  128. ExtractMachineName(WCHAR *pSB);
  129. RPC_BINDING_HANDLE TestBindingGetHandle(
  130. IN PWSTR pwstrCompressedBinding
  131. );
  132. #endif // __STRING_HXX