Commit 94ae366b authored by Daniel Salzman's avatar Daniel Salzman

libknot/rdataset: rename structure items

parent 90f073b5
......@@ -540,7 +540,7 @@ static int send_rrset(knot_rrset_t *rrset, send_ctx_t *ctx)
return KNOT_ESPACE;
}
for (size_t i = 0; i < rrset->rrs.rr_count; ++i) {
for (size_t i = 0; i < rrset->rrs.count; ++i) {
ret = knot_rrset_txt_dump_data(rrset, i, ctx->rdata,
sizeof(ctx->rdata), &ctx->style);
if (ret < 0) {
......
......@@ -94,7 +94,7 @@ static int ds_query_consume(knot_layer_t *layer, knot_pkt_t *pkt)
for (size_t j = 0; j < answer->count; j++) {
const knot_rrset_t *rr = knot_pkt_rr(answer, j);
if (!rr || rr->type != KNOT_RRTYPE_DS || rr->rrs.rr_count != 1) {
if (!rr || rr->type != KNOT_RRTYPE_DS || rr->rrs.count != 1) {
ns_log(LOG_WARNING, data->zone_name, LOG_OPERATION_PARENT,
LOG_DIRECTION_OUT, data->remote, "malformed message");
return KNOT_STATE_FAIL;
......
......@@ -44,7 +44,7 @@ inline static bool valid_nsec3_node(const zone_node_t *node)
return false;
}
if (nsec3->rr_count != 1) {
if (nsec3->count != 1) {
return false;
}
......
......@@ -281,11 +281,11 @@ int knot_synth_rrsig(uint16_t type, const knot_rdataset_t *rrsig_rrs,
return KNOT_ENOENT;
}
if (out_sig == NULL || out_sig->rr_count > 0) {
if (out_sig == NULL || out_sig->count > 0) {
return KNOT_EINVAL;
}
for (int i = 0; i < rrsig_rrs->rr_count; ++i) {
for (int i = 0; i < rrsig_rrs->count; ++i) {
if (type == knot_rrsig_type_covered(rrsig_rrs, i)) {
const knot_rdata_t *rr_to_copy = knot_rdataset_at(rrsig_rrs, i);
int ret = knot_rdataset_add(out_sig, rr_to_copy, mm);
......@@ -296,7 +296,7 @@ int knot_synth_rrsig(uint16_t type, const knot_rdataset_t *rrsig_rrs,
}
}
return out_sig->rr_count > 0 ? KNOT_EOK : KNOT_ENOENT;
return out_sig->count > 0 ? KNOT_EOK : KNOT_ENOENT;
}
/*- Verification of signatures -----------------------------------------------*/
......
......@@ -174,7 +174,7 @@ static bool nsec3param_valid(const knot_rdataset_t *rrs,
}
// multiple NSEC3 records
if (rrs->rr_count != 1) {
if (rrs->count != 1) {
return false;
}
......
......@@ -110,7 +110,7 @@ static bool valid_signature_exists(const knot_rrset_t *covered,
return false;
}
uint16_t rrsigs_rdata_count = rrsigs->rrs.rr_count;
uint16_t rrsigs_rdata_count = rrsigs->rrs.count;
for (uint16_t i = 0; i < rrsigs_rdata_count; i++) {
uint16_t rr_keytag = knot_rrsig_key_tag(&rrsigs->rrs, i);
uint16_t rr_covered = knot_rrsig_type_covered(&rrsigs->rrs, i);
......@@ -278,7 +278,7 @@ static int remove_expired_rrsigs(const knot_rrset_t *covered,
return KNOT_EOK;
}
uint16_t rrsig_rdata_count = synth_rrsig.rrs.rr_count;
uint16_t rrsig_rdata_count = synth_rrsig.rrs.count;
for (uint16_t i = 0; i < rrsig_rdata_count; i++) {
struct keyptr_dynarray keys = get_matching_zone_keys(&synth_rrsig, i, zone_keys);
int endloop = 0; // 1 - continue; 2 - break
......@@ -481,7 +481,7 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
return KNOT_EOK;
}
uint16_t rrsigs_rdata_count = rrsigs->rrs.rr_count;
uint16_t rrsigs_rdata_count = rrsigs->rrs.count;
for (uint16_t i = 0; i < rrsigs_rdata_count; ++i) {
uint16_t type_covered = knot_rrsig_type_covered(&rrsigs->rrs, i);
if (!node_rrtype_exists(node, type_covered)) {
......
......@@ -832,7 +832,7 @@ static int soa_query_consume(knot_layer_t *layer, knot_pkt_t *pkt)
const knot_pktsection_t *answer = knot_pkt_section(pkt, KNOT_ANSWER);
const knot_rrset_t *rr = answer->count == 1 ? knot_pkt_rr(answer, 0) : NULL;
if (!rr || rr->type != KNOT_RRTYPE_SOA || rr->rrs.rr_count != 1) {
if (!rr || rr->type != KNOT_RRTYPE_SOA || rr->rrs.count != 1) {
REFRESH_LOG(LOG_WARNING, data->zone->name, data->remote,
"malformed message");
return KNOT_STATE_FAIL;
......
......@@ -114,7 +114,7 @@ void serialize_prepare(serialize_ctx_t *ctx, size_t max_size, size_t *realsize)
size_t candidate = 0;
long tmp_phase = ctx->rrset_phase;
while (1) {
if (tmp_phase >= ctx->rrset_buf[ctx->rrset_buf_size - 1].rrs.rr_count) {
if (tmp_phase >= ctx->rrset_buf[ctx->rrset_buf_size - 1].rrs.count) {
if (ctx->rrset_buf_size >= RRSET_BUF_MAXSIZE) {
return;
}
......@@ -145,7 +145,7 @@ void serialize_chunk(serialize_ctx_t *ctx, uint8_t *dst_chunk, size_t chunk_size
wire_ctx_t wire = wire_ctx_init(dst_chunk, chunk_size);
for (size_t i = 0; ; ) {
if (ctx->rrset_phase >= ctx->rrset_buf[i].rrs.rr_count) {
if (ctx->rrset_phase >= ctx->rrset_buf[i].rrs.count) {
if (++i >= ctx->rrset_buf_size) {
break;
}
......@@ -160,7 +160,7 @@ void serialize_chunk(serialize_ctx_t *ctx, uint8_t *dst_chunk, size_t chunk_size
wire_ctx_skip(&wire, size);
wire_ctx_write_u16(&wire, ctx->rrset_buf[i].type);
wire_ctx_write_u16(&wire, ctx->rrset_buf[i].rclass);
wire_ctx_write_u16(&wire, ctx->rrset_buf[i].rrs.rr_count);
wire_ctx_write_u16(&wire, ctx->rrset_buf[i].rrs.count);
} else {
const knot_rdata_t *rr = knot_rdataset_at(&ctx->rrset_buf[i].rrs,
ctx->rrset_phase);
......@@ -265,7 +265,7 @@ int deserialize_rrset_chunks(wire_ctx_t *wire, knot_rrset_t *rrset,
static uint64_t rrset_binary_size(const knot_rrset_t *rrset)
{
if (rrset == NULL || rrset->rrs.rr_count == 0) {
if (rrset == NULL || rrset->rrs.count == 0) {
return 0;
}
......@@ -273,7 +273,7 @@ static uint64_t rrset_binary_size(const knot_rrset_t *rrset)
uint64_t size = knot_dname_size(rrset->owner) + 3 * sizeof(uint16_t);
// RRs.
for (uint16_t i = 0; i < rrset->rrs.rr_count; i++) {
for (uint16_t i = 0; i < rrset->rrs.count; i++) {
const knot_rdata_t *rr = knot_rdataset_at(&rrset->rrs, i);
assert(rr);
......
......@@ -824,7 +824,7 @@ int process_query_put_rr(knot_pkt_t *pkt, knotd_qdata_t *qdata,
const knot_rrset_t *rr, const knot_rrset_t *rrsigs,
uint16_t compr_hint, uint32_t flags)
{
if (rr->rrs.rr_count < 1) {
if (rr->rrs.count < 1) {
return KNOT_EMALF;
}
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 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
......@@ -76,10 +76,10 @@ static int replace_rdataset_with_copy(zone_node_t *node, uint16_t type)
return KNOT_ENOMEM;
}
memcpy(copy, rrs->data, knot_rdataset_size(rrs));
memcpy(copy, rrs->rdata, knot_rdataset_size(rrs));
// Store new data into node RRS.
rrs->data = copy;
rrs->rdata = copy;
return KNOT_EOK;
}
......@@ -126,7 +126,7 @@ static bool can_remove(const zone_node_t *node, const knot_rrset_t *rr)
return false;
}
for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) {
for (uint16_t i = 0; i < rr->rrs.count; ++i) {
knot_rdata_t *rr_cmp = knot_rdataset_at(&rr->rrs, i);
if (knot_rdataset_member(node_rrs, rr_cmp)) {
// At least one RR matches.
......@@ -264,7 +264,7 @@ int apply_add_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
knot_rrset_t changed_rrset = node_rrset(node, rr->type);
if (!knot_rrset_empty(&changed_rrset)) {
// Modifying existing RRSet.
knot_rdata_t *old_data = changed_rrset.rrs.data;
knot_rdata_t *old_data = changed_rrset.rrs.rdata;
int ret = replace_rdataset_with_copy(node, rr->type);
if (ret != KNOT_EOK) {
return ret;
......@@ -283,7 +283,7 @@ int apply_add_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
if (ret == KNOT_EOK || ret == KNOT_ETTL) {
// RR added, store for possible rollback.
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
int data_ret = add_new_data(ctx, rrs->data);
int data_ret = add_new_data(ctx, rrs->rdata);
if (data_ret != KNOT_EOK) {
knot_rdataset_clear(rrs, NULL);
return data_ret;
......@@ -326,7 +326,7 @@ int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
contents->nsec3_nodes : contents->nodes;
knot_rrset_t removed_rrset = node_rrset(node, rr->type);
knot_rdata_t *old_data = removed_rrset.rrs.data;
knot_rdata_t *old_data = removed_rrset.rrs.rdata;
int ret = replace_rdataset_with_copy(node, rr->type);
if (ret != KNOT_EOK) {
return ret;
......@@ -347,9 +347,9 @@ int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
return ret;
}
if (changed_rrs->rr_count > 0) {
if (changed_rrs->count > 0) {
// Subtraction left some data in RRSet, store it for rollback.
ret = add_new_data(ctx, changed_rrs->data);
ret = add_new_data(ctx, changed_rrs->rdata);
if (ret != KNOT_EOK) {
knot_rdataset_clear(changed_rrs, NULL);
return ret;
......
......@@ -163,7 +163,7 @@ static int check_not_in_use(zone_update_t *update,
/*!< \brief Returns true if rrset has 0 data or RDATA of size 0 (we need TTL).*/
static bool rrset_empty(const knot_rrset_t *rrset)
{
uint16_t rr_count = rrset->rrs.rr_count;
uint16_t rr_count = rrset->rrs.count;
if (rr_count == 0) {
return true;
}
......@@ -282,7 +282,7 @@ static bool node_contains_rr(const zone_node_t *node,
{
const knot_rdataset_t *zone_rrs = node_rdataset(node, rr->type);
if (zone_rrs) {
assert(rr->rrs.rr_count == 1);
assert(rr->rrs.count == 1);
return knot_rdataset_member(zone_rrs, knot_rdataset_at(&rr->rrs, 0));
} else {
return false;
......@@ -494,7 +494,7 @@ static int process_rem_rr(const knot_rrset_t *rr,
// Zone without apex NS.
return KNOT_EOK;
}
if (ns_rrs->rr_count == 1) {
if (ns_rrs->count == 1) {
// Cannot remove last apex NS RR.
return KNOT_EOK;
}
......@@ -507,7 +507,7 @@ static int process_rem_rr(const knot_rrset_t *rr,
}
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
if (!knot_rdataset_member(rrs, rr->rrs.data)) {
if (!knot_rdataset_member(rrs, rr->rrs.rdata)) {
// Node does not contain this RR
return KNOT_EOK;
}
......
......@@ -120,7 +120,7 @@ static int discover_additionals(const knot_dname_t *owner, struct rr_data *rr_da
rr_data->additional = NULL;
const knot_rdataset_t *rrs = &rr_data->rrs;
uint16_t rdcount = rrs->rr_count;
uint16_t rdcount = rrs->count;
uint16_t mandatory_count = 0;
uint16_t others_count = 0;
......@@ -353,7 +353,7 @@ static int adjust_nsec3_node(zone_node_t **tnode, void *data)
// check if this node belongs to correct chain
const knot_rdataset_t *nsec3_rrs = node_rdataset(node, KNOT_RRTYPE_NSEC3);
for (uint16_t i = 0; nsec3_rrs != NULL && i < nsec3_rrs->rr_count; i++) {
for (uint16_t i = 0; nsec3_rrs != NULL && i < nsec3_rrs->count; i++) {
if (nsec3_params_match(nsec3_rrs, &args->zone->nsec3_params, i)) {
node->flags |= NODE_FLAGS_IN_NSEC3_CHAIN;
}
......@@ -641,7 +641,7 @@ static int remove_rr(zone_contents_t *z, const knot_rrset_t *rr,
return ret;
}
if (node_rrs->rr_count == 0) {
if (node_rrs->count == 0) {
// RRSet is empty now, remove it from node, all data freed.
node_remove_rdataset(node, rr->type);
// If node is empty now, delete it from zone tree.
......@@ -966,7 +966,7 @@ static int load_nsec3param(zone_contents_t *contents)
return KNOT_EOK;
}
if (rrs->rr_count < 1) {
if (rrs->count < 1) {
return KNOT_EINVAL;
}
......
......@@ -76,7 +76,7 @@ static int add_rrset_no_merge(zone_node_t *node, const knot_rrset_t *rrset,
/*! \brief Checks if the added RR has the same TTL as the first RR in the node. */
static bool ttl_changed(struct rr_data *node_data, const knot_rrset_t *rrset)
{
if (rrset->type == KNOT_RRTYPE_RRSIG || node_data->rrs.rr_count == 0) {
if (rrset->type == KNOT_RRTYPE_RRSIG || node_data->rrs.count == 0) {
return false;
}
......@@ -272,7 +272,7 @@ bool node_rrtype_is_signed(const zone_node_t *node, uint16_t type)
return false;
}
uint16_t rrsigs_rdata_count = rrsigs->rr_count;
uint16_t rrsigs_rdata_count = rrsigs->count;
for (uint16_t i = 0; i < rrsigs_rdata_count; ++i) {
const uint16_t type_covered =
knot_rrsig_type_covered(rrsigs, i);
......
......@@ -349,7 +349,7 @@ static int check_rrsig_rdata(sem_handler_t *handler,
return KNOT_EOK;
}
for (int i = 0; i < dnskeys->rr_count; i++) {
for (int i = 0; i < dnskeys->count; i++) {
uint16_t flags = knot_dnskey_flags(dnskeys, i);
uint8_t proto = knot_dnskey_proto(dnskeys, i);
/* RFC 4034 2.1.1 & 2.1.2 */
......@@ -432,7 +432,7 @@ static int check_rrsig_in_rrset(sem_handler_t *handler,
}
bool verified = false;
for (uint16_t i = 0; ret == KNOT_EOK && i < (&rrsigs)->rr_count; ++i) {
for (uint16_t i = 0; ret == KNOT_EOK && i < (&rrsigs)->count; ++i) {
ret = check_rrsig_rdata(handler, zone, node, &rrsigs, i, rrset,
context, level, &verified);
}
......@@ -468,7 +468,7 @@ static int check_delegation(const zone_node_t *node, semchecks_data_t *data)
}
// check glue record for delegation
for (int i = 0; i < ns_rrs->rr_count; ++i) {
for (int i = 0; i < ns_rrs->count; ++i) {
const knot_dname_t *ns_dname = knot_ns_name(ns_rrs, i);
if (!knot_dname_is_sub(ns_dname, node->owner)) {
continue;
......@@ -515,11 +515,11 @@ static int check_submission(const zone_node_t *node, semchecks_data_t *data)
return KNOT_EOK;
}
if (cdss->rr_count != 1) {
if (cdss->count != 1) {
data->handler->cb(data->handler, data->zone, node,
SEM_ERR_CDS_MULTIPLE, NULL);
}
if (cdnskeys->rr_count != 1) {
if (cdnskeys->count != 1) {
data->handler->cb(data->handler, data->zone, node,
SEM_ERR_CDNSKEY_MULTIPLE, NULL);
}
......@@ -530,7 +530,7 @@ static int check_submission(const zone_node_t *node, semchecks_data_t *data)
const knot_rdataset_t *dnskeys = node_rdataset(data->zone->apex,
KNOT_RRTYPE_DNSKEY);
for (int i = 0; dnskeys != NULL && i < dnskeys->rr_count; i++) {
for (int i = 0; dnskeys != NULL && i < dnskeys->count; i++) {
knot_rdata_t *dnskey = knot_rdataset_at(dnskeys, i);
if (knot_rdata_cmp(dnskey, cdnskey) != 0) {
continue;
......@@ -585,7 +585,7 @@ static int check_ds(const zone_node_t *node, semchecks_data_t *data)
return KNOT_EOK;
}
for (int i = 0; i < dss->rr_count; i++) {
for (int i = 0; i < dss->count; i++) {
uint16_t keytag = knot_ds_key_tag(dss, i);
uint8_t digest_type = knot_ds_digest_type(dss, i);
......@@ -772,7 +772,7 @@ static int check_nsec(const zone_node_t *node, semchecks_data_t *data)
}
/* Test that only one record is in the NSEC RRSet */
if (nsec_rrs->rr_count != 1) {
if (nsec_rrs->count != 1) {
data->handler->cb(data->handler, data->zone, node,
SEM_ERR_NSEC_RDATA_MULTIPLE, NULL);
}
......@@ -1015,7 +1015,7 @@ static int check_cname(const zone_node_t *node, semchecks_data_t *data)
data->handler->cb(data->handler, data->zone, node,
SEM_ERR_CNAME_EXTRA_RECORDS, NULL);
}
if (cname_rrs->rr_count != 1) {
if (cname_rrs->count != 1) {
data->handler->fatal_error = true;
data->handler->cb(data->handler, data->zone, node,
SEM_ERR_CNAME_MULTIPLE, NULL);
......@@ -1114,7 +1114,7 @@ static void check_dnskey(zone_contents_t *zone, sem_handler_t *handler)
return;
}
for (int i = 0; i < dnskeys->rr_count; i++) {
for (int i = 0; i < dnskeys->count; i++) {
knot_rdata_t *dnskey = knot_rdataset_at(dnskeys, i);
dnssec_key_t *key;
int ret = dnssec_key_from_rdata(&key, zone->apex->owner,
......
......@@ -46,8 +46,8 @@ static int load_soas(const zone_contents_t *zone1, const zone_contents_t *zone2,
return KNOT_EINVAL;
}
if (soa_rrset1.rrs.rr_count == 0 ||
soa_rrset2.rrs.rr_count == 0) {
if (soa_rrset1.rrs.count == 0 ||
soa_rrset2.rrs.count == 0) {
return KNOT_EINVAL;
}
......@@ -129,7 +129,7 @@ static int rdata_return_changes(const knot_rrset_t *rrset1,
* changed/removed rdatas. This has awful computation time.
*/
bool ttl_differ = rrset1->ttl != rrset2->ttl;
uint16_t rr1_count = rrset1->rrs.rr_count;
uint16_t rr1_count = rrset1->rrs.count;
for (uint16_t i = 0; i < rr1_count; ++i) {
if (ttl_differ || !rr_exists(rrset2, rrset1, i)) {
/*
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2018 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
......@@ -48,7 +48,7 @@ static int apex_node_dump_text(zone_node_t *node, dump_params_t *params)
if (ret < 0) {
return ret;
}
params->rr_count += soa.rrs.rr_count;
params->rr_count += soa.rrs.count;
fprintf(params->file, "%s", params->buf);
params->buf[0] = '\0';
}
......@@ -72,7 +72,7 @@ static int apex_node_dump_text(zone_node_t *node, dump_params_t *params)
if (ret < 0) {
return ret;
}
params->rr_count += rrset.rrs.rr_count;
params->rr_count += rrset.rrs.count;
fprintf(params->file, "%s", params->buf);
params->buf[0] = '\0';
}
......@@ -128,7 +128,7 @@ static int node_dump_text(zone_node_t *node, void *data)
if (ret < 0) {
return ret;
}
params->rr_count += rrset.rrs.rr_count;
params->rr_count += rrset.rrs.count;
fprintf(params->file, "%s", params->buf);
params->buf[0] = '\0';
}
......
......@@ -76,7 +76,7 @@ static bool handle_err(zcreator_t *zc, const knot_rrset_t *rr, int ret, bool mas
int zcreator_step(zcreator_t *zc, const knot_rrset_t *rr)
{
if (zc == NULL || rr == NULL || rr->rrs.rr_count != 1) {
if (zc == NULL || rr == NULL || rr->rrs.count != 1) {
return KNOT_EINVAL;
}
......
......@@ -43,8 +43,8 @@ static bool pkt_contains(const knot_pkt_t *packet, const knot_rrset_t *rrset)
for (int i = 0; i < packet->rrset_count; ++i) {
const uint16_t type = packet->rr[i].type;
const knot_rdata_t *data = packet->rr[i].rrs.data;
if (type == rrset->type && data == rrset->rrs.data) {
const knot_rdata_t *data = packet->rr[i].rrs.rdata;
if (type == rrset->type && data == rrset->rrs.rdata) {
return true;
}
}
......@@ -544,7 +544,7 @@ int knot_pkt_put_rotate(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t
}
size_t len = ret;
uint16_t rr_added = rr->rrs.rr_count;
uint16_t rr_added = rr->rrs.count;
/* Keep reference to special types. */
if (rr->type == KNOT_RRTYPE_OPT) {
......@@ -736,7 +736,7 @@ static int parse_payload(knot_pkt_t *pkt, unsigned flags)
const knot_pktsection_t *ar = knot_pkt_section(pkt, KNOT_ADDITIONAL);
if (pkt->tsig_rr != NULL) {
const knot_rrset_t *last_rr = knot_pkt_rr(ar, ar->count - 1);
if (ar->count > 0 && pkt->tsig_rr->rrs.data != last_rr->rrs.data) {
if (ar->count > 0 && pkt->tsig_rr->rrs.rdata != last_rr->rrs.rdata) {
return KNOT_EMALF;
}
}
......
......@@ -316,7 +316,7 @@ static int write_fixed_header(const knot_rrset_t *rrset, uint16_t rrset_index,
uint8_t **dst, size_t *dst_avail)
{
assert(rrset);
assert(rrset_index < rrset->rrs.rr_count);
assert(rrset_index < rrset->rrs.count);
assert(dst && *dst);
assert(dst_avail);
......@@ -420,7 +420,7 @@ static int write_rdata(const knot_rrset_t *rrset, uint16_t rrset_index,
uint8_t **dst, size_t *dst_avail, knot_compr_t *compr)
{
assert(rrset);
assert(rrset_index < rrset->rrs.rr_count);
assert(rrset_index < rrset->rrs.count);
assert(dst && *dst);
assert(dst_avail);
......@@ -486,17 +486,17 @@ int knot_rrset_to_wire_rotate(const knot_rrset_t *rrset, uint8_t *wire,
if (rrset == NULL || wire == NULL) {
return KNOT_EINVAL;
}
if (rrset->rrs.rr_count == 0) {
if (rrset->rrs.count == 0) {
return 0;
}
if (rotate != 0) {
rotate %= rrset->rrs.rr_count;
rotate %= rrset->rrs.count;
}
uint8_t *write = wire;
size_t capacity = max_size;
uint16_t count = rrset->rrs.rr_count;
uint16_t count = rrset->rrs.count;
for (uint16_t i = rotate; i < count + rotate; i++) {
uint16_t pos = (i < count) ? i : (i - count);
int ret = write_rr(rrset, pos, &write, &capacity, compr);
......
......@@ -26,10 +26,10 @@
static knot_rdata_t *rr_seek(const knot_rdataset_t *rrs, uint16_t pos)
{
assert(rrs);
assert(0 < rrs->rr_count);
assert(pos < rrs->rr_count);
assert(0 < rrs->count);
assert(pos < rrs->count);
uint8_t *raw = (uint8_t *)(rrs->data);
uint8_t *raw = (uint8_t *)(rrs->rdata);
for (uint16_t i = 0; i < pos; ++i) {
raw += knot_rdata_size(((knot_rdata_t *)raw)->len);
}
......@@ -39,7 +39,7 @@ static knot_rdata_t *rr_seek(const knot_rdataset_t *rrs, uint16_t pos)
static int find_rr_pos(const knot_rdataset_t *rrs, const knot_rdata_t *rr)
{
for (uint16_t i = 0; i < rrs->rr_count; ++i) {
for (uint16_t i = 0; i < rrs->count; ++i) {
const knot_rdata_t *search_rr = rr_seek(rrs, i);
if (knot_rdata_cmp(rr, search_rr) == 0) {
return i;
......@@ -54,9 +54,9 @@ static int add_rr_at(knot_rdataset_t *rrs, const knot_rdata_t *rr, uint16_t pos,
{
assert(rrs);
assert(rr);
assert(pos <= rrs->rr_count);
assert(pos <= rrs->count);
if (rrs->rr_count == UINT16_MAX) {
if (rrs->count == UINT16_MAX) {
return KNOT_ESPACE;
}
......@@ -64,17 +64,17 @@ static int add_rr_at(knot_rdataset_t *rrs, const knot_rdata_t *rr, uint16_t pos,
size_t new_size = knot_rdata_size(rr->len);
// Realloc RDATA.
knot_rdata_t *tmp = mm_realloc(mm, rrs->data, total_size + new_size,
knot_rdata_t *tmp = mm_realloc(mm, rrs->rdata, total_size + new_size,
total_size);
if (tmp == NULL) {
return KNOT_ENOMEM;
} else {
rrs->data = tmp;
rrs->rdata = tmp;
}
if (rrs->rr_count == 0 || pos == rrs->rr_count) {
if (rrs->count == 0 || pos == rrs->count) {
// No need to rearange RDATA.
rrs->rr_count++;
rrs->count++;
knot_rdata_t *new_rr = rr_seek(rrs, pos);
knot_rdata_init(new_rr, rr->len, rr->data);
return KNOT_EOK;
......@@ -82,7 +82,7 @@ static int add_rr_at(knot_rdataset_t *rrs, const knot_rdata_t *rr, uint16_t pos,
// RDATA have to be rearanged.
knot_rdata_t *old_rr = rr_seek(rrs, pos);
knot_rdata_t *last_rr = rr_seek(rrs, rrs->rr_count - 1);
knot_rdata_t *last_rr = rr_seek(rrs, rrs->count - 1);
// Make space for new RDATA by moving the array.
uint8_t *dst = (uint8_t *)old_rr + new_size;
......@@ -93,7 +93,7 @@ static int add_rr_at(knot_rdataset_t *rrs, const knot_rdata_t *rr, uint16_t pos,
// Set new RDATA.
knot_rdata_init(old_rr, rr->len, rr->data);
rrs->rr_count++;
rrs->count++;
return KNOT_EOK;
}
......@@ -101,11 +101,11 @@ static int add_rr_at(knot_rdataset_t *rrs, const knot_rdata_t *rr, uint16_t pos,
static int remove_rr_at(knot_rdataset_t *rrs, uint16_t pos, knot_mm_t *mm)
{
assert(rrs);
assert(0 < rrs->rr_count);
assert(pos < rrs->rr_count);
assert(0 < rrs->count);
assert(pos < rrs->count);
knot_rdata_t *old_rr = rr_seek(rrs, pos);
knot_rdata_t *last_rr = rr_seek(rrs, rrs->rr_count - 1);
knot_rdata_t *last_rr = rr_seek(rrs, rrs->count - 1);
size_t total_size = knot_rdataset_size(rrs);
size_t old_size = knot_rdata_size(old_rr->len);
......@@ -116,21 +116,21 @@ static int remove_rr_at(knot_rdataset_t *rrs, uint16_t pos, knot_mm_t *mm)
assert(old_threshold <= last_threshold);
memmove(old_rr, old_threshold, last_threshold - old_threshold);
if (rrs->rr_count > 1) {
if (rrs->count > 1) {
// Realloc RDATA.
knot_rdata_t *tmp = mm_realloc(mm, rrs->data, total_size - old_size,
knot_rdata_t *tmp = mm_realloc(mm, rrs->rdata, total_size - old_size,
total_size);
if (tmp == NULL) {
return KNOT_ENOMEM;
} else {
rrs->data = tmp;
rrs->rdata = tmp;
}
} else {
// Free RDATA.
mm_free(mm, rrs->data);
rrs->data = NULL;
mm_free(mm, rrs->rdata);
rrs->rdata = NULL;
}
rrs->rr_count--;
rrs->count--;
return KNOT_EOK;
}
......@@ -142,7 +142,7 @@ void knot_rdataset_clear(knot_rdataset_t *rrs, knot_mm_t *mm)
return;
}
mm_free(mm, rrs->data);
mm_free(mm, rrs->rdata);
knot_rdataset_init(rrs);
}
......@@ -153,14 +153,14 @@ int knot_rdataset_copy(knot_rdataset_t *dst, const knot_rdataset_t *src, knot_mm
return KNOT_EINVAL;
}
dst->rr_count = src->rr_count;
dst->count = src->count;
size_t src_size = knot_rdataset_size(src);
dst->data = mm_alloc(mm, src_size);
if (dst->data == NULL) {
dst->rdata = mm_alloc(mm, src_size);
if (dst->rdata == NULL) {
return KNOT_ENOMEM;
}
memcpy(dst->data, src->data, src_size);
memcpy(dst->rdata, src->rdata, src_size);
return KNOT_EOK;
}
......@@ -168,7 +168,7 @@ int knot_rdataset_copy(knot_rdataset_t *dst, const knot_rdataset_t *src, knot_mm
_public_
knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *rrs, uint16_t pos)
{
if (rrs == NULL || rrs->rr_count == 0 || pos >= rrs->rr_count) {
if (rrs == NULL || rrs->count == 0 || pos >= rrs->count) {
return NULL;
}
......@@ -178,12 +178,12 @@ knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *rrs, uint16_t pos)
_public_
size_t knot_rdataset_size(const knot_rdataset_t *rrs)
{
if (rrs == NULL || rrs->rr_count == 0) {
if (rrs == NULL || rrs->count == 0) {
return 0;
}
const knot_rdata_t *last = rr_seek(rrs, rrs->rr_count - 1);
return (uint8_t *)last + knot_rdata_size(last->len) - (uint8_t *)rrs->data;
const knot_rdata_t *last = rr_seek(rrs, rrs->count - 1);
return (uint8_t *)last + knot_rdata_size(last->len) - (uint8_t *)rrs->rdata;
}
_public_
......@@ -194,11 +194,11 @@ int knot_rdataset_add(knot_rdataset_t *rrs, const knot_rdata_t *rr, knot_mm_t *m
}
// First insert to empty rdataset.
if (rrs->rr_count == 0) {
if (rrs->count == 0) {
return add_rr_at(rrs, rr, 0, mm);
}
for (int i = rrs->rr_count - 1; i >= 0; --i) {
for (int i = rrs->count - 1; i >= 0; --i) {
const knot_rdata_t *rrset_rr = rr_seek(rrs, i);
int cmp = knot_rdata_cmp(rrset_rr, rr);
if (cmp == 0) {
......@@ -219,22 +219,22 @@ int knot_rdataset_reserve(knot_rdataset_t *rrs, uint16_t size, knot_mm_t *mm)
{
if (rrs == NULL) {
return KNOT_EINVAL;
} else if (rrs->rr_count == UINT16_MAX) {
} else if (rrs->count == UINT16_MAX) {
return KNOT_ESPACE;
}