summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-06-29 08:07:10 +0200
committerdefault <nobody@localhost>2023-06-29 08:07:10 +0200
commit61957a86da212cb0784dfc3de7bfcafe3dc7589b (patch)
tree6523ebbfcff60189b30e3402e10f3065fde0830a
parent090c7cc166809ef9f9eb5cb40d97046002c1a305 (diff)
Added instance blocking to data storage.
-rw-r--r--data.c66
-rw-r--r--snac.h4
2 files changed, 70 insertions, 0 deletions
diff --git a/data.c b/data.c
index 9972865..117e16f 100644
--- a/data.c
+++ b/data.c
@@ -1751,6 +1751,72 @@ xs_list *inbox_list(void)
}
+/** instance-wide operations **/
+
+xs_str *_instance_block_fn(const char *instance)
+{
+ xs *s1 = xs_replace(instance, "https:/" "/", "");
+ xs *l = xs_split(s1, "/");
+ char *p = xs_list_get(l, 0);
+ xs *md5 = xs_md5_hex(p, strlen(p));
+
+ return xs_fmt("%s/block/%s", srv_basedir, md5);
+}
+
+
+int is_instance_blocked(const char *instance)
+{
+ xs *fn = _instance_block_fn(instance);
+
+ return !!(mtime(fn) != 0.0);
+}
+
+
+int instance_block(const char *instance)
+/* blocks a full instance */
+{
+ int ret;
+
+ /* create the subdir */
+ xs *dir = xs_fmt("%s/block/", srv_basedir);
+ mkdirx(dir);
+
+ if (!is_instance_blocked(instance)) {
+ xs *fn = _instance_block_fn(instance);
+ FILE *f;
+
+ if ((f = fopen(fn, "w")) != NULL) {
+ fprintf(f, "%s\n", instance);
+ fclose(f);
+
+ ret = 0;
+ }
+ else
+ ret = -1;
+ }
+ else
+ ret = -2;
+
+ return ret;
+}
+
+
+int instance_unblock(const char *instance)
+/* unblocks a full instance */
+{
+ int ret;
+
+ if (is_instance_blocked(instance)) {
+ xs *fn = _instance_block_fn(instance);
+ ret = unlink(fn);
+ }
+ else
+ ret = -2;
+
+ return ret;
+}
+
+
/** notifications **/
xs_str *notify_check_time(snac *snac, int reset)
diff --git a/snac.h b/snac.h
index 5a26ec2..13cfe8c 100644
--- a/snac.h
+++ b/snac.h
@@ -161,6 +161,10 @@ void inbox_add(const char *inbox);
void inbox_add_by_actor(const xs_dict *actor);
xs_list *inbox_list(void);
+int is_instance_blocked(const char *instance);
+int instance_block(const char *instance);
+int instance_unblock(const char *instance);
+
void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries);
void enqueue_output_raw(const char *keyid, const char *seckey,
xs_dict *msg, xs_str *inbox, int retries);