Commit dcb9e7fc authored by Daniel Salzman's avatar Daniel Salzman

libknot: add TXT rdataset getters

parent 949487a5
......@@ -415,6 +415,7 @@ src/libknot/rrtype/rrsig.h
src/libknot/rrtype/soa.h
src/libknot/rrtype/tsig.c
src/libknot/rrtype/tsig.h
src/libknot/rrtype/txt.h
src/libknot/tsig-op.c
src/libknot/tsig-op.h
src/libknot/tsig.c
......
......@@ -52,6 +52,7 @@ nobase_libknot_la_HEADERS = \
libknot/rrtype/rrsig.h \
libknot/rrtype/soa.h \
libknot/rrtype/tsig.h \
libknot/rrtype/txt.h \
libknot/tsig-op.h \
libknot/tsig.h
......
......@@ -45,6 +45,7 @@
#include "libknot/rrtype/rrsig.h"
#include "libknot/rrtype/soa.h"
#include "libknot/rrtype/tsig.h"
#include "libknot/rrtype/txt.h"
#include "libknot/tsig-op.h"
/*! @} */
/* Copyright (C) 2015 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "libknot/rdataset.h"
static inline
size_t knot_txt_count(const knot_rdataset_t *rrs, size_t pos)
{
KNOT_RDATASET_CHECK(rrs, pos, return 0);
const knot_rdata_t *rdata = knot_rdataset_at(rrs, pos);
const uint8_t *start = knot_rdata_data(rdata);
const uint8_t *end = start + knot_rdata_rdlen(rdata);
size_t count = 0;
for (const uint8_t *p = start; p < end; p += 1 + *p) {
count++;
}
return count;
}
static inline
const uint8_t *knot_txt_data(const knot_rdataset_t *rrs, size_t pos, size_t index)
{
KNOT_RDATASET_CHECK(rrs, pos, return NULL);
const knot_rdata_t *rdata = knot_rdataset_at(rrs, pos);
const uint8_t *start = knot_rdata_data(rdata);
const uint8_t *end = start + knot_rdata_rdlen(rdata);
const uint8_t *data = start;
for (size_t i = 0; i < index; i++) {
data += 1 + *data;
if (data > end) {
return NULL;
}
}
return data;
}
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