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) } -#if 0 -d_char *inbox_list(snac *snac, char *msg) -/* returns the list of inboxes that are recipients of this message */ -{ - xs *rcpts = recipient_list(snac, msg, 1); - xs_set inboxes; - char *p, *v; - - xs_set_init(&inboxes); - - p = rcpts; - while (xs_list_iter(&p, &v)) { - xs *inbox; - - if ((inbox = get_actor_inbox(snac, v)) != NULL) { - /* add the inbox if it's not already there */ - xs_set_add(&inboxes, inbox); - } - else - snac_log(snac, xs_fmt("cannot find inbox for %s", v)); - } - - return xs_set_result(&inboxes); -} -#endif - -int is_msg_public(snac *snac, char *msg) +int is_msg_public(snac *snac, xs_dict *msg) /* checks if a message is public */ { int ret = 0; xs *rcpts = recipient_list(snac, msg, 0); - char *p, *v; - p = rcpts; - while (!ret && xs_list_iter(&p, &v)) { - if (strcmp(v, public_address) == 0) - ret = 1; - } - - return ret; + return xs_list_in(rcpts, public_address) != -1; } diff --git a/data.c b/data.c index 1b41944..4403bf4 100644 --- a/data.c +++ b/data.c @@ -1375,7 +1375,7 @@ void inbox_add(const char *inbox) xs *fn = xs_fmt("%s/inbox/%s", srv_basedir, md5); FILE *f; - if ((f = fopen(fn, "w")) != NULL) { + if (strlen(inbox) < 256 && (f = fopen(fn, "w")) != NULL) { pthread_mutex_lock(&data_mutex); fprintf(f, "%s\n", inbox); @@ -1397,15 +1397,36 @@ void inbox_add_by_actor(const xs_dict *actor) } -#if 0 xs_list *inbox_list(void) /* returns the collected inboxes as a list */ { - xs_list *l = xs_list_new(); + xs_list *ibl = xs_list_new(); + xs *spec = xs_fmt("%s/inbox/" "*", srv_basedir); + xs *files = xs_glob(spec, 0, 0); + xs_list *p = files; + xs_val *v; - return l; + while (xs_list_iter(&p, &v)) { + FILE *f; + + if ((f = fopen(v, "r")) != NULL) { + char line[256]; + + if (fgets(line, sizeof(line), f)) { + fclose(f); + + int i = strlen(line); + + if (i) { + line[i - 1] = '\0'; + ibl = xs_list_append(ibl, line); + } + } + } + } + + return ibl; } -#endif /** the queue **/ diff --git a/snac.h b/snac.h index 9cca864..3ad8891 100644 --- a/snac.h +++ b/snac.h @@ -134,6 +134,7 @@ d_char *history_list(snac *snac); void inbox_add(const char *inbox); void inbox_add_by_actor(const xs_dict *actor); +xs_list *inbox_list(void); void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries); 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, xs_val **payload, int *p_size, int timeout); d_char *get_actor_inbox(snac *snac, char *actor); int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); -int is_msg_public(snac *snac, char *msg); +int is_msg_public(snac *snac, xs_dict *msg); int process_user_queue(snac *snac); void process_queue_item(xs_dict *q_item);