Commit f182d7ba authored by Lubos Slovak's avatar Lubos Slovak

Rewritten most of changeset-applying functions.

- Changed function node_update_ref().
- Other functions copied and changed:
  - zone shallow copy
  - a bunch of all xfrin_ functions.
- Added deep copy of zone tree.

refs #1550
parent 1c5a9731
This diff is collapsed.
......@@ -623,7 +623,10 @@ void knot_node_set_zone(knot_node_t *node, knot_zone_t *zone)
void knot_node_update_ref(knot_node_t **ref)
{
if (*ref != NULL && knot_node_is_old(*ref)) {
// if (*ref != NULL && knot_node_is_old(*ref)) {
// *ref = (*ref)->new_node;
// }
if (*ref != NULL && (*ref)->new_node != NULL) {
*ref = (*ref)->new_node;
}
}
......@@ -632,52 +635,18 @@ void knot_node_update_ref(knot_node_t **ref)
void knot_node_update_refs(knot_node_t *node)
{
/* CLEANUP */
/* OMG! */
// reference to previous node
knot_node_update_ref(&node->prev);
// if (node->prev && knot_node_is_old(node->prev)) {
// assert(node->prev->new_node != NULL);
// node->prev = node->prev->new_node;
// }
// reference to next node
knot_node_update_ref(&node->next);
// if (node->next && knot_node_is_old(node->next)) {
// assert(node->next->new_node != NULL);
// node->next = node->next->new_node;
// }
// reference to parent
// if (node->parent && knot_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
// //knot_node_set_parent(node, node->parent->new_node);
// node->parent = node->parent->new_node;
// }
knot_node_update_ref(&node->parent);
// reference to wildcard child
knot_node_update_ref(&node->wildcard_child);
// if (node->wildcard_child && knot_node_is_old(node->wildcard_child)) {
// assert(node->wildcard_child->new_node != NULL);
// node->wildcard_child = node->wildcard_child->new_node;
// }
// reference to NSEC3 node
knot_node_update_ref(&node->nsec3_node);
// if (node->nsec3_node && knot_node_is_old(node->nsec3_node)) {
// assert(node->nsec3_node->new_node != NULL);
// node->nsec3_node = node->nsec3_node->new_node;
// }
// reference to NSEC3 referrer
knot_node_update_ref(&node->nsec3_referer);
// if (node->nsec3_referer && knot_node_is_old(node->nsec3_referer)) {
// assert(node->nsec3_referer->new_node != NULL);
// node->nsec3_referer = node->nsec3_referer->new_node;
// }
}
/*----------------------------------------------------------------------------*/
......@@ -880,11 +849,8 @@ int knot_node_shallow_copy(const knot_node_t *from, knot_node_t **to)
memcpy(*to, from, sizeof(knot_node_t));
// copy RRSets
// copy the skip list with the old references
/* CLEANUP */
(*to)->rrset_tree = gen_tree_shallow_copy(from->rrset_tree);
// assert((*to)->rrset_tree != from->rrset_tree);
// (*to)->rrsets = skip_copy_list(from->rrsets);
if ((*to)->rrset_tree == NULL) {
free(*to);
*to = NULL;
......
......@@ -2214,7 +2214,7 @@ int knot_zone_contents_dname_table_apply(knot_zone_contents_t *contents,
/*----------------------------------------------------------------------------*/
int knot_zone_contents_shallow_copy(const knot_zone_contents_t *from,
knot_zone_contents_t **to)
knot_zone_contents_t **to)
{
if (from == NULL || to == NULL) {
return KNOT_EBADARG;
......@@ -2310,6 +2310,101 @@ cleanup:
/*----------------------------------------------------------------------------*/
int knot_zone_contents_shallow_copy2(const knot_zone_contents_t *from,
knot_zone_contents_t **to)
{
if (from == NULL || to == NULL) {
return KNOT_EBADARG;
}
/* Copy to same destination as source. */
if (from == *to) {
return KNOT_EBADARG;
}
int ret = KNOT_EOK;
knot_zone_contents_t *contents = (knot_zone_contents_t *)calloc(
1, sizeof(knot_zone_contents_t));
if (contents == NULL) {
ERR_ALLOC_FAILED;
return KNOT_ENOMEM;
}
contents->apex = from->apex;
contents->nodes = malloc(sizeof(knot_zone_tree_t));
if (contents->nodes == NULL) {
ERR_ALLOC_FAILED;
ret = KNOT_ENOMEM;
goto cleanup;
}
contents->nsec3_nodes = malloc(sizeof(knot_zone_tree_t));
if (contents->nsec3_nodes == NULL) {
ERR_ALLOC_FAILED;
ret = KNOT_ENOMEM;
goto cleanup;
}
if (from->dname_table != NULL) {
contents->dname_table = knot_dname_table_new();
if (contents->dname_table == NULL) {
ERR_ALLOC_FAILED;
ret = KNOT_ENOMEM;
goto cleanup;
}
if ((ret = knot_dname_table_shallow_copy(from->dname_table,
contents->dname_table)) != KNOT_EOK) {
goto cleanup;
}
} else {
contents->dname_table = NULL;
}
contents->node_count = from->node_count;
contents->generation = from->generation;
contents->zone = from->zone;
// /* Initialize NSEC3 params */
// memcpy(&contents->nsec3_params, &from->nsec3_params,
// sizeof(knot_nsec3_params_t));
if ((ret = knot_zone_tree_deep_copy(from->nodes,
contents->nodes)) != KNOT_EOK
|| (ret = knot_zone_tree_deep_copy(from->nsec3_nodes,
contents->nsec3_nodes)) != KNOT_EOK) {
goto cleanup;
}
#ifdef USE_HASH_TABLE
if (from->table != NULL) {
ret = ck_deep_copy(from->table, &contents->table);
if (ret != 0) {
dbg_zone("knot_zone_contents_shallow_copy: "
"hash table copied\n");
ret = KNOT_ERROR;
goto cleanup;
}
}
#endif
dbg_zone("knot_zone_contents_shallow_copy: finished OK\n");
*to = contents;
return KNOT_EOK;
cleanup:
knot_zone_tree_free(&contents->nodes);
knot_zone_tree_free(&contents->nsec3_nodes);
free(contents->dname_table);
free(contents);
return ret;
}
/*----------------------------------------------------------------------------*/
void knot_zone_contents_free(knot_zone_contents_t **contents)
{
if (contents == NULL || *contents == NULL) {
......
......@@ -544,7 +544,10 @@ int knot_zone_contents_dname_table_apply(knot_zone_contents_t *contents,
* \retval KNOT_ENOMEM
*/
int knot_zone_contents_shallow_copy(const knot_zone_contents_t *from,
knot_zone_contents_t **to);
knot_zone_contents_t **to);
int knot_zone_contents_shallow_copy2(const knot_zone_contents_t *from,
knot_zone_contents_t **to);
void knot_zone_contents_free(knot_zone_contents_t **contents);
......
......@@ -87,6 +87,8 @@ static int knot_zone_tree_copy_node(knot_zone_tree_node_t *from,
if (ret != KNOT_EOK) {
knot_zone_tree_delete_subtree((*to)->avl.avl_left);
(*to)->avl.avl_left = NULL;
free(*to);
*to = NULL;
return ret;
}
......@@ -113,6 +115,53 @@ static void knot_zone_tree_free_node(knot_zone_tree_node_t *node,
free(node);
}
/*----------------------------------------------------------------------------*/
static int knot_zone_tree_deep_copy_node(knot_zone_tree_node_t *from,
knot_zone_tree_node_t **to)
{
if (from == NULL) {
*to = NULL;
return KNOT_EOK;
}
*to = (knot_zone_tree_node_t *)
malloc(sizeof(knot_zone_tree_node_t));
if (*to == NULL) {
return KNOT_ENOMEM;
}
//(*to)->node = from->node;
int ret = knot_node_shallow_copy(from->node, &(*to)->node);
if (ret != KNOT_EOK) {
free(*to);
return ret;
}
(*to)->avl.avl_height = from->avl.avl_height;
ret = knot_zone_tree_deep_copy_node(from->avl.avl_left,
&(*to)->avl.avl_left);
if (ret != KNOT_EOK) {
return ret;
}
ret = knot_zone_tree_deep_copy_node(from->avl.avl_right,
&(*to)->avl.avl_right);
if (ret != KNOT_EOK) {
knot_zone_tree_free_node((*to)->avl.avl_left, 1, 0);
(*to)->avl.avl_left = NULL;
knot_node_free(&(*to)->node, 0, 0);
free(*to);
*to = NULL;
return ret;
}
knot_node_set_new_node(from->node, (*to)->node);
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
/* API functions */
/*----------------------------------------------------------------------------*/
......@@ -445,6 +494,25 @@ int knot_zone_tree_shallow_copy(knot_zone_tree_t *from,
/*----------------------------------------------------------------------------*/
int knot_zone_tree_deep_copy(knot_zone_tree_t *from,
knot_zone_tree_t *to)
{
if (to == NULL || from == NULL) {
return KNOT_EBADARG;
}
/*
* This function will copy the tree by hand, so that the nodes
* do not have to be inserted the normal way. It should be substantially
* faster.
*/
to->th_cmp = from->th_cmp;
return knot_zone_tree_deep_copy_node(from->th_root, &to->th_root);
}
/*----------------------------------------------------------------------------*/
void knot_zone_tree_free(knot_zone_tree_t **tree)
{
if (tree == NULL || *tree == NULL) {
......
......@@ -276,6 +276,9 @@ int knot_zone_tree_reverse_apply_postorder(knot_zone_tree_t *tree,
int knot_zone_tree_shallow_copy(knot_zone_tree_t *from,
knot_zone_tree_t *to);
int knot_zone_tree_deep_copy(knot_zone_tree_t *from,
knot_zone_tree_t *to);
/*!
* \brief Destroys the zone tree, not touching the saved data.
*
......
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