Commit 919ee662 authored by Marek Vavruša's avatar Marek Vavruša

libknot: split rr.h into rdata.h and rdataset.h

parent 26378b61
......@@ -189,8 +189,6 @@ src/libknot/dnssec/crypto.c
src/libknot/dnssec/crypto.h
src/libknot/dnssec/key.c
src/libknot/dnssec/key.h
src/libknot/dnssec/nsec3.c
src/libknot/dnssec/nsec3.h
src/libknot/dnssec/policy.c
src/libknot/dnssec/policy.h
src/libknot/dnssec/random.h
......@@ -210,24 +208,27 @@ src/libknot/packet/pkt.h
src/libknot/packet/wire.h
src/libknot/processing/process.c
src/libknot/processing/process.h
src/libknot/rdata.c
src/libknot/rdata.h
src/libknot/rdata/dname.h
src/libknot/rdata/dnskey.h
src/libknot/rdata/nsec.h
src/libknot/rdata/nsec3.c
src/libknot/rdata/nsec3.h
src/libknot/rdata/nsec3param.c
src/libknot/rdata/nsec3param.h
src/libknot/rdata/rrsig.h
src/libknot/rdata/soa.h
src/libknot/rr.c
src/libknot/rr.h
src/libknot/rdata/tsig.c
src/libknot/rdata/tsig.h
src/libknot/rdataset.c
src/libknot/rdataset.h
src/libknot/rrset-dump.c
src/libknot/rrset-dump.h
src/libknot/rrset.c
src/libknot/rrset.h
src/libknot/tsig-op.c
src/libknot/tsig-op.h
src/libknot/tsig.c
src/libknot/tsig.h
src/libknot/util/endian.h
src/libknot/util/tolower.c
src/libknot/util/tolower.h
......
......@@ -181,8 +181,10 @@ libknot_la_SOURCES = \
libknot/rdata/tsig.h \
libknot/rrset-dump.c \
libknot/rrset-dump.h \
libknot/rr.c \
libknot/rr.h \
libknot/rdata.c \
libknot/rdata.h \
libknot/rdataset.c \
libknot/rdataset.h \
libknot/rrset.c \
libknot/rrset.h \
libknot/tsig-op.c \
......
/*!
* \file rr.h
* \file serialization.h
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
......
......@@ -23,7 +23,7 @@
#include "libknot/common.h"
#include "knot/zone/node.h"
#include "libknot/rrset.h"
#include "libknot/rr.h"
#include "libknot/rdataset.h"
#include "libknot/rdata/rrsig.h"
#include "common/descriptor.h"
#include "common/debug.h"
......
......@@ -31,7 +31,7 @@
#include "common/descriptor.h"
#include "libknot/dname.h"
#include "libknot/rrset.h"
#include "libknot/rr.h"
#include "libknot/rdataset.h"
struct rr_data;
......
......@@ -33,7 +33,7 @@
#include "libknot/packet/wire.h"
#include "libknot/packet/compr.h"
#include "libknot/packet/pkt.h"
#include "libknot/rr.h"
#include "libknot/rdataset.h"
#include "libknot/rrset.h"
#include "libknot/rrset-dump.h"
#include "libknot/rdata/dname.h"
......
/* Copyright (C) 2014 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/>.
*/
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "libknot/rdata.h"
#include "libknot/common.h"
#include "common/errcode.h"
#ifndef STRICT_ALIGNMENT
#pragma pack(push, 1)
#endif
/*!< \brief Helper structure - offsets in RR array. */
struct rr_offsets {
uint32_t ttl;
uint16_t size;
uint8_t rdata[];
};
#ifndef STRICT_ALIGNMENT
#pragma pack(pop)
#endif
uint16_t knot_rr_rdata_size(const knot_rr_t *rr)
{
return ((struct rr_offsets *)rr)->size;
}
void knot_rr_set_size(knot_rr_t *rr, uint16_t size)
{
((struct rr_offsets *)rr)->size = size;
}
uint32_t knot_rr_ttl(const knot_rr_t *rr)
{
return ((struct rr_offsets *)rr)->ttl;
}
void knot_rr_set_ttl(knot_rr_t *rr, uint32_t ttl)
{
((struct rr_offsets *)rr)->ttl = ttl;
}
uint8_t *knot_rr_rdata(const knot_rr_t *rr)
{
return ((struct rr_offsets *)rr)->rdata;
}
size_t knot_rr_array_size(uint16_t size)
{
return size + sizeof(struct rr_offsets);
}
int knot_rr_cmp(const knot_rr_t *rr1, const knot_rr_t *rr2)
{
assert(rr1 && rr2);
const uint8_t *r1 = knot_rr_rdata(rr1);
const uint8_t *r2 = knot_rr_rdata(rr2);
uint16_t l1 = knot_rr_rdata_size(rr1);
uint16_t l2 = knot_rr_rdata_size(rr2);
int cmp = memcmp(r1, r2, MIN(l1, l2));
if (cmp == 0 && l1 != l2) {
cmp = l1 < l2 ? -1 : 1;
}
return cmp;
}
/*!
* \file rdata.h
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* \brief API for manipulating RRs and RR arrays.
*
* \addtogroup libknot
* @{
*/
/* Copyright (C) 2014 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 <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "common/mempattern.h"
/* ---------------------------- Single RR ----------------------------------- */
/*!
* \brief knot_rr_t Array holding single RR payload, i.e. ttl, size and RDATA.
*/
typedef uint8_t knot_rr_t;
/* ------------------------- RR getters/setters ----------------------------- */
/*!
* \brief Returns RDATA size of single RR.
* \param rr RR whose size we want.
* \return RR size.
*/
uint16_t knot_rr_rdata_size(const knot_rr_t *rr);
/*!
* \brief Sets size for given RR.
* \param rr RR whose size we want to set.
* \param size Size to be set.
*/
void knot_rr_set_size(knot_rr_t *rr, uint16_t size);
/*!
* \brief Returns TTL of single RR.
* \param rr RR whose TTL we want.
* \return RR TTL.
*/
uint32_t knot_rr_ttl(const knot_rr_t *rr);
/*!
* \brief Sets TTL for given RR.
* \param rr RR whose TTL we want to set.
* \param ttl TTL to be set.
*/
void knot_rr_set_ttl(knot_rr_t *rr, uint32_t ttl);
/*!
* \brief Returns pointer to RR data.
* \param rr RR whose data we want.
* \return RR data pointer.
*/
uint8_t *knot_rr_rdata(const knot_rr_t *rr);
/* ----------------------------- RR misc ------------------------------------ */
/*!
* \brief Returns actual size of RR structure for given RDATA size.
* \param size RDATA size.
* \return Actual structure size.
*/
size_t knot_rr_array_size(uint16_t size);
/*!
* \brief Canonical comparison of two RRs. Both RRs *must* exist.
* \param rr1 First RR to compare.
* \param rr2 Second RR to compare.
* \retval 0 if rr1 == rr2.
* \retval < 0 if rr1 < rr2.
* \retval > 0 if rr1 > rr2.
*/
int knot_rr_cmp(const knot_rr_t *rr1, const knot_rr_t *rr2);
......@@ -17,7 +17,7 @@
#pragma once
#include "common/descriptor.h"
#include "libknot/rr.h"
#include "libknot/rdataset.h"
#include "libknot/dname.h"
static inline
......
......@@ -16,7 +16,7 @@
#pragma once
#include "libknot/rr.h"
#include "libknot/rdataset.h"
#define KNOT_RDATA_DNSKEY_FLAG_KSK 1
......
......@@ -16,7 +16,7 @@
#pragma once
#include "libknot/rr.h"
#include "libknot/rdataset.h"
static inline
const knot_dname_t *knot_nsec_next(const knot_rrs_t *rrs)
......
......@@ -32,7 +32,7 @@
#include <string.h>
#include "libknot/consts.h"
#include "libknot/rr.h"
#include "libknot/rdataset.h"
#include "libknot/rdata/nsec3param.h"
static inline
......
......@@ -21,7 +21,7 @@
#include <string.h>
#include "libknot/consts.h"
#include "libknot/rr.h"
#include "libknot/rdataset.h"
/*!
* \brief Structure representing the NSEC3PARAM resource record.
......
......@@ -16,7 +16,7 @@
#pragma once
#include "libknot/rr.h"
#include "libknot/rdataset.h"
static inline
uint16_t knot_rrsig_type_covered(const knot_rrs_t *rrs, size_t pos)
......
......@@ -16,7 +16,7 @@
#pragma once
#include "libknot/rr.h"
#include "libknot/rdataset.h"
#include "libknot/dname.h"
static inline
......
......@@ -19,24 +19,8 @@
#include <stdio.h>
#include <stdlib.h>
#include "libknot/rr.h"
#include "libknot/rdataset.h"
#include "libknot/common.h"
#include "common/errcode.h"
#ifndef STRICT_ALIGNMENT
#pragma pack(push, 1)
#endif
/*!< \brief Helper structure - offsets in RR array. */
struct rr_offsets {
uint32_t ttl;
uint16_t size;
uint8_t rdata[];
};
#ifndef STRICT_ALIGNMENT
#pragma pack(pop)
#endif
static void *mm_realloc(mm_ctx_t *mm, void *what, size_t size, size_t prev_size)
{
......@@ -59,6 +43,7 @@ static void *mm_realloc(mm_ctx_t *mm, void *what, size_t size, size_t prev_size)
}
}
static knot_rr_t *rr_seek(knot_rr_t *d, size_t pos)
{
if (d == NULL) {
......@@ -180,50 +165,6 @@ static int remove_rr_at(knot_rrs_t *rrs, size_t pos, mm_ctx_t *mm)
return KNOT_EOK;
}
uint16_t knot_rr_rdata_size(const knot_rr_t *rr)
{
return ((struct rr_offsets *)rr)->size;
}
void knot_rr_set_size(knot_rr_t *rr, uint16_t size)
{
((struct rr_offsets *)rr)->size = size;
}
uint32_t knot_rr_ttl(const knot_rr_t *rr)
{
return ((struct rr_offsets *)rr)->ttl;
}
void knot_rr_set_ttl(knot_rr_t *rr, uint32_t ttl)
{
((struct rr_offsets *)rr)->ttl = ttl;
}
uint8_t *knot_rr_rdata(const knot_rr_t *rr)
{
return ((struct rr_offsets *)rr)->rdata;
}
size_t knot_rr_array_size(uint16_t size)
{
return size + sizeof(struct rr_offsets);
}
int knot_rr_cmp(const knot_rr_t *rr1, const knot_rr_t *rr2)
{
assert(rr1 && rr2);
const uint8_t *r1 = knot_rr_rdata(rr1);
const uint8_t *r2 = knot_rr_rdata(rr2);
uint16_t l1 = knot_rr_rdata_size(rr1);
uint16_t l2 = knot_rr_rdata_size(rr2);
int cmp = memcmp(r1, r2, MIN(l1, l2));
if (cmp == 0 && l1 != l2) {
cmp = l1 < l2 ? -1 : 1;
}
return cmp;
}
void knot_rrs_init(knot_rrs_t *rrs)
{
if (rrs) {
......@@ -404,5 +345,4 @@ int knot_rrs_subtract(knot_rrs_t *from, const knot_rrs_t *what, mm_ctx_t *mm)
}
return KNOT_EOK;
}
}
\ No newline at end of file
/*!
* \file rr.h
* \file rdataset.h
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
......@@ -31,69 +31,7 @@
#include <stdbool.h>
#include "common/mempattern.h"
/* ---------------------------- Single RR ----------------------------------- */
/*!
* \brief knot_rr_t Array holding single RR payload, i.e. ttl, size and RDATA.
*/
typedef uint8_t knot_rr_t;
/* ------------------------- RR getters/setters ----------------------------- */
/*!
* \brief Returns RDATA size of single RR.
* \param rr RR whose size we want.
* \return RR size.
*/
uint16_t knot_rr_rdata_size(const knot_rr_t *rr);
/*!
* \brief Sets size for given RR.
* \param rr RR whose size we want to set.
* \param size Size to be set.
*/
void knot_rr_set_size(knot_rr_t *rr, uint16_t size);
/*!
* \brief Returns TTL of single RR.
* \param rr RR whose TTL we want.
* \return RR TTL.
*/
uint32_t knot_rr_ttl(const knot_rr_t *rr);
/*!
* \brief Sets TTL for given RR.
* \param rr RR whose TTL we want to set.
* \param ttl TTL to be set.
*/
void knot_rr_set_ttl(knot_rr_t *rr, uint32_t ttl);
/*!
* \brief Returns pointer to RR data.
* \param rr RR whose data we want.
* \return RR data pointer.
*/
uint8_t *knot_rr_rdata(const knot_rr_t *rr);
/* ----------------------------- RR misc ------------------------------------ */
/*!
* \brief Returns actual size of RR structure for given RDATA size.
* \param size RDATA size.
* \return Actual structure size.
*/
size_t knot_rr_array_size(uint16_t size);
/*!
* \brief Canonical comparison of two RRs. Both RRs *must* exist.
* \param rr1 First RR to compare.
* \param rr2 Second RR to compare.
* \retval 0 if rr1 == rr2.
* \retval < 0 if rr1 < rr2.
* \retval > 0 if rr1 > rr2.
*/
int knot_rr_cmp(const knot_rr_t *rr1, const knot_rr_t *rr2);
#include "libknot/rdata.h"
/* --------------------------- Multiple RRs ----------------------------------*/
......@@ -218,4 +156,4 @@ static inline uint8_t *data_offset(const knot_rrs_t *rrs, size_t pos,
size_t offset) {
knot_rr_t *rr = knot_rrs_rr(rrs, pos);
return knot_rr_rdata(rr) + offset;
}
}
\ No newline at end of file
......@@ -33,7 +33,7 @@
#include "common/mempattern.h"
#include "libknot/dname.h"
#include "libknot/rr.h"
#include "libknot/rdataset.h"
struct knot_compr;
struct knot_node;
......
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