summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-06-02 15:34:43 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-06-02 15:39:37 +0100
commit5b79e6254fffc507db1f537f38deaf3b7678369b (patch)
treef2482e31bfc8c7717b36fa49def83e8f5a383fb1
parent14c2ac408c9ce0284367c463f443aa1c0f1249cc (diff)
downloadrspamd-5b79e6254fffc507db1f537f38deaf3b7678369b.tar.gz
rspamd-5b79e6254fffc507db1f537f38deaf3b7678369b.zip
Restore build.
-rw-r--r--src/controller.c55
-rw-r--r--src/libmime/filter.c60
-rw-r--r--src/libserver/protocol.c2
-rw-r--r--src/libserver/task.h3
-rw-r--r--src/worker.c27
5 files changed, 43 insertions, 104 deletions
diff --git a/src/controller.c b/src/controller.c
index 73a563340..18ce87cd0 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -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;
}
diff --git a/src/libmime/filter.c b/src/libmime/filter.c
index 83dc24dc3..8fde0823c 100644
--- a/src/libmime/filter.c
+++ b/src/libmime/filter.c
@@ -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)
{
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index acdf1129a..9549ea047 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -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
diff --git a/src/libserver/task.h b/src/libserver/task.h
index 3a1d11458..295ac76c3 100644
--- a/src/libserver/task.h
+++ b/src/libserver/task.h
@@ -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 | \
diff --git a/src/worker.c b/src/worker.c
index f723c2f47..3d9c7dabe 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -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;
}