From: Ebersold Date: Wed, 18 May 2022 21:06:49 +0000 (+0200) Subject: Better parsing. Added automatic adding files based in imports. Started mib module... X-Git-Url: https://git.ebersold.fr/?a=commitdiff_plain;h=c353a6983c79159d419ca1e0303b2191be1f1ba9;p=parser%2Fasn1.git Better parsing. Added automatic adding files based in imports. Started mib module declaration --- diff --git a/adt/asn1_meta.h b/adt/asn1_meta.h index dedb2c2..0c84ce6 100644 --- a/adt/asn1_meta.h +++ b/adt/asn1_meta.h @@ -21,6 +21,13 @@ namespace asn1 SNMP_MODULE_IDENT, /* Mib MODULE-IDENTITY */ SNMP_TEXTUAL_CONV, /* Mib TEXTUAL-CONVENTION */ SNMP_OBJECT_TYPE, /* Mib OBJECT-TYPE */ + SNMP_NOTIFICATION_TYPE, + SNMP_OBJECT_IDENTITY, + SNMP_TRAP_TYPE, + SNMP_OBJECT_GROUP, + SNMP_NOTIFICATION_GROUP, + SNMP_MODULE_COMPLIANCE, + SNMP_AGENT_COMPTABILITIES, MAX } id; inline meta(meta::id id = INVALID) : m_id(id) {}; diff --git a/adt/asn1_meta.inc b/adt/asn1_meta.inc index 0e0342a..00e3aa7 100644 --- a/adt/asn1_meta.inc +++ b/adt/asn1_meta.inc @@ -11,7 +11,17 @@ 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) +ASSIGNMENT(SNMP_MODULE_IDENT,mib_module_identity,assignment) +ASSIGNMENT(SNMP_TEXTUAL_CONV,mib_tc,assignment) +ASSIGNMENT(SNMP_OBJECT_TYPE,mib_object_type,assignment) +ASSIGNMENT(SNMP_NOTIFICATION_TYPE,mib_notification_type,assignment) +ASSIGNMENT(SNMP_OBJECT_IDENTITY,mib_object_identity,assignment) +ASSIGNMENT(SNMP_TRAP_TYPE,mib_trap_type,assignment) +ASSIGNMENT(SNMP_OBJECT_GROUP,mib_object_group,assignment) +ASSIGNMENT(SNMP_NOTIFICATION_GROUP,mib_notification_group,assignment) +ASSIGNMENT(SNMP_MODULE_COMPLIANCE,mib_module_compliance,assignment) +ASSIGNMENT(SNMP_AGENT_COMPTABILITIES,mib_agent_compatibilities,assignment) + + + #undef ASSIGNMENT diff --git a/adt/asn1_module.h b/adt/asn1_module.h index a243126..1d7b705 100644 --- a/adt/asn1_module.h +++ b/adt/asn1_module.h @@ -105,7 +105,26 @@ class module : public asn1::constructed return !m_s.compare(n->name()); }; -} +/** + * @brief mib_module is a module that defines mib objects. + * As is very different compared to an asn1 module + * + */ +class mib : public module +{ + private: + + public: + /// Default mib module constructor + mib(const char *_name); + /// Default mib module desctructor + virtual ~mib(); +}; + +} /* end of asn1 namespace */ + + + /** vim:et:sw=2:ts=2 diff --git a/adt/asn1_node_mib_leaf.h b/adt/asn1_node_mib_leaf.h new file mode 100644 index 0000000..3604c1d --- /dev/null +++ b/adt/asn1_node_mib_leaf.h @@ -0,0 +1,30 @@ +#ifndef ASN1_NODE_MIB_LEAF_H__ +#define ASN1_NODE_MIB_LEAF_H__ + + +/** + * TODO: Not sur if the type is appropriate. + * I'm more thinking of mib_object which is not + * 100% true either + * + */ +class mib_leaf : public constructed +{ + public: + typedef std::string syntax_type; + typedef std::string oid_type; + public: + /// Default constructor + mib_leaf(); + /// Default destructor + virtual ~mib_leaf() ; + + syntax_type get_syntax() { return m_syntax; } const; + protected: + oid_type m_oid; + syntax_type m_syntax; // There is a syntax +}; + + + +#endif diff --git a/adt/asn1_recursive_visitor.h b/adt/asn1_recursive_visitor.h index 1eb3802..e3d46a3 100644 --- a/adt/asn1_recursive_visitor.h +++ b/adt/asn1_recursive_visitor.h @@ -385,9 +385,17 @@ 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,{}) +DEF_TRAVERSE_ASSIGN(mib_module_identity,{}) +DEF_TRAVERSE_ASSIGN(mib_tc,{}) +DEF_TRAVERSE_ASSIGN(mib_object_type,{}) +DEF_TRAVERSE_ASSIGN(mib_notification_type,{}) +DEF_TRAVERSE_ASSIGN(mib_object_identity,{}) +DEF_TRAVERSE_ASSIGN(mib_trap_type,{}) +DEF_TRAVERSE_ASSIGN(mib_object_group,{}) +DEF_TRAVERSE_ASSIGN(mib_notification_group,{}) +DEF_TRAVERSE_ASSIGN(mib_module_compliance,{}) +DEF_TRAVERSE_ASSIGN(mib_agent_compatibilities,{}) + /* Implementation Traverse type */ diff --git a/libparser/asn1.l b/libparser/asn1.l index bb5e647..f1ec89f 100644 --- a/libparser/asn1.l +++ b/libparser/asn1.l @@ -174,7 +174,7 @@ ALL TOK(T_ALL) APPLICATION TOK(T_APPLICATION) AUTOMATIC TOK(T_AUTOMATIC) BEGIN TOK(T_BEGIN) -BITS TOK(T_BIT) +BITS TOK(T_BITS) BIT TOK(T_BIT) BMPString TOK(T_BMPString) @@ -287,12 +287,12 @@ IMPORTS { AGENT-COMPABILITIES SNMP_TOK(T_MACRO_NAME) { - {Identifier} NODE_TOK(T_IDENTIFIER) - {String_Literal} NODE_TOK(T_IDENTIFIER) - {CapitalReference} NODE_TOK(T_CAPITALREFERENCE) + {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_LBRACET) + "}" TOK(T_RBRACET) "," TOK(T_COMMA) ";" { yy_pop_state(); @@ -327,8 +327,8 @@ IMPORTS { UNITS TOK(T_UNITS) VARIABLES TOK(T_VARIABLES) WRITE-SYNTAX TOK(T_WRITE_SYNTAX) - {Identifier} NODE_TOK(T_IDENTIFIER) - {CapitalReference} NODE_TOK(T_CAPITALREFERENCE) + {Identifier} NODE_TOK(T_IDENTIFIER) + {CapitalReference} NODE_TOK(T_CAPITALREFERENCE) {TypeReference} NODE_TOK(T_TYPEREFERENCE) \"[^\"]*\" { /* QUOTED STRING */ yylval->node = new asn1::node(yytext); diff --git a/libparser/asn1.y b/libparser/asn1.y index 5d05509..2478924 100644 --- a/libparser/asn1.y +++ b/libparser/asn1.y @@ -174,6 +174,8 @@ static asn1::classdef *gCurrentClassDef = NULL; %} +%right T_ASSIGN + %token T_ABSENT %token T_ABSTRACT %token T_ABSTRACT_SYNTAX @@ -612,6 +614,11 @@ import: $3->identifier($5); $3->name($5->name()); m->enter_symbol($3,$3->type_id()()); + if (asn1::parser::instance()->is_mode_mib()) + { // New attempt to add files direcly for paring + asn1::parser *p = asn1::parser::instance(); + p->add_file($5->name()); + } } ; @@ -2197,6 +2204,9 @@ type: opt_tag builtin_type opt_constraint_def { $$->as_typenode()->constraint($3); $$->tag($1); } + | T_BITS { + ASN_LOG_DEBUG( "type: T_BITS"); + } ; builtin_type: boolean_def @@ -3262,39 +3272,39 @@ defined_syntax_token: snmp_assignment: snmp_module_identity { ASN_LOG_DEBUG("snmp_assignment :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_module_identity_assignment($1->name()); } | snmp_textual_convention { ASN_LOG_DEBUG("snmp_textual_convention:"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_tc_assignment($1->name()); } | snmp_object_type { ASN_LOG_DEBUG("snmp_object_type :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_object_type_assignment($1->name()); } | snmp_notification_type { ASN_LOG_DEBUG("snmp_notification_type :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_notification_type_assignment($1->name()); } | snmp_trap_type { ASN_LOG_DEBUG("snmp_notification_type :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_trap_type_assignment($1->name()); } | snmp_notification_group { ASN_LOG_DEBUG("snmp_notification_group :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_notification_group_assignment($1->name()); } | snmp_module_compliance { ASN_LOG_DEBUG("snmp_object_type :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_module_compliance_assignment($1->name()); } | snmp_object_group { ASN_LOG_DEBUG("snmp_object_group :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_object_group_assignment($1->name()); } | snmp_object_identity { ASN_LOG_DEBUG("snmp_object_identity :"); - $$ = new asn1::snmp_mib_identity_assignment($1->name()); + $$ = new asn1::mib_object_identity_assignment($1->name()); } ; @@ -3318,6 +3328,7 @@ snmp_module_identity: T_IDENTIFIER T_MACRO_NAME { ASN_LOG_DEBUG("snmp_module_identity: %s end",$1->name().c_str()); asn1::module *m = get_current_module(); asn1::node *ids = m->leave_context(); + ids->set_parent(m->current_context()); $$ = ids; $$ = $1; } @@ -3327,7 +3338,7 @@ snmp_mi_attributes: snmp_mi_last_update snmp_mi_organization snmp_mi_contact snmp_description - snmp_mi_revisions { + snmp_mi_revision_part { ASN_LOG_DEBUG("snmp_mi_attributes: end"); } ; @@ -3345,6 +3356,10 @@ snmp_mi_contact: T_CONTACT_INFO T_QUOTED_STRING { } ; +snmp_mi_revision_part: /*Empty*/ + | snmp_mi_revisions +; + snmp_mi_revisions: snmp_mi_revision { } | snmp_mi_revision snmp_mi_revisions { @@ -3387,8 +3402,8 @@ snmp_tc_reference: /* can be null */ }; snmp_tc_syntax: /* can be null */ - | T_SYNTAX type_assign_right opt_constraint_def { -}; + | T_SYNTAX snmp_syntax +; /** SNMP OBJECT-TYPE */ snmp_object_type: T_IDENTIFIER T_MACRO_OBJECT_TYPE snmp_ot_attributes @@ -3404,9 +3419,8 @@ snmp_ot_attributes: snmp_ot_syntax snmp_ot_access snmp_ot_status snmp_description - snmp_ot_index - snmp_ot_augments snmp_ot_reference + snmp_ot_index_part snmp_ot_defval ; @@ -3436,13 +3450,11 @@ snmp_ot_status: T_STATUS T_IDENTIFIER { } ; -snmp_ot_augments: /**/ - | T_AUGMENTS T_LBRACET snmp_ot_indexes T_RBRACET { - } -; -snmp_ot_index: /**/ +snmp_ot_index_part: /**/ | T_INDEX T_LBRACET snmp_ot_indexes T_RBRACET { } + | T_AUGMENTS T_LBRACET snmp_ot_indexes T_RBRACET { + } ; snmp_ot_indexes: T_IDENTIFIER { } @@ -3514,6 +3526,8 @@ snmp_mc_module: T_MODULE snmp_mc_module_name snmp_mc_module_name: /* Empty */ | T_IDENTIFIER + | T_TYPEREFERENCE + | T_CAPITALREFERENCE ; snmp_mc_mandatory_groups: T_MANDATORY_GROUPS T_LBRACET snmp_mc_mandatories T_RBRACET @@ -3548,8 +3562,7 @@ snmp_mc_object: T_OBJECT T_IDENTIFIER /* Need to find out what kind of syntax it is about here */ snmp_mc_obj_syntax: /**/ - | T_SYNTAX type - | T_SYNTAX T_BITS T_LBRACET constant_list T_RBRACET + | T_SYNTAX snmp_syntax | T_WRITE_SYNTAX type_assign_right opt_constraint_def ; @@ -3594,11 +3607,15 @@ snmp_notification_type: T_IDENTIFIER T_MACRO_NOTIFICATION_TYPE $$ = $1; }; -snmp_nt_attributes: snmp_objects +snmp_nt_attributes: snmp_nt_objects snmp_status snmp_description { }; +snmp_nt_objects: snmp_objects + | /* empty*/ +; + /** SNMP NOTIFICATION-GROUP */ snmp_notification_group: T_IDENTIFIER T_MACRO_NOTIFICATION_GROUP snmp_ng_attributes { @@ -3641,6 +3658,14 @@ snmp_oi_attributes: snmp_description { }; + /* SNMP SYNTAX rule. Based on type assign right without parameters*/ + +snmp_syntax: complex_type_reference opt_constraint_def + | complex_type_reference T_LBRACET constant_list T_RBRACET + | builtin_type opt_constraint_def + | T_BITS T_LBRACET constant_list T_RBRACET +; + /* * */ diff --git a/libparser/asn1_parser.cpp b/libparser/asn1_parser.cpp index f8f26a8..cf89039 100644 --- a/libparser/asn1_parser.cpp +++ b/libparser/asn1_parser.cpp @@ -78,6 +78,7 @@ int _asn1_wrap() asn1p->files().pop_back(); return 0; } else { + std::cout<<"Not Found File : "<##event (m_c); \ + } \ + asn1::##type *m_c; \ +}; + +#define NOTIFY_LISTENERS(call,arg) \ + std::for_each(m_listeners.begin() \ + , m_listeners.end() \ + ,call (arg)); + + +// Example: CALL_LISTENER(onConstraint,constraint) + // struct got_constraint { @@ -252,6 +272,18 @@ parser::got_act_parameter(asn1::node *c) pl->add_parameter(c); } + +void +parser::add_file(const std::string &_from) +{ + // Be sur the file is not already in there + if (std::find(m_files.begin(),m_files.end(),_from) == m_files.end()) + { + std::cout<<"ADD_FILE: "<<_from<