Commit ab22677e authored by Lubos Slovak's avatar Lubos Slovak

Common library separated.

This includes:
- base32 encoding
- dynamic array
- skip-list
- latency profiling
- print routines
- Bird list
- Slab allocator
- AVL tree

refs #400
parent 9bac0d95
......@@ -2,11 +2,26 @@ Doxy.page.h
CodingStyle
Makefile.am
src/Makefile.am
src/alloc/malloc.c
src/alloc/malloc.h
src/alloc/slab.c
src/alloc/slab.h
src/alloc/alloc-common.h
src/common/slab/malloc.c
src/common/slab/malloc.h
src/common/slab/slab.c
src/common/slab/slab.h
src/common/slab/alloc-common.h
src/common/lists.h
src/common/lists.c
src/common/base32.h
src/common/base32.c
src/common/print.c
src/common/print.h
src/common/latency.c
src/common/latency.h
src/common/dynamic-array.c
src/common/dynamic-array.h
src/common/skip-list.c
src/common/skip-list.h
src/common/tree.h
src/common/base32hex.h
src/common/base32hex.c
src/dnslib/dnslib-common.h
src/dnslib/dname.h
src/dnslib/dname.c
......@@ -42,13 +57,6 @@ src/dnslib/zone-load.c
src/dnslib/zone-load.h
src/dnslib/zone-dump-text.h
src/dnslib/zone-dump-text.c
src/dnslib/ext/dynamic-array.c
src/dnslib/ext/dynamic-array.h
src/dnslib/ext/skip-list.c
src/dnslib/ext/skip-list.h
src/dnslib/ext/tree.h
src/dnslib/ext/base32hex.h
src/dnslib/ext/base32hex.c
src/dnslib/hash/cuckoo-hash-table.c
src/dnslib/hash/cuckoo-hash-table.h
src/dnslib/hash/hash-functions.c
......@@ -71,19 +79,9 @@ src/knot/main.c
src/knot/ctl/knotc_main.c
src/knot/ctl/process.c
src/knot/ctl/process.h
src/knot/lib/bitset.c
src/knot/lib/bitset.h
src/knot/lib/lists.h
src/knot/lib/lists.c
src/knot/lib/base32.h
src/knot/lib/base32.c
src/knot/other/debug.h
src/knot/other/log.c
src/knot/other/log.h
src/knot/other/print.c
src/knot/other/print.h
src/knot/other/latency.c
src/knot/other/latency.h
src/knot/stat/gatherer.c
src/knot/stat/gatherer.h
src/knot/stat/stat.h
......
......@@ -70,21 +70,27 @@ knotd_SOURCES = \
noinst_LTLIBRARIES = libknot.la
libknot_la_SOURCES = \
alloc/slab.c \
alloc/malloc.c \
alloc/slab.h \
alloc/malloc.h \
common/slab/slab.c \
common/slab/malloc.c \
common/slab/slab.h \
common/slab/malloc.h \
common/lists.c \
common/base32.c \
common/lists.h \
common/base32.h \
common/print.c \
common/print.h \
common/dynamic-array.c \
common/skip-list.c \
common/base32hex.c \
common/skip-list.h \
common/dynamic-array.h \
common/tree.h \
common/base32hex.h \
knot/stat/gatherer.c \
knot/stat/stat.c \
knot/stat/gatherer.h \
knot/stat/stat.h \
dnslib/ext/dynamic-array.c \
dnslib/ext/skip-list.c \
dnslib/ext/base32hex.c \
dnslib/ext/skip-list.h \
dnslib/ext/dynamic-array.h \
dnslib/ext/tree.h \
dnslib/ext/base32hex.h \
dnslib/edns.c \
dnslib/utils.c \
dnslib/rrset.c \
......@@ -124,15 +130,7 @@ libknot_la_SOURCES = \
dnslib/debug.h \
dnslib/nsec3.h \
knot/common.h \
knot/lib/lists.c \
knot/lib/bitset.c \
knot/lib/base32.c \
knot/lib/lists.h \
knot/lib/bitset.h \
knot/lib/base32.h \
knot/other/log.c \
knot/other/print.c \
knot/other/print.h \
knot/other/log.h \
knot/other/debug.h \
knot/conf/cf-parse.y \
......
......@@ -6,7 +6,7 @@
#include <urcu.h>
//#include "common.h"
#include "dnslib/ext/dynamic-array.h"
#include "common/dynamic-array.h"
#ifndef ERR_ALLOC_FAILED
#define ERR_ALLOC_FAILED fprintf(stderr, "Allocation failed at %s:%d\n", \
......
......@@ -12,8 +12,8 @@
* \addtogroup data_structures
* @{
*/
#ifndef _KNOT_DYNAMIC_ARRAY_H_
#define _KNOT_DYNAMIC_ARRAY_H_
#ifndef _KNOT_COMMON_DYNAMIC_ARRAY_H_
#define _KNOT_COMMON_DYNAMIC_ARRAY_H_
#include <string.h>
#include <pthread.h>
......@@ -135,6 +135,6 @@ uint da_get_count(const da_array_t *array);
/*----------------------------------------------------------------------------*/
#endif /* _KNOT_DYNAMIC_ARRAY_H_ */
#endif /* _KNOT_COMMON_DYNAMIC_ARRAY_H_ */
/*! @} */
#ifndef _LATENCYPROF_H_
#define _LATENCYPROF_H_
#ifndef _KNOT_COMMON_LATENCY_H_
#define _KNOT_COMMON_LATENCY_H_
/* Optional. */
#ifdef PROF_LATENCY
......@@ -40,4 +40,4 @@ int pf_pthread_mutex_unlock(pthread_mutex_t *mutex,
pf_pthread_mutex_unlock(m, __FUNCTION__, __FILE__, __LINE__)
#endif // PROF_LATENCY
#endif // _LATENCYPROF_H_
#endif // _KNOT_COMMON_LATENCY_H_
......@@ -27,7 +27,7 @@
#define _BIRD_LISTS_C_
#include <stdlib.h>
#include "knot/lib/lists.h"
#include "common/lists.h"
/**
* add_tail - append a node to a list
......
#include <config.h>
#include <stdio.h>
#include "knot/common.h"
#include "print.h"
#include "log.h"
void hex_printf(const char *data, int length, printf_t print_handler)
{
......@@ -19,16 +17,6 @@ void hex_print(const char *data, int length)
hex_printf(data, length, &printf);
}
void hex_log(int source, const char *data, int length)
{
int ptr = 0;
for (; ptr < length; ptr++) {
log_msg(source, LOG_DEBUG, "0x%02x ",
(unsigned char)*(data + ptr));
}
log_msg(source, LOG_DEBUG, "\n");
}
void bit_printf(const char *data, int length, printf_t print_handler)
{
unsigned char mask = 0x01;
......
......@@ -12,15 +12,14 @@
* @{
*/
#ifndef _KNOT_PRINT_H_
#define _KNOT_PRINT_H_
#ifndef _KNOT_COMMON_PRINT_H_
#define _KNOT_COMMON_PRINT_H_
typedef int (*printf_t)(const char *fmt, ...);
/* Hex-value printing.
*/
void hex_log(int source, const char *data, int length);
void hex_print(const char *data, int length);
void hex_printf(const char *data, int length, printf_t print_handler);
......@@ -30,6 +29,6 @@ void hex_printf(const char *data, int length, printf_t print_handler);
void bit_print(const char *data, int length);
void bit_printf(const char *data, int length, printf_t print_handler);
#endif /* _KNOT_PRINT_H_ */
#endif /* _KNOT_COMMON_PRINT_H_ */
/*! @} */
......@@ -36,7 +36,7 @@ Retrieved from: http://en.literateprograms.org/Skip_list_(C)?oldid=12811
#include <assert.h>
//#include "common.h"
#include "dnslib/ext/skip-list.h"
#include "common/skip-list.h"
#define ERR_ALLOC_FAILED fprintf(stderr, "Allocation failed at %s:%d\n", \
__FILE__, __LINE__)
......
......@@ -41,8 +41,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Retrieved from: http://en.literateprograms.org/Skip_list_(C)?oldid=12811
*/
#ifndef _KNOT_SKIP_LIST_H_
#define _KNOT_SKIP_LIST_H_
#ifndef _KNOT_COMMON_SKIP_LIST_H_
#define _KNOT_COMMON_SKIP_LIST_H_
/*----------------------------------------------------------------------------*/
/*!
......@@ -196,6 +196,6 @@ const skip_node_t *skip_next(const skip_node_t *node);
void skip_print_list(const skip_list_t *list,
void (*print_item)(void *, void *));
#endif /* _KNOT_SKIP_LIST_H_ */
#endif /* _KNOT_COMMON_SKIP_LIST_H_ */
/*! \} */
......@@ -8,8 +8,8 @@
* \addtogroup alloc
* @{
*/
#ifndef _KNOT_ALLOC_COMMON_H_
#define _KNOT_ALLOC_COMMON_H_
#ifndef _KNOT_COMMON_ALLOC_COMMON_H_
#define _KNOT_COMMON_ALLOC_COMMON_H_
#include <stdio.h>
......@@ -32,6 +32,6 @@
#endif
#endif /* _KNOT_ALLOC_COMMON_H_ */
#endif /* _KNOT_COMMON_ALLOC_COMMON_H_ */
/*! @} */
......@@ -7,7 +7,7 @@
#include <string.h>
#include <sys/resource.h>
#include "alloc/alloc-common.h"
#include "common/slab/alloc-common.h"
#ifdef MEM_DEBUG
/*
......
......@@ -9,8 +9,8 @@
* @{
*/
#ifndef __KNOT_MALLOC_H__
#define __KNOT_MALLOC_H__
#ifndef _KNOT_COMMON_MALLOC_H_
#define _KNOT_COMMON_MALLOC_H_
#include <stdlib.h>
......@@ -23,4 +23,4 @@
*/
void usage_dump();
#endif
#endif // _KNOT_COMMON_MALLOC_H_
......@@ -6,8 +6,8 @@
#include <stdlib.h>
#include <sys/mman.h>
#include "alloc/alloc-common.h"
#include "alloc/slab.h"
#include "common/slab/alloc-common.h"
#include "common/slab/slab.h"
/* Magic constants.
*/
......
......@@ -67,8 +67,8 @@
* @{
*/
#ifndef _KNOT_SLAB_H_
#define _KNOT_SLAB_H_
#ifndef _KNOT_COMMON_SLAB_H_
#define _KNOT_COMMON_SLAB_H_
#include <pthread.h>
#include <stdint.h>
......@@ -329,6 +329,6 @@ void *slab_alloc_realloc(slab_alloc_t* alloc, void *ptr, size_t size);
*/
void slab_alloc_stats(slab_alloc_t* alloc);
#endif /* _KNOT_SLAB_H_ */
#endif /* _KNOT_COMMON_SLAB_H_ */
/*! \} */
......@@ -14,7 +14,7 @@
/* Memory cache.
*/
#include "alloc/slab.h"
#include "common/slab/slab.h"
#include <stdio.h>
#include <pthread.h>
static pthread_key_t dname_ckey;
......
......@@ -11,7 +11,7 @@
#include "dnslib/debug.h"
#include "dnslib/hash/cuckoo-hash-table.h"
#include "dnslib/hash/hash-functions.h"
#include "dnslib/ext/dynamic-array.h"
#include "common/dynamic-array.h"
/*----------------------------------------------------------------------------*/
/* Macros and inline functions */
......
......@@ -26,7 +26,7 @@
#include <pthread.h>
#include "dnslib/hash/universal-system.h"
#include "dnslib/ext/dynamic-array.h"
#include "common/dynamic-array.h"
/*----------------------------------------------------------------------------*/
......
......@@ -5,8 +5,8 @@
#include "dnslib-common.h"
#include "dnslib/node.h"
#include "dnslib/rrset.h"
#include "dnslib/ext/skip-list.h"
#include "dnslib/ext/tree.h"
#include "common/skip-list.h"
#include "common/tree.h"
/*----------------------------------------------------------------------------*/
......
......@@ -14,9 +14,9 @@
#define _KNOT_DNSLIB_NODE_H_
#include "dnslib/dname.h"
#include "dnslib/ext/skip-list.h"
#include "common/skip-list.h"
#include "dnslib/rrset.h"
#include "dnslib/ext/tree.h"
#include "common/tree.h"
/*----------------------------------------------------------------------------*/
/*!
......
......@@ -10,7 +10,7 @@
#include <arpa/inet.h>
#include "dnslib.h"
#include "dnslib/ext/skip-list.h"
#include "common/skip-list.h"
/* TODO max length of alg */
......
......@@ -7,7 +7,7 @@
#include "dnslib/zone-dump.h"
#include "dnslib/dnslib.h"
#include "dnslib/debug.h"
#include "dnslib/ext/skip-list.h"
#include "common/skip-list.h"
/* \note For space and speed purposes, dname ID (to be later used in loading)
* is being stored in dname->node field. Not to be confused with dname's actual
......
......@@ -11,8 +11,8 @@
#include "dnslib/nsec3.h"
#include "dnslib/debug.h"
#include "dnslib/utils.h"
#include "dnslib/ext/tree.h"
#include "dnslib/ext/base32hex.h"
#include "common/tree.h"
#include "common/base32hex.h"
#include "dnslib/hash/cuckoo-hash-table.h"
/*----------------------------------------------------------------------------*/
......
......@@ -15,7 +15,7 @@
#include "dnslib/node.h"
#include "dnslib/dname.h"
#include "dnslib/nsec3.h"
#include "dnslib/ext/tree.h"
#include "common/tree.h"
#include "dnslib/hash/cuckoo-hash-table.h"
/*----------------------------------------------------------------------------*/
......
......@@ -10,7 +10,7 @@
#include "dnslib/dname.h"
#include "dnslib/node.h"
#include "dnslib/debug.h"
#include "dnslib/ext/skip-list.h"
#include "common/skip-list.h"
/*----------------------------------------------------------------------------*/
/* Non-API functions */
......
......@@ -15,7 +15,7 @@
#ifndef _KNOT_DNSLIB_ZONEDB_H_
#define _KNOT_DNSLIB_ZONEDB_H_
#include "dnslib/ext/skip-list.h"
#include "common/skip-list.h"
#include "dnslib/zone.h"
#include "dnslib/node.h"
#include "dnslib/dname.h"
......
......@@ -46,8 +46,8 @@ typedef unsigned int uint;
/* Common includes.
*/
#include "knot/other/latency.h"
#include "knot/other/print.h"
#include "common/latency.h"
#include "common/print.h"
#include "knot/other/log.h"
#include "knot/other/debug.h"
......
......@@ -16,7 +16,7 @@
#include <sys/socket.h>
#include "dnslib/descriptor.h"
#include "knot/lib/lists.h"
#include "common/lists.h"
#include "knot/other/log.h"
/* Constants. */
......
......@@ -7,7 +7,7 @@
#include "knot/conf/logconf.h"
#include "knot/conf/conf.h"
#include "knot/other/log.h"
#include "knot/lib/lists.h"
#include "common/lists.h"
int log_conf_hook(const struct conf_t *conf)
{
......
#include <config.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "knot/lib/bitset.h"
#define WORD_SIZE 32
#define WORD_CHECK 31
static unsigned int size = 0;
//static bitset_t clear = NULL;
void BITSET_CREATE( bitset_t *bitset, unsigned int n )
{
size = ((n >> WORD_EXP) + 1) * sizeof(uint32_t);
*bitset = (bitset_t)malloc(size);
//clear = (bitset_t)malloc(size);
//memset(clear, 0, size);
}
void BITSET_DESTROY( bitset_t *bitset )
{
assert(size > 0);
free(*bitset);
*bitset = NULL;
}
void BITSET_SET( bitset_t bitset, unsigned int i )
{
assert(size > 0);
bitset[((unsigned)i) >> WORD_EXP]
|= (1 << (((unsigned)i) & WORD_CHECK));
}
void BITSET_UNSET( bitset_t bitset, unsigned int i )
{
assert(size > 0);
bitset[((unsigned)i) >> WORD_EXP]
&= ~(1 << (((unsigned)i) & WORD_CHECK));
}
unsigned int BITSET_GET( bitset_t bitset, unsigned int i )
{
assert(size > 0);
return bitset[((unsigned)i) >> WORD_EXP]
& (1 << (((unsigned)i) & WORD_CHECK));
}
unsigned int BITSET_ISSET( bitset_t bitset, unsigned int i )
{
assert(size > 0);
return BITSET_GET(bitset, i) != 0;
//return 0;
}
void BITSET_CLEAR( bitset_t bitset, unsigned int n )
{
assert(size > 0);
memset(bitset, 0, size);
//memcpy(bitset, clear, size);
}
#ifndef BITSET
#define BITSET
#include <stdint.h> /* uint32_t */
#define WORD_EXP 5
typedef uint32_t* bitset_t;
void BITSET_CREATE( bitset_t *bitset, unsigned int n );
void BITSET_DESTROY( bitset_t *bitset );
void BITSET_SET( bitset_t bitset, unsigned int i );
void BITSET_UNSET( bitset_t bitset, unsigned int i );
unsigned int BITSET_GET( bitset_t bitset, unsigned int i );
unsigned int BITSET_ISSET( bitset_t bitset, unsigned int i );
void BITSET_CLEAR( bitset_t bitset, unsigned int n );
#endif /* BITSET */
......@@ -12,7 +12,7 @@
#define _KNOT_DEBUG_H_
#include "knot/other/log.h"
#include "knot/other/print.h"
#include "common/print.h"
//#define SM_DEBUG
//#define NS_DEBUG
......
......@@ -6,7 +6,7 @@
#include "knot/common.h"
#include "knot/other/log.h"
#include "knot/lib/lists.h"
#include "common/lists.h"
#include "knot/conf/conf.h"
/*! Log source table. */
......@@ -237,3 +237,13 @@ int log_vmsg(logsrc_t src, int level, const char *msg, va_list ap)
return ret;
}
void hex_log(int source, const char *data, int length)
{
int ptr = 0;
for (; ptr < length; ptr++) {
log_msg(source, LOG_DEBUG, "0x%02x ",
(unsigned char)*(data + ptr));
}
log_msg(source, LOG_DEBUG, "\n");
}
......@@ -164,6 +164,8 @@ int log_msg(logsrc_t src, int level, const char *msg, ...)
*/
int log_vmsg(logsrc_t src, int level, const char *msg, va_list ap);
void hex_log(int source, const char *data, int length);
/* Convenient logging. */
#define log_server_fatal(msg...) log_msg(LOG_SERVER, LOG_FATAL, msg)
#define log_server_error(msg...) log_msg(LOG_SERVER, LOG_ERR, msg)
......
......@@ -2,7 +2,7 @@
#include <pthread.h>
#include "knot/stat/stat-common.h"
#include "alloc/malloc.h"
#include "common/slab/malloc.h"
#include "knot/stat/gatherer.h"
gatherer_t *new_gatherer()
......
#include "tests/tap_unit.h"
#include "dnslib/ext/dynamic-array.h"
#include "common/dynamic-array.h"
#include <unistd.h>
#include <urcu.h>
......
#include <time.h>
#include "tests/tap_unit.h"
#include "dnslib/ext/skip-list.h"
#include "common/skip-list.h"
static int skiplist_tests_count(int argc, char *argv[]);
static int skiplist_tests_run(int argc, char *argv[]);
......
......@@ -4,7 +4,7 @@
#include <stdbool.h>
#include "tests/tap_unit.h"
#include "alloc/slab.h"
#include "common/slab/slab.h"
/* Explicitly ask for symbols,
* as the constructor and desctructor
......
......@@ -22,7 +22,7 @@
#include "dnslib/node.h"
#include "dnslib/rdata.h"
#include "dnslib/zone.h"
#include "alloc/slab.h"
#include "common/slab/slab.h"
#define MAXRDATALEN 64
#define MAXLABELLEN 63
......
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