summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.c7
-rw-r--r--data.c40
-rw-r--r--snac.h2
3 files changed, 48 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c
index 1976012..22a12fa 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -1921,10 +1921,15 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1921 snac_debug(snac, 0, xs_fmt("dropped reply %s to hidden post %s", id, in_reply_to)); 1921 snac_debug(snac, 0, xs_fmt("dropped reply %s to hidden post %s", id, in_reply_to));
1922 } 1922 }
1923 else { 1923 else {
1924 if (content_check("filter_reject.txt", object)) {
1925 snac_log(snac, xs_fmt("rejected by content %s", id));
1926 return 1;
1927 }
1928
1924 timeline_request(snac, &in_reply_to, &wrk, 0); 1929 timeline_request(snac, &in_reply_to, &wrk, 0);
1925 1930
1926 if (timeline_add(snac, id, object)) { 1931 if (timeline_add(snac, id, object)) {
1927 snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); 1932 snac_log(snac, xs_fmt("new '%s' %s %s", utype, actor, id));
1928 do_notify = 1; 1933 do_notify = 1;
1929 } 1934 }
1930 1935
diff --git a/data.c b/data.c
index 4d9824a..67536fd 100644
--- a/data.c
+++ b/data.c
@@ -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
2012int 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
2011xs_str *notify_check_time(snac *snac, int reset) 2051xs_str *notify_check_time(snac *snac, int reset)
diff --git a/snac.h b/snac.h
index 1afbfc7..f2bcedb 100644
--- a/snac.h
+++ b/snac.h
@@ -204,6 +204,8 @@ int is_instance_blocked(const char *instance);
204int instance_block(const char *instance); 204int instance_block(const char *instance);
205int instance_unblock(const char *instance); 205int instance_unblock(const char *instance);
206 206
207int content_check(const char *file, const xs_dict *msg);
208
207void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); 209void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries);
208void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries); 210void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries);
209void enqueue_output_raw(const char *keyid, const char *seckey, 211void enqueue_output_raw(const char *keyid, const char *seckey,