From bcd2b1996d8632a2e1e7ca288f189d603da11b5d Mon Sep 17 00:00:00 2001
From: Daniel Salzman <daniel.salzman@nic.cz>
Date: Thu, 10 Dec 2015 16:53:14 +0100
Subject: [PATCH] contrib: move lists from internal

---
 Knot.files                                    |  4 +--
 src/Makefile.am                               |  4 +--
 src/{libknot/internal => contrib/ucw}/lists.c | 16 +++++-----
 src/{libknot/internal => contrib/ucw}/lists.h | 30 ++-----------------
 src/knot/common/log.c                         |  2 +-
 src/knot/conf/base.h                          |  2 +-
 src/knot/ctl/estimator.c                      |  2 +-
 src/knot/nameserver/axfr.c                    |  2 +-
 src/knot/nameserver/query_module.h            |  2 +-
 src/knot/server/server.h                      |  2 +-
 src/knot/updates/acl.h                        |  2 +-
 src/knot/updates/apply.c                      |  2 +-
 src/knot/updates/changesets.h                 |  2 +-
 src/knot/updates/ddns.c                       |  2 +-
 src/knot/updates/zone-update.c                |  3 +-
 src/knot/worker/queue.h                       |  2 +-
 src/knot/zone/zone.c                          |  7 ++---
 src/libknot/processing/overlay.c              |  2 +-
 src/libknot/processing/requestor.c            |  2 +-
 src/utils/common/exec.c                       |  2 +-
 src/utils/common/netio.h                      |  1 -
 src/utils/common/params.h                     |  2 +-
 src/utils/common/resolv.c                     |  2 +-
 src/utils/common/resolv.h                     |  2 +-
 src/utils/kdig/kdig_exec.c                    |  2 +-
 src/utils/kdig/kdig_params.c                  |  2 +-
 src/utils/khost/khost_params.c                |  2 +-
 src/utils/knsupdate/knsupdate_params.h        |  2 +-
 28 files changed, 37 insertions(+), 70 deletions(-)
 rename src/{libknot/internal => contrib/ucw}/lists.c (96%)
 rename src/{libknot/internal => contrib/ucw}/lists.h (71%)

diff --git a/Knot.files b/Knot.files
index 55671009c..38763eee6 100644
--- a/Knot.files
+++ b/Knot.files
@@ -80,6 +80,8 @@ src/contrib/ucw/array-sort.h
 src/contrib/ucw/binsearch.h
 src/contrib/ucw/heap.c
 src/contrib/ucw/heap.h
+src/contrib/ucw/lists.c
+src/contrib/ucw/lists.h
 src/contrib/ucw/mempool.c
 src/contrib/ucw/mempool.h
 src/contrib/wire.h
@@ -380,8 +382,6 @@ src/libknot/dnssec/rrset-sign.h
 src/libknot/errcode.h
 src/libknot/error.c
 src/libknot/error.h
-src/libknot/internal/lists.c
-src/libknot/internal/lists.h
 src/libknot/internal/namedb/namedb.h
 src/libknot/internal/namedb/namedb_lmdb.c
 src/libknot/internal/namedb/namedb_lmdb.h
diff --git a/src/Makefile.am b/src/Makefile.am
index a74228b63..42c1cdb03 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,6 +46,7 @@ nobase_libcontrib_la_HEADERS =			\
 	contrib/ucw/array-sort.h		\
 	contrib/ucw/binsearch.h			\
 	contrib/ucw/heap.h			\
+	contrib/ucw/lists.h			\
 	contrib/ucw/mempool.h
 
 # dynamic: libknot headers
@@ -90,7 +91,6 @@ nobase_libknot_la_HEADERS =			\
 
 libknot_internal_ladir = $(includedir)
 nobase_libknot_internal_la_HEADERS = 		\
-	libknot/internal/lists.h		\
 	libknot/internal/namedb/namedb.h	\
 	libknot/internal/namedb/namedb_lmdb.h	\
 	libknot/internal/namedb/namedb_trie.h
@@ -118,6 +118,7 @@ libcontrib_la_SOURCES = 			\
 	contrib/openbsd/strlcat.c		\
 	contrib/openbsd/strlcpy.c		\
 	contrib/ucw/heap.c			\
+	contrib/ucw/lists.c			\
 	contrib/ucw/mempool.c			\
 	$(nobase_libcontrib_la_HEADERS)
 
@@ -160,7 +161,6 @@ libknot_yparser_la_SOURCES = 			\
 	$(nobase_libknot_yparser_la_HEADERS)
 
 libknot_internal_la_SOURCES = 			\
-	libknot/internal/lists.c		\
 	libknot/internal/namedb/namedb_lmdb.c	\
 	libknot/internal/namedb/namedb_trie.c	\
 	$(nobase_libknot_internal_la_HEADERS)
diff --git a/src/libknot/internal/lists.c b/src/contrib/ucw/lists.c
similarity index 96%
rename from src/libknot/internal/lists.c
rename to src/contrib/ucw/lists.c
index 1b25cb85b..1b5e2d366 100644
--- a/src/libknot/internal/lists.c
+++ b/src/contrib/ucw/lists.c
@@ -24,11 +24,9 @@
  * similar to that used in the &fib structure.
  */
 
-#define _BIRD_LISTS_C_
-
 #include <stdlib.h>
 #include <string.h>
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 #include "contrib/mempattern.h"
 
 /**
@@ -38,7 +36,7 @@
  *
  * add_tail() takes a node @n and appends it at the end of the list @l.
  */
-LIST_INLINE void
+void
 add_tail(list_t *l, node_t *n)
 {
   node_t *z = l->tail;
@@ -56,7 +54,7 @@ add_tail(list_t *l, node_t *n)
  *
  * add_head() takes a node @n and prepends it at the start of the list @l.
  */
-LIST_INLINE void
+void
 add_head(list_t *l, node_t *n)
 {
   node_t *z = l->head;
@@ -75,7 +73,7 @@ add_head(list_t *l, node_t *n)
  * Inserts a node @n to a linked list after an already inserted
  * node @after.
  */
-LIST_INLINE void
+void
 insert_node(node_t *n, node_t *after)
 {
   node_t *z = after->next;
@@ -92,7 +90,7 @@ insert_node(node_t *n, node_t *after)
  *
  * Removes a node @n from the list it's linked in.
  */
-LIST_INLINE void
+void
 rem_node(node_t *n)
 {
   node_t *z = n->prev;
@@ -111,7 +109,7 @@ rem_node(node_t *n)
  * init_list() takes a &list structure and initializes its
  * fields, so that it represents an empty list.
  */
-LIST_INLINE void
+void
 init_list(list_t *l)
 {
   l->head = (node_t *) &l->null;
@@ -127,7 +125,7 @@ init_list(list_t *l)
  * This function appends all elements of the list @l to
  * the list @to in constant time.
  */
-LIST_INLINE void
+void
 add_tail_list(list_t *to, list_t *l)
 {
   node_t *p = to->tail;
diff --git a/src/libknot/internal/lists.h b/src/contrib/ucw/lists.h
similarity index 71%
rename from src/libknot/internal/lists.h
rename to src/contrib/ucw/lists.h
index b0a726a55..3713a5ea2 100644
--- a/src/libknot/internal/lists.h
+++ b/src/contrib/ucw/lists.h
@@ -1,18 +1,3 @@
-/*  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
-    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/>.
- */
 /*
  *	BIRD Library -- Linked Lists
  *
@@ -36,7 +21,8 @@
  *     tail                    tail_node.prev
  */
 
-#include <string.h>  // size_t
+#include <string.h>
+#include "libknot/mm_ctx.h"
 
 typedef struct node {
   struct node *next, *prev;
@@ -82,8 +68,6 @@ void insert_node(node_t *, node_t *);
 void list_dup(list_t *dst, list_t *src, size_t itemsz);
 size_t list_size(const list_t *);
 
-#include <stdbool.h>
-#include "libknot/mm_ctx.h"
 /*!
  * \brief Generic pointer list implementation.
  */
@@ -96,13 +80,3 @@ ptrnode_t *ptrlist_add(list_t *, void *, knot_mm_t *);
 void ptrlist_free(list_t *, knot_mm_t *);
 void ptrlist_rem(ptrnode_t *node, knot_mm_t *mm);
 
-/*! \todo This is broken atm.
-#ifndef _BIRD_LISTS_C_
-#define LIST_INLINE extern inline
-#include "knot/lib/lists.c"
-#undef LIST_INLINE
-#else
-#define LIST_INLINE
-#endif
-*/
-#define LIST_INLINE
diff --git a/src/knot/common/log.c b/src/knot/common/log.c
index fdf436b69..eb40e72de 100644
--- a/src/knot/common/log.c
+++ b/src/knot/common/log.c
@@ -31,9 +31,9 @@
 
 #include "knot/common/log.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
 #include "contrib/macros.h"
 #include "contrib/openbsd/strlcpy.h"
+#include "contrib/ucw/lists.h"
 
 /* Single log message buffer length (one line). */
 #define LOG_BUFLEN 512
diff --git a/src/knot/conf/base.h b/src/knot/conf/base.h
index 174926426..6ab15a63a 100644
--- a/src/knot/conf/base.h
+++ b/src/knot/conf/base.h
@@ -26,9 +26,9 @@
 #pragma once
 
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
 #include "libknot/internal/namedb/namedb_lmdb.h"
 #include "libknot/yparser/ypscheme.h"
+#include "contrib/ucw/lists.h"
 
 /*! Default template identifier. */
 #define CONF_DEFAULT_ID		((uint8_t *)"\x08""default\0")
diff --git a/src/knot/ctl/estimator.c b/src/knot/ctl/estimator.c
index 1e92e5032..20569777e 100644
--- a/src/knot/ctl/estimator.c
+++ b/src/knot/ctl/estimator.c
@@ -20,10 +20,10 @@
 #include "knot/zone/node.h"
 #include "libknot/errcode.h"
 #include "libknot/dname.h"
-#include "libknot/internal/lists.h"
 #include "libknot/descriptor.h"
 #include "contrib/macros.h"
 #include "contrib/string.h"
+#include "contrib/ucw/lists.h"
 
 // Addition constants used for tweaking, mostly malloc overhead
 enum estim_consts {
diff --git a/src/knot/nameserver/axfr.c b/src/knot/nameserver/axfr.c
index d56f19d52..7ecfecc40 100644
--- a/src/knot/nameserver/axfr.c
+++ b/src/knot/nameserver/axfr.c
@@ -25,9 +25,9 @@
 #include "knot/common/log.h"
 #include "libknot/libknot.h"
 #include "libknot/descriptor.h"
-#include "libknot/internal/lists.h"
 #include "contrib/print.h"
 #include "contrib/sockaddr.h"
+#include "contrib/ucw/lists.h"
 
 /* AXFR context. @note aliasing the generic xfr_proc */
 struct axfr_proc {
diff --git a/src/knot/nameserver/query_module.h b/src/knot/nameserver/query_module.h
index 52ebe7633..702b0c89f 100644
--- a/src/knot/nameserver/query_module.h
+++ b/src/knot/nameserver/query_module.h
@@ -41,10 +41,10 @@
 #pragma once
 
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
 #include "libknot/mm_ctx.h"
 #include "knot/conf/conf.h"
 #include "knot/conf/tools.h"
+#include "contrib/ucw/lists.h"
 
 #define MODULE_ERR(mod, msg, ...) \
 	log_error("module '%.*s', " msg, mod[0], mod + 1, ##__VA_ARGS__)
diff --git a/src/knot/server/server.h b/src/knot/server/server.h
index 0599bfbf0..73c2cd803 100644
--- a/src/knot/server/server.h
+++ b/src/knot/server/server.h
@@ -32,13 +32,13 @@
 #include "sys/socket.h"
 
 #include "knot/common/evsched.h"
-#include "libknot/internal/lists.h"
 #include "knot/common/fdset.h"
 #include "libknot/internal/namedb/namedb.h"
 #include "knot/server/dthreads.h"
 #include "knot/server/rrl.h"
 #include "knot/worker/pool.h"
 #include "knot/zone/zonedb.h"
+#include "contrib/ucw/lists.h"
 
 /* Forwad declarations. */
 struct iface;
diff --git a/src/knot/updates/acl.h b/src/knot/updates/acl.h
index 4dd8aec65..6d3cb2323 100644
--- a/src/knot/updates/acl.h
+++ b/src/knot/updates/acl.h
@@ -26,8 +26,8 @@
 
 #include <sys/socket.h>
 
-#include "libknot/internal/lists.h"
 #include "contrib/mempattern.h"
+#include "contrib/ucw/lists.h"
 #include "libknot/rrtype/tsig.h"
 #include "knot/conf/conf.h"
 
diff --git a/src/knot/updates/apply.c b/src/knot/updates/apply.c
index a7fc95655..4a83a343a 100644
--- a/src/knot/updates/apply.c
+++ b/src/knot/updates/apply.c
@@ -22,8 +22,8 @@
 #include "knot/zone/zonefile.h"
 #include "knot/common/log.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
 #include "contrib/macros.h"
+#include "contrib/ucw/lists.h"
 
 /* --------------------------- Update cleanup ------------------------------- */
 
diff --git a/src/knot/updates/changesets.h b/src/knot/updates/changesets.h
index d6ea0ce23..d76389014 100644
--- a/src/knot/updates/changesets.h
+++ b/src/knot/updates/changesets.h
@@ -28,7 +28,7 @@
 
 #include "libknot/rrset.h"
 #include "knot/zone/contents.h"
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 
 /*! \brief One zone change, from 'soa_from' to 'soa_to'. */
 typedef struct {
diff --git a/src/knot/updates/ddns.c b/src/knot/updates/ddns.c
index df6d8651d..c0d7195b0 100644
--- a/src/knot/updates/ddns.c
+++ b/src/knot/updates/ddns.c
@@ -28,7 +28,7 @@
 #include "libknot/consts.h"
 #include "libknot/rrtype/soa.h"
 #include "libknot/descriptor.h"
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 
 /* ----------------------------- prereq check ------------------------------- */
 
diff --git a/src/knot/updates/zone-update.c b/src/knot/updates/zone-update.c
index ed2de4f41..64b2f400c 100644
--- a/src/knot/updates/zone-update.c
+++ b/src/knot/updates/zone-update.c
@@ -20,8 +20,7 @@
 #include "knot/dnssec/zone-events.h"
 #include "knot/updates/apply.h"
 #include "knot/zone/serial.h"
-
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 #include "contrib/ucw/mempool.h"
 
 static int add_to_node(zone_node_t *node, const zone_node_t *add_node,
diff --git a/src/knot/worker/queue.h b/src/knot/worker/queue.h
index 3f0899830..d60d9d662 100644
--- a/src/knot/worker/queue.h
+++ b/src/knot/worker/queue.h
@@ -16,7 +16,7 @@
 
 #pragma once
 
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 
 struct task;
 typedef void (*task_cb)(struct task *);
diff --git a/src/knot/zone/zone.c b/src/knot/zone/zone.c
index 8e64721c1..a8b18f82e 100644
--- a/src/knot/zone/zone.c
+++ b/src/knot/zone/zone.c
@@ -21,9 +21,7 @@
 #include <urcu.h>
 
 #include "dnssec/random.h"
-#include "libknot/descriptor.h"
 #include "knot/common/evsched.h"
-#include "libknot/internal/lists.h"
 #include "knot/common/log.h"
 #include "knot/common/trim.h"
 #include "knot/zone/node.h"
@@ -33,12 +31,11 @@
 #include "knot/zone/contents.h"
 #include "knot/updates/acl.h"
 #include "knot/updates/apply.h"
-#include "libknot/processing/requestor.h"
 #include "knot/nameserver/process_query.h"
 #include "libknot/libknot.h"
-#include "libknot/dname.h"
+#include "libknot/processing/requestor.h"
 #include "contrib/string.h"
-#include "libknot/rrtype/soa.h"
+#include "contrib/ucw/lists.h"
 
 #define JOURNAL_SUFFIX	".diff.db"
 
diff --git a/src/libknot/processing/overlay.c b/src/libknot/processing/overlay.c
index 18dc4c73e..b050648f7 100644
--- a/src/libknot/processing/overlay.c
+++ b/src/libknot/processing/overlay.c
@@ -17,8 +17,8 @@
 #include "libknot/attribute.h"
 #include "libknot/processing/overlay.h"
 #include "libknot/errcode.h"
-#include "libknot/internal/lists.h"
 #include "contrib/mempattern.h"
+#include "contrib/ucw/lists.h"
 
 #define LAYERS	((list_t *)overlay->layers)
 
diff --git a/src/libknot/processing/requestor.c b/src/libknot/processing/requestor.c
index d34a07c42..866e8019f 100644
--- a/src/libknot/processing/requestor.c
+++ b/src/libknot/processing/requestor.c
@@ -19,10 +19,10 @@
 #include "libknot/attribute.h"
 #include "libknot/processing/requestor.h"
 #include "libknot/errcode.h"
-#include "libknot/internal/lists.h"
 #include "contrib/mempattern.h"
 #include "contrib/net.h"
 #include "contrib/sockaddr.h"
+#include "contrib/ucw/lists.h"
 
 #define PENDING	((list_t *)requestor->pending)
 
diff --git a/src/utils/common/exec.c b/src/utils/common/exec.c
index 74e710a8a..0448c38e9 100644
--- a/src/utils/common/exec.c
+++ b/src/utils/common/exec.c
@@ -24,11 +24,11 @@
 #include "utils/common/netio.h"
 #include "utils/common/params.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.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[] = {
diff --git a/src/utils/common/netio.h b/src/utils/common/netio.h
index e8bed18f0..bbf00c533 100644
--- a/src/utils/common/netio.h
+++ b/src/utils/common/netio.h
@@ -31,7 +31,6 @@
 #include <sys/socket.h>
 
 #include "utils/common/params.h"
-#include "libknot/internal/lists.h"
 
 /*! \brief Structure containing server information. */
 typedef struct {
diff --git a/src/utils/common/params.h b/src/utils/common/params.h
index a83822ede..1e8aadd27 100644
--- a/src/utils/common/params.h
+++ b/src/utils/common/params.h
@@ -31,7 +31,7 @@
 #include <stdbool.h>
 
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 
 #define DEFAULT_IPV4_NAME	"127.0.0.1"
 #define DEFAULT_IPV6_NAME	"::1"
diff --git a/src/utils/common/resolv.c b/src/utils/common/resolv.c
index 7313555bd..f70df6102 100644
--- a/src/utils/common/resolv.c
+++ b/src/utils/common/resolv.c
@@ -21,7 +21,7 @@
 #include "utils/common/msg.h"
 #include "utils/common/params.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 
 #define RESOLV_FILE	"/etc/resolv.conf"
 
diff --git a/src/utils/common/resolv.h b/src/utils/common/resolv.h
index 1c8e1df9d..f0d871703 100644
--- a/src/utils/common/resolv.h
+++ b/src/utils/common/resolv.h
@@ -27,7 +27,7 @@
 #pragma once
 
 #include "utils/common/netio.h"
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 
 srv_info_t* parse_nameserver(const char *str, const char *def_port);
 
diff --git a/src/utils/kdig/kdig_exec.c b/src/utils/kdig/kdig_exec.c
index f10336fc7..1983cbc3a 100644
--- a/src/utils/kdig/kdig_exec.c
+++ b/src/utils/kdig/kdig_exec.c
@@ -25,9 +25,9 @@
 #include "utils/common/netio.h"
 #include "utils/common/sign.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
 #include "contrib/sockaddr.h"
 #include "contrib/print.h"
+#include "contrib/ucw/lists.h"
 
 #if USE_DNSTAP
 # include "contrib/dnstap/convert.h"
diff --git a/src/utils/kdig/kdig_params.c b/src/utils/kdig/kdig_params.c
index fc8b9f595..c871153cc 100644
--- a/src/utils/kdig/kdig_params.c
+++ b/src/utils/kdig/kdig_params.c
@@ -27,8 +27,8 @@
 #include "utils/common/resolv.h"
 #include "libknot/descriptor.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
 #include "contrib/sockaddr.h"
+#include "contrib/ucw/lists.h"
 
 #define DEFAULT_RETRIES_DIG	2
 #define DEFAULT_TIMEOUT_DIG	5
diff --git a/src/utils/khost/khost_params.c b/src/utils/khost/khost_params.c
index dce0485e4..46b57cc73 100644
--- a/src/utils/khost/khost_params.c
+++ b/src/utils/khost/khost_params.c
@@ -26,7 +26,7 @@
 #include "utils/common/params.h"
 #include "utils/common/resolv.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
+#include "contrib/ucw/lists.h"
 
 #define DEFAULT_RETRIES_HOST	1
 #define DEFAULT_TIMEOUT_HOST	2
diff --git a/src/utils/knsupdate/knsupdate_params.h b/src/utils/knsupdate/knsupdate_params.h
index 494de3491..66d43c59d 100644
--- a/src/utils/knsupdate/knsupdate_params.h
+++ b/src/utils/knsupdate/knsupdate_params.h
@@ -32,8 +32,8 @@
 #include "utils/common/params.h"
 #include "utils/common/sign.h"
 #include "libknot/libknot.h"
-#include "libknot/internal/lists.h"
 #include "zscanner/scanner.h"
+#include "contrib/ucw/lists.h"
 
 #define KNSUPDATE_VERSION "knsupdate, version " PACKAGE_VERSION "\n"
 
-- 
GitLab