From 485134e78ab625ade8b54f47b70779c49cba2811 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 19 May 2017 16:55:28 +0100 Subject: [PATCH] [Fix] Fix spamc support in rspamd proxy --- src/libserver/protocol.c | 2 +- src/libserver/protocol.h | 3 +++ src/rspamd_proxy.c | 29 +++++++++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 4acf0202d..f322295e0 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -1000,7 +1000,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) { diff --git a/src/libserver/protocol.h b/src/libserver/protocol.h index c0095fedc..40bae4003 100644 --- a/src/libserver/protocol.h +++ b/src/libserver/protocol.h @@ -109,4 +109,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 diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c index 97215d7c4..24da9187e 100644 --- a/src/rspamd_proxy.c +++ b/src/rspamd_proxy.c @@ -144,6 +144,12 @@ struct rspamd_proxy_backend_connection { gint parser_to_ref; }; +enum rspamd_proxy_legacy_support { + LEGACY_SUPPORT_NO = 0, + LEGACY_SUPPORT_RSPAMC, + LEGACY_SUPPORT_SPAMC +}; + struct rspamd_proxy_session { rspamd_mempool_t *pool; struct rspamd_proxy_ctx *ctx; @@ -157,7 +163,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; }; @@ -1171,11 +1177,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; } @@ -1338,7 +1352,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"); } -- 2.39.5