Skip to content
Snippets Groups Projects
Commit 4fd0e18d authored by Jan Hák's avatar Jan Hák Committed by Daniel Salzman
Browse files

kcatalogprint: add parameters for filtering catalog or member zone

parent 57580f4a
No related branches found
No related tags found
No related merge requests found
Pipeline #101182 passed
...@@ -53,6 +53,12 @@ Use specified catalog database path and default configuration. ...@@ -53,6 +53,12 @@ Use specified catalog database path and default configuration.
.SS Options .SS Options
.INDENT 0.0 .INDENT 0.0
.TP .TP
\fB\-a\fP, \fB\-\-catalog\fP
Filter the output by catalog zone name.
.TP
\fB\-m\fP, \fB\-\-member\fP
Filter the output by member zone name.
.TP
\fB\-h\fP, \fB\-\-help\fP \fB\-h\fP, \fB\-\-help\fP
Print the program help. Print the program help.
.TP .TP
......
...@@ -30,6 +30,12 @@ Config options ...@@ -30,6 +30,12 @@ Config options
Options Options
....... .......
**-a**, **--catalog**
Filter the output by catalog zone name.
**-m**, **--member**
Filter the output by member zone name.
**-h**, **--help** **-h**, **--help**
Print the program help. Print the program help.
......
/* Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> /* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
...@@ -25,18 +25,24 @@ ...@@ -25,18 +25,24 @@
#define PROGRAM_NAME "kcatalogprint" #define PROGRAM_NAME "kcatalogprint"
static knot_dname_t *filter_member = NULL;
static knot_dname_t *filter_catalog = NULL;
static void print_help(void) static void print_help(void)
{ {
printf("Usage: %s [-c | -C | -D <path>] [parameters]\n" printf("Usage: %s [-c | -C | -D <path>] [parameters]\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" -c, --config <file> Path to a textual configuration file.\n" " -c, --config <file> Path to a textual configuration file.\n"
" (default %s)\n" " (default %s)\n"
" -C, --confdb <dir> Path to a configuration database directory.\n" " -C, --confdb <dir> Path to a configuration database directory.\n"
" (default %s)\n" " (default %s)\n"
" -D, --dir <path> Path to a catalog database directory, use default configuration.\n" " -D, --dir <path> Path to a catalog database directory, use default\n"
" -h, --help Print the program help.\n" " configuration.\n"
" -V, --version Print the program version.\n", " -a, --catalog <name> Filter the output by catalog zone name.\n"
" -m, --member <name> Filter the output by member zone name.\n"
" -h, --help Print the program help.\n"
" -V, --version Print the program version.\n",
PROGRAM_NAME, CONF_DEFAULT_FILE, CONF_DEFAULT_DBDIR); PROGRAM_NAME, CONF_DEFAULT_FILE, CONF_DEFAULT_DBDIR);
} }
...@@ -50,6 +56,9 @@ static void print_dname(const knot_dname_t *d) ...@@ -50,6 +56,9 @@ static void print_dname(const knot_dname_t *d)
static int catalog_print_cb(const knot_dname_t *mem, const knot_dname_t *ow, static int catalog_print_cb(const knot_dname_t *mem, const knot_dname_t *ow,
const knot_dname_t *cz, const char *group, void *ctx) const knot_dname_t *cz, const char *group, void *ctx)
{ {
if (filter_catalog != NULL && !knot_dname_is_equal(filter_catalog, cz)) {
return KNOT_EOK;
}
print_dname(mem); print_dname(mem);
print_dname(ow); print_dname(ow);
print_dname(cz); print_dname(cz);
...@@ -67,7 +76,7 @@ static void catalog_print(catalog_t *cat) ...@@ -67,7 +76,7 @@ static void catalog_print(catalog_t *cat)
if (cat != NULL) { if (cat != NULL) {
int ret = catalog_open(cat); int ret = catalog_open(cat);
if (ret == KNOT_EOK) { if (ret == KNOT_EOK) {
ret = catalog_apply(cat, NULL, catalog_print_cb, &total, false); ret = catalog_apply(cat, filter_member, catalog_print_cb, &total, false);
} }
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
ERR2("failed to print catalog (%s)\n", knot_strerror(ret)); ERR2("failed to print catalog (%s)\n", knot_strerror(ret));
...@@ -78,19 +87,27 @@ static void catalog_print(catalog_t *cat) ...@@ -78,19 +87,27 @@ static void catalog_print(catalog_t *cat)
printf("Total records: %zd\n", total); printf("Total records: %zd\n", total);
} }
static void params_cleanup(void)
{
free(filter_member);
free(filter_catalog);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct option opts[] = { struct option opts[] = {
{ "config", required_argument, NULL, 'c' }, { "config", required_argument, NULL, 'c' },
{ "confdb", required_argument, NULL, 'C' }, { "confdb", required_argument, NULL, 'C' },
{ "dir", required_argument, NULL, 'D' }, { "dir", required_argument, NULL, 'D' },
{ "catalog", required_argument, NULL, 'a' },
{ "member", required_argument, NULL, 'm' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ NULL } { NULL }
}; };
int opt = 0; int opt = 0;
while ((opt = getopt_long(argc, argv, "c:C:D:hV", opts, NULL)) != -1) { while ((opt = getopt_long(argc, argv, "c:C:D:a:m:hV", opts, NULL)) != -1) {
switch (opt) { switch (opt) {
case 'c': case 'c':
if (util_conf_init_file(optarg) != KNOT_EOK) { if (util_conf_init_file(optarg) != KNOT_EOK) {
...@@ -107,6 +124,16 @@ int main(int argc, char *argv[]) ...@@ -107,6 +124,16 @@ int main(int argc, char *argv[])
goto failure; goto failure;
} }
break; break;
case 'a':
free(filter_catalog);
filter_catalog = knot_dname_from_str_alloc(optarg);
knot_dname_to_lower(filter_catalog);
break;
case 'm':
free(filter_member);
filter_member = knot_dname_from_str_alloc(optarg);
knot_dname_to_lower(filter_member);
break;
case 'h': case 'h':
print_help(); print_help();
goto success; goto success;
...@@ -141,9 +168,11 @@ int main(int argc, char *argv[]) ...@@ -141,9 +168,11 @@ int main(int argc, char *argv[])
catalog_deinit(&c); catalog_deinit(&c);
success: success:
params_cleanup();
util_conf_deinit(); util_conf_deinit();
return EXIT_SUCCESS; return EXIT_SUCCESS;
failure: failure:
params_cleanup();
util_conf_deinit(); util_conf_deinit();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
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