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.

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