diff options
| author | 2023-12-06 14:46:51 +0100 | |
|---|---|---|
| committer | 2023-12-06 14:46:51 +0100 | |
| commit | bad729c631819db04191605a237c8fa632818dd8 (patch) | |
| tree | ececcb0643dfa5020e2b155c0208808d8e4a73e9 /activitypub.c | |
| 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.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 47 |
1 files changed, 47 insertions, 0 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)); |