Skip to content
Snippets Groups Projects
Commit d1c204c7 authored by Lubos Slovak's avatar Lubos Slovak
Browse files

Counting node's children.

- Each time a parent is set, the parent's children count is
  increased.
- It is necessary that there is no manipulation with node and
  its children that does not use the API.

refs #1035 @10m
parent c2778e09
No related branches found
No related tags found
No related merge requests found
......@@ -159,13 +159,11 @@ dnslib_node_t *dnslib_node_new(dnslib_dname_t *owner, dnslib_node_t *parent,
}
ret->owner = owner;
ret->parent = parent;
dnslib_node_set_parent(ret, parent);
ret->rrsets = skip_create_list(compare_rrset_types);
ret->flags = flags;
// ret->avl.avl_left = NULL;
// ret->avl.avl_right = NULL;
// ret->avl.avl_height = 0;
assert(ret->children == 0);
return ret;
}
......@@ -277,9 +275,21 @@ const dnslib_node_t *dnslib_node_parent(const dnslib_node_t *node)
return node->parent;
}
/*----------------------------------------------------------------------------*/
void dnslib_node_set_parent(dnslib_node_t *node, dnslib_node_t *parent)
{
// decrease number of children of previous parent
if (node->parent != NULL) {
--parent->children;
}
// set the parent
node->parent = parent;
// increase the count of children of the new parent
if (parent != NULL) {
++parent->children;
}
}
/*----------------------------------------------------------------------------*/
......@@ -400,6 +410,9 @@ void dnslib_node_update_refs(dnslib_node_t *node)
// reference to parent
if (node->parent && dnslib_node_is_old(node->parent)) {
assert(node->parent->new_node != NULL);
// do not use the API function to set parent, so that children count
// is not changed
//dnslib_node_set_parent(node, node->parent->new_node);
node->parent = node->parent->new_node;
}
......@@ -567,6 +580,11 @@ void dnslib_node_free(dnslib_node_t **node, int free_owner, int fix_refs)
&& (*node)->parent->wildcard_child == (*node)) {
(*node)->parent->wildcard_child = NULL;
}
// fix parent's children count
if ((*node)->parent) {
--(*node)->parent->children;
}
}
free(*node);
......@@ -593,6 +611,9 @@ int dnslib_node_deep_copy(const dnslib_node_t *from, dnslib_node_t **to)
}
// copy references
// do not use the API function to set parent, so that children count
// is not changed
(*to)->parent = from->parent;
(*to)->nsec3_node = from->nsec3_node;
(*to)->nsec3_referer = from->nsec3_referer;
......
......@@ -70,6 +70,8 @@ struct dnslib_node {
uint8_t flags;
struct dnslib_node *new_node;
unsigned int children;
};
typedef struct dnslib_node dnslib_node_t;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment