]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Restore build.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 2 Jun 2015 14:34:43 +0000 (15:34 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 2 Jun 2015 14:39:37 +0000 (15:39 +0100)
src/controller.c
src/libmime/filter.c
src/libserver/protocol.c
src/libserver/task.h
src/worker.c

index 73a563340f7103cfe3c5467a135d67c293d3657c..18ce87cd085ce1ea5974a1a3ace4010982b64f8e 100644 (file)
@@ -942,19 +942,24 @@ rspamd_controller_check_fin_task (void *ud)
        struct rspamd_http_connection_entry *conn_ent;
        struct rspamd_http_message *msg;
 
-       rspamd_process_statistics (task);
-       conn_ent = task->fin_arg;
-       msg = rspamd_http_new_message (HTTP_RESPONSE);
-       msg->date = time (NULL);
-       msg->code = 200;
-       rspamd_protocol_http_reply (msg, task);
-       rspamd_http_connection_reset (conn_ent->conn);
-       rspamd_http_connection_write_message (conn_ent->conn, msg, NULL,
-               "application/json", conn_ent, conn_ent->conn->fd, conn_ent->rt->ptv,
-               conn_ent->rt->ev_base);
-       conn_ent->is_reply = TRUE;
+       /* Task is already finished or skipped */
+       if (RSPAMD_TASK_IS_PROCESSED (task) || !rspamd_task_process (task,
+                       RSPAMD_TASK_PROCESS_ALL)) {
+               conn_ent = task->fin_arg;
+               msg = rspamd_http_new_message (HTTP_RESPONSE);
+               msg->date = time (NULL);
+               msg->code = 200;
+               rspamd_protocol_http_reply (msg, task);
+               rspamd_http_connection_reset (conn_ent->conn);
+               rspamd_http_connection_write_message (conn_ent->conn, msg, NULL,
+                               "application/json", conn_ent, conn_ent->conn->fd, conn_ent->rt->ptv,
+                               conn_ent->rt->ev_base);
+               conn_ent->is_reply = TRUE;
+               return TRUE;
+       }
 
-       return TRUE;
+       /* One more iteration */
+       return FALSE;
 }
 
 static int
@@ -1005,10 +1010,15 @@ rspamd_controller_handle_learn_common (
        task->sock = conn_ent->conn->fd;
 
 
-       /* XXX: Handle encrypted messages */
-       if (!rspamd_task_process (task, msg, msg->body->str, msg->body->len, FALSE)) {
-               msg_warn ("filters cannot be processed for %s", task->message_id);
-               rspamd_controller_send_error (conn_ent, 500, task->last_error);
+       if (!rspamd_task_load_message (task, msg, msg->body->str, msg->body->len)) {
+               rspamd_controller_send_error (conn_ent, task->err->code, task->err->message);
+               rspamd_session_destroy (task->s);
+               return 0;
+       }
+
+       if (!rspamd_task_process (task, RSPAMD_TASK_PROCESS_LEARN)) {
+               msg_warn ("message cannot be processed for %s", task->message_id);
+               rspamd_controller_send_error (conn_ent, task->err->code, task->err->message);
                rspamd_session_destroy (task->s);
                return 0;
        }
@@ -1094,10 +1104,15 @@ rspamd_controller_handle_scan (struct rspamd_http_connection_entry *conn_ent,
        task->http_conn = rspamd_http_connection_ref (conn_ent->conn);
        task->sock = conn_ent->conn->fd;
 
-       /* XXX: handle encrypted messages */
-       if (!rspamd_task_process (task, msg, msg->body->str, msg->body->len, FALSE)) {
-               msg_warn ("filters cannot be processed for %s", task->message_id);
-               rspamd_controller_send_error (conn_ent, 500, task->last_error);
+       if (!rspamd_task_load_message (task, msg, msg->body->str, msg->body->len)) {
+               rspamd_controller_send_error (conn_ent, task->err->code, task->err->message);
+               rspamd_session_destroy (task->s);
+               return 0;
+       }
+
+       if (!rspamd_task_process (task, RSPAMD_TASK_PROCESS_ALL)) {
+               msg_warn ("message cannot be processed for %s", task->message_id);
+               rspamd_controller_send_error (conn_ent, task->err->code, task->err->message);
                rspamd_session_destroy (task->s);
                return 0;
        }
index 83dc24dc3ba4136340e525bbdc551ebf1d252362..8fde0823c71f271bd135d5bd004ccc8309c33f58 100644 (file)
@@ -297,66 +297,6 @@ rspamd_task_insert_result_single (struct rspamd_task *task,
        insert_result_common (task, symbol, flag, opts, TRUE);
 }
 
-static void
-insert_metric_header (gpointer metric_name, gpointer metric_value,
-       gpointer data)
-{
-#ifndef GLIB_HASH_COMPAT
-       struct rspamd_task *task = (struct rspamd_task *)data;
-       gint r = 0;
-       /* Try to be rfc2822 compatible and avoid long headers with folding */
-       gchar header_name[128], outbuf[1000];
-       GList *symbols = NULL, *cur;
-       struct metric_result *metric_res = (struct metric_result *)metric_value;
-       double ms;
-
-       rspamd_snprintf (header_name,
-               sizeof (header_name),
-               "X-Spam-%s",
-               metric_res->metric->name);
-
-       if (!check_metric_settings (task, metric_res->metric, &ms)) {
-               ms = metric_res->metric->actions[METRIC_ACTION_REJECT].score;
-       }
-       if (ms > 0 && metric_res->score >= ms) {
-               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r,
-                               "yes; %.2f/%.2f/%.2f; ", metric_res->score, ms, ms);
-       }
-       else {
-               r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r,
-                               "no; %.2f/%.2f/%.2f; ", metric_res->score, ms, ms);
-       }
-
-       symbols = g_hash_table_get_keys (metric_res->symbols);
-       cur = symbols;
-       while (cur) {
-               if (g_list_next (cur) != NULL) {
-                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r,
-                                       "%s,", (gchar *)cur->data);
-               }
-               else {
-                       r += rspamd_snprintf (outbuf + r, sizeof (outbuf) - r,
-                                       "%s", (gchar *)cur->data);
-               }
-               cur = g_list_next (cur);
-       }
-       g_list_free (symbols);
-#ifdef GMIME24
-       g_mime_object_append_header (GMIME_OBJECT (
-                       task->message), header_name, outbuf);
-#else
-       g_mime_message_add_header (task->message, header_name, outbuf);
-#endif
-
-#endif /* GLIB_COMPAT */
-}
-
-void
-insert_headers (struct rspamd_task *task)
-{
-       g_hash_table_foreach (task->results, insert_metric_header, task);
-}
-
 gboolean
 rspamd_action_from_str (const gchar *data, gint *result)
 {
index acdf1129a8150ae19be68f14c4d983a41b8a15f4..9549ea047529681eee29f6fe7e7b54be0db687cb 100644 (file)
@@ -1147,6 +1147,8 @@ rspamd_protocol_write_reply (struct rspamd_task *task)
        rspamd_http_connection_reset (task->http_conn);
        rspamd_http_connection_write_message (task->http_conn, msg, NULL,
                ctype, task, task->sock, &task->tv, task->ev_base);
+
+       task->processed_stages |= RSPAMD_TASK_STAGE_REPLIED;
 }
 
 void
index 3a1d114583a3f0759e68e2c20bcf0c567171b47b..295ac76c39c3534b7d2c8f0f3b57731c6fc3ee5b 100644 (file)
@@ -60,7 +60,8 @@ enum rspamd_task_stage {
        RSPAMD_TASK_STAGE_CLASSIFIERS = (1 << 5),
        RSPAMD_TASK_STAGE_COMPOSITES = (1 << 6),
        RSPAMD_TASK_STAGE_POST_FILTERS = (1 << 7),
-       RSPAMD_TASK_STAGE_DONE = (1 << 8)
+       RSPAMD_TASK_STAGE_DONE = (1 << 8),
+       RSPAMD_TASK_STAGE_REPLIED = (1 << 9)
 };
 
 #define RSPAMD_TASK_PROCESS_ALL (RSPAMD_TASK_STAGE_CONNECT | \
index f723c2f47f5c07196add51f4f377faa49b3f308b..3d9c7dabeeb0310481ac206348115c62a511b4c0 100644 (file)
@@ -106,8 +106,6 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
 
        ctx = task->worker->ctx;
 
-       task->state = WRITE_REPLY;
-
        if (!rspamd_protocol_handle_request (task, msg)) {
                return 0;
        }
@@ -116,15 +114,12 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
                return 0;
        }
 
-       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;
-
+       if (!rspamd_task_load_message (task, msg, chunk, len)) {
+               rspamd_session_destroy (task->s);
                return 0;
        }
 
-       rspamd_task_process (task, msg, chunk, len, TRUE);
+       rspamd_task_process (task, RSPAMD_TASK_PROCESS_ALL);
 
        return 0;
 }
@@ -146,26 +141,12 @@ rspamd_worker_finish_handler (struct rspamd_http_connection *conn,
 {
        struct rspamd_task *task = (struct rspamd_task *) conn->ud;
 
-       if (task->state == CLOSING_CONNECTION || task->state == WRITING_REPLY) {
+       if (task->processed_stages & RSPAMD_TASK_STAGE_REPLIED) {
                /* We are done here */
                msg_debug ("normally closing connection from: %s",
                        rspamd_inet_address_to_string (task->client_addr));
                rspamd_session_destroy (task->s);
        }
-       else if (task->state == WRITE_REPLY) {
-               /*
-                * We can come here if no filters has delayed their job and we want to
-                * write reply immediately. But this handler is executed when message
-                * is read
-                */
-               msg_debug ("want write message to the wire: %s",
-                       rspamd_inet_address_to_string (task->client_addr));
-               /*
-                * If all filters have finished their tasks, this function will trigger
-                * writing a reply.
-                */
-               rspamd_session_pending (task->s);
-       }
 
        return 0;
 }