diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-19 18:57:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-19 18:57:43 +0000 |
commit | 759edd03e2d11c2f44ccc91b0160e05d22e4f29b (patch) | |
tree | a56b129a4c5e592fff05394a587795f2ffbec989 /src/libserver | |
parent | 033d4b2d749fca44e4b067f9a5486a289b61a95e (diff) | |
download | rspamd-759edd03e2d11c2f44ccc91b0160e05d22e4f29b.tar.gz rspamd-759edd03e2d11c2f44ccc91b0160e05d22e4f29b.zip |
Add re cache logic to task routines.
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/task.c | 36 | ||||
-rw-r--r-- | src/libserver/task.h | 19 |
2 files changed, 54 insertions, 1 deletions
diff --git a/src/libserver/task.c b/src/libserver/task.c index a4286634f..8f5334927 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_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; +} diff --git a/src/libserver/task.h b/src/libserver/task.h index 799182f01..f4f22823f 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -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_ */ |