]> source.dussan.org Git - rspamd.git/commitdiff
Cache data of parts distance function to speed up multiply rules with such function.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 12 Jul 2011 14:35:47 +0000 (18:35 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 12 Jul 2011 14:35:47 +0000 (18:35 +0400)
src/cfg_file.h
src/expressions.c

index 268906d40216c3af50801974591aa104e9bb696d..7e2dfd413d46539cc795ef811f337c43cb1d0c9f 100644 (file)
@@ -189,6 +189,8 @@ struct statfile {
     statfile_normalize_func normalizer;             /**< function that is used as normaliser                */
     void *normalizer_data;                          /**< normalizer function params                         */
        gchar *normalizer_str;                                                  /**< source string (for dump)                                                   */
+       GHashTable *opts;                                                               /**< different statfile options                                                 */
+       gboolean is_spam;                                                               /**< spam flag                                                                                  */
 };
 
 /**
index fa6ce0fefa578469770e9a05b7ffa758e4fdc8ca..d330526def6083b88131df2ba2e212caf29e3c87 100644 (file)
@@ -1016,7 +1016,7 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused)
        struct expression_argument     *arg;
        GMimeObject                    *parent;
        const GMimeContentType         *ct;
-
+       gint                           *pdiff;
 
        if (args == NULL) {
                debug_task ("no threshold is specified, assume it 100");
@@ -1032,10 +1032,23 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused)
                }
        }
 
+       if ((pdiff = memory_pool_get_variable (task->task_pool, "parts_distance")) != NULL) {
+               diff = *pdiff;
+               if (diff != -1 && diff <= threshold) {
+                       return TRUE;
+               }
+               else {
+                       return FALSE;
+               }
+       }
+
        if (g_list_length (task->text_parts) == 2) {
                cur = g_list_first (task->text_parts);
                p1 = cur->data;
                cur = g_list_next (cur);
+               pdiff = memory_pool_alloc (task->task_pool, sizeof (gint));
+               *pdiff = -1;
+
                if (cur == NULL) {
                        msg_info ("bad parts list");
                        return FALSE;
@@ -1051,30 +1064,38 @@ rspamd_parts_distance (struct worker_task * task, GList * args, void *unused)
                        if (ct == NULL || ! g_mime_content_type_is_type ((GMimeContentType *)ct, "multipart", "alternative")) {
 #endif
                                debug_task ("two parts are not belong to multipart/alternative container, skip check");
+                               memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL);
                                return FALSE;
                        }
                }
                else {
                        debug_task ("message contains two parts but they are in different multi-parts");
+                       memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL);
                        return FALSE;
                }
                if (!p1->is_empty && !p2->is_empty) {
                        diff = fuzzy_compare_parts (p1, p2);
                        debug_task ("got likeliness between parts of %d%%, threshold is %d%%", diff, threshold);
+                       *pdiff = diff;
+                       memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL);
                        if (diff <= threshold) {
                                return TRUE;
                        }
                }
                else if ((p1->is_empty && !p2->is_empty) || (!p1->is_empty && p2->is_empty)) {
                        /* Empty and non empty parts are different */
+                       *pdiff = 0;
+                       memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL);
                        return TRUE;
                }
        }
        else {
                debug_task ("message has too many text parts, so do not try to compare them with each other");
+               memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL);
                return FALSE;
        }
 
+       memory_pool_set_variable (task->task_pool, "parts_distance", pdiff, NULL);
        return FALSE;
 }