diff options
| author | 2023-12-06 14:46:51 +0100 | |
|---|---|---|
| committer | 2023-12-06 14:46:51 +0100 | |
| commit | bad729c631819db04191605a237c8fa632818dd8 (patch) | |
| tree | ececcb0643dfa5020e2b155c0208808d8e4a73e9 | |
| parent | Show the md5 of the original post in its link in html_actor_icon(). (diff) | |
| download | snac2-bad729c631819db04191605a237c8fa632818dd8.tar.gz snac2-bad729c631819db04191605a237c8fa632818dd8.tar.xz snac2-bad729c631819db04191605a237c8fa632818dd8.zip | |
Started work to support shared inboxes.
| -rw-r--r-- | activitypub.c | 47 | ||||
| -rw-r--r-- | data.c | 23 | ||||
| -rw-r--r-- | snac.h | 1 |
3 files changed, 70 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c index e354a22..92a1026 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1008,6 +1008,15 @@ xs_dict *msg_actor(snac *snac) | |||
| 1008 | msg = xs_dict_set(msg, "attachment", attach); | 1008 | msg = xs_dict_set(msg, "attachment", attach); |
| 1009 | } | 1009 | } |
| 1010 | 1010 | ||
| 1011 | #ifdef SHARED_INBOX | ||
| 1012 | { | ||
| 1013 | xs *d = xs_dict_new(); | ||
| 1014 | xs *si = xs_fmt("%s/shared-inbox", srv_baseurl); | ||
| 1015 | d = xs_dict_append(d, "sharedInbox", si); | ||
| 1016 | msg = xs_dict_set(msg, "endpoints", d); | ||
| 1017 | } | ||
| 1018 | #endif | ||
| 1019 | |||
| 1011 | return msg; | 1020 | return msg; |
| 1012 | } | 1021 | } |
| 1013 | 1022 | ||
| @@ -2025,6 +2034,39 @@ void process_queue_item(xs_dict *q_item) | |||
| 2025 | srv_log(xs_dup("purge end")); | 2034 | srv_log(xs_dup("purge end")); |
| 2026 | } | 2035 | } |
| 2027 | else | 2036 | else |
| 2037 | if (strcmp(type, "input") == 0) { | ||
| 2038 | /* redistribute the input message to all users */ | ||
| 2039 | char *ntid = xs_dict_get(q_item, "ntid"); | ||
| 2040 | xs *tmpfn = xs_fmt("%s/tmp/%s.json", srv_basedir, ntid); | ||
| 2041 | FILE *f; | ||
| 2042 | |||
| 2043 | if ((f = fopen(tmpfn, "w")) != NULL) { | ||
| 2044 | xs_json_dump(q_item, 4, f); | ||
| 2045 | fclose(f); | ||
| 2046 | } | ||
| 2047 | |||
| 2048 | xs *users = user_list(); | ||
| 2049 | xs_list *p = users; | ||
| 2050 | char *v; | ||
| 2051 | |||
| 2052 | while (xs_list_iter(&p, &v)) { | ||
| 2053 | snac user; | ||
| 2054 | |||
| 2055 | if (user_open(&user, v)) { | ||
| 2056 | xs *fn = xs_fmt("%s/queue/%s.json", user.basedir, ntid); | ||
| 2057 | |||
| 2058 | srv_debug(1, xs_fmt("enqueue_input (from shared inbox) %s", fn)); | ||
| 2059 | |||
| 2060 | if (link(tmpfn, fn) < 0) | ||
| 2061 | srv_log(xs_fmt("link(%s, %s) error", tmpfn, fn)); | ||
| 2062 | |||
| 2063 | user_free(&user); | ||
| 2064 | } | ||
| 2065 | } | ||
| 2066 | |||
| 2067 | unlink(tmpfn); | ||
| 2068 | } | ||
| 2069 | else | ||
| 2028 | srv_log(xs_fmt("unexpected q_item type '%s'", type)); | 2070 | srv_log(xs_fmt("unexpected q_item type '%s'", type)); |
| 2029 | } | 2071 | } |
| 2030 | 2072 | ||
| @@ -2197,6 +2239,11 @@ int activitypub_post_handler(const xs_dict *req, const char *q_path, | |||
| 2197 | /* get the user and path */ | 2239 | /* get the user and path */ |
| 2198 | xs *l = xs_split_n(q_path, "/", 2); | 2240 | xs *l = xs_split_n(q_path, "/", 2); |
| 2199 | 2241 | ||
| 2242 | if (xs_list_len(l) == 2 && strcmp(xs_list_get(l, 1), "shared-inbox") == 0) { | ||
| 2243 | enqueue_shared_input(msg, req, 0); | ||
| 2244 | return 202; | ||
| 2245 | } | ||
| 2246 | |||
| 2200 | if (xs_list_len(l) != 3 || strcmp(xs_list_get(l, 2), "inbox") != 0) { | 2247 | if (xs_list_len(l) != 3 || strcmp(xs_list_get(l, 2), "inbox") != 0) { |
| 2201 | /* strange q_path */ | 2248 | /* strange q_path */ |
| 2202 | srv_debug(1, xs_fmt("activitypub_post_handler unsupported path %s", q_path)); | 2249 | srv_debug(1, xs_fmt("activitypub_post_handler unsupported path %s", q_path)); |
| @@ -99,6 +99,9 @@ int srv_open(char *basedir, int auto_upgrade) | |||
| 99 | xs *ibdir = xs_fmt("%s/inbox", srv_basedir); | 99 | xs *ibdir = xs_fmt("%s/inbox", srv_basedir); |
| 100 | mkdirx(ibdir); | 100 | mkdirx(ibdir); |
| 101 | 101 | ||
| 102 | xs *tmpdir = xs_fmt("%s/tmp", srv_basedir); | ||
| 103 | mkdirx(tmpdir); | ||
| 104 | |||
| 102 | #ifdef __OpenBSD__ | 105 | #ifdef __OpenBSD__ |
| 103 | char *v = xs_dict_get(srv_config, "disable_openbsd_security"); | 106 | char *v = xs_dict_get(srv_config, "disable_openbsd_security"); |
| 104 | 107 | ||
| @@ -1586,9 +1589,12 @@ void tag_index(const char *id, const xs_dict *obj) | |||
| 1586 | char *name = xs_dict_get(v, "name"); | 1589 | char *name = xs_dict_get(v, "name"); |
| 1587 | 1590 | ||
| 1588 | if (!xs_is_null(type) && !xs_is_null(name) && strcmp(type, "Hashtag") == 0) { | 1591 | if (!xs_is_null(type) && !xs_is_null(name) && strcmp(type, "Hashtag") == 0) { |
| 1589 | if (*name == '#') | 1592 | while (*name == '#' || *name == '@') |
| 1590 | name++; | 1593 | name++; |
| 1591 | 1594 | ||
| 1595 | if (*name == '\0') | ||
| 1596 | continue; | ||
| 1597 | |||
| 1592 | name = xs_tolower_i(name); | 1598 | name = xs_tolower_i(name); |
| 1593 | 1599 | ||
| 1594 | xs *md5_tag = xs_md5_hex(name, strlen(name)); | 1600 | xs *md5_tag = xs_md5_hex(name, strlen(name)); |
| @@ -2123,6 +2129,21 @@ void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retri | |||
| 2123 | } | 2129 | } |
| 2124 | 2130 | ||
| 2125 | 2131 | ||
| 2132 | void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries) | ||
| 2133 | /* enqueues an input message from the shared input */ | ||
| 2134 | { | ||
| 2135 | xs *qmsg = _new_qmsg("input", msg, retries); | ||
| 2136 | char *ntid = xs_dict_get(qmsg, "ntid"); | ||
| 2137 | xs *fn = xs_fmt("%s/queue/%s.json", srv_basedir, ntid); | ||
| 2138 | |||
| 2139 | qmsg = xs_dict_append(qmsg, "req", req); | ||
| 2140 | |||
| 2141 | qmsg = _enqueue_put(fn, qmsg); | ||
| 2142 | |||
| 2143 | srv_debug(1, xs_fmt("enqueue_shared_input %s", fn)); | ||
| 2144 | } | ||
| 2145 | |||
| 2146 | |||
| 2126 | void enqueue_output_raw(const char *keyid, const char *seckey, | 2147 | void enqueue_output_raw(const char *keyid, const char *seckey, |
| 2127 | xs_dict *msg, xs_str *inbox, int retries, int p_status) | 2148 | xs_dict *msg, xs_str *inbox, int retries, int p_status) |
| 2128 | /* enqueues an output message to an inbox */ | 2149 | /* enqueues an output message to an inbox */ |
| @@ -181,6 +181,7 @@ int instance_block(const char *instance); | |||
| 181 | int instance_unblock(const char *instance); | 181 | int instance_unblock(const char *instance); |
| 182 | 182 | ||
| 183 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); | 183 | void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); |
| 184 | void enqueue_shared_input(const xs_dict *msg, const xs_dict *req, int retries); | ||
| 184 | void enqueue_output_raw(const char *keyid, const char *seckey, | 185 | void enqueue_output_raw(const char *keyid, const char *seckey, |
| 185 | xs_dict *msg, xs_str *inbox, int retries, int p_status); | 186 | xs_dict *msg, xs_str *inbox, int retries, int p_status); |
| 186 | void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries, int p_status); | 187 | void enqueue_output(snac *snac, xs_dict *msg, xs_str *inbox, int retries, int p_status); |