diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-30 13:41:32 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-03-30 13:41:32 +0100 |
commit | 69d84ae579a7817e5fac0c64cab4fd3b3d6b1470 (patch) | |
tree | 0233f6520ff2cd2a1ac21a30869738582f12dd3a /src | |
parent | bd61e464bc4a9728429859948d76e2e9303b7d55 (diff) | |
download | rspamd-69d84ae579a7817e5fac0c64cab4fd3b3d6b1470.tar.gz rspamd-69d84ae579a7817e5fac0c64cab4fd3b3d6b1470.zip |
Load control chunk.
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/protocol.c | 3 | ||||
-rw-r--r-- | src/libserver/task.c | 33 | ||||
-rw-r--r-- | src/libserver/task.h | 2 |
3 files changed, 37 insertions, 1 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 08e7bc3c3..1f5b1f447 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -397,6 +397,9 @@ rspamd_protocol_handle_headers (struct rspamd_task *task, msg_err ("Invalid message length header: %s", h->value->str); validh = FALSE; } + else { + task->flags |= RSPAMD_TASK_FLAG_HAS_CONTROL; + } } else { validh = FALSE; diff --git a/src/libserver/task.c b/src/libserver/task.c index be6bd134c..4c8934ada 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -309,6 +309,9 @@ rspamd_task_process (struct rspamd_task *task, gboolean process_extra_filters) { gint r; + guint control_len; + struct ucl_parser *parser; + ucl_object_t *control_obj; GError *err = NULL; task->msg.start = start; @@ -320,6 +323,36 @@ rspamd_task_process (struct rspamd_task *task, rspamd_protocol_handle_headers (task, msg); + if (task->flags & RSPAMD_TASK_FLAG_HAS_CONTROL) { + /* We have control chunk, so we need to process it separately */ + if (task->msg.len < task->message_len) { + msg_warn ("message has invalid message length: %ud and total len: %ud", + task->message_len, task->msg.len); + task->last_error = "Invalid length"; + task->error_code = RSPAMD_PROTOCOL_ERROR; + task->state = WRITE_REPLY; + return FALSE; + } + control_len = task->msg.len - task->message_len; + + if (control_len > 0) { + parser = ucl_parser_new (UCL_PARSER_KEY_LOWERCASE); + + if (!ucl_parser_add_chunk (parser, task->msg.start, control_len)) { + msg_warn ("processing of control chunk failed: %s", + ucl_parser_get_error (parser)); + ucl_parser_free (parser); + } + else { + control_obj = ucl_parser_get_object (parser); + ucl_parser_free (parser); + } + + task->msg.start += control_len; + task->msg.len -= control_len; + } + } + r = process_message (task); if (r == -1) { msg_warn ("processing of message failed"); diff --git a/src/libserver/task.h b/src/libserver/task.h index 52c45c9d4..d4f92fd8d 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -60,7 +60,7 @@ enum rspamd_metric_action { #define RSPAMD_TASK_FLAG_PASS_ALL (1 << 6) #define RSPAMD_TASK_FLAG_NO_LOG (1 << 7) #define RSPAMD_TASK_FLAG_NO_IP (1 << 8) -#define RSPAMD_TASK_FLAG_HAS_JSON (1 << 9) +#define RSPAMD_TASK_FLAG_HAS_CONTROL (1 << 9) #define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP)) #define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON)) |