Commit ee6c4de1 authored by Daniel Salzman's avatar Daniel Salzman

libknot: move lookup_table as knot_lookup from contrib

parent 3d31a919
......@@ -31,6 +31,7 @@ libtap/tap/float.h
libtap/tap/macros.h
samples/Makefile.am
src/Makefile.am
src/contrib/asan.h
src/contrib/base32hex.c
src/contrib/base32hex.h
src/contrib/base64.c
......@@ -57,7 +58,6 @@ src/contrib/lmdb/lmdb.h
src/contrib/lmdb/mdb.c
src/contrib/lmdb/midl.c
src/contrib/lmdb/midl.h
src/contrib/lookup.h
src/contrib/macros.h
src/contrib/mempattern.c
src/contrib/mempattern.h
......@@ -388,6 +388,7 @@ src/libknot/errcode.h
src/libknot/error.c
src/libknot/error.h
src/libknot/libknot.h
src/libknot/lookup.h
src/libknot/mm_ctx.h
src/libknot/packet/compr.c
src/libknot/packet/compr.h
......@@ -411,6 +412,7 @@ src/libknot/rrset-dump.c
src/libknot/rrset-dump.h
src/libknot/rrset.c
src/libknot/rrset.h
src/libknot/rrtype/aaaa.c
src/libknot/rrtype/aaaa.h
src/libknot/rrtype/dnskey.c
src/libknot/rrtype/dnskey.h
......
......@@ -33,7 +33,6 @@ libcontrib_la_SOURCES = \
contrib/getline.h \
contrib/hhash.c \
contrib/hhash.h \
contrib/lookup.h \
contrib/macros.h \
contrib/mempattern.c \
contrib/mempattern.h \
......@@ -90,6 +89,7 @@ nobase_libknot_la_HEADERS = \
libknot/errcode.h \
libknot/error.h \
libknot/libknot.h \
libknot/lookup.h \
libknot/mm_ctx.h \
libknot/db/db.h \
libknot/db/db_lmdb.h \
......
......@@ -38,7 +38,7 @@
#include "knot/modules/dnstap.h"
#endif
static const lookup_table_t key_algs[] = {
static const knot_lookup_t key_algs[] = {
{ DNSSEC_TSIG_HMAC_MD5, "hmac-md5" },
{ DNSSEC_TSIG_HMAC_SHA1, "hmac-sha1" },
{ DNSSEC_TSIG_HMAC_SHA224, "hmac-sha224" },
......@@ -48,7 +48,7 @@ static const lookup_table_t key_algs[] = {
{ 0, NULL }
};
const lookup_table_t acl_actions[] = {
const knot_lookup_t acl_actions[] = {
{ ACL_ACTION_NOTIFY, "notify" },
{ ACL_ACTION_TRANSFER, "transfer" },
{ ACL_ACTION_UPDATE, "update" },
......@@ -56,13 +56,13 @@ const lookup_table_t acl_actions[] = {
{ 0, NULL }
};
static const lookup_table_t serial_policies[] = {
static const knot_lookup_t serial_policies[] = {
{ SERIAL_POLICY_INCREMENT, "increment" },
{ SERIAL_POLICY_UNIXTIME, "unixtime" },
{ 0, NULL }
};
static const lookup_table_t log_severities[] = {
static const knot_lookup_t log_severities[] = {
{ LOG_UPTO(LOG_CRIT), "critical" },
{ LOG_UPTO(LOG_ERR), "error" },
{ LOG_UPTO(LOG_WARNING), "warning" },
......
......@@ -25,8 +25,8 @@
#pragma once
#include "libknot/lookup.h"
#include "libknot/yparser/ypscheme.h"
#include "contrib/lookup.h"
#define C_ACL "\x03""acl"
#define C_ACTION "\x06""action"
......@@ -91,7 +91,7 @@ enum {
SERIAL_POLICY_UNIXTIME = 2
};
extern const lookup_table_t acl_actions[];
extern const knot_lookup_t acl_actions[];
extern const yp_item_t conf_scheme[];
......
......@@ -36,7 +36,7 @@ enum synth_template_type {
SYNTH_REVERSE = 2
};
static const lookup_table_t synthetic_types[] = {
static const knot_lookup_t synthetic_types[] = {
{ SYNTH_FORWARD, "forward" },
{ SYNTH_REVERSE, "reverse" },
{ 0, NULL }
......
......@@ -386,7 +386,7 @@ int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata)
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
const lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
const knot_lookup_t *lut = knot_lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
AXFRIN_LOG(LOG_WARNING, "server responded with %s", lut->name);
}
......
......@@ -695,7 +695,7 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
const lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
const knot_lookup_t *lut = knot_lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
IXFRIN_LOG(LOG_WARNING, "server responded with %s", lut->name);
}
......
......@@ -119,7 +119,7 @@ int notify_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
/* Check RCODE. */
uint8_t rcode = knot_wire_get_rcode(pkt->wire);
if (rcode != KNOT_RCODE_NOERROR) {
const lookup_table_t *lut = lookup_by_id(knot_rcode_names, rcode);
const knot_lookup_t *lut = knot_lookup_by_id(knot_rcode_names, rcode);
if (lut != NULL) {
NOTIFY_RLOG(LOG_WARNING, "server responded with %s", lut->name);
}
......
......@@ -568,8 +568,8 @@ bool process_query_acl_check(const knot_dname_t *zone_name, acl_action_t action,
if (!acl_allowed(&acl, action, query_source, &tsig)) {
char addr_str[SOCKADDR_STRLEN] = { 0 };
sockaddr_tostr(addr_str, sizeof(addr_str), query_source);
const lookup_table_t *act = lookup_by_id((lookup_table_t *)acl_actions,
action);
const knot_lookup_t *act = knot_lookup_by_id((knot_lookup_t *)acl_actions,
action);
char *key_name = knot_dname_to_str_alloc(tsig.name);
log_zone_debug(zone_name,
......
......@@ -17,9 +17,9 @@
#include "libknot/attribute.h"
#include "libknot/codes.h"
#include "libknot/consts.h"
#include "contrib/lookup.h"
const lookup_table_t opcode_names[] = {
_public_
const knot_lookup_t knot_opcode_names[] = {
{ KNOT_OPCODE_QUERY, "QUERY" },
{ KNOT_OPCODE_IQUERY, "IQUERY" },
{ KNOT_OPCODE_STATUS, "STATUS" },
......@@ -27,10 +27,9 @@ const lookup_table_t opcode_names[] = {
{ KNOT_OPCODE_UPDATE, "UPDATE" },
{ 0, NULL }
};
_public_
const void *knot_opcode_names = opcode_names;
const lookup_table_t rcode_names[] = {
_public_
const knot_lookup_t knot_rcode_names[] = {
{ KNOT_RCODE_NOERROR, "NOERROR" },
{ KNOT_RCODE_FORMERR, "FORMERR" },
{ KNOT_RCODE_SERVFAIL, "SERVFAIL" },
......@@ -45,29 +44,26 @@ const lookup_table_t rcode_names[] = {
{ KNOT_RCODE_BADVERS, "BADVERS" },
{ 0, NULL }
};
_public_
const void *knot_rcode_names = rcode_names;
const lookup_table_t tsig_err_names[] = {
_public_
const knot_lookup_t knot_tsig_err_names[] = {
{ KNOT_TSIG_ERR_BADSIG, "BADSIG" },
{ KNOT_TSIG_ERR_BADKEY, "BADKEY" },
{ KNOT_TSIG_ERR_BADTIME, "BADTIME" },
{ KNOT_TSIG_ERR_BADTRUNC, "BADTRUNC" },
{ 0, NULL }
};
_public_
const void *knot_tsig_err_names = tsig_err_names;
const lookup_table_t tkey_err_names[] = {
_public_
const knot_lookup_t knot_tkey_err_names[] = {
{ KNOT_TKEY_ERR_BADMODE, "BADMODE" },
{ KNOT_TKEY_ERR_BADNAME, "BADNAME" },
{ KNOT_TKEY_ERR_BADALG, "BADALG" },
{ 0, NULL }
};
_public_
const void *knot_tkey_err_names = tkey_err_names;
const lookup_table_t dnssec_alg_names[] = {
_public_
const knot_lookup_t knot_dnssec_alg_names[] = {
{ KNOT_DNSSEC_ALG_RSAMD5, "RSAMD5" },
{ KNOT_DNSSEC_ALG_DH, "DH" },
{ KNOT_DNSSEC_ALG_DSA, "DSA" },
......@@ -81,5 +77,3 @@ const lookup_table_t dnssec_alg_names[] = {
{ KNOT_DNSSEC_ALG_ECDSAP384SHA384, "ECDSAP384SHA384" },
{ 0, NULL }
};
_public_
const void *knot_dnssec_alg_names = dnssec_alg_names;
......@@ -24,29 +24,31 @@
#pragma once
#include "libknot/lookup.h"
/*!
* \brief DNS operation code names.
*/
extern const void *knot_opcode_names;
extern const knot_lookup_t knot_opcode_names[];
/*!
* \brief DNS reply code names.
*/
extern const void *knot_rcode_names;
extern const knot_lookup_t knot_rcode_names[];
/*!
* \brief TSIG error names.
*/
extern const void *knot_tsig_err_names;
extern const knot_lookup_t knot_tsig_err_names[];
/*!
* \brief TKEY error names.
*/
extern const void *knot_tkey_err_names;
extern const knot_lookup_t knot_tkey_err_names[];
/*!
* \brief DNSSEC algorithm names.
*/
extern const void *knot_dnssec_alg_names;
extern const knot_lookup_t knot_dnssec_alg_names[];
/*! @} */
/*!
* \file libknot.h
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* \brief Convenience header for including whole library.
*
* \addtogroup libknot
* @{
*/
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
......@@ -23,6 +13,14 @@
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 Convenience header for including whole library.
*
* \addtogroup libknot
* @{
*/
#pragma once
......@@ -33,6 +31,7 @@
#include "libknot/dname.h"
#include "libknot/errcode.h"
#include "libknot/error.h"
#include "libknot/lookup.h"
#include "libknot/mm_ctx.h"
#include "libknot/rdata.h"
#include "libknot/rdataset.h"
......
......@@ -18,7 +18,7 @@
*
* \brief A general purpose lookup table.
*
* \addtogroup contrib
* \addtogroup libknot
* @{
*/
......@@ -29,10 +29,10 @@
/*!
* \brief A general purpose lookup table.
*/
typedef struct lookup_table {
typedef struct knot_lookup {
int id;
const char *name;
} lookup_table_t;
} knot_lookup_t;
/*!
* \brief Looks up the given name in the lookup table.
......@@ -43,7 +43,7 @@ typedef struct lookup_table {
* \return Item in the lookup table with the given name or NULL if no such is
* present.
*/
inline static const lookup_table_t *lookup_by_name(const lookup_table_t *table, const char *name)
inline static const knot_lookup_t *knot_lookup_by_name(const knot_lookup_t *table, const char *name)
{
if (table == NULL || name == NULL) {
return NULL;
......@@ -68,7 +68,7 @@ inline static const lookup_table_t *lookup_by_name(const lookup_table_t *table,
* \return Item in the lookup table with the given id or NULL if no such is
* present.
*/
inline static const lookup_table_t *lookup_by_id(const lookup_table_t *table, int id)
inline static const knot_lookup_t *knot_lookup_by_id(const knot_lookup_t *table, int id)
{
if (table == NULL) {
return NULL;
......
......@@ -33,9 +33,9 @@
#include "libknot/consts.h"
#include "libknot/descriptor.h"
#include "libknot/errcode.h"
#include "libknot/lookup.h"
#include "contrib/base32hex.h"
#include "contrib/base64.h"
#include "contrib/lookup.h"
#include "contrib/wire.h"
#include "contrib/wire_ctx.h"
......@@ -1190,10 +1190,10 @@ static void wire_tsig_rcode_to_str(rrset_dump_params_t *p)
data = wire_read_u16(p->in);
// Find RCODE name.
const lookup_table_t *rcode = NULL;
rcode = lookup_by_id((data >= ((lookup_table_t *)knot_tsig_err_names)->id) ?
knot_tsig_err_names : knot_rcode_names,
data);
const knot_lookup_t *rcode = NULL;
rcode = knot_lookup_by_id((data >= ((knot_lookup_t *)knot_tsig_err_names)->id) ?
knot_tsig_err_names : knot_rcode_names,
data);
if (rcode != NULL) {
rcode_str = rcode->name;
}
......@@ -1313,8 +1313,8 @@ static void dnskey_info(const uint8_t *rdata,
.size = rdata_len };
dnssec_keytag(&rdata_bin, &key_tag);
const lookup_table_t *alg = NULL;
alg = lookup_by_id(knot_dnssec_alg_names, alg_id);
const knot_lookup_t *alg = NULL;
alg = knot_lookup_by_id(knot_dnssec_alg_names, alg_id);
int ret = snprintf(out, out_len, "%s, %s (%zub), id = %u",
sep ? "KSK" : "ZSK",
......
......@@ -16,11 +16,11 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "libknot/yparser/ypscheme.h"
#include "libknot/yparser/yptrafo.h"
#include "libknot/errcode.h"
#include "contrib/lookup.h"
/*! Initializes the referenced item. */
static int set_ref_item(
......
......@@ -30,7 +30,7 @@
#include "libknot/yparser/yparser.h"
struct wire_ctx;
struct lookup_table;
struct knot_lookup;
/*! Maximal length of item name. */
#define YP_MAX_ITEM_NAME_LEN 64
......@@ -119,7 +119,7 @@ typedef union {
/*! Option variables. */
struct {
/*! List of options (maximal value is 255). */
struct lookup_table const *opts;
struct knot_lookup const *opts;
/*! Default value. */
unsigned dflt;
} o;
......
......@@ -23,8 +23,8 @@
#include "libknot/yparser/yptrafo.h"
#include "libknot/consts.h"
#include "libknot/dname.h"
#include "libknot/lookup.h"
#include "contrib/base64.h"
#include "contrib/lookup.h"
#include "contrib/sockaddr.h"
#include "contrib/wire.h"
#include "contrib/wire_ctx.h"
......@@ -504,7 +504,7 @@ int yp_addr_to_txt(
int yp_option_to_bin(
YP_TXT_BIN_PARAMS,
const lookup_table_t *opts)
const knot_lookup_t *opts)
{
YP_CHECK_PARAMS_BIN;
......@@ -522,7 +522,7 @@ int yp_option_to_bin(
int yp_option_to_txt(
YP_BIN_TXT_PARAMS,
const lookup_table_t *opts)
const knot_lookup_t *opts)
{
uint8_t id = wire_ctx_read_u8(in);
......
......@@ -26,7 +26,7 @@
#include "libknot/yparser/ypscheme.h"
struct lookup_table;
struct knot_lookup;
/*!
* Transforms textual item value to binary form.
......@@ -263,12 +263,12 @@ int yp_addr_to_txt(
int yp_option_to_bin(
YP_TXT_BIN_PARAMS,
const struct lookup_table *opts
const struct knot_lookup *opts
);
int yp_option_to_txt(
YP_BIN_TXT_PARAMS,
const struct lookup_table *opts
const struct knot_lookup *opts
);
int yp_dname_to_bin(
......
......@@ -24,14 +24,13 @@
#include "utils/common/netio.h"
#include "utils/common/params.h"
#include "libknot/libknot.h"
#include "contrib/lookup.h"
#include "contrib/print.h"
#include "contrib/sockaddr.h"
#include "contrib/openbsd/strlcat.h"
#include "contrib/ucw/lists.h"
#include "contrib/wire_ctx.h"
static lookup_table_t rtypes[] = {
static knot_lookup_t rtypes[] = {
{ KNOT_RRTYPE_A, "has IPv4 address" },
{ KNOT_RRTYPE_NS, "nameserver is" },
{ KNOT_RRTYPE_CNAME, "is an alias for" },
......@@ -56,17 +55,17 @@ static void print_header(const knot_pkt_t *packet, const style_t *style,
uint8_t opcode_id;
const char *rcode_str = "Unknown";
const char *opcode_str = "Unknown";
const lookup_table_t *rcode, *opcode;
const knot_lookup_t *rcode, *opcode;
// Get RCODE from Header and check for Extended RCODE from OPT RR.
rcode = lookup_by_id(knot_rcode_names, ext_rcode);
rcode = knot_lookup_by_id(knot_rcode_names, ext_rcode);
if (rcode != NULL) {
rcode_str = rcode->name;
}
// Get OPCODE.
opcode_id = knot_wire_get_opcode(packet->wire);
opcode = lookup_by_id(knot_opcode_names, opcode_id);
opcode = knot_lookup_by_id(knot_opcode_names, opcode_id);
if (opcode != NULL) {
opcode_str = opcode->name;
}
......@@ -219,10 +218,10 @@ static void print_section_opt(const knot_rrset_t *rr, const uint8_t rcode)
uint8_t ercode = knot_edns_get_ext_rcode(rr);
uint16_t ext_rcode_id = knot_edns_whole_rcode(ercode, rcode);
const char *ext_rcode_str = "Unused";
const lookup_table_t *ext_rcode;
const knot_lookup_t *ext_rcode;
if (ercode > 0) {
ext_rcode = lookup_by_id(knot_rcode_names, ext_rcode_id);
ext_rcode = knot_lookup_by_id(knot_rcode_names, ext_rcode_id);
if (ext_rcode != NULL) {
ext_rcode_str = ext_rcode->name;
} else {
......@@ -384,7 +383,7 @@ static void print_section_host(const knot_rrset_t *rrsets,
for (size_t i = 0; i < count; i++) {
const knot_rrset_t *rrset = &rrsets[i];
const lookup_table_t *descr;
const knot_lookup_t *descr;
char type[32] = "NULL";
char *owner;
......@@ -392,7 +391,7 @@ static void print_section_host(const knot_rrset_t *rrsets,
if (style->style.ascii_to_idn != NULL) {
style->style.ascii_to_idn(&owner);
}
descr = lookup_by_id(rtypes, rrset->type);
descr = knot_lookup_by_id(rtypes, rrset->type);
uint16_t rrset_rdata_count = rrset->rrs.rr_count;
for (uint16_t j = 0; j < rrset_rdata_count; j++) {
......@@ -441,14 +440,14 @@ static void print_error_host(const uint16_t code,
const char *rcode_str = "Unknown";
char type[32] = "Unknown";
char *owner;
const lookup_table_t *rcode;
const knot_lookup_t *rcode;
owner = knot_dname_to_str_alloc(knot_pkt_qname(packet));
if (style->style.ascii_to_idn != NULL) {
style->style.ascii_to_idn(&owner);
}
rcode = lookup_by_id(knot_rcode_names, code);
rcode = knot_lookup_by_id(knot_rcode_names, code);
if (rcode != NULL) {
rcode_str = rcode->name;
}
......
......@@ -33,7 +33,6 @@
#include "utils/common/token.h"
#include "libknot/libknot.h"
#include "contrib/macros.h"
#include "contrib/lookup.h"
#include "contrib/string.h"
#include "contrib/openbsd/strlcpy.h"
......@@ -882,7 +881,7 @@ int cmd_send(const char* lp, knsupdate_params_t *params)
uint8_t rc = knot_wire_get_rcode(params->answer->wire);
if (rc != KNOT_RCODE_NOERROR) {
const char *rcode_str = "Unknown";
const lookup_table_t *rcode = lookup_by_id(knot_rcode_names, rc);
const knot_lookup_t *rcode = knot_lookup_by_id(knot_rcode_names, rc);
if (rcode != NULL) {
rcode_str = rcode->name;
}
......
......@@ -16,9 +16,9 @@
#include <tap/basic.h>
#include "contrib/lookup.h"
#include "libknot/lookup.h"
const lookup_table_t test_table[] = {
const knot_lookup_t test_table[] = {
{ 0, "test item 0" },
{ 10, "" },
{ 2, "test item 2" },
......@@ -31,35 +31,35 @@ int main(int argc, char *argv[])
plan(9);
/* Lookup by ID. */
const lookup_table_t *found = lookup_by_id(test_table, 3);
const knot_lookup_t *found = knot_lookup_by_id(test_table, 3);
ok(found == NULL, "lookup table: find by id - non-existent ID");
found = lookup_by_id(test_table, 2);
found = knot_lookup_by_id(test_table, 2);
ok(found && found->id == 2 && strcmp(found->name, "test item 2") == 0,
"lookup table: find by id - ID 2 (unordered IDs)");
found = lookup_by_id(NULL, 2);
found = knot_lookup_by_id(NULL, 2);
ok(found == NULL, "lookup table: find by id - table == NULL");
/* Lookup by name. */
found = lookup_by_name(test_table, "test item 2");
found = knot_lookup_by_name(test_table, "test item 2");
ok(found && found->id == 2 && strcmp(found->name, "test item 2") == 0,
"lookup table: find by name - existent");
found = lookup_by_name(test_table, "");
found = knot_lookup_by_name(test_table, "");
ok(found && found->id == 10 && strcmp(found->name, "") == 0,
"lookup table: find by name - empty string");
found = lookup_by_name(test_table, NULL);
found = knot_lookup_by_name(test_table, NULL);
ok(found == NULL, "lookup table: find by name - NULL name");
found = lookup_by_name(NULL, "test item 2");
found = knot_lookup_by_name(NULL, "test item 2");
ok(found == NULL, "lookup table: find by name - NULL table");
found = lookup_by_name(NULL, NULL);
found = knot_lookup_by_name(NULL, NULL);
ok(found == NULL, "lookup table: find by name - NULL table & NULL name");
found = lookup_by_name(test_table, "non existent name");
found = knot_lookup_by_name(test_table, "non existent name");
ok(found == NULL, "lookup table: find by name - non-existent name");
return 0;
......
......@@ -22,7 +22,6 @@
#include "libknot/yparser/ypscheme.h"
#include "libknot/yparser/yptrafo.h"
#include "libknot/libknot.h"
#include "contrib/lookup.h"
#define C_ID "\x02""id"
#define C_INT "\x07""integer"
......@@ -51,7 +50,7 @@ static const yp_item_t multi_group[] = {
{ NULL }
};
static const lookup_table_t opts[] = {
static const knot_lookup_t opts[] = {
{ 1, "one" },
{ 10, "ten" },
{ 0, NULL }
......
......@@ -22,7 +22,6 @@
#include "libknot/yparser/yptrafo.h"
#include "libknot/libknot.h"
#include "contrib/lookup.h"
static void int_test(const char *txt, int64_t num, yp_style_t s,
int64_t min, int64_t max)
......@@ -90,7 +89,7 @@ static void bool_bad_test(const char *txt, int code)
ok(ret == code, "invalid txt to bin");
}
static void opt_test(const char *txt, unsigned val, const lookup_table_t *opts)
static void opt_test(const char *txt, unsigned val, const knot_lookup_t *opts)
{
int ret;
uint8_t b[64];
......@@ -111,7 +110,7 @@ static void opt_test(const char *txt, unsigned val, const lookup_table_t *opts)
ok(memcmp(txt, t, t_len) == 0, "compare");
}
static void opt_bad_test(const char *txt, int code, const lookup_table_t *opts)
static void opt_bad_test(const char *txt, int code, const knot_lookup_t *opts)
{
int ret;
uint8_t b[64];
......@@ -311,7 +310,7 @@ int main(int argc, char *argv[])
bool_bad_test("enable", KNOT_EINVAL);
/* Option tests. */
static const lookup_table_t opts[] = {
static const knot_lookup_t opts[] = {
{ 1, "one" },
{ 10, "ten" },
{ 255, "max" },
......
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