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.

367 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. hash.h
  5. Abstract:
  6. Replacement routines for the string table functions in setupapi.dll.
  7. This routines are much more easy to work with.
  8. Author:
  9. Jim Schmidt (jimschm) 22-Dec-1998
  10. Revision History:
  11. ovidiut 11-Oct-1999 Updated for new coding conventions and Win64 compliance
  12. --*/
  13. //
  14. // Includes
  15. //
  16. // None
  17. //
  18. // Strings
  19. //
  20. // None
  21. //
  22. // Constants
  23. //
  24. // None
  25. //
  26. // Macros
  27. //
  28. #define CASE_SENSITIVE TRUE
  29. #define CASE_INSENSITIVE FALSE
  30. #define UNKNOWN_LETTER_CASE FALSE
  31. #define ALREADY_LOWERCASE TRUE
  32. #define DEFAULT_BUCKET_SIZE 0
  33. //
  34. // Types
  35. //
  36. typedef const void *HASHTABLE;
  37. typedef const void *HASHITEM;
  38. typedef struct {
  39. PCSTR String;
  40. PCVOID ExtraData;
  41. HASHITEM Index;
  42. HASHTABLE Internal;
  43. } HASHTABLE_ENUMA, *PHASHTABLE_ENUMA;
  44. typedef struct {
  45. PCWSTR String;
  46. PCVOID ExtraData;
  47. HASHITEM Index;
  48. HASHTABLE Internal;
  49. } HASHTABLE_ENUMW, *PHASHTABLE_ENUMW;
  50. typedef
  51. BOOL
  52. (*PHASHTABLE_CALLBACK_ROUTINEA)(
  53. IN HASHTABLE HashTable,
  54. IN HASHITEM Index,
  55. IN PCSTR String,
  56. IN PVOID ExtraData,
  57. IN UINT ExtraDataSize,
  58. IN LPARAM lParam
  59. );
  60. typedef
  61. BOOL
  62. (*PHASHTABLE_CALLBACK_ROUTINEW)(
  63. IN HASHTABLE HashTable,
  64. IN HASHITEM Index,
  65. IN PCWSTR String,
  66. IN PVOID ExtraData,
  67. IN UINT ExtraDataSize,
  68. IN LPARAM lParam
  69. );
  70. //
  71. // Globals
  72. //
  73. // None
  74. //
  75. // Macro expansion list
  76. //
  77. // None
  78. //
  79. // Function prototypes and wrapper macros
  80. //
  81. HASHTABLE
  82. RealHtAllocExAW (
  83. IN BOOL CaseSensitive,
  84. IN BOOL Unicode,
  85. IN BOOL ExternalStrings,
  86. IN UINT ExtraDataSize,
  87. IN UINT BucketCount OPTIONAL
  88. );
  89. #define HtAllocExAW(cs,u,s,d,b) TRACK_BEGIN(HASHTABLE, HtAllocExAW)\
  90. RealHtAllocExAW(cs,u,s,d,b)\
  91. TRACK_END()
  92. #define HtAllocA() HtAllocExAW(FALSE,FALSE,FALSE,0,0)
  93. #define HtAllocW() HtAllocExAW(FALSE,TRUE,FALSE,0,0)
  94. #define HtAllocWithDataA(size) HtAllocExAW(FALSE,FALSE,FALSE,size,0)
  95. #define HtAllocWithDataW(size) HtAllocExAW(FALSE,TRUE,FALSE,size,0)
  96. #define HtAllocExA(cs,datasize,bucketcount) HtAllocExAW(cs,FALSE,FALSE,datasize,bucketcount)
  97. #define HtAllocExW(cs,datasize,bucketcount) HtAllocExAW(cs,TRUE,FALSE,datasize,bucketcount)
  98. #define HtAllocExternStrA() HtAllocExAW(FALSE,FALSE,TRUE,0,0)
  99. #define HtAllocExternStrW() HtAllocExAW(FALSE,TRUE,TRUE,0,0)
  100. #define HtAllocExternStrWithDataA(size) HtAllocExAW(FALSE,FALSE,TRUE,0,0)
  101. #define HtAllocExternStrWithDataW(size) HtAllocExAW(FALSE,TRUE,TRUE,0,0)
  102. #define HtAllocExternStrExA(cs,size,bucketcount) HtAllocExAW(cs,FALSE,TRUE,size,bucketcount)
  103. #define HtAllocExternStrExW(cs,size,bucketcount) HtAllocExAW(cs,TRUE,TRUE,size,bucketcount)
  104. VOID
  105. HtFree (
  106. IN HASHTABLE HashTable
  107. );
  108. HASHITEM
  109. HtAddStringExA (
  110. IN HASHTABLE HashTable,
  111. IN PCSTR String,
  112. IN PCVOID ExtraData, OPTIONAL
  113. IN BOOL AlreadyLowercase
  114. );
  115. #define HtAddStringA(table,string) HtAddStringExA(table,string,NULL,UNKNOWN_LETTER_CASE)
  116. #define HtAddStringAndDataA(table,string,data) HtAddStringExA(table,string,data,UNKNOWN_LETTER_CASE)
  117. HASHITEM
  118. HtAddStringExW (
  119. IN HASHTABLE HashTable,
  120. IN PCWSTR String,
  121. IN PCVOID ExtraData, OPTIONAL
  122. IN BOOL AlreadyLowercase
  123. );
  124. #define HtAddStringW(table,string) HtAddStringExW(table,string,NULL,UNKNOWN_LETTER_CASE)
  125. #define HtAddStringAndDataW(table,string,data) HtAddStringExW(table,string,data,UNKNOWN_LETTER_CASE)
  126. BOOL
  127. HtRemoveItem (
  128. IN HASHTABLE HashTable,
  129. IN HASHITEM Item
  130. );
  131. BOOL
  132. HtRemoveStringA (
  133. IN HASHTABLE HashTable,
  134. IN PCSTR AnsiString
  135. );
  136. BOOL
  137. HtRemoveStringW (
  138. IN HASHTABLE HashTable,
  139. IN PCWSTR UnicodeString
  140. );
  141. HASHITEM
  142. HtFindStringExA (
  143. IN HASHTABLE HashTable,
  144. IN PCSTR String,
  145. OUT PVOID ExtraData, OPTIONAL
  146. IN BOOL AlreadyLowercase
  147. );
  148. #define HtFindStringA(table,string) HtFindStringExA(table,string,NULL,UNKNOWN_LETTER_CASE)
  149. #define HtFindStringAndDataA(table,string,data) HtFindStringExA(table,string,data,UNKNOWN_LETTER_CASE)
  150. HASHITEM
  151. HtFindStringExW (
  152. IN HASHTABLE HashTable,
  153. IN PCWSTR String,
  154. OUT PVOID ExtraData, OPTIONAL
  155. IN BOOL AlreadyLowercase
  156. );
  157. #define HtFindStringW(table,string) HtFindStringExW(table,string,NULL,UNKNOWN_LETTER_CASE)
  158. #define HtFindStringAndDataW(table,string,data) HtFindStringExW(table,string,data,UNKNOWN_LETTER_CASE)
  159. HASHITEM
  160. HtFindPrefixExA (
  161. IN HASHTABLE HashTable,
  162. IN PCSTR StringStart,
  163. IN PCSTR BufferEnd,
  164. OUT PVOID ExtraData, OPTIONAL
  165. IN BOOL AlreadyLowercase
  166. );
  167. #define HtFindPrefixA(table,str,end) HtFindPrefixExA(table,str,end,NULL,UNKNOWN_LETTER_CASE)
  168. HASHITEM
  169. HtFindPrefixExW (
  170. IN HASHTABLE HashTable,
  171. IN PCWSTR StringStart,
  172. IN PCWSTR BufferEnd,
  173. OUT PVOID ExtraData, OPTIONAL
  174. IN BOOL AlreadyLowercase
  175. );
  176. #define HtFindPrefixW(table,str,end) HtFindPrefixExW(table,str,end,NULL,UNKNOWN_LETTER_CASE)
  177. BOOL
  178. HtGetExtraData (
  179. IN HASHTABLE HashTable,
  180. IN HASHITEM Index,
  181. OUT PCVOID *ExtraData
  182. );
  183. BOOL
  184. HtCopyStringData (
  185. IN HASHTABLE HashTable,
  186. IN HASHITEM Index,
  187. OUT PVOID ExtraData
  188. );
  189. BOOL
  190. HtSetStringData (
  191. IN HASHTABLE HashTable,
  192. IN HASHITEM Index,
  193. IN PCVOID ExtraData
  194. );
  195. PCSTR
  196. HtGetStringFromItemA (
  197. IN HASHITEM Index
  198. );
  199. PCWSTR
  200. HtGetStringFromItemW (
  201. IN HASHITEM Index
  202. );
  203. BOOL
  204. EnumFirstHashTableStringA (
  205. OUT PHASHTABLE_ENUMA EnumPtr,
  206. IN HASHTABLE HashTable
  207. );
  208. BOOL
  209. EnumFirstHashTableStringW (
  210. OUT PHASHTABLE_ENUMW EnumPtr,
  211. IN HASHTABLE HashTable
  212. );
  213. BOOL
  214. EnumNextHashTableStringA (
  215. IN OUT PHASHTABLE_ENUMA EnumPtr
  216. );
  217. BOOL
  218. EnumNextHashTableStringW (
  219. IN OUT PHASHTABLE_ENUMW EnumPtr
  220. );
  221. BOOL
  222. EnumHashTableWithCallbackA (
  223. IN HASHTABLE Table,
  224. IN PHASHTABLE_CALLBACK_ROUTINEA Proc,
  225. IN LPARAM lParam
  226. );
  227. BOOL
  228. EnumHashTableWithCallbackW (
  229. IN HASHTABLE Table,
  230. IN PHASHTABLE_CALLBACK_ROUTINEW Proc,
  231. IN LPARAM lParam
  232. );
  233. //
  234. // Macro expansion definition
  235. //
  236. // None
  237. //
  238. // A & W macros
  239. //
  240. #ifdef UNICODE
  241. #define HASHTABLE_ENUM HASHTABLE_ENUMW
  242. #define PHASHTABLE_ENUM PHASHTABLE_ENUMW
  243. #define PHASH_CALLBACK_ROUTINE PHASH_CALLBACK_ROUTINEW
  244. #define HtAlloc HtAllocW
  245. #define HtAllocWithData HtAllocWithDataW
  246. #define HtAllocEx HtAllocExW
  247. #define HtAllocExternStr HtAllocExternStrW
  248. #define HtAllocExternStrWithData HtAllocExternStrWithDataW
  249. #define HtAllocExternStrEx HtAllocExternStrExW
  250. #define HtAddString HtAddStringW
  251. #define HtAddStringAndData HtAddStringAndDataW
  252. #define HtAddStringEx HtAddStringExW
  253. #define HtRemoveString HtRemoveStringW
  254. #define HtFindString HtFindStringW
  255. #define HtFindStringAndData HtFindStringAndDataW
  256. #define HtFindStringEx HtFindStringExW
  257. #define HtFindPrefix HtFindPrefixW
  258. #define HtFindPrefixEx HtFindPrefixExW
  259. #define HtGetStringFromItem HtGetStringFromItemW
  260. #define EnumFirstHashTableString EnumFirstHashTableStringW
  261. #define EnumNextHashTableString EnumNextHashTableStringW
  262. #define EnumHashTableWithCallback EnumHashTableWithCallbackW
  263. #else
  264. #define HASHTABLE_ENUM HASHTABLE_ENUMA
  265. #define PHASHTABLE_ENUM PHASHTABLE_ENUMA
  266. #define PHASH_CALLBACK_ROUTINE PHASH_CALLBACK_ROUTINEA
  267. #define HtAlloc HtAllocA
  268. #define HtAllocWithData HtAllocWithDataA
  269. #define HtAllocEx HtAllocExA
  270. #define HtAllocExternStr HtAllocExternStrA
  271. #define HtAllocExternStrWithData HtAllocExternStrWithDataA
  272. #define HtAllocExternStrEx HtAllocExternStrExA
  273. #define HtAddString HtAddStringA
  274. #define HtAddStringAndData HtAddStringAndDataA
  275. #define HtAddStringEx HtAddStringExA
  276. #define HtRemoveString HtRemoveStringA
  277. #define HtFindString HtFindStringA
  278. #define HtFindStringAndData HtFindStringAndDataA
  279. #define HtFindStringEx HtFindStringExA
  280. #define HtFindPrefix HtFindPrefixA
  281. #define HtFindPrefixEx HtFindPrefixExA
  282. #define HtGetStringFromItem HtGetStringFromItemA
  283. #define EnumFirstHashTableString EnumFirstHashTableStringA
  284. #define EnumNextHashTableString EnumNextHashTableStringA
  285. #define EnumHashTableWithCallback EnumHashTableWithCallbackA
  286. #endif