From: Vsevolod Stakhov Date: Sat, 25 Nov 2017 13:37:38 +0000 (+0000) Subject: [Fix] Better handling of the legacy protocol X-Git-Tag: 1.7.0~409 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d2e806d902f1469e87070b340291d21fa04fc26a;p=rspamd.git [Fix] Better handling of the legacy protocol --- diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index bcecceadd..707ec7806 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -583,11 +583,11 @@ rspamd_protocol_handle_request (struct rspamd_task *task, gboolean ret = TRUE; if (msg->method == HTTP_SYMBOLS) { - task->cmd = CMD_SYMBOLS; + task->cmd = CMD_CHECK_V2; task->flags &= ~RSPAMD_TASK_FLAG_JSON; } else if (msg->method == HTTP_CHECK) { - task->cmd = CMD_CHECK; + task->cmd = CMD_CHECK_V2; task->flags &= ~RSPAMD_TASK_FLAG_JSON; } else { @@ -926,28 +926,35 @@ void rspamd_ucl_torspamc_output (const ucl_object_t *top, rspamd_fstring_t **out) { - const ucl_object_t *metric, *score, + const ucl_object_t *symbols, *score, *required_score, *is_spam, *elt, *cur; ucl_object_iter_t iter = NULL; - metric = ucl_object_lookup (top, DEFAULT_METRIC); - if (metric != NULL) { - score = ucl_object_lookup (metric, "score"); - required_score = ucl_object_lookup (metric, "required_score"); - is_spam = ucl_object_lookup (metric, "is_spam"); - rspamd_printf_fstring (out, + score = ucl_object_lookup (top, "score"); + required_score = ucl_object_lookup (top, "required_score"); + is_spam = ucl_object_lookup (top, "is_spam"); + rspamd_printf_fstring (out, "Metric: default; %s; %.2f / %.2f / 0.0\r\n", ucl_object_toboolean (is_spam) ? "True" : "False", ucl_object_todouble (score), ucl_object_todouble (required_score)); - elt = ucl_object_lookup (metric, "action"); - if (elt != NULL) { - rspamd_printf_fstring (out, "Action: %s\r\n", + elt = ucl_object_lookup (top, "action"); + if (elt != NULL) { + rspamd_printf_fstring (out, "Action: %s\r\n", ucl_object_tostring (elt)); - } + } + + elt = ucl_object_lookup (top, "subject"); + if (elt != NULL) { + rspamd_printf_fstring (out, "Subject: %s\r\n", + ucl_object_tostring (elt)); + } + + symbols = ucl_object_lookup (top, "symbols"); + if (symbols != NULL) { iter = NULL; - while ((elt = ucl_object_iterate (metric, &iter, true)) != NULL) { + while ((elt = ucl_object_iterate (symbols, &iter, true)) != NULL) { if (elt->type == UCL_OBJECT) { const ucl_object_t *sym_score; sym_score = ucl_object_lookup (elt, "score"); @@ -956,12 +963,6 @@ rspamd_ucl_torspamc_output (const ucl_object_t *top, ucl_object_todouble (sym_score)); } } - - elt = ucl_object_lookup (metric, "subject"); - if (elt != NULL) { - rspamd_printf_fstring (out, "Subject: %s\r\n", - ucl_object_tostring (elt)); - } } elt = ucl_object_lookup (top, "messages"); @@ -986,23 +987,24 @@ void rspamd_ucl_tospamc_output (const ucl_object_t *top, rspamd_fstring_t **out) { - const ucl_object_t *metric, *score, + const ucl_object_t *symbols, *score, *required_score, *is_spam, *elt; ucl_object_iter_t iter = NULL; rspamd_fstring_t *f; - metric = ucl_object_lookup (top, DEFAULT_METRIC); - if (metric != NULL) { - score = ucl_object_lookup (metric, "score"); - required_score = ucl_object_lookup (metric, "required_score"); - is_spam = ucl_object_lookup (metric, "is_spam"); - rspamd_printf_fstring (out, + score = ucl_object_lookup (top, "score"); + required_score = ucl_object_lookup (top, "required_score"); + is_spam = ucl_object_lookup (top, "is_spam"); + rspamd_printf_fstring (out, "Spam: %s ; %.2f / %.2f\r\n\r\n", ucl_object_toboolean (is_spam) ? "True" : "False", ucl_object_todouble (score), ucl_object_todouble (required_score)); - while ((elt = ucl_object_iterate (metric, &iter, true)) != NULL) { + symbols = ucl_object_lookup (top, "symbols"); + + if (symbols != NULL) { + while ((elt = ucl_object_iterate (symbols, &iter, true)) != NULL) { if (elt->type == UCL_OBJECT) { rspamd_printf_fstring (out, "%s,", ucl_object_key (elt)); diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 5b2206be4..12b14bc92 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -20,6 +20,7 @@ #include "libutil/http.h" #include "libutil/http_private.h" #include "libserver/protocol.h" +#include "libserver/protocol_internal.h" #include "libserver/cfg_file.h" #include "libserver/url.h" #include "libserver/dns.h" @@ -1885,16 +1886,17 @@ proxy_client_finish_handler (struct rspamd_http_connection *conn, if (msg->flags & RSPAMD_HTTP_FLAG_SPAMC) { session->legacy_support = LEGACY_SUPPORT_SPAMC; + msg_info_session ("enabling legacy spamc mode for session"); } else { - session->legacy_support = LEGACY_SUPPORT_SPAMC; + session->legacy_support = LEGACY_SUPPORT_RSPAMC; + msg_info_session ("enabling legacy rspamc mode for session"); } - - msg_info_session ("enabling legacy rspamc mode for session"); } if (msg->url->len == 0) { - msg->url = rspamd_fstring_append (msg->url, "/check", strlen ("/check")); + msg->url = rspamd_fstring_append (msg->url, + "/" MSG_CMD_CHECK_V2, strlen ("/" MSG_CMD_CHECK_V2)); } if (!proxy_check_file (msg, session)) {