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.

306 lines
8.6 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_PARSER_H
  5. #define SIMC_PARSER_H
  6. /* This file contains the SIMCParse class, which is the parsing engine
  7. * for parsing MIB files, and it works with the SIMCScanner class, which
  8. * is the tokenizing engine
  9. */
  10. /*
  11. * The SIMCParser class is derived form the yy_parse class that is
  12. * generated by the MKS YACC utility, using the information
  13. * provided in the yacc.y file. This uses the class SIMCScanner as its
  14. * scanner. SIMCScanner is derived form the class yy_scan that is generated
  15. * by the MKS LEX utility, using the information provided by the lex.l
  16. * file.
  17. * This uses 2 dlls "smierrsy.dll" and "smierrsm.dll" to hold the
  18. * strings that represent the syntax errors and semantic errors
  19. * respectively.
  20. * It uses an SIMCErrorContainer object to put the error messages, it
  21. * generates.
  22. * It put the parse information generated for a single parse, info
  23. * an SIMCModule object.
  24. * It "knows" about the commonly occuring SMI symbols, like "ip",
  25. * "transmission" etc., as defined in the "compiler requirements spec".
  26. */
  27. class SIMCParser : public yy_parse
  28. {
  29. // The size of the buffer used to construct an error message
  30. static const int MESSAGE_SIZE;
  31. // The lowest syntax error Id
  32. static const int SYNTAX_ERROR_BASE;
  33. // The lowest parser semantic error Id
  34. static const int SEMANTIC_ERROR_BASE;
  35. // The text for the various severity levels enumerated by
  36. // enum severityLevel
  37. static const char * const severityLevels[];
  38. // The place to put the error messages
  39. SIMCErrorContainer *_errorContainer;
  40. // The information collected from the module
  41. SIMCModule * _module;
  42. // The flag that is used to decide whether to parse the next module as
  43. // a V1 or a V2 one. Used by Parse()
  44. int _snmpVersion;
  45. // Used to set those pesky references that are initially beleived to be forward
  46. // references, but actually are references to imported symbols.
  47. BOOL SetImportSymbols();
  48. // A count of errors, for each call of Parse()
  49. long _fatalCount, _warningCount, _informationCount;
  50. public:
  51. // The resource-only dll with parser error text string table
  52. static HINSTANCE semanticErrorsDll;
  53. // The resource-only dll with syntax error text string table
  54. static HINSTANCE syntaxErrorsDll;
  55. // You always need an error container and a scanner, to parse
  56. SIMCParser(SIMCErrorContainer * errorContainer, SIMCScanner * scanner);
  57. virtual ~SIMCParser();
  58. // The names of the dlls
  59. static const char * const semanticErrorsDllFile;
  60. static const char * const syntaxErrorsDllFile;
  61. // The scanner associated with this parser
  62. SIMCScanner *_theScanner;
  63. // ---------------- The symbols known by the parser ---------------------
  64. SIMCModule *other, // Modules common to V1 and V2
  65. *rfc1155, // These are V1 only
  66. *rfc1213,
  67. *rfc1212,
  68. *rfc1215,
  69. *rfc1230,
  70. *rfc1902, // These are V2 only
  71. *rfc1903,
  72. *rfc1904,
  73. *rfc1906;
  74. SIMCSymbol **objectIdentifierType, // These are primitive ASN.1 types
  75. **integerType,
  76. **octetStringType,
  77. **nullType,
  78. **bitsType,
  79. **booleanType;
  80. SIMCSymbol // These are V1 OIDs
  81. **isoV1,
  82. **ccittV1,
  83. **jointIsoCcittV1,
  84. **internetV1,
  85. **directoryV1,
  86. **mgmtV1,
  87. **experimentalV1,
  88. **privateV1,
  89. **enterprisesV1,
  90. **mib2V1,
  91. **ipV1,
  92. **interfacesV1,
  93. **transmissionV1,
  94. **zeroDotZeroV2,
  95. **orgV2, // These are V2 OIDs
  96. **dodV2,
  97. **internetV2,
  98. **directoryV2,
  99. **mgmtV2,
  100. **mib2V2,
  101. **ipV2,
  102. **interfacesV2,
  103. **transmissionV2,
  104. **experimentalV2,
  105. **privateV2,
  106. **enterprisesV2,
  107. **securityV2,
  108. **snmpV2V2,
  109. **snmpDomainsV2,
  110. **snmpProxysV2,
  111. **snmpModulesV2,
  112. **snmpUDPDomainV2,
  113. **snmpCLNSDomainV2,
  114. **snmpCONSDomainV2,
  115. **snmpDDPDomainV2,
  116. **snmpIPXDomainV2,
  117. **rfc1157DomainV2,
  118. **rfc1157ProxyV2;
  119. SIMCSymbol **trueValueReference, // Some values
  120. **falseValueReference,
  121. **nullValueReference;
  122. // Symbols for the severity levels of the messages
  123. enum SeverityLevel
  124. {
  125. INVALID,
  126. FATAL,
  127. WARNING,
  128. INFORMATION
  129. };
  130. // Manipulate the SNMP version of this parser. Parsing is done based
  131. // on this value, as follows
  132. // 1 - SNMPv2 SMI
  133. // 2 - SNMPv2 SMI
  134. // 0 - Union of V1 and V2 SMIs
  135. int GetSnmpVersion() const
  136. {
  137. return _snmpVersion;
  138. }
  139. BOOL SetSnmpVersion( int x )
  140. {
  141. switch(x)
  142. {
  143. case 0: // '0' means union of v1 and v2 SMIs
  144. case 1:
  145. case 2:
  146. _snmpVersion = x;
  147. return TRUE;
  148. default:
  149. _snmpVersion = 0;
  150. return FALSE;
  151. }
  152. }
  153. /*
  154. * The main parsing function that is called by the user
  155. * Return TRUE if the parse is successful. The GetModule() function
  156. * may then be called to retrieve the parsed information.
  157. * It it returns false, check the error container for error
  158. * messages
  159. */
  160. BOOL Parse();
  161. // A function to generate syntax error messages
  162. void SyntaxError(int errorType,
  163. int lineNo = -1,
  164. int columnNo = -1,
  165. char *lastToken = NULL, char *infoString = NULL);
  166. // Convert severity level to "readable" form
  167. const char * const GetSeverityString(int severityLevel)
  168. {
  169. return severityLevels[severityLevel];
  170. }
  171. // A function to generate semantic error messages
  172. void SemanticError(const char * const fileName, int errorType,
  173. int lineNo,
  174. int columnNo,
  175. ...);
  176. // Get the parsed information, after a successful call to Parse()
  177. SIMCModule * GetModule() const;
  178. void SetErrorContainer(SIMCErrorContainer *errorContainer)
  179. {
  180. if(errorContainer)
  181. _errorContainer = errorContainer;
  182. }
  183. SIMCErrorContainer * GetErrorContainer() const
  184. {
  185. return _errorContainer;
  186. }
  187. void SetScanner( SIMCScanner * scanner)
  188. {
  189. _theScanner = scanner;
  190. }
  191. /*
  192. * Utility functions that are used in Parse(), and also
  193. * can be used by the user of this class.
  194. *
  195. */
  196. // TRUE, if the symbol specified, is viewed as a symbol
  197. // "known" to the parser, from the module specified, as per
  198. // SNMPV1 SMI rules
  199. static BOOL IsReservedSymbolV1(const char *const name,
  200. const char * const moduleName);
  201. // Returns the module in which this "known" symbol is defined, as
  202. // per the SNMPV1 SMI. Return null if the symbol is "unknown"
  203. const SIMCModule* IsReservedSymbolV1(const char * const symbolName);
  204. // TRUE, if the symbol specified, is viewed as a symbol
  205. // "known" to the parser, from the module specified, as per
  206. // SNMPV2 SMI rules
  207. static BOOL IsReservedSymbolV2(const char *const name,
  208. const char * const moduleName);
  209. // Returns the module in which this "known" symbol is defined, as
  210. // per the SNMPV2 SMI. Return null if the symbol is "unknown"
  211. const SIMCModule* IsReservedSymbolV2(const char * const symbolName);
  212. // Another way of using the above functions
  213. const SIMCModule* IsReservedSymbol(const char * const symbolName);
  214. BOOL IsReservedSymbol(const char *const name, const char * const moduleName);
  215. static BOOL IsReservedSymbol(long snmpVersion, const char *const name,
  216. const char * const moduleName);
  217. // TRUE, if the module specified, is viewed as a module
  218. // "known" to the parser, as per SNMPV1 SMI rules
  219. static BOOL IsReservedModuleV1(const char *const name);
  220. // TRUE, if the module specified, is viewed as a module
  221. // "known" to the parser, as per SNMPV2 SMI rules
  222. static BOOL IsReservedModuleV2(const char *const name);
  223. // Another way of using the above functions
  224. static BOOL IsReservedModule(long snmpVersion, const char *const name);
  225. // Used in error-tolerance. Never called by the user
  226. static const char * GetCorrectModuleNames(const char * const symbolName);
  227. // Helper functions
  228. void DoImportModule( SIMCModule *mainModule, SIMCModule *importModule);
  229. void CreateReservedModules();
  230. void RemoveExtraneousReservedModule(SIMCModule *module);
  231. // Generate a unique name of the form "*n" for an anonymnous symbol.
  232. // n is an integer
  233. char * GenerateSymbolName()
  234. {
  235. static long n = 1;
  236. char buf[25];
  237. buf[0] = '*';
  238. sprintf(buf+1, "%ld", n++);
  239. return NewString(buf);
  240. }
  241. long GetFatalCount() const
  242. {
  243. return _fatalCount;
  244. }
  245. long GetWarningCount() const
  246. {
  247. return _warningCount;
  248. }
  249. long GetInformationCount() const
  250. {
  251. return _informationCount;
  252. }
  253. };
  254. #endif // SIMC_PARSER_H