New function dequeue().

This commit is contained in:
default 2022-09-20 12:50:37 +02:00
parent e923a4f5ec
commit 922b04b4d7
3 changed files with 25 additions and 1 deletions

20
data.c
View file

@ -587,3 +587,23 @@ d_char *queue(snac *snac)
return list;
}
d_char *dequeue(snac *snac, char *fn)
/* dequeues a message */
{
FILE *f;
d_char *obj = NULL;
if ((f = fopen(fn, "r")) != NULL) {
/* delete right now */
unlink(fn);
xs *j = xs_readall(f);
obj = xs_json_loads(j);
fclose(f);
}
return obj;
}

5
main.c
View file

@ -21,7 +21,10 @@ int main(int argc, char *argv[])
p = list;
while (xs_list_iter(&p, &fn)) {
printf("%s\n", fn);
xs *obj;
obj = dequeue(&snac, fn);
printf("%s\n", xs_dict_get(obj, "actor"));
}
}

1
snac.h
View file

@ -60,3 +60,4 @@ int is_muted(snac *snac, char *actor);
void enqueue(snac *snac, char *actor, char *msg, int retries);
d_char *queue(snac *snac);
d_char *dequeue(snac *snac, char *fn);