diff options
Diffstat (limited to '')
| -rw-r--r-- | activitypub.c | 24 | ||||
| -rw-r--r-- | httpd.c | 5 |
2 files changed, 13 insertions, 16 deletions
diff --git a/activitypub.c b/activitypub.c index cede02c..976222a 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -156,6 +156,7 @@ d_char *msg_collection(snac *snac, char *id) | |||
| 156 | 156 | ||
| 157 | 157 | ||
| 158 | d_char *msg_update(snac *snac, char *object) | 158 | d_char *msg_update(snac *snac, char *object) |
| 159 | /* creates an Update message */ | ||
| 159 | { | 160 | { |
| 160 | xs *id = xs_fmt("%s/Update", xs_dict_get(object, "id")); | 161 | xs *id = xs_fmt("%s/Update", xs_dict_get(object, "id")); |
| 161 | d_char *msg = msg_base(snac, "Update", id, snac->actor, ""); | 162 | d_char *msg = msg_base(snac, "Update", id, snac->actor, ""); |
| @@ -331,31 +332,32 @@ int activitypub_post_handler(d_char *req, char *q_path, | |||
| 331 | xs_str_in(i_ctype, "application/ld+json") == -1) | 332 | xs_str_in(i_ctype, "application/ld+json") == -1) |
| 332 | return 0; | 333 | return 0; |
| 333 | 334 | ||
| 335 | /* decode the message */ | ||
| 336 | xs *msg = xs_json_loads(payload); | ||
| 337 | |||
| 338 | if (msg == NULL) { | ||
| 339 | srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path)); | ||
| 340 | status = 400; | ||
| 341 | } | ||
| 342 | |||
| 343 | /* get the user and path */ | ||
| 334 | xs *l = xs_split_n(q_path, "/", 2); | 344 | xs *l = xs_split_n(q_path, "/", 2); |
| 335 | char *uid; | 345 | char *uid; |
| 336 | 346 | ||
| 337 | if (xs_list_len(l) != 3 || strcmp(xs_list_get(l, 2), "inbox") != 0) { | 347 | if (xs_list_len(l) != 3 || strcmp(xs_list_get(l, 2), "inbox") != 0) { |
| 338 | /* strange q_path */ | 348 | /* strange q_path */ |
| 339 | srv_log(xs_fmt("activitypub_post_handler unsupported path %s", q_path)); | 349 | srv_debug(1, xs_fmt("activitypub_post_handler unsupported path %s", q_path)); |
| 340 | return 404; | 350 | return 404; |
| 341 | } | 351 | } |
| 342 | 352 | ||
| 343 | uid = xs_list_get(l, 1); | 353 | uid = xs_list_get(l, 1); |
| 344 | if (!user_open(&snac, uid)) { | 354 | if (!user_open(&snac, uid)) { |
| 345 | /* invalid user */ | 355 | /* invalid user */ |
| 346 | srv_log(xs_fmt("activitypub_post_handler bad user %s", uid)); | 356 | srv_debug(1, xs_fmt("activitypub_post_handler bad user %s", uid)); |
| 347 | return 404; | 357 | return 404; |
| 348 | } | 358 | } |
| 349 | 359 | ||
| 350 | /* decode */ | 360 | enqueue_input(&snac, msg, req); |
| 351 | xs *msg = xs_json_loads(payload); | ||
| 352 | |||
| 353 | if (msg && xs_dict_get(msg, "actor") && xs_dict_get(msg, "type")) | ||
| 354 | enqueue_input(&snac, msg, req); | ||
| 355 | else { | ||
| 356 | srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path)); | ||
| 357 | status = 400; | ||
| 358 | } | ||
| 359 | 361 | ||
| 360 | user_free(&snac); | 362 | user_free(&snac); |
| 361 | 363 | ||
| @@ -106,11 +106,6 @@ void httpd_connection(int rs) | |||
| 106 | 106 | ||
| 107 | req = xs_httpd_request(f, &payload, &p_size); | 107 | req = xs_httpd_request(f, &payload, &p_size); |
| 108 | 108 | ||
| 109 | { | ||
| 110 | xs *j = xs_json_dumps_pp(req, 4); | ||
| 111 | printf("%s\n", j); | ||
| 112 | } | ||
| 113 | |||
| 114 | req_hdrs = xs_dict_get(req, "headers"); | 109 | req_hdrs = xs_dict_get(req, "headers"); |
| 115 | 110 | ||
| 116 | method = xs_dict_get(req_hdrs, "method"); | 111 | method = xs_dict_get(req_hdrs, "method"); |