void charset_hook(rx_t local, const string_t alias) {
rx_set_template(local, alias);
- rx_list_append(&charset_hooks, local);
+ rx_list_add2(&charset_hooks, &local);
RETURN();
};
void iconv_hook(rx_t local, const string_t alias) {
rx_set_template(local, alias);
- rx_list_append(&iconv_hooks, local);
+ rx_list_add2(&iconv_hooks, &local);
RETURN();
};
};
}
l = rx_lookup(l, str);
- if (l) {
+ if (*l) {
rx_t *r = rx_list_pop(l);
rx_delete(&r);
return 0;
l = &(*l)->next;
}
- return NULL;
+ return l;
+}
+
+void rx_list_add(rx_t **l, rx_t *rxp)
+{
+ l = rx_lookup(l, rxp->pattern);
+ if (*l) {
+ rx_t *r = rx_list_pop(l);
+ rx_delete(&r);
+ }
+ rx_list_push(l, rxp);
+}
+
+void rx_list_add2(rx_t **l, rx_t **rxp)
+{
+ l = rx_lookup(l, (*rxp)->pattern);
+ if (*l) {
+ rx_t *r = rx_list_pop(l);
+ rx_delete(&r);
+ }
+ if (m_strisempty((*rxp)->tpl)) {
+ rx_delete(rxp);
+ } else {
+ rx_list_push(l, *rxp);
+ }
+}
+
+void rx_list_remove(rx_t **l, const rx_t *r)
+{
+ l = rx_lookup(l, r->pattern);
+ if (*l) {
+ rx_t *tmp = rx_list_pop(l);
+ rx_delete(&tmp);
+ }
}
int rx_sanitize_string(char *dst, ssize_t n, const char *src)
} rx_t;
rx_t *rx_compile(const char*, int);
-int rx_validate(const char*, char*, ssize_t);
-void rx_set_template(rx_t *, const char*);
void rx_wipe(rx_t *);
DO_DELETE(rx_t, rx);
-
DO_SLIST(rx_t, rx, rx_delete);
+int rx_validate(const char*, char*, ssize_t);
+void rx_set_template(rx_t *, const char*);
+int rx_sanitize_string(char *, ssize_t, const char *);
+
/* for handling lists */
+rx_t **rx_lookup(rx_t**, const char*); /* lookup pattern */
+
int rx_list_match(rx_t *, const char*); /* match all items list agains string */
+void rx_list_add(rx_t **, rx_t *);
+void rx_list_remove(rx_t **, const rx_t *);
+
int rx_list_match2(rx_t *l, const char *s, char *dst, int dlen);
-rx_t **rx_lookup(rx_t**, const char*); /* lookup pattern */
-int rx_sanitize_string(char *, ssize_t, const char *);
+void rx_list_add2(rx_t **, rx_t **);
#define REGCOMP(X,Y,Z) regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
#define REGEXEC(X,Y) regexec(X, Y, 0, NULL, 0)
void spam(rx_t rx, const string_t tpl) {
rx_set_template(rx, tpl);
- rx_list_append(&SpamList, rx);
+ rx_list_add2(&SpamList, &rx);
+ rx_list_remove(&NoSpamList, rx);
RETURN();
};
rx_list_wipe(&NoSpamList);
rx_delete(&rx);
} else {
- rx_list_append(&NoSpamList, rx);
+ rx_list_remove(&SpamList, rx);
+ rx_list_add2(&NoSpamList, &rx);
}
RETURN();
};