diff options
| author | 2023-03-02 09:15:40 +0100 | |
|---|---|---|
| committer | 2023-03-02 09:15:40 +0100 | |
| commit | 29b12498dd511b00586446b98f11ccb1d44088eb (patch) | |
| tree | 3b7178a7770a4d99712b6b69f9848d7b71d51085 | |
| parent | Renamed inboxes/ to inbox/. (diff) | |
| download | snac2-29b12498dd511b00586446b98f11ccb1d44088eb.tar.gz snac2-29b12498dd511b00586446b98f11ccb1d44088eb.tar.xz snac2-29b12498dd511b00586446b98f11ccb1d44088eb.zip | |
Simplified is_msg_public().
| -rw-r--r-- | activitypub.c | 37 | ||||
| -rw-r--r-- | data.c | 31 | ||||
| -rw-r--r-- | snac.h | 3 |
3 files changed, 30 insertions, 41 deletions
diff --git a/activitypub.c b/activitypub.c index 498ba1f..79c20d7 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -279,46 +279,13 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public) | |||
| 279 | } | 279 | } |
| 280 | 280 | ||
| 281 | 281 | ||
| 282 | #if 0 | 282 | int is_msg_public(snac *snac, xs_dict *msg) |
| 283 | d_char *inbox_list(snac *snac, char *msg) | ||
| 284 | /* returns the list of inboxes that are recipients of this message */ | ||
| 285 | { | ||
| 286 | xs *rcpts = recipient_list(snac, msg, 1); | ||
| 287 | xs_set inboxes; | ||
| 288 | char *p, *v; | ||
| 289 | |||
| 290 | xs_set_init(&inboxes); | ||
| 291 | |||
| 292 | p = rcpts; | ||
| 293 | while (xs_list_iter(&p, &v)) { | ||
| 294 | xs *inbox; | ||
| 295 | |||
| 296 | if ((inbox = get_actor_inbox(snac, v)) != NULL) { | ||
| 297 | /* add the inbox if it's not already there */ | ||
| 298 | xs_set_add(&inboxes, inbox); | ||
| 299 | } | ||
| 300 | else | ||
| 301 | snac_log(snac, xs_fmt("cannot find inbox for %s", v)); | ||
| 302 | } | ||
| 303 | |||
| 304 | return xs_set_result(&inboxes); | ||
| 305 | } | ||
| 306 | #endif | ||
| 307 | |||
| 308 | int is_msg_public(snac *snac, char *msg) | ||
| 309 | /* checks if a message is public */ | 283 | /* checks if a message is public */ |
| 310 | { | 284 | { |
| 311 | int ret = 0; | 285 | int ret = 0; |
| 312 | xs *rcpts = recipient_list(snac, msg, 0); | 286 | xs *rcpts = recipient_list(snac, msg, 0); |
| 313 | char *p, *v; | ||
| 314 | |||
| 315 | p = rcpts; | ||
| 316 | while (!ret && xs_list_iter(&p, &v)) { | ||
| 317 | if (strcmp(v, public_address) == 0) | ||
| 318 | ret = 1; | ||
| 319 | } | ||
| 320 | 287 | ||
| 321 | return ret; | 288 | return xs_list_in(rcpts, public_address) != -1; |
| 322 | } | 289 | } |
| 323 | 290 | ||
| 324 | 291 | ||
| @@ -1375,7 +1375,7 @@ void inbox_add(const char *inbox) | |||
| 1375 | xs *fn = xs_fmt("%s/inbox/%s", srv_basedir, md5); | 1375 | xs *fn = xs_fmt("%s/inbox/%s", srv_basedir, md5); |
| 1376 | FILE *f; | 1376 | FILE *f; |
| 1377 | 1377 | ||
| 1378 | if ((f = fopen(fn, "w")) != NULL) { | 1378 | if (strlen(inbox) < 256 && (f = fopen(fn, "w")) != NULL) { |
| 1379 | pthread_mutex_lock(&data_mutex); | 1379 | pthread_mutex_lock(&data_mutex); |
| 1380 | 1380 | ||
| 1381 | fprintf(f, "%s\n", inbox); | 1381 | fprintf(f, "%s\n", inbox); |
| @@ -1397,15 +1397,36 @@ void inbox_add_by_actor(const xs_dict *actor) | |||
| 1397 | } | 1397 | } |
| 1398 | 1398 | ||
| 1399 | 1399 | ||
| 1400 | #if 0 | ||
| 1401 | xs_list *inbox_list(void) | 1400 | xs_list *inbox_list(void) |
| 1402 | /* returns the collected inboxes as a list */ | 1401 | /* returns the collected inboxes as a list */ |
| 1403 | { | 1402 | { |
| 1404 | xs_list *l = xs_list_new(); | 1403 | xs_list *ibl = xs_list_new(); |
| 1404 | xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); | ||
| 1405 | xs *files = xs_glob(spec, 0, 0); | ||
| 1406 | xs_list *p = files; | ||
| 1407 | xs_val *v; | ||
| 1408 | |||
| 1409 | while (xs_list_iter(&p, &v)) { | ||
| 1410 | FILE *f; | ||
| 1411 | |||
| 1412 | if ((f = fopen(v, "r")) != NULL) { | ||
| 1413 | char line[256]; | ||
| 1414 | |||
| 1415 | if (fgets(line, sizeof(line), f)) { | ||
| 1416 | fclose(f); | ||
| 1417 | |||
| 1418 | int i = strlen(line); | ||
| 1419 | |||
| 1420 | if (i) { | ||
| 1421 | line[i - 1] = '\0'; | ||
| 1422 | ibl = xs_list_append(ibl, line); | ||
| 1423 | } | ||
| 1424 | } | ||
| 1425 | } | ||
| 1426 | } | ||
| 1405 | 1427 | ||
| 1406 | return l; | 1428 | return ibl; |
| 1407 | } | 1429 | } |
| 1408 | #endif | ||
| 1409 | 1430 | ||
| 1410 | 1431 | ||
| 1411 | /** the queue **/ | 1432 | /** the queue **/ |
| @@ -134,6 +134,7 @@ d_char *history_list(snac *snac); | |||
| 134 | 134 | ||
| 135 | void inbox_add(const char *inbox); | 135 | void inbox_add(const char *inbox); |
| 136 | void inbox_add_by_actor(const xs_dict *actor); | 136 | void inbox_add_by_actor(const xs_dict *actor); |
| 137 | xs_list *inbox_list(void); | ||
| 137 | 138 | ||
| 138 | void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries); | 139 | void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries); |
| 139 | void enqueue_output_raw(const char *keyid, const char *seckey, | 140 | void enqueue_output_raw(const char *keyid, const char *seckey, |
| @@ -193,7 +194,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, | |||
| 193 | xs_val **payload, int *p_size, int timeout); | 194 | xs_val **payload, int *p_size, int timeout); |
| 194 | d_char *get_actor_inbox(snac *snac, char *actor); | 195 | d_char *get_actor_inbox(snac *snac, char *actor); |
| 195 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); | 196 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); |
| 196 | int is_msg_public(snac *snac, char *msg); | 197 | int is_msg_public(snac *snac, xs_dict *msg); |
| 197 | 198 | ||
| 198 | int process_user_queue(snac *snac); | 199 | int process_user_queue(snac *snac); |
| 199 | void process_queue_item(xs_dict *q_item); | 200 | void process_queue_item(xs_dict *q_item); |