diff options
author | Daniel Salzman <daniel.salzman@nic.cz> | 2021-03-01 13:27:33 +0100 |
---|---|---|
committer | Daniel Salzman <daniel.salzman@nic.cz> | 2021-03-18 16:47:27 +0100 |
commit | 5fb42f84343e2d4fb84ba86fb0e2e262a0edf75a (patch) | |
tree | 9ca8a7443e2472a8339e9e3ce839c2e27c9a5d3e /src | |
parent | catalog: complete refactoring with little fixes/enh (diff) | |
download | knot-5fb42f84343e2d4fb84ba86fb0e2e262a0edf75a.tar.xz knot-5fb42f84343e2d4fb84ba86fb0e2e262a0edf75a.zip |
catalog: move catalog_print() to kcatalogprint
Diffstat (limited to 'src')
-rw-r--r-- | src/knot/catalog/catalog_db.c | 46 | ||||
-rw-r--r-- | src/knot/catalog/catalog_db.h | 9 | ||||
-rw-r--r-- | src/utils/kcatalogprint/main.c | 40 |
3 files changed, 40 insertions, 55 deletions
diff --git a/src/knot/catalog/catalog_db.c b/src/knot/catalog/catalog_db.c index 28628bb7a..736c3e75d 100644 --- a/src/knot/catalog/catalog_db.c +++ b/src/knot/catalog/catalog_db.c @@ -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); -} diff --git a/src/knot/catalog/catalog_db.h b/src/knot/catalog/catalog_db.h index e0c2184d2..a9fcef8fc 100644 --- a/src/knot/catalog/catalog_db.h +++ b/src/knot/catalog/catalog_db.h @@ -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); diff --git a/src/utils/kcatalogprint/main.c b/src/utils/kcatalogprint/main.c index b46813c4a..367157797 100644 --- a/src/utils/kcatalogprint/main.c +++ b/src/utils/kcatalogprint/main.c @@ -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[] = { |