summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.c35
-rw-r--r--data.c6
-rw-r--r--httpd.c2
-rw-r--r--main.c4
-rw-r--r--snac.c12
-rw-r--r--snac.h1
6 files changed, 41 insertions, 19 deletions
diff --git a/activitypub.c b/activitypub.c
index 091e4bf..2e11a82 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -194,18 +194,27 @@ d_char *msg_update(snac *snac, char *object)
d_char *msg_admiration(snac *snac, char *object, char *type)
/* creates a Like or Announce message */
{
- xs *ntid = tid(0);
- xs *id = xs_fmt("%s/d/%d/%s", snac->actor, ntid, type);
- d_char *msg = msg_base(snac, type, id, snac->actor, "");
- xs *rcpts = xs_list_new();
+ xs *a_msg = NULL;
+ d_char *msg = NULL;
/* call the object */
timeline_request(snac, object, snac->actor);
- rcpts = xs_list_append(rcpts, public_address);
+ if ((a_msg = timeline_find(snac, object)) != NULL) {
+ xs *ntid = tid(0);
+ xs *id = xs_fmt("%s/d/%d/%s", snac->actor, ntid, type);
+ xs *rcpts = xs_list_new();
- msg = xs_dict_append(msg, "to", rcpts);
- msg = xs_dict_append(msg, "object", object);
+ msg = msg_base(snac, type, id, snac->actor, "");
+
+ rcpts = xs_list_append(rcpts, public_address);
+ rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo"));
+
+ msg = xs_dict_append(msg, "to", rcpts);
+ msg = xs_dict_append(msg, "object", object);
+ }
+ else
+ snac_log(snac, xs_fmt("msg_admiration cannot retrieve object %s", object));
return msg;
}
@@ -372,9 +381,11 @@ void process_queue(snac *snac)
char *actor = xs_dict_get(q_item, "actor");
char *msg = xs_dict_get(q_item, "object");
int retries = xs_number_get(xs_dict_get(q_item, "retries"));
+ xs *payload = NULL;
+ int p_size = 0;
/* deliver */
- status = send_to_actor(snac, actor, msg, NULL, 0);
+ status = send_to_actor(snac, actor, msg, &payload, &p_size);
if (!valid_status(status)) {
/* error sending; reenqueue? */
@@ -420,12 +431,14 @@ d_char *recipient_list(snac *snac, char *msg, int expand_public)
char *p = fwers;
while (xs_list_iter(&p, &fw)) {
- if (!xs_list_in(list, fw))
- list = xs_list_append(list, fw);
+ char *actor = xs_dict_get(fw, "actor");
+
+ if (xs_list_in(list, actor) == -1)
+ list = xs_list_append(list, actor);
}
}
else
- if (!xs_list_in(list, v))
+ if (xs_list_in(list, v) == -1)
list = xs_list_append(list, v);
}
}
diff --git a/data.c b/data.c
index ac6e225..5e6bcac 100644
--- a/data.c
+++ b/data.c
@@ -302,8 +302,8 @@ int timeline_here(snac *snac, char *id)
d_char *timeline_find(snac *snac, char *id)
/* gets a message from the timeline by id */
{
- xs *fn = _timeline_find_fn(snac, id);
- xs *msg = NULL;
+ xs *fn = _timeline_find_fn(snac, id);
+ d_char *msg = NULL;
if (fn != NULL) {
FILE *f;
@@ -820,7 +820,7 @@ void enqueue_output(snac *snac, char *msg, char *actor, int retries)
return;
}
- int qrt = xs_number_get(xs_dict_get(srv_config, "query_retry_minutes"));
+ int qrt = xs_number_get(xs_dict_get(srv_config, "queue_retry_minutes"));
xs *ntid = tid(retries * 60 * qrt);
xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid);
xs *tfn = xs_fmt("%s.tmp", fn);
diff --git a/httpd.c b/httpd.c
index 7728d04..256d7b1 100644
--- a/httpd.c
+++ b/httpd.c
@@ -97,7 +97,7 @@ void httpd_connection(int rs)
xs *headers = NULL;
xs *q_path = NULL;
xs *payload = NULL;
- int p_size;
+ int p_size = 0;
char *p;
f = xs_socket_accept(rs);
diff --git a/main.c b/main.c
index 8efbc36..eed5ea8 100644
--- a/main.c
+++ b/main.c
@@ -119,7 +119,9 @@ int main(int argc, char *argv[])
if (strcmp(cmd, "announce") == 0) {
xs *msg = msg_admiration(&snac, url, "Announce");
- {
+ if (msg != NULL) {
+ post(&snac, msg);
+
xs *j = xs_json_dumps_pp(msg, 4);
printf("%s\n", j);
}
diff --git a/snac.c b/snac.c
index 52ac7d3..2c350bb 100644
--- a/snac.c
+++ b/snac.c
@@ -142,7 +142,7 @@ void srv_archive(char *direction, char *req, char *payload, int p_size,
/* archives a connection */
{
/* obsessive archiving */
- xs *date = xs_local_time("%Y%m%d%H%M%S");
+ xs *date = tid(0);
xs *dir = xs_fmt("%s/archive/%s", srv_basedir, date);
FILE *f;
@@ -172,7 +172,10 @@ void srv_archive(char *direction, char *req, char *payload, int p_size,
if ((f = fopen(payload_fn, "w")) != NULL) {
xs *v1 = xs_json_loads(payload);
- xs *j1 = xs_json_dumps_pp(v1, 4);
+ xs *j1 = NULL;
+
+ if (v1 != NULL)
+ j1 = xs_json_dumps_pp(v1, 4);
if (j1 != NULL)
fwrite(j1, strlen(j1), 1, f);
@@ -200,7 +203,10 @@ void srv_archive(char *direction, char *req, char *payload, int p_size,
if ((f = fopen(body_fn, "w")) != NULL) {
xs *v1 = xs_json_loads(body);
- xs *j1 = xs_json_dumps_pp(v1, 4);
+ xs *j1 = NULL;
+
+ if (v1 != NULL)
+ j1 = xs_json_dumps_pp(v1, 4);
if (j1 != NULL)
fwrite(j1, strlen(j1), 1, f);
diff --git a/snac.h b/snac.h
index f39e383..aef8d69 100644
--- a/snac.h
+++ b/snac.h
@@ -94,6 +94,7 @@ int actor_request(snac *snac, char *actor, d_char **data);
int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_size);
int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size);
void process_queue(snac *snac);
+void post(snac *snac, char *msg);
int activitypub_get_handler(d_char *req, char *q_path,
char **body, int *b_size, char **ctype);
int activitypub_post_handler(d_char *req, char *q_path,