From 9a2428ac8f9eeb51f3d6df241a525f2af69d86c0 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 27 Dec 2018 09:30:29 +0000 Subject: [PATCH] pass the table pointer to the lookup()/fecth() methods ok gilles@ --- usr.sbin/smtpd/smtpd.h | 6 +++--- usr.sbin/smtpd/table.c | 6 +++--- usr.sbin/smtpd/table_db.c | 21 ++++++++------------- usr.sbin/smtpd/table_getpwnam.c | 6 +++--- usr.sbin/smtpd/table_proc.c | 10 +++++----- usr.sbin/smtpd/table_static.c | 12 +++++------- 6 files changed, 27 insertions(+), 34 deletions(-) diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 397427d3957..6f42711ac7d 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.609 2018/12/27 08:57:03 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.610 2018/12/27 09:30:29 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -368,8 +368,8 @@ struct table_backend { int (*open)(struct table *); int (*update)(struct table *); void (*close)(struct table *); - int (*lookup)(void *, enum table_service, const char *, char **); - int (*fetch)(void *, enum table_service, char **); + int (*lookup)(struct table *, enum table_service, const char *, char **); + int (*fetch)(struct table *, enum table_service, char **); }; diff --git a/usr.sbin/smtpd/table.c b/usr.sbin/smtpd/table.c index e6190afa3b9..43ad9afabe4 100644 --- a/usr.sbin/smtpd/table.c +++ b/usr.sbin/smtpd/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.40 2018/12/27 08:57:03 eric Exp $ */ +/* $OpenBSD: table.c,v 1.41 2018/12/27 09:30:29 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -136,7 +136,7 @@ table_lookup(struct table *table, enum table_service kind, const char *key, return -1; } - r = table->t_backend->lookup(table->t_handle, kind, lkey, lk ? &buf : NULL); + r = table->t_backend->lookup(table, kind, lkey, lk ? &buf : NULL); if (r == 1) { log_trace(TRACE_LOOKUP, "lookup: %s \"%s\" as %s in table %s:%s -> %s%s%s", @@ -174,7 +174,7 @@ table_fetch(struct table *table, enum table_service kind, union lookup *lk) if (table->t_backend->fetch == NULL) return (-1); - r = table->t_backend->fetch(table->t_handle, kind, lk ? &buf : NULL); + r = table->t_backend->fetch(table, kind, lk ? &buf : NULL); if (r == 1) { log_trace(TRACE_LOOKUP, "lookup: fetch %s from table %s:%s -> %s%s%s", diff --git a/usr.sbin/smtpd/table_db.c b/usr.sbin/smtpd/table_db.c index 3f1074dcdd6..9e71d1c30d3 100644 --- a/usr.sbin/smtpd/table_db.c +++ b/usr.sbin/smtpd/table_db.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_db.c,v 1.16 2018/12/27 08:57:03 eric Exp $ */ +/* $OpenBSD: table_db.c,v 1.17 2018/12/27 09:30:29 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade @@ -44,8 +44,8 @@ static int table_db_config(struct table *); static int table_db_update(struct table *); static int table_db_open(struct table *); static void *table_db_open2(struct table *); -static int table_db_lookup(void *, enum table_service, const char *, char **); -static int table_db_fetch(void *, enum table_service, char **); +static int table_db_lookup(struct table *, enum table_service, const char *, char **); +static int table_db_fetch(struct table *, enum table_service, char **); static void table_db_close(struct table *); static void table_db_close2(void *); @@ -77,7 +77,6 @@ struct dbhandle { DB *db; char pathname[PATH_MAX]; time_t mtime; - struct table *table; }; static int @@ -141,7 +140,6 @@ table_db_open2(struct table *table) handle->db = dbopen(table->t_config, O_RDONLY, 0600, DB_HASH, NULL); if (handle->db == NULL) goto error; - handle->table = table; return handle; @@ -161,11 +159,10 @@ table_db_close2(void *hdl) } static int -table_db_lookup(void *hdl, enum table_service service, const char *key, +table_db_lookup(struct table *table, enum table_service service, const char *key, char **dst) { - struct dbhandle *handle = hdl; - struct table *table = NULL; + struct dbhandle *handle = table->t_handle; char *line; size_t len = 0; int ret; @@ -178,8 +175,7 @@ table_db_lookup(void *hdl, enum table_service service, const char *key, /* DB has changed, close and reopen */ if (sb.st_mtime != handle->mtime) { - table = handle->table; - table_db_update(handle->table); + table_db_update(table); handle = table->t_handle; } @@ -204,10 +200,9 @@ table_db_lookup(void *hdl, enum table_service service, const char *key, } static int -table_db_fetch(void *hdl, enum table_service service, char **dst) +table_db_fetch(struct table *table, enum table_service service, char **dst) { - struct dbhandle *handle = hdl; - struct table *table = handle->table; + struct dbhandle *handle = table->t_handle; DBT dbk; DBT dbd; int r; diff --git a/usr.sbin/smtpd/table_getpwnam.c b/usr.sbin/smtpd/table_getpwnam.c index 45a377aaf65..abc4fc8f8d2 100644 --- a/usr.sbin/smtpd/table_getpwnam.c +++ b/usr.sbin/smtpd/table_getpwnam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_getpwnam.c,v 1.10 2018/12/27 08:57:03 eric Exp $ */ +/* $OpenBSD: table_getpwnam.c,v 1.11 2018/12/27 09:30:29 eric Exp $ */ /* * Copyright (c) 2012 Gilles Chehade @@ -41,7 +41,7 @@ static int table_getpwnam_config(struct table *); static int table_getpwnam_update(struct table *); static int table_getpwnam_open(struct table *); -static int table_getpwnam_lookup(void *, enum table_service, const char *, +static int table_getpwnam_lookup(struct table *, enum table_service, const char *, char **); static void table_getpwnam_close(struct table *); @@ -83,7 +83,7 @@ table_getpwnam_close(struct table *table) } static int -table_getpwnam_lookup(void *hdl, enum table_service kind, const char *key, +table_getpwnam_lookup(struct table *table, enum table_service kind, const char *key, char **dst) { struct passwd *pw; diff --git a/usr.sbin/smtpd/table_proc.c b/usr.sbin/smtpd/table_proc.c index 22fd20c916b..f930142fff7 100644 --- a/usr.sbin/smtpd/table_proc.c +++ b/usr.sbin/smtpd/table_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_proc.c,v 1.13 2018/12/27 08:57:03 eric Exp $ */ +/* $OpenBSD: table_proc.c,v 1.14 2018/12/27 09:30:29 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -182,9 +182,9 @@ imsg_add_params(struct ibuf *buf) } static int -table_proc_lookup(void *arg, enum table_service s, const char *k, char **dst) +table_proc_lookup(struct table *table, enum table_service s, const char *k, char **dst) { - struct table_proc_priv *priv = arg; + struct table_proc_priv *priv = table->t_handle; struct ibuf *buf; int r; @@ -226,9 +226,9 @@ table_proc_lookup(void *arg, enum table_service s, const char *k, char **dst) } static int -table_proc_fetch(void *arg, enum table_service s, char **dst) +table_proc_fetch(struct table *table, enum table_service s, char **dst) { - struct table_proc_priv *priv = arg; + struct table_proc_priv *priv = table->t_handle; struct ibuf *buf; int r; diff --git a/usr.sbin/smtpd/table_static.c b/usr.sbin/smtpd/table_static.c index bdd3a59ee42..88377b3f037 100644 --- a/usr.sbin/smtpd/table_static.c +++ b/usr.sbin/smtpd/table_static.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table_static.c,v 1.26 2018/12/27 08:57:03 eric Exp $ */ +/* $OpenBSD: table_static.c,v 1.27 2018/12/27 09:30:29 eric Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -42,9 +42,9 @@ static int table_static_config(struct table *); static int table_static_update(struct table *); static int table_static_open(struct table *); -static int table_static_lookup(void *, enum table_service, const char *, +static int table_static_lookup(struct table *, enum table_service, const char *, char **); -static int table_static_fetch(void *, enum table_service, char **); +static int table_static_fetch(struct table *, enum table_service, char **); static void table_static_close(struct table *); struct table_backend table_backend_static = { @@ -216,10 +216,9 @@ table_static_close(struct table *table) } static int -table_static_lookup(void *hdl, enum table_service service, const char *key, +table_static_lookup(struct table *m, enum table_service service, const char *key, char **dst) { - struct table *m = hdl; char *line; int ret; int (*match)(const char *, const char *) = NULL; @@ -266,9 +265,8 @@ table_static_lookup(void *hdl, enum table_service service, const char *key, } static int -table_static_fetch(void *hdl, enum table_service service, char **dst) +table_static_fetch(struct table *t, enum table_service service, char **dst) { - struct table *t = hdl; const char *k; if (!dict_iter(&t->t_dict, &t->t_iter, &k, (void **)NULL)) { -- 2.20.1