Commit 6eb8875f authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

zone tree: apply callback becomes node* instead of node**

parent 976eb76c
......@@ -687,10 +687,8 @@ static bool nsec3_is_empty(zone_node_t *node, bool opt_out)
* It also lowers the children count for the parent of marked node. This must be
* fixed before further operations on the zone.
*/
static int nsec3_mark_empty(zone_node_t **node_p, void *data)
static int nsec3_mark_empty(zone_node_t *node, void *data)
{
zone_node_t *node = *node_p;
if (!(node->flags & NODE_FLAGS_EMPTY) && nsec3_is_empty(node, (data != NULL))) {
/*!
* Mark this node and all parent nodes that meet the same
......@@ -705,7 +703,7 @@ static int nsec3_mark_empty(zone_node_t **node_p, void *data)
*/
node->parent->children--;
/* Recurse using the parent node */
return nsec3_mark_empty(&node->parent, data);
return nsec3_mark_empty(node->parent, data);
}
}
......@@ -719,11 +717,9 @@ static int nsec3_mark_empty(zone_node_t **node_p, void *data)
* The children count of node's parent is increased if this node was marked as
* empty, as it was previously decreased in the \a nsec3_mark_empty() function.
*/
static int nsec3_reset(zone_node_t **node_p, void *data)
static int nsec3_reset(zone_node_t *node, void *data)
{
UNUSED(data);
zone_node_t *node = *node_p;
if (node->flags & NODE_FLAGS_EMPTY) {
/* If node was marked as empty, increase its parent's children
* count.
......
......@@ -524,14 +524,14 @@ typedef struct {
* \param node Node to be signed.
* \param data Callback data, node_sign_args_t.
*/
static int sign_node(zone_node_t **node, void *data)
static int sign_node(zone_node_t *node, void *data)
{
assert(node && *node);
assert(node);
assert(data);
node_sign_args_t *args = (node_sign_args_t *)data;
if ((*node)->rrset_count == 0) {
if (node->rrset_count == 0) {
return KNOT_EOK;
}
......@@ -539,7 +539,7 @@ static int sign_node(zone_node_t **node, void *data)
return KNOT_EOK;
}
int result = sign_node_rrsets(*node, args->sign_ctx,
int result = sign_node_rrsets(node, args->sign_ctx,
&args->changeset, &args->expires_at);
return result;
......
......@@ -41,12 +41,12 @@ static void rrs_list_clear(list_t *l, knot_mm_t *mm)
}
/*! \brief Frees additional data from single node */
static int free_additional(zone_node_t **node, void *data)
static int free_additional(zone_node_t *node, void *data)
{
UNUSED(data);
for (uint16_t i = 0; i < (*node)->rrset_count; ++i) {
struct rr_data *rrdata = &(*node)->rrs[i];
for (uint16_t i = 0; i < node->rrset_count; ++i) {
struct rr_data *rrdata = &node->rrs[i];
additional_clear(rrdata->additional);
rrdata->additional = NULL;
}
......
......@@ -267,13 +267,12 @@ typedef struct {
bool measure_size;
} zone_adjust_arg_t;
static int adjust_single(zone_node_t **tnode, void *data)
static int adjust_single(zone_node_t *node, void *data)
{
assert(tnode != NULL);
assert(node != NULL);
assert(data != NULL);
zone_adjust_arg_t *args = (zone_adjust_arg_t *)data;
zone_node_t *node = *tnode;
// remember first node
if (args->first_node == NULL) {
......
......@@ -25,21 +25,6 @@
#include "contrib/qp-trie/trie.h"
#include "contrib/macros.h"
typedef struct {
zone_contents_apply_cb_t func;
void *data;
} zone_tree_func_t;
static int tree_apply_cb(zone_node_t **node, void *data)
{
if (node == NULL || data == NULL) {
return KNOT_EINVAL;
}
zone_tree_func_t *f = (zone_tree_func_t *)data;
return f->func(*node, f->data);
}
/*!
* \brief Checks if the given node can be inserted into the given zone.
*
......@@ -75,14 +60,13 @@ static int check_node(const zone_contents_t *contents, const zone_node_t *node)
* \param node Node to destroy RRSets from.
* \param data Unused parameter.
*/
static int destroy_node_rrsets_from_tree(zone_node_t **node, void *data)
static int destroy_node_rrsets_from_tree(zone_node_t *node, void *data)
{
assert(node);
UNUSED(data);
if (*node != NULL) {
node_free_rrsets(*node, NULL);
node_free(*node, NULL);
if (node != NULL) {
node_free_rrsets(node, NULL);
node_free(node, NULL);
}
return KNOT_EOK;
......@@ -644,33 +628,21 @@ bool zone_contents_find_node_or_wildcard(const zone_contents_t *contents,
}
int zone_contents_apply(zone_contents_t *contents,
zone_contents_apply_cb_t function, void *data)
zone_tree_apply_cb_t function, void *data)
{
if (contents == NULL) {
return KNOT_EINVAL;
}
zone_tree_func_t f = {
.func = function,
.data = data
};
return zone_tree_apply(contents->nodes, tree_apply_cb, &f);
return zone_tree_apply(contents->nodes, function, data);
}
int zone_contents_nsec3_apply(zone_contents_t *contents,
zone_contents_apply_cb_t function, void *data)
zone_tree_apply_cb_t function, void *data)
{
if (contents == NULL) {
return KNOT_EINVAL;
}
zone_tree_func_t f = {
.func = function,
.data = data
};
return zone_tree_apply(contents->nsec3_nodes, tree_apply_cb, &f);
return zone_tree_apply(contents->nsec3_nodes, function, data);
}
int zone_contents_shallow_copy(const zone_contents_t *from, zone_contents_t **to)
......
......@@ -38,11 +38,6 @@ typedef struct zone_contents {
bool dnssec;
} zone_contents_t;
/*!
* \brief Signature of callback for zone contents apply functions.
*/
typedef int (*zone_contents_apply_cb_t)(zone_node_t *node, void *data);
/*!
* \brief Allocate and create new zone contents.
*
......@@ -219,7 +214,7 @@ bool zone_contents_find_node_or_wildcard(const zone_contents_t *contents,
* \param data Arbitrary data to be passed to the function.
*/
int zone_contents_apply(zone_contents_t *contents,
zone_contents_apply_cb_t function, void *data);
zone_tree_apply_cb_t function, void *data);
/*!
* \brief Applies the given function to each NSEC3 node in the zone.
......@@ -230,7 +225,7 @@ int zone_contents_apply(zone_contents_t *contents,
* \param data Arbitrary data to be passed to the function.
*/
int zone_contents_nsec3_apply(zone_contents_t *contents,
zone_contents_apply_cb_t function, void *data);
zone_tree_apply_cb_t function, void *data);
/*!
* \brief Creates a shallow copy of the zone (no stored data are copied).
......
......@@ -208,14 +208,12 @@ static int diff_rrsets(const knot_rrset_t *rrset1, const knot_rrset_t *rrset2,
}
/*!< \todo this could be generic function for adding / removing. */
static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
static int knot_zone_diff_node(zone_node_t *node, void *data)
{
if (node_ptr == NULL || *node_ptr == NULL || data == NULL) {
if (node == NULL || data == NULL) {
return KNOT_EINVAL;
}
zone_node_t *node = *node_ptr;
struct zone_diff_param *param = (struct zone_diff_param *)data;
if (param->changeset == NULL) {
return KNOT_EINVAL;
......@@ -301,14 +299,12 @@ static int knot_zone_diff_node(zone_node_t **node_ptr, void *data)
}
/*!< \todo possibly not needed! */
static int add_new_nodes(zone_node_t **node_ptr, void *data)
static int add_new_nodes(zone_node_t *node, void *data)
{
if (node_ptr == NULL || *node_ptr == NULL || data == NULL) {
if (node == NULL || data == NULL) {
return KNOT_EINVAL;
}
zone_node_t *node = *node_ptr;
struct zone_diff_param *param = (struct zone_diff_param *)data;
if (param->changeset == NULL) {
return KNOT_EINVAL;
......
......@@ -22,6 +22,17 @@
#include "libknot/errcode.h"
#include "contrib/macros.h"
typedef struct {
zone_tree_apply_cb_t func;
void *data;
} zone_tree_func_t;
static int tree_apply_cb(trie_val_t *node, void *data)
{
zone_tree_func_t *f = (zone_tree_func_t *)data;
return f->func((zone_node_t *)*node, f->data);
}
zone_tree_t *zone_tree_create(void)
{
return trie_create(NULL);
......@@ -176,7 +187,12 @@ int zone_tree_apply(zone_tree_t *tree, zone_tree_apply_cb_t function, void *data
return KNOT_EOK;
}
return trie_apply(tree, (int (*)(trie_val_t *, void *))function, data);
zone_tree_func_t f = {
.func = function,
.data = data,
};
return trie_apply(tree, tree_apply_cb, &f);
}
int zone_tree_it_begin(zone_tree_t *tree, zone_tree_it_t *it)
......@@ -222,13 +238,11 @@ void zone_tree_free(zone_tree_t **tree)
*tree = NULL;
}
static int zone_tree_free_node(zone_node_t **node, void *data)
static int zone_tree_free_node(zone_node_t *node, void *data)
{
UNUSED(data);
if (node) {
node_free(*node, NULL);
}
node_free(node, NULL);
return KNOT_EOK;
}
......
......@@ -24,7 +24,7 @@ typedef trie_t zone_tree_t;
/*!
* \brief Signature of callback for zone apply functions.
*/
typedef int (*zone_tree_apply_cb_t)(zone_node_t **node, void *data);
typedef int (*zone_tree_apply_cb_t)(zone_node_t *node, void *data);
/*!
* \brief Zone tree iteration context.
......
......@@ -51,10 +51,10 @@ static void ztree_free_data(void)
}
}
static int ztree_iter_data(zone_node_t **node, void *data)
static int ztree_iter_data(zone_node_t *node, void *data)
{
unsigned *i = (unsigned *)data;
knot_dname_t *owner = (*node)->owner;
knot_dname_t *owner = node->owner;
int result = KNOT_EOK;
if (owner != ORDER[*i]) {
result = KNOT_ERROR;
......
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