]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
knotc: reduce usage and automate the value of MAX_FILTERS
authorDaniel Salzman <daniel.salzman@nic.cz>
Mon, 12 Jun 2023 08:13:16 +0000 (10:13 +0200)
committerDavid Vašek <david.vasek@nic.cz>
Tue, 13 Jun 2023 09:10:20 +0000 (11:10 +0200)
src/utils/knotc/commands.c

index 19e9d7cb89427e1760638f4c139ecc73b43ee4aa..2b38ca1b2eea37b099e8b17c3423834327144218 100644 (file)
@@ -681,19 +681,18 @@ static int cmd_zone_ctl(cmd_args_t *args)
        return ctl_receive(args);
 }
 
-#define MAX_FILTERS 14
-
 typedef struct {
        const char *name;
        char id;
        bool with_data; // Only ONE filter of each filter_desc_t may have data!
 } filter_desc_t;
 
-const filter_desc_t zone_flush_filters[MAX_FILTERS] = {
+const filter_desc_t zone_flush_filters[] = {
        { "+outdir", CTL_FILTER_FLUSH_OUTDIR, true },
+       { NULL },
 };
 
-const filter_desc_t zone_backup_filters[MAX_FILTERS] = {
+const filter_desc_t zone_backup_filters[] = {
        { "+backupdir",   CTL_FILTER_BACKUP_OUTDIR,      true },
        { "+zonefile",    CTL_FILTER_BACKUP_ZONEFILE,   false },
        { "+nozonefile",  CTL_FILTER_BACKUP_NOZONEFILE, false },
@@ -707,18 +706,20 @@ const filter_desc_t zone_backup_filters[MAX_FILTERS] = {
        { "+nocatalog",   CTL_FILTER_BACKUP_NOCATALOG,  false },
        { "+quic",        CTL_FILTER_BACKUP_QUIC,       false },
        { "+noquic",      CTL_FILTER_BACKUP_NOQUIC,     false },
+       { NULL },
 };
 
-const filter_desc_t zone_status_filters[MAX_FILTERS] = {
+const filter_desc_t zone_status_filters[] = {
        { "+role",        CTL_FILTER_STATUS_ROLE },
        { "+serial",      CTL_FILTER_STATUS_SERIAL },
        { "+transaction", CTL_FILTER_STATUS_TRANSACTION },
        { "+freeze",      CTL_FILTER_STATUS_FREEZE },
        { "+catalog",     CTL_FILTER_STATUS_CATALOG },
        { "+events",      CTL_FILTER_STATUS_EVENTS },
+       { NULL },
 };
 
-const filter_desc_t zone_purge_filters[MAX_FILTERS] = {
+const filter_desc_t zone_purge_filters[] = {
        { "+expire",   CTL_FILTER_PURGE_EXPIRE },
        { "+zonefile", CTL_FILTER_PURGE_ZONEFILE },
        { "+journal",  CTL_FILTER_PURGE_JOURNAL },
@@ -726,9 +727,12 @@ const filter_desc_t zone_purge_filters[MAX_FILTERS] = {
        { "+kaspdb",   CTL_FILTER_PURGE_KASPDB },
        { "+catalog",  CTL_FILTER_PURGE_CATALOG },
        { "+orphan",   CTL_FILTER_PURGE_ORPHAN },
+       { NULL },
 };
 
-const filter_desc_t null_filter = { 0 };
+const filter_desc_t null_filter = { NULL };
+
+#define MAX_FILTERS sizeof(zone_backup_filters) / sizeof(filter_desc_t) - 1
 
 static const filter_desc_t *get_filter(ctl_cmd_t cmd, const char *filter_name)
 {
@@ -750,7 +754,7 @@ static const filter_desc_t *get_filter(ctl_cmd_t cmd, const char *filter_name)
        default:
                return &null_filter;
        }
-       for (size_t i = 0; i < MAX_FILTERS && fd[i].name != NULL; i++) {
+       for (size_t i = 0; fd[i].name != NULL; i++) {
                if (strcmp(fd[i].name, filter_name) == 0) {
                        return &fd[i];
                }