Skip to content
Snippets Groups Projects
Commit 5fb42f84 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

catalog: move catalog_print() to kcatalogprint

parent 230326d8
No related branches found
No related tags found
1 merge request!1265Complete refactoring of catalog zones, little fixes/enh
......@@ -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);
}
......@@ -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);
/* 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[] = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment