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.

319 lines
9.9 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. spddb.h
  7. FILE HISTORY:
  8. */
  9. #ifndef _SPDDB_H
  10. #define _SPDDB_H
  11. #ifndef _HARRAY_H
  12. #include "harray.h"
  13. #endif
  14. #include "spdutil.h"
  15. #define PROTOCOL_ID_OFFSET 9
  16. interface ISpdInfo;
  17. template <class T>
  18. void
  19. FreeItemsAndEmptyArray (
  20. T& array);
  21. DWORD
  22. IsAdmin(
  23. LPCTSTR szMachineName,
  24. LPCTSTR szAccount,
  25. LPCTSTR szPassword,
  26. BOOL * pfIsAdmin
  27. );
  28. typedef enum _IPFWMON_INFO_TYPE
  29. {
  30. MON_FILTER=0x1,
  31. MON_LOG_DATA=0x2,
  32. MON_FWSTATS=0x100,
  33. MON_FWINIT=0x400
  34. } IPFWMON_INFO_TYPE;
  35. DWORD DeallocateDbRecord(PWZC_DB_RECORD const pwzcRec);
  36. class CLogDataInfo
  37. {
  38. public:
  39. WZC_DB_RECORD m_wzcDbRecord;
  40. public:
  41. CLogDataInfo()
  42. {
  43. memset(&m_wzcDbRecord, 0, sizeof(WZC_DB_RECORD));
  44. }
  45. DWORD ConvertToDbRecord(PWZC_DB_RECORD pwzcRecord)
  46. {
  47. DWORD dwErr = ERROR_SUCCESS;
  48. dwErr = AllocateAndCopy(pwzcRecord, &m_wzcDbRecord);
  49. return dwErr;
  50. }
  51. CLogDataInfo& operator=(const WZC_DB_RECORD &wzcDbRecord)
  52. {
  53. const WZC_DB_RECORD *pwzcDbRecord = &wzcDbRecord;
  54. AllocateAndCopy(&m_wzcDbRecord, pwzcDbRecord);
  55. return *this;
  56. }
  57. CLogDataInfo& operator=(const CLogDataInfo &cLogData)
  58. {
  59. const WZC_DB_RECORD *pwzcDbRecord = &cLogData.m_wzcDbRecord;
  60. AllocateAndCopy(&m_wzcDbRecord, pwzcDbRecord);
  61. return *this;
  62. }
  63. BOOL operator==(const CLogDataInfo &LogDataRHS)
  64. {
  65. BOOL bEqual = FALSE;
  66. const WZC_DB_RECORD *pwzcDbLHS = &m_wzcDbRecord;
  67. const WZC_DB_RECORD *pwzcDbRHS = &LogDataRHS.m_wzcDbRecord;
  68. //TODO: Complete and check all the fields inside
  69. if ( (pwzcDbLHS->recordid == pwzcDbRHS->recordid) &&
  70. (pwzcDbLHS->componentid == pwzcDbRHS->componentid) &&
  71. (pwzcDbLHS->category == pwzcDbRHS->category) &&
  72. (pwzcDbLHS->timestamp == pwzcDbRHS->timestamp) &&
  73. (pwzcDbLHS->message.dwDataLen == pwzcDbRHS->message.dwDataLen) &&
  74. (pwzcDbLHS->localmac.dwDataLen == pwzcDbRHS->localmac.dwDataLen)&&
  75. (pwzcDbLHS->remotemac.dwDataLen==pwzcDbRHS->remotemac.dwDataLen)&&
  76. (pwzcDbLHS->ssid.dwDataLen == pwzcDbRHS->ssid.dwDataLen) &&
  77. (pwzcDbLHS->context.dwDataLen == pwzcDbRHS->context.dwDataLen) )
  78. bEqual = TRUE;
  79. return bEqual;
  80. }
  81. BOOL operator!=(const CLogDataInfo &LogDataRHS)
  82. {
  83. BOOL bNotEqual = FALSE;
  84. const WZC_DB_RECORD *pwzcDbLHS = &m_wzcDbRecord;
  85. const WZC_DB_RECORD *pwzcDbRHS = &LogDataRHS.m_wzcDbRecord;
  86. //TODO: complete and check all fields inside
  87. if ( (pwzcDbLHS->recordid != pwzcDbRHS->recordid) ||
  88. (pwzcDbLHS->componentid != pwzcDbRHS->componentid) ||
  89. (pwzcDbLHS->category != pwzcDbRHS->category) ||
  90. (pwzcDbLHS->timestamp != pwzcDbRHS->timestamp) ||
  91. (pwzcDbLHS->message.dwDataLen != pwzcDbRHS->message.dwDataLen) ||
  92. (pwzcDbLHS->localmac.dwDataLen != pwzcDbRHS->localmac.dwDataLen)||
  93. (pwzcDbLHS->remotemac.dwDataLen!=pwzcDbRHS->remotemac.dwDataLen)||
  94. (pwzcDbLHS->ssid.dwDataLen != pwzcDbRHS->ssid.dwDataLen) ||
  95. (pwzcDbLHS->context.dwDataLen != pwzcDbRHS->context.dwDataLen) )
  96. bNotEqual = TRUE;
  97. return bNotEqual;
  98. }
  99. void Deallocate()
  100. {
  101. DeallocateDbRecord(&m_wzcDbRecord);
  102. }
  103. ~CLogDataInfo()
  104. {
  105. DeallocateDbRecord(&m_wzcDbRecord);
  106. }
  107. private:
  108. DWORD AllocateAndCopy(WZC_DB_RECORD *pwzcDest,
  109. const WZC_DB_RECORD *pwzcSrc)
  110. {
  111. DWORD dwErr = ERROR_SUCCESS;
  112. pwzcDest->recordid = pwzcSrc->recordid;
  113. pwzcDest->componentid = pwzcSrc->componentid;
  114. pwzcDest->category = pwzcSrc->category;
  115. pwzcDest->timestamp = pwzcSrc->timestamp;
  116. pwzcDest->message.dwDataLen = pwzcSrc->message.dwDataLen;
  117. pwzcDest->localmac.dwDataLen = pwzcSrc->localmac.dwDataLen;
  118. pwzcDest->remotemac.dwDataLen = pwzcSrc->remotemac.dwDataLen;
  119. pwzcDest->ssid.dwDataLen = pwzcSrc->ssid.dwDataLen;
  120. pwzcDest->context.dwDataLen = pwzcSrc->context.dwDataLen;
  121. try
  122. {
  123. if (pwzcSrc->message.dwDataLen > 0)
  124. {
  125. pwzcDest->message.pData = new
  126. BYTE[pwzcSrc->message.dwDataLen];
  127. memcpy(pwzcDest->message.pData,
  128. pwzcSrc->message.pData,
  129. pwzcSrc->message.dwDataLen);
  130. }
  131. else
  132. pwzcDest->message.pData = NULL;
  133. if (pwzcSrc->localmac.dwDataLen > 0)
  134. {
  135. pwzcDest->localmac.pData = new
  136. BYTE[pwzcSrc->localmac.dwDataLen];
  137. memcpy(pwzcDest->localmac.pData,
  138. pwzcSrc->localmac.pData,
  139. pwzcSrc->localmac.dwDataLen);
  140. }
  141. else
  142. pwzcDest->localmac.pData = NULL;
  143. if (pwzcSrc->remotemac.dwDataLen > 0)
  144. {
  145. pwzcDest->remotemac.pData = new
  146. BYTE[pwzcSrc->remotemac.dwDataLen];
  147. memcpy(pwzcDest->remotemac.pData,
  148. pwzcSrc->remotemac.pData,
  149. pwzcSrc->remotemac.dwDataLen);
  150. }
  151. else
  152. pwzcDest->remotemac.pData = NULL;
  153. if (pwzcSrc->ssid.dwDataLen > 0)
  154. {
  155. pwzcDest->ssid.pData = new
  156. BYTE[pwzcSrc->ssid.dwDataLen];
  157. memcpy(pwzcDest->ssid.pData, pwzcSrc->ssid.pData,
  158. pwzcSrc->ssid.dwDataLen);
  159. }
  160. else
  161. pwzcDest->ssid.pData = NULL;
  162. if (pwzcSrc->context.dwDataLen > 0)
  163. {
  164. pwzcDest->context.pData = new
  165. BYTE[pwzcSrc->context.dwDataLen];
  166. memcpy(pwzcDest->context.pData,
  167. pwzcSrc->context.pData,
  168. pwzcSrc->context.dwDataLen);
  169. }
  170. else
  171. pwzcDest->context.pData = NULL;
  172. }
  173. catch(...)
  174. {
  175. Panic0("Memory allocation failure AllocateAndCopy");
  176. dwErr = ERROR_OUTOFMEMORY;
  177. }
  178. return dwErr;
  179. }
  180. };
  181. typedef CArray<CLogDataInfo *, CLogDataInfo *> CLogDataInfoArray;
  182. #define MAX_STR_LEN 80
  183. #define DeclareISpdInfoMembers(IPURE) \
  184. STDMETHOD(Destroy) (THIS) IPURE; \
  185. STDMETHOD(SetComputerName) (THIS_ LPTSTR pszName) IPURE; \
  186. STDMETHOD(GetComputerName) (THIS_ CString * pstName) IPURE; \
  187. STDMETHOD(GetSession) (THIS_ PHANDLE phsession) IPURE; \
  188. STDMETHOD(SetSession) (THIS_ HANDLE hsession) IPURE; \
  189. STDMETHOD(ResetSession) (THIS) IPURE; \
  190. STDMETHOD(EnumLogData) (THIS_ PDWORD pdwNew, PDWORD pdwTotal) IPURE; \
  191. STDMETHOD(FlushLogs) (THIS) IPURE; \
  192. STDMETHOD(GetLogDataInfo) (THIS_ int iIndex, CLogDataInfo * pLogDataInfo) IPURE; \
  193. STDMETHOD(SetSortOptions) (THIS_ DWORD dwColID, BOOL bAscending) IPURE; \
  194. STDMETHOD_(DWORD, GetLogDataCount) (THIS) IPURE; \
  195. STDMETHOD(SortLogData) (THIS_ DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  196. STDMETHOD(SortLogData) (THIS) IPURE; \
  197. STDMETHOD(GetLastIndex) (THIS_ int *pnIndex) IPURE; \
  198. STDMETHOD(GetSpecificLog) (THIS_ int nIndex, CLogDataInfo *pLogDataInfo) IPURE; \
  199. STDMETHOD(FindIndex) (THIS_ int *pnIndex, CLogDataInfo *pLogDataInfo) IPURE; \
  200. STDMETHOD_(DWORD, GetInitInfo) (THIS) IPURE; \
  201. STDMETHOD_(void, SetInitInfo) (THIS_ DWORD dwInitInfo) IPURE; \
  202. STDMETHOD_(DWORD, GetActiveInfo) (THIS) IPURE; \
  203. STDMETHOD_(void, SetActiveInfo) (THIS_ DWORD dwActiveInfo) IPURE; \
  204. STDMETHOD_(void, StartFromFirstRecord) (THIS_ BOOL bFromFirst) IPURE; \
  205. #undef INTERFACE
  206. #define INTERFACE ISpdInfo
  207. DECLARE_INTERFACE_(ISpdInfo, IUnknown)
  208. {
  209. public:
  210. DeclareIUnknownMembers(PURE)
  211. DeclareISpdInfoMembers(PURE)
  212. };
  213. typedef ComSmartPointer<ISpdInfo, &IID_ISpdInfo> SPISpdInfo;
  214. class CSpdInfo : public ISpdInfo
  215. {
  216. public:
  217. CSpdInfo();
  218. ~CSpdInfo();
  219. DeclareIUnknownMembers(IMPL);
  220. DeclareISpdInfoMembers(IMPL);
  221. private:
  222. CLogDataInfoArray m_arrayLogData; //For Log Data
  223. CIndexMgrLogData m_IndexMgrLogData;
  224. CCriticalSection m_csData;
  225. CString m_stMachineName;
  226. LONG m_cRef;
  227. DWORD m_Init;
  228. DWORD m_Active;
  229. HANDLE m_session;
  230. bool m_session_init;
  231. BOOL m_bFromFirst;
  232. BOOL m_bEliminateDuplicates;
  233. //Remember the users last choice for sorting
  234. DWORD m_dwSortIndex;
  235. DWORD m_dwSortOption;
  236. /* Configureable parameter representing the number of records that
  237. * may be stored in the database and hence indicates the number of
  238. * records that are cached in the monitor.
  239. */
  240. int m_nNumRecords;
  241. private:
  242. DWORD
  243. EliminateDuplicates(
  244. CLogDataInfoArray *pArray
  245. );
  246. HRESULT
  247. InternalEnumLogData(
  248. CLogDataInfoArray *pArray,
  249. DWORD dwPreferredNum,
  250. BOOL pbFromFirst
  251. );
  252. HRESULT
  253. InternalGetSpecificLog(
  254. CLogDataInfo *pLogDataInfo
  255. );
  256. void
  257. FreeItemsAndEmptyArray(
  258. CLogDataInfoArray& array
  259. );
  260. };
  261. HRESULT
  262. CreateSpdInfo(
  263. ISpdInfo **ppSpdInfo
  264. );
  265. #endif // _SPDDB_H