summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c
index bdee395..4a7c247 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -165,6 +165,9 @@ int activitypub_get_handler(d_char *req, char *q_path,
165 snac snac; 165 snac snac;
166 xs *msg = xs_dict_new(); 166 xs *msg = xs_dict_new();
167 167
168 if (accept == NULL)
169 return 400;
170
168 if (xs_str_in(accept, "application/activity+json") == -1 && 171 if (xs_str_in(accept, "application/activity+json") == -1 &&
169 xs_str_in(accept, "application/ld+json") == -1) 172 xs_str_in(accept, "application/ld+json") == -1)
170 return 0; 173 return 0;
@@ -222,11 +225,14 @@ int activitypub_post_handler(d_char *req, char *q_path,
222 char **body, int *b_size, char **ctype) 225 char **body, int *b_size, char **ctype)
223/* processes an input message */ 226/* processes an input message */
224{ 227{
225 int status = 200; 228 int status = 202; /* accepted */
226 char *headers = xs_dict_get(req, "headers"); 229 char *headers = xs_dict_get(req, "headers");
227 char *i_ctype = xs_dict_get(headers, "content-type"); 230 char *i_ctype = xs_dict_get(headers, "content-type");
228 snac snac; 231 snac snac;
229 232
233 if (i_ctype == NULL)
234 return 400;
235
230 if (xs_str_in(i_ctype, "application/activity+json") == -1 && 236 if (xs_str_in(i_ctype, "application/activity+json") == -1 &&
231 xs_str_in(i_ctype, "application/ld+json") == -1) 237 xs_str_in(i_ctype, "application/ld+json") == -1)
232 return 0; 238 return 0;
@@ -247,6 +253,16 @@ int activitypub_post_handler(d_char *req, char *q_path,
247 return 404; 253 return 404;
248 } 254 }
249 255
256 /* decode */
257 xs *msg = xs_json_loads(payload);
258
259 if (msg && xs_dict_get(msg, "actor") && xs_dict_get(msg, "type"))
260 enqueue_input(&snac, msg);
261 else {
262 srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path));
263 status = 400;
264 }
265
250 user_free(&snac); 266 user_free(&snac);
251 267
252 return status; 268 return status;