]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix redefining of `one_shot` and other `nshots` related attrs
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Nov 2019 15:55:17 +0000 (15:55 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Nov 2019 15:55:17 +0000 (15:55 +0000)
src/libserver/cfg_rcl.c
src/libserver/cfg_utils.c

index e4924ae20b324bb000ed699199a10dbf45ab4845..c7d414df4d82de60bddd7a00f3be074cc0eb636f 100644 (file)
@@ -456,11 +456,10 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
        const gchar *description = NULL;
        gdouble score = NAN;
        guint priority = 1, flags = 0;
-       gint nshots;
+       gint nshots = 0;
 
        g_assert (key != NULL);
        cfg = sd->cfg;
-       nshots = cfg->default_max_shots;
 
        if ((elt = ucl_object_lookup (obj, "one_shot")) != NULL) {
                if (ucl_object_type (elt) != UCL_BOOLEAN) {
index 59840847b754ceed8af78725db6b521374fc2c2b..ba009cc8184621376e2d7b92f2c19e4153ce6957 100644 (file)
@@ -1598,7 +1598,7 @@ rspamd_config_new_symbol (struct rspamd_config *cfg, const gchar *symbol,
        sym_def->weight_ptr = score_ptr;
        sym_def->name = rspamd_mempool_strdup (cfg->cfg_pool, symbol);
        sym_def->flags = flags;
-       sym_def->nshots = nshots;
+       sym_def->nshots = nshots != 0 ? nshots : cfg->default_max_shots;
        sym_def->groups = g_ptr_array_sized_new (1);
        rspamd_mempool_add_destructor (cfg->cfg_pool, rspamd_ptr_array_free_hard,
                        sym_def->groups);
@@ -1700,6 +1700,11 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
                                                description);
                        }
 
+                       /* Or nshots in case of non-default setting */
+                       if (nshots != 0 && sym_def->nshots == cfg->default_max_shots) {
+                               sym_def->nshots = nshots;
+                       }
+
                        return FALSE;
                }
                else {
@@ -1720,7 +1725,16 @@ rspamd_config_add_symbol (struct rspamd_config *cfg,
                        }
 
                        sym_def->flags = flags;
-                       sym_def->nshots = nshots;
+
+                       if (nshots != 0) {
+                               sym_def->nshots = nshots;
+                       }
+                       else {
+                               /* Do not reset unless we have exactly lower priority */
+                               if (sym_def->priority < priority) {
+                                       sym_def->nshots = cfg->default_max_shots;
+                               }
+                       }
 
                        if (description) {
                                sym_def->description = rspamd_mempool_strdup (cfg->cfg_pool,