diff options
author | 2016-04-11 20:36:54 +0200 | |
---|---|---|
committer | 2016-04-11 20:36:54 +0200 | |
commit | 33ea0951f889eb1edccc90244603d968a09dd392 (patch) | |
tree | df533c06fb6283fa95e06013c6c92e883a7e7304 | |
parent | replace malloc with xmalloc, change return style, and fix a few strings (diff) | |
download | OpenSMTPD-extras-33ea0951f889eb1edccc90244603d968a09dd392.tar.xz OpenSMTPD-extras-33ea0951f889eb1edccc90244603d968a09dd392.zip |
change limit option to bytes instead of lines, similar to filter-spamassassin
-rw-r--r-- | extras/wip/filters/filter-regex/filter-regex.8 | 10 | ||||
-rw-r--r-- | extras/wip/filters/filter-regex/filter_regex.c | 11 |
2 files changed, 10 insertions, 11 deletions
diff --git a/extras/wip/filters/filter-regex/filter-regex.8 b/extras/wip/filters/filter-regex/filter-regex.8 index 5c50857..9009dd7 100644 --- a/extras/wip/filters/filter-regex/filter-regex.8 +++ b/extras/wip/filters/filter-regex/filter-regex.8 @@ -1,6 +1,6 @@ .\" $OpenBSD: $ .\" -.\" Copyright (c) 2015, Joerg Jung <jung@openbsd.org> +.\" Copyright (c) 2015, 2016 Joerg Jung <jung@openbsd.org> .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: May 15 2015 $ +.Dd $Mdocdate: April 10 2016 $ .Dt FILTER-REGEX 8 .Os .Sh NAME @@ -40,13 +40,11 @@ Debug mode, if this option is specified, will run in the foreground and log to .Em stderr . .It Fl l Ar limit -Set the number of lines +Set the number of bytes .Ar limit -of -.Nm after which the regular expression processing is stopped and the mail is accepted. -The accepted values are within the range of 1 and UINT_MAX. +The accepted values are within the range of 1 and SIZE_T_MAX. .Pp The default .Ar limit diff --git a/extras/wip/filters/filter-regex/filter_regex.c b/extras/wip/filters/filter-regex/filter_regex.c index b9e0cbb..bfe5563 100644 --- a/extras/wip/filters/filter-regex/filter_regex.c +++ b/extras/wip/filters/filter-regex/filter_regex.c @@ -2,7 +2,7 @@ /* * Copyright (c) 2015 Armin Wolfermann <armin@wolfermann.org> - * Copyright (c) 2015 Joerg Jung <jung@openbsd.org> + * Copyright (c) 2015, 2016 Joerg Jung <jung@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -53,7 +53,7 @@ static struct { const char *s; struct regex_q *rq; } regex_s[] = { { "connect", ®ex_connect }, { "helo", ®ex_helo }, { "mail", ®ex_mail }, { "rcpt", ®ex_rcpt }, { "dataline", ®ex_dataline }, { NULL, NULL } }; -static unsigned int regex_limit; +static size_t regex_limit; static char * regex_skip(char *s) { @@ -212,14 +212,15 @@ regex_on_rcpt(uint64_t id, struct mailaddr *r) static void regex_on_dataline(uint64_t id, const char *l) { - struct { int m; unsigned int l; } *u; + struct { int m; size_t l; } *u; filter_api_writeln(id, l); if ((u = filter_api_get_udata(id)) == NULL) { u = xcalloc(1, sizeof(*u), "on_dataline"); filter_api_set_udata(id, u); } - if (u->m || (regex_limit && ++u->l >= regex_limit)) + u->l += strlen(l); + if (u->m || (regex_limit && u->l >= regex_limit)) return; u->m = regex_match(®ex_dataline, l); } @@ -291,7 +292,7 @@ main(int argc, char **argv) fatalx("bogus argument(s)"); if (l) { - regex_limit = strtonum(l, 1, UINT_MAX, &errstr); + regex_limit = strtonum(l, 1, SIZE_T_MAX, &errstr); if (errstr) fatalx("limit option is %s: %s", errstr, l); } |