diff options
| author | 2022-09-26 11:19:45 +0200 | |
|---|---|---|
| committer | 2022-09-26 11:19:45 +0200 | |
| commit | fd6f71bfe36331d046e4183c2c133c6f01c9af2d (patch) | |
| tree | 2523108550567f4f20d0b3e3d8ec703f09a05c4d | |
| parent | New function msg_admiration(). (diff) | |
| download | penes-snac2-fd6f71bfe36331d046e4183c2c133c6f01c9af2d.tar.gz penes-snac2-fd6f71bfe36331d046e4183c2c133c6f01c9af2d.tar.xz penes-snac2-fd6f71bfe36331d046e4183c2c133c6f01c9af2d.zip | |
More work but signatures seem to still fail.
| -rw-r--r-- | activitypub.c | 35 | ||||
| -rw-r--r-- | data.c | 6 | ||||
| -rw-r--r-- | httpd.c | 2 | ||||
| -rw-r--r-- | main.c | 4 | ||||
| -rw-r--r-- | snac.c | 12 | ||||
| -rw-r--r-- | snac.h | 1 |
6 files changed, 41 insertions, 19 deletions
diff --git a/activitypub.c b/activitypub.c index 091e4bf..2e11a82 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -194,18 +194,27 @@ d_char *msg_update(snac *snac, char *object) | |||
| 194 | d_char *msg_admiration(snac *snac, char *object, char *type) | 194 | d_char *msg_admiration(snac *snac, char *object, char *type) |
| 195 | /* creates a Like or Announce message */ | 195 | /* creates a Like or Announce message */ |
| 196 | { | 196 | { |
| 197 | xs *ntid = tid(0); | 197 | xs *a_msg = NULL; |
| 198 | xs *id = xs_fmt("%s/d/%d/%s", snac->actor, ntid, type); | 198 | d_char *msg = NULL; |
| 199 | d_char *msg = msg_base(snac, type, id, snac->actor, ""); | ||
| 200 | xs *rcpts = xs_list_new(); | ||
| 201 | 199 | ||
| 202 | /* call the object */ | 200 | /* call the object */ |
| 203 | timeline_request(snac, object, snac->actor); | 201 | timeline_request(snac, object, snac->actor); |
| 204 | 202 | ||
| 205 | rcpts = xs_list_append(rcpts, public_address); | 203 | if ((a_msg = timeline_find(snac, object)) != NULL) { |
| 204 | xs *ntid = tid(0); | ||
| 205 | xs *id = xs_fmt("%s/d/%d/%s", snac->actor, ntid, type); | ||
| 206 | xs *rcpts = xs_list_new(); | ||
| 206 | 207 | ||
| 207 | msg = xs_dict_append(msg, "to", rcpts); | 208 | msg = msg_base(snac, type, id, snac->actor, ""); |
| 208 | msg = xs_dict_append(msg, "object", object); | 209 | |
| 210 | rcpts = xs_list_append(rcpts, public_address); | ||
| 211 | rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); | ||
| 212 | |||
| 213 | msg = xs_dict_append(msg, "to", rcpts); | ||
| 214 | msg = xs_dict_append(msg, "object", object); | ||
| 215 | } | ||
| 216 | else | ||
| 217 | snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object)); | ||
| 209 | 218 | ||
| 210 | return msg; | 219 | return msg; |
| 211 | } | 220 | } |
| @@ -372,9 +381,11 @@ void process_queue(snac *snac) | |||
| 372 | char *actor = xs_dict_get(q_item, "actor"); | 381 | char *actor = xs_dict_get(q_item, "actor"); |
| 373 | char *msg = xs_dict_get(q_item, "object"); | 382 | char *msg = xs_dict_get(q_item, "object"); |
| 374 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); | 383 | int retries = xs_number_get(xs_dict_get(q_item, "retries")); |
| 384 | xs *payload = NULL; | ||
| 385 | int p_size = 0; | ||
| 375 | 386 | ||
| 376 | /* deliver */ | 387 | /* deliver */ |
| 377 | status = send_to_actor(snac, actor, msg, NULL, 0); | 388 | status = send_to_actor(snac, actor, msg, &payload, &p_size); |
| 378 | 389 | ||
| 379 | if (!valid_status(status)) { | 390 | if (!valid_status(status)) { |
| 380 | /* error sending; reenqueue? */ | 391 | /* error sending; reenqueue? */ |
| @@ -420,12 +431,14 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public) | |||
| 420 | 431 | ||
| 421 | char *p = fwers; | 432 | char *p = fwers; |
| 422 | while (xs_list_iter(&p, &fw)) { | 433 | while (xs_list_iter(&p, &fw)) { |
| 423 | if (!xs_list_in(list, fw)) | 434 | char *actor = xs_dict_get(fw, "actor"); |
| 424 | list = xs_list_append(list, fw); | 435 | |
| 436 | if (xs_list_in(list, actor) == -1) | ||
| 437 | list = xs_list_append(list, actor); | ||
| 425 | } | 438 | } |
| 426 | } | 439 | } |
| 427 | else | 440 | else |
| 428 | if (!xs_list_in(list, v)) | 441 | if (xs_list_in(list, v) == -1) |
| 429 | list = xs_list_append(list, v); | 442 | list = xs_list_append(list, v); |
| 430 | } | 443 | } |
| 431 | } | 444 | } |
| @@ -302,8 +302,8 @@ int timeline_here(snac *snac, char *id) | |||
| 302 | d_char *timeline_find(snac *snac, char *id) | 302 | d_char *timeline_find(snac *snac, char *id) |
| 303 | /* gets a message from the timeline by id */ | 303 | /* gets a message from the timeline by id */ |
| 304 | { | 304 | { |
| 305 | xs *fn = _timeline_find_fn(snac, id); | 305 | xs *fn = _timeline_find_fn(snac, id); |
| 306 | xs *msg = NULL; | 306 | d_char *msg = NULL; |
| 307 | 307 | ||
| 308 | if (fn != NULL) { | 308 | if (fn != NULL) { |
| 309 | FILE *f; | 309 | FILE *f; |
| @@ -820,7 +820,7 @@ void enqueue_output(snac *snac, char *msg, char *actor, int retries) | |||
| 820 | return; | 820 | return; |
| 821 | } | 821 | } |
| 822 | 822 | ||
| 823 | int qrt = xs_number_get(xs_dict_get(srv_config, "query_retry_minutes")); | 823 | int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes")); |
| 824 | xs *ntid = tid(retries * 60 * qrt); | 824 | xs *ntid = tid(retries * 60 * qrt); |
| 825 | xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); | 825 | xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid); |
| 826 | xs *tfn = xs_fmt("%s.tmp", fn); | 826 | xs *tfn = xs_fmt("%s.tmp", fn); |
| @@ -97,7 +97,7 @@ void httpd_connection(int rs) | |||
| 97 | xs *headers = NULL; | 97 | xs *headers = NULL; |
| 98 | xs *q_path = NULL; | 98 | xs *q_path = NULL; |
| 99 | xs *payload = NULL; | 99 | xs *payload = NULL; |
| 100 | int p_size; | 100 | int p_size = 0; |
| 101 | char *p; | 101 | char *p; |
| 102 | 102 | ||
| 103 | f = xs_socket_accept(rs); | 103 | f = xs_socket_accept(rs); |
| @@ -119,7 +119,9 @@ int main(int argc, char *argv[]) | |||
| 119 | if (strcmp(cmd, "announce") == 0) { | 119 | if (strcmp(cmd, "announce") == 0) { |
| 120 | xs *msg = msg_admiration(&snac, url, "Announce"); | 120 | xs *msg = msg_admiration(&snac, url, "Announce"); |
| 121 | 121 | ||
| 122 | { | 122 | if (msg != NULL) { |
| 123 | post(&snac, msg); | ||
| 124 | |||
| 123 | xs *j = xs_json_dumps_pp(msg, 4); | 125 | xs *j = xs_json_dumps_pp(msg, 4); |
| 124 | printf("%s\n", j); | 126 | printf("%s\n", j); |
| 125 | } | 127 | } |
| @@ -142,7 +142,7 @@ void srv_archive(char *direction, char *req, char *payload, int p_size, | |||
| 142 | /* archives a connection */ | 142 | /* archives a connection */ |
| 143 | { | 143 | { |
| 144 | /* obsessive archiving */ | 144 | /* obsessive archiving */ |
| 145 | xs *date = xs_local_time("%Y%m%d%H%M%S"); | 145 | xs *date = tid(0); |
| 146 | xs *dir = xs_fmt("%s/archive/%s", srv_basedir, date); | 146 | xs *dir = xs_fmt("%s/archive/%s", srv_basedir, date); |
| 147 | FILE *f; | 147 | FILE *f; |
| 148 | 148 | ||
| @@ -172,7 +172,10 @@ void srv_archive(char *direction, char *req, char *payload, int p_size, | |||
| 172 | 172 | ||
| 173 | if ((f = fopen(payload_fn, "w")) != NULL) { | 173 | if ((f = fopen(payload_fn, "w")) != NULL) { |
| 174 | xs *v1 = xs_json_loads(payload); | 174 | xs *v1 = xs_json_loads(payload); |
| 175 | xs *j1 = xs_json_dumps_pp(v1, 4); | 175 | xs *j1 = NULL; |
| 176 | |||
| 177 | if (v1 != NULL) | ||
| 178 | j1 = xs_json_dumps_pp(v1, 4); | ||
| 176 | 179 | ||
| 177 | if (j1 != NULL) | 180 | if (j1 != NULL) |
| 178 | fwrite(j1, strlen(j1), 1, f); | 181 | fwrite(j1, strlen(j1), 1, f); |
| @@ -200,7 +203,10 @@ void srv_archive(char *direction, char *req, char *payload, int p_size, | |||
| 200 | 203 | ||
| 201 | if ((f = fopen(body_fn, "w")) != NULL) { | 204 | if ((f = fopen(body_fn, "w")) != NULL) { |
| 202 | xs *v1 = xs_json_loads(body); | 205 | xs *v1 = xs_json_loads(body); |
| 203 | xs *j1 = xs_json_dumps_pp(v1, 4); | 206 | xs *j1 = NULL; |
| 207 | |||
| 208 | if (v1 != NULL) | ||
| 209 | j1 = xs_json_dumps_pp(v1, 4); | ||
| 204 | 210 | ||
| 205 | if (j1 != NULL) | 211 | if (j1 != NULL) |
| 206 | fwrite(j1, strlen(j1), 1, f); | 212 | fwrite(j1, strlen(j1), 1, f); |
| @@ -94,6 +94,7 @@ int actor_request(snac *snac, char *actor, d_char **data); | |||
| 94 | int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size); | 94 | int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size); |
| 95 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size); | 95 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size); |
| 96 | void process_queue(snac *snac); | 96 | void process_queue(snac *snac); |
| 97 | void post(snac *snac, char *msg); | ||
| 97 | int activitypub_get_handler(d_char *req, char *q_path, | 98 | int activitypub_get_handler(d_char *req, char *q_path, |
| 98 | char **body, int *b_size, char **ctype); | 99 | char **body, int *b_size, char **ctype); |
| 99 | int activitypub_post_handler(d_char *req, char *q_path, | 100 | int activitypub_post_handler(d_char *req, char *q_path, |