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.

305 lines
8.0 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. harray.h
  7. Index mgr for wins db
  8. FILE HISTORY:
  9. Oct 13 1997 EricDav Created
  10. */
  11. #ifndef _HARRAY_H
  12. #define _HARRAY_H
  13. #include "afxmt.h"
  14. class CVerifyWins ;
  15. typedef enum _INDEX_TYPE
  16. {
  17. INDEX_TYPE_NAME,
  18. INDEX_TYPE_IP,
  19. INDEX_TYPE_VERSION,
  20. INDEX_TYPE_TYPE,
  21. INDEX_TYPE_EXPIRATION,
  22. INDEX_TYPE_STATE,
  23. INDEX_TYPE_STATIC,
  24. INDEX_TYPE_OWNER,
  25. INDEX_TYPE_FILTER
  26. } INDEX_TYPE;
  27. class CHRowIndex;
  28. typedef CArray<HROW, HROW> HRowArray;
  29. typedef CList<CHRowIndex *, CHRowIndex *> HRowArrayList;
  30. // base class for a sorted index
  31. class CHRowIndex
  32. {
  33. public:
  34. CHRowIndex(INDEX_TYPE IndexType);
  35. virtual ~CHRowIndex();
  36. public:
  37. // used for insertion into the list
  38. virtual int BCompare(const void *, const void *) = 0;
  39. virtual int BCompareD(const void *, const void *) = 0;
  40. virtual HRESULT Sort() = 0;
  41. virtual HRESULT Add(HROW hrow, BOOL bEnd);
  42. virtual HRESULT Remove(HROW hrow);
  43. virtual HRESULT GetType(INDEX_TYPE * pIndexType);
  44. virtual HROW GetHRow(int nIndex);
  45. virtual int GetIndex(HROW hrow);
  46. BOOL IsAscending() { return m_bAscending; }
  47. void SetAscending(BOOL bAscending) { m_bAscending = bAscending; }
  48. HRESULT SetArray(HRowArray & hrowArray);
  49. HRowArray & GetArray() { return m_hrowArray; }
  50. void SetType(INDEX_TYPE indexType)
  51. {
  52. m_dbType = indexType;
  53. }
  54. void * BSearch(const void * key, const void * base, size_t num, size_t width);
  55. protected:
  56. INDEX_TYPE m_dbType;
  57. HRowArray m_hrowArray;
  58. BOOL m_bAscending;
  59. };
  60. // the Index manager
  61. class CIndexMgr : public HRowArrayList
  62. {
  63. public:
  64. CIndexMgr();
  65. virtual ~CIndexMgr();
  66. public:
  67. HRESULT Initialize();
  68. HRESULT Reset();
  69. UINT GetTotalCount();
  70. UINT GetCurrentCount();
  71. BOOL AcceptWinsRecord(WinsRecord *pWinsRecord);
  72. HRESULT AddHRow(HROW hrow, BOOL bLoading = FALSE, BOOL bFilterChecked = FALSE);
  73. HRESULT RemoveHRow(HROW hrow);
  74. HRESULT Sort(WINSDB_SORT_TYPE SortType, DWORD dwSortOptions);
  75. HRESULT Filter(WINSDB_FILTER_TYPE FilterType, DWORD dwParam1, DWORD dwParam2);
  76. HRESULT AddFilter(WINSDB_FILTER_TYPE FilterType, DWORD dwParam1, DWORD dwParam2, LPCOLESTR strParam3);
  77. HRESULT ClearFilter(WINSDB_FILTER_TYPE FilterType);
  78. HRESULT SetActiveView(WINSDB_VIEW_TYPE ViewType);
  79. HRESULT GetHRow(int nIndex, LPHROW phrow);
  80. HRESULT GetIndex(HROW hrow, int * pIndex);
  81. CHRowIndex * GetNameIndex();
  82. CHRowIndex * GetFilteredNameIndex();
  83. void CleanupIndicies();
  84. protected:
  85. HRowArrayList m_listIndicies;
  86. POSITION m_posCurrentIndex;
  87. POSITION m_posFilteredIndex;
  88. POSITION m_posLastIndex;
  89. // points to either Filtered index or the index depending on whether the
  90. // view is filtered or not
  91. POSITION m_posUpdatedIndex;
  92. CCriticalSection m_cs;
  93. HRowArrayList m_listFilteredIndices;
  94. BOOL m_bFiltered;
  95. };
  96. // Index for name sorted
  97. class CIndexName : public CHRowIndex
  98. {
  99. public:
  100. CIndexName() : CHRowIndex(INDEX_TYPE_NAME) { };
  101. public:
  102. // used for insertion into the list
  103. int BCompare(const void *, const void *);
  104. int BCompareD(const void *, const void *);
  105. // used for sorting the list
  106. virtual HRESULT Sort();
  107. static int __cdecl QCompareA(const void *, const void *);
  108. static int __cdecl QCompareD(const void *, const void *);
  109. };
  110. // Index for type sorted
  111. class CIndexType : public CHRowIndex
  112. {
  113. public:
  114. CIndexType() : CHRowIndex(INDEX_TYPE_TYPE) { };
  115. public:
  116. // used for insertion into the list
  117. int BCompare(const void *, const void *);
  118. int BCompareD(const void *, const void *);
  119. // used for sorting the list
  120. virtual HRESULT Sort();
  121. static int __cdecl QCompareA(const void *, const void *);
  122. static int __cdecl QCompareD(const void *, const void *);
  123. };
  124. // Index for IP address sorted
  125. class CIndexIpAddr : public CHRowIndex
  126. {
  127. public:
  128. CIndexIpAddr() : CHRowIndex(INDEX_TYPE_IP) { };
  129. public:
  130. // used for insertion into the list
  131. int BCompare(const void *, const void *);
  132. int BCompareD(const void *, const void *);
  133. // used for sorting the list
  134. virtual HRESULT Sort();
  135. static int __cdecl QCompareA(const void *, const void *);
  136. static int __cdecl QCompareD(const void *, const void *);
  137. };
  138. // Index for Expiration sorted
  139. class CIndexExpiration : public CHRowIndex
  140. {
  141. public:
  142. CIndexExpiration() : CHRowIndex(INDEX_TYPE_EXPIRATION) { };
  143. public:
  144. // used for insertion into the list
  145. int BCompare(const void *, const void *);
  146. int BCompareD(const void *, const void *);
  147. // used for sorting the list
  148. virtual HRESULT Sort();
  149. static int __cdecl QCompareA(const void *, const void *);
  150. static int __cdecl QCompareD(const void *, const void *);
  151. };
  152. // Index for version sorted
  153. class CIndexVersion : public CHRowIndex
  154. {
  155. public:
  156. CIndexVersion() : CHRowIndex(INDEX_TYPE_VERSION) { };
  157. public:
  158. // used for insertion into the list
  159. int BCompare(const void *, const void *);
  160. int BCompareD(const void *, const void *);
  161. // used for sorting the list
  162. virtual HRESULT Sort();
  163. static int __cdecl QCompareA(const void *, const void *);
  164. static int __cdecl QCompareD(const void *, const void *);
  165. };
  166. // Index for version sorted
  167. class CIndexState : public CHRowIndex
  168. {
  169. public:
  170. CIndexState() : CHRowIndex(INDEX_TYPE_STATE) { };
  171. public:
  172. // used for insertion into the list
  173. int BCompare(const void *, const void *);
  174. int BCompareD(const void *, const void *);
  175. // used for sorting the list
  176. virtual HRESULT Sort();
  177. static int __cdecl QCompareA(const void *, const void *);
  178. static int __cdecl QCompareD(const void *, const void *);
  179. };
  180. // Index for version sorted
  181. class CIndexStatic : public CHRowIndex
  182. {
  183. public:
  184. CIndexStatic() : CHRowIndex(INDEX_TYPE_STATIC) { };
  185. public:
  186. // used for insertion into the list
  187. int BCompare(const void *, const void *);
  188. int BCompareD(const void *, const void *);
  189. // used for sorting the list
  190. virtual HRESULT Sort();
  191. static int __cdecl QCompareA(const void *, const void *);
  192. static int __cdecl QCompareD(const void *, const void *);
  193. };
  194. // Index for Owner sorted
  195. class CIndexOwner : public CHRowIndex
  196. {
  197. public:
  198. CIndexOwner() : CHRowIndex(INDEX_TYPE_OWNER) { };
  199. public:
  200. // used for insertion into the list
  201. int BCompare(const void *, const void *);
  202. int BCompareD(const void *, const void *);
  203. // used for sorting the list
  204. virtual HRESULT Sort();
  205. static int __cdecl QCompareA(const void *, const void *);
  206. static int __cdecl QCompareD(const void *, const void *);
  207. };
  208. typedef CMap<DWORD, DWORD&, BOOL, BOOL&> CFilterTypeMap;
  209. typedef struct
  210. {
  211. DWORD Mask;
  212. DWORD Address;
  213. } tIpReference;
  214. // Filtered Index for name sorted
  215. class CFilteredIndexName : public CIndexName
  216. {
  217. // returns the pointer to the pName where the matching failed
  218. // or NULL if the matching succeeded.
  219. LPCSTR PatternMatching(LPCSTR pName, LPCSTR pPattern, INT nNameLen);
  220. BOOL SubnetMatching(tIpReference &IpRefPattern, DWORD dwIPAddress);
  221. public:
  222. CFilteredIndexName()
  223. {
  224. SetType(INDEX_TYPE_FILTER);
  225. m_pchFilteredName = NULL;
  226. };
  227. ~CFilteredIndexName()
  228. {
  229. if (m_pchFilteredName != NULL)
  230. delete m_pchFilteredName;
  231. }
  232. public:
  233. HRESULT AddFilter(WINSDB_FILTER_TYPE FilterType, DWORD dwData1, DWORD dwData2, LPCOLESTR strData3);
  234. HRESULT ClearFilter(WINSDB_FILTER_TYPE FilterType);
  235. BOOL CheckForFilter(LPHROW hrowCheck);
  236. BOOL CheckWinsRecordForFilter(WinsRecord *pWinsRecord);
  237. CFilterTypeMap m_mapFilterTypes;
  238. CDWordArray m_dwaFilteredOwners;
  239. CArray <tIpReference, tIpReference> m_taFilteredIp;
  240. LPSTR m_pchFilteredName;
  241. BOOL m_bMatchCase;
  242. };
  243. #endif //_HARRAY_H