snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit afce422785cb98608b135a473f6f6c7c0c592277
parent 4304f7301cdd9e111cd3936d4129e333a7612c82
Author: default <nobody@localhost>
Date:   Thu, 17 Nov 2022 09:04:24 +0100

Use endpoints/sharedInbox instead of inbox, if there is one.

Diffstat:
Mactivitypub.c | 35+++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/activitypub.c b/activitypub.c @@ -133,24 +133,35 @@ int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_s } -int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size) -/* sends a message to an actor */ +d_char *get_actor_inbox(snac *snac, char *actor) +/* gets an actor's inbox */ { - int status; xs *data = NULL; + char *v = NULL; - /* resolve the actor first */ - status = actor_request(snac, actor, &data); - - if (valid_status(status)) { - char *inbox = xs_dict_get(data, "inbox"); + if (valid_status(actor_request(snac, actor, &data))) { + /* try first endpoints/sharedInbox */ + if ((v = xs_dict_get(data, "endpoints"))) + v = xs_dict_get(v, "sharedInbox"); - if (inbox != NULL) - status = send_to_inbox(snac, inbox, msg, payload, p_size); - else - status = 400; + /* try then the regular inbox */ + if (xs_is_null(v)) + v = xs_dict_get(data, "inbox"); } + return xs_is_null(v) ? NULL : xs_dup(v); +} + + +int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size) +/* sends a message to an actor */ +{ + int status = 400; + xs *inbox = get_actor_inbox(snac, actor); + + if (!xs_is_null(inbox)) + status = send_to_inbox(snac, inbox, msg, payload, p_size); + snac_log(snac, xs_fmt("send_to_actor %s %d", actor, status)); return status;