From 5e3c50d6e1ea2105add614fa2eb45612e577ddac Mon Sep 17 00:00:00 2001 From: default Date: Thu, 2 Mar 2023 08:43:50 +0100 Subject: [PATCH] New inbox collection functions. --- activitypub.c | 18 ++---------------- data.c | 34 ++++++++++++++++++++++++++++++++++ snac.h | 3 +++ utils.c | 3 +++ 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/activitypub.c b/activitypub.c index a259a25..663fa24 100644 --- a/activitypub.c +++ b/activitypub.c @@ -117,22 +117,8 @@ int actor_request(snac *snac, char *actor, d_char **data) } } -#if 0 - if (valid_status(status) && data && *data) { - xs *fn = xs_fmt("%s/inboxes.lst", srv_basedir); - FILE *f; - - if ((f = fopen(fn, "a")) != NULL) { - char *v; - if (!xs_is_null(v = xs_dict_get(*data, "endpoints")) && - !xs_is_null(v = xs_dict_get(v, "sharedInbox"))) { - fprintf(f, "%s\n", v); - } - - fclose(f); - } - } -#endif + if (valid_status(status) && data && *data) + inbox_add_by_actor(*data); return status; } diff --git a/data.c b/data.c index 8934f31..208c057 100644 --- a/data.c +++ b/data.c @@ -96,6 +96,9 @@ int srv_open(char *basedir, int auto_upgrade) xs *qdir = xs_fmt("%s/queue", srv_basedir); mkdirx(qdir); + xs *ibdir = xs_fmt("%s/inboxes", srv_basedir); + mkdirx(ibdir); + #ifdef __OpenBSD__ char *v = xs_dict_get(srv_config, "disable_openbsd_security"); @@ -1363,6 +1366,37 @@ d_char *history_list(snac *snac) } +/** inbox collection **/ + +void inbox_add(const char *inbox) +/* collects a shared inbox */ +{ + xs *md5 = xs_md5_hex(inbox, strlen(inbox)); + xs *fn = xs_fmt("%s/inboxes/%s", srv_basedir, md5); + FILE *f; + + if ((f = fopen(fn, "w")) != NULL) { + pthread_mutex_lock(&data_mutex); + + fprintf(f, "%s\n", inbox); + fclose(f); + + pthread_mutex_unlock(&data_mutex); + } +} + + +void inbox_add_by_actor(const xs_dict *actor) +/* collects an actor's shared inbox, if it has one */ +{ + char *v; + + if (!xs_is_null(v = xs_dict_get(actor, "endpoints")) && + !xs_is_null(v = xs_dict_get(v, "sharedInbox"))) + inbox_add(v); +} + + /** the queue **/ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) diff --git a/snac.h b/snac.h index bc929df..9cca864 100644 --- a/snac.h +++ b/snac.h @@ -132,6 +132,9 @@ d_char *history_get(snac *snac, char *id); int history_del(snac *snac, char *id); d_char *history_list(snac *snac); +void inbox_add(const char *inbox); +void inbox_add_by_actor(const xs_dict *actor); + void enqueue_input(snac *snac, xs_dict *msg, xs_dict *req, int retries); void enqueue_output_raw(const char *keyid, const char *seckey, xs_dict *msg, xs_str *inbox, int retries); diff --git a/utils.c b/utils.c index 384fde9..cdfa2e6 100644 --- a/utils.c +++ b/utils.c @@ -157,6 +157,9 @@ int snac_init(const char *basedir) xs *qdir = xs_fmt("%s/queue", srv_basedir); mkdirx(qdir); + xs *ibdir = xs_fmt("%s/inbox", srv_basedir); + mkdirx(ibdir); + xs *gfn = xs_fmt("%s/greeting.html", srv_basedir); if ((f = fopen(gfn, "w")) == NULL) { printf("ERROR: cannot create '%s'\n", gfn);