commit bad729c
default
·
2023-12-06 13:46:51 +0000 UTC
parent 7a18a60
Started work to support shared inboxes.
3 files changed,
+70,
-1
+47,
-0
1@@ -1008,6 +1008,15 @@ xs_dict *msg_actor(snac *snac)
2 msg = xs_dict_set(msg, "attachment", attach);
3 }
4
5+#ifdef SHARED_INBOX
6+ {
7+ xs *d = xs_dict_new();
8+ xs *si = xs_fmt("%s/shared-inbox", srv_baseurl);
9+ d = xs_dict_append(d, "sharedInbox", si);
10+ msg = xs_dict_set(msg, "endpoints", d);
11+ }
12+#endif
13+
14 return msg;
15 }
16
17@@ -2024,6 +2033,39 @@ void process_queue_item(xs_dict *q_item)
18
19 srv_log(xs_dup("purge end"));
20 }
21+ else
22+ if (strcmp(type, "input") == 0) {
23+ /* redistribute the input message to all users */
24+ char *ntid = xs_dict_get(q_item, "ntid");
25+ xs *tmpfn = xs_fmt("%s/tmp/%s.json", srv_basedir, ntid);
26+ FILE *f;
27+
28+ if ((f = fopen(tmpfn, "w")) != NULL) {
29+ xs_json_dump(q_item, 4, f);
30+ fclose(f);
31+ }
32+
33+ xs *users = user_list();
34+ xs_list *p = users;
35+ char *v;
36+
37+ while (xs_list_iter(&p, &v)) {
38+ snac user;
39+
40+ if (user_open(&user, v)) {
41+ xs *fn = xs_fmt("%s/queue/%s.json", user.basedir, ntid);
42+
43+ srv_debug(1, xs_fmt("enqueue_input (from shared inbox) %s", fn));
44+
45+ if (link(tmpfn, fn) < 0)
46+ srv_log(xs_fmt("link(%s, %s) error", tmpfn, fn));
47+
48+ user_free(&user);
49+ }
50+ }
51+
52+ unlink(tmpfn);
53+ }
54 else
55 srv_log(xs_fmt("unexpected q_item type '%s'", type));
56 }
57@@ -2197,6 +2239,11 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path,
58 /* get the user and path */
59 xs *l = xs_split_n(q_path, "/", 2);
60
61+ if (xs_list_len(l) == 2 && strcmp(xs_list_get(l, 1), "shared-inbox") == 0) {
62+ enqueue_shared_input(msg, req, 0);
63+ return 202;
64+ }
65+
66 if (xs_list_len(l) != 3 || strcmp(xs_list_get(l, 2), "inbox") != 0) {
67 /* strange q_path */
68 srv_debug(1, xs_fmt("activitypub_post_handler unsupported path %s", q_path));
M
data.c
+22,
-1
1@@ -99,6 +99,9 @@ int srv_open(char *basedir, int auto_upgrade)
2 xs *ibdir = xs_fmt("%s/inbox", srv_basedir);
3 mkdirx(ibdir);
4
5+ xs *tmpdir = xs_fmt("%s/tmp", srv_basedir);
6+ mkdirx(tmpdir);
7+
8 #ifdef __OpenBSD__
9 char *v = xs_dict_get(srv_config, "disable_openbsd_security");
10
11@@ -1586,9 +1589,12 @@ void tag_index(const char *id, const xs_dict *obj)
12 char *name = xs_dict_get(v, "name");
13
14 if (!xs_is_null(type) && !xs_is_null(name) && strcmp(type, "Hashtag") == 0) {
15- if (*name == '#')
16+ while (*name == '#' || *name == '@')
17 name++;
18
19+ if (*name == '\0')
20+ continue;
21+
22 name = xs_tolower_i(name);
23
24 xs *md5_tag = xs_md5_hex(name, strlen(name));
25@@ -2123,6 +2129,21 @@ void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retri
26 }
27
28
29+void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries)
30+/* enqueues an input message from the shared input */
31+{
32+ xs *qmsg = _new_qmsg("input", msg, retries);
33+ char *ntid = xs_dict_get(qmsg, "ntid");
34+ xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid);
35+
36+ qmsg = xs_dict_append(qmsg, "req", req);
37+
38+ qmsg = _enqueue_put(fn, qmsg);
39+
40+ srv_debug(1, xs_fmt("enqueue_shared_input %s", fn));
41+}
42+
43+
44 void enqueue_output_raw(const char *keyid, const char *seckey,
45 xs_dict *msg, xs_str *inbox, int retries, int p_status)
46 /* enqueues an output message to an inbox */
M
snac.h
+1,
-0
1@@ -181,6 +181,7 @@ int instance_block(const char *instance);
2 int instance_unblock(const char *instance);
3
4 void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries);
5+void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries);
6 void enqueue_output_raw(const char *keyid, const char *seckey,
7 xs_dict *msg, xs_str *inbox, int retries, int p_status);
8 void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries, int p_status);