Browse Source

New function actor_failure() (again, but much better).

grunfink 10 months ago
parent
commit
cddb2724d5
2 changed files with 40 additions and 0 deletions
  1. 39 0
      data.c
  2. 1 0
      snac.h

+ 39 - 0
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 */
 {

+ 1 - 0
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);