diff options
author | default <nobody@localhost> | 2022-09-23 23:09:09 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2022-09-23 23:09:09 +0200 |
commit | c181c57f5611a477f11b8be375263ef9fed638dd (patch) | |
tree | ec475f2cd6b91f1dbc103171f75d330c8d6a7ab4 /activitypub.c | |
parent | b4a4fa0b0d02747c231367dc7a609c96171b7066 (diff) |
New function enqueue_input().
Diffstat (limited to 'activitypub.c')
-rw-r--r-- | activitypub.c | 18 |
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, snac snac; xs *msg = xs_dict_new(); + if (accept == NULL) + return 400; + if (xs_str_in(accept, "application/activity+json") == -1 && xs_str_in(accept, "application/ld+json") == -1) return 0; @@ -222,11 +225,14 @@ int activitypub_post_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype) /* processes an input message */ { - int status = 200; + int status = 202; /* accepted */ char *headers = xs_dict_get(req, "headers"); char *i_ctype = xs_dict_get(headers, "content-type"); snac snac; + if (i_ctype == NULL) + return 400; + if (xs_str_in(i_ctype, "application/activity+json") == -1 && xs_str_in(i_ctype, "application/ld+json") == -1) return 0; @@ -247,6 +253,16 @@ int activitypub_post_handler(d_char *req, char *q_path, return 404; } + /* decode */ + xs *msg = xs_json_loads(payload); + + if (msg && xs_dict_get(msg, "actor") && xs_dict_get(msg, "type")) + enqueue_input(&snac, msg); + else { + srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path)); + status = 400; + } + user_free(&snac); return status; |