/usr/include/libknot/rdataset.h is in libknot-dev 2.4.0-3+deb9u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | /* 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/>.
*/
/*!
* \file
*
* \brief API for manipulating RR arrays.
*
* \addtogroup libknot
* @{
*/
#pragma once
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "libknot/mm_ctx.h"
#include "libknot/rdata.h"
/*!< \brief Set of RRs. */
typedef struct knot_rdataset {
uint16_t rr_count; /*!< \brief Count of RRs stored in the structure. */
knot_rdata_t *data; /*!< \brief Actual data, canonically sorted. */
} knot_rdataset_t;
/* -------------------------- RRs init/clear ---------------------------------*/
/*!
* \brief Initializes RRS structure.
* \param rrs Structure to be initialized.
*/
void knot_rdataset_init(knot_rdataset_t *rrs);
/*!
* \brief Frees data initialized by RRS structure, but not the structure itself.
* \param rrs Structure to be cleared.
* \param mm Memory context used to create allocations.
*/
void knot_rdataset_clear(knot_rdataset_t *rrs, knot_mm_t *mm);
/*!
* \brief Deep copies RRS structure. All data are duplicated.
* \param dst Copy destination.
* \param src Copy source.
* \param mm Memory context.
* \return KNOT_E*
*/
int knot_rdataset_copy(knot_rdataset_t *dst, const knot_rdataset_t *src, knot_mm_t *mm);
/* ----------------------- RRs getters/setters ------------------------------ */
/*!
* \brief Gets RR from RRS structure, using given position.
* \param rrs RRS structure to get RR from.
* \param pos Position to use.
* \return Pointer to RR at \a pos position.
*/
knot_rdata_t *knot_rdataset_at(const knot_rdataset_t *rrs, size_t pos);
/*!
* \brief Makes RRS structure from a list of resource records (in the given order).
* \param dst RRS structure to write into.
* \param src Array of records to copy from.
* \param count The number of records to copy.
* \param mm Memory context.
*/
int knot_rdataset_gather(knot_rdataset_t *dst, knot_rdata_t **src, uint16_t count,
knot_mm_t *mm);
/*!
* \brief Returns size of the structures holding the RR set.
* \param rrs RR array.
* \return Array size.
*/
size_t knot_rdataset_size(const knot_rdataset_t *rrs);
/*!
* \brief Returns the common TTL of the RR set.
* \note Actually returns the TTL of the first RR.
* \param rrs RR array.
* \return TTL.
*/
uint32_t knot_rdataset_ttl(const knot_rdataset_t *rrs);
/*!
* \brief Sets TTL of all the RRs in the RR set.
* \param rrs RR array.
* \param ttl TTL to set.
*/
void knot_rdataset_set_ttl(knot_rdataset_t *rrs, uint32_t ttl);
/* ----------------------- RRs RR manipulation ------------------------------ */
/*!
* \brief Adds single RR into RRS structure. All data are copied.
* \param rrs RRS structure to add RR into.
* \param rr RR to add.
* \param mm Memory context.
* \return KNOT_E*
*/
int knot_rdataset_add(knot_rdataset_t *rrs, const knot_rdata_t *rr, knot_mm_t *mm);
/*!
* \brief Reserves space at the end of the RRS structure.
* \param rrs RRS structure to reserve space at.
* \param size How much space to reserve.
* \param mm Memory context.
* \return KNOT_E*
*/
int knot_rdataset_reserve(knot_rdataset_t *rrs, size_t size, knot_mm_t *mm);
/*!
* \brief Removes the last RR from RRS structure, i.e. does the opposite of _reserve.
* \param rrs RRS structure to remove RR from.
* \param mm Memory context.
* \return KNOT_E*
*/
int knot_rdataset_unreserve(knot_rdataset_t *rrs, knot_mm_t *mm);
/* ---------------------- RRs set-like operations --------------------------- */
/*!
* \brief RRS equality check.
* \param rrs1 First RRS to be compared.
* \param rrs2 Second RRS to be compared.
* \retval true if rrs1 == rrs2.
* \retval false if rrs1 != rrs2.
*/
bool knot_rdataset_eq(const knot_rdataset_t *rrs1, const knot_rdataset_t *rrs2);
/*!
* \brief Returns true if \a rr is present in \a rrs, false otherwise.
* \param rrs RRS to search in.
* \param rr RR to compare with.
* \param cmp_ttl If set to true, TTLs will be compared as well.
* \retval true if \a rr is present in \a rrs.
* \retval false if \a rr is not present in \a rrs.
*/
bool knot_rdataset_member(const knot_rdataset_t *rrs, const knot_rdata_t *rr,
bool cmp_ttl);
/*!
* \brief Merges two RRS into the first one. Second RRS is left intact.
* Canonical order is preserved.
* \param rrs1 Destination RRS (merge here).
* \param rrs2 RRS to be merged (merge from).
* \param mm Memory context.
* \return KNOT_E*
*/
int knot_rdataset_merge(knot_rdataset_t *rrs1, const knot_rdataset_t *rrs2,
knot_mm_t *mm);
/*!
* \brief RRS set-like intersection. Full compare is done.
* \param a First RRS to intersect.
* \param b Second RRS to intersect.
* \param out Output RRS with intersection, RDATA are created anew.
* \param mm Memory context. Will be used to create new RDATA.
* \return KNOT_E*
*/
int knot_rdataset_intersect(const knot_rdataset_t *a, const knot_rdataset_t *b,
knot_rdataset_t *out, knot_mm_t *mm);
/*!
* \brief Does set-like RRS subtraction. \a from RRS is changed.
* \param from RRS to subtract from.
* \param what RRS to subtract.
* \param mm Memory context use to reallocated \a from data.
* \return KNOT_E*
*/
int knot_rdataset_subtract(knot_rdataset_t *from, const knot_rdataset_t *what,
knot_mm_t *mm);
/*!
* \brief Sorts the dataset. Removes the element if found to be duplicate.
* \param rss RRS to sort.
* \param pos Position of the element to sort.
* \param mm Memory context used to remove the element if duplicate.
* \return KNOT_E*
*/
int knot_rdataset_sort_at(knot_rdataset_t *rrs, size_t pos, knot_mm_t *mm);
/*! \brief Accession helpers. */
#define KNOT_RDATASET_CHECK(rrs, pos, code) \
if (rrs == NULL || rrs->data == NULL || rrs->rr_count == 0 || \
pos >= rrs->rr_count) { \
code; \
}
/*! \todo Documentation. */
static inline
uint8_t *knot_rdata_offset(const knot_rdataset_t *rrs, size_t pos, size_t offset) {
knot_rdata_t *rr = knot_rdataset_at(rrs, pos);
return knot_rdata_data(rr) + offset;
}
/*! @} */
|