From: Ebersold Date: Sun, 25 Sep 2022 16:49:01 +0000 (+0200) Subject: continued working on mib parsing X-Git-Url: https://git.ebersold.fr/?a=commitdiff_plain;ds=inline;p=parser%2Fasn1.git continued working on mib parsing --- diff --git a/adt/asn1_node.cpp b/adt/asn1_node.cpp index 7c297eb..a69d370 100644 --- a/adt/asn1_node.cpp +++ b/adt/asn1_node.cpp @@ -33,9 +33,8 @@ node::node(const std::string name, meta m ) : m_is_generated(CL_GREEN) , , m_constraints("VIDE") , m_identifier(NULL) ,m_parameters(NULL) - ,m_value(NULL) ,m_type(NULL) - ,m_parent(NULL) + ,m_parent(NULL) ,m_marker(marker_type::FL_NONE) { m_tag.m_mode = tag_type::TM_DEFAULT; @@ -68,10 +67,9 @@ node::node(const std::string name, type t ,meta m ) : m_is_generated(CL_GREEN), ,m_constraints("VIDE") ,m_identifier(NULL) ,m_parameters(NULL) - ,m_parent(NULL) - ,m_value(NULL) - ,m_type(NULL) - ,m_marker(marker_type::FL_NONE) + ,m_parent(NULL) + ,m_type(NULL) + ,m_marker(marker_type::FL_NONE) { m_marker.m_flags = marker_type::FL_NONE; m_tag.m_mode = tag_type::TM_DEFAULT; @@ -243,10 +241,9 @@ node::node(const node &n) : m_is_generated(n.m_is_generated),m_meta(n.m_meta),m_ ,m_identifier(NULL) ,m_tag(n.m_tag) ,m_parameters(NULL) - ,m_value(n.m_value) ,m_type(n.m_type) ,m_uid(n.m_uid) - ,m_parent(n.m_parent) + ,m_parent(n.m_parent) { } @@ -259,7 +256,6 @@ node::node(const char *name) :m_is_generated(CL_GREEN) , m_ref(0), m_name(name) ,m_constraints("") ,m_identifier(NULL) ,m_parameters(NULL) - ,m_value(NULL) ,m_type(NULL) ,m_parent(NULL) ,m_marker(marker_type::FL_NONE) diff --git a/adt/asn1_node.h b/adt/asn1_node.h index 23abb71..3ce8175 100644 --- a/adt/asn1_node.h +++ b/adt/asn1_node.h @@ -208,10 +208,6 @@ namespace asn1 inline void type_id(asn1::type::id t) { m_type_id = t; } inline type type_id() const {return m_type_id;}; - - inline asn1::value *value() const { return m_value;}; - - inline void value(asn1::value *v) {m_value =v;}; // Meta stuff inline void meta_id(asn1::meta::id m) {m_meta = m;} @@ -329,7 +325,6 @@ namespace asn1 node *m_next; node *m_type; // 2011/05/03 must be deprecated - asn1::value *m_value; // Should become part of valuetype node *m_identifier; asn1::constructed *m_parameters; asn1::constraint m_constraints; diff --git a/adt/asn1_node_assignment.cpp b/adt/asn1_node_assignment.cpp index 7911d2a..48d5137 100644 --- a/adt/asn1_node_assignment.cpp +++ b/adt/asn1_node_assignment.cpp @@ -44,6 +44,16 @@ assignment::get_objectset() const return reinterpret_cast(type_node()); } +constraint * +assignment::get_constraint() const +{ + valueset *v = reinterpret_cast(type_node()); + if (v != nullptr ) + return v->get_constraint(); + return nullptr; +} + + parameter * assignment::have_parameter(asn1::node *actp,long &idx) { diff --git a/adt/asn1_node_assignment.h b/adt/asn1_node_assignment.h index 6d07141..b59b5d6 100644 --- a/adt/asn1_node_assignment.h +++ b/adt/asn1_node_assignment.h @@ -24,8 +24,11 @@ class assignment : public node // Should replace node with typenode void set_type(asn1::node *n); - typenode *get_type() const; - objectset *get_objectset() const; + typenode *get_type() const; + + objectset *get_objectset() const; + /// a valueset assignement content is constraints + constraint *get_constraint() const; /** * node is an act_parameter ... */ @@ -34,6 +37,7 @@ class assignment : public node }; #define ASSIGNMENT(tp,cls,parent) \ + class cls; \ class cls ## _assignment : public parent \ {\ public:\ @@ -44,6 +48,11 @@ class assignment : public node {}; \ ~cls ## _assignment () {}; \ cls ## _assignment *clone() { return new cls ## _assignment(*this);}; \ + private: \ + cls * m_## cls ; \ + public: \ + cls * aget_## cls() const {return m_## cls; } \ + void set_## cls( cls *_v ) { m_## cls = _v ; } ; \ }; #include "asn1_meta.inc" diff --git a/adt/asn1_node_field.cpp b/adt/asn1_node_field.cpp index 5cc49ea..7817390 100644 --- a/adt/asn1_node_field.cpp +++ b/adt/asn1_node_field.cpp @@ -149,5 +149,14 @@ classfield_osf::get_type() const return reinterpret_cast(type_node()); } +value * +classfield_osf::get_value() const +{ + asn1::value *v = reinterpret_cast(type_node()); + std::cout<<"classfield_osf::get_value "<= 1) + { + return *(m_constraints.begin()); + } + return NULL; +} + /** * objectset */ @@ -94,4 +104,16 @@ objectset::set_classref(asn1::typeref *ref) m_classref = ref; } + +asn1::constraint * +objectset::get_constraint() const +{ + if (m_constraints.size() >= 1) + { + return *(m_constraints.begin()); + } + return NULL; +} + + } diff --git a/adt/asn1_node_valuetype.h b/adt/asn1_node_valuetype.h index e04815b..82d54b4 100644 --- a/adt/asn1_node_valuetype.h +++ b/adt/asn1_node_valuetype.h @@ -22,6 +22,9 @@ class objectset_assignment; */ class valuetype : public node { + private: + // No copy contructor + valuetype(const valuetype &_b) : node(_b) {}; public: valuetype(asn1::value *_val,meta _m = meta::VALUE); @@ -36,7 +39,12 @@ class valuetype : public node void value_long(long long l) ; long long value_long() const ; - protected: + /// New from node + inline asn1::value *value() const { return m_value;}; + + inline void value(asn1::value *v) {m_value =v;}; + private: + asn1::value *m_value; // Should become part of valuetype }; /** @@ -56,6 +64,10 @@ class valueset : public typenode * Specific for Rose .... */ asn1::typeref *get_typeref(); + /** + * return constraint from value set + */ + asn1::constraint *get_constraint() const; protected: }; @@ -80,6 +92,10 @@ class objectset : public typenode asn1::typeref *get_classref() const { return m_classref; } + /** + * return constraint from value set + */ + asn1::constraint *get_constraint() const; protected: asn1::typeref *m_classref; diff --git a/adt/asn1_recursive_visitor.h b/adt/asn1_recursive_visitor.h index e3d46a3..ea484c4 100644 --- a/adt/asn1_recursive_visitor.h +++ b/adt/asn1_recursive_visitor.h @@ -359,9 +359,9 @@ DEF_TRAVERSE_ASSIGN(typeref,{}) DEF_TRAVERSE_ASSIGN(type,{}) DEF_TRAVERSE_ASSIGN(value,{}) DEF_TRAVERSE_ASSIGN(valueset,{ - if ( asn1::value *v = S->value()) + if ( asn1::constraint *_constraint = S->get_constraint()) { - traverse_constraint(v->m_constraint); + traverse_constraint(_constraint); } }) DEF_TRAVERSE_ASSIGN(object,{ @@ -418,16 +418,16 @@ DEF_TRAVERSE_TYPE(exportvar,{}) DEF_TRAVERSE_TYPE(extensible,{}) DEF_TRAVERSE_TYPE(components_of,{}) DEF_TRAVERSE_TYPE(valueset,{ - if ( asn1::value *v = S->value()) + if ( asn1::constraint *v = S->get_constraint()) { - traverse_constraint(v->m_constraint); + traverse_constraint(v); } }) DEF_TRAVERSE_TYPE(objectset,{ - if ( asn1::value *v = S->value()) + if ( asn1::constraint *v = S->get_constraint()) { - traverse_constraint(v->m_constraint); + traverse_constraint(v); } }) @@ -474,9 +474,15 @@ DEF_TRAVERSE_CLASSFIELD(classfield_osf,{ { if (f) { - if ( asn1::value *v = f->value()) + // f is a node. that contains a value + // as node does not contain value anymore. It's either valueset + // or object set + if ( asn1::constraint *v = dynamic_cast(f)->get_constraint()) { - traverse_constraint(v->m_constraint); + traverse_constraint(v); + } else + { + std::cerr<<"recursive travers : classfield_ofs "<identifier_name().c_str()); os<<"#define "<identifier_cpp_name(); - os<<"\t "<value()->cpp_name()<<""; + //os<<"\t "<value()->cpp_name()<<""; + os<<"\t "<(n)->aget_value()->cpp_name()<<""; } break; case asn1::type::ASN1_REFERENCE: @@ -416,7 +417,8 @@ void generate_header::gen_const(std::ostream &os,asn1::node *n) break; default: { - asn1::value *v = n->value(); + //asn1::value *v = n->value(); + asn1::value *v = dynamic_cast(n)->aget_value(); GEN_LOG_DEBUG("default case %s\n",type->identifier_name().c_str()); assert(v != NULL); switch (v->type) diff --git a/libgen/asn1_gen_optimizer.cpp b/libgen/asn1_gen_optimizer.cpp index 94d3af3..d099a0d 100644 --- a/libgen/asn1_gen_optimizer.cpp +++ b/libgen/asn1_gen_optimizer.cpp @@ -306,7 +306,8 @@ class optimize_phase1 : public asn1::recursive_visitor ); if (v && v->m_node->type_id()() == 0) { - asn1::constructed *vn = v->m_node->value()->m_node->as_constructed(); + //asn1::constructed *vn = v->m_node->value()->m_node->as_constructed(); + asn1::constructed *vn = dynamic_cast(v->m_node)->value()->m_node->as_constructed(); std::cerr<<__FUNCTION__<<" Proccess ftvf because of wrong id "; std::cerr<<"<"<m_node->cpp_name()<<"> "<m_node)).name()< void visit_choice(asn1::choice *type) { - asn1::value *val = type->value(); + //asn1::value *val = type->value(); + asn1::valuetype *vt = reinterpret_cast(type); + asn1::value *val = (vt != nullptr)?vt->value():nullptr; + std::cout<<"ftvf::visit_choice type is :"<cpp_name()<<" "<cpp_name()<m_node->type_id()()) { diff --git a/libgen/cpp/cghpph_enumerated.cpp b/libgen/cpp/cghpph_enumerated.cpp index 6c5ecf3..2f5e263 100644 --- a/libgen/cpp/cghpph_enumerated.cpp +++ b/libgen/cpp/cghpph_enumerated.cpp @@ -81,7 +81,8 @@ void cghpph_enumerated::generate_members( ) m_os<<"\tenum e"<< m_structName<<" {\n"; for (; it != m_enumerated.end();++it) { - asn1::value *num = (*it)->value(); + asn1::valuetype *vt = dynamic_cast(*it); + asn1::value *num = (vt == nullptr)?NULL:vt->value(); if (it != m_enumerated.begin() ) m_os<<",\n"; m_os<<"\t\t"<<(*it)->cpp_name()<<" "; diff --git a/libparser/asn1.l b/libparser/asn1.l index f1ec89f..0654977 100644 --- a/libparser/asn1.l +++ b/libparser/asn1.l @@ -113,6 +113,7 @@ void _asn1_error(const char *s) { %x snmp_imports %x snmp %x snmp_quoted_string +%x snmp_ignore /* */ Digits [0-9]+ @@ -125,7 +126,7 @@ Real [-+]?[0-9]+[.]?([eE][-+]?)?[0-9]+ Char ([^\n\t\"\'\\]) Char_Literal "'"({Char}|\")"'" String_Literal \"({Char}|"'")*\" -HString '[0-9A-F \r\r\v\f\n]+'H +HString '[0-9A-Fa-f \r\r\v\f\n]+'[Hh] BString '[01 \t\r\v\f\n]+'B Identifier [a-z][a-zA-Z0-9]*([-][a-zA-Z0-9]+)* CapitalReference [A-Z][A-Z0-9]*([-][A-Z0-9]+)* @@ -171,7 +172,7 @@ wsp [\t\r\v\f\n ] ABSTRACT-SYNTAX TOK(T_ABSTRACT_SYNTAX) ALL TOK(T_ALL) ANY TOK(T_ANY) -APPLICATION TOK(T_APPLICATION) +APPLICATION TOK(T_APPLICATION) AUTOMATIC TOK(T_AUTOMATIC) BEGIN TOK(T_BEGIN) BITS TOK(T_BITS) @@ -212,7 +213,7 @@ EMBEDDED {HString} TOK(T_hstring) IA5String TOK(T_IA5String) IDENTIFIER TOK(T_STR_IDENTIFIER) -IMPLICIT TOK(T_IMPLICIT) +IMPLICIT TOK(T_IMPLICIT) IMPLIED TOK(T_IMPLIED) IMPORTS { if (gParser->is_mode_mib()) @@ -244,7 +245,7 @@ IMPORTS { PLUS-INFINITY PRESENT TOK(T_PRESENT) PrintableString TOK(T_PrintableString) -PRIVATE +PRIVATE REAL TOK(T_REAL) RELATIVE-OID TOK(T_RELATIVE_OID) RELATIVE-OID-IRI TOK(T_RELATIVE_OID_IRI) @@ -263,7 +264,7 @@ IMPORTS { UNION TOK(T_UNION) UNITS TOK(T_UNITS) UNIQUE TOK(T_UNIQUE) -UNIVERSAL TOK(T_UNIVERSAL) +UNIVERSAL TOK(T_UNIVERSAL) UniversalString TOK(T_UniversalString) UTCTime TOK(T_UTCTime) @@ -284,8 +285,10 @@ IMPORTS { OBJECT-GROUP SNMP_TOK(T_MACRO_OBJECT_GROUP) NOTIFICATION-GROUP SNMP_TOK(T_MACRO_NOTIFICATION_GROUP) MODULE-COMPLIANCE SNMP_TOK(T_MACRO_MODULE_COMPLIANCE) -AGENT-COMPABILITIES SNMP_TOK(T_MACRO_NAME) - +AGENT-CAPABILITIES SNMP_TOK(T_MACRO_NAME) +MACRO { yy_push_state(snmp_ignore); + return T_MACRO; + } { {Identifier} NODE_TOK(T_IDENTIFIER) {String_Literal} NODE_TOK(T_IDENTIFIER) @@ -340,6 +343,10 @@ IMPORTS { {wsp}+ /* ignore whitespace*/ } +{ + END { yy_pop_state(); /* Leave macro */ return T_END; } + . { printf("%s",yytext);} +} {Identifier} NODE_TOK(T_IDENTIFIER) {String_Literal} NODE_TOK(T_IDENTIFIER) @@ -361,8 +368,8 @@ IMPORTS { "<" TOK(T_LT) "@" TOK(T_AT) "!" TOK(T_EXCLAMATION) -"[" TOK(T_LBRACKET) -"]" TOK(T_RBRACKET) +"[" TOK(T_LBRACKET) +"]" TOK(T_RBRACKET) "{" TOK(T_LBRACET) "}" TOK(T_RBRACET) ")" TOK(T_RPARENTHESES) diff --git a/libparser/asn1.y b/libparser/asn1.y index 2478924..3bff06e 100644 --- a/libparser/asn1.y +++ b/libparser/asn1.y @@ -234,6 +234,7 @@ static asn1::classdef *gCurrentClassDef = NULL; %token T_INTERSECTION %token T_LAST_UPDATED %token T_LT +%token T_MACRO %token T_MACRO_NAME %token T_MACRO_NOTIFICATION_TYPE %token T_MACRO_NOTIFICATION_GROUP @@ -933,13 +934,16 @@ tag_type: delete $2; } ; +/* -tag: tag_type { $$ = $1; $$.m_set = true; } - | T_LBRACKET tag_type T_RBRACKET { + +*/ +tag: + T_LBRACKET tag_type T_RBRACKET { ASN_LOG_DEBUG("tag: tag_type 1 [%d,%ld] ",$2.m_class,$2.m_value); $$ = $2; $$.m_set = true; @@ -976,8 +980,16 @@ opt_tag: default: T_DEFAULT value { ASN_LOG_DEBUG("default: with value"); $$ = new asn1::node::marker_type(asn1::node::marker_type::FL_DEFAULT); - aeb::intrusive_ptr p($2->value()); - $$->m_value1 = p; + asn1::valuetype *vt= dynamic_cast($2); + if (vt ) + { + aeb::intrusive_ptr p(vt->value()); + $$->m_value1 = p; + }else + { + asn1::object_identifier *oid = $2->as_object_identifier(); + ASN_LOG_ERROR("default: with value BUG value is an oid"); + } } ; @@ -2527,33 +2539,36 @@ value_assignment: , $1->name().c_str()); asn1::node *i = new asn1::node("CONST STRING",asn1::meta::VALUE); i->type_id(asn1::type::ASN1_STRING); - $$ = new asn1::value_assignment($1->name()); + asn1::value_assignment *va = new asn1::value_assignment($1->name()); + $$ = va; $4->identifier($$); i->identifier($$); $$->type_node(i); - $$->value(new asn1::value(asn1::value::VT_STRING)); + va->set_value(new asn1::value(asn1::value::VT_STRING)); delete($1); } | identifier T_INTEGER T_ASSIGN value { ASN_LOG_WARNING("value_assignment : ident %s type INTEGER value=%s TO BE FINALIZED",$1->name().c_str(),$4->name().c_str()); asn1::node *i = $4; - $$ = new asn1::value_assignment($1->name()); + asn1::value_assignment *va = new asn1::value_assignment($1->name()); + $$ = va; i->identifier($$); $$->type_node(i); //TODO remove $$->meta_id(asn1::meta::VALUE); - $$->value($4->value()); + va->set_value(dynamic_cast($4)->value()); delete($1); } | identifier T_TYPEREFERENCE T_ASSIGN value { ASN_LOG_WARNING("value_assignment : ident %s type=%s value=%s TO BE FINALIZED",$1->name().c_str(),$2->name().c_str(),$4->name().c_str()); asn1::node *tr = new asn1::typeref( new asn1::simple_reference($2->name())); delete($2); - $$ = new asn1::value_assignment($1->name()); + asn1::value_assignment *va = new asn1::value_assignment($1->name()); + $$ = va; tr->identifier($$); $$->type_node(tr); if ($4->meta_id()() == asn1::meta::VALUE) { - $$->value($4->value()); + va->set_value(dynamic_cast($4)->value()); } delete($1); } @@ -2562,14 +2577,15 @@ value_assignment: ASN_LOG_WARNING("value_assignment : N ident %s type=%s value=%s TO BE FINALIZED",$1->name().c_str(),$2->name().c_str(),$5->name().c_str()); asn1::node *tr = new asn1::typeref( new asn1::simple_reference($2->name())); delete($2); - $$ = new asn1::value_assignment($1->name()); + asn1::value_assignment *va = new asn1::value_assignment($1->name()); + $$ = va; tr->identifier($$); tr->meta_id(asn1::meta::TYPEREF); tr->type_id(asn1::type::ASN1_REFERENCE); $$->type_node(tr); if ($5->meta_id()() == asn1::meta::VALUE) { - $$->value($5->value()); + va->set_value(dynamic_cast($5)->value()); } delete($1); } @@ -2622,10 +2638,10 @@ value: builtin_value { | defined_value { ASN_LOG_DEBUG("value: defined_value : %s",$1->name().c_str()); + $$ = $1; $$->meta_id(asn1::meta::VALUE); asn1::value *v = new asn1::value($1->name()); - $$->value(v); - $$ = $1; + dynamic_cast($$)->value(v); } | value_from_object { ASN_LOG_DEBUG("value: value_from_object .."); @@ -3305,6 +3321,9 @@ snmp_assignment: snmp_module_identity | snmp_object_identity { ASN_LOG_DEBUG("snmp_object_identity :"); $$ = new asn1::mib_object_identity_assignment($1->name()); + } + | snmp_macro { + $$ = new asn1::mib_object_identity_assignment($1->name()); } ; @@ -3468,9 +3487,11 @@ snmp_ot_reference: /**/ ; snmp_ot_defval: /*NULL */ - | T_DEFVAL T_LBRACET T_IDENTIFIER T_RBRACET { + | T_DEFVAL T_LBRACET value T_RBRACET { + ASN_LOG_DEBUG("snmp_ot_defval: TODO"); } - | T_DEFVAL T_LBRACET T_NUM T_RBRACET { + | T_DEFVAL T_LBRACET T_QUOTED_STRING T_RBRACET { + ASN_LOG_DEBUG("snmp_ot_defval: TODO"); } ; @@ -3665,6 +3686,34 @@ snmp_syntax: complex_type_reference opt_constraint_def | builtin_type opt_constraint_def | T_BITS T_LBRACET constant_list T_RBRACET ; +snmp_macro: T_MACRO_NAME T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_OBJECT_IDENTITY T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_OBJECT_TYPE T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_NOTIFICATION_TYPE T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_TRAP_TYPE T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_TC T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_OBJECT_GROUP T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_NOTIFICATION_GROUP T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } + | T_MACRO_MODULE_COMPLIANCE T_MACRO T_END { + ASN_LOG_DEBUG("snmp smi MACRO to be ignored:"); + } +; /* *