diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2010-04-21 19:37:33 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2010-04-21 19:37:33 +0000 |
commit | 8ce41e9fda91d29fefdeec97863a9f8ddaca36a2 (patch) | |
tree | 2113d13414257c83cb20cb491a9eb97a06f7fa93 /usr.sbin | |
parent | 6091432ef10a115d6df3da0ffff5bf63a26d6a31 (diff) |
simplify map_lookup() by having the backend lookup done in new
map_backend_lookup() function, no functionnal change, first of
many changes to come in map.c
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/map.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/usr.sbin/smtpd/map.c b/usr.sbin/smtpd/map.c index 41de676ceba..4e8a5737cff 100644 --- a/usr.sbin/smtpd/map.c +++ b/usr.sbin/smtpd/map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map.c,v 1.9 2010/02/17 17:37:15 gilles Exp $ */ +/* $OpenBSD: map.c,v 1.10 2010/04/21 19:37:32 gilles Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -34,6 +34,8 @@ #include "smtpd.h" +struct map_backend *map_backend_lookup(enum map_src); + /* db(3) backend */ void *map_db_open(char *); void map_db_close(void *); @@ -48,7 +50,7 @@ int map_stdio_put(void *, char *, char *); struct map_backend { - enum map_src map_type; + enum map_src source; void *(*open)(char *); void (*close)(void *); char *(*get)(void *, char *); @@ -87,7 +89,6 @@ map_find(struct smtpd *env, objid_t id) char * map_lookup(struct smtpd *env, objid_t mapid, char *key) { - u_int8_t i; void *hdl = NULL; char *result = NULL; struct map *map; @@ -97,14 +98,8 @@ map_lookup(struct smtpd *env, objid_t mapid, char *key) if (map == NULL) return NULL; - for (i = 0; i < nitems(map_backends); ++i) - if (map_backends[i].map_type == map->m_src) - break; + backend = map_backend_lookup(map->m_src); - if (i == nitems(map_backends)) - fatalx("invalid map type"); - - backend = &map_backends[i]; hdl = backend->open(map->m_config); if (hdl == NULL) { log_warn("map_lookup: can't open %s", map->m_config); @@ -117,6 +112,21 @@ map_lookup(struct smtpd *env, objid_t mapid, char *key) return result; } +struct map_backend * +map_backend_lookup(enum map_src source) +{ + u_int8_t i; + + for (i = 0; i < nitems(map_backends); ++i) + if (map_backends[i].source == source) + break; + + if (i == nitems(map_backends)) + fatalx("invalid map type"); + + return &map_backends[i]; +} + /* db(3) backend */ void * |