]> source.dussan.org Git - rspamd.git/commitdiff
Add cache id support for regexp
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 3 Dec 2015 09:24:59 +0000 (09:24 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 3 Dec 2015 09:24:59 +0000 (09:24 +0000)
src/libutil/regexp.c
src/libutil/regexp.h

index 2ddfa694d07ad76c6afae2374725fa7f0641a50a..eaea894c033a9b40ae5ddacf8305cd6295ea490f 100644 (file)
@@ -51,6 +51,7 @@ struct rspamd_regexp_s {
        regexp_id_t id;
        ref_entry_t ref;
        gpointer ud;
+       guint64 cache_id;
        gint flags;
        gint ncaptures;
        gint nbackref;
@@ -245,6 +246,7 @@ fin:
        REF_INIT_RETAIN (res, rspamd_regexp_dtor);
        res->flags = rspamd_flags;
        res->pattern = real_pattern;
+       res->cache_id = RSPAMD_INVALID_ID;
 
        if (rspamd_flags & RSPAMD_REGEXP_FLAG_RAW) {
                res->raw_re = r;
@@ -502,6 +504,26 @@ rspamd_regexp_get_ncaptures (rspamd_regexp_t *re)
        return re->ncaptures;
 }
 
+guint64
+rspamd_regexp_get_cache_id (rspamd_regexp_t *re)
+{
+       g_assert (re != NULL);
+
+       return re->cache_id;
+}
+
+guint64
+rspamd_regexp_set_cache_id (rspamd_regexp_t *re, guint64 id)
+{
+       guint64 old;
+
+       g_assert (re != NULL);
+       old = re->cache_id;
+       re->cache_id = id;
+
+       return old;
+}
+
 gboolean
 rspamd_regexp_match (rspamd_regexp_t *re, const gchar *text, gsize len,
                gboolean raw)
index 2c33f780dd72bbf1b63f85020afd5d05c23ee694..cf012668a2762ced9b4659a99f806b41c4f6b6c0 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "config.h"
 
+#define RSPAMD_INVALID_ID ((guint64)-1LL)
+
 typedef struct rspamd_regexp_s rspamd_regexp_t;
 struct rspamd_regexp_cache;
 struct rspamd_re_capture {
@@ -120,6 +122,16 @@ gint rspamd_regexp_get_nbackrefs (rspamd_regexp_t *re);
  */
 gint rspamd_regexp_get_ncaptures (rspamd_regexp_t *re);
 
+/**
+ * Returns cache id for a regexp
+ */
+guint64 rspamd_regexp_get_cache_id (rspamd_regexp_t *re);
+
+/**
+ * Sets cache id for a regexp
+ */
+guint64 rspamd_regexp_set_cache_id (rspamd_regexp_t *re, guint64 id);
+
 /**
  * Create new regexp cache
  * @return