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.

526 lines
15 KiB

  1. //
  2. // Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
  3. //
  4. #ifndef SIMC_MODULE_H
  5. #define SIMC_MODULE_H
  6. /* This file contains the SIMCModule class, which basically
  7. * represents the parse tree for a single module.
  8. */
  9. // Return value for many of the symbol-table methods.
  10. #define NOT_FOUND 0
  11. #define AMBIGUOUS 1
  12. #define UNAMBIGUOUS 2
  13. class SIMCSymbol;
  14. class SIMCType;
  15. class SIMCSubType;
  16. class SIMCEnumOrBitsType;
  17. class SIMCValue;
  18. class SIMCOidValue;
  19. class SIMCOctetStringValue;
  20. class SIMCDefinedTypeReference;
  21. class SIMCDefinedValueReference;
  22. class SIMCBuiltInTypeReference;
  23. class SIMCBuiltInValueReference;
  24. class SIMCObjectTypeType;
  25. class SIMCObjectTypeV1;
  26. class SIMCObjectTypeV2;
  27. class SIMCObjectIdentityType;
  28. class SIMCObjectGroup;
  29. class SIMCOidTree;
  30. class SIMCParseTree;
  31. // Some typedefs
  32. #ifndef SIMC_GROUP_LIST
  33. #define SIMC_GROUP_LIST
  34. typedef CList<SIMCObjectGroup *, SIMCObjectGroup*> SIMCGroupList;
  35. ostream& operator << (ostream& outStream, const SIMCGroupList& obj);
  36. #endif
  37. typedef CList<SIMCModule *, SIMCModule *> SIMCModuleList;
  38. typedef CList<CString, const CString&> SIMCModuleNameList;
  39. typedef CMap <CString, LPCSTR, SIMCSymbol **, SIMCSymbol**>
  40. SIMCSymbolTable;
  41. /* Each element in the list of revision clauses
  42. * in the MODULE-IDENTITY macro
  43. */
  44. class SIMCRevisionElement
  45. {
  46. char *_revision, *_description;
  47. public:
  48. SIMCRevisionElement( const char * revision, const char * description)
  49. {
  50. if(revision)
  51. _revision = NewString(revision);
  52. else
  53. _revision = NULL;
  54. if(description)
  55. _description = NewString(description);
  56. else
  57. _description = NULL;
  58. }
  59. ~SIMCRevisionElement()
  60. {
  61. if(_revision)
  62. delete _revision;
  63. if(_description)
  64. delete _description;
  65. }
  66. const char * GetRevision() const
  67. {
  68. return _revision;
  69. }
  70. const char * GetDescription() const
  71. {
  72. return _description;
  73. }
  74. };
  75. // A list of revision clauses
  76. typedef CList<SIMCRevisionElement *, SIMCRevisionElement *> SIMCRevisionList;
  77. /*
  78. * This class represents the parse tree information that results from the
  79. * parsing of a single MIB module. It basically contains.
  80. *
  81. * 1. A symbol table, for all the symbols in the module
  82. * 2. The values of various MODULE-IDENTITY clauses. These are
  83. * fabricated, if the MODULE-IDENTITY clause is absent in the module
  84. * 3. A list of object groups that are fabricated for this module, as per
  85. * the rules in the "compiler requirements specification"
  86. */
  87. class SIMCModule : public SIMCSymbol
  88. {
  89. // The version of this module
  90. // 1 - SNMPv2 SMI
  91. // 2 - SNMPv2 SMI
  92. // 0 - Union of V1 and V2 SMIs
  93. int _snmpVersion;
  94. // The items from the MODULE-IDENTITY macro
  95. char * _lastUpdated;
  96. char * _organization;
  97. char * _contactInfo;
  98. char * _moduleIdentityName;
  99. char * _description;
  100. SIMCRevisionList _revisionList;
  101. SIMCCleanOidValue * _moduleIdentityValue;
  102. // This is null if it is the main input module, otherwise it points
  103. // to the module that imported this module
  104. SIMCModule * _parentModule;
  105. // The names of the modules in the IMPORTS clause
  106. SIMCModuleNameList _namesOfImportModules;
  107. // The actual import modules
  108. SIMCModuleList *_listOfImportModules;
  109. // The Symbol table
  110. SIMCSymbolTable *_symbolTable;
  111. // A value for the hash table (CMap) object that optimizes
  112. // its working
  113. static const int SYMBOLS_PER_MODULE;
  114. // The fabricated list OBJECT-GROUPS
  115. SIMCGroupList *_listOfObjectGroups;
  116. // All the NOTIFICATION-TYPEs in the module
  117. SIMCNotificationList *_listOfNotificationTypes;
  118. // Name of the file from which this was constructed
  119. char *_inputFileName;
  120. public:
  121. // Used in RTTIing a SIMCSymbol pointer
  122. enum SymbolClass
  123. {
  124. SYMBOL_INVALID,
  125. SYMBOL_UNKNOWN,
  126. SYMBOL_IMPORT,
  127. SYMBOL_MODULE,
  128. SYMBOL_BUILTIN_TYPE_REF,
  129. SYMBOL_DEFINED_TYPE_REF,
  130. SYMBOL_TEXTUAL_CONVENTION,
  131. SYMBOL_BUILTIN_VALUE_REF,
  132. SYMBOL_DEFINED_VALUE_REF
  133. };
  134. // Used in RTTIing a SIMCType pointer
  135. enum TypeClass
  136. {
  137. TYPE_INVALID,
  138. TYPE_PRIMITIVE,
  139. TYPE_RANGE,
  140. TYPE_SIZE,
  141. TYPE_ENUM_OR_BITS,
  142. TYPE_SEQUENCE_OF,
  143. TYPE_SEQUENCE,
  144. TYPE_TRAP_TYPE,
  145. TYPE_NOTIFICATION_TYPE,
  146. TYPE_OBJECT_TYPE_V1,
  147. TYPE_OBJECT_TYPE_V2,
  148. TYPE_OBJECT_IDENTITY
  149. };
  150. // Used in RTTIing a SIMCValue pointer
  151. enum ValueClass
  152. {
  153. VALUE_INVALID,
  154. VALUE_INTEGER,
  155. VALUE_OID,
  156. VALUE_OCTET_STRING,
  157. VALUE_BOOLEAN,
  158. VALUE_BITS,
  159. VALUE_NULL
  160. };
  161. enum PrimitiveType
  162. {
  163. PRIMITIVE_INVALID,
  164. PRIMITIVE_INTEGER,
  165. PRIMITIVE_OID,
  166. PRIMITIVE_OCTET_STRING,
  167. PRIMITIVE_BOOLEAN,
  168. PRIMITIVE_BITS,
  169. PRIMITIVE_NULL,
  170. PRIMITIVE_NETWORK_ADDRESS,
  171. PRIMITIVE_IP_ADDRESS,
  172. PRIMITIVE_COUNTER,
  173. PRIMITIVE_GAUGE,
  174. PRIMITIVE_TIME_TICKS,
  175. PRIMITIVE_OPAQUE,
  176. PRIMITIVE_DISPLAY_STRING,
  177. PRIMITIVE_PHYS_ADDRESS,
  178. PRIMITIVE_MAC_ADDRESS,
  179. PRIMITIVE_INTEGER_32,
  180. PRIMITIVE_COUNTER_32,
  181. PRIMITIVE_GAUGE_32,
  182. PRIMITIVE_COUNTER_64,
  183. PRIMITIVE_UNSIGNED_32,
  184. PRIMITIVE_DATE_AND_TIME,
  185. PRIMITIVE_SNMP_UDP_ADDRESS,
  186. PRIMITIVE_SNMP_OSI_ADDRESS,
  187. PRIMITIVE_SNMP_IPX_ADDRESS
  188. };
  189. SIMCModule(const char *const moduleName = NULL,
  190. const char * const inputFileName = NULL,
  191. SIMCSymbolTable *symbolTable = NULL,
  192. SIMCModuleList *listOfImportModules = NULL,
  193. SIMCModule *parentModule = NULL,
  194. int snmpVersion = 0,
  195. long lineNumber = 0, long columnNumber = 0,
  196. long referenceCount = 0);
  197. virtual ~SIMCModule();
  198. // Manipulate the SNMP version of the module
  199. int GetSnmpVersion() const
  200. {
  201. return _snmpVersion;
  202. }
  203. BOOL SetSnmpVersion( int x )
  204. {
  205. switch(x)
  206. {
  207. case 0: // '0' means union of v1 and v2 SMIs
  208. case 1:
  209. case 2:
  210. _snmpVersion = x;
  211. return TRUE;
  212. default:
  213. _snmpVersion = 0;
  214. return FALSE;
  215. }
  216. }
  217. // Manipulate the name of this module
  218. const char * GetModuleName() const
  219. {
  220. return GetSymbolName();
  221. }
  222. void SetModuleName(const char * const s)
  223. {
  224. SetSymbolName(s);
  225. }
  226. // Manipulate the input file name of this module
  227. const char * GetInputFileName() const
  228. {
  229. return _inputFileName;
  230. }
  231. void SetInputFileName(const char * const s)
  232. {
  233. if(_inputFileName)
  234. delete []_inputFileName;
  235. _inputFileName = NewString(s);
  236. }
  237. // Manipulate the MODULE-IDENTITY clauses
  238. const char * GetLastUpdated() const
  239. {
  240. return _lastUpdated;
  241. }
  242. void SetLastUpdated(const char * const s)
  243. {
  244. if(_lastUpdated)
  245. delete [] _lastUpdated;
  246. _lastUpdated = NewString(s);
  247. }
  248. const char * GetOrganization() const
  249. {
  250. return _organization;
  251. }
  252. void SetOrganization(const char * const s)
  253. {
  254. if(_organization)
  255. delete [] _organization;
  256. _organization = NewString(s);
  257. }
  258. const char * GetContactInfo() const
  259. {
  260. return _contactInfo;
  261. }
  262. void SetContactInfo(const char * const s)
  263. {
  264. if(_contactInfo)
  265. delete [] _contactInfo;
  266. _contactInfo = NewString(s);
  267. }
  268. const char * GetDescription() const
  269. {
  270. return _description;
  271. }
  272. void SetDescription(const char * const s)
  273. {
  274. if(_description)
  275. delete [] _description;
  276. _description = NewString(s);
  277. }
  278. void AddRevisionClause(SIMCRevisionElement *revisionElement)
  279. {
  280. _revisionList.AddTail(revisionElement);
  281. }
  282. const SIMCRevisionList * GetRevisionList() const
  283. {
  284. return &_revisionList;
  285. }
  286. const char * GetModuleIdentityName() const
  287. {
  288. return _moduleIdentityName;
  289. }
  290. void SetModuleIdentityName(const char * const s)
  291. {
  292. if(_moduleIdentityName)
  293. delete [] _moduleIdentityName;
  294. _moduleIdentityName = NewString(s);
  295. }
  296. void SetModuleIdentityValue(SIMCCleanOidValue * value)
  297. {
  298. if(_moduleIdentityValue)
  299. delete _moduleIdentityValue;
  300. _moduleIdentityValue = value;
  301. }
  302. BOOL GetModuleIdentityValue( SIMCCleanOidValue& retVal) const
  303. {
  304. if( _moduleIdentityValue )
  305. {
  306. CleanOidValueCopy(retVal, *_moduleIdentityValue);
  307. return TRUE;
  308. }
  309. else
  310. return FALSE;
  311. }
  312. // Get the whole symbol table itself. Very rarely used
  313. SIMCSymbolTable* GetSymbolTable() const
  314. {
  315. return _symbolTable;
  316. }
  317. // Get the list of import modules
  318. SIMCModuleList *GetListOfImportModules() const
  319. {
  320. return _listOfImportModules;
  321. }
  322. // Get the names of the import modules
  323. const SIMCModuleNameList* GetImportModuleNameList() const
  324. {
  325. return &_namesOfImportModules;
  326. }
  327. // If this module is created just because it appears in the
  328. // IMPORT clause of a parent module, then a pointer to the parent
  329. // module is returned. This has to be set by the user, of course
  330. const SIMCModule* GetParentModule() const
  331. {
  332. return _parentModule;
  333. }
  334. void SetParentModule( SIMCModule *parentModule);
  335. // Manipulate the list of import modules of this module
  336. void AddImportModule( SIMCModule * newModule);
  337. BOOL RemoveImportModule(SIMCModule *module);
  338. // This just adds to _namesOfImportModules
  339. void AddImportModuleName(const SIMCModule *newModule)
  340. {
  341. _namesOfImportModules.AddTail(newModule->GetModuleName());
  342. }
  343. SIMCModule *GetImportModule(const char * const name) const;
  344. // Manipulate the list of object groups of this module
  345. void AddObjectGroup(SIMCObjectGroup *group);
  346. // Gets the object group whose name is the speciified name
  347. SIMCObjectGroup *GetObjectGroup(const char * const name) const;
  348. SIMCGroupList *GetObjectGroupList() const
  349. {
  350. return _listOfObjectGroups;
  351. }
  352. // Returns the object group in which this symbol is present
  353. SIMCObjectGroup *GetObjectGroup(SIMCSymbol *symbol) const;
  354. // Manipulate the list of NOTIFICATION-TYPES in this module
  355. SIMCNotificationList *GetNotificationTypeList() const
  356. {
  357. return _listOfNotificationTypes;
  358. }
  359. // A debugging function
  360. virtual void WriteSymbol(ostream& outStream) const;
  361. //-------------SYMBOL TABLE RELATED METHODS ----------------------
  362. SIMCSymbol ** GetSymbol( const char * const symbolName) const;
  363. int GetImportedSymbol( const char * const symbolName, SIMCSymbol ** &retVal1,
  364. SIMCSymbol ** &retVal2) const;
  365. BOOL AddSymbol(SIMCSymbol * );
  366. BOOL RemoveSymbol(const char * const symbolName);
  367. BOOL RemoveSymbol(SIMCSymbol **);
  368. BOOL ReplaceSymbol(const char *const symbolName, SIMCSymbol *newSymbol);
  369. //------------ RTTI methods(static)------------------------------------
  370. static SymbolClass GetSymbolClass(SIMCSymbol **spp);
  371. static TypeClass GetTypeClass(SIMCType *t);
  372. static ValueClass GetValueClass(SIMCValue *v);
  373. //-------------- Methods used in semantic checking and resolution -----
  374. // These set the state of each symbol to one ofenum SIMCResolutionStatus
  375. // RESOLVE_UNSET, // Haven't resolved it yet
  376. // RESOLVE_UNDEFINED, // Could not resolve it
  377. // RESOLVE_IMPORT, // Resolved to IMPORTS
  378. // RESOLVE_CORRECT // Resolved properly
  379. // as defined in enum SIMCResolutionStatus, of SIMCSymbol
  380. BOOL SetResolutionStatus();
  381. static SIMCResolutionStatus SetResolutionStatus(SIMCSymbol **symbol);
  382. static SIMCResolutionStatus SetResolutionStatus(SIMCDefinedTypeReference * orig);
  383. static SIMCResolutionStatus SetResolutionStatus(SIMCDefinedValueReference *orig);
  384. private:
  385. // These are the recursive routines called by the above 2 methods
  386. static SIMCResolutionStatus SetResolutionStatusRec(SIMCDefinedTypeReference * orig,
  387. SIMCDefinedTypeReferenceList& checkedList);
  388. static SIMCResolutionStatus SetResolutionStatusRec(SIMCDefinedValueReference *orig,
  389. SIMCDefinedValueReferenceList& checkedList);
  390. public:
  391. // This sets the type that is the root of a subtype (range and size
  392. // constructs) or an ENUM or BITS type, and also the root value of a symbol that results from
  393. // successive assignment statements
  394. BOOL SetRootAll();
  395. static SIMCResolutionStatus SetRootSymbol(SIMCSymbol **symbol);
  396. static SIMCResolutionStatus SetRootSubType(SIMCSubType *s);
  397. private:
  398. static SIMCResolutionStatus SetRootSubTypeRec(SIMCSubType *s,
  399. SIMCSubTypeList& checkedList);
  400. static SIMCResolutionStatus SetRootEnumOrBitsRec(SIMCEnumOrBitsType *t,
  401. SIMCSubTypeList& checkedList);
  402. public:
  403. // This is a hack to take care of DEFVAL clauses
  404. BOOL SetDefVal();
  405. SIMCResolutionStatus SetDefVal(SIMCObjectTypeType *objType);
  406. // Returs the PrimitiveType of a symbol
  407. static PrimitiveType GetPrimitiveType(const SIMCTypeReference *typeRef);
  408. static PrimitiveType GetPrimitiveType(const char * const name);
  409. // Value checking functions
  410. static SIMCResolutionStatus IsIntegerValue(SIMCSymbol **s, int& retValue);
  411. static SIMCResolutionStatus IsObjectIdentifierValue(SIMCSymbol **s,
  412. SIMCOidValue* &retValue);
  413. static SIMCResolutionStatus IsNullValue(SIMCSymbol **s);
  414. static SIMCResolutionStatus IsOctetStringValue(SIMCSymbol **s,
  415. SIMCOctetStringValue* &retValue);
  416. static SIMCResolutionStatus IsBitsValue(SIMCSymbol **s,
  417. SIMCBitsValue * &retValue);
  418. // Type checking functions
  419. static SIMCResolutionStatus IsObjectTypeV1(SIMCSymbol **value,
  420. SIMCObjectTypeV1 * &retValObjectType);
  421. static SIMCResolutionStatus IsObjectTypeV2(SIMCSymbol **value,
  422. SIMCObjectTypeV2 * &retValObjectType);
  423. static SIMCResolutionStatus IsObjectType(SIMCSymbol **value,
  424. SIMCObjectTypeType * &retValObjectType);
  425. static SIMCResolutionStatus IsTrapType(SIMCSymbol **value,
  426. SIMCTrapTypeType * &retValTrapType);
  427. static SIMCResolutionStatus IsNotificationType(SIMCSymbol **value,
  428. SIMCNotificationTypeType * &retValNotificationType);
  429. static SIMCResolutionStatus IsEnumType(SIMCSymbol **value,
  430. SIMCEnumOrBitsType * &retValEnumType);
  431. // Reference checking functions
  432. static SIMCResolutionStatus IsTypeReference(SIMCSymbol **symbol,
  433. SIMCTypeReference * &retVal);
  434. static SIMCResolutionStatus IsValueReference(SIMCSymbol **symbol,
  435. SIMCSymbol ** &retTypeRef,
  436. SIMCBuiltInValueReference *&retVal);
  437. static SIMCResolutionStatus IsSequenceTypeReference(SIMCSymbol **symbol,
  438. SIMCBuiltInTypeReference * &retVal1,
  439. SIMCSequenceType *&retVal2);
  440. static SIMCResolutionStatus IsSequenceOfTypeReference(SIMCSymbol **symbol,
  441. SIMCBuiltInTypeReference * &retVal1,
  442. SIMCSequenceOfType *&retVal2);
  443. // For fabrication of OBJECT-GROUPs
  444. static SIMCResolutionStatus IsNamedNode(SIMCSymbol **symbol);
  445. static SIMCResolutionStatus IsScalar(SIMCSymbol **symbol);
  446. static SIMCResolutionStatus IsTable(SIMCSymbol **symbol);
  447. static SIMCResolutionStatus IsRow(SIMCSymbol **symbol);
  448. // Other helpers
  449. static SIMCResolutionStatus IsNotZeroSizeObject(SIMCObjectTypeType *objectType);
  450. static SIMCResolutionStatus IsFixedSizeObject(SIMCObjectTypeType *objectType);
  451. // This fabricates NOTICFICATION-TYPEs from TRAP-TYPEs and then proceeds to
  452. // fabricate NOTIFICATION-GROUPs from them.
  453. BOOL FabricateNotificationGroups(SIMCParseTree& theParseTree,
  454. const SIMCOidTree& theOidTree);
  455. };
  456. template<>
  457. UINT AFXAPI HashKey(LPCSTR key);
  458. #endif // SIMC_MODULE_H