]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Better handling of the legacy protocol
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 25 Nov 2017 13:37:38 +0000 (13:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 10 Dec 2017 17:10:50 +0000 (17:10 +0000)
src/libserver/protocol.c
src/rspamd_proxy.c

index dc96704bd62c816a7f5637d27d8cfdc68326a93a..6e5a60a72c44ca829561384e38e4d2da29777735 100644 (file)
@@ -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 {
@@ -951,28 +951,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");
@@ -981,12 +988,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");
@@ -1011,23 +1012,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));
index 7134c4b526534b96af5497839913e9b158ef5144..7fe62453405e03b0a8042799352fb9332cf67075 100644 (file)
@@ -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"
@@ -1850,16 +1851,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)) {