aboutsummaryrefslogtreecommitdiffstats
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
parent289809e28780b529a2dc4a3c6057f82409196a10 (diff)
downloadrspamd-52285ba801090d1fad15060d6b1a61460dcbdc36.tar.gz
rspamd-52285ba801090d1fad15060d6b1a61460dcbdc36.zip
Allow storage of auxiliary userdata inside regexp structure.
-rw-r--r--src/libutil/regexp.c36
-rw-r--r--src/libutil/regexp.h25
2 files changed, 61 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)
diff --git a/src/libutil/regexp.h b/src/libutil/regexp.h
index 41835af84..3c08de71a 100644
--- a/src/libutil/regexp.h
+++ b/src/libutil/regexp.h
@@ -76,6 +76,20 @@ rspamd_regexp_t* rspamd_regexp_ref (rspamd_regexp_t *re);
void rspamd_regexp_unref (rspamd_regexp_t *re);
/**
+ * Set auxiliary userdata for the specified regexp
+ * @param re regexp object
+ * @param ud opaque pointer
+ */
+void rspamd_regexp_set_ud (rspamd_regexp_t *re, gpointer ud);
+
+/**
+ * Get userdata for a regexp object
+ * @param re regexp object
+ * @return opaque pointer
+ */
+gpointer rspamd_regexp_get_ud (rspamd_regexp_t *re);
+
+/**
* Get pattern for the specified regexp object
* @param re
* @return
@@ -100,6 +114,17 @@ rspamd_regexp_t* rspamd_regexp_cache_query (struct rspamd_regexp_cache* cache,
const gchar *flags);
/**
+ * Insert item to the cache using custom pattern and flags
+ * @param cache
+ * @param pattern
+ * @param flags
+ * @param re
+ */
+void rspamd_regexp_cache_insert (struct rspamd_regexp_cache* cache,
+ const gchar *pattern,
+ const gchar *flags, rspamd_regexp_t *re);
+
+/**
* Create or get cached regexp from the specified cache
* @param cache regexp cache. if NULL, the superglobal cache is used (*not* thread-safe)
* @param pattern regexp pattern