]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
catalog: move catalog_print() to kcatalogprint
authorDaniel Salzman <daniel.salzman@nic.cz>
Mon, 1 Mar 2021 12:27:33 +0000 (13:27 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Thu, 18 Mar 2021 15:47:27 +0000 (16:47 +0100)
src/knot/catalog/catalog_db.c
src/knot/catalog/catalog_db.h
src/utils/kcatalogprint/main.c

index 28628bb7a2f11742922d45c5cf3d342ddb1c3f57..736c3e75db21be0884655420378e800153b39afa 100644 (file)
@@ -14,7 +14,6 @@
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include <stdio.h>
 #include <string.h>
 #include <urcu.h>
 
@@ -327,48 +326,3 @@ int catalog_copy(knot_lmdb_db_t *from, knot_lmdb_db_t *to,
        knot_lmdb_commit(&txn_w);
        return txn_w.ret;
 }
-
-static void print_dname(const knot_dname_t *d)
-{
-       knot_dname_txt_storage_t tmp;
-       knot_dname_to_str(tmp, d, sizeof(tmp));
-       printf("%s  ", tmp);
-}
-
-static void print_dname3(const char *prefix, const knot_dname_t *a,
-                         const knot_dname_t *b,const knot_dname_t *c)
-{
-       printf("%s", prefix);
-       print_dname(a);
-       print_dname(b);
-       print_dname(c);
-       printf("\n");
-}
-
-static int catalog_print_cb(const knot_dname_t *mem, const knot_dname_t *ow,
-                            const knot_dname_t *cz, void *ctx)
-{
-       print_dname3("", mem, ow, cz);
-       (*(ssize_t *)ctx)++;
-       return KNOT_EOK;
-}
-
-void catalog_print(catalog_t *cat)
-{
-       ssize_t total = 0;
-
-       printf(";; <catalog zone> <record owner> <record zone>\n");
-
-       if (cat != NULL) {
-               int ret = catalog_open(cat);
-               if (ret == KNOT_EOK) {
-                       ret = catalog_apply(cat, NULL, catalog_print_cb, &total, false);
-               }
-               if (ret != KNOT_EOK) {
-                       printf("Catalog print failed (%s)\n", knot_strerror(ret));
-                       return;
-               }
-       }
-
-       printf("Total records: %zd\n", total);
-}
index e0c2184d227c1b681692048bf89c1ebb6c41b6ce..a9fcef8fc2cc90fa0c9692c2ca5215a456b4c151 100644 (file)
@@ -181,11 +181,4 @@ int catalog_apply(catalog_t *cat, const knot_dname_t *for_member,
  * \return KNOT_E*
  */
 int catalog_copy(knot_lmdb_db_t *from, knot_lmdb_db_t *to,
-                 const knot_dname_t *zone_only, bool read_rw_txn);
-
-/*!
- * \brief Print to stdout whole contents of catalog database (for human).
- *
- * \param cat   Catalog database to be printed.
- */
-void catalog_print(catalog_t *cat);
+                 const knot_dname_t *cat_only, bool read_rw_txn);
index b46813c4a00ffe27ccec8f2db8eb83fde4ff9eeb..367157797c5afdbf07657fdda57c9fcf48ce907f 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2020 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2021 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
@@ -33,6 +33,44 @@ static void print_help(void)
               PROGRAM_NAME);
 }
 
+static void print_dname(const knot_dname_t *d)
+{
+       knot_dname_txt_storage_t tmp;
+       knot_dname_to_str(tmp, d, sizeof(tmp));
+       printf("%s  ", tmp);
+}
+
+static int catalog_print_cb(const knot_dname_t *mem, const knot_dname_t *ow,
+                            const knot_dname_t *cz, void *ctx)
+{
+       print_dname(mem);
+       print_dname(ow);
+       print_dname(cz);
+       printf("\n");
+       (*(ssize_t *)ctx)++;
+       return KNOT_EOK;
+}
+
+static void catalog_print(catalog_t *cat)
+{
+       ssize_t total = 0;
+
+       printf(";; <catalog zone> <record owner> <record zone>\n");
+
+       if (cat != NULL) {
+               int ret = catalog_open(cat);
+               if (ret == KNOT_EOK) {
+                       ret = catalog_apply(cat, NULL, catalog_print_cb, &total, false);
+               }
+               if (ret != KNOT_EOK) {
+                       printf("Catalog print failed (%s)\n", knot_strerror(ret));
+                       return;
+               }
+       }
+
+       printf("Total records: %zd\n", total);
+}
+
 int main(int argc, char *argv[])
 {
        struct option options[] = {