Commit bbd0aa72 authored by Daniel Salzman's avatar Daniel Salzman

updates: code cleanup

parent 2475f30d
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -231,7 +231,7 @@ void apply_init_ctx(apply_ctx_t *ctx, zone_contents_t *contents, uint32_t flags)
}
int apply_prepare_zone_copy(zone_contents_t *old_contents,
zone_contents_t **new_contents)
zone_contents_t **new_contents)
{
if (old_contents == NULL || new_contents == NULL) {
return KNOT_EINVAL;
......@@ -321,7 +321,7 @@ int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
}
zone_tree_t *tree = knot_rrset_is_nsec3rel(rr) ?
contents->nsec3_nodes : contents->nodes;
contents->nsec3_nodes : contents->nodes;
knot_rrset_t removed_rrset = node_rrset(node, rr->type);
knot_rdata_t *old_data = removed_rrset.rrs.data;
......@@ -387,9 +387,11 @@ int apply_prepare_to_sign(apply_ctx_t *ctx)
return zone_contents_adjust_pointers(ctx->contents);
}
int apply_changesets(apply_ctx_t *ctx, zone_t *zone, list_t *chsets, zone_contents_t **new_contents)
int apply_changesets(apply_ctx_t *ctx, zone_t *zone, list_t *chsets,
zone_contents_t **new_contents)
{
if (ctx == NULL || zone == NULL || chsets == NULL || EMPTY_LIST(*chsets) || new_contents == NULL) {
if (ctx == NULL || zone == NULL || chsets == NULL ||
EMPTY_LIST(*chsets) || new_contents == NULL) {
return KNOT_EINVAL;
}
......@@ -430,9 +432,10 @@ int apply_changesets(apply_ctx_t *ctx, zone_t *zone, list_t *chsets, zone_conten
return KNOT_EOK;
}
int apply_changeset(apply_ctx_t *ctx, zone_t *zone, changeset_t *change, zone_contents_t **new_contents)
int apply_changeset(apply_ctx_t *ctx, zone_t *zone, changeset_t *ch,
zone_contents_t **new_contents)
{
if (ctx == NULL || zone == NULL || change == NULL || new_contents == NULL) {
if (ctx == NULL || zone == NULL || ch == NULL || new_contents == NULL) {
return KNOT_EINVAL;
}
......@@ -449,7 +452,7 @@ int apply_changeset(apply_ctx_t *ctx, zone_t *zone, changeset_t *change, zone_co
ctx->contents = contents_copy;
ret = apply_single(ctx, change);
ret = apply_single(ctx, ch);
if (ret != KNOT_EOK) {
update_rollback(ctx);
update_free_zone(&ctx->contents);
......@@ -519,38 +522,44 @@ int apply_finalize(apply_ctx_t *ctx)
void update_cleanup(apply_ctx_t *ctx)
{
if (ctx) {
// Delete old RR data
rrs_list_clear(&ctx->old_data, NULL);
init_list(&ctx->old_data);
// Keep new RR data
ptrlist_free(&ctx->new_data, NULL);
init_list(&ctx->new_data);
if (ctx == NULL) {
return;
}
// Delete old RR data
rrs_list_clear(&ctx->old_data, NULL);
init_list(&ctx->old_data);
// Keep new RR data
ptrlist_free(&ctx->new_data, NULL);
init_list(&ctx->new_data);
}
void update_rollback(apply_ctx_t *ctx)
{
if (ctx) {
// Delete new RR data
rrs_list_clear(&ctx->new_data, NULL);
init_list(&ctx->new_data);
// Keep old RR data
ptrlist_free(&ctx->old_data, NULL);
init_list(&ctx->old_data);
if (ctx == NULL) {
return;
}
// Delete new RR data
rrs_list_clear(&ctx->new_data, NULL);
init_list(&ctx->new_data);
// Keep old RR data
ptrlist_free(&ctx->old_data, NULL);
init_list(&ctx->old_data);
}
void update_free_zone(zone_contents_t **contents)
{
if (contents && *contents) {
zone_tree_apply((*contents)->nodes, free_additional, NULL);
zone_tree_deep_free(&(*contents)->nodes);
zone_tree_deep_free(&(*contents)->nsec3_nodes);
if (contents == NULL || *contents == NULL) {
return;
}
dnssec_nsec3_params_free(&(*contents)->nsec3_params);
zone_tree_apply((*contents)->nodes, free_additional, NULL);
zone_tree_deep_free(&(*contents)->nodes);
zone_tree_deep_free(&(*contents)->nsec3_nodes);
free(*contents);
*contents = NULL;
}
dnssec_nsec3_params_free(&(*contents)->nsec3_params);
free(*contents);
*contents = NULL;
}
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -85,7 +85,7 @@ int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr);
* \brief Adds a single RR into zone contents.
*
* \param ctx Apply context.
* \param ch
* \param ch Changeset to be applied to the zone.
*
* \return KNOT_E*
*/
......@@ -97,7 +97,6 @@ int apply_replace_soa(apply_ctx_t *ctx, changeset_t *ch);
* Adjusted pointers are required for DNSSEC.
*
* \param ctx Apply context.
* \param ch
*
* \return KNOT_E*
*/
......@@ -147,7 +146,6 @@ int apply_changesets_directly(apply_ctx_t *ctx, list_t *chsets);
*/
int apply_changeset_directly(apply_ctx_t *ctx, changeset_t *ch);
/*!
* \brief Finalizes the zone contents for publishing.
*
......
......@@ -251,7 +251,8 @@ int zone_update_remove_rrset(zone_update_t *update, knot_dname_t *owner, uint16_
const zone_node_t *node = zone_contents_find_node(update->new_cont, owner);
if (node != NULL) {
knot_rrset_t rrset = node_rrset(node, type);
int ret = changeset_add_removal(&update->change, &rrset, CHANGESET_CHECK);
int ret = changeset_add_removal(&update->change, &rrset,
CHANGESET_CHECK);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -298,7 +299,8 @@ int zone_update_remove_node(zone_update_t *update, const knot_dname_t *owner)
size_t rrset_count = node->rrset_count;
for (int i = 0; i < rrset_count; ++i) {
knot_rrset_t rrset = node_rrset_at(node, rrset_count - 1 - i);
int ret = changeset_add_removal(&update->change, &rrset, CHANGESET_CHECK);
int ret = changeset_add_removal(&update->change, &rrset,
CHANGESET_CHECK);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -429,7 +431,8 @@ static int set_new_soa(zone_update_t *update, unsigned serial_policy)
{
assert(update);
knot_rrset_t *soa_cpy = node_create_rrset(zone_update_get_apex(update), KNOT_RRTYPE_SOA);
knot_rrset_t *soa_cpy = node_create_rrset(zone_update_get_apex(update),
KNOT_RRTYPE_SOA);
if (soa_cpy == NULL) {
return KNOT_ENOMEM;
}
......@@ -448,7 +451,8 @@ static int set_new_soa(zone_update_t *update, unsigned serial_policy)
return KNOT_EOK;
}
static int commit_incremental(conf_t *conf, zone_update_t *update, zone_contents_t **contents_out)
static int commit_incremental(conf_t *conf, zone_update_t *update,
zone_contents_t **contents_out)
{
assert(update);
assert(contents_out);
......@@ -584,7 +588,8 @@ int zone_update_commit(conf_t *conf, zone_update_t *update)
/* If there is anything to change */
if (new_contents != NULL) {
/* Switch zone contents. */
zone_contents_t *old_contents = zone_switch_contents(update->zone, new_contents);
zone_contents_t *old_contents = zone_switch_contents(update->zone,
new_contents);
/* Sync RCU. */
synchronize_rcu();
......@@ -733,4 +738,3 @@ bool zone_update_no_change(zone_update_t *update)
return false;
}
}
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