Fixed a bug in the digest header.

This commit is contained in:
default 2022-09-25 18:50:53 +02:00
parent 6169932733
commit 6f7f98ded3
4 changed files with 23 additions and 11 deletions

View File

@ -233,8 +233,8 @@ void process_message(snac *snac, char *msg, char *req)
timeline_request(snac, in_reply_to);
if (timeline_add(snac, id, msg, in_reply_to))
snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
timeline_add(snac, id, msg, in_reply_to);
}
}
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"));

6
data.c
View File

@ -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;
}

17
http.c
View File

@ -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;
}

2
snac.h
View File

@ -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);