Also store the req object in enqueue_input().

This commit is contained in:
default 2022-09-24 10:03:27 +02:00
parent 3df33c845d
commit a6712ba79a
3 changed files with 12 additions and 11 deletions

View file

@ -122,6 +122,9 @@ void process_message(snac *snac, char *msg)
char *actor = xs_dict_get(msg, "actor");
char *type = xs_dict_get(msg, "type");
/* check the signature */
/* ... */
if (strcmp(type, "Follow") == 0) {
}
else
@ -179,7 +182,7 @@ void process_queue(snac *snac)
snac_log(snac, xs_fmt("process_queue giving up %s %d", actor, status));
else {
/* reenqueue */
enqueue_output(snac, actor, msg, retries + 1);
enqueue_output(snac, msg, actor, retries + 1);
snac_log(snac, xs_fmt("process_queue requeue %s %d", actor, retries + 1));
}
}
@ -292,14 +295,11 @@ int activitypub_post_handler(d_char *req, char *q_path,
return 404;
}
/* signature checking should happen here */
/* ... */
/* decode */
xs *msg = xs_json_loads(payload);
if (msg && xs_dict_get(msg, "actor") && xs_dict_get(msg, "type"))
enqueue_input(&snac, msg);
enqueue_input(&snac, msg, req);
else {
srv_log(xs_fmt("activitypub_post_handler JSON error %s", q_path));
status = 400;

9
data.c
View file

@ -709,12 +709,12 @@ int actor_get(snac *snac, char *actor, d_char **data)
}
void enqueue_input(snac *snac, char *msg)
void enqueue_input(snac *snac, char *msg, char *req)
/* enqueues an input message */
{
xs *ntid = tid(0);
xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid);
xs *tfn = xs_str_cat(fn, ".tmp");
xs *tfn = xs_fmt("%s.tmp", fn);
FILE *f;
if ((f = fopen(tfn, "w")) != NULL) {
@ -723,6 +723,7 @@ void enqueue_input(snac *snac, char *msg)
qmsg = xs_dict_append(qmsg, "type", "input");
qmsg = xs_dict_append(qmsg, "object", msg);
qmsg = xs_dict_append(qmsg, "req", req);
j = xs_json_dumps_pp(qmsg, 4);
@ -736,7 +737,7 @@ void enqueue_input(snac *snac, char *msg)
}
void enqueue_output(snac *snac, char *actor, char *msg, int retries)
void enqueue_output(snac *snac, char *msg, char *actor, int retries)
/* enqueues an output message for an actor */
{
if (strcmp(actor, snac->actor) == 0) {
@ -747,7 +748,7 @@ void enqueue_output(snac *snac, char *actor, char *msg, int retries)
int qrt = xs_number_get(xs_dict_get(srv_config, "query_retry_minutes"));
xs *ntid = tid(retries * 60 * qrt);
xs *fn = xs_fmt("%s/queue/%s.json", snac->basedir, ntid);
xs *tfn = xs_str_cat(fn, ".tmp");
xs *tfn = xs_fmt("%s.tmp", fn);
FILE *f;
if ((f = fopen(tfn, "w")) != NULL) {

4
snac.h
View file

@ -64,8 +64,8 @@ int is_muted(snac *snac, char *actor);
int actor_add(snac *snac, char *actor, char *msg);
int actor_get(snac *snac, char *actor, d_char **data);
void enqueue_input(snac *snac, char *msg);
void enqueue_output(snac *snac, char *actor, char *msg, int retries);
void enqueue_input(snac *snac, char *msg, char *req);
void enqueue_output(snac *snac, char *msg, char *actor, int retries);
d_char *queue(snac *snac);
d_char *dequeue(snac *snac, char *fn);