summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/coding.c4
-rw-r--r--lib/decoding.c20
-rw-r--r--lib/element.c2
-rw-r--r--lib/int.h1
-rw-r--r--lib/parser_aux.c18
-rw-r--r--lib/parser_aux.h13
-rw-r--r--lib/structure.c22
7 files changed, 48 insertions, 32 deletions
diff --git a/lib/coding.c b/lib/coding.c
index 9b90477..dc79fcc 100644
--- a/lib/coding.c
+++ b/lib/coding.c
@@ -1246,7 +1246,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
continue;
}
else
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
move = UP;
}
if (move == UP)
@@ -1320,7 +1320,7 @@ asn1_der_coding (asn1_node element, const char *name, void *ider, int *len,
move = UP;
}
if (move == UP)
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
*len = counter;
diff --git a/lib/decoding.c b/lib/decoding.c
index 54f0167..c79a5c4 100644
--- a/lib/decoding.c
+++ b/lib/decoding.c
@@ -622,7 +622,7 @@ _asn1_delete_not_used (asn1_node node)
{
p2 = _asn1_find_left (p);
if (!p2)
- p2 = _asn1_find_up (p);
+ p2 = _asn1_get_up (p);
}
asn1_delete_structure (&p);
p = p2;
@@ -645,7 +645,7 @@ _asn1_delete_not_used (asn1_node node)
{
while (1)
{
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
if (p == node)
{
p = NULL;
@@ -929,7 +929,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len,
{
if (p->type & CONST_SET)
{
- p2 = _asn1_find_up (p);
+ p2 = _asn1_get_up (p);
len2 = p2->tmp_ival;
if (len2 == -1)
{
@@ -985,7 +985,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len,
if ((p->type & CONST_OPTION) || (p->type & CONST_DEFAULT))
{
- p2 = _asn1_find_up (p);
+ p2 = _asn1_get_up (p);
len2 = p2->tmp_ival;
if (counter == len2)
{
@@ -1048,7 +1048,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len,
if ((p->type & CONST_OPTION) || (p->type & CONST_DEFAULT))
{
- p2 = _asn1_find_up (p);
+ p2 = _asn1_get_up (p);
len2 = p2->tmp_ival;
if ((len2 != -1) && (counter > len2))
@@ -1463,7 +1463,7 @@ asn1_der_decoding (asn1_node * element, const void *ider, int ider_len,
move = UP;
}
if (move == UP)
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
_asn1_delete_not_used (*element);
@@ -1639,7 +1639,7 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element)
break;
}
- p3 = _asn1_find_up (p);
+ p3 = _asn1_get_up (p);
if (!p3)
{
@@ -1659,8 +1659,8 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element)
(p3->value == NULL))
{
- p3 = _asn1_find_up (p);
- p3 = _asn1_find_up (p3);
+ p3 = _asn1_get_up (p);
+ p3 = _asn1_get_up (p3);
if (!p3)
{
@@ -1795,7 +1795,7 @@ asn1_expand_any_defined_by (asn1_node definitions, asn1_node * element)
{
while (1)
{
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
if (p == *element)
{
p = NULL;
diff --git a/lib/element.c b/lib/element.c
index ac30e46..c2b7107 100644
--- a/lib/element.c
+++ b/lib/element.c
@@ -52,7 +52,7 @@ _asn1_hierarchical_name (asn1_node node, char *name, int name_size)
_asn1_str_cat (name, name_size, ".");
_asn1_str_cat (name, name_size, tmp_name);
}
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
if (name[0] == 0)
diff --git a/lib/int.h b/lib/int.h
index 82d0d3f..8cc79cc 100644
--- a/lib/int.h
+++ b/lib/int.h
@@ -51,6 +51,7 @@ struct asn1_node_st
unsigned int type; /* Node type */
unsigned char *value; /* Node value */
int value_len;
+ asn1_node up; /* Pointer to the parent node */
asn1_node down; /* Pointer to the son node */
asn1_node right; /* Pointer to the brother node */
asn1_node left; /* Pointer to the next list element */
diff --git a/lib/parser_aux.c b/lib/parser_aux.c
index 39e4046..32dfba0 100644
--- a/lib/parser_aux.c
+++ b/lib/parser_aux.c
@@ -419,7 +419,11 @@ _asn1_set_right (asn1_node node, asn1_node right)
return node;
node->right = right;
if (right)
- right->left = node;
+ {
+ right->left = node;
+ if (right->up == NULL)
+ right->up = node->up;
+ }
return node;
}
@@ -615,7 +619,7 @@ _asn1_change_integer_value (asn1_node node)
{
while (1)
{
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
if (p == node)
{
p = NULL;
@@ -740,7 +744,7 @@ _asn1_expand_object_id (asn1_node node)
move = UP;
}
if (move == UP)
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
@@ -812,7 +816,7 @@ _asn1_expand_object_id (asn1_node node)
move = UP;
}
if (move == UP)
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
return ASN1_SUCCESS;
@@ -882,7 +886,7 @@ _asn1_type_set_config (asn1_node node)
move = UP;
}
if (move == UP)
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
return ASN1_SUCCESS;
@@ -979,7 +983,7 @@ _asn1_check_identifier (asn1_node node)
{
while (1)
{
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
if (p == node)
{
p = NULL;
@@ -1039,7 +1043,7 @@ _asn1_set_default_tag (asn1_node node)
{
while (1)
{
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
if (p == node)
{
p = NULL;
diff --git a/lib/parser_aux.h b/lib/parser_aux.h
index 1f1aec2..55d9061 100644
--- a/lib/parser_aux.h
+++ b/lib/parser_aux.h
@@ -57,6 +57,14 @@ char *_asn1_ltostr (long v, char *str);
asn1_node _asn1_find_up (asn1_node node);
+inline static asn1_node _asn1_get_up(asn1_node node)
+{
+ if (node && node->up)
+ return node->up;
+ else
+ return _asn1_find_up(node);
+}
+
int _asn1_change_integer_value (asn1_node node);
int _asn1_expand_object_id (asn1_node node);
@@ -99,7 +107,10 @@ _asn1_set_down (asn1_node node, asn1_node down)
return node;
node->down = down;
if (down)
- down->left = node;
+ {
+ down->left = node;
+ down->up = node;
+ }
return node;
}
diff --git a/lib/structure.c b/lib/structure.c
index 2184aa8..1c9dd59 100644
--- a/lib/structure.c
+++ b/lib/structure.c
@@ -134,7 +134,7 @@ _asn1_create_static_structure (asn1_node pointer, char *output_file_name,
{
while (1)
{
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
if (p == pointer)
{
p = NULL;
@@ -221,7 +221,7 @@ asn1_array2tree (const asn1_static_node * array, asn1_node * definitions,
if (p_last == *definitions)
break;
- p_last = _asn1_find_up (p_last);
+ p_last = _asn1_get_up (p_last);
if (p_last == NULL)
break;
@@ -321,7 +321,7 @@ asn1_delete_structure2 (asn1_node * structure, unsigned int flags)
p2 = p->right;
if (p != *structure)
{
- p3 = _asn1_find_up (p);
+ p3 = _asn1_get_up (p);
_asn1_set_down (p3, p2);
_asn1_remove_node (p, flags);
p = p3;
@@ -331,7 +331,7 @@ asn1_delete_structure2 (asn1_node * structure, unsigned int flags)
p3 = _asn1_find_left (p);
if (!p3)
{
- p3 = _asn1_find_up (p);
+ p3 = _asn1_get_up (p);
if (p3)
_asn1_set_down (p3, p2);
else
@@ -379,7 +379,7 @@ asn1_delete_element (asn1_node structure, const char *element_name)
p3 = _asn1_find_left (source_node);
if (!p3)
{
- p3 = _asn1_find_up (source_node);
+ p3 = _asn1_get_up (source_node);
if (p3)
_asn1_set_down (p3, p2);
else if (source_node->right)
@@ -439,8 +439,8 @@ _asn1_copy_structure3 (asn1_node source_node)
else
{
move = UP;
- p_s = _asn1_find_up (p_s);
- p_d = _asn1_find_up (p_d);
+ p_s = _asn1_get_up (p_s);
+ p_d = _asn1_get_up (p_d);
}
}
while (p_s != source_node);
@@ -540,7 +540,7 @@ _asn1_type_choice_config (asn1_node node)
move = UP;
}
if (move == UP)
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
return ASN1_SUCCESS;
@@ -591,7 +591,7 @@ _asn1_expand_identifier (asn1_node * node, asn1_node root)
_asn1_set_right (p3, p2);
else
{
- p3 = _asn1_find_up (p);
+ p3 = _asn1_get_up (p);
if (p3)
_asn1_set_down (p3, p2);
else
@@ -647,7 +647,7 @@ _asn1_expand_identifier (asn1_node * node, asn1_node root)
move = UP;
}
if (move == UP)
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
}
return ASN1_SUCCESS;
@@ -1015,7 +1015,7 @@ asn1_print_structure (FILE * out, asn1_node structure, const char *name,
{
while (1)
{
- p = _asn1_find_up (p);
+ p = _asn1_get_up (p);
if (p == root)
{
p = NULL;