diff options
| author | 2022-09-24 10:03:27 +0200 | |
|---|---|---|
| committer | 2022-09-24 10:03:27 +0200 | |
| commit | a6712ba79a617e4481117fe486858d62977f0260 (patch) | |
| tree | d975efbf9ddacd7a7aa6cf77514b0048a74ab764 | |
| parent | More ActivityPub work. (diff) | |
| download | snac2-a6712ba79a617e4481117fe486858d62977f0260.tar.gz snac2-a6712ba79a617e4481117fe486858d62977f0260.tar.xz snac2-a6712ba79a617e4481117fe486858d62977f0260.zip | |
Also store the req object in enqueue_input().
| -rw-r--r-- | activitypub.c | 10 | ||||
| -rw-r--r-- | data.c | 9 | ||||
| -rw-r--r-- | snac.h | 4 |
3 files changed, 12 insertions, 11 deletions
diff --git a/activitypub.c b/activitypub.c index 8ee7b3d..7701ecf 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -122,6 +122,9 @@ void process_message(snac *snac, char *msg) | |||
| 122 | char *actor = xs_dict_get(msg, "actor"); | 122 | char *actor = xs_dict_get(msg, "actor"); |
| 123 | char *type = xs_dict_get(msg, "type"); | 123 | char *type = xs_dict_get(msg, "type"); |
| 124 | 124 | ||
| 125 | /* check the signature */ | ||
| 126 | /* ... */ | ||
| 127 | |||
| 125 | if (strcmp(type, "Follow") == 0) { | 128 | if (strcmp(type, "Follow") == 0) { |
| 126 | } | 129 | } |
| 127 | else | 130 | else |
| @@ -179,7 +182,7 @@ void process_queue(snac *snac) | |||
| 179 | snac_log(snac, xs_fmt("process_queue giving up %s %d", actor, status)); | 182 | snac_log(snac, xs_fmt("process_queue giving up %s %d", actor, status)); |
| 180 | else { | 183 | else { |
| 181 | /* reenqueue */ | 184 | /* reenqueue */ |
| 182 | enqueue_output(snac, actor, msg, retries + 1); | 185 | enqueue_output(snac, msg, actor, retries + 1); |
| 183 | snac_log(snac, xs_fmt("process_queue requeue %s %d", actor, retries + 1)); | 186 | snac_log(snac, xs_fmt("process_queue requeue %s %d", actor, retries + 1)); |
| 184 | } | 187 | } |
| 185 | } | 188 | } |
| @@ -292,14 +295,11 @@ int activitypub_post_handler(d_char *req, char *q_path, | |||
| 292 | return 404; | 295 | return 404; |
| 293 | } | 296 | } |
| 294 | 297 | ||
| 295 | /* signature checking should happen here */ | ||
| 296 | /* ... */ | ||
| 297 | |||
| 298 | /* decode */ | 298 | /* decode */ |
| 299 | xs *msg = xs_json_loads(payload); | 299 | xs *msg = xs_json_loads(payload); |
| 300 | 300 | ||
| 301 | if (msg && xs_dict_get(msg, "actor") && xs_dict_get(msg, "type")) | 301 | if (msg && xs_dict_get(msg, "actor") && xs_dict_get(msg, "type")) |
| 302 | enqueue_input(&snac, msg); | 302 | enqueue_input(&snac, msg, req); |
| 303 | else { | 303 | else { |
| 304 | srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path)); | 304 | srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path)); |
| 305 | status = 400; | 305 | status = 400; |
| @@ -709,12 +709,12 @@ int actor_get(snac *snac, char *actor, d_char **data) | |||
| 709 | } | 709 | } |
| 710 | 710 | ||
| 711 | 711 | ||
| 712 | void enqueue_input(snac *snac, char *msg) | 712 | void enqueue_input(snac *snac, char *msg, char *req) |
| 713 | /* enqueues an input message */ | 713 | /* enqueues an input message */ |
| 714 | { | 714 | { |
| 715 | xs *ntid = tid(0); | 715 | xs *ntid = tid(0); |
| 716 | xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); | 716 | xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); |
| 717 | xs *tfn = xs_str_cat(fn, ".tmp"); | 717 | xs *tfn = xs_fmt("%s.tmp", fn); |
| 718 | FILE *f; | 718 | FILE *f; |
| 719 | 719 | ||
| 720 | if ((f = fopen(tfn, "w")) != NULL) { | 720 | if ((f = fopen(tfn, "w")) != NULL) { |
| @@ -723,6 +723,7 @@ void enqueue_input(snac *snac, char *msg) | |||
| 723 | 723 | ||
| 724 | qmsg = xs_dict_append(qmsg, "type", "input"); | 724 | qmsg = xs_dict_append(qmsg, "type", "input"); |
| 725 | qmsg = xs_dict_append(qmsg, "object", msg); | 725 | qmsg = xs_dict_append(qmsg, "object", msg); |
| 726 | qmsg = xs_dict_append(qmsg, "req", req); | ||
| 726 | 727 | ||
| 727 | j = xs_json_dumps_pp(qmsg, 4); | 728 | j = xs_json_dumps_pp(qmsg, 4); |
| 728 | 729 | ||
| @@ -736,7 +737,7 @@ void enqueue_input(snac *snac, char *msg) | |||
| 736 | } | 737 | } |
| 737 | 738 | ||
| 738 | 739 | ||
| 739 | void enqueue_output(snac *snac, char *actor, char *msg, int retries) | 740 | void enqueue_output(snac *snac, char *msg, char *actor, int retries) |
| 740 | /* enqueues an output message for an actor */ | 741 | /* enqueues an output message for an actor */ |
| 741 | { | 742 | { |
| 742 | if (strcmp(actor, snac->actor) == 0) { | 743 | if (strcmp(actor, snac->actor) == 0) { |
| @@ -747,7 +748,7 @@ void enqueue_output(snac *snac, char *actor, char *msg, int retries) | |||
| 747 | int qrt = xs_number_get(xs_dict_get(srv_config, "query_retry_minutes")); | 748 | int qrt = xs_number_get(xs_dict_get(srv_config, "query_retry_minutes")); |
| 748 | xs *ntid = tid(retries * 60 * qrt); | 749 | xs *ntid = tid(retries * 60 * qrt); |
| 749 | xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); | 750 | xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); |
| 750 | xs *tfn = xs_str_cat(fn, ".tmp"); | 751 | xs *tfn = xs_fmt("%s.tmp", fn); |
| 751 | FILE *f; | 752 | FILE *f; |
| 752 | 753 | ||
| 753 | if ((f = fopen(tfn, "w")) != NULL) { | 754 | if ((f = fopen(tfn, "w")) != NULL) { |
| @@ -64,8 +64,8 @@ int is_muted(snac *snac, char *actor); | |||
| 64 | int actor_add(snac *snac, char *actor, char *msg); | 64 | int actor_add(snac *snac, char *actor, char *msg); |
| 65 | int actor_get(snac *snac, char *actor, d_char **data); | 65 | int actor_get(snac *snac, char *actor, d_char **data); |
| 66 | 66 | ||
| 67 | void enqueue_input(snac *snac, char *msg); | 67 | void enqueue_input(snac *snac, char *msg, char *req); |
| 68 | void enqueue_output(snac *snac, char *actor, char *msg, int retries); | 68 | void enqueue_output(snac *snac, char *msg, char *actor, int retries); |
| 69 | 69 | ||
| 70 | d_char *queue(snac *snac); | 70 | d_char *queue(snac *snac); |
| 71 | d_char *dequeue(snac *snac, char *fn); | 71 | d_char *dequeue(snac *snac, char *fn); |