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.

259 lines
6.4 KiB

  1. #include <stdafx.h>
  2. #include "Errors.h"
  3. #include "Parser.h"
  4. #include "Registry.h"
  5. #include "EventCmd.h"
  6. COperation::COperation(tOperation operation)
  7. {
  8. m_Operation = operation;
  9. m_pNextOperation = NULL;
  10. }
  11. COperation::~COperation()
  12. {
  13. if (m_pNextOperation)
  14. delete m_pNextOperation;
  15. }
  16. COperation* COperation::Insert(COperation *pOperation)
  17. {
  18. if (pOperation->m_Operation < m_Operation)
  19. {
  20. pOperation->m_pNextOperation = this;
  21. return pOperation;
  22. }
  23. if (m_pNextOperation == NULL)
  24. m_pNextOperation = pOperation;
  25. else
  26. m_pNextOperation = m_pNextOperation->Insert(pOperation);
  27. return this;
  28. }
  29. COperation* COperation::GetNextOp()
  30. {
  31. return m_pNextOperation;
  32. }
  33. DWORD COperation::CheckedStrToDword(DWORD & dwDword, char *szDword)
  34. {
  35. dwDword = 0;
  36. while (*szDword != '\0')
  37. {
  38. if (*szDword < '0' || *szDword > '9')
  39. return ERROR_BAD_FORMAT;
  40. dwDword *= 10;
  41. dwDword += (*szDword++ - '0');
  42. }
  43. return ERROR_SUCCESS;
  44. }
  45. COpEvents::COpEvents(tOperation operation) : COperation(operation)
  46. {
  47. m_szEventSource = NULL;
  48. m_dwEventID = 0;
  49. m_dwCount = 1;
  50. m_dwTime = 0;
  51. }
  52. COpEvents::~COpEvents()
  53. {
  54. if (m_szEventSource != NULL)
  55. delete m_szEventSource;
  56. }
  57. DWORD COpEvents::ParseCmdArgs()
  58. {
  59. DWORD retCode;
  60. char szToken[INPUT_TOKEN_SZ];
  61. if ((retCode = gParser.GetNextToken(szToken, INPUT_TOKEN_SZ)) != ERROR_SUCCESS ||
  62. (retCode = gParser.CheckUnGetToken(KEYWORD_PRAGMA, szToken)) != ERROR_SUCCESS)
  63. {
  64. _W(WARN_ALERT, IDS_ALRT_WRN16,
  65. gParser.m_nLineNo,
  66. gParser.m_nTokenNo);
  67. return retCode;
  68. }
  69. if ((retCode = gParser.GetNextToken(szToken, INPUT_TOKEN_SZ)) != ERROR_SUCCESS ||
  70. (retCode = gParser.CheckUnGetToken(KEYWORD_PRAGMA, szToken)) != ERROR_SUCCESS)
  71. {
  72. _W(WARN_ALERT, IDS_ALRT_WRN17,
  73. gParser.m_nLineNo,
  74. gParser.m_nTokenNo);
  75. return retCode;
  76. }
  77. if (m_szEventSource != NULL)
  78. delete m_szEventSource;
  79. m_szEventSource = new char[sizeof(szToken) + 1];
  80. strcpy(m_szEventSource, szToken);
  81. if ((retCode = gParser.GetNextToken(szToken, INPUT_TOKEN_SZ)) != ERROR_SUCCESS ||
  82. (retCode = gParser.CheckUnGetToken(KEYWORD_PRAGMA, szToken)) != ERROR_SUCCESS ||
  83. (retCode = CheckedStrToDword(m_dwEventID, szToken)) != ERROR_SUCCESS)
  84. {
  85. _W(WARN_ALERT, IDS_ALRT_WRN18,
  86. gParser.m_nLineNo,
  87. gParser.m_nTokenNo);
  88. return retCode;
  89. }
  90. if ((retCode = gParser.GetNextToken(szToken, INPUT_TOKEN_SZ)) == ERROR_SUCCESS)
  91. {
  92. if (gParser.CheckUnGetToken(KEYWORD_PRAGMA, szToken) != ERROR_SUCCESS)
  93. goto done;
  94. if ((retCode = CheckedStrToDword(m_dwCount, szToken)) != ERROR_SUCCESS)
  95. {
  96. _W(WARN_ALERT, IDS_ALRT_WRN19,
  97. gParser.m_nLineNo,
  98. gParser.m_nTokenNo);
  99. return retCode;
  100. }
  101. }
  102. if ((retCode = gParser.GetNextToken(szToken, INPUT_TOKEN_SZ)) == ERROR_SUCCESS)
  103. {
  104. if (gParser.CheckUnGetToken(KEYWORD_PRAGMA, szToken) != ERROR_SUCCESS)
  105. goto done;
  106. if ((retCode = CheckedStrToDword(m_dwTime, szToken)) != ERROR_SUCCESS)
  107. {
  108. _W(WARN_ALERT, IDS_ALRT_WRN20,
  109. gParser.m_nLineNo,
  110. gParser.m_nTokenNo);
  111. return retCode;
  112. }
  113. }
  114. if (m_dwCount <= 1 && m_dwTime > 0)
  115. {
  116. _W(WARN_ALERT, IDS_ALRT_WRN21,
  117. gParser.m_nLineNo,
  118. gParser.m_nTokenNo,
  119. m_dwTime);
  120. m_dwTime = 0;
  121. }
  122. if (m_dwCount >= 2 && m_dwTime == 0)
  123. {
  124. _W(WARN_ALERT, IDS_ALRT_WRN22,
  125. gParser.m_nLineNo,
  126. gParser.m_nTokenNo,
  127. m_dwCount,
  128. m_dwTime);
  129. }
  130. done:
  131. retCode = ERROR_SUCCESS;
  132. if (m_dwCount >= 2 && m_dwTime == 0)
  133. m_dwTime = 1;
  134. _W(WARN_ATTENTION, IDS_ALRT_WRN23,
  135. m_Operation == OP_ADD_EVENT ? "ADD" : "DELETE",
  136. m_szEventSource,
  137. m_dwEventID,
  138. m_dwCount,
  139. m_dwTime);
  140. return retCode;
  141. };
  142. DWORD COpEvents::ProcessCommand()
  143. {
  144. DWORD retCode;
  145. switch(m_Operation)
  146. {
  147. case OP_ADD_EVENT:
  148. retCode = gRegistry.AddEvent(m_szEventSource, m_dwEventID, m_dwCount, m_dwTime);
  149. break;
  150. case OP_DEL_EVENT:
  151. retCode = gRegistry.DelEvent(m_szEventSource, m_dwEventID);
  152. break;
  153. default:
  154. return _E(ERROR_INTERNAL_ERROR, IDS_ERR02, m_Operation);
  155. }
  156. return retCode;
  157. }
  158. COpTraps::COpTraps(tOperation operation) : COperation(operation)
  159. {
  160. m_szCommunity = NULL;
  161. m_szAddress = NULL;
  162. }
  163. COpTraps::~COpTraps()
  164. {
  165. if (m_szCommunity != NULL)
  166. delete m_szCommunity;
  167. if (m_szAddress != NULL)
  168. delete m_szAddress;
  169. }
  170. DWORD COpTraps::ParseCmdArgs()
  171. {
  172. DWORD retCode;
  173. char szToken[INPUT_TOKEN_SZ];
  174. if ((retCode = gParser.GetNextToken(szToken, INPUT_TOKEN_SZ)) != ERROR_SUCCESS ||
  175. (retCode = gParser.CheckUnGetToken(KEYWORD_PRAGMA, szToken)) != ERROR_SUCCESS)
  176. {
  177. _W(WARN_ALERT, IDS_ALRT_WRN24,
  178. gParser.m_nLineNo,
  179. gParser.m_nTokenNo);
  180. return retCode;
  181. }
  182. if (m_szCommunity != NULL)
  183. delete m_szCommunity;
  184. m_szCommunity = new char[strlen(szToken)+1];
  185. if (m_szCommunity == NULL)
  186. return _E(ERROR_OUTOFMEMORY, IDS_ERR01);
  187. strcpy(m_szCommunity, szToken);
  188. if ((retCode = gParser.GetNextToken(szToken, INPUT_TOKEN_SZ)) != ERROR_SUCCESS ||
  189. (retCode = gParser.CheckUnGetToken(KEYWORD_PRAGMA, szToken)) != ERROR_SUCCESS)
  190. {
  191. _W(WARN_ALERT, IDS_ALRT_WRN25,
  192. gParser.m_nLineNo,
  193. gParser.m_nTokenNo);
  194. }
  195. if (m_szAddress != NULL)
  196. delete m_szAddress;
  197. m_szAddress = new char [strlen(szToken) + 1];
  198. if (m_szAddress == NULL)
  199. return _E(ERROR_OUTOFMEMORY, IDS_ERR01);
  200. strcpy(m_szAddress, szToken);
  201. _W(WARN_ATTENTION, IDS_ATTN_WRN26,
  202. m_Operation == OP_ADD_TRAP ? "ADD_TRAP_DEST" : "DELETE_TRAP_DEST",
  203. m_szCommunity,
  204. m_szAddress);
  205. return ERROR_SUCCESS;
  206. }
  207. DWORD COpTraps::ProcessCommand()
  208. {
  209. DWORD retCode;
  210. switch(m_Operation)
  211. {
  212. case OP_ADD_TRAP:
  213. retCode = gRegistry.AddTrap(m_szCommunity, m_szAddress);
  214. break;
  215. case OP_DEL_TRAP:
  216. retCode = gRegistry.DelTrap(m_szCommunity, m_szAddress);
  217. break;
  218. default:
  219. return _E(ERROR_INTERNAL_ERROR, IDS_ERR03, m_Operation);
  220. }
  221. return retCode;
  222. }