diff options
| author | 2024-03-11 06:00:21 +0100 | |
|---|---|---|
| committer | 2024-03-11 06:00:21 +0100 | |
| commit | 60c2a50ed9a0efc8bbbdbeb48b4a96a1eb80f946 (patch) | |
| tree | 70e577d7064b3f1f52138d984e0a693d8e161b6c /data.c | |
| parent | Replaced all xs_dict_iter() with xs_dict_next(). (diff) | |
| download | snac2-60c2a50ed9a0efc8bbbdbeb48b4a96a1eb80f946.tar.gz snac2-60c2a50ed9a0efc8bbbdbeb48b4a96a1eb80f946.tar.xz snac2-60c2a50ed9a0efc8bbbdbeb48b4a96a1eb80f946.zip | |
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 @@ | |||
| 9 | #include "xs_glob.h" | 9 | #include "xs_glob.h" |
| 10 | #include "xs_set.h" | 10 | #include "xs_set.h" |
| 11 | #include "xs_time.h" | 11 | #include "xs_time.h" |
| 12 | #include "xs_regex.h" | ||
| 12 | 13 | ||
| 13 | #include "snac.h" | 14 | #include "snac.h" |
| 14 | 15 | ||
| @@ -2006,6 +2007,45 @@ int instance_unblock(const char *instance) | |||
| 2006 | } | 2007 | } |
| 2007 | 2008 | ||
| 2008 | 2009 | ||
| 2010 | /** content filtering **/ | ||
| 2011 | |||
| 2012 | int content_check(const char *file, const xs_dict *msg) | ||
| 2013 | /* checks if message content matches any of the regexes in file */ | ||
| 2014 | { | ||
| 2015 | xs *fn = xs_fmt("%s/%s", srv_basedir, file); | ||
| 2016 | FILE *f; | ||
| 2017 | int r = 0; | ||
| 2018 | char *v = xs_dict_get(msg, "content"); | ||
| 2019 | |||
| 2020 | if (xs_type(v) == XSTYPE_STRING && *v) { | ||
| 2021 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 2022 | srv_debug(1, xs_fmt("content_check: loading regexes from %s", fn)); | ||
| 2023 | |||
| 2024 | xs *c = xs_regex_replace(v, "<[^>]+>", " "); | ||
| 2025 | c = xs_regex_replace_i(c, " {2,}", " "); | ||
| 2026 | c = xs_tolower_i(c); | ||
| 2027 | |||
| 2028 | while (!r && !feof(f)) { | ||
| 2029 | xs *rx = xs_strip_i(xs_readline(f)); | ||
| 2030 | |||
| 2031 | if (*rx) { | ||
| 2032 | xs *l = xs_regex_select_n(c, rx, 1); | ||
| 2033 | |||
| 2034 | if (xs_list_len(l)) { | ||
| 2035 | srv_debug(1, xs_fmt("content_check: match for '%s'", rx)); | ||
| 2036 | r = 1; | ||
| 2037 | } | ||
| 2038 | } | ||
| 2039 | } | ||
| 2040 | |||
| 2041 | fclose(f); | ||
| 2042 | } | ||
| 2043 | } | ||
| 2044 | |||
| 2045 | return r; | ||
| 2046 | } | ||
| 2047 | |||
| 2048 | |||
| 2009 | /** notifications **/ | 2049 | /** notifications **/ |
| 2010 | 2050 | ||
| 2011 | xs_str *notify_check_time(snac *snac, int reset) | 2051 | xs_str *notify_check_time(snac *snac, int reset) |