From 922b04b4d79c01d13a0de71edf934f019f5a9771 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 20 Sep 2022 12:50:37 +0200 Subject: [PATCH] New function dequeue(). --- data.c | 20 ++++++++++++++++++++ main.c | 5 ++++- snac.h | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/data.c b/data.c index e875f90..0c0d6a2 100644 --- a/data.c +++ b/data.c @@ -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; +} diff --git a/main.c b/main.c index dd072e2..42606c2 100644 --- a/main.c +++ b/main.c @@ -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")); } } diff --git a/snac.h b/snac.h index 9e8432d..d2df160 100644 --- a/snac.h +++ b/snac.h @@ -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);