commit 48941cf
default
·
2024-03-11 08:53:20 +0000 UTC
parent bb28b1c
Also call content_check() from timeline_request().
2 files changed,
+16,
-10
M
data.c
+13,
-9
1@@ -354,18 +354,22 @@ int timeline_request(snac *snac, char **id, xs_str **wrk, int level)
2 if (xs_match(type, "Note|Page|Article|Video")) {
3 const char *actor = get_atto(object);
4
5- /* request (and drop) the actor for this entry */
6- if (!xs_is_null(actor))
7- actor_request(snac, actor, NULL);
8+ if (content_check("filter_reject.txt", object))
9+ snac_log(snac, xs_fmt("timeline_request rejected by content %s", nid));
10+ else {
11+ /* request (and drop) the actor for this entry */
12+ if (!xs_is_null(actor))
13+ actor_request(snac, actor, NULL);
14
15- /* does it have an ancestor? */
16- char *in_reply_to = xs_dict_get(object, "inReplyTo");
17+ /* does it have an ancestor? */
18+ char *in_reply_to = xs_dict_get(object, "inReplyTo");
19
20- /* store */
21- timeline_add(snac, nid, object);
22+ /* store */
23+ timeline_add(snac, nid, object);
24
25- /* recurse! */
26- timeline_request(snac, &in_reply_to, NULL, level + 1);
27+ /* recurse! */
28+ timeline_request(snac, &in_reply_to, NULL, level + 1);
29+ }
30 }
31 }
32 }
M
data.c
+3,
-1
1@@ -2010,7 +2010,8 @@ int instance_unblock(const char *instance)
2 /** content filtering **/
3
4 int content_check(const char *file, const xs_dict *msg)
5-/* checks if message content matches any of the regexes in file */
6+/* checks if a message's content matches any of the regexes in file */
7+/* file format: one regex per line */
8 {
9 xs *fn = xs_fmt("%s/%s", srv_basedir, file);
10 FILE *f;
11@@ -2021,6 +2022,7 @@ int content_check(const char *file, const xs_dict *msg)
12 if ((f = fopen(fn, "r")) != NULL) {
13 srv_debug(1, xs_fmt("content_check: loading regexes from %s", fn));
14
15+ /* massage content (strip HTML tags, etc.) */
16 xs *c = xs_regex_replace(v, "<[^>]+>", " ");
17 c = xs_regex_replace_i(c, " {2,}", " ");
18 c = xs_tolower_i(c);