From c7283f8e50304ec0e0efa13a674ebe867f51be07 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 18 Feb 2014 16:55:13 +0000 Subject: [PATCH] Fix empty messages processing. --- src/client/rspamc.c | 7 +++++++ src/lua/lua_task.c | 2 +- src/protocol.c | 9 ++++++--- src/roll_history.c | 2 +- src/worker.c | 5 ++++- src/worker_util.c | 2 ++ 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/client/rspamc.c b/src/client/rspamc.c index e7244090b..8defef0f4 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -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 */ diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index eadc05662..986684b27 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -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 diff --git a/src/protocol.c b/src/protocol.c index 345723fb9..1a831aa25 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -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: diff --git a/src/roll_history.c b/src/roll_history.c index fb9fe2e0c..b189e12d6 100644 --- a/src/roll_history.c +++ b/src/roll_history.c @@ -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; } diff --git a/src/worker.c b/src/worker.c index 2433965fb..f322fcf7b 100644 --- a/src/worker.c +++ b/src/worker.c @@ -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; diff --git a/src/worker_util.c b/src/worker_util.c index 65d69aeaa..f8e1b4b7e 100644 --- a/src/worker_util.c +++ b/src/worker_util.c @@ -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; } -- 2.39.5