summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/activitypub.c b/activitypub.c
index 5f26f73..7f63310 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -9,6 +9,7 @@
9#include "xs_openssl.h" 9#include "xs_openssl.h"
10#include "xs_regex.h" 10#include "xs_regex.h"
11#include "xs_time.h" 11#include "xs_time.h"
12#include "xs_set.h"
12 13
13#include "snac.h" 14#include "snac.h"
14 15
@@ -169,11 +170,13 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s
169d_char *recipient_list(snac *snac, char *msg, int expand_public) 170d_char *recipient_list(snac *snac, char *msg, int expand_public)
170/* returns the list of recipients for a message */ 171/* returns the list of recipients for a message */
171{ 172{
172 d_char *list = xs_list_new();
173 char *to = xs_dict_get(msg, "to"); 173 char *to = xs_dict_get(msg, "to");
174 char *cc = xs_dict_get(msg, "cc"); 174 char *cc = xs_dict_get(msg, "cc");
175 xs_set rcpts;
175 int n; 176 int n;
176 177
178 xs_set_init(&rcpts);
179
177 char *lists[] = { to, cc, NULL }; 180 char *lists[] = { to, cc, NULL };
178 for (n = 0; lists[n]; n++) { 181 for (n = 0; lists[n]; n++) {
179 char *l = lists[n]; 182 char *l = lists[n];
@@ -192,45 +195,41 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
192 if (expand_public && strcmp(v, public_address) == 0) { 195 if (expand_public && strcmp(v, public_address) == 0) {
193 /* iterate the followers and add them */ 196 /* iterate the followers and add them */
194 xs *fwers = follower_list(snac); 197 xs *fwers = follower_list(snac);
195 char *fw; 198 char *actor;
196 199
197 char *p = fwers; 200 char *p = fwers;
198 while (xs_list_iter(&p, &fw)) { 201 while (xs_list_iter(&p, &actor))
199 char *actor = xs_dict_get(fw, "actor"); 202 xs_set_add(&rcpts, actor);
200
201 if (xs_list_in(list, actor) == -1)
202 list = xs_list_append(list, actor);
203 }
204 } 203 }
205 else 204 else
206 if (xs_list_in(list, v) == -1) 205 xs_set_add(&rcpts, v);
207 list = xs_list_append(list, v);
208 } 206 }
209 } 207 }
210 208
211 return list; 209 return xs_set_result(&rcpts);
212} 210}
213 211
214 212
215d_char *inbox_list(snac *snac, char *msg) 213d_char *inbox_list(snac *snac, char *msg)
216/* returns the list of inboxes that are recipients of this message */ 214/* returns the list of inboxes that are recipients of this message */
217{ 215{
218 d_char *list = xs_list_new(); 216 xs *rcpts = recipient_list(snac, msg, 1);
219 xs *rcpts = recipient_list(snac, msg, 1); 217 xs_set inboxes;
220 char *p, *v; 218 char *p, *v;
221 219
220 xs_set_init(&inboxes);
221
222 p = rcpts; 222 p = rcpts;
223 while (xs_list_iter(&p, &v)) { 223 while (xs_list_iter(&p, &v)) {
224 xs *inbox; 224 xs *inbox;
225 225
226 if ((inbox = get_actor_inbox(snac, v)) != NULL) { 226 if ((inbox = get_actor_inbox(snac, v)) != NULL) {
227 /* add the inbox if it's not already there */ 227 /* add the inbox if it's not already there */
228 if (xs_list_in(list, inbox) == -1) 228 xs_set_add(&inboxes, inbox);
229 list = xs_list_append(list, inbox);
230 } 229 }
231 } 230 }
232 231
233 return list; 232 return xs_set_result(&inboxes);
234} 233}
235 234
236 235
@@ -824,7 +823,7 @@ int process_message(snac *snac, char *msg, char *req)
824 823
825 timeline_add(snac, xs_dict_get(f_msg, "id"), f_msg, NULL, NULL); 824 timeline_add(snac, xs_dict_get(f_msg, "id"), f_msg, NULL, NULL);
826 825
827 follower_add(snac, actor, f_msg); 826 follower_add(snac, actor);
828 827
829 snac_log(snac, xs_fmt("New follower %s", actor)); 828 snac_log(snac, xs_fmt("New follower %s", actor));
830 do_notify = 1; 829 do_notify = 1;
@@ -918,6 +917,7 @@ int process_message(snac *snac, char *msg, char *req)
918 if (strcmp(type, "Update") == 0) { 917 if (strcmp(type, "Update") == 0) {
919 if (strcmp(utype, "Person") == 0) { 918 if (strcmp(utype, "Person") == 0) {
920 actor_add(snac, actor, xs_dict_get(msg, "object")); 919 actor_add(snac, actor, xs_dict_get(msg, "object"));
920
921 snac_log(snac, xs_fmt("updated actor %s", actor)); 921 snac_log(snac, xs_fmt("updated actor %s", actor));
922 } 922 }
923 else 923 else
@@ -1017,10 +1017,10 @@ void process_queue(snac *snac)
1017 FILE *f; 1017 FILE *f;
1018 int ok = 0; 1018 int ok = 0;
1019 1019
1020 f = popen("/usr/sbin/sendmail -t", "w"); 1020 if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) {
1021 if (f) {
1022 fprintf(f, "%s\n", msg); 1021 fprintf(f, "%s\n", msg);
1023 if (pclose(f) != EOF) //this is a pipe stream not just a file 1022
1023 if (pclose(f) != -1)
1024 ok = 1; 1024 ok = 1;
1025 } 1025 }
1026 1026
@@ -1089,7 +1089,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
1089 if (p_path == NULL) { 1089 if (p_path == NULL) {
1090 /* if there was no component after the user, it's an actor request */ 1090 /* if there was no component after the user, it's an actor request */
1091 msg = msg_actor(&snac); 1091 msg = msg_actor(&snac);
1092 *ctype = "application/ld+json"; 1092 *ctype = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
1093 } 1093 }
1094 else 1094 else
1095 if (strcmp(p_path, "outbox") == 0) { 1095 if (strcmp(p_path, "outbox") == 0) {