]> source.dussan.org Git - rspamd.git/commitdiff
Add re cache logic to task routines.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 18:57:43 +0000 (18:57 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 19 Mar 2015 18:57:43 +0000 (18:57 +0000)
src/libserver/task.c
src/libserver/task.h

index a4286634ff9845a5d9d98aa60e0eb51a92d82609..8f53349277cffbfab78fe4a69fbeba641cbd64da 100644 (file)
@@ -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_regexp_hash, rspamd_regexp_equal);
+       new_task->re_cache = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
        rspamd_mempool_add_destructor (new_task->task_pool,
                (rspamd_mempool_destruct_t) g_hash_table_unref,
                new_task->re_cache);
@@ -450,3 +450,37 @@ rspamd_task_add_sender (struct rspamd_task *task, const gchar *sender)
 
        return FALSE;
 }
+
+
+guint
+rspamd_task_re_cache_add (struct rspamd_task *task, gchar *re,
+               guint value)
+{
+       guint ret = RSPAMD_TASK_CACHE_NO_VALUE;
+       gpointer p;
+
+       p = g_hash_table_lookup (task->re_cache, re);
+
+       if (p != NULL) {
+               ret = GPOINTER_TO_INT (p);
+       }
+
+       g_hash_table_insert (task->re_cache, re, GINT_TO_POINTER (value));
+
+       return ret;
+}
+
+guint
+rspamd_task_re_cache_check (struct rspamd_task *task, const gchar *re)
+{
+       guint ret = RSPAMD_TASK_CACHE_NO_VALUE;
+       gpointer p;
+
+       p = g_hash_table_lookup (task->re_cache, re);
+
+       if (p != NULL) {
+               ret = GPOINTER_TO_INT (p);
+       }
+
+       return ret;
+}
index 799182f0138f1c94d55feb38a95a7ecdcbb8e700..f4f22823fd2f28932329ca67699e4d2dbcb5f77c 100644 (file)
@@ -218,5 +218,24 @@ gboolean rspamd_task_add_recipient (struct rspamd_task *task, const gchar *rcpt)
  */
 gboolean rspamd_task_add_sender (struct rspamd_task *task, const gchar *sender);
 
+#define RSPAMD_TASK_CACHE_NO_VALUE ((guint)-1)
+
+/**
+ * Add or replace the value to the task cache of regular expressions results
+ * @param task task object
+ * @param re text value of regexp
+ * @param value value to add
+ * @return previous value of element or RSPAMD_TASK_CACHE_NO_VALUE
+ */
+guint rspamd_task_re_cache_add (struct rspamd_task *task, gchar *re,
+               guint value);
+
+/**
+ * Check for cached result of re inside cache
+ * @param task task object
+ * @param re text value of regexp
+ * @return the current value of element or RSPAMD_TASK_CACHE_NO_VALUE
+ */
+guint rspamd_task_re_cache_check (struct rspamd_task *task, const gchar *re);
 
 #endif /* TASK_H_ */