]> source.dussan.org Git - rspamd.git/commitdiff
Fix empty messages processing.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 18 Feb 2014 16:55:13 +0000 (16:55 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 18 Feb 2014 16:55:13 +0000 (16:55 +0000)
src/client/rspamc.c
src/lua/lua_task.c
src/protocol.c
src/roll_history.c
src/worker.c
src/worker_util.c

index e7244090be6ee5637895bc3a9e79d13bea2790dc..8defef0f452f388314487d7debe255487f1c2333 100644 (file)
@@ -462,6 +462,9 @@ rspamc_symbols_output (ucl_object_t *obj)
                        rspamd_fprintf (stdout, "Emails: %s\n", emitted);
                        free (emitted);
                }
+               else if (g_ascii_strcasecmp (ucl_object_key (cur), "error") == 0) {
+                       rspamd_fprintf (stdout, "Scan error: %s\n", ucl_object_tostring (cur));
+               }
                else if (cur->type == UCL_OBJECT) {
                        /* Parse metric */
                        rspamc_metric_output (cur);
@@ -511,6 +514,9 @@ rspamc_client_cb (struct rspamd_client_connection *conn,
                }
                ucl_object_unref (result);
        }
+       else if (err != NULL) {
+               rspamd_fprintf (stdout, "%s\n", err->message);
+       }
 
        rspamd_fprintf (stdout, "\n");
        fflush (stdout);
@@ -584,6 +590,7 @@ main (gint argc, gchar **argv, gchar **env)
        if (argc == 1) {
                start_argc = argc;
                in = stdin;
+               cmd = check_rspamc_command ("symbols");
        }
        else if (argc == 2) {
                /* One argument is whether command or filename */
index eadc056623a011886bb9027d3b39c1f94ecf182a..986684b2781c6924b9241828b4226c1cde963351 100644 (file)
@@ -963,7 +963,7 @@ lua_task_get_from_headers (lua_State *L)
        struct worker_task             *task = lua_check_task (L);
        InternetAddressList            *addrs;
 
-       if (task) {
+       if (task && task->message != NULL) {
 #ifndef GMIME24
                addrs = internet_address_parse_string (g_mime_message_get_sender (task->message));
 #else
index 345723fb980f01632523754b6f40b6567fbe1337..1a831aa25e6a33efb696031add44740e1b8aaf27 100644 (file)
@@ -706,7 +706,8 @@ void
 rspamd_protocol_write_reply (struct worker_task *task)
 {
        struct rspamd_http_message    *msg;
-       const gchar                   *ctype = "text/plain";
+       const gchar                   *ctype = "application/json";
+       ucl_object_t                   *top = NULL;
 
        msg = rspamd_http_new_message (HTTP_RESPONSE);
        msg->date = time (NULL);
@@ -716,7 +717,10 @@ rspamd_protocol_write_reply (struct worker_task *task)
        debug_task ("writing reply to client");
        if (task->error_code != 0) {
                msg->code = task->error_code;
-               msg->body = g_string_new (task->last_error);
+               top = ucl_object_insert_key (top, ucl_object_fromstring (task->last_error), "error", 0, false);
+               msg->body = g_string_sized_new (256);
+               rspamd_ucl_emit_gstring (top, UCL_EMIT_JSON_COMPACT, msg->body);
+               ucl_object_unref (top);
        }
        else {
                switch (task->cmd) {
@@ -726,7 +730,6 @@ rspamd_protocol_write_reply (struct worker_task *task)
                case CMD_SYMBOLS:
                case CMD_PROCESS:
                case CMD_SKIP:
-                       ctype = "application/json";
                        write_check_reply (msg, task);
                        break;
                case CMD_PING:
index fb9fe2e0c830011d6b7a318e5c03ae095f8082c4..b189e12d61ad7df4e6189acf742ecf958d519efb 100644 (file)
@@ -142,7 +142,7 @@ rspamd_roll_history_update (struct roll_history *history, struct worker_task *ta
        }
 
        row->scan_time = task->scan_milliseconds;
-       row->len = task->msg->len;
+       row->len = (task->msg == NULL ? 0 : task->msg->len);
        row->completed = TRUE;
 }
 
index 2433965fbb7771384cc5a3627fb004481fd0f293..f322fcf7b8bcfc74ed7c914312a48618b2c82e3f 100644 (file)
@@ -183,6 +183,9 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
 
        if (msg->body->len == 0) {
                msg_err ("got zero length body, cannot continue");
+               task->last_error = "message's body is empty";
+               task->error_code = RSPAMD_LENGTH_ERROR;
+               task->state = WRITE_REPLY;
                return 0;
        }
 
@@ -215,7 +218,7 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
                if (task->cfg->pre_filters == NULL) {
                        r = process_filters (task);
                        if (r == -1) {
-                               task->last_error = "Filter processing error";
+                               task->last_error = "filter processing error";
                                task->error_code = RSPAMD_FILTER_ERROR;
                                task->state = WRITE_REPLY;
                                return 0;
index 65d69aeaada009d59a9858aac4a317e83a9bb35e..f8e1b4b7edc35206f8bf4cb495ea0fecc1c1679e 100644 (file)
@@ -99,6 +99,8 @@ construct_task (struct rspamd_worker *worker)
        new_task->is_mime = TRUE;
        new_task->pre_result.action = METRIC_ACTION_NOACTION;
 
+       new_task->message_id = new_task->queue_id = "undef";
+
        return new_task;
 }