]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
* Fix error in regexps results hashing
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 4 May 2009 15:35:45 +0000 (19:35 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Mon, 4 May 2009 15:35:45 +0000 (19:35 +0400)
src/expressions.c
src/expressions.h
src/worker.c

index e86802a1ff9a84cf9f354d1330172cc8ad464c31..07f1c45fbbff2d2f0c6c36a6b393c365561f906d 100644 (file)
@@ -105,17 +105,27 @@ re_cache_add (char *line, void *pointer)
 
 /* Task cache functions */
 void 
-task_cache_add (struct worker_task *task, void *pointer, int32_t result)
+task_cache_add (struct worker_task *task, struct rspamd_regexp *re, int32_t result)
 {
-       g_hash_table_insert (task->re_cache, pointer, GINT_TO_POINTER (result));
+    if (result == 0) {
+        result = -1;
+    }
+
+       g_hash_table_insert (task->re_cache, re->regexp_text, GINT_TO_POINTER (result));
 }
 
 int32_t
-task_cache_check (struct worker_task *task, void *pointer)
+task_cache_check (struct worker_task *task, struct rspamd_regexp *re)
 {
        gpointer res;
-       if ((res = g_hash_table_lookup (task->re_cache, pointer)) != NULL) {
-               return GPOINTER_TO_INT (res);
+    int32_t r;
+
+       if ((res = g_hash_table_lookup (task->re_cache, re->regexp_text)) != NULL) {
+        r = GPOINTER_TO_INT (res);
+        if (r == -1) {
+            return 0;
+        }
+        return 1;
        }
        return -1;
 }
index 06034c4850538852c23f9268ec681221a68416db..6ee5d97e985e35126a9868fbf6d031381ba16f36 100644 (file)
@@ -101,7 +101,7 @@ void * re_cache_check (const char *line);
  * @param pointer regexp data
  * @param result numeric result of this regexp
  */
-void task_cache_add (struct worker_task *task, void *pointer, int32_t result);
+void task_cache_add (struct worker_task *task, struct rspamd_regexp *re, int32_t result);
 
 /**
  * Check regexp in cache
@@ -109,7 +109,7 @@ void task_cache_add (struct worker_task *task, void *pointer, int32_t result);
  * @param pointer regexp data
  * @return numeric result if value exists or -1 if not
  */
-int32_t task_cache_check (struct worker_task *task, void *pointer);
+int32_t task_cache_check (struct worker_task *task, struct rspamd_regexp *re);
 
 /**
  * Parse and return a single function argument for a function (may recurse)
index 5242c008798c6f3300cb1876a298bb5ca2b7eb17..e97454121d9644fac6cc003debc9d021fc5080ea 100644 (file)
@@ -291,7 +291,7 @@ accept_socket (int fd, short what, void *arg)
        memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func)rcpt_destruct, new_task);
        new_task->results = g_hash_table_new (g_str_hash, g_str_equal);
        memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func)g_hash_table_destroy, new_task->results);
-       new_task->re_cache = g_hash_table_new (g_direct_hash, g_direct_equal);
+       new_task->re_cache = g_hash_table_new (g_str_hash, g_str_equal);
        memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func)g_hash_table_destroy, new_task->re_cache);
 
        worker->srv->stat->connections_count ++;