X-Git-Url: https://www.pipapo.org/gitweb/?p=rxpd;a=blobdiff_plain;f=src%2Frxpd_rule.c;h=4dedc596a695ccac004a0dadaf580945ddd9eb31;hp=3fc9d67ea024de54e76000ac8bd0a9f4b861475e;hb=3a35b8c703859aa77ac86e8c2b863e6956daad28;hpb=dc83eb6a1bb03ce092e9a8097161203927af19b8 diff --git a/src/rxpd_rule.c b/src/rxpd_rule.c index 3fc9d67..4dedc59 100644 --- a/src/rxpd_rule.c +++ b/src/rxpd_rule.c @@ -55,7 +55,6 @@ rxpd_rule_new (const char* buf) self->string = rxpd_strdup (namestart+1); else { - regfree (&self->rx); char ebuf[256]; size_t len = regerror (err, NULL, ebuf, 256); self->string = rxpd_malloc (len + strlen(namestart+1) + 14); @@ -96,6 +95,47 @@ rxpd_rule_copy (const struct rxpd_rule* src) return self; } +struct rxpd_rule* +rxpd_rule_activate (struct rxpd_rule* self) +{ + if (self) + { + char* buf; + if (self->string[0] == '#' && (buf = strstr (self->string, ": ")+2) && *buf) + { + if (*buf != '#') + { + char* namestart = strchr (buf, ':'); + char* rxstart = namestart? strchr (namestart+1, ':') : NULL; + + if (!rxstart) + return NULL; + + // TODO regflags from base + if (regcomp (&self->rx, rxstart+1, REG_EXTENDED|REG_ICASE|REG_NOSUB)) + return NULL; + + free (self->string); + self->string = rxpd_strdup (namestart+1); + + if (namestart != buf) + { + /* atime given */ + self->atime = atoi (buf); + if (!self->atime) + /* atime was zero or not set */ + self->atime = time (NULL)-1; + } + } + else + self->string = rxpd_strdup (buf); + } + else + return NULL; + } + return self; +} + struct rxpd_rule* rxpd_rule_comment (struct rxpd_rule* self, const char* comment) {