]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow empty tasks to be processed
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Apr 2016 17:44:39 +0000 (18:44 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 21 Apr 2016 17:44:39 +0000 (18:44 +0100)
src/libmime/message.c
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h
src/libserver/task.c
src/libserver/task.h

index 6b6af40e3979518cc585a65a335147008eea03b1..1f218e8b7ce796cb8ebef170c45b946f5824287e 100644 (file)
@@ -1569,6 +1569,12 @@ rspamd_message_parse (struct rspamd_task *task)
        gint diff, *pdiff, i;
        guint tw, dw;
 
+       if (RSPAMD_TASK_IS_EMPTY (task)) {
+               /* Don't do anything with empty task */
+
+               return TRUE;
+       }
+
        tmp = rspamd_mempool_alloc (task->task_pool, sizeof (GByteArray));
        p = task->msg.begin;
        len = task->msg.len;
index 8b530cefee88fb1387e53b80da17e8b52d0967d7..717018e2503cefc71a2fa29683dd66201052156d 100644 (file)
@@ -1086,7 +1086,10 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
                /* Check has been started */
                setbit (checkpoint->processed_bits, item->id * 2);
 
-               if (item->condition_cb != -1) {
+               if (RSPAMD_TASK_IS_EMPTY (task) && !(item->type & SYMBOL_TYPE_EMPTY)) {
+                       check = FALSE;
+               }
+               else if (item->condition_cb != -1) {
                        /* We also executes condition callback to check if we need this symbol */
                        L = task->cfg->lua_state;
                        lua_rawgeti (L, LUA_REGISTRYINDEX, item->condition_cb);
index 692d6c060fe0b71d7993ab812bad5096dcc95de6..56008d2c18f8bfd2c1fb36766b04d7d2a633752c 100644 (file)
@@ -35,7 +35,8 @@ enum rspamd_symbol_type {
        SYMBOL_TYPE_SKIPPED = (1 << 4),
        SYMBOL_TYPE_COMPOSITE = (1 << 5),
        SYMBOL_TYPE_CLASSIFIER = (1 << 6),
-       SYMBOL_TYPE_FINE = (1 << 7)
+       SYMBOL_TYPE_FINE = (1 << 7),
+       SYMBOL_TYPE_EMPTY = (1 << 8) /* Allow execution on empty tasks */
 };
 
 /**
index bf337cbaa323651576331352cb75d46a4ec11407..492a69d720ca1a195954480dd8281284ad24ecb2 100644 (file)
@@ -326,11 +326,7 @@ rspamd_task_load_message (struct rspamd_task *task,
                task->msg.len = len;
 
                if (task->msg.len == 0) {
-                       msg_warn_task ("message has invalid message length: %uz",
-                                       task->msg.len);
-                       g_set_error (&task->err, rspamd_task_quark(), RSPAMD_PROTOCOL_ERROR,
-                                       "Invalid length");
-                       return FALSE;
+                       task->flags |= RSPAMD_TASK_FLAG_EMPTY;
                }
 
                if (task->flags & RSPAMD_TASK_FLAG_HAS_CONTROL) {
@@ -447,10 +443,12 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
        case RSPAMD_TASK_STAGE_CLASSIFIERS:
        case RSPAMD_TASK_STAGE_CLASSIFIERS_PRE:
        case RSPAMD_TASK_STAGE_CLASSIFIERS_POST:
-               if (rspamd_stat_classify (task, task->cfg->lua_state, st, &stat_error) ==
-                               RSPAMD_STAT_PROCESS_ERROR) {
-                       msg_err_task ("classify error: %e", stat_error);
-                       g_error_free (stat_error);
+               if (!RSPAMD_TASK_IS_EMPTY (task)) {
+                       if (rspamd_stat_classify (task, task->cfg->lua_state, st, &stat_error) ==
+                                       RSPAMD_STAT_PROCESS_ERROR) {
+                               msg_err_task ("classify error: %e", stat_error);
+                               g_error_free (stat_error);
+                       }
                }
                break;
 
@@ -460,7 +458,8 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
 
        case RSPAMD_TASK_STAGE_POST_FILTERS:
                rspamd_lua_call_post_filters (task);
-               if (task->flags & RSPAMD_TASK_FLAG_LEARN_AUTO) {
+               if ((task->flags & RSPAMD_TASK_FLAG_LEARN_AUTO) &&
+                               !RSPAMD_TASK_IS_EMPTY (task)) {
                        rspamd_stat_check_autolearn (task);
                }
                break;
index c27d4bcb5d42d416e7d45d7201785dc2e6fd25cc..40ece993f10f4f0e8703db886658302802e5503f 100644 (file)
@@ -102,12 +102,14 @@ enum rspamd_task_stage {
 #define RSPAMD_TASK_FLAG_BROKEN_HEADERS (1 << 19)
 #define RSPAMD_TASK_FLAG_HAS_SPAM_TOKENS (1 << 20)
 #define RSPAMD_TASK_FLAG_HAS_HAM_TOKENS (1 << 21)
+#define RSPAMD_TASK_FLAG_EMPTY (1 << 22)
 
 #define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP))
 #define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))
 #define RSPAMD_TASK_IS_SPAMC(task) (((task)->flags & RSPAMD_TASK_FLAG_SPAMC))
 #define RSPAMD_TASK_IS_PROCESSED(task) (((task)->processed_stages & RSPAMD_TASK_STAGE_DONE))
 #define RSPAMD_TASK_IS_CLASSIFIED(task) (((task)->processed_stages & RSPAMD_TASK_STAGE_CLASSIFIERS))
+#define RSPAMD_TASK_IS_EMPTY(task) (((task)->flags & RSPAMD_TASK_FLAG_EMPTY))
 
 /**
  * Worker task structure