Started snmp mib parsing
authorEbersold <aebersol@n3150.home>
Mon, 16 May 2022 17:03:54 +0000 (19:03 +0200)
committerEbersold <aebersol@n3150.home>
Mon, 16 May 2022 17:03:54 +0000 (19:03 +0200)
adt/asn1_meta.h
adt/asn1_meta.inc
adt/asn1_node_valuetype.h
adt/asn1_recursive_visitor.h
libparser/asn1.l
libparser/asn1.y
libparser/asn1_parser.cpp
libparser/asn1_parser.h
libparser/asn1_parser_listener.h
main.cpp
rtasn1/asn1_types.h

index 51e8b11e0a8eb84f29a607747ea7c88cc9a42c49..dedb2c289216a7a9244ca4e8884c9c680a346f3d 100644 (file)
@@ -18,6 +18,9 @@ namespace asn1
         OBJECTCLASS, /* FCT := CLASS {}                */
         OBJECTSET,   /* objref DefinedObject :=  {set }                */
         OBJECTFIELD,
+        SNMP_MODULE_IDENT,     /* Mib MODULE-IDENTITY       */
+        SNMP_TEXTUAL_CONV,     /* Mib TEXTUAL-CONVENTION    */
+        SNMP_OBJECT_TYPE,      /* Mib OBJECT-TYPE           */
         MAX
       } id;
       inline meta(meta::id id = INVALID) : m_id(id) {};
index 4a9da44f695eb4f0353e75bd63e49e1d7ac36fff..0e0342a2f0639f9c75ca163d8c3d5f61610a3322 100644 (file)
@@ -11,4 +11,7 @@ ASSIGNMENT(OBJECTCLASS,objectclass,assignment)
 ASSIGNMENT(OBJECTSET,objectset,assignment)
 ASSIGNMENT(OBJECTFIELD,objectfield,assignment)
 
+ASSIGNMENT(SNMP_MODULE_IDENT,snmp_mib_identity,assignment)
+ASSIGNMENT(SNMP_TEXTUAL_CONV,snmp_mib_tc,assignment)
+ASSIGNMENT(SNMP_OBJECT_TYPE,snmp_mib_object_type,assignment)
 #undef ASSIGNMENT
index d0ba83e36b3001ee12606a00d6923b5d7da430c1..e04815b44abf6343985ca6be35a787478abd1b37 100644 (file)
@@ -3,7 +3,9 @@
 
 class objectset_assignment;
 /**
- * Helper node that deals with all kind of value.
+ * Helper node that deals with all kind of value. It representes
+ * an ASN1 ReferencedValue: DefinedValue
+ *                | ValueFromObject
  * Possible meta 
  *  -> VALUE
  *  -> VALUESET
index ad562c6607f61d223bbccdf9bfc2e6678d209040..1eb3802e46a87a323316d95b5012cd0e9d01dc8e 100644 (file)
@@ -385,6 +385,10 @@ DEF_TRAVERSE_ASSIGN(objectset,{
 })
 DEF_TRAVERSE_ASSIGN(objectfield,{})
 
+DEF_TRAVERSE_ASSIGN(snmp_mib_identity,{})
+DEF_TRAVERSE_ASSIGN(snmp_mib_tc,{})
+DEF_TRAVERSE_ASSIGN(snmp_mib_object_type,{})
+
 /* Implementation Traverse type */
 
 
index c5067d179d7df3c11ad8e92c9a25b71e4407fbd4..bb5e64787832171c856f8a7847c47f661aadea27 100644 (file)
@@ -7,6 +7,7 @@
 #include "asn1_node.h"
 #include "asn1_constraint.h"
 #include "asn1_module.h"
+#include "asn1_parser.h"
 
 /*
 %option never-interactive
@@ -46,6 +47,8 @@ typedef  union
 #define YY_DECL int _asn1_lex(YYSTYPE *yylval)
 #endif 
 
+static asn1::parser *gParser = asn1::parser::instance();
+
 #include "pasn1.hpp"
 
 long
@@ -63,6 +66,12 @@ void _asn1_error(const char *s) {
 #define REF_VF        { yylval->reference = new asn1::valuefield_reference(yytext);return T_VALUEFIELDREFERENCE;}
 #define NODE_TOK(x)   { yylval->node = new asn1::node(yytext);return x;}
 
+#define SNMP_TOK(x)   { yylval->node = new asn1::node(yytext);  \
+                        if (gParser->is_mode_mib())             \
+                        { return x; } else                      \
+                        return T_CAPITALREFERENCE;              \
+                      }
+
 #define NUM_TOK(x)    { asn1::valuetype *vt = new asn1::valuetype(std::string(yytext),NULL);\
                         (yylval)->node = vt; \
                         asn1::value *v = new asn1::value(asn1::value::VT_INTEGER); \
@@ -101,6 +110,10 @@ void _asn1_error(const char *s) {
 %x with_syntax
 %x object
 
+%x snmp_imports
+%x snmp
+%x snmp_quoted_string
+
 /* */
 Digits          [0-9]+
 NDigits         -{Digits}
@@ -130,7 +143,7 @@ wsp [\t\r\v\f\n ]
 -{3,}/[\r\n] /* Comment */
 
 <INITIAL,with_syntax>-- yy_push_state(dash_comment);
-<INITIAL,object>-- yy_push_state(dash_comment);
+<INITIAL,object,snmp>-- yy_push_state(dash_comment);
 
 <dash_comment>{ /* Very special to treat rules for dash_comment rules */
     {nl}    yy_pop_state();
@@ -147,112 +160,185 @@ wsp [\t\r\v\f\n ]
     .       /* skip */
 }
 
-"::="           TOK(T_ASSIGN)
+<INITIAL,snmp>"::="           TOK(T_ASSIGN)
 
 {BString}       TOK(T_bstring)
-{Digits}        NUM_TOK(T_NUM)
-{NDigits}       NUM_TOK(T_NUM)
+<INITIAL,snmp>{Digits}        NUM_TOK(T_NUM)
+<INITIAL,snmp>{NDigits}       NUM_TOK(T_NUM)
 
-ABSENT          TOK(T_ABSENT)
-ABSTRACT        TOK(T_ABSTRACT)
-ABSTRACT-SYNTAX TOK(T_ABSTRACT_SYNTAX)
+<INITIAL,snmp>ABSENT          TOK(T_ABSENT)
+<INITIAL,snmp>ABSTRACT        TOK(T_ABSTRACT)
+<INITIAL>ABSTRACT-SYNTAX TOK(T_ABSTRACT_SYNTAX)
 ALL             TOK(T_ALL)
-ANY             TOK(T_ANY)
-APPLICATION     TOK(T_APPLICATION)
-AUTOMATIC       TOK(T_AUTOMATIC)
-BEGIN           TOK(T_BEGIN)
-BIT             TOK(T_BIT)
-
-BMPString       TOK(T_BMPString)
-BOOLEAN         TOK(T_BOOLEAN)
-BY              TOK(T_BY)
-CHARACTER       TOK(T_CHARACTER)
-CHOICE          TOK(T_CHOICE)
-CLASS           TOK(T_CLASS)
-COMPONENT       TOK(T_COMPONENT)
-COMPONENTS      TOK(T_COMPONENTS)
-CONTAINING      TOK(T_CONTAINING)
-CONSTRAINED     TOK(T_CONSTRAINED)
-DATE            TOK(T_DATE)
-DATE-TIME       TOK(T_DATE_TIME)
-DEFAULT         TOK(T_DEFAULT)
-DEFINED         TOK(T_DEFINED) /* Not reserved word in ASN1 may be old parser (ANY DEFINED BY) */
-
-DEFINITIONS     TOK(T_DEFINITIONS)
-DURATION        TOK(T_DURATION)
+<INITIAL>ANY             TOK(T_ANY)
+<INITIAL>APPLICATION     TOK(T_APPLICATION)
+<INITIAL>AUTOMATIC       TOK(T_AUTOMATIC)
+<INITIAL>BEGIN           TOK(T_BEGIN)
+<snmp>BITS      TOK(T_BIT)
+<INITIAL,snmp>BIT             TOK(T_BIT)
+
+<INITIAL,snmp>BMPString       TOK(T_BMPString)
+<INITIAL,snmp>BOOLEAN         TOK(T_BOOLEAN)
+<INITIAL>BY              TOK(T_BY)
+<INITIAL,snmp>CHARACTER       TOK(T_CHARACTER)
+<INITIAL,snmp>CHOICE          TOK(T_CHOICE)
+<INITIAL>CLASS           TOK(T_CLASS)
+<INITIAL>COMPONENT       TOK(T_COMPONENT)
+<INITIAL>COMPONENTS      TOK(T_COMPONENTS)
+<INITIAL>CONTAINING      TOK(T_CONTAINING)
+<INITIAL>CONSTRAINED     TOK(T_CONSTRAINED)
+<INITIAL>DATE            TOK(T_DATE)
+<INITIAL>DATE-TIME       TOK(T_DATE_TIME)
+<INITIAL>DEFAULT         TOK(T_DEFAULT)
+<INITIAL>DEFINED         TOK(T_DEFINED) /* Not reserved word in ASN1 may be old parser (ANY DEFINED BY) */
+
+<INITIAL,snmp>DEFINITIONS     TOK(T_DEFINITIONS)
+<INITIAL>DURATION        TOK(T_DURATION)
 EMBEDDED
-ENCODED             TOK(T_ENCODED)
-ENCODING-CONTROL    TOK(T_ENCODING_CONTROL)
-END                 TOK(T_END)
-ENUMERATED          TOK(T_ENUMERATED)
-EXCEPT              TOK(T_EXCEPT)
-EXPLICIT            TOK(T_EXPLICIT)
-EXPORTS             TOK(T_EXPORTS)
-EXTENSIBILITY       TOK(T_EXTENSIBILITY)
-EXTERNAL            TOK(T_EXTERNAL)
-FALSE               TOK(T_ASN1_FALSE)
-FROM                TOK(T_FROM)
-GeneralizedTime     TOK(T_GeneralizedTime)
-GeneralString       TOK(T_GeneralizedString)
-GraphicString       TOK(T_GraphicString)
-{HString}           TOK(T_hstring)
-IA5String           TOK(T_IA5String)
-IDENTIFIER          TOK(T_STR_IDENTIFIER)
-IMPLICIT            TOK(T_IMPLICIT)
-IMPLIED             TOK(T_IMPLIED)
-IMPORTS             TOK(T_IMPORTS)
-INCLUDES            TOK(T_INCLUDES)
-INSTANCE            TOK(T_INSTANCE)
-INSTRUCTIONS        TOK(T_INSTRUCTIONS)
-INTEGER             TOK(T_INTEGER)
-INTERSECTION        TOK(T_INTERSECTION)
-ISO64String         TOK(T_ISO646String)
-MAX                 TOK(T_MAX)
-MIN                 TOK(T_MIN)
-MINUS-INFINITY      TOK(T_MINUS_INFINITY)
-NOT-A-NUMBER        TOK(T_NOT_A_NUMBER)
-NULL                TOK(T_NULL)
-NumericString       TOK(T_NumericString)
-ObjectDescriptor    TOK(T_ObjectDescriptorString)
-OBJECT              TOK(T_OBJECT)
-OCTET               TOK(T_OCTET)
-OF                  TOK(T_OF)
-OID-IRI             TOK(T_OID_IRI)
-OPTIONAL            TOK(T_OPTIONAL)
-PATTERN             TOK(T_PATTERN)
-PDV
-PLUS-INFINITY
-PRESENT             TOK(T_PRESENT)
-PrintableString     TOK(T_PrintableString)
-PRIVATE
-REAL                TOK(T_REAL)
-RELATIVE-OID        TOK(T_RELATIVE_OID)
-RELATIVE-OID-IRI    TOK(T_RELATIVE_OID_IRI)
-SEQUENCE            TOK(T_SEQUENCE)
-SET                 TOK(T_SET)
-SETTINGS            TOK(T_SETTINGS)
-SIZE                TOK(T_SIZE)
-STRING              TOK(T_STRING)
-SYNTAX              TOK(T_SYNTAX)
-T61String           TOK(T_T61String)
-TAGS                TOK(T_TAGS)
-TeletexString       TOK(T_TeletexString)
-TIME                TOK(T_TIME)
-TIME-OF-DAY         TOK(T_TIME_OF_DAY)
-TRUE                TOK(T_ASN1_TRUE)
-UNION               TOK(T_UNION)
-UNIQUE              TOK(T_UNIQUE)
-UNIVERSAL           TOK(T_UNIVERSAL)
-UniversalString     TOK(T_UniversalString)
-
-UTCTime             TOK(T_UTCTime)
-UTF8String          TOK(T_UTF8String)
-
-VideotextString     TOK(T_VideotextString)
-VisibleString       TOK(T_VisibleString)
-WITH                TOK(T_WITH)
+<INITIAL>ENCODED             TOK(T_ENCODED)
+<INITIAL>ENCODING-CONTROL    TOK(T_ENCODING_CONTROL)
+<INITIAL,snmp>END                 TOK(T_END)
+<INITIAL>ENUMERATED          TOK(T_ENUMERATED)
+<INITIAL>EXCEPT              TOK(T_EXCEPT)
+<INITIAL>EXPLICIT            TOK(T_EXPLICIT)
+<INITIAL>EXPORTS             TOK(T_EXPORTS)
+<INITIAL>EXTENSIBILITY       TOK(T_EXTENSIBILITY)
+<INITIAL>EXTERNAL            TOK(T_EXTERNAL)
+<INITIAL>FALSE               TOK(T_ASN1_FALSE)
+<INITIAL,snmp,snmp_imports>FROM                TOK(T_FROM)
+<INITIAL,snmp>GeneralizedTime     TOK(T_GeneralizedTime)
+<INITIAL,snmp>GeneralString       TOK(T_GeneralizedString)
+<INITIAL,snmp>GraphicString       TOK(T_GraphicString)
+<INITIAL,snmp>{HString}           TOK(T_hstring)
+<INITIAL,snmp>IA5String           TOK(T_IA5String)
+<INITIAL,snmp>IDENTIFIER          TOK(T_STR_IDENTIFIER)
+<INITIAL>IMPLICIT            TOK(T_IMPLICIT)
+<INITIAL>IMPLIED             TOK(T_IMPLIED)
+IMPORTS             {
+                      if (gParser->is_mode_mib())
+                        yy_push_state(snmp_imports);
+                      return T_IMPORTS;
+                    }
+<INITIAL>INCLUDES            TOK(T_INCLUDES)
+<INITIAL>INSTANCE            TOK(T_INSTANCE)
+<INITIAL>INSTRUCTIONS        TOK(T_INSTRUCTIONS)
+<INITIAL,snmp>INTEGER             TOK(T_INTEGER)
+<INITIAL>INTERSECTION        TOK(T_INTERSECTION)
+<INITIAL,snmp>ISO64String         TOK(T_ISO646String)
+<INITIAL,snmp>MAX                 TOK(T_MAX)
+<snmp>MAX-ACCESS          TOK(T_MAX_ACCESS)
+<INITIAL,snmp>MIN                 TOK(T_MIN)
+<INITIAL>MINUS-INFINITY      TOK(T_MINUS_INFINITY)
+<INITIAL>NOT-A-NUMBER        TOK(T_NOT_A_NUMBER)
+<INITIAL>NULL                TOK(T_NULL)
+<INITIAL,snmp>NumericString       TOK(T_NumericString)
+<INITIAL,snmp>ObjectDescriptor    TOK(T_ObjectDescriptorString)
+<snmp>OBJECTS       TOK(T_OBJECTS)
+<INITIAL,snmp>OBJECT   TOK(T_OBJECT)
+<INITIAL,snmp>OCTET               TOK(T_OCTET)
+<INITIAL,snmp>OF                  TOK(T_OF)
+<INITIAL>OID-IRI             TOK(T_OID_IRI)
+<INITIAL>OPTIONAL            TOK(T_OPTIONAL)
+<INITIAL>PATTERN             TOK(T_PATTERN)
+<INITIAL>PDV
+<INITIAL>PLUS-INFINITY
+<INITIAL>PRESENT             TOK(T_PRESENT)
+<INITIAL>PrintableString     TOK(T_PrintableString)
+<INITIAL>PRIVATE
+<INITIAL>REAL                TOK(T_REAL)
+<INITIAL>RELATIVE-OID        TOK(T_RELATIVE_OID)
+<INITIAL>RELATIVE-OID-IRI    TOK(T_RELATIVE_OID_IRI)
+<INITIAL,snmp>SEQUENCE            TOK(T_SEQUENCE)
+<INITIAL>SET                 TOK(T_SET)
+<INITIAL>SETTINGS            TOK(T_SETTINGS)
+<INITIAL,snmp>SIZE                TOK(T_SIZE)
+<INITIAL,snmp>STRING              TOK(T_STRING)
+<INITIAL,snmp>SYNTAX              TOK(T_SYNTAX)
+<INITIAL>T61String           TOK(T_T61String)
+<INITIAL>TAGS                TOK(T_TAGS)
+<INITIAL>TeletexString       TOK(T_TeletexString)
+<INITIAL>TIME                TOK(T_TIME)
+<INITIAL>TIME-OF-DAY         TOK(T_TIME_OF_DAY)
+<INITIAL>TRUE                TOK(T_ASN1_TRUE)
+<INITIAL>UNION               TOK(T_UNION)
+<INITIAL>UNITS               TOK(T_UNITS)
+<INITIAL>UNIQUE              TOK(T_UNIQUE)
+<INITIAL>UNIVERSAL           TOK(T_UNIVERSAL)
+<INITIAL>UniversalString     TOK(T_UniversalString)
+
+<INITIAL>UTCTime             TOK(T_UTCTime)
+<INITIAL>UTF8String          TOK(T_UTF8String)
+
+<INITIAL>VideotextString     TOK(T_VideotextString)
+<INITIAL>VisibleString       TOK(T_VisibleString)
+<INITIAL>WITH                TOK(T_WITH)
+
+%{ /** SIM SNMP MACRO Names */ %}
+
+<snmp>MODULE-IDENTITY     SNMP_TOK(T_MACRO_NAME)
+<snmp>OBJECT-IDENTITY     SNMP_TOK(T_MACRO_OBJECT_IDENTITY)
+<snmp>OBJECT-TYPE         SNMP_TOK(T_MACRO_OBJECT_TYPE)
+<snmp>NOTIFICATION-TYPE   SNMP_TOK(T_MACRO_NOTIFICATION_TYPE)
+<snmp>TRAP-TYPE           SNMP_TOK(T_MACRO_TRAP_TYPE)
+<snmp>TEXTUAL-CONVENTION  SNMP_TOK(T_MACRO_TC)
+<snmp>OBJECT-GROUP        SNMP_TOK(T_MACRO_OBJECT_GROUP)
+<snmp>NOTIFICATION-GROUP  SNMP_TOK(T_MACRO_NOTIFICATION_GROUP)
+<snmp>MODULE-COMPLIANCE   SNMP_TOK(T_MACRO_MODULE_COMPLIANCE)
+<snmp>AGENT-COMPABILITIES SNMP_TOK(T_MACRO_NAME)
+
+<snmp_imports>{
+       {Identifier}           NODE_TOK(T_IDENTIFIER)
+       {String_Literal}       NODE_TOK(T_IDENTIFIER)
+       {CapitalReference}     NODE_TOK(T_CAPITALREFERENCE)
+        {TypeReference}        NODE_TOK(T_TYPEREFERENCE)
+       "{"                    TOK(T_LBRACET)
+       "}"                    TOK(T_RBRACET)
+        ","                    TOK(T_COMMA)
+        ";"                    {
+                                 yy_pop_state(); 
+                                 return T_SIMILICON;
+                               }
+        {wsp}+  /* ignore whitespace*/
+}
 
+<snmp_quoted_string>{
+  \"[^\"]*\" { return T_QUOTED_STRING;}
+}
 
+<snmp>{
+        ACCESS                 TOK(T_ACCESS)
+        AUGMENTS               TOK(T_AUGMENTS)
+        CONTACT-INFO           TOK(T_CONTACT_INFO)
+        DESCRIPTION            TOK(T_DESCRIPTION)
+        DISPLAY-HINT           TOK(T_DISPLAY_HINT)
+        DEFVAL                 TOK(T_DEFVAL)
+        ENTERPRISE             TOK(T_ENTERPRISE)
+        GROUP                  TOK(T_GROUP)
+        INDEX                  TOK(T_INDEX)
+        LAST-UPDATED           TOK(T_LAST_UPDATED)
+        MANDATORY-GROUPS       TOK(T_MANDATORY_GROUPS)
+        MIN-ACCESS             TOK(T_MIN_ACCESS)
+        MODULE                 TOK(T_MODULE)
+        NOTIFICATIONS          TOK(T_NOTIFICATIONS)
+        REVISION               TOK(T_REVISION)
+        REFERENCE              TOK(T_REFERENCE)
+        ORGANIZATION           TOK(T_ORGANIZATION)
+        STATUS                 TOK(T_STATUS)
+        UNITS                  TOK(T_UNITS)
+        VARIABLES              TOK(T_VARIABLES)
+        WRITE-SYNTAX           TOK(T_WRITE_SYNTAX)
+       {Identifier}           NODE_TOK(T_IDENTIFIER)
+       {CapitalReference}     NODE_TOK(T_CAPITALREFERENCE)
+        {TypeReference}        NODE_TOK(T_TYPEREFERENCE)
+        \"[^\"]*\"             { /* QUOTED STRING */
+                                 yylval->node = new asn1::node(yytext);
+                                 return T_QUOTED_STRING;
+                               }
+        ";"                    {
+                                 return T_SIMILICON;
+                               }
+        {wsp}+  /* ignore whitespace*/
+}
 
 
 {Identifier}           NODE_TOK(T_IDENTIFIER)
@@ -277,17 +363,17 @@ WITH                TOK(T_WITH)
 "!"             TOK(T_EXCLAMATION)
 "["             TOK(T_LBRACKET)
 "]"             TOK(T_RBRACKET)
-"{"             TOK(T_LBRACET)
-"}"             TOK(T_RBRACET)
-")"             TOK(T_RPARENTHESES)
-"("             TOK(T_LPARENTHESES)
-"."            TOK(T_POINT)
-".."            TOK(T_TWOPOINT)
-"..."           TOK(T_THREEPOINT)
-","             TOK(T_COMMA)
+<INITIAL,snmp>"{"             TOK(T_LBRACET)
+<INITIAL,snmp>"}"             TOK(T_RBRACET)
+<INITIAL,snmp>")"             TOK(T_RPARENTHESES)
+<INITIAL,snmp>"("             TOK(T_LPARENTHESES)
+"."                TOK(T_POINT)
+<INITIAL,snmp>".."               TOK(T_TWOPOINT)
+"..."              TOK(T_THREEPOINT)
+<INITIAL,snmp>","  TOK(T_COMMA)
 ";"             TOK(T_SIMILICON)
 ":"             TOK(T_COLON)
-"|"             TOK(T_UNION)
+<INITIAL,snmp>"|"             TOK(T_UNION)
 "^"             TOK(T_EXCEPT)
 "_"             TOK(T_USCORE)
 {wsp}+  /* ignore whitespace*/
@@ -368,6 +454,16 @@ void disable_object()
 {
     yy_pop_state();
 }
+/* SNMP MIB INFORMATION LEX*/
+void enable_snmp()
+{
+    yy_push_state(snmp);
+}
+void disable_snmp()
+{
+    yy_pop_state();
+}
+
 
 
 
index f102f2c356199d0522b661ed01d1b099b3f825cb..0543511a943430d9a5991f3d0dfc001229cee7d6 100644 (file)
@@ -47,18 +47,34 @@ extern void enable_encoding_control(void);
 extern void disable_with_syntax(void);\r
 extern void enable_object(void);\r
 extern void disable_object(void);\r
+\r
+extern void enable_snmp(void);\r
+extern void disable_snmp(void);\r
+\r
+#if 1\r
+#define OLD_ENABLE_SNMP() \r
+#define OLD_DISABLE_SNMP() \r
+#define NEW_ENABLE_SNMP() enable_snmp()\r
+#define NEW_DISABLE_SNMP() disable_snmp()\r
+#else\r
+#define OLD_ENABLE_SNMP() enable_snmp()\r
+#define OLD_DISABLE_SNMP() disable_snmp() \r
+#define NEW_ENABLE_SNMP()\r
+#define NEW_DISABLE_SNMP() \r
+#endif\r
 //#include "lasn1.cpp"\r
 \r
 static\r
 asn1::parser *gParser = asn1::parser::instance();\r
 \r
+#define LOG_BUF_LEN 256\r
 #if defined(__GNUC__) && defined(DEBUG)\r
 #define ASN_LOG_DEBUG(fmt,args...) do {\\r
-  char _lbuf[256]; \\r
+  char _lbuf[LOG_BUF_LEN]; \\r
   if ( gLog.is_open()) { \\r
     gLog<<"DEBUG "; \\r
-    sprintf(_lbuf,fmt,##args); gLog<<_lbuf; \\r
-    sprintf(_lbuf," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \\r
+    snprintf(_lbuf,LOG_BUF_LEN,fmt,##args); gLog<<_lbuf; \\r
+    snprintf(_lbuf,LOG_BUF_LEN," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \\r
   } else if (gParser->debug_console() ) { \\r
   fprintf(stderr,"asn1_parser (DEBUG): "); \\r
   fprintf(stderr,fmt,##args);\\r
@@ -67,11 +83,11 @@ asn1::parser *gParser = asn1::parser::instance();
 } while (0)\r
 \r
 #define ASN_LOG_WARNING(fmt,args...) do {\\r
-  char _lbuf[256]; \\r
+  char _lbuf[LOG_BUF_LEN]; \\r
   if (gLog.is_open()) { \\r
     gLog<<"WARN "; \\r
-    sprintf(_lbuf,fmt,##args); gLog<<_lbuf; \\r
-    sprintf(_lbuf," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \\r
+    snprintf(_lbuf,LOG_BUF_LEN,fmt,##args); gLog<<_lbuf; \\r
+    snprintf(_lbuf,LOG_BUF_LEN," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \\r
   }  \\r
   fprintf(stderr,"asn1_parser (WARNI): "); \\r
   fprintf(stderr,fmt,##args);\\r
@@ -79,11 +95,11 @@ asn1::parser *gParser = asn1::parser::instance();
 } while (0)\r
 \r
 #define ASN_LOG_ERROR(fmt,args...) do {\\r
-  char _lbuf[256]; \\r
+  char _lbuf[LOG_BUF_LEN]; \\r
   if ( gLog.is_open()) { \\r
     gLog<<"ERROR "; \\r
-    sprintf(_lbuf,fmt,##args); gLog<<_lbuf; \\r
-    sprintf(_lbuf," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \\r
+    snprintf(_lbuf,LOG_BUF_LEN,fmt,##args); gLog<<_lbuf; \\r
+    snprintf(_lbuf,LOG_BUF_LEN," (asn1.y : %d)\n",__LINE__); gLog<<_lbuf; \\r
   }  \\r
   fprintf(stderr,"asn1_parser (ERROR): "); \\r
   fprintf(stderr,fmt,##args);\\r
@@ -161,6 +177,8 @@ static asn1::classdef *gCurrentClassDef = NULL;
 %token T_ABSENT\r
 %token T_ABSTRACT\r
 %token T_ABSTRACT_SYNTAX\r
+%token T_ACCESS\r
+%token T_AUGMENTS\r
 %token T_ALL\r
 %token T_ANY\r
 %token T_APPLICATION\r
@@ -171,6 +189,7 @@ static asn1::classdef *gCurrentClassDef = NULL;
 %token T_AUTOMATIC\r
 %token T_BEGIN\r
 %token T_BIT\r
+%token T_BITS\r
 %token T_BOOLEAN\r
 %token T_BY\r
 %token <node>T_CAPITALREFERENCE\r
@@ -178,63 +197,93 @@ static asn1::classdef *gCurrentClassDef = NULL;
 %token T_CHOICE\r
 %token T_CLASS\r
 %token T_COLON\r
+%token T_CONTACT_INFO\r
 %token T_COMPONENT\r
 %token T_COMPONENTS\r
 %token T_CONTAINING\r
+%token T_DESCRIPTION\r
+%token T_DEFVAL\r
 %token T_DATE\r
 %token T_DATE_TIME\r
 %token T_CONSTRAINED\r
 %token T_DEFAULT\r
 %token T_DEFINITIONS\r
+%token T_DISPLAY_HINT\r
 %token T_DURATION\r
 %token T_ENCODED\r
 %token T_ENCODING_CONTROL\r
 %token T_END\r
+%token T_ENTERPRISE\r
 %token T_EXPLICIT\r
 %token T_EXCEPT\r
 %token T_EXCLAMATION\r
 %token T_EXPORTS\r
 %token T_EXTENSIBILITY\r
 %token T_EXTERNAL\r
+%token T_GROUP\r
 %token <node>T_IDENTIFIER\r
 %token T_IMPLICIT\r
 %token T_IMPLIED\r
 %token T_INCLUDES\r
+%token T_INDEX\r
 %token T_INSTANCE\r
 %token T_INSTRUCTIONS\r
 %token <node>T_INTEGER\r
 %token T_INTERSECTION\r
+%token T_LAST_UPDATED\r
 %token T_LT\r
+%token <node>T_MACRO_NAME\r
+%token <node>T_MACRO_NOTIFICATION_TYPE\r
+%token <node>T_MACRO_NOTIFICATION_GROUP\r
+%token <node>T_MACRO_OBJECT_GROUP\r
+%token <node>T_MACRO_OBJECT_TYPE\r
+%token <node>T_MACRO_TRAP_TYPE\r
+%token <node>T_MACRO_OBJECT_IDENTITY\r
+%token <node>T_MACRO_TC\r
+%token <node>T_MACRO_MODULE_COMPLIANCE\r
+%token T_MANDATORY_GROUPS\r
 %token T_MAX\r
+%token T_MAX_ACCESS\r
 %token T_MIN\r
+%token T_MIN_ACCESS\r
+%token T_MODULE\r
 %token T_MINUS_INFINITY\r
 %token T_NOT_A_NUMBER\r
+%token T_NOTIFICATIONS\r
 %token T_NULL\r
 %token <node>T_NUM\r
+%token T_OBJECT\r
+%token T_OBJECTS\r
 %token T_OCTET\r
 %token T_OPTIONAL\r
 %token T_OF\r
 %token T_OID_IRI\r
-%token T_OBJECT\r
+%token T_ORGANIZATION\r
 %token T_Quadruple\r
+%token T_QUOTED_STRING\r
 %token T_POINT\r
 %token T_PATTERN\r
 %token T_PRESENT\r
 %token T_PRIVATE\r
 %token T_REAL\r
+%token T_REFERENCE\r
 %token T_RELATIVE_OID\r
 %token T_RELATIVE_OID_IRI\r
+%token T_REVISION\r
 %token T_SIMILICON\r
 %token T_SEQUENCE\r
 %token T_SET\r
 %token T_SETTINGS\r
 %token T_SIZE\r
+%token T_STATUS\r
 %token T_STRING\r
 %token T_SYNTAX\r
 %token T_Tuple\r
 %token T_UNION\r
+%token T_UNITS\r
 %token T_UNIVERSAL\r
 %token T_UNIQUE\r
+%token T_VARIABLES\r
 %token T_STR_IDENTIFIER\r
 %token <node>T_TYPEREFERENCE\r
 %token <reference>T_TYPEFIELDREFERENCE\r
@@ -275,6 +324,7 @@ static asn1::classdef *gCurrentClassDef = NULL;
 %token T_TWOPOINT\r
 %token T_THREEPOINT\r
 %token T_WITH\r
+%token T_WRITE_SYNTAX\r
 %token T_USCORE\r
 %token T_bstring\r
 %token T_hstring\r
@@ -374,6 +424,7 @@ static asn1::classdef *gCurrentClassDef = NULL;
 %type <node>        set_def\r
 %type <node>        set_value\r
 %type <node>        sequence_def\r
+%type <node>        snmp_assignment\r
 %type <node>        choice_def \r
 %type <node>        defined_syntax_list\r
 %type <node>        parameter_list \r
@@ -411,7 +462,6 @@ static asn1::classdef *gCurrentClassDef = NULL;
 %name-prefix="_asn1_"\r
 %pure-parser\r
 \r
-\r
 %%\r
 \r
 definition_files:definitions\r
@@ -661,10 +711,15 @@ definition_module: opt_exports opt_imports
     asn1::module *m = get_current_module();\r
     m->imports(i);\r
     m->exports(e);\r
+    /* May be enable snmp here  if mib*/\r
+    if (asn1::parser::instance()->is_mode_mib())\r
+    { NEW_ENABLE_SNMP(); }\r
   } type_constant_list\r
   {\r
     $$ = $4;\r
- }\r
+    if (asn1::parser::instance()->is_mode_mib())\r
+    { NEW_DISABLE_SNMP(); }\r
+  }\r
  ;\r
 \r
 opt_tags_def: /* Empty */\r
@@ -3201,6 +3256,391 @@ defined_syntax_token:
   }\r
 ;\r
 \r
+/*\r
+ * SNMP / MIB rules\r
+ */\r
+snmp_assignment: snmp_module_identity\r
+ {\r
+    ASN_LOG_DEBUG("snmp_assignment :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_textual_convention  {\r
+    ASN_LOG_DEBUG("snmp_textual_convention:");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_object_type {\r
+    ASN_LOG_DEBUG("snmp_object_type :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_notification_type {\r
+    ASN_LOG_DEBUG("snmp_notification_type :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_trap_type {\r
+    ASN_LOG_DEBUG("snmp_notification_type :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_notification_group {\r
+    ASN_LOG_DEBUG("snmp_notification_group :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_module_compliance {\r
+    ASN_LOG_DEBUG("snmp_object_type :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_object_group {\r
+    ASN_LOG_DEBUG("snmp_object_group :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+  | snmp_object_identity {\r
+    ASN_LOG_DEBUG("snmp_object_identity :");\r
+    $$ = new asn1::snmp_mib_identity_assignment($<node>1->name()); \r
+  }\r
+;\r
+\r
+/* SNMP common rules */\r
+snmp_description: T_DESCRIPTION T_QUOTED_STRING  {\r
+    ASN_LOG_DEBUG("snmp_mi_description: %s",$<node>2->name().c_str());\r
+  }\r
+;\r
+\r
+snmp_status: T_STATUS T_IDENTIFIER\r
+;\r
+\r
+/** SNMP MODULE_IDENTITY */\r
+snmp_module_identity: T_IDENTIFIER T_MACRO_NAME {\r
+    ASN_LOG_DEBUG("snmp_module_identity: %s ",$1->name().c_str());\r
+  } snmp_mi_attributes {\r
+    ASN_LOG_DEBUG("snmp_module_identity: + %s",$1->name().c_str());\r
+  } T_ASSIGN {\r
+    ASN_LOG_DEBUG("snmp_module_identity: %s have assigment",$1->name().c_str());\r
+  } T_LBRACET obj_constant_list T_RBRACET {\r
+    ASN_LOG_DEBUG("snmp_module_identity: %s end",$1->name().c_str());\r
+    asn1::module *m = get_current_module();\r
+    asn1::node *ids = m->leave_context();\r
+    $<node>$ = ids;\r
+    $<node>$ = $<node>1;\r
+}\r
+;\r
+\r
+snmp_mi_attributes: snmp_mi_last_update\r
+  snmp_mi_organization\r
+  snmp_mi_contact\r
+  snmp_description\r
+  snmp_mi_revisions {\r
+    ASN_LOG_DEBUG("snmp_mi_attributes: end");\r
+}\r
+;\r
+\r
+snmp_mi_last_update: T_LAST_UPDATED T_QUOTED_STRING {\r
+    ASN_LOG_DEBUG("snmp_mi_last_updated %s",$<node>2->name().c_str());\r
+  }\r
+;\r
+snmp_mi_organization: T_ORGANIZATION T_QUOTED_STRING {\r
+    ASN_LOG_DEBUG("snmp_mi_organization");\r
+  }\r
+;\r
+snmp_mi_contact: T_CONTACT_INFO T_QUOTED_STRING {\r
+    ASN_LOG_DEBUG("snmp_mi_contact:");\r
+  }\r
+;\r
+\r
+snmp_mi_revisions: snmp_mi_revision {\r
+  }\r
+  | snmp_mi_revision snmp_mi_revisions {\r
+  }\r
+;\r
+\r
+snmp_mi_revision: T_REVISION T_QUOTED_STRING\r
+  T_DESCRIPTION T_QUOTED_STRING {\r
+    ASN_LOG_DEBUG("snmp_mi_revision: revision %s / description %s",$<node>2->name().c_str(),$<node>4->name().c_str());\r
+  }\r
+;\r
+\r
+/** SNMP TEXTUAL CONVENTION */\r
+snmp_textual_convention: T_TYPEREFERENCE T_ASSIGN T_MACRO_TC snmp_tc_attributes {\r
+    $<node>$ = $1;\r
+  }\r
+;\r
+\r
+snmp_tc_attributes: snmp_tc_display\r
+  snmp_tc_status\r
+  snmp_tc_description\r
+  snmp_tc_reference\r
+  snmp_tc_syntax\r
+;\r
+\r
+snmp_tc_display: /* can be null */\r
+  | T_DISPLAY_HINT T_QUOTED_STRING {\r
+};\r
+\r
+snmp_tc_status: /* can be null */\r
+  | snmp_status {\r
+};\r
+\r
+snmp_tc_description: /* can be null */\r
+  | snmp_description {\r
+};\r
+\r
+snmp_tc_reference: /* can be null */\r
+  | T_REFERENCE T_QUOTED_STRING {\r
+};\r
+\r
+snmp_tc_syntax: /* can be null */\r
+  | T_SYNTAX type_assign_right opt_constraint_def {\r
+};\r
+\r
+/** SNMP OBJECT-TYPE  */\r
+snmp_object_type: T_IDENTIFIER T_MACRO_OBJECT_TYPE snmp_ot_attributes \r
+  T_ASSIGN T_LBRACET obj_constant_list T_RBRACET {\r
+    asn1::module *m = get_current_module();\r
+    asn1::node *ids = m->leave_context();\r
+    $<node>$ = $1;\r
+  }\r
+;\r
+\r
+snmp_ot_attributes: snmp_ot_syntax\r
+  snmp_ot_units\r
+  snmp_ot_access\r
+  snmp_ot_status\r
+  snmp_description\r
+  snmp_ot_index\r
+  snmp_ot_augments\r
+  snmp_ot_reference\r
+  snmp_ot_defval\r
+;\r
+\r
+snmp_ot_syntax: T_SYNTAX type_assign_right opt_constraint_def {\r
+ }\r
+ | T_SYNTAX T_BITS T_LBRACET snmp_ot_bits T_RBRACET {\r
+ }\r
+;\r
+\r
+snmp_ot_bits:obj_constant {\r
+  }\r
+  | snmp_ot_bits T_COMMA obj_constant {\r
+  }\r
+;\r
+\r
+snmp_ot_units: /* NULL*/\r
+  | T_UNITS T_QUOTED_STRING {\r
+  }\r
+;\r
+snmp_ot_access: T_MAX_ACCESS T_IDENTIFIER {\r
+  }\r
+  | T_ACCESS T_IDENTIFIER {\r
+}\r
+;\r
+\r
+snmp_ot_status: T_STATUS T_IDENTIFIER {\r
+  }\r
+;\r
+\r
+snmp_ot_augments: /**/\r
+  | T_AUGMENTS T_LBRACET snmp_ot_indexes T_RBRACET {\r
+  }\r
+;\r
+snmp_ot_index: /**/\r
+  | T_INDEX T_LBRACET snmp_ot_indexes T_RBRACET {\r
+  }\r
+;\r
+snmp_ot_indexes: T_IDENTIFIER  {\r
+  }\r
+  | snmp_ot_indexes T_COMMA T_IDENTIFIER {\r
+}\r
+;\r
+\r
+snmp_ot_reference: /**/\r
+  | T_REFERENCE T_QUOTED_STRING {\r
+  }\r
+;\r
+\r
+snmp_ot_defval: /*NULL */\r
+  | T_DEFVAL T_LBRACET T_IDENTIFIER T_RBRACET {\r
+  }\r
+  | T_DEFVAL T_LBRACET T_NUM T_RBRACET {\r
+  }\r
+;\r
+\r
+/** SNMP TRAP-TYPE  */\r
+snmp_trap_type: T_IDENTIFIER T_MACRO_TRAP_TYPE snmp_tt_attributes \r
+  T_ASSIGN  pos_neg_num {\r
+    $<node>$ = $1;\r
+  }\r
+;\r
+\r
+snmp_tt_attributes: snmp_tt_entreprise\r
+  snmp_tt_vars\r
+  snmp_tc_description\r
+  snmp_tc_reference\r
+;\r
+\r
+snmp_tt_entreprise: T_ENTERPRISE T_LBRACET T_RBRACET \r
+  | T_ENTERPRISE T_IDENTIFIER\r
+;\r
+\r
+snmp_tt_vars: /* NULL */\r
+ | T_VARIABLES T_LBRACET snmp_tt_variable_list T_RBRACET\r
+;\r
+\r
+snmp_tt_variable_list: T_IDENTIFIER\r
+  | snmp_tt_variable_list T_COMMA T_IDENTIFIER\r
+;\r
+\r
+/** SNMP MODULE-COMPLIANCE */\r
+snmp_module_compliance: T_IDENTIFIER T_MACRO_MODULE_COMPLIANCE snmp_mc_attributes {\r
+    $<node>$ = $1;\r
+   } T_ASSIGN\r
+   T_LBRACET obj_constant_list T_RBRACET {\r
+    ASN_LOG_DEBUG("snmp_module_compliance: %s end",$1->name().c_str());\r
+    asn1::module *m = get_current_module();\r
+    asn1::node *ids = m->leave_context();\r
+    $<node>$ = $<node>1;\r
+};\r
+\r
+snmp_mc_attributes: snmp_status\r
+  snmp_description\r
+  snmp_mc_modules  \r
+  snmp_mc_compliance_part \r
+;\r
+\r
+snmp_mc_modules: snmp_mc_module\r
+  | snmp_mc_module snmp_mc_modules\r
+;\r
+\r
+snmp_mc_module: T_MODULE snmp_mc_module_name\r
+ snmp_mc_mandatory_groups \r
+;\r
+\r
+snmp_mc_module_name: /* Empty */\r
+  | T_IDENTIFIER\r
+;\r
+\r
+snmp_mc_mandatory_groups: T_MANDATORY_GROUPS T_LBRACET snmp_mc_mandatories T_RBRACET\r
+;\r
+\r
+snmp_mc_mandatories: T_IDENTIFIER\r
+  | snmp_mc_mandatories T_COMMA T_IDENTIFIER\r
+;\r
+\r
+\r
+snmp_mc_compliance_part: /* Can be NULL */\r
+  | snmp_mc_compliances\r
+;\r
+\r
+snmp_mc_compliances: snmp_mc_compliance\r
+  | snmp_mc_compliance snmp_mc_compliances\r
+;\r
+\r
+snmp_mc_compliance: snmp_mc_group\r
+  | snmp_mc_object\r
+;\r
+\r
+snmp_mc_group: T_GROUP T_IDENTIFIER\r
+  T_DESCRIPTION T_QUOTED_STRING\r
+;\r
+\r
+snmp_mc_object: T_OBJECT T_IDENTIFIER\r
+  snmp_mc_obj_syntax\r
+  snmp_mc_obj_access\r
+  snmp_description\r
+;\r
+\r
+/* Need to find out what kind of syntax it is about here */\r
+snmp_mc_obj_syntax: /**/\r
+  | T_SYNTAX  type\r
+  | T_SYNTAX  T_BITS T_LBRACET constant_list T_RBRACET\r
+  | T_WRITE_SYNTAX  type_assign_right opt_constraint_def\r
+; \r
+  \r
+snmp_mc_obj_access: /* Can be null */\r
+  | T_MIN_ACCESS T_IDENTIFIER {\r
+  }\r
+;\r
+\r
+/** SNMP  OBJECT-GROUP */\r
+snmp_object_group: T_IDENTIFIER T_MACRO_OBJECT_GROUP \r
+   snmp_og_attributes {\r
+    $<node>$ = $1;\r
+   } T_ASSIGN\r
+   T_LBRACET obj_constant_list T_RBRACET {\r
+    ASN_LOG_DEBUG("snmp_module_compliance: %s end",$1->name().c_str());\r
+    asn1::module *m = get_current_module();\r
+    asn1::node *ids = m->leave_context();\r
+    $<node>$ = $<node>1;\r
+};\r
+\r
+snmp_og_attributes: snmp_objects\r
+  snmp_status\r
+  snmp_description\r
+;\r
+\r
+snmp_objects: T_OBJECTS T_LBRACET snmp_og_list T_RBRACET\r
+;\r
+\r
+snmp_og_list: T_IDENTIFIER\r
+  | snmp_og_list T_COMMA T_IDENTIFIER {\r
+};\r
+\r
+/** SNMP  NOTIFICATION-TYPE  */\r
+snmp_notification_type: T_IDENTIFIER  T_MACRO_NOTIFICATION_TYPE \r
+    snmp_nt_attributes {\r
+    $<node>$ = $1;\r
+   } T_ASSIGN\r
+   T_LBRACET obj_constant_list T_RBRACET {\r
+    ASN_LOG_DEBUG("snmp_module_compliance: %s end",$1->name().c_str());\r
+    asn1::module *m = get_current_module();\r
+    asn1::node *ids = m->leave_context();\r
+    $<node>$ = $<node>1;\r
+};\r
+\r
+snmp_nt_attributes: snmp_objects\r
+  snmp_status \r
+  snmp_description {\r
+};\r
+\r
+/** SNMP  NOTIFICATION-GROUP  */\r
+snmp_notification_group: T_IDENTIFIER  T_MACRO_NOTIFICATION_GROUP \r
+    snmp_ng_attributes {\r
+    $<node>$ = $1;\r
+   } T_ASSIGN\r
+   T_LBRACET obj_constant_list T_RBRACET {\r
+    ASN_LOG_DEBUG("snmp_notification_group %s end",$1->name().c_str());\r
+    asn1::module *m = get_current_module();\r
+    asn1::node *ids = m->leave_context();\r
+    $<node>$ = $<node>1;\r
+};\r
+\r
+snmp_ng_attributes: snmp_ng_notifications\r
+  snmp_status \r
+  snmp_description {\r
+};\r
+\r
+snmp_ng_notifications: T_NOTIFICATIONS T_LBRACET snmp_ng_list T_RBRACET {\r
+}\r
+;\r
+\r
+snmp_ng_list: T_IDENTIFIER\r
+  | snmp_ng_list T_COMMA T_IDENTIFIER {\r
+};\r
+\r
+/** SNMP  OBJECT-IDENTITY  */\r
+snmp_object_identity: T_IDENTIFIER  T_MACRO_OBJECT_IDENTITY \r
+    snmp_oi_attributes {\r
+    $<node>$ = $1;\r
+   } T_ASSIGN\r
+   T_LBRACET obj_constant_list T_RBRACET {\r
+    ASN_LOG_DEBUG("snmp_notification_group %s end",$1->name().c_str());\r
+    asn1::module *m = get_current_module();\r
+    asn1::node *ids = m->leave_context();\r
+    $<node>$ = $<node>1;\r
+};\r
+\r
+snmp_oi_attributes: \r
+  snmp_status \r
+  snmp_description {\r
+};\r
+\r
 /*\r
  *\r
  */\r
@@ -3226,6 +3666,10 @@ type_constant:
     ASN_LOG_DEBUG("type_constant: constant_set_def");\r
     $$ = $1;\r
   } \r
+  |  snmp_assignment {\r
+    ASN_LOG_DEBUG("type_constant:snmp_assignment");\r
+    $$ = $1;\r
+  } \r
   | T_ENCODING_CONTROL  T_CAPITALREFERENCE {\r
     ASN_LOG_DEBUG("type_constant: encoding control start enable ignored for now");\r
     enable_encoding_control();\r
index 95cf42a8dfbe967c6301cb8b895933ba232b2882..f8f26a8a46d9db666df726f3f4ec53332165151d 100644 (file)
@@ -43,33 +43,38 @@ int _asn1_wrap()
     // close the current in, and open the new one
     if ((asn1p->file_mode() )  && _asn1_in != NULL)
     {
-       fclose(_asn1_in);
-      _asn1_in = NULL;
+        fclose(_asn1_in);
+        _asn1_in = NULL;
     } else if (!asn1p->file_mode())
     {
         return 1;
     }
     // Only process files if specified
     if (asn1p->files().size() > 0)
-    {
-      if (asn1p->includes().size() > 0) {
-        std::list<std::string>::iterator it;
-        for ( it = asn1p->includes().begin()
-            ; it != asn1p->includes().end(); ++it)
+    { 
+        fullname = asn1p->files().back();
+        /* Search over includes if can't access */
+        if ((asn1p->includes().size() > 0)
+             && access(fullname.c_str(),F_OK) /* Could not open */
+           )
         {
-            fullname = (*it) + asn1p->files().back();
-            if (!access(fullname.c_str(),F_OK))
-            { 
-                break;
+            std::list<std::string>::iterator it;
+            for ( it = asn1p->includes().begin()
+            ; it != asn1p->includes().end(); ++it)
+            {
+                fullname = (*it) + asn1p->files().back();
+                if (!access(fullname.c_str(),F_OK))
+                { 
+                    break;
+                }
             }
-        }
       }
       if (fullname.size() > 0)
       {
         _asn1_in = fopen(fullname.c_str(),"r");
         if (_asn1_in != NULL)
         {
-           std::cout<<"New File : "<<fullname<<std::endl;
+            std::cout<<"New File : "<<fullname<<std::endl;
             asn1p->files().pop_back();
             return  0;
         } else {
index 0e418fc71426504f6d9cef34463c37d6691a4f43..6546f2a9affdfd9f44407824628e7d84cfbbf800 100644 (file)
@@ -64,6 +64,12 @@ class parser
     void got_act_parameter(asn1::node *n);
 
     int parse();
+    
+    inline void set_mode(const std::string &_mode) 
+    { m_mode = _mode ; }
+    
+    inline bool is_mode_mib() const
+    { return !m_mode.compare("mib") ; }
 
     inline bool debug_console() const
     { return m_debug_console ; }
@@ -77,7 +83,7 @@ class parser
     { m_file_mode = fm;}    
   private:
     parser() 
-      : m_file_mode(false) , m_root(NULL)
+      : m_file_mode(false) , m_root(NULL),m_mode("asn1")
     {};
     parser(const parser &p)
     {};
@@ -87,7 +93,8 @@ class parser
   private:
     modules_type    m_modules;
     static parser  *m_instance;
-
+    std::string     m_mode;
+    bool            m_first_token; // Will be used to select right grammer
   protected:
    bool             m_debug_console;
    node            *m_root; 
index 27587d7f002918979ef06075a4956993a8dc3399..0111f6caaff693525b3994792690b0681001943b 100644 (file)
@@ -23,5 +23,17 @@ class parser_listener
   protected:  
 };
 
+/**
+ * @brief in addition to the root listener, the  mib listener
+ * recieves notifications regardinf mib objects
+ */
+class mib_listener : public parser_listener
+{
+  public:
+    mib_listener() {} ;
+
+    virtual void onObjectType(void ) {};
+};
+
 }
 #endif /*ASN1_PARSER_LISTENER_H*/
index 274636715f49e39efbfffb0673ae96f61734e306..8b1eda6c15fb6f4063cc9658e9ac903c57ecde23 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -32,29 +32,37 @@ enum optionIndex {
   UNKNOWN, HELP
   ,UML,ERULE
   ,FICHIER,OUTPUT,INCLUDE
-  ,PLANG,COMMENT,CODEC,OPTSPLIT,OPTDBG,OPT_END};
+  ,PLANG,OPTMODE,COMMENT,CODEC,OPTSPLIT,OPTDBG,OPT_END};
 /*----------------------------------------------------------------------------*/
 const option::Descriptor usage[] = {
  {UNKNOWN,      0, "", "", option::Arg::None,"Welcome to asn1p compiler (c) aeb"
                    " 2016-2018 " BUILD_TYPE " " BUILD_VERSION "\n"
                    "Usage asn1p [options]\n\texample:"
                    " asn1p -e ber -f toto.asn1 -I[path]\n"},
- {HELP,         0, "h",  "help",option::Arg::None,"--help,-h \tPrint help and quit."},
- {UML,          0, "u", "uml",  option::Arg::Optional,"--uml,-u \tGenerate UML model of asn1 model."},
- {ERULE,        0, "e", "ecoding_rule",  option::Arg::Required,"--encoding_rule ,-e \t Encoding rules to use"
+ {HELP,         0, "h", "help", option::Arg::None,"--help,-h \tPrint help and quit."},
+ {UML,          0, "u", "uml" , option::Arg::Optional,"--uml,-u \t"
+                   "Generate UML model of asn1 model."},
+ {ERULE,        0, "e", "ecoding_rule",  option::Arg::Required,"--encoding_rule ,-e \t"
+                   " Encoding rules to use"
                    " accepted ER: ber,per,oer,jer,xer "},
- {FICHIER,      0, "f", "file", option::Arg::Required,"--file,-f \tAsn1 input file to parse"},
- {OUTPUT,       0, "o", "ouput", option::Arg::Required,"--output,-o \toutput file without extension to be generated"},
- {INCLUDE,      0, "I", "include",     option::Arg::Required,"--include,-I\tInclude path to look for other asn1 files."},
+ {FICHIER,      0, "f", "file", option::Arg::Required,"--file,-f \t"
+                   "Asn1 or Mib input file to parse"},
+ {OUTPUT,       0, "o", "ouput", option::Arg::Required,"--output,-o \t"
+                   "output file without extension to be generated"},
+ {INCLUDE,      0, "I", "include",     option::Arg::Required,"--include,-I\t"
+                   "Include path to look for other asn1 files."},
  {PLANG,        0, "l", "language",     option::Arg::Required,"--language,-l\t"
-                   "Programming language cpp, uml, javascript, lds, sql [default: cpp]"},
+                   "Programming language generated: cpp, uml, javascript, lds, sql [default: cpp]"},
+ {OPTMODE,      0, "m", "mode", option::Arg::Required,"--mode,-m \t"
+                   "Parsing mode. asn1 or mib. Default is asn1"},
  {COMMENT,      0, "n", "comment",     option::Arg::Required,"--comment,-n\t"
                 "(true or ON)/(false or OFF) generate comment in source def true"},
  {CODEC,        0, "c", "codec",     option::Arg::Required,"--codec,-c\tCodecs"
                    " functions ON or OFF [default: OFF]"
  },
  {OPTSPLIT,     0, "s", "split",     option::Arg::None,"--split,-s\t"
-                   " put codec code in separated cpp files. Needed for huge definitions"
+                   " put codec code in separated cpp files."
+                   " Needed for huge definitions"
  },
  {OPTDBG,       0, "d", "debug",     option::Arg::Required,"--debug,-d\tconsole=1 "
                    " msg=1 debug messages in code parser=<1-8> parser debug traces"},
@@ -96,6 +104,47 @@ struct language_config
   bool    m_c;
 };
 
+/**
+ * Parse option. Return true if found.
+ * False otherwise
+ */
+template<typename T>
+bool retrieveOption(option::Option *_opt,T &_arg,const T _default)
+{
+    bool _ret = false;
+    _arg = _default;
+    if (_opt )
+    {
+        for (option::Option *opts = _opt;opts; opts = opts->next()) {
+            if (opts->arg)
+            {
+               _arg = atoi(opts->arg);
+               _ret = true;
+            }
+        }
+    }
+    return _ret;
+}
+
+template<>
+bool retrieveOption<std::string>(option::Option *_opt,std::string &_arg,const std::string _default)
+{
+    bool _ret = false;
+    _arg = _default;
+    if (_opt )
+    {
+        for (option::Option *opts = _opt;opts; opts = opts->next()) {
+            if (opts->arg)
+            {
+               _arg = std::string(opts->arg);
+               _ret = true;
+            }
+        }
+    }
+    return _ret;
+}
+
+
 
 /**
  * Main entry point
@@ -104,6 +153,7 @@ int main(int argc,char **argv)
 {
     std::map<std::string,std::string> module_map;
     std::string umlname;
+    std::string mode;
     asn1::parser::iterator it;
     asn1::parser *p = asn1::parser::instance();
     asn1::generator_config g_config;
@@ -133,6 +183,11 @@ int main(int argc,char **argv)
                 p->includes().push_back(std::string(opts->arg));
         }
     }
+    if (retrieveOption<std::string>(options[OPTMODE],mode,std::string("asn1")))
+    {
+        p->set_mode(mode);
+    }
+
     if (options[OPTSPLIT])
     {
           g_config.with_split_cpp(true);  
@@ -154,9 +209,9 @@ int main(int argc,char **argv)
         {
           g_config.with_codec(true);  
         } else
-             {
-              std::cerr<<"Wrong argument for CODEC"<<std::endl;
-             }
+        {
+          std::cerr<<"Wrong argument for CODEC"<<std::endl;
+        }
       }
     }
     /**
index 16ac1f78ba32d28ccd759dbf3c49d16f1886d4f0..0889db01149dfd83125055f01e4b98d6db8bd507 100644 (file)
@@ -65,7 +65,7 @@ struct member_desc {
   enum               type_flags m_flags;
   long               m_tmode;            /* tag mode EXPLICIT(1) or IMPLICIT(-1) */
   long               m_tag;              /* tag value id<<2 |class      */
-  int                m_member_offser;    /* Member offset               */
+  int                m_member_offset;    /* Member offset               */
   long               m_midx;             /* member index is structure   */
   struct descriptor *m_type;             /* member type descriptor      */
   const char        *m_name;             /* member str name for display */