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.

405 lines
11 KiB

  1. #ifndef _trapreg_h
  2. #define _trapreg_h
  3. #include "regkey.h"
  4. #include "utils.h"
  5. #define MAX_TRAP_SIZE 4096
  6. #define THRESHOLD_COUNT 500
  7. #define THRESHOLD_TIME 300
  8. // Values for the SNMP_EVENTS\Parameters\Threshold flag
  9. #define THROTTLE_RESET 0
  10. #define THROTTLE_TRIPPED 1
  11. // Values for the SNMP_EVENTS\Parameters\ThresholdEnabled flag
  12. #define THROTTLE_DISABLED 0
  13. #define THROTTLE_ENABLED 1
  14. //***************************************************************************
  15. // REGISTRY KEYS
  16. //
  17. // The following strings are registry keys. They should not be internationalized,
  18. // so they are not in the string table.
  19. //
  20. //****************************************************************************
  21. #define SZ_REGKEY_MICROSOFT _T("SOFTWARE\\Microsoft")
  22. #define SZ_REGKEY_SOURCE_EVENTLOG _T("SYSTEM\\CurrentControlSet\\Services\\EventLog")
  23. #define SZ_REGKEY_SNMP_EVENTS _T("SOFTWARE\\Microsoft\\SNMP_EVENTS")
  24. // These are subkeys under \SOFTWARE\Microsoft\SNMP_EVENTS
  25. #define SZ_REGKEY_EVENTLOG _T("EventLog")
  26. #define SZ_REGKEY_SOURCES _T("EventLog\\Sources")
  27. #define SZ_REGKEY_CURRENTLY_OPEN _T("CurrentlyOpen")
  28. #define SZ_REGKEY_SOURCE_ENTERPRISE_OID _T("EnterpriseOID")
  29. #define SZ_REGKEY_SOURCE_APPEND _T("Append")
  30. #define SZ_REGKEY_PARAMETERS _T("EventLog\\Parameters")
  31. #define SZ_REGKEY_PARAMS _T("Parameters")
  32. #define SZ_REGKEY_PARAMS_BASE_ENTERPRISE_OID _T("BaseEnterpriseOID")
  33. #define SZ_REGKEY_PARAMS_TRIMFLAG _T("TrimFlag")
  34. #define SZ_REGKEY_PARAMS_MAXTRAP_SIZE _T("MaxTrapSize")
  35. #define SZ_REGKEY_PARAMS_TRIM_MESSAGE _T("TrimMessage")
  36. #define SZ_REGKEY_PARAMS_THRESHOLD _T("Threshold")
  37. #define SZ_REGKEY_PARAMS_THRESHOLDENABLED _T("ThresholdEnabled")
  38. #define SZ_REGKEY_PARAMS_THRESHOLDCOUNT _T("ThresholdCount")
  39. #define SZ_REGKEY_PARAMS_THRESHOLDTIME _T("ThresholdTime")
  40. #define SZ_REGKEY_EVENT_COUNT _T("Count")
  41. #define SZ_REGKEY_EVENT_TIME _T("Time")
  42. #define SZ_REGKEY_EVENT_FULLID _T("FullID")
  43. #define SZ_REGKEY_SOURCE_EVENT_MESSAGE_FILE _T("EventMessageFile")
  44. #define SZ_NAME_REGVAL_TRANSLATOR_ENABLED _T("TranslatorEnabled")
  45. #define SZ_NAME_REGVAL_REVISIONCOUNT _T("RevisionCount")
  46. #define SZ_NAME_REGVAL_CONFIGTYPE _T("ConfigurationType")
  47. #define SZ_REGVAL_YES "YES"
  48. #define SZ_REGVAL_NO "NO"
  49. //**********************************************************************
  50. // The number of load steps that are performed in CTrapDlg::OnInitDialog
  51. // This is the number of steps that will be reserved in the progress
  52. // indicator for OnInitDialog
  53. //*********************************************************************
  54. #define LOAD_STEPS_IN_TRAPDLG 5
  55. // 11 setup steps plus 10 steps for the four known event logs
  56. #define LOAD_SETUP_STEP_COUNT 11
  57. #define LOAD_LOG_ARRAY_STEP_COUNT 40
  58. #define LOAD_STEP_COUNT (LOAD_SETUP_STEP_COUNT + LOAD_LOG_ARRAY_STEP_COUNT + LOAD_STEPS_IN_TRAPDLG)
  59. class CDlgSaveProgress;
  60. class CRegistryKey;
  61. class CXEventSource;
  62. class CBaseArray : public CObArray
  63. {
  64. public:
  65. CBaseArray() {}
  66. ~CBaseArray() {}
  67. void DeleteAll();
  68. };
  69. class CXEventSource;
  70. class CXEventLog;
  71. //The registry is made up of logs, that contain sources, that contain events
  72. class CXMessage : public CObject
  73. {
  74. public:
  75. CXMessage(CXEventSource* pEventSource);
  76. CXEventSource* m_pEventSource;
  77. DWORD m_dwId;
  78. CString m_sText;
  79. CXMessage& operator=(CXMessage& message);
  80. DWORD GetShortId() {return LOWORD(m_dwId); }
  81. void GetShortId(CString& sText);
  82. void GetSeverity(CString& sSeverity);
  83. void IsTrapping(CString& sIsTrapping);
  84. void SetAndCleanText(PMESSAGE_RESOURCE_ENTRY pEntry);
  85. };
  86. class CXMessageArray : private CBaseArray
  87. {
  88. public:
  89. CXMessageArray();
  90. ~CXMessageArray() {}
  91. void Initialize(CXEventSource* pEventSource) {m_pEventSource = pEventSource; }
  92. CXMessage* GetAt(int nIndex) {return (CXMessage*) CBaseArray::GetAt(nIndex); }
  93. CXMessage* operator[](int nIndex) {return (CXMessage*) CBaseArray::GetAt(nIndex); }
  94. void Add(CXMessage* pMessage) { CBaseArray::Add(pMessage); }
  95. void RemoveAll() {CBaseArray::RemoveAll(); }
  96. void DeleteAll() {CBaseArray::DeleteAll(); }
  97. LONG GetSize() {return (LONG)CBaseArray::GetSize(); }
  98. SCODE LoadMessages();
  99. CXMessage* FindMessage(DWORD dwId);
  100. CXEventSource* m_pEventSource;
  101. private:
  102. BOOL m_bDidLoadMessages;
  103. SCODE GetNextPath(CString& sPathlist, CString& sPath);
  104. };
  105. class CXEvent : public CObject
  106. {
  107. public:
  108. CXEvent(CXEventSource* pEventSource);
  109. CXEvent(CXMessage* pMessage);
  110. ~CXEvent();
  111. CXEventSource* m_pEventSource;
  112. DWORD m_dwCount;
  113. DWORD m_dwTimeInterval;
  114. CXMessage m_message;
  115. SCODE Deserialize(CRegistryKey& regkeyParent, CString& sName);
  116. SCODE Serialize(CRegistryKey& regkeyParent);
  117. void GetName(CString& sText) {DecString(sText, m_message.m_dwId); }
  118. void GetCount(CString& sText);
  119. void GetTimeInterval(CString& sText);
  120. };
  121. class CXEventArray : public CBaseArray
  122. {
  123. public:
  124. ~CXEventArray() {}
  125. CXEvent* GetAt(int nIndex) {return (CXEvent*) CBaseArray::GetAt(nIndex); }
  126. CXEvent* operator[](int nIndex) {return (CXEvent*) CBaseArray::GetAt(nIndex); }
  127. // void Add(CXEvent* pEvent) { CBaseArray::Add(pEvent); }
  128. void Add(CXEvent* pEvent);
  129. void RemoveAll() {CBaseArray::RemoveAll(); }
  130. void DeleteAll() {CBaseArray::DeleteAll(); }
  131. LONG GetSize() {return (LONG)CBaseArray::GetSize(); }
  132. SCODE Deserialize(CXEventSource* pEventSource);
  133. SCODE Serialize(CRegistryKey& regkeyParent);
  134. CXEvent* FindEvent(DWORD dwId);
  135. SCODE RemoveEvent(CXEvent* pEvent);
  136. };
  137. class CXEventSource : public CObject
  138. {
  139. public:
  140. CXEventSource(CXEventLog* pEventLog, CString& sName);
  141. ~CXEventSource();
  142. // Public data members
  143. CXEventLog* m_pEventLog;
  144. CString m_sName;
  145. CXEventArray m_aEvents;
  146. CXMessageArray m_aMessages;
  147. CString m_sLibPath;
  148. CXMessage* FindMessage(DWORD dwId) {return m_aMessages.FindMessage(dwId); }
  149. CXEvent* FindEvent(DWORD dwId) {return m_aEvents.FindEvent(dwId); }
  150. CXEventSource* FindEventSource(CString& sEventSource);
  151. SCODE Deserialize(CRegistryKey& regkeyParent);
  152. SCODE Serialize(CRegistryKey& regkeyParent);
  153. void GetEnterpriseOID(CString& sEnterpriseOID, BOOL bGetFullID=FALSE);
  154. SCODE LoadMessages() {return m_aMessages.LoadMessages(); }
  155. private:
  156. SCODE GetLibPath(CRegistryKey& regkey);
  157. };
  158. // CObArray is declared a private base type to ensure strong typing.
  159. class CXEventSourceArray : private CBaseArray
  160. {
  161. public:
  162. // Base array functionality public member functions.
  163. ~CXEventSourceArray() {DeleteAll(); }
  164. CXEventSource* GetAt(int nIndex) {return (CXEventSource*) CBaseArray::GetAt(nIndex); }
  165. CXEventSource* operator[](int nIndex) {return (CXEventSource*) CBaseArray::GetAt(nIndex); }
  166. void Add(CXEventSource* pEventSource) { CBaseArray::Add(pEventSource); }
  167. void RemoveAll() {CBaseArray::RemoveAll(); }
  168. void DeleteAll() {CBaseArray::DeleteAll(); }
  169. LONG GetSize() {return (LONG)CBaseArray::GetSize(); }
  170. // Public members specific to CXEventSourceArray
  171. CXEventSource* FindEventSource(CString& sSource);
  172. LONG FindEvent(CString& sLog, CString& sSource, DWORD dwEventId);
  173. SCODE Deserialize(CXEventLog* pEventLog);
  174. SCODE Serialize(CRegistryKey& regkey);
  175. };
  176. class CXEventLog : public CObject
  177. {
  178. public:
  179. CXEventLog(CString& sName) {m_sName = sName;}
  180. CXEventSourceArray m_aEventSources;
  181. CString m_sName;
  182. SCODE Deserialize();
  183. SCODE Serialize(CRegistryKey& regkey);
  184. CXEventSource* FindEventSource(CString& sEventSource);
  185. };
  186. inline CXEventSource* CXEventLog::FindEventSource(CString& sEventSource)
  187. {
  188. return m_aEventSources.FindEventSource(sEventSource);
  189. }
  190. class CXEventLogArray : private CBaseArray
  191. {
  192. public:
  193. // Base array functionality public member functions.
  194. CXEventLogArray() {}
  195. ~CXEventLogArray() {DeleteAll(); }
  196. CXEventLog* GetAt(int nIndex) {return (CXEventLog*) CBaseArray::GetAt(nIndex); }
  197. CXEventLog* operator[](int nIndex) {return (CXEventLog*) CBaseArray::GetAt(nIndex); }
  198. void Add(CXEventLog* pEventLog) { CBaseArray::Add(pEventLog); }
  199. void RemoveAll() {CBaseArray::RemoveAll(); }
  200. void DeleteAll() {CBaseArray::DeleteAll(); }
  201. LONG GetSize() {return (LONG)CBaseArray::GetSize(); }
  202. SCODE Deserialize();
  203. SCODE Serialize();
  204. CXEventSource* FindEventSource(CString& sLog, CString& sEventSource);
  205. };
  206. class CTraps
  207. {
  208. public:
  209. CXEventLogArray m_aEventLogs;
  210. SCODE Serialize();
  211. SCODE Deserialize();
  212. };
  213. class CTrapParams
  214. {
  215. public:
  216. CTrapParams();
  217. SCODE Serialize();
  218. SCODE Deserialize();
  219. SCODE ResetExtensionAgent();
  220. BOOL ThrottleIsTripped();
  221. CString m_sBaseEnterpriseOID;
  222. CString m_sSupportedView;
  223. CString m_sTracefileName;
  224. DWORD m_dwTraceLevel;
  225. // Data members for the "limit" section of the settings dialog
  226. struct {
  227. BOOL m_bTrimFlag; // Limit trap length
  228. BOOL m_bTrimMessages; // Trim messages first
  229. DWORD m_dwMaxTrapSize; // Trap length (bytes)
  230. }m_trapsize;
  231. // Data members for the "throttle" section of the settings dialog
  232. struct {
  233. long m_nTraps;
  234. long m_nSeconds;
  235. BOOL m_bIsEnabled;
  236. }m_throttle;
  237. };
  238. class CTrapReg
  239. {
  240. public:
  241. CTrapReg();
  242. ~CTrapReg();
  243. SCODE Connect(LPCTSTR pszComputerName, BOOL bIsReconnecting = FALSE);
  244. SCODE Serialize();
  245. SCODE Deserialize();
  246. SCODE LockRegistry();
  247. void UnlockRegistry();
  248. SCODE SetConfigType(DWORD dwConfigType);
  249. DWORD GetConfigType() {return m_dwConfigType; }
  250. void SetApplyButton(CButton *pbtnApply) { m_pbtnApply = pbtnApply; }
  251. void SetDirty(BOOL bDirty);
  252. inline BOOL SourceHasTraps(CString& sSource);
  253. // Public data members.
  254. CRegistryKey m_regkeySource; // SYSTEM\CurrentControlSet\Services\EventLogs
  255. CRegistryKey m_regkeySnmp; // SOFTWARE\Microsoft\SNMP_EVENTS
  256. CRegistryKey m_regkeyEventLog;
  257. CXEventLogArray m_aEventLogs;
  258. CTrapParams m_params;
  259. CDlgSaveProgress* m_pdlgSaveProgress;
  260. CDlgSaveProgress* m_pdlgLoadProgress;
  261. LONG m_nLoadStepsPerSource;
  262. LONG m_nLoadStepsPerLog;
  263. LONG m_nLoadSteps;
  264. BOOL m_bShowConfigTypeBox;
  265. BOOL m_bRegIsReadOnly;
  266. BOOL m_bIsDirty;
  267. BOOL m_bSomeMessageWasNotFound;
  268. CString m_sComputerName;
  269. CButton *m_pbtnApply;
  270. private:
  271. LONG GetSaveProgressStepCount();
  272. SCODE BuildSourceHasTrapsMap();
  273. BOOL m_bNeedToCloseKeys;
  274. CMapStringToPtr m_mapSourceHasTraps;
  275. BOOL m_bDidLockRegistry;
  276. DWORD m_dwConfigType;
  277. };
  278. extern CTrapReg g_trapreg;
  279. enum {
  280. CONFIG_TYPE_DEFAULT = 0,
  281. CONFIG_TYPE_CUSTOM,
  282. CONFIG_TYPE_DEFAULT_PENDING
  283. };
  284. // Error failure values.
  285. enum
  286. {
  287. E_REGKEY_NOT_FOUND = -1000,
  288. E_REG_CANT_CONNECT,
  289. E_REGKEY_NOT_INSTALLED,
  290. E_REGKEY_CANT_OPEN,
  291. E_REGKEY_NO_CREATE,
  292. E_REG_NOT_INSTALLED,
  293. E_REGKEY_LOST_CONNECTION,
  294. E_ACCESS_DENIED,
  295. E_MESSAGE_NOT_FOUND
  296. };
  297. // Success status codes
  298. enum
  299. {
  300. S_NO_EVENTS = 1000,
  301. S_NO_SOURCES,
  302. S_SAVE_CANCELED,
  303. S_LOAD_CANCELED
  304. };
  305. //*******************************************************************
  306. // CTrapReg::SourceHasTraps
  307. //
  308. // Check to see if traps have been configured for the specified event
  309. // source.
  310. //
  311. // Parameters:
  312. // CString& sEventSource
  313. // The name of the event source.
  314. //
  315. // Returns:
  316. // TRUE if the event source has traps, FALSE otherwise.
  317. //
  318. //********************************************************************
  319. inline BOOL CTrapReg::SourceHasTraps(CString& sEventSource)
  320. {
  321. LPVOID pVoid;
  322. CString tmp(sEventSource);
  323. tmp.MakeUpper();
  324. return m_mapSourceHasTraps.Lookup(tmp, pVoid);
  325. }
  326. #endif //_trapreg_h