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 @@
#include "xs_openssl.h"
#include "xs_regex.h"
#include "xs_time.h"
+#include "xs_set.h"
#include "snac.h"
@@ -169,11 +170,13 @@ int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_s
d_char *recipient_list(snac *snac, char *msg, int expand_public)
/* returns the list of recipients for a message */
{
- d_char *list = xs_list_new();
char *to = xs_dict_get(msg, "to");
char *cc = xs_dict_get(msg, "cc");
+ xs_set rcpts;
int n;
+ xs_set_init(&rcpts);
+
char *lists[] = { to, cc, NULL };
for (n = 0; lists[n]; n++) {
char *l = lists[n];
@@ -192,45 +195,41 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
if (expand_public && strcmp(v, public_address) == 0) {
/* iterate the followers and add them */
xs *fwers = follower_list(snac);
- char *fw;
+ char *actor;
char *p = fwers;
- while (xs_list_iter(&p, &fw)) {
- char *actor = xs_dict_get(fw, "actor");
-
- if (xs_list_in(list, actor) == -1)
- list = xs_list_append(list, actor);
- }
+ while (xs_list_iter(&p, &actor))
+ xs_set_add(&rcpts, actor);
}
else
- if (xs_list_in(list, v) == -1)
- list = xs_list_append(list, v);
+ xs_set_add(&rcpts, v);
}
}
- return list;
+ return xs_set_result(&rcpts);
}
d_char *inbox_list(snac *snac, char *msg)
/* returns the list of inboxes that are recipients of this message */
{
- d_char *list = xs_list_new();
- xs *rcpts = recipient_list(snac, msg, 1);
+ xs *rcpts = recipient_list(snac, msg, 1);
+ xs_set inboxes;
char *p, *v;
+ xs_set_init(&inboxes);
+
p = rcpts;
while (xs_list_iter(&p, &v)) {
xs *inbox;
if ((inbox = get_actor_inbox(snac, v)) != NULL) {
/* add the inbox if it's not already there */
- if (xs_list_in(list, inbox) == -1)
- list = xs_list_append(list, inbox);
+ xs_set_add(&inboxes, inbox);
}
}
- return list;
+ return xs_set_result(&inboxes);
}
@@ -824,7 +823,7 @@ int process_message(snac *snac, char *msg, char *req)
timeline_add(snac, xs_dict_get(f_msg, "id"), f_msg, NULL, NULL);
- follower_add(snac, actor, f_msg);
+ follower_add(snac, actor);
snac_log(snac, xs_fmt("New follower %s", actor));
do_notify = 1;
@@ -918,6 +917,7 @@ int process_message(snac *snac, char *msg, char *req)
if (strcmp(type, "Update") == 0) {
if (strcmp(utype, "Person") == 0) {
actor_add(snac, actor, xs_dict_get(msg, "object"));
+
snac_log(snac, xs_fmt("updated actor %s", actor));
}
else
@@ -1017,10 +1017,10 @@ void process_queue(snac *snac)
FILE *f;
int ok = 0;
- f = popen("/usr/sbin/sendmail -t", "w");
- if (f) {
+ if ((f = popen("/usr/sbin/sendmail -t", "w")) != NULL) {
fprintf(f, "%s\n", msg);
- if (pclose(f) != EOF) //this is a pipe stream not just a file
+
+ if (pclose(f) != -1)
ok = 1;
}
@@ -1089,7 +1089,7 @@ int activitypub_get_handler(d_char *req, char *q_path,
if (p_path == NULL) {
/* if there was no component after the user, it's an actor request */
msg = msg_actor(&snac);
- *ctype = "application/ld+json";
+ *ctype = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"";
}
else
if (strcmp(p_path, "outbox") == 0) {