diff --git a/activitypub.c b/activitypub.c index 7c93ca5..8924f1c 100644 --- a/activitypub.c +++ b/activitypub.c @@ -233,8 +233,8 @@ void process_message(snac *snac, char *msg, char *req) timeline_request(snac, in_reply_to); - snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); - timeline_add(snac, id, msg, in_reply_to); + if (timeline_add(snac, id, msg, in_reply_to)) + snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); } } else @@ -247,8 +247,10 @@ void process_message(snac *snac, char *msg, char *req) else */ if (strcmp(type, "Like") == 0) { - if (xs_type(object) == XSTYPE_STRING) + if (xs_type(object) == XSTYPE_STRING) { timeline_admire(snac, object, actor, 1); + snac_log(snac, xs_fmt("new 'Like' %s %s", actor, object)); + } else snac_debug(snac, 2, xs_fmt("xs_type for 'Like' object not string")); } @@ -258,6 +260,7 @@ void process_message(snac *snac, char *msg, char *req) timeline_request(snac, object); timeline_admire(snac, object, actor, 0); + snac_log(snac, xs_fmt("new 'Announce' %s %s", actor, object)); } else snac_debug(snac, 2, xs_fmt("xs_type for 'Announce' object not string")); diff --git a/data.c b/data.c index 9fa06ae..3167d28 100644 --- a/data.c +++ b/data.c @@ -530,14 +530,14 @@ void _timeline_write(snac *snac, char *id, char *msg, char *parent) } -void timeline_add(snac *snac, char *id, char *o_msg, char *parent) +int timeline_add(snac *snac, char *id, char *o_msg, char *parent) /* adds a message to the timeline */ { xs *pfn = _timeline_find_fn(snac, id); if (pfn != NULL) { snac_log(snac, xs_fmt("timeline_add refusing rewrite %s %s", id, pfn)); - return; + return 0; } xs *msg = xs_dup(o_msg); @@ -560,6 +560,8 @@ void timeline_add(snac *snac, char *id, char *o_msg, char *parent) _timeline_write(snac, id, msg, parent); snac_log(snac, xs_fmt("timeline_add %s", id)); + + return 1; } diff --git a/http.c b/http.c index 56fbbda..65d934c 100644 --- a/http.c +++ b/http.c @@ -17,7 +17,7 @@ d_char *http_signed_request(snac *snac, char *method, char *url, { xs *l1; xs *date; - xs *digest; + xs *digest_b64, *digest; xs *s64; xs *signature; xs *hdrs; @@ -25,6 +25,7 @@ d_char *http_signed_request(snac *snac, char *method, char *url, char *target; char *seckey; char *k, *v; + d_char *response; date = xs_utc_time("%a, %d %b %Y %H:%M:%S GMT"); @@ -43,9 +44,11 @@ d_char *http_signed_request(snac *snac, char *method, char *url, /* digest */ if (body != NULL) - digest = xs_sha256_base64(body, b_size); + digest_b64 = xs_sha256_base64(body, b_size); else - digest = xs_sha256_base64("", 0); + digest_b64 = xs_sha256_base64("", 0); + + digest = xs_fmt("SHA-256=%s", digest_b64); seckey = xs_dict_get(snac->key, "secret"); @@ -53,7 +56,7 @@ d_char *http_signed_request(snac *snac, char *method, char *url, /* build the string to be signed */ xs *s = xs_fmt("(request-target): %s /%s\n" "host: %s\n" - "digest: SHA-256=%s\n" + "digest: %s\n" "date: %s", strcmp(method, "POST") == 0 ? "post" : "get", target, host, digest, date); @@ -81,6 +84,10 @@ d_char *http_signed_request(snac *snac, char *method, char *url, hdrs = xs_dict_append(hdrs, "digest", digest); hdrs = xs_dict_append(hdrs, "user-agent", "snac/2.x"); - return xs_http_request(method, url, hdrs, + response = xs_http_request(method, url, hdrs, body, b_size, status, payload, p_size); + + srv_archive("SEND", hdrs, body, b_size, *status, response, *payload, *p_size); + + return response; } diff --git a/snac.h b/snac.h index 82e2c2f..436e0f0 100644 --- a/snac.h +++ b/snac.h @@ -56,7 +56,7 @@ d_char *timeline_find(snac *snac, char *id); void timeline_del(snac *snac, char *id); d_char *timeline_get(snac *snac, char *fn); d_char *timeline_list(snac *snac); -void timeline_add(snac *snac, char *id, char *msg, char *parent); +int timeline_add(snac *snac, char *id, char *msg, char *parent); void timeline_admire(snac *snac, char *id, char *admirer, int like); int following_add(snac *snac, char *actor, char *msg);