aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libserver/task.c2
-rw-r--r--src/libutil/regexp.c4
-rw-r--r--src/libutil/regexp.h22
3 files changed, 25 insertions, 3 deletions
diff --git a/src/libserver/task.c b/src/libserver/task.c
index f6eeef2b1..a4286634f 100644
--- a/src/libserver/task.c
+++ b/src/libserver/task.c
@@ -73,7 +73,7 @@ rspamd_task_new (struct rspamd_worker *worker)
rspamd_mempool_add_destructor (new_task->task_pool,
(rspamd_mempool_destruct_t) g_hash_table_unref,
new_task->results);
- new_task->re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
+ new_task->re_cache = g_hash_table_new (rspamd_regexp_hash, rspamd_regexp_equal);
rspamd_mempool_add_destructor (new_task->task_pool,
(rspamd_mempool_destruct_t) g_hash_table_unref,
new_task->re_cache);
diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c
index b8bd4454c..bf1a1762d 100644
--- a/src/libutil/regexp.c
+++ b/src/libutil/regexp.c
@@ -436,7 +436,7 @@ rspamd_regexp_get_ud (rspamd_regexp_t *re)
return re->ud;
}
-static gboolean
+gboolean
rspamd_regexp_equal (gconstpointer a, gconstpointer b)
{
const guchar *ia = a, *ib = b;
@@ -444,7 +444,7 @@ rspamd_regexp_equal (gconstpointer a, gconstpointer b)
return (memcmp (ia, ib, sizeof (regexp_id_t)) == 0);
}
-static guint32
+guint32
rspamd_regexp_hash (gconstpointer a)
{
const guchar *ia = a;
diff --git a/src/libutil/regexp.h b/src/libutil/regexp.h
index 3c08de71a..fc236c1b3 100644
--- a/src/libutil/regexp.h
+++ b/src/libutil/regexp.h
@@ -90,6 +90,13 @@ void rspamd_regexp_set_ud (rspamd_regexp_t *re, gpointer ud);
gpointer rspamd_regexp_get_ud (rspamd_regexp_t *re);
/**
+ * Get regexp ID suitable for hashing
+ * @param re
+ * @return
+ */
+gpointer rspamd_regexp_get_id (rspamd_regexp_t *re);
+
+/**
* Get pattern for the specified regexp object
* @param re
* @return
@@ -152,6 +159,21 @@ gboolean rspamd_regexp_cache_remove (struct rspamd_regexp_cache *cache,
void rspamd_regexp_cache_destroy (struct rspamd_regexp_cache *cache);
/**
+ * Return the value for regexp hash based on its ID
+ * @param a
+ * @return
+ */
+guint32 rspamd_regexp_hash (gconstpointer a);
+
+/**
+ * Compare two regexp objects based on theirs ID
+ * @param a
+ * @param b
+ * @return
+ */
+gboolean rspamd_regexp_equal (gconstpointer a, gconstpointer b);
+
+/**
* Initialize superglobal regexp cache and library
*/
void rspamd_regexp_library_init (void);