]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix spamc support in rspamd proxy
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 19 May 2017 15:55:28 +0000 (16:55 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 19 May 2017 15:55:28 +0000 (16:55 +0100)
src/libserver/protocol.c
src/libserver/protocol.h
src/rspamd_proxy.c

index 7a9a74afa03deea6c814c5314229f9ea0e417494..1602ab76fcc9a76c2d5ac0815cf4801a7d2a380a 100644 (file)
@@ -988,7 +988,7 @@ rspamd_ucl_torspamc_output (const ucl_object_t *top,
        }
 }
 
-static void
+void
 rspamd_ucl_tospamc_output (const ucl_object_t *top,
        rspamd_fstring_t **out)
 {
index 3b7dabc731e9b631b4d85fa62dd3dd9c649d22d6..254c5fcd19e0385e89b74c23bdfe0a26b91b65f4 100644 (file)
@@ -114,4 +114,7 @@ void rspamd_protocol_write_reply (struct rspamd_task *task);
 void rspamd_ucl_torspamc_output (const ucl_object_t *top,
        rspamd_fstring_t **out);
 
+void  rspamd_ucl_tospamc_output (const ucl_object_t *top,
+               rspamd_fstring_t **out);
+
 #endif
index e9858b0ba1d5884c8bc18b57b204b8080f2c2ba8..2365eb9b611628890988410c182e7500d322c35c 100644 (file)
@@ -156,6 +156,12 @@ struct rspamd_proxy_backend_connection {
        struct rspamd_task *task;
 };
 
+enum rspamd_proxy_legacy_support {
+       LEGACY_SUPPORT_NO = 0,
+       LEGACY_SUPPORT_RSPAMC,
+       LEGACY_SUPPORT_SPAMC
+};
+
 struct rspamd_proxy_session {
        struct rspamd_worker *worker;
        rspamd_mempool_t *pool;
@@ -171,7 +177,7 @@ struct rspamd_proxy_session {
        GPtrArray *mirror_conns;
        gsize map_len;
        gint client_sock;
-       gboolean is_spamc;
+       enum rspamd_proxy_legacy_support legacy_support;
        gint retries;
        ref_entry_t ref;
 };
@@ -1387,11 +1393,19 @@ proxy_backend_master_finish_handler (struct rspamd_http_connection *conn,
        }
 
 
-       if (session->is_spamc) {
+       if (session->legacy_support > LEGACY_SUPPORT_NO) {
                /* We need to reformat ucl to fit with legacy spamc protocol */
                if (bk_conn->results) {
                        reply = rspamd_fstring_new ();
-                       rspamd_ucl_torspamc_output (bk_conn->results, &reply);
+
+                       if (session->legacy_support == LEGACY_SUPPORT_SPAMC) {
+                               rspamd_ucl_tospamc_output (bk_conn->results, &reply);
+                               msg->flags |= RSPAMD_HTTP_FLAG_SPAMC;
+                       }
+                       else {
+                               rspamd_ucl_torspamc_output (bk_conn->results, &reply);
+                       }
+
                        rspamd_http_message_set_body_from_fstring_steal (msg, reply);
                        msg->method = HTTP_SYMBOLS;
                }
@@ -1736,7 +1750,14 @@ proxy_client_finish_handler (struct rspamd_http_connection *conn,
                /* Reset spamc legacy */
                if (msg->method >= HTTP_SYMBOLS) {
                        msg->method = HTTP_GET;
-                       session->is_spamc = TRUE;
+
+                       if (msg->flags & RSPAMD_HTTP_FLAG_SPAMC) {
+                               session->legacy_support = LEGACY_SUPPORT_SPAMC;
+                       }
+                       else {
+                               session->legacy_support = LEGACY_SUPPORT_SPAMC;
+                       }
+
                        msg_info_session ("enabling legacy rspamc mode for session");
                }