diff options
| author | 2022-09-23 20:59:19 +0200 | |
|---|---|---|
| committer | 2022-09-23 20:59:19 +0200 | |
| commit | 6e6c3154940e21a97473154e57e851790740d550 (patch) | |
| tree | e42370734efa7b9e27477f864448bccb947048e8 /activitypub.c | |
| parent | xs_httpd_request() also returns the payload. (diff) | |
| download | snac2-6e6c3154940e21a97473154e57e851790740d550.tar.gz snac2-6e6c3154940e21a97473154e57e851790740d550.tar.xz snac2-6e6c3154940e21a97473154e57e851790740d550.zip | |
New function activitypub_get_handler().
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c index d470e10..7c302bb 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -156,13 +156,73 @@ void process_queue(snac *snac) | |||
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | 158 | ||
| 159 | int activitypub_get_handler(d_char *req, char *q_path, | ||
| 160 | char **body, int *b_size, char **ctype) | ||
| 161 | { | ||
| 162 | int status = 200; | ||
| 163 | char *headers = xs_dict_get(req, "headers"); | ||
| 164 | char *accept = xs_dict_get(headers, "accept"); | ||
| 165 | snac snac; | ||
| 166 | xs *msg = xs_dict_new(); | ||
| 167 | |||
| 168 | if (xs_str_in(accept, "application/activity+json") == -1 && | ||
| 169 | xs_str_in(accept, "application/ld+json") == -1) | ||
| 170 | return 0; | ||
| 171 | |||
| 172 | xs *l = xs_split_n(q_path, "/", 2); | ||
| 173 | char *uid, *p_path; | ||
| 174 | |||
| 175 | uid = xs_list_get(l, 1); | ||
| 176 | if (!user_open(&snac, uid)) { | ||
| 177 | /* invalid user */ | ||
| 178 | srv_log(xs_fmt("activitypub_get_handler bad user %s", uid)); | ||
| 179 | return 404; | ||
| 180 | } | ||
| 181 | |||
| 182 | p_path = xs_list_get(l, 2); | ||
| 183 | |||
| 184 | if (p_path == NULL) { | ||
| 185 | /* if there was no component after the user, it's an actor request */ | ||
| 186 | } | ||
| 187 | else | ||
| 188 | if (strcmp(p_path, "outbox") == 0) { | ||
| 189 | } | ||
| 190 | else | ||
| 191 | if (strcmp(p_path, "followers") == 0 || strcmp(p_path, "following") == 0) { | ||
| 192 | xs *id = xs_fmt("%s/%s", snac.actor, p_path); | ||
| 193 | |||
| 194 | msg = xs_dict_append(msg, "@context", "https:/" "/www.w3.org/ns/activitystreams"); | ||
| 195 | msg = xs_dict_append(msg, "attributedTo", snac.actor); | ||
| 196 | msg = xs_dict_append(msg, "id", id); | ||
| 197 | msg = xs_dict_append(msg, "orderedItems", xs_list_new()); | ||
| 198 | msg = xs_dict_append(msg, "totalItems", xs_number_new(0)); | ||
| 199 | msg = xs_dict_append(msg, "type", "OrderedCollection"); | ||
| 200 | } | ||
| 201 | else | ||
| 202 | if (xs_startswith(p_path, "p/")) { | ||
| 203 | } | ||
| 204 | else | ||
| 205 | status = 404; | ||
| 206 | |||
| 207 | if (status == 200) { | ||
| 208 | *body = xs_json_dumps_pp(msg, 4); | ||
| 209 | *b_size = strlen(*body); | ||
| 210 | } | ||
| 211 | |||
| 212 | user_free(&snac); | ||
| 213 | |||
| 214 | return status; | ||
| 215 | } | ||
| 216 | |||
| 217 | |||
| 159 | int activitypub_post_handler(d_char *req, char *q_path, | 218 | int activitypub_post_handler(d_char *req, char *q_path, |
| 160 | d_char *payload, int p_size, | 219 | d_char *payload, int p_size, |
| 161 | char **body, int *b_size, char **ctype) | 220 | char **body, int *b_size, char **ctype) |
| 162 | /* processes an input message */ | 221 | /* processes an input message */ |
| 163 | { | 222 | { |
| 164 | int status = 200; | 223 | int status = 200; |
| 165 | char *i_ctype = xs_dict_get(req, "content-type"); | 224 | char *headers = xs_dict_get(req, "headers"); |
| 225 | char *i_ctype = xs_dict_get(headers, "content-type"); | ||
| 166 | snac snac; | 226 | snac snac; |
| 167 | 227 | ||
| 168 | if (xs_str_in(i_ctype, "application/activity+json") == -1 && | 228 | if (xs_str_in(i_ctype, "application/activity+json") == -1 && |