aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/regexp.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-07 22:43:23 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-03-07 22:43:23 +0000
commit52285ba801090d1fad15060d6b1a61460dcbdc36 (patch)
tree47c4eda53e903dbfc0ca85376b16b97efc8a2e54 /src/libutil/regexp.c
parent289809e28780b529a2dc4a3c6057f82409196a10 (diff)
downloadrspamd-52285ba801090d1fad15060d6b1a61460dcbdc36.tar.gz
rspamd-52285ba801090d1fad15060d6b1a61460dcbdc36.zip
Allow storage of auxiliary userdata inside regexp structure.
Diffstat (limited to 'src/libutil/regexp.c')
-rw-r--r--src/libutil/regexp.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c
index 3b76d15e0..9151066f7 100644
--- a/src/libutil/regexp.c
+++ b/src/libutil/regexp.c
@@ -51,6 +51,7 @@ struct rspamd_regexp_s {
pcre_extra *raw_extra;
regexp_id_t id;
ref_entry_t ref;
+ gpointer ud;
gint flags;
};
@@ -418,6 +419,22 @@ rspamd_regexp_unref (rspamd_regexp_t *re)
REF_RELEASE (re);
}
+void
+rspamd_regexp_set_ud (rspamd_regexp_t *re, gpointer ud)
+{
+ g_assert (re != NULL);
+
+ re->ud = ud;
+}
+
+gpointer
+rspamd_regexp_get_ud (rspamd_regexp_t *re)
+{
+ g_assert (re != NULL);
+
+ return re->ud;
+}
+
static gboolean
rspamd_regexp_equal (gconstpointer a, gconstpointer b)
{
@@ -499,6 +516,25 @@ rspamd_regexp_cache_create (struct rspamd_regexp_cache *cache,
return res;
}
+void rspamd_regexp_cache_insert (struct rspamd_regexp_cache* cache,
+ const gchar *pattern,
+ const gchar *flags, rspamd_regexp_t *re)
+{
+ g_assert (re != NULL);
+ g_assert (pattern != NULL);
+
+ if (cache == NULL) {
+ cache = global_re_cache;
+ }
+
+ g_assert (cache != NULL);
+ /* Generate custom id */
+ rspamd_regexp_generate_id (pattern, flags, re->id);
+
+ REF_RETAIN (re);
+ g_hash_table_insert (cache->tbl, re->id, re);
+}
+
gboolean
rspamd_regexp_cache_remove (struct rspamd_regexp_cache *cache,
rspamd_regexp_t *re)