mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
New function content_check().
This commit is contained in:
parent
951e6b2315
commit
60c2a50ed9
@ -1921,10 +1921,15 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
|
||||
snac_debug(snac, 0, xs_fmt("dropped reply %s to hidden post %s", id, in_reply_to));
|
||||
}
|
||||
else {
|
||||
if (content_check("filter_reject.txt", object)) {
|
||||
snac_log(snac, xs_fmt("rejected by content %s", id));
|
||||
return 1;
|
||||
}
|
||||
|
||||
timeline_request(snac, &in_reply_to, &wrk, 0);
|
||||
|
||||
if (timeline_add(snac, id, object)) {
|
||||
snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
|
||||
snac_log(snac, xs_fmt("new '%s' %s %s", utype, actor, id));
|
||||
do_notify = 1;
|
||||
}
|
||||
|
||||
|
40
data.c
40
data.c
@ -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)
|
||||
|
2
snac.h
2
snac.h
@ -204,6 +204,8 @@ int is_instance_blocked(const char *instance);
|
||||
int instance_block(const char *instance);
|
||||
int instance_unblock(const char *instance);
|
||||
|
||||
int content_check(const char *file, const xs_dict *msg);
|
||||
|
||||
void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries);
|
||||
void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries);
|
||||
void enqueue_output_raw(const char *keyid, const char *seckey,
|
||||
|
Loading…
Reference in New Issue
Block a user