summaryrefslogtreecommitdiff
path: root/lib/parser_aux.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parser_aux.c')
-rw-r--r--lib/parser_aux.c117
1 files changed, 65 insertions, 52 deletions
diff --git a/lib/parser_aux.c b/lib/parser_aux.c
index 786ea64..095204e 100644
--- a/lib/parser_aux.c
+++ b/lib/parser_aux.c
@@ -28,50 +28,37 @@
char _asn1_identifierMissing[ASN1_MAX_NAME_SIZE + 1]; /* identifier name not found */
-/***********************************************/
-/* Type: list_type */
-/* Description: type used in the list during */
-/* the structure creation. */
-/***********************************************/
-typedef struct list_struct
-{
- asn1_node node;
- struct list_struct *next;
-} list_type;
-
-
-/* Pointer to the first element of the list */
-list_type *firstElement = NULL;
/******************************************************/
/* Function : _asn1_add_static_node */
/* Description: creates a new NODE_ASN element and */
-/* puts it in the list pointed by firstElement. */
+/* puts it in the list pointed by e_list. */
/* Parameters: */
+/* e_list: of type list_type; must be NULL initially */
/* type: type of the new element (see ASN1_ETYPE_ */
/* and CONST_ constants). */
/* Return: pointer to the new element. */
/******************************************************/
asn1_node
-_asn1_add_static_node (unsigned int type)
+_asn1_add_static_node (list_type **e_list, unsigned int type)
{
- list_type *listElement;
+ list_type *p;
asn1_node punt;
punt = calloc (1, sizeof (struct asn1_node_st));
if (punt == NULL)
return NULL;
- listElement = malloc (sizeof (list_type));
- if (listElement == NULL)
+ p = malloc (sizeof (list_type));
+ if (p == NULL)
{
free (punt);
return NULL;
}
- listElement->node = punt;
- listElement->next = firstElement;
- firstElement = listElement;
+ p->node = punt;
+ p->next = *e_list;
+ *e_list = p;
punt->type = type;
@@ -91,9 +78,9 @@ _asn1_add_static_node (unsigned int type)
* Returns: the search result, or %NULL if not found.
**/
asn1_node
-asn1_find_node (asn1_node pointer, const char *name)
+asn1_find_node (asn1_node_const pointer, const char *name)
{
- asn1_node p;
+ asn1_node_const p;
char *n_end, n[ASN1_MAX_NAME_SIZE + 1];
const char *n_start;
unsigned int nsize;
@@ -152,7 +139,7 @@ asn1_find_node (asn1_node pointer, const char *name)
else
{ /* *pointer doesn't have a name */
if (n_start[0] == 0)
- return p;
+ return (asn1_node) p;
}
while (n_start)
@@ -206,7 +193,7 @@ asn1_find_node (asn1_node pointer, const char *name)
return NULL;
} /* while */
- return p;
+ return (asn1_node) p;
}
@@ -407,7 +394,7 @@ _asn1_set_name (asn1_node node, const char *name)
/* Return: pointer to the NODE_ASN element. */
/******************************************************************/
asn1_node
-_asn1_cpy_name (asn1_node dst, asn1_node src)
+_asn1_cpy_name (asn1_node dst, asn1_node_const src)
{
if (dst == NULL)
return dst;
@@ -454,16 +441,16 @@ _asn1_set_right (asn1_node node, asn1_node right)
/* Return: pointer to the last element along the right chain. */
/******************************************************************/
asn1_node
-_asn1_get_last_right (asn1_node node)
+_asn1_get_last_right (asn1_node_const node)
{
- asn1_node p;
+ asn1_node_const p;
if (node == NULL)
return NULL;
p = node;
while (p->right)
p = p->right;
- return p;
+ return (asn1_node) p;
}
/******************************************************************/
@@ -501,9 +488,9 @@ _asn1_remove_node (asn1_node node, unsigned int flags)
/* Return: Null if not found. */
/******************************************************************/
asn1_node
-_asn1_find_up (asn1_node node)
+_asn1_find_up (asn1_node_const node)
{
- asn1_node p;
+ asn1_node_const p;
if (node == NULL)
return NULL;
@@ -517,20 +504,37 @@ _asn1_find_up (asn1_node node)
}
/******************************************************************/
+/* Function : _asn1_delete_node_from_list */
+/* Description: deletes the list element given */
+/******************************************************************/
+static void
+_asn1_delete_node_from_list (list_type *list, asn1_node node)
+{
+ list_type *p = list;
+
+ while (p)
+ {
+ if (p->node == node)
+ p->node = NULL;
+ p = p->next;
+ }
+}
+
+/******************************************************************/
/* Function : _asn1_delete_list */
/* Description: deletes the list elements (not the elements */
/* pointed by them). */
/******************************************************************/
void
-_asn1_delete_list (void)
+_asn1_delete_list (list_type *e_list)
{
- list_type *listElement;
+ list_type *p;
- while (firstElement)
+ while (e_list)
{
- listElement = firstElement;
- firstElement = firstElement->next;
- free (listElement);
+ p = e_list;
+ e_list = e_list->next;
+ free (p);
}
}
@@ -540,16 +544,16 @@ _asn1_delete_list (void)
/* pointed by them. */
/******************************************************************/
void
-_asn1_delete_list_and_nodes (void)
+_asn1_delete_list_and_nodes (list_type *e_list)
{
- list_type *listElement;
+ list_type *p;
- while (firstElement)
+ while (e_list)
{
- listElement = firstElement;
- firstElement = firstElement->next;
- _asn1_remove_node (listElement->node, 0);
- free (listElement);
+ p = e_list;
+ e_list = e_list->next;
+ _asn1_remove_node (p->node, 0);
+ free (p);
}
}
@@ -665,17 +669,18 @@ _asn1_change_integer_value (asn1_node node)
/* Function : _asn1_expand_object_id */
/* Description: expand the IDs of an OBJECT IDENTIFIER constant. */
/* Parameters: */
+/* list: root of an object list */
/* node: root of an ASN1 element. */
/* Return: */
-/* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */
-/* otherwise ASN1_SUCCESS */
+/* ASN1_ELEMENT_NOT_FOUND if NODE is NULL, */
+/* otherwise ASN1_SUCCESS */
/******************************************************************/
int
-_asn1_expand_object_id (asn1_node node)
+_asn1_expand_object_id (list_type *list, asn1_node node)
{
asn1_node p, p2, p3, p4, p5;
char name_root[ASN1_MAX_NAME_SIZE], name2[2 * ASN1_MAX_NAME_SIZE + 1];
- int move, tlen;
+ int move, tlen, tries;
if (node == NULL)
return ASN1_ELEMENT_NOT_FOUND;
@@ -684,6 +689,7 @@ _asn1_expand_object_id (asn1_node node)
p = node;
move = DOWN;
+ tries = 0;
while (!((p == node) && (move == UP)))
{
@@ -707,6 +713,7 @@ _asn1_expand_object_id (asn1_node node)
|| !(p3->type & CONST_ASSIGN))
return ASN1_ELEMENT_NOT_FOUND;
_asn1_set_down (p, p2->right);
+ _asn1_delete_node_from_list(list, p2);
_asn1_remove_node (p2, 0);
p2 = p;
p4 = p3->down;
@@ -738,6 +745,11 @@ _asn1_expand_object_id (asn1_node node)
p4 = p4->right;
}
move = DOWN;
+
+ tries++;
+ if (tries >= EXPAND_OBJECT_ID_MAX_RECURSION)
+ return ASN1_RECURSION;
+
continue;
}
}
@@ -747,6 +759,7 @@ _asn1_expand_object_id (asn1_node node)
else
move = RIGHT;
+ tries = 0;
if (move == DOWN)
{
if (p->down)
@@ -935,9 +948,9 @@ _asn1_type_set_config (asn1_node node)
/* otherwise ASN1_SUCCESS */
/******************************************************************/
int
-_asn1_check_identifier (asn1_node node)
+_asn1_check_identifier (asn1_node_const node)
{
- asn1_node p, p2;
+ asn1_node_const p, p2;
char name2[ASN1_MAX_NAME_SIZE * 2 + 2];
if (node == NULL)
@@ -1016,7 +1029,7 @@ _asn1_check_identifier (asn1_node node)
p = p->right;
else
{
- while (1)
+ while (p)
{
p = _asn1_find_up (p);
if (p == node)