diff options
author | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-12-22 10:39:17 +0000 |
---|---|---|
committer | Gilles Chehade <gilles@cvs.openbsd.org> | 2018-12-22 10:39:17 +0000 |
commit | f3b1e4ded71ad9279c4d0ecc764292d76e4ef86c (patch) | |
tree | f1a66dba0f5778aeb8bacd2db8af9880b3e01b7c /usr.sbin | |
parent | 4c89bc7b04088a0255798c0ce2326a4d0e1a96f6 (diff) |
simplify filter_data() and filter_data_next() by factoring logic
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/smtpd/lka_filter.c | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/usr.sbin/smtpd/lka_filter.c b/usr.sbin/smtpd/lka_filter.c index 08b5eb0d5e4..404cc25b682 100644 --- a/usr.sbin/smtpd/lka_filter.c +++ b/usr.sbin/smtpd/lka_filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lka_filter.c,v 1.22 2018/12/22 10:18:56 gilles Exp $ */ +/* $OpenBSD: lka_filter.c,v 1.23 2018/12/22 10:39:16 gilles Exp $ */ /* * Copyright (c) 2018 Gilles Chehade <gilles@poolp.org> @@ -563,20 +563,36 @@ filter_protocol_next(uint64_t token, uint64_t reqid, const char *param) filter_result_proceed(reqid); } - static void -filter_data(uint64_t reqid, const char *line) +filter_data_internal(uint64_t token, uint64_t reqid, const char *line) { struct filter_session *fs; struct filter_chain *filter_chain; struct filter_entry *filter_entry; struct filter *filter; - fs = tree_xget(&sessions, reqid); + fs = token ? + tree_get(&sessions, reqid) : + tree_xget(&sessions, reqid); + if (fs == NULL) + return; + + if (!token) + fs->phase = FILTER_DATA_LINE; + if (fs->phase != FILTER_DATA_LINE) + fatalx("misbehaving filter"); - fs->phase = FILTER_DATA_LINE; filter_chain = dict_get(&filter_chains, fs->filter_name); filter_entry = TAILQ_FIRST(&filter_chain->chain[fs->phase]); + if (token) { + TAILQ_FOREACH(filter_entry, &filter_chain->chain[fs->phase], entries) + if (filter_entry->id == token) + break; + if (filter_entry == NULL) + fatalx("misbehaving filter"); + filter_entry = TAILQ_NEXT(filter_entry, entries); + } + if (filter_entry == NULL) { io_printf(fs->io, "%s\r\n", line); return; @@ -587,30 +603,15 @@ filter_data(uint64_t reqid, const char *line) } static void -filter_data_next(uint64_t token, uint64_t reqid, const char *line) +filter_data(uint64_t reqid, const char *line) { - struct filter_session *fs; - struct filter_chain *filter_chain; - struct filter_entry *filter_entry; - struct filter *filter; - - /* client session may have disappeared while we were in proc */ - if ((fs = tree_get(&sessions, reqid)) == NULL) - return; - - filter_chain = dict_get(&filter_chains, fs->filter_name); - - TAILQ_FOREACH(filter_entry, &filter_chain->chain[fs->phase], entries) - if (filter_entry->id == token) - break; - - if ((filter_entry = TAILQ_NEXT(filter_entry, entries))) { - filter = dict_get(&filters, filter_entry->name); - filter_data_query(filter, filter_entry->id, reqid, line); - return; - } + filter_data_internal(0, reqid, line); +} - io_printf(fs->io, "%s\r\n", line); +static void +filter_data_next(uint64_t token, uint64_t reqid, const char *line) +{ + filter_data_internal(token, reqid, line); } |