From: Daniel Salzman Date: Mon, 1 Mar 2021 12:27:33 +0000 (+0100) Subject: catalog: move catalog_print() to kcatalogprint X-Git-Tag: v3.1.0~198^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fb42f84343e2d4fb84ba86fb0e2e262a0edf75a;p=thirdparty%2Fknot-dns.git catalog: move catalog_print() to kcatalogprint --- diff --git a/src/knot/catalog/catalog_db.c b/src/knot/catalog/catalog_db.c index 28628bb7a2..736c3e75db 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 . */ -#include #include #include @@ -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(";; \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 e0c2184d22..a9fcef8fc2 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 b46813c4a0..367157797c 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. +/* Copyright (C) 2021 CZ.NIC, z.s.p.o. 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(";; \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[] = {