Commit c61ae4d8 authored by Lubos Slovak's avatar Lubos Slovak

Renamed changesets functions

refs #1047 @15m
parent a08abecc
......@@ -7,20 +7,20 @@
#include "dnslib/rrset.h"
#include "dnslib/error.h"
static const size_t XFRIN_CHANGESET_COUNT = 5;
static const size_t XFRIN_CHANGESET_STEP = 5;
static const size_t XFRIN_CHANGESET_RRSET_COUNT = 5;
static const size_t XFRIN_CHANGESET_RRSET_STEP = 5;
static const size_t DNSLIB_CHANGESET_COUNT = 5;
static const size_t DNSLIB_CHANGESET_STEP = 5;
static const size_t DNSLIB_CHANGESET_RRSET_COUNT = 5;
static const size_t DNSLIB_CHANGESET_RRSET_STEP = 5;
/*----------------------------------------------------------------------------*/
static int xfrin_changeset_check_count(dnslib_rrset_t ***rrsets, size_t count,
size_t *allocated)
static int dnslib_changeset_check_count(dnslib_rrset_t ***rrsets, size_t count,
size_t *allocated)
{
// this should also do for the initial case (*rrsets == NULL)
if (count == *allocated) {
dnslib_rrset_t **rrsets_new = (dnslib_rrset_t **)calloc(
*allocated + XFRIN_CHANGESET_RRSET_STEP,
*allocated + DNSLIB_CHANGESET_RRSET_STEP,
sizeof(dnslib_rrset_t *));
if (rrsets_new == NULL) {
return DNSLIB_ENOMEM;
......@@ -30,7 +30,7 @@ static int xfrin_changeset_check_count(dnslib_rrset_t ***rrsets, size_t count,
dnslib_rrset_t **rrsets_old = *rrsets;
*rrsets = rrsets_new;
*allocated += XFRIN_CHANGESET_RRSET_STEP;
*allocated += DNSLIB_CHANGESET_RRSET_STEP;
free(rrsets_old);
}
......@@ -39,8 +39,8 @@ static int xfrin_changeset_check_count(dnslib_rrset_t ***rrsets, size_t count,
/*----------------------------------------------------------------------------*/
static int xfrin_changeset_rrsets_match(const dnslib_rrset_t *rrset1,
const dnslib_rrset_t *rrset2)
static int dnslib_changeset_rrsets_match(const dnslib_rrset_t *rrset1,
const dnslib_rrset_t *rrset2)
{
return dnslib_rrset_compare(rrset1, rrset2, DNSLIB_RRSET_COMPARE_HEADER)
&& (dnslib_rrset_type(rrset1) != DNSLIB_RRTYPE_RRSIG
......@@ -52,7 +52,7 @@ static int xfrin_changeset_rrsets_match(const dnslib_rrset_t *rrset1,
/*----------------------------------------------------------------------------*/
int xfrin_allocate_changesets(dnslib_changesets_t **changesets)
int dnslib_changeset_allocate(dnslib_changesets_t **changesets)
{
// create new changesets
*changesets = (dnslib_changesets_t *)(
......@@ -66,16 +66,16 @@ int xfrin_allocate_changesets(dnslib_changesets_t **changesets)
assert((*changesets)->count == 0);
assert((*changesets)->sets = NULL);
return xfrin_changesets_check_size(*changesets);
return dnslib_changesets_check_size(*changesets);
}
/*----------------------------------------------------------------------------*/
int xfrin_changeset_add_rrset(dnslib_rrset_t ***rrsets,
int dnslib_changeset_add_rrset(dnslib_rrset_t ***rrsets,
size_t *count, size_t *allocated,
dnslib_rrset_t *rrset)
{
int ret = xfrin_changeset_check_count(rrsets, *count, allocated);
int ret = dnslib_changeset_check_count(rrsets, *count, allocated);
if (ret != DNSLIB_EOK) {
return ret;
}
......@@ -87,13 +87,13 @@ int xfrin_changeset_add_rrset(dnslib_rrset_t ***rrsets,
/*----------------------------------------------------------------------------*/
int xfrin_changeset_add_rr(dnslib_rrset_t ***rrsets, size_t *count,
int dnslib_changeset_add_rr(dnslib_rrset_t ***rrsets, size_t *count,
size_t *allocated, dnslib_rrset_t *rr)
{
// try to find the RRSet in the list of RRSets
int i = 0;
while (i < *count && !xfrin_changeset_rrsets_match((*rrsets)[i], rr)) {
while (i < *count && !dnslib_changeset_rrsets_match((*rrsets)[i], rr)) {
++i;
}
......@@ -109,13 +109,13 @@ int xfrin_changeset_add_rr(dnslib_rrset_t ***rrsets, size_t *count,
return DNSLIB_EOK;
} else {
return xfrin_changeset_add_rrset(rrsets, count, allocated, rr);
return dnslib_changeset_add_rrset(rrsets, count, allocated, rr);
}
}
/*----------------------------------------------------------------------------*/
int xfrin_changeset_add_new_rr(dnslib_changeset_t *changeset,
int dnslib_changeset_add_new_rr(dnslib_changeset_t *changeset,
dnslib_rrset_t *rrset,
xfrin_changeset_part_t part)
{
......@@ -142,7 +142,7 @@ int xfrin_changeset_add_new_rr(dnslib_changeset_t *changeset,
assert(count != NULL);
assert(allocated != NULL);
int ret = xfrin_changeset_add_rr(rrsets, count, allocated, rrset);
int ret = dnslib_changeset_add_rr(rrsets, count, allocated, rrset);
if (ret != DNSLIB_EOK) {
return ret;
}
......@@ -152,7 +152,7 @@ int xfrin_changeset_add_new_rr(dnslib_changeset_t *changeset,
/*----------------------------------------------------------------------------*/
void xfrin_changeset_store_soa(dnslib_rrset_t **chg_soa,
void dnslib_changeset_store_soa(dnslib_rrset_t **chg_soa,
uint32_t *chg_serial, dnslib_rrset_t *soa)
{
*chg_soa = soa;
......@@ -161,16 +161,16 @@ void xfrin_changeset_store_soa(dnslib_rrset_t **chg_soa,
/*----------------------------------------------------------------------------*/
int xfrin_changeset_add_soa(dnslib_changeset_t *changeset, dnslib_rrset_t *soa,
int dnslib_changeset_add_soa(dnslib_changeset_t *changeset, dnslib_rrset_t *soa,
xfrin_changeset_part_t part)
{
switch (part) {
case XFRIN_CHANGESET_ADD:
xfrin_changeset_store_soa(&changeset->soa_to,
dnslib_changeset_store_soa(&changeset->soa_to,
&changeset->serial_to, soa);
break;
case XFRIN_CHANGESET_REMOVE:
xfrin_changeset_store_soa(&changeset->soa_from,
dnslib_changeset_store_soa(&changeset->soa_from,
&changeset->serial_from, soa);
break;
default:
......@@ -183,11 +183,11 @@ int xfrin_changeset_add_soa(dnslib_changeset_t *changeset, dnslib_rrset_t *soa,
/*---------------------------------------------------------------------------*/
int xfrin_changesets_check_size(dnslib_changesets_t *changesets)
int dnslib_changesets_check_size(dnslib_changesets_t *changesets)
{
if (changesets->allocated == changesets->count) {
dnslib_changeset_t *sets = (dnslib_changeset_t *)calloc(
changesets->allocated + XFRIN_CHANGESET_STEP,
changesets->allocated + DNSLIB_CHANGESET_STEP,
sizeof(dnslib_changeset_t));
if (sets == NULL) {
return DNSLIB_ENOMEM;
......@@ -197,7 +197,7 @@ int xfrin_changesets_check_size(dnslib_changesets_t *changesets)
memcpy(sets, changesets->sets, changesets->count);
dnslib_changeset_t *old_sets = changesets->sets;
changesets->sets = sets;
changesets->count += XFRIN_CHANGESET_STEP;
changesets->count += DNSLIB_CHANGESET_STEP;
free(old_sets);
}
......@@ -206,7 +206,7 @@ int xfrin_changesets_check_size(dnslib_changesets_t *changesets)
/*----------------------------------------------------------------------------*/
void xfrin_free_changesets(dnslib_changesets_t **changesets)
void dnslib_free_changesets(dnslib_changesets_t **changesets)
{
if (changesets == NULL || *changesets == NULL) {
return;
......
......@@ -56,28 +56,28 @@ typedef enum {
/*----------------------------------------------------------------------------*/
int xfrin_allocate_changesets(dnslib_changesets_t **changesets);
int dnslib_changeset_allocate(dnslib_changesets_t **changesets);
int xfrin_changeset_add_rrset(dnslib_rrset_t ***rrsets,
size_t *count, size_t *allocated,
dnslib_rrset_t *rrset);
int dnslib_changeset_add_rrset(dnslib_rrset_t ***rrsets,
size_t *count, size_t *allocated,
dnslib_rrset_t *rrset);
int xfrin_changeset_add_rr(dnslib_rrset_t ***rrsets, size_t *count,
size_t *allocated, dnslib_rrset_t *rr);
int dnslib_changeset_add_rr(dnslib_rrset_t ***rrsets, size_t *count,
size_t *allocated, dnslib_rrset_t *rr);
int xfrin_changeset_add_new_rr(dnslib_changeset_t *changeset,
dnslib_rrset_t *rrset,
xfrin_changeset_part_t part);
int dnslib_changeset_add_new_rr(dnslib_changeset_t *changeset,
dnslib_rrset_t *rrset,
xfrin_changeset_part_t part);
void xfrin_changeset_store_soa(dnslib_rrset_t **chg_soa,
uint32_t *chg_serial, dnslib_rrset_t *soa);
void dnslib_changeset_store_soa(dnslib_rrset_t **chg_soa,
uint32_t *chg_serial, dnslib_rrset_t *soa);
int xfrin_changeset_add_soa(dnslib_changeset_t *changeset, dnslib_rrset_t *soa,
xfrin_changeset_part_t part);
int dnslib_changeset_add_soa(dnslib_changeset_t *changeset, dnslib_rrset_t *soa,
xfrin_changeset_part_t part);
void xfrin_free_changesets(dnslib_changesets_t **changesets);
int dnslib_changesets_check_size(dnslib_changesets_t *changesets);
int xfrin_changesets_check_size(dnslib_changesets_t *changesets);
void dnslib_free_changesets(dnslib_changesets_t **changesets);
#endif /* _KNOT_DNSLIB_CHANGESETS_H_ */
......
......@@ -2882,7 +2882,7 @@ int dnslib_ns_process_ixfrin(dnslib_nameserver_t *nameserver,
dnslib_rrset_owner(chgsets->sets[0].soa_from));
if (zone == NULL) {
debug_dnslib_ns("No zone found for incoming IXFR!\n");
xfrin_free_changesets(
dnslib_free_changesets(
(dnslib_changesets_t **)(&xfr->data));
return DNSLIB_ENOZONE; /*! \todo Other error code? */
}
......
......@@ -20,6 +20,7 @@
#include "dnslib/query.h"
#include "dnslib/error.h"
#include "dnslib/changesets.h"
/*----------------------------------------------------------------------------*/
/* Non-API functions */
/*----------------------------------------------------------------------------*/
......@@ -720,7 +721,7 @@ int xfrin_process_ixfr_packet(const uint8_t *pkt, size_t size,
assert(soa1 != NULL);
if (*changesets == NULL
&& (ret = xfrin_allocate_changesets(changesets)) != DNSLIB_EOK) {
&& (ret = dnslib_changeset_allocate(changesets)) != DNSLIB_EOK) {
dnslib_packet_free(&packet);
return ret;
}
......@@ -752,14 +753,14 @@ int xfrin_process_ixfr_packet(const uint8_t *pkt, size_t size,
break;
}
if ((ret = xfrin_changesets_check_size(*changesets))
if ((ret = dnslib_changesets_check_size(*changesets))
!= DNSLIB_EOK) {
dnslib_rrset_deep_free(&rr, 1, 1, 1);
goto cleanup;
}
// save the origin SOA of the remove part
ret = xfrin_changeset_add_soa(
ret = dnslib_changeset_add_soa(
&(*changesets)->sets[i], rr, XFRIN_CHANGESET_REMOVE);
if (ret != DNSLIB_EOK) {
dnslib_rrset_deep_free(&rr, 1, 1, 1);
......@@ -773,7 +774,7 @@ int xfrin_process_ixfr_packet(const uint8_t *pkt, size_t size,
}
assert(dnslib_rrset_type(rr) != DNSLIB_RRTYPE_SOA);
if ((ret = xfrin_changeset_add_new_rr(
if ((ret = dnslib_changeset_add_new_rr(
&(*changesets)->sets[i], rr,
XFRIN_CHANGESET_REMOVE)) != DNSLIB_EOK) {
dnslib_rrset_deep_free(&rr, 1, 1, 1);
......@@ -786,7 +787,7 @@ int xfrin_process_ixfr_packet(const uint8_t *pkt, size_t size,
&& dnslib_rrset_type(rr) == DNSLIB_RRTYPE_SOA);
// save the origin SOA of the add part
ret = xfrin_changeset_add_soa(
ret = dnslib_changeset_add_soa(
&(*changesets)->sets[i], rr, XFRIN_CHANGESET_ADD);
if (ret != DNSLIB_EOK) {
dnslib_rrset_deep_free(&rr, 1, 1, 1);
......@@ -800,7 +801,7 @@ int xfrin_process_ixfr_packet(const uint8_t *pkt, size_t size,
}
assert(dnslib_rrset_type(rr) != DNSLIB_RRTYPE_SOA);
if ((ret = xfrin_changeset_add_new_rr(
if ((ret = dnslib_changeset_add_new_rr(
&(*changesets)->sets[i], rr,
XFRIN_CHANGESET_ADD)) != DNSLIB_EOK) {
dnslib_rrset_deep_free(&rr, 1, 1, 1);
......@@ -841,7 +842,7 @@ int xfrin_process_ixfr_packet(const uint8_t *pkt, size_t size,
return ret;
cleanup:
xfrin_free_changesets(changesets);
dnslib_free_changesets(changesets);
dnslib_packet_free(&packet);
return ret;
}
......
......@@ -712,7 +712,7 @@ static int zones_changesets_from_binary(dnslib_changesets_t *chgsets)
assert(chgsets->sets[i].serial_from
== dnslib_rdata_soa_serial(
dnslib_rrset_rdata(rrset)));
xfrin_changeset_store_soa(
dnslib_changeset_store_soa(
&chgsets->sets[i].soa_from,
&chgsets->sets[i].serial_from, rrset);
++soa;
......@@ -729,13 +729,13 @@ static int zones_changesets_from_binary(dnslib_changesets_t *chgsets)
assert(chgsets->sets[i].serial_from
== dnslib_rdata_soa_serial(
dnslib_rrset_rdata(rrset)));
xfrin_changeset_store_soa(
dnslib_changeset_store_soa(
&chgsets->sets[i].soa_to,
&chgsets->sets[i].serial_to,
rrset);
++soa;
} else {
ret = xfrin_changeset_add_rrset(
ret = dnslib_changeset_add_rrset(
&chgsets->sets[i].remove,
&chgsets->sets[i].remove_count,
&chgsets->sets[i]
......@@ -750,7 +750,7 @@ static int zones_changesets_from_binary(dnslib_changesets_t *chgsets)
== DNSLIB_RRTYPE_SOA) {
return DNSLIB_EMALF;
} else {
ret = xfrin_changeset_add_rrset(
ret = dnslib_changeset_add_rrset(
&chgsets->sets[i].add,
&chgsets->sets[i].add_count,
&chgsets->sets[i].add_allocated,
......@@ -804,7 +804,7 @@ static int zones_load_changesets(const dnslib_zone_t *zone,
/* Check changesets size if needed. */
++dst->count;
ret = xfrin_changesets_check_size(dst);
ret = dnslib_changesets_check_size(dst);
if (ret != DNSLIB_EOK) {
debug_dnslib_xfr("ixfr_db: failed to check changesets size\n");
--dst->count;
......@@ -902,7 +902,7 @@ static int zones_journal_apply(dnslib_zone_t *zone)
}
/* Free changesets and return. */
xfrin_free_changesets(&chsets);
dnslib_free_changesets(&chsets);
return ret;
}
......
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