]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to set Settings-Id for all connections
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Aug 2017 17:54:41 +0000 (18:54 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Aug 2017 18:05:30 +0000 (19:05 +0100)
src/rspamd_proxy.c

index 6474188cc9ed9af20e2ffb11203901f24327d131..3345bd785ea90ee732b28b148bde0bf480bc9769 100644 (file)
@@ -74,6 +74,7 @@ worker_t rspamd_proxy_worker = {
 
 struct rspamd_http_upstream {
        gchar *name;
+       gchar *settings_id;
        struct upstream_list *u;
        struct rspamd_cryptobox_pubkey *key;
        gdouble timeout;
@@ -181,6 +182,7 @@ struct rspamd_proxy_session {
        rspamd_inet_addr_t *client_addr;
        struct rspamd_http_connection *client_conn;
        struct rspamd_milter_session *client_milter_conn;
+       struct rspamd_http_upstream *backend;
        gpointer map;
        gchar *fname;
        gpointer shmem_ref;
@@ -431,6 +433,11 @@ rspamd_proxy_parse_upstream (rspamd_mempool_t *pool,
                ucl_object_todouble_safe (elt, &up->timeout);
        }
 
+       elt = ucl_object_lookup_any (obj, "settings", "settings_id", NULL);
+       if (elt && ucl_object_type (elt) == UCL_STRING) {
+               up->settings_id = rspamd_mempool_strdup (pool, ucl_object_tostring (elt));
+       }
+
        /*
         * Accept lua function here in form
         * fun :: String -> UCL
@@ -1646,6 +1653,12 @@ rspamd_proxy_self_scan (struct rspamd_proxy_session *session)
                        NULL, (event_finalizer_t )rspamd_task_free, task);
        data = rspamd_http_message_get_body (msg, &len);
 
+       if (session->backend->settings_id) {
+               rspamd_http_message_remove_header (msg, "Settings-ID");
+               rspamd_http_message_add_header (msg, "Settings-ID",
+                               session->backend->settings_id);
+       }
+
        /* Process message */
        if (!rspamd_protocol_handle_request (task, msg)) {
                msg_err_task ("cannot handle request: %e", task->err);
@@ -1710,6 +1723,8 @@ proxy_send_master_message (struct rspamd_proxy_session *session)
                goto err;
        }
        else {
+               session->backend = backend;
+
                if (backend->self_scan) {
                        return rspamd_proxy_self_scan (session);
                }
@@ -1765,6 +1780,12 @@ retry:
                                        session->ctx->local_key);
                }
 
+               if (backend->settings_id != NULL) {
+                       rspamd_http_message_remove_header (msg, "Settings-ID");
+                       rspamd_http_message_add_header (msg, "Settings-ID",
+                                       backend->settings_id);
+               }
+
                if (backend->local ||
                                rspamd_inet_address_is_local (
                                                rspamd_upstream_addr (session->master_conn->up), FALSE)) {