diff options
| -rw-r--r-- | activitypub.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/activitypub.c b/activitypub.c index 82230ff..44b5ba2 100644 --- 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 | |||
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | 135 | ||
| 136 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size) | 136 | d_char *get_actor_inbox(snac *snac, char *actor) |
| 137 | /* sends a message to an actor */ | 137 | /* gets an actor's inbox */ |
| 138 | { | 138 | { |
| 139 | int status; | ||
| 140 | xs *data = NULL; | 139 | xs *data = NULL; |
| 140 | char *v = NULL; | ||
| 141 | 141 | ||
| 142 | /* resolve the actor first */ | 142 | if (valid_status(actor_request(snac, actor, &data))) { |
| 143 | status = actor_request(snac, actor, &data); | 143 | /* try first endpoints/sharedInbox */ |
| 144 | 144 | if ((v = xs_dict_get(data, "endpoints"))) | |
| 145 | if (valid_status(status)) { | 145 | v = xs_dict_get(v, "sharedInbox"); |
| 146 | char *inbox = xs_dict_get(data, "inbox"); | ||
| 147 | 146 | ||
| 148 | if (inbox != NULL) | 147 | /* try then the regular inbox */ |
| 149 | status = send_to_inbox(snac, inbox, msg, payload, p_size); | 148 | if (xs_is_null(v)) |
| 150 | else | 149 | v = xs_dict_get(data, "inbox"); |
| 151 | status = 400; | ||
| 152 | } | 150 | } |
| 153 | 151 | ||
| 152 | return xs_is_null(v) ? NULL : xs_dup(v); | ||
| 153 | } | ||
| 154 | |||
| 155 | |||
| 156 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size) | ||
| 157 | /* sends a message to an actor */ | ||
| 158 | { | ||
| 159 | int status = 400; | ||
| 160 | xs *inbox = get_actor_inbox(snac, actor); | ||
| 161 | |||
| 162 | if (!xs_is_null(inbox)) | ||
| 163 | status = send_to_inbox(snac, inbox, msg, payload, p_size); | ||
| 164 | |||
| 154 | snac_log(snac, xs_fmt("send_to_actor %s %d", actor, status)); | 165 | snac_log(snac, xs_fmt("send_to_actor %s %d", actor, status)); |
| 155 | 166 | ||
| 156 | return status; | 167 | return status; |