Commit f947e863 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

dnssec: equivalent code change

parent 88234334
......@@ -88,22 +88,14 @@ int key_records_dump(char **buf, size_t *buf_size, const key_records_t *r)
}
int ret = KNOT_EOK;
size_t total = 1;
const knot_rrset_t *all_rr[4] = { &r->dnskey, &r->cdnskey, &r->cds, &r->rrsig };
// first go: just detect the size
if (!knot_rrset_empty(&r->dnskey)) {
ret = knot_rrset_txt_dump(&r->dnskey, buf, buf_size, &KNOT_DUMP_STYLE_DEFAULT);
total += ret;
}
if (ret >= 0 && !knot_rrset_empty(&r->cdnskey)) {
ret = knot_rrset_txt_dump(&r->cdnskey, buf, buf_size, &KNOT_DUMP_STYLE_DEFAULT);
total += ret;
}
if (ret >= 0 && !knot_rrset_empty(&r->cds)) {
ret = knot_rrset_txt_dump(&r->cds, buf, buf_size, &KNOT_DUMP_STYLE_DEFAULT);
total += ret;
}
if (ret >= 0 && !knot_rrset_empty(&r->rrsig)) {
ret = knot_rrset_txt_dump(&r->rrsig, buf, buf_size, &KNOT_DUMP_STYLE_DEFAULT);
total += ret;
for (int i = 0; i < 4; i++) {
if (ret >= 0 && !knot_rrset_empty(all_rr[i])) {
ret = knot_rrset_txt_dump(all_rr[i], buf, buf_size, &KNOT_DUMP_STYLE_DEFAULT);
(void)buf;
total += ret;
}
}
if (ret >= 0 && total > *buf_size) {
free(*buf);
......@@ -116,21 +108,13 @@ int key_records_dump(char **buf, size_t *buf_size, const key_records_t *r)
char *fake_buf = *buf;
size_t fake_size = *buf_size;
//second go: do it
if (ret >= 0 && !knot_rrset_empty(&r->dnskey)) {
ret = knot_rrset_txt_dump(&r->dnskey, &fake_buf, &fake_size, &KNOT_DUMP_STYLE_DEFAULT);
fake_buf += ret, fake_size -= ret;
}
if (ret >= 0 && !knot_rrset_empty(&r->cdnskey)) {
ret = knot_rrset_txt_dump(&r->cdnskey, &fake_buf, &fake_size, &KNOT_DUMP_STYLE_DEFAULT);
fake_buf += ret, fake_size -= ret;
}
if (ret >= 0 && !knot_rrset_empty(&r->cds)) {
ret = knot_rrset_txt_dump(&r->cds, &fake_buf, &fake_size, &KNOT_DUMP_STYLE_DEFAULT);
fake_buf += ret, fake_size -= ret;
}
if (ret >= 0 && !knot_rrset_empty(&r->rrsig)) {
ret = knot_rrset_txt_dump(&r->rrsig, &fake_buf, &fake_size, &KNOT_DUMP_STYLE_DEFAULT);
for (int i = 0; i < 4; i++) {
if (ret >= 0 && !knot_rrset_empty(all_rr[i])) {
ret = knot_rrset_txt_dump(all_rr[i], &fake_buf, &fake_size, &KNOT_DUMP_STYLE_DEFAULT);
fake_buf += ret, fake_size -= ret;
}
}
assert(fake_buf - *buf == total - 1);
return ret >= 0 ? KNOT_EOK : 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