diff options
author | default <nobody@localhost> | 2024-03-11 06:00:21 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2024-03-11 06:00:21 +0100 |
commit | 60c2a50ed9a0efc8bbbdbeb48b4a96a1eb80f946 (patch) | |
tree | 70e577d7064b3f1f52138d984e0a693d8e161b6c /data.c | |
parent | 951e6b23151d298d9babeec81bc9926c11bdb3b3 (diff) |
New function content_check().
Diffstat (limited to 'data.c')
-rw-r--r-- | data.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -9,6 +9,7 @@ #include "xs_glob.h" #include "xs_set.h" #include "xs_time.h" +#include "xs_regex.h" #include "snac.h" @@ -2006,6 +2007,45 @@ int instance_unblock(const char *instance) } +/** content filtering **/ + +int content_check(const char *file, const xs_dict *msg) +/* checks if message content matches any of the regexes in file */ +{ + xs *fn = xs_fmt("%s/%s", srv_basedir, file); + FILE *f; + int r = 0; + char *v = xs_dict_get(msg, "content"); + + if (xs_type(v) == XSTYPE_STRING && *v) { + if ((f = fopen(fn, "r")) != NULL) { + srv_debug(1, xs_fmt("content_check: loading regexes from %s", fn)); + + xs *c = xs_regex_replace(v, "<[^>]+>", " "); + c = xs_regex_replace_i(c, " {2,}", " "); + c = xs_tolower_i(c); + + while (!r && !feof(f)) { + xs *rx = xs_strip_i(xs_readline(f)); + + if (*rx) { + xs *l = xs_regex_select_n(c, rx, 1); + + if (xs_list_len(l)) { + srv_debug(1, xs_fmt("content_check: match for '%s'", rx)); + r = 1; + } + } + } + + fclose(f); + } + } + + return r; +} + + /** notifications **/ xs_str *notify_check_time(snac *snac, int reset) |