commit afce422
default
·
2022-11-17 08:04:24 +0000 UTC
parent 4304f73
Use endpoints/sharedInbox instead of inbox, if there is one.
1 files changed,
+23,
-12
+23,
-12
1@@ -133,24 +133,35 @@ int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_s
2 }
3
4
5-int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size)
6-/* sends a message to an actor */
7+d_char *get_actor_inbox(snac *snac, char *actor)
8+/* gets an actor's inbox */
9 {
10- int status;
11 xs *data = NULL;
12+ char *v = NULL;
13
14- /* resolve the actor first */
15- status = actor_request(snac, actor, &data);
16-
17- if (valid_status(status)) {
18- char *inbox = xs_dict_get(data, "inbox");
19+ if (valid_status(actor_request(snac, actor, &data))) {
20+ /* try first endpoints/sharedInbox */
21+ if ((v = xs_dict_get(data, "endpoints")))
22+ v = xs_dict_get(v, "sharedInbox");
23
24- if (inbox != NULL)
25- status = send_to_inbox(snac, inbox, msg, payload, p_size);
26- else
27- status = 400;
28+ /* try then the regular inbox */
29+ if (xs_is_null(v))
30+ v = xs_dict_get(data, "inbox");
31 }
32
33+ return xs_is_null(v) ? NULL : xs_dup(v);
34+}
35+
36+
37+int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size)
38+/* sends a message to an actor */
39+{
40+ int status = 400;
41+ xs *inbox = get_actor_inbox(snac, actor);
42+
43+ if (!xs_is_null(inbox))
44+ status = send_to_inbox(snac, inbox, msg, payload, p_size);
45+
46 snac_log(snac, xs_fmt("send_to_actor %s %d", actor, status));
47
48 return status;