Skip to content
Snippets Groups Projects
Commit 3ceae7e0 authored by Jan Kadlec's avatar Jan Kadlec
Browse files

new_node: added missing doxygen, cleanup.

- knot_rrset_copy now returns pointer
parent d951b29b
Branches
Tags
No related merge requests found
......@@ -742,7 +742,8 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
if (knot_rrset_rr_ttl(dnskeys, 0) != knot_rrset_rr_ttl(soa, 0)) {
dbg_dnssec_detail("removing DNSKEYs (SOA TTL differs)\n");
result = knot_rrset_copy(dnskeys, &to_remove, NULL);
to_remove = knot_rrset_copy(dnskeys, NULL);
result = to_remove ? KNOT_EOK : KNOT_ENOMEM;
goto done;
}
......@@ -1351,15 +1352,15 @@ int knot_zone_sign_update_soa(const knot_rrset_t *soa,
knot_rrset_t *soa_from = NULL;
knot_rrset_t *soa_to = NULL;
result = knot_rrset_copy(soa, &soa_from, NULL);
if (result != KNOT_EOK) {
return result;
soa_from = knot_rrset_copy(soa, NULL);
if (soa_from == NULL) {
return KNOT_ENOMEM;
}
result = knot_rrset_copy(soa, &soa_to, NULL);
if (result != KNOT_EOK) {
soa_to = knot_rrset_copy(soa, NULL);
if (soa_to == NULL) {
knot_rrset_free(&soa_from, NULL);
return result;
return KNOT_ENOMEM;
}
knot_rrs_soa_serial_set(&soa_to->rrs, new_serial);
......
......@@ -55,8 +55,8 @@ typedef struct knot_changeset {
uint32_t serial_from; /*!< SOA start serial. */
uint32_t serial_to; /*!< SOA destination serial. */
uint32_t flags; /*!< DDNS / IXFR flags. */
list_t old_data;
list_t new_data;
list_t old_data; /*!< Old data, to be freed after succesfull update. */
list_t new_data; /*!< New data, to be freed after failed update. */
} knot_changeset_t;
/*----------------------------------------------------------------------------*/
......
......@@ -61,7 +61,7 @@ static int add_rr_to_list(list_t *l, const knot_rrset_t *rr)
}
};
knot_rrset_t *rr_copy = knot_rrset_cpy(rr, NULL);
knot_rrset_t *rr_copy = knot_rrset_copy(rr, NULL);
if (rr_copy == NULL) {
return KNOT_ENOMEM;
}
......@@ -497,7 +497,7 @@ static bool skip_record_addition(knot_changeset_t *changeset,
static int add_rr_to_chgset(const knot_rrset_t *rr, knot_changeset_t *changeset,
int *apex_ns_rem)
{
knot_rrset_t *rr_copy = knot_rrset_cpy(rr, NULL);
knot_rrset_t *rr_copy = knot_rrset_copy(rr, NULL);
if (rr_copy == NULL) {
return KNOT_ENOMEM;
}
......@@ -536,7 +536,7 @@ static bool skip_record_removal(knot_changeset_t *changeset, knot_rrset_t *rr)
static int rem_rr_to_chgset(const knot_rrset_t *rr, knot_changeset_t *changeset,
int *apex_ns_rem)
{
knot_rrset_t *rr_copy = knot_rrset_cpy(rr, NULL);
knot_rrset_t *rr_copy = knot_rrset_copy(rr, NULL);
if (rr_copy == NULL) {
return KNOT_ENOMEM;
}
......@@ -1016,7 +1016,7 @@ int knot_ddns_process_update(const knot_zone_contents_t *zone,
}
int64_t sn_rr = knot_rrs_soa_serial(&rr->rrs);
assert(knot_serial_compare(sn_rr, sn_old) > 0);
soa_end = knot_rrset_cpy(rr, NULL);
soa_end = knot_rrset_copy(rr, NULL);
if (soa_end == NULL) {
return KNOT_ENOMEM;
}
......@@ -1030,7 +1030,7 @@ int knot_ddns_process_update(const knot_zone_contents_t *zone,
return KNOT_EOK;
}
soa_end = knot_rrset_cpy(soa_begin, NULL);
soa_end = knot_rrset_copy(soa_begin, NULL);
if (soa_end == NULL) {
*rcode = KNOT_RCODE_SERVFAIL;
return KNOT_ENOMEM;
......
......@@ -59,9 +59,9 @@ int knot_ddns_process_prereqs(const knot_pkt_t *query,
* \return KNOT_E*
*/
int knot_ddns_process_update(const knot_zone_contents_t *zone,
const knot_pkt_t *query,
knot_changeset_t *changeset,
uint16_t *rcode, uint32_t new_serial);
const knot_pkt_t *query,
knot_changeset_t *changeset,
uint16_t *rcode, uint32_t new_serial);
#endif /* _KNOT_DDNS_H_ */
......
......@@ -344,7 +344,7 @@ int xfrin_process_ixfr_packet(knot_pkt_t *pkt, knot_ns_xfr_t *xfr)
}
// just store the first SOA for later use
(*chs)->first_soa = knot_rrset_cpy(rr, NULL);
(*chs)->first_soa = knot_rrset_copy(rr, NULL);
if ((*chs)->first_soa == NULL) {
ret = KNOT_ENOMEM;
goto cleanup;
......@@ -508,7 +508,7 @@ dbg_xfrin_exec_verb(
if (chset == NULL) {
goto cleanup;
}
knot_rrset_t *soa = knot_rrset_cpy(rr, NULL);
knot_rrset_t *soa = knot_rrset_copy(rr, NULL);
if (soa == NULL) {
ret = KNOT_ENOMEM;
goto cleanup;
......@@ -526,7 +526,7 @@ dbg_xfrin_exec_verb(
if (rr->type == KNOT_RRTYPE_SOA) {
// we should not be here if soa_from is not set
assert(chset->soa_from != NULL);
knot_rrset_t *soa = knot_rrset_cpy(rr, NULL);
knot_rrset_t *soa = knot_rrset_copy(rr, NULL);
if (soa == NULL) {
ret = KNOT_ENOMEM;
goto cleanup;
......@@ -537,7 +537,7 @@ dbg_xfrin_exec_verb(
} else {
// just add the RR to the REMOVE part and
// continue
knot_rrset_t *cpy = knot_rrset_cpy(rr, NULL);
knot_rrset_t *cpy = knot_rrset_copy(rr, NULL);
if (cpy == NULL) {
ret = KNOT_ENOMEM;
goto cleanup;
......@@ -561,7 +561,7 @@ dbg_xfrin_exec_verb(
continue;
} else {
// just add the RR to the ADD part and continue
knot_rrset_t *cpy = knot_rrset_cpy(rr, NULL);
knot_rrset_t *cpy = knot_rrset_copy(rr, NULL);
if (cpy == NULL) {
ret = KNOT_ENOMEM;
goto cleanup;
......
......@@ -199,7 +199,7 @@ knot_rrset_t *knot_node_create_rrset(const knot_node_t *node, uint16_t type)
for (uint16_t i = 0; i < node->rrset_count; ++i) {
if (node->rrs[i].type == type) {
knot_rrset_t rrset = NODE_RR_INIT_N(node, i);
return knot_rrset_cpy(&rrset, NULL);
return knot_rrset_copy(&rrset, NULL);
}
}
......
......@@ -107,15 +107,14 @@ static int knot_zone_diff_changeset_add_rrset(knot_changeset_t *changeset,
return KNOT_EOK;
}
knot_rrset_t *rrset_copy = NULL;
int ret = knot_rrset_copy(rrset, &rrset_copy, NULL);
if (ret != KNOT_EOK) {
knot_rrset_t *rrset_copy = knot_rrset_copy(rrset, NULL);
if (rrset_copy == NULL) {
dbg_zonediff("zone_diff: add_rrset: Cannot copy RRSet.\n");
return ret;
return KNOT_ENOMEM;
}
ret = knot_changeset_add_rrset(changeset, rrset_copy,
KNOT_CHANGESET_ADD);
int ret = knot_changeset_add_rrset(changeset, rrset_copy,
KNOT_CHANGESET_ADD);
if (ret != KNOT_EOK) {
/* We have to free the copy now! */
knot_rrset_free(&rrset_copy, NULL);
......@@ -146,15 +145,14 @@ static int knot_zone_diff_changeset_remove_rrset(knot_changeset_t *changeset,
return KNOT_EOK;
}
knot_rrset_t *rrset_copy = NULL;
int ret = knot_rrset_copy(rrset, &rrset_copy, NULL);
if (ret != KNOT_EOK) {
knot_rrset_t *rrset_copy = knot_rrset_copy(rrset, NULL);
if (rrset_copy == NULL) {
dbg_zonediff("zone_diff: remove_rrset: Cannot copy RRSet.\n");
return ret;
return KNOT_ENOMEM;
}
ret = knot_changeset_add_rrset(changeset, rrset_copy,
KNOT_CHANGESET_REMOVE);
int ret = knot_changeset_add_rrset(changeset, rrset_copy,
KNOT_CHANGESET_REMOVE);
if (ret != KNOT_EOK) {
/* We have to free the copy now. */
knot_rrset_free(&rrset_copy, NULL);
......
......@@ -724,31 +724,6 @@ bool knot_rrset_equal(const knot_rrset_t *r1,
return true;
}
int knot_rrset_copy(const knot_rrset_t *from, knot_rrset_t **to, mm_ctx_t *mm)
{
if (from == NULL || to == NULL) {
return KNOT_EINVAL;
}
dbg_rrset_detail("rr: deep_copy: Copying RRs of type %d\n",
from->type);
*to = knot_rrset_new_from(from, mm);
if (*to == NULL) {
*to = NULL;
return KNOT_ENOMEM;
}
int ret = knot_rrs_copy(&(*to)->rrs, &from->rrs, mm);
if (ret != KNOT_EOK) {
knot_rrset_free(to, mm);
return ret;
}
(*to)->additional = NULL;
return KNOT_EOK;
}
static void rrset_deep_free_content(knot_rrset_t *rrset,
mm_ctx_t *mm)
{
......@@ -1134,10 +1109,24 @@ int knot_rrset_copy_int(knot_rrset_t *dst, const knot_rrset_t *src, mm_ctx_t *mm
return KNOT_EOK;
}
knot_rrset_t *knot_rrset_cpy(const knot_rrset_t *src, mm_ctx_t *mm)
knot_rrset_t *knot_rrset_copy(const knot_rrset_t *src, mm_ctx_t *mm)
{
knot_rrset_t *dst = NULL;
int ret = knot_rrset_copy(src, &dst, mm);
return ret == KNOT_EOK ? dst : NULL;
if (src == NULL) {
return NULL;
}
knot_rrset_t *rrset = knot_rrset_new_from(src, mm);
if (rrset == NULL) {
return NULL;
}
int ret = knot_rrs_copy(&rrset->rrs, &src->rrs, mm);
if (ret != KNOT_EOK) {
knot_rrset_free(&rrset, mm);
return NULL;
}
rrset->additional = NULL;
return rrset;
}
......@@ -173,17 +173,6 @@ bool knot_rrset_equal(const knot_rrset_t *r1,
const knot_rrset_t *r2,
knot_rrset_compare_type_t cmp);
/*!
* \brief Complete copy of RRSet structure.
*
* \param from Source data.
* \param to Destionation data.
* \param mm Memory context.
*
* \return KNOT_E*
*/
int knot_rrset_copy(const knot_rrset_t *from, knot_rrset_t **to, mm_ctx_t *mm);
/*!
* \brief Destroys the RRSet structure and all its substructures.
)
......@@ -346,9 +335,48 @@ int knot_rrset_synth_rrsig(const knot_dname_t *owner, uint16_t type,
const knot_rrset_t *rrsigs,
knot_rrset_t **out_sig, mm_ctx_t *mm);
/*!
* \brief Checks whether RRSet is empty.
*
* \param rrset RRSet to check.
*
* \retval True if RRSet is empty.
* \retval False if RRSet is not empty.
*/
bool knot_rrset_empty(const knot_rrset_t *rrset);
/*!
* \brief Deep copies one RRSet into another.
*
* \param dst Destination RRSet.
* \param src Source RRSet.
* \param mm Memory context.
*
* \return KNOT_E*
*/
int knot_rrset_copy_int(knot_rrset_t *dst, const knot_rrset_t *src, mm_ctx_t *mm);
knot_rrset_t *knot_rrset_cpy(const knot_rrset_t *src, mm_ctx_t *mm);
/*!
* \brief Creates new RRSet from \a src RRSet.
*
* \param src Source RRSet.
* \param mm Memory context.
*
* \retval Pointer to new RRSet if all went OK.
* \retval NULL on error.
*/
knot_rrset_t *knot_rrset_copy(const knot_rrset_t *src, mm_ctx_t *mm);
/*!
* \brief RRSet intersection.
*
* \param a First RRSet to intersect.
* \param b Second RRset to intersect.
* \param out Output RRSet with intersection.
* \param mm Memory context.
*
* \return KNOT_E*
*/
int knot_rrset_intersection(const knot_rrset_t *a, const knot_rrset_t *b,
knot_rrset_t *out, mm_ctx_t *mm);
......
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