Commit 4b7b72ca authored by Jan Včelák's avatar Jan Včelák 🚀

Merge branch 'libknot-cleanup' into 'master'

libknot dependencies cleanup

Divided files from `common` to `common` and `common-knot`, some moved to `libknot`.

Only those in `common` are used in `libknot` and only in .c files. `libknot` headers are no longer dependent on any headers outside `libknot`.

See issue #199

See merge request !245
parents 51fb5ee8 5b849029
......@@ -24,59 +24,51 @@ man/Makefile.am
patches/Makefile.am
samples/Makefile.am
src/Makefile.am
src/common/array-sort.h
src/common/base32hex.c
src/common/base32hex.h
src/common/base64.c
src/common/base64.h
src/common/binsearch.h
src/common/crc.h
src/common/debug.h
src/common/descriptor.c
src/common/descriptor.h
src/common/errcode.c
src/common/errcode.h
src/common/errors.c
src/common/errors.h
src/common/evsched.c
src/common/evsched.h
src/common/fdset.c
src/common/fdset.h
src/common/getline.c
src/common/getline.h
src/common/hattrie/hat-trie.c
src/common/hattrie/hat-trie.h
src/common/hattrie/murmurhash3.c
src/common/hattrie/murmurhash3.h
src/common/heap.c
src/common/heap.h
src/common/hex.c
src/common/hex.h
src/common/hhash.c
src/common/hhash.h
src/common/lists.c
src/common/lists.h
src/common/log.c
src/common/log.h
src/common/memdup.h
src/common/mempattern.c
src/common/mempattern.h
src/common/mempool.c
src/common/mempool.h
src/common/print.c
src/common/print.h
src/common/ref.c
src/common/ref.h
src/common/slab/alloc-common.h
src/common/slab/slab.c
src/common/slab/slab.h
src/common/sockaddr.c
src/common/sockaddr.h
src/common/strlcat.c
src/common/strlcat.h
src/common/strlcpy.c
src/common/strlcpy.h
src/common/strtonum.h
src/common-knot/array-sort.h
src/common-knot/binsearch.h
src/common-knot/crc.h
src/common-knot/evsched.c
src/common-knot/evsched.h
src/common-knot/fdset.c
src/common-knot/fdset.h
src/common-knot/hattrie/hat-trie.c
src/common-knot/hattrie/hat-trie.h
src/common-knot/hattrie/murmurhash3.c
src/common-knot/hattrie/murmurhash3.h
src/common-knot/heap.c
src/common-knot/heap.h
src/common-knot/hex.c
src/common-knot/hex.h
src/common-knot/hhash.c
src/common-knot/hhash.h
src/common-knot/lists.c
src/common-knot/lists.h
src/common-knot/print.c
src/common-knot/print.h
src/common-knot/ref.c
src/common-knot/ref.h
src/common-knot/slab/alloc-common.h
src/common-knot/slab/slab.c
src/common-knot/slab/slab.h
src/common-knot/sockaddr.c
src/common-knot/sockaddr.h
src/common-knot/strlcat.c
src/common-knot/strlcat.h
src/common-knot/strlcpy.c
src/common-knot/strlcpy.h
src/common-knot/strtonum.h
src/dnstap/Makefile.am
src/dnstap/convert.c
src/dnstap/convert.h
......@@ -203,6 +195,8 @@ src/libknot/binary.h
src/libknot/common.h
src/libknot/consts.c
src/libknot/consts.h
src/libknot/descriptor.c
src/libknot/descriptor.h
src/libknot/dname.c
src/libknot/dname.h
src/libknot/dnssec/bitmap.h
......@@ -220,7 +214,13 @@ src/libknot/dnssec/sig0.c
src/libknot/dnssec/sig0.h
src/libknot/dnssec/sign.c
src/libknot/dnssec/sign.h
src/libknot/errcode.c
src/libknot/errcode.h
src/libknot/errors.c
src/libknot/errors.h
src/libknot/libknot.h
src/libknot/mempattern.c
src/libknot/mempattern.h
src/libknot/packet/compr.c
src/libknot/packet/compr.h
src/libknot/packet/pkt.c
......
......@@ -4,7 +4,7 @@ SUBDIRS = zscanner dnstap .
sbin_PROGRAMS = knotc knotd
bin_PROGRAMS = kdig khost knsupdate knsec3hash
lib_LTLIBRARIES = libknot.la
noinst_LTLIBRARIES = libknotd.la libknots.la libknotus.la
noinst_LTLIBRARIES = libknotd.la libknots.la libknotus.la libknotcs.la
# $(YACC) will generate header file
AM_CPPFLAGS = \
......@@ -60,61 +60,61 @@ knsupdate_SOURCES = \
knsec3hash_SOURCES = \
utils/nsec3hash/nsec3hash_main.c
# static: shared
# static: shared (not in libknot)
libknots_la_SOURCES = \
common/array-sort.h \
common-knot/array-sort.h \
common-knot/binsearch.h \
common-knot/crc.h \
common-knot/evsched.c \
common-knot/evsched.h \
common-knot/fdset.c \
common-knot/fdset.h \
common-knot/hattrie/hat-trie.c \
common-knot/hattrie/hat-trie.h \
common-knot/hattrie/murmurhash3.c \
common-knot/hattrie/murmurhash3.h \
common-knot/heap.c \
common-knot/heap.h \
common-knot/hex.c \
common-knot/hex.h \
common-knot/hhash.c \
common-knot/hhash.h \
common-knot/lists.c \
common-knot/lists.h \
common-knot/print.c \
common-knot/print.h \
common-knot/ref.c \
common-knot/ref.h \
common-knot/slab/alloc-common.h \
common-knot/slab/slab.c \
common-knot/slab/slab.h \
common-knot/sockaddr.c \
common-knot/sockaddr.h \
common-knot/strlcat.c \
common-knot/strlcat.h \
common-knot/strlcpy.c \
common-knot/strlcpy.h \
common-knot/strtonum.h \
common-knot/trim.h
# static: common shared (also in libknot)
libknotcs_la_SOURCES = \
common/base32hex.c \
common/base32hex.h \
common/base64.c \
common/base64.h \
common/binsearch.h \
common/crc.h \
common/debug.h \
common/descriptor.c \
common/descriptor.h \
common/errcode.c \
common/errcode.h \
common/errors.c \
common/errors.h \
common/evsched.c \
common/evsched.h \
common/fdset.c \
common/fdset.h \
common/getline.c \
common/getline.h \
common/hattrie/hat-trie.c \
common/hattrie/hat-trie.h \
common/hattrie/murmurhash3.c \
common/hattrie/murmurhash3.h \
common/heap.c \
common/heap.h \
common/hex.c \
common/hex.h \
common/hhash.c \
common/hhash.h \
common/lists.c \
common/lists.h \
common/log.c \
common/log.h \
common/mem.c \
common/mem.h \
common/memdup.h \
common/mempattern.c \
common/mempattern.h \
common/mempool.c \
common/mempool.h \
common/print.c \
common/print.h \
common/ref.c \
common/ref.h \
common/slab/alloc-common.h \
common/slab/slab.c \
common/slab/slab.h \
common/sockaddr.c \
common/sockaddr.h \
common/strlcat.c \
common/strlcat.h \
common/strlcpy.c \
common/strlcpy.h \
common/strtonum.h
common/log.c \
common/log.h
# static: utilities shared
libknotus_la_SOURCES = \
......@@ -135,7 +135,7 @@ libknotus_la_SOURCES = \
libknot_la_LDFLAGS = \
$(AM_LDFLAGS) \
-version-info 0:1:0 \
-export-symbols-regex '^(knot|KNOT|rrset|tsig|zone)_'
-export-symbols-regex '^(knot|KNOT|rrset|tsig|zone|mm)_'
libknot_la_SOURCES = \
libknot/binary.c \
......@@ -144,6 +144,8 @@ libknot_la_SOURCES = \
libknot/consts.c \
libknot/consts.h \
libknot/consts.h \
libknot/descriptor.c \
libknot/descriptor.h \
libknot/dname.c \
libknot/dname.h \
libknot/dnssec/config.h \
......@@ -161,9 +163,11 @@ libknot_la_SOURCES = \
libknot/dnssec/sig0.h \
libknot/dnssec/sign.c \
libknot/dnssec/sign.h \
libknot/rrtype/opt.c \
libknot/rrtype/opt.h \
libknot/errcode.c \
libknot/errcode.h \
libknot/libknot.h \
libknot/mempattern.c \
libknot/mempattern.h \
libknot/packet/compr.c \
libknot/packet/compr.h \
libknot/packet/pkt.c \
......@@ -179,6 +183,8 @@ libknot_la_SOURCES = \
libknot/rrtype/nsec3param.h \
libknot/rrtype/nsec3param.c \
libknot/rrtype/nsec.h \
libknot/rrtype/opt.c \
libknot/rrtype/opt.h \
libknot/rrtype/rrsig.h \
libknot/rrtype/soa.h \
libknot/rrtype/tsig.c \
......@@ -311,23 +317,24 @@ libknotd_la_SOURCES = \
knot/zone/zonefile.h
# libraries
libknot_la_LIBADD = libknots.la zscanner/libzscanner.la
libknotd_la_LIBADD = libknots.la libknot.la
libknot_la_LIBADD = libknotcs.la zscanner/libzscanner.la
libknotd_la_LIBADD = libknots.la libknotcs.la libknot.la
libknotus_la_LDFLAGS = $(libidn_LIBS)
libknotus_la_CFLAGS = $(libidn_CFLAGS)
# sbin programs
knotd_LDADD = libknot.la libknotd.la
knotd_CPPFLAGS = $(AM_CPPFLAGS) ${systemd_daemon_CFLAGS}
knotd_LDFLAGS = $(AM_LDFLAGS) ${systemd_daemon_LIBS}
knotd_CPPFLAGS = $(AM_CPPFLAGS) $(systemd_daemon_CFLAGS)
knotd_LDFLAGS = $(AM_LDFLAGS) $(systemd_daemon_LIBS)
knotc_LDADD = libknot.la libknotd.la
# bin programs
kdig_LDADD = libknotus.la libknots.la libknot.la $(libidn_LIBS)
khost_LDADD = libknotus.la libknots.la libknot.la $(libidn_LIBS)
knsupdate_LDADD = libknotus.la libknots.la libknot.la zscanner/libzscanner.la
knsec3hash_LDADD = libknotus.la libknots.la libknot.la
BIN_LIBS = libknotus.la libknotcs.la libknots.la libknot.la
kdig_LDADD = $(BIN_LIBS) $(libidn_LIBS)
khost_LDADD = $(BIN_LIBS) $(libidn_LIBS)
knsupdate_LDADD = $(BIN_LIBS) zscanner/libzscanner.la
knsec3hash_LDADD = $(BIN_LIBS)
if HAVE_DNSTAP
libknotd_la_SOURCES += \
......
......@@ -20,8 +20,8 @@
#include <string.h>
#include <assert.h>
#include "common/errcode.h"
#include "common/evsched.h"
#include "libknot/errcode.h"
#include "common-knot/evsched.h"
/*! \brief Some implementations of timercmp >= are broken, this is for compat.*/
static inline int timercmp_ge(struct timeval *a, struct timeval *b) {
......
......@@ -30,7 +30,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <sys/time.h>
#include "common/heap.h"
#include "common-knot/heap.h"
/* Forward decls. */
struct evsched;
......
......@@ -18,7 +18,7 @@
#include <string.h>
#include <unistd.h>
#include <time.h>
#include "common/fdset.h"
#include "common-knot/fdset.h"
#include "libknot/common.h"
/* Workarounds for clock_gettime() not available on some platforms. */
......
......@@ -8,8 +8,8 @@
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include "common/hattrie/hat-trie.h"
#include "common/hhash.h"
#include "common-knot/hattrie/hat-trie.h"
#include "common-knot/hhash.h"
/* number of child nodes for used alphabet */
#define NODE_CHILDS (TRIE_MAXCHAR+1)
......
......@@ -24,8 +24,8 @@ extern "C" {
#include <stdlib.h>
#include <stdbool.h>
#include "libknot/common.h"
#include "common/mempattern.h"
#include "common/hhash.h"
#include "libknot/mempattern.h"
#include "common-knot/hhash.h"
/* Hat-trie defines. */
#define TRIE_ZEROBUCKETS 0 /* Do not use hash buckets (pure trie). */
......
/* This is MurmurHash3. The original C++ code was placed in the public domain
* by its author, Austin Appleby. */
#include "common/hattrie/murmurhash3.h"
#include "common-knot/hattrie/murmurhash3.h"
static inline uint32_t fmix(uint32_t h)
{
......
......@@ -37,7 +37,7 @@
* ------
***/
#include "common/heap.h"
#include "common-knot/heap.h"
#include <string.h>
#include <stdlib.h>
......
......@@ -19,7 +19,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "common/errcode.h"
#include "libknot/errcode.h"
/*!
* \brief Convert HEX char to byte.
......
......@@ -2,10 +2,10 @@
#include <assert.h>
#include <stdbool.h>
#include "common/hhash.h"
#include "common/binsearch.h"
#include "common/errcode.h"
#include "common/hattrie/murmurhash3.h"
#include "common-knot/hhash.h"
#include "common-knot/binsearch.h"
#include "libknot/errcode.h"
#include "common-knot/hattrie/murmurhash3.h"
#include "libknot/common.h"
/* UCW array sorting defines. */
......@@ -14,7 +14,7 @@ static int universal_cmp(uint32_t k1, uint32_t k2, hhash_t *tbl);
#define ASORT_KEY_TYPE uint32_t
#define ASORT_LT(x, y) (universal_cmp((x), (y), tbl) < 0)
#define ASORT_EXTRA_ARGS , hhash_t *tbl
#include "common/array-sort.h"
#include "common-knot/array-sort.h"
/* Hopscotch internal defines. */
#define HOP_NEXT(x) __builtin_ctz((x))
......
......@@ -29,7 +29,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include "common/mempattern.h"
#include "libknot/mempattern.h"
/*! \brief Bitvector type. */
typedef unsigned hhbitvec_t;
......
......@@ -28,7 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include "common/lists.h"
#include "common-knot/lists.h"
/**
* add_tail - append a node to a list
......
......@@ -83,7 +83,7 @@ void list_dup(list_t *dst, list_t *src, size_t itemsz);
size_t list_size(const list_t *);
#include <stdbool.h>
#include "common/mempattern.h"
#include "libknot/mempattern.h"
/*!
* \brief Generic pointer list implementation.
*/
......
......@@ -16,7 +16,7 @@
#include <stdio.h>
#include <ctype.h>
#include "common/print.h"
#include "common-knot/print.h"
void array_printf(const uint8_t *data, const unsigned length,
printf_t print_handler, const char type)
......
......@@ -16,7 +16,7 @@
#include <stdio.h>
#include "common/ref.h"
#include "common-knot/ref.h"
void ref_init(ref_t *p, ref_destructor_t dtor)
{
......
......@@ -21,8 +21,8 @@
#include <stdlib.h>
#include <sys/mman.h>
#include "common/slab/alloc-common.h"
#include "common/slab/slab.h"
#include "common-knot/slab/alloc-common.h"
#include "common-knot/slab/slab.h"
/*
* Magic constants.
......
......@@ -18,9 +18,9 @@
#include <string.h>
#include <netdb.h>
#include "common/sockaddr.h"
#include "common/strlcpy.h"
#include "common/errcode.h"
#include "common-knot/sockaddr.h"
#include "libknot/errcode.h"
#include "common-knot/strlcpy.h"
#include "libknot/consts.h"
int sockaddr_len(const struct sockaddr_storage *ss)
......
......@@ -17,7 +17,7 @@
#include <sys/types.h>
#include <string.h>
#include "common/strlcat.h"
#include "common-knot/strlcat.h"
size_t
knot_strlcat(char *dst, const char *src, size_t siz)
......
......@@ -17,7 +17,7 @@
#include <sys/types.h>
#include <string.h>
#include "common/strlcpy.h"
#include "common-knot/strlcpy.h"
size_t
knot_strlcpy(char *dst, const char *src, size_t siz)
......
......@@ -29,7 +29,7 @@
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include "common/errcode.h"
#include "libknot/errcode.h"
typedef long long int knot_strtoll_result_t;
typedef unsigned long long int knot_strtoull_result_t;
......
/* 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
#ifdef HAVE_MALLOC_TRIM
#include <malloc.h>
#endif
/*!
* \brief Trim excess heap memory.
*/
static inline void mem_trim(void)
{
#ifdef HAVE_MALLOC_TRIM
malloc_trim(0);
#endif
}
......@@ -15,7 +15,7 @@
*/
#include "common/base32hex.h"
#include "common/errcode.h"
#include "libknot/errcode.h"
#include <stdlib.h> // malloc
#include <stdint.h> // uint8_t
......
......@@ -15,7 +15,7 @@
*/
#include "common/base64.h"
#include "common/errcode.h"
#include "libknot/errcode.h"
#include <stdlib.h> // malloc
#include <stdint.h> // uint8_t
......
......@@ -32,7 +32,7 @@
#include <stdio.h>
#include "common/log.h"
#include "common/print.h"
#include "common-knot/print.h"
/*
* Debug macros
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* 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
......@@ -12,65 +12,31 @@
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 <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "common/errors.h"
#include "common/errcode.h"
/*!
* \brief Looks up the given id in the lookup table.
*
* \param table Lookup table.
* \param id ID to look up.
*
* \return Item in the lookup table with the given id or NULL if no such is
* present.
*/
static const error_table_t *error_lookup_by_id(const error_table_t *table,
int id)
static const error_table_t *lookup_error(const error_table_t *table, int id)
{
while (table->name != 0) {
while (table->name != NULL) {
if (table->id == id) {
return table;
}
table++;
}
return 0;
return NULL;
}
const char *error_to_str(const error_table_t *table, int code)
const char *error_to_str(const error_table_t *table, int id)
{
const error_table_t *msg = error_lookup_by_id(table, code);
if (msg != 0) {
const error_table_t *msg = lookup_error(table, id);
if (msg != NULL) {
return msg->name;
} else {
return "Unknown error.";
}
}
int _map_errno(int fallback_value, int arg0, ...)
{
/* Iterate all variable-length arguments. */
va_list ap;
va_start(ap, arg0);
/* KNOT_ERROR serves as a sentinel. */
for (int c = arg0; c != 0; c = va_arg(ap, int)) {
/* Error code matches with mapped. */
if (c == errno) {
/* Return negative value of the code. */
va_end(ap);
return err2code(abs(c));
}
}
va_end(ap);
/* Fallback error code. */
return fallback_value;
}
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* 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
......@@ -12,66 +12,24 @@
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 errors.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>