From cddb2724d56ce8e1d80d4eec3c13702634704022 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 28 Sep 2025 14:40:24 +0200 Subject: New function actor_failure() (again, but much better). --- data.c | 39 +++++++++++++++++++++++++++++++++++++++ snac.h | 1 + 2 files changed, 40 insertions(+) diff --git a/data.c b/data.c index 4a16a82..3b45665 100644 --- a/data.c +++ b/data.c @@ -3042,6 +3042,45 @@ xs_list *content_search(snac *user, const char *regex, } +int actor_failure(const char *actor, int op) +/* actor failure maintenance */ +{ + int ret = 0; + + xs *md5 = xs_md5_hex(actor, strlen(actor)); + xs *fn = xs_fmt("%s/failure/%s", srv_basedir, md5); + + switch (op) { + case 0: /** check **/ + if (mtime(fn)) + ret = -1; + + break; + + case 1: /** register a failure **/ + if (mtime(fn) == 0.0) { + FILE *f; + + /* only create once, as the date will be used */ + if ((f = fopen(fn, "w")) != NULL) { + fprintf(f, "%s\n", actor); + fclose(f); + } + } + + break; + + case 2: /** clear a failure **/ + /* called whenever a message comes from this instance */ + unlink(fn); + + break; + } + + return ret; +} + + int instance_failure(const char *url, int op) /* do some checks and accounting on instance failures */ { diff --git a/snac.h b/snac.h index 1a58e0b..aaa5558 100644 --- a/snac.h +++ b/snac.h @@ -278,6 +278,7 @@ int content_match(const char *file, const xs_dict *msg); xs_list *content_search(snac *user, const char *regex, int priv, int skip, int show, int max_secs, int *timeout); +int actor_failure(const char *actor, int op); int instance_failure(const char *url, int op); void enqueue_input(snac *snac, const xs_dict *msg, const xs_dict *req, int retries); -- cgit v1.2.3