Skip to content

Commit

Permalink
introduce table_dump() and tweak format
Browse files Browse the repository at this point in the history
ok gilles@
  • Loading branch information
ericfaurot committed Dec 28, 2018
1 parent 54e30ac commit 9c07e90
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 26 deletions.
3 changes: 2 additions & 1 deletion usr.sbin/smtpd/smtpd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: smtpd.h,v 1.614 2018/12/28 11:40:29 eric Exp $ */
/* $OpenBSD: smtpd.h,v 1.615 2018/12/28 15:09:28 eric Exp $ */

/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
Expand Down Expand Up @@ -1603,6 +1603,7 @@ int table_config(struct table *);
int table_open(struct table *);
int table_update(struct table *);
void table_close(struct table *);
void table_dump(struct table *);
int table_check_use(struct table *, uint32_t, uint32_t);
int table_check_type(struct table *, uint32_t);
int table_check_service(struct table *, uint32_t);
Expand Down
64 changes: 39 additions & 25 deletions usr.sbin/smtpd/table.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: table.c,v 1.46 2018/12/28 13:47:54 eric Exp $ */
/* $OpenBSD: table.c,v 1.47 2018/12/28 15:09:28 eric Exp $ */

/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
Expand Down Expand Up @@ -273,6 +273,42 @@ table_add(struct table *t, const char *key, const char *val)
log_warnx("warn: failed to add \"%s\" in table \"%s\"", key, t->t_name);
}

void
table_dump(struct table *t)
{
const char *type;
char buf[LINE_MAX];

switch(t->t_type) {
case T_NONE:
type = "NONE";
break;
case T_DYNAMIC:
type = "DYNAMIC";
break;
case T_LIST:
type = "LIST";
break;
case T_HASH:
type = "HASH";
break;
default:
type = "???";
break;
}

if (t->t_config[0])
snprintf(buf, sizeof(buf), " config=\"%s\"", t->t_config);
else
buf[0] = '\0';

log_debug("TABLE \"%s\" backend=%s type=%s%s", t->t_name,
t->t_backend->name, type, buf);

if (t->t_backend->dump)
t->t_backend->dump(t);
}

int
table_check_type(struct table *t, uint32_t mask)
{
Expand Down Expand Up @@ -446,32 +482,10 @@ table_dump_all(struct smtpd *conf)
{
struct table *t;
void *iter;
const char *sep;
char buf[1024];

iter = NULL;
while (dict_iter(conf->sc_tables_dict, &iter, NULL, (void **)&t)) {
sep = "";
buf[0] = '\0';
if (t->t_type & T_DYNAMIC) {
(void)strlcat(buf, "DYNAMIC", sizeof(buf));
sep = ",";
}
if (t->t_type & T_LIST) {
(void)strlcat(buf, sep, sizeof(buf));
(void)strlcat(buf, "LIST", sizeof(buf));
sep = ",";
}
if (t->t_type & T_HASH) {
(void)strlcat(buf, sep, sizeof(buf));
(void)strlcat(buf, "HASH", sizeof(buf));
sep = ",";
}
log_debug("TABLE \"%s\" type=%s config=\"%s\"",
t->t_name, buf, t->t_config);
if (t->t_backend->dump)
t->t_backend->dump(t);
}
while (dict_iter(conf->sc_tables_dict, &iter, NULL, (void **)&t))
table_dump(t);
}

void
Expand Down

0 comments on commit 9c07e90

Please sign in to comment.