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.

228 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. strmap.h
  5. Abstract:
  6. Strmap (formally pathmap) is a fast hueristic-based program that
  7. searches strings and attempts to replace substrings when there
  8. are matching substrings in the mapping database.
  9. Author:
  10. Marc R. Whitten (marcw) 20-Mar-1997
  11. Revision History:
  12. Jim Schmidt (jimschm) 08-May-2000 Rewrote mapping, added Flags & ex nodes
  13. Calin Negreanu (calinn) 02-Mar-2000 Ported from win9xupg project
  14. --*/
  15. #pragma once
  16. //
  17. // Constants
  18. //
  19. #define SZMAP_COMPLETE_MATCH_ONLY 0x0001
  20. #define SZMAP_FIRST_CHAR_MUST_MATCH 0x0002
  21. #define SZMAP_RETURN_AFTER_FIRST_REPLACE 0x0004
  22. #define SZMAP_REQUIRE_WACK_OR_NUL 0x0008
  23. //
  24. // Types
  25. //
  26. typedef struct {
  27. BOOL UnicodeData;
  28. //
  29. // The filter can replace NewSubString. (The filter must also
  30. // set NewSubStringSizeInBytes when replacing NewSubString.)
  31. //
  32. union {
  33. struct {
  34. PCWSTR OriginalString;
  35. PCWSTR BeginningOfMatch;
  36. PCWSTR CurrentString;
  37. PCWSTR OldSubString;
  38. PCWSTR NewSubString;
  39. INT NewSubStringSizeInBytes;
  40. } Unicode;
  41. struct {
  42. PCSTR OriginalString;
  43. PCSTR BeginningOfMatch;
  44. PCSTR CurrentString;
  45. PCSTR OldSubString;
  46. PCSTR NewSubString;
  47. INT NewSubStringSizeInBytes;
  48. } Ansi;
  49. };
  50. } STRINGMAP_FILTER_DATA, *PSTRINGMAP_FILTER_DATA;
  51. typedef BOOL(STRINGMAP_FILTER_PROTOTYPE)(PSTRINGMAP_FILTER_DATA Data);
  52. typedef STRINGMAP_FILTER_PROTOTYPE * STRINGMAP_FILTER;
  53. typedef struct TAG_CHARNODE {
  54. WORD Char;
  55. WORD Flags;
  56. PVOID OriginalStr;
  57. PVOID ReplacementStr;
  58. INT ReplacementBytes;
  59. struct TAG_CHARNODE *NextLevel;
  60. struct TAG_CHARNODE *NextPeer;
  61. } CHARNODE, *PCHARNODE;
  62. typedef struct {
  63. CHARNODE Node;
  64. STRINGMAP_FILTER Filter;
  65. ULONG_PTR ExtraData;
  66. } CHARNODEEX, *PCHARNODEEX;
  67. typedef struct {
  68. PCHARNODE FirstLevelRoot;
  69. BOOL UsesExNode;
  70. BOOL UsesFilter;
  71. BOOL UsesExtraData;
  72. PVOID CleanUpChain;
  73. } STRINGMAP, *PSTRINGMAP;
  74. //
  75. // Function Prototypes
  76. //
  77. PSTRINGMAP
  78. SzMapCreateEx (
  79. IN BOOL UsesFilter,
  80. IN BOOL UsesExtraData
  81. );
  82. #define SzMapCreate() SzMapCreateEx(FALSE,FALSE)
  83. VOID
  84. SzMapDestroy (
  85. IN PSTRINGMAP Map
  86. );
  87. VOID
  88. SzMapAddExA (
  89. IN OUT PSTRINGMAP Map,
  90. IN PCSTR Old,
  91. IN PCSTR New,
  92. IN STRINGMAP_FILTER Filter, OPTIONAL
  93. IN ULONG_PTR ExtraData, OPTIONAL
  94. IN DWORD Flags
  95. );
  96. #define SzMapAddA(Map,Old,New) SzMapAddExA(Map,Old,New,NULL,0,0)
  97. VOID
  98. SzMapAddExW (
  99. IN OUT PSTRINGMAP Map,
  100. IN PCWSTR Old,
  101. IN PCWSTR New,
  102. IN STRINGMAP_FILTER Filter, OPTIONAL
  103. IN ULONG_PTR ExtraData, OPTIONAL
  104. IN DWORD Flags
  105. );
  106. #define SzMapAddW(Map,Old,New) SzMapAddExW(Map,Old,New,NULL,0,0)
  107. BOOL
  108. SzMapSearchAndReplaceExA (
  109. IN PSTRINGMAP Map,
  110. IN PCSTR SrcBuffer,
  111. OUT PSTR Buffer, // can be the same as SrcBuffer
  112. IN INT InboundBytes, OPTIONAL
  113. OUT PINT OutboundBytesPtr, OPTIONAL
  114. IN INT MaxSizeInBytes,
  115. IN DWORD Flags,
  116. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  117. OUT PCSTR *EndOfString OPTIONAL
  118. );
  119. #define SzMapSearchAndReplaceA(map,buffer,maxbytes) SzMapSearchAndReplaceExA(map,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  120. BOOL
  121. SzMapSearchAndReplaceExW (
  122. IN PSTRINGMAP Map,
  123. IN PCWSTR SrcBuffer,
  124. OUT PWSTR Buffer, // can be the same as SrcBuffer
  125. IN INT InboundBytes, OPTIONAL
  126. OUT PINT OutboundBytes, OPTIONAL
  127. IN INT MaxSizeInBytes,
  128. IN DWORD Flags,
  129. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  130. OUT PCWSTR *EndOfString OPTIONAL
  131. );
  132. #define SzMapSearchAndReplaceW(map,buffer,maxbytes) SzMapSearchAndReplaceExW(map,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  133. BOOL
  134. SzMapMultiTableSearchAndReplaceExA (
  135. IN PSTRINGMAP *MapArray,
  136. IN UINT MapArrayCount,
  137. IN PCSTR SrcBuffer,
  138. OUT PSTR Buffer, // can be the same as SrcBuffer
  139. IN INT InboundBytes, OPTIONAL
  140. OUT PINT OutboundBytesPtr, OPTIONAL
  141. IN INT MaxSizeInBytes,
  142. IN DWORD Flags,
  143. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  144. OUT PCSTR *EndOfString OPTIONAL
  145. );
  146. #define SzMapMultiTableSearchAndReplaceA(array,count,buffer,maxbytes) \
  147. SzMapMultiTableSearchAndReplaceExA(array,count,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  148. BOOL
  149. SzMapMultiTableSearchAndReplaceExW (
  150. IN PSTRINGMAP *MapArray,
  151. IN UINT MapArrayCount,
  152. IN PCWSTR SrcBuffer,
  153. OUT PWSTR Buffer, // can be the same as SrcBuffer
  154. IN INT InboundBytes, OPTIONAL
  155. OUT PINT OutboundBytes, OPTIONAL
  156. IN INT MaxSizeInBytes,
  157. IN DWORD Flags,
  158. OUT ULONG_PTR *ExtraDataValue, OPTIONAL
  159. OUT PCWSTR *EndOfString OPTIONAL
  160. );
  161. #define SzMapMultiTableSearchAndReplaceW(array,count,buffer,maxbytes) \
  162. SzMapMultiTableSearchAndReplaceExW(array,count,buffer,buffer,0,NULL,maxbytes,0,NULL,NULL)
  163. //
  164. // A & W Macros
  165. //
  166. #ifdef UNICODE
  167. #define SzMapAddEx SzMapAddExW
  168. #define SzMapAdd SzMapAddW
  169. #define SzMapSearchAndReplaceEx SzMapSearchAndReplaceExW
  170. #define SzMapSearchAndReplace SzMapSearchAndReplaceW
  171. #define SzMapMultiTableSearchAndReplaceEx SzMapMultiTableSearchAndReplaceExW
  172. #define SzMapMultiTableSearchAndReplace SzMapMultiTableSearchAndReplaceW
  173. #else
  174. #define SzMapAddEx SzMapAddExA
  175. #define SzMapAdd SzMapAddA
  176. #define SzMapSearchAndReplaceEx SzMapSearchAndReplaceExA
  177. #define SzMapSearchAndReplace SzMapSearchAndReplaceA
  178. #define SzMapMultiTableSearchAndReplaceEx SzMapMultiTableSearchAndReplaceExA
  179. #define SzMapMultiTableSearchAndReplace SzMapMultiTableSearchAndReplaceA
  180. #endif