Commit 6d97ce95 authored by Denis Filatov's avatar Denis Filatov Committed by v0-e

fix WITH DESCENDANTS; tests for WITH DESCENDANTS

parent d3faf7fc
......@@ -149,8 +149,15 @@ asn1f_lookup_module(arg_t *arg, const char *module_name, const asn1p_oid_t *oid,
TQ_FOR(mod, &(arg->asn->modules), mod_next) {
if(oid) {
if(mod->module_oid) {
if(0 == asn1p_oid_compare_opt(oid,
mod->module_oid, oid_option)) {
int r = asn1p_oid_compare(oid, mod->module_oid);
if(oid_option == XPT_WITH_SUCCESSORS) {
if(r == oid->arcs_count && r == mod->module_oid->arcs_count) /* positive and last arc */
r = 0;
} else if(oid_option == XPT_WITH_DESCENDANTS) {
if(oid->arcs_count == (-1 - r))
r = 0;
}
if(0 == r) {
/* Match! Even if name doesn't. */
oid = mod->module_oid;
ret = mod;
......
......@@ -109,18 +109,3 @@ asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b) {
return 1+i;
}
}
int
asn1p_oid_compare_opt(const asn1p_oid_t *a, const asn1p_oid_t *b, int oid_options) {
int r = asn1p_oid_compare(a, b);
if(oid_options == OID_WITH_SUCCESSORS) {
if(r == a->arcs_count && r == b->arcs_count) /* positive and last arc */
r = 0;
} else if(oid_options == OID_WITH_DESCENDANTS) {
if(a->arcs_count == (0 - r))
r = 0;
}
return r;
}
......@@ -63,9 +63,4 @@ void asn1p_oid_free(asn1p_oid_t *);
*/
int asn1p_oid_compare(const asn1p_oid_t *a, const asn1p_oid_t *b);
#define OID_WITH_SUCCESSORS 1
#define OID_WITH_DESCENDANTS 2
int asn1p_oid_compare_opt(const asn1p_oid_t *a, const asn1p_oid_t *b, int oid_option);
#endif /* ASN1_PARSER_OID_H */
......@@ -23,7 +23,10 @@ typedef struct asn1p_xports_s {
asn1p_value_t *value; /* DefinedValue */
} identifier;
int option; /* (0) | WITH SUCCESSORS (1) | WITH DESCENDANTS (2) */
enum asn1p_import_option {
XPT_WITH_SUCCESSORS = 1,
XPT_WITH_DESCENDANTS
} option;
/*
* Number of entities to import.
......
......@@ -769,10 +769,10 @@ ImportsElement:
ImportSelectionOption:
TOK_WITH TOK_SUCCESSORS {
$$ = OID_WITH_SUCCESSORS;
$$ = XPT_WITH_SUCCESSORS;
}
| TOK_WITH TOK_DESCENDANTS {
$$ = OID_WITH_DESCENDANTS;
$$ = XPT_WITH_DESCENDANTS;
}
;
......
-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .121
ModuleIMPORTS
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 161 }
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
IMPORTS ImportedType
FROM ImportedModule1
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 163 major-version-1(1) }
WITH DESCENDANTS
;
Type ::= ImportedType
END
ImportedModule1
{ iso org(3) dod(6) internet (1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 163 major-version-1(1) super-minor-version(1) super-minor-version(1)}
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
IMPORTS -- nothing --;
ImportedType ::= INTEGER
END
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment