]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add `one_param` flag for metric symbols
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 27 Oct 2016 08:32:45 +0000 (10:32 +0200)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 27 Oct 2016 08:32:45 +0000 (10:32 +0200)
src/libmime/filter.c
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/lua/lua_config.c
src/plugins/regexp.c

index 5b998406f9bcf356a1e3c9a427f81b20048158cb..a1dae9f5ca64a5f5dc957b8c06f606f2a16bbed1 100644 (file)
@@ -142,7 +142,8 @@ insert_metric_result (struct rspamd_task *task,
                         */
                        single = TRUE;
                }
-               if (s->options && opts && opts != s->options) {
+               if (s->options && opts && opts != s->options &&
+                               !(sdef->flags & RSPAMD_SYMBOL_FLAG_ONEPARAM)) {
                        /* Append new options */
                        s->options = g_list_concat (s->options, g_list_copy (opts));
                        /*
index d10ce235df971bb1d46a66386656e05321e6a6c2..1ca6118a5c16e0e7d6019023a546da13935ac4f9 100644 (file)
@@ -96,6 +96,7 @@ struct rspamd_symbols_group {
 
 #define RSPAMD_SYMBOL_FLAG_ONESHOT (1 << 0)
 #define RSPAMD_SYMBOL_FLAG_IGNORE (1 << 1)
+#define RSPAMD_SYMBOL_FLAG_ONEPARAM (1 << 2)
 
 /**
  * Symbol definition
index 5cfd73ee30b203a8d17f6d34f0e30a769f7173a1..a260ca99a6d3593f80ec5d4a7f63402b47bbc7b8 100644 (file)
@@ -349,6 +349,12 @@ rspamd_rcl_symbol_handler (rspamd_mempool_t *pool, const ucl_object_t *obj,
                }
        }
 
+       if ((elt = ucl_object_lookup (obj, "one_param")) != NULL) {
+               if (ucl_object_toboolean (elt)) {
+                       flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
+               }
+       }
+
        if ((elt = ucl_object_lookup (obj, "ignore")) != NULL) {
                if (ucl_object_toboolean (elt)) {
                        flags |= RSPAMD_SYMBOL_FLAG_IGNORE;
index 915666a7d13fb6a55c8c53b9dd5950bd784118cc..b9a727efad85c25bfb912d77b19ed8562da56eaa 100644 (file)
@@ -242,9 +242,11 @@ LUA_FUNCTION_DEF (config, register_dependency);
  * - `description`: description of symbol (string, optional)
  * - `group`: name of group for symbol (string, optional)
  * - `one_shot`: turn off multiple hits for a symbol (boolean, optional)
+ * - `one_param`: turn off multiple options for a symbol (boolean, optional)
  * - `flags`: comma separated string of flags:
  *    + `ignore`: do not strictly check validity of symbol and corresponding rule
  *    + `one_shot`: turn off multiple hits for a symbol
+ *    + `one_param`: allow only one parameter for a symbol
  * - `priority`: priority of symbol's definition
  */
 LUA_FUNCTION_DEF (config, set_metric_symbol);
@@ -1376,7 +1378,7 @@ lua_config_set_metric_symbol (lua_State * L)
                        *group = NULL, *name = NULL, *flags_str = NULL;
        double weight;
        struct metric *metric;
-       gboolean one_shot = FALSE;
+       gboolean one_shot = FALSE, one_param = FALSE;
        GError *err = NULL;
        gdouble priority = 0.0;
        guint flags = 0;
@@ -1386,9 +1388,10 @@ lua_config_set_metric_symbol (lua_State * L)
                if (lua_type (L, 2) == LUA_TTABLE) {
                        if (!rspamd_lua_parse_table_arguments (L, 2, &err,
                                        "*name=S;score=N;description=S;"
-                                       "group=S;one_shot=B;metric=S;priority=N;flags=S",
+                                       "group=S;one_shot=B;one_param=B;metric=S;priority=N;flags=S",
                                        &name, &weight, &description,
-                                       &group, &one_shot, &metric_name, &priority, &flags_str)) {
+                                       &group, &one_shot, &one_param,
+                                       &metric_name, &priority, &flags_str)) {
                                msg_err_config ("bad arguments: %e", err);
                                g_error_free (err);
 
@@ -1421,14 +1424,20 @@ lua_config_set_metric_symbol (lua_State * L)
                if (one_shot) {
                        flags |= RSPAMD_SYMBOL_FLAG_ONESHOT;
                }
+               if (one_param) {
+                       flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
+               }
 
                if (flags_str) {
                        if (strstr (flags_str, "one_shot") != NULL) {
                                flags |= RSPAMD_SYMBOL_FLAG_ONESHOT;
                        }
-                       else if (strstr (flags_str, "ignore") != NULL) {
+                       if (strstr (flags_str, "ignore") != NULL) {
                                flags |= RSPAMD_SYMBOL_FLAG_IGNORE;
                        }
+                       if (strstr (flags_str, "one_param") != NULL) {
+                               flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
+                       }
                }
 
                if (metric == NULL) {
@@ -1787,6 +1796,16 @@ lua_config_newindex (lua_State *L)
                                        }
                                        lua_pop (L, 1);
 
+                                       lua_pushstring (L, "one_param");
+                                       lua_gettable (L, -2);
+
+                                       if (lua_type (L, -1) == LUA_TBOOLEAN) {
+                                               if (lua_toboolean (L, -1)) {
+                                                       flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
+                                               }
+                                       }
+                                       lua_pop (L, 1);
+
                                        /*
                                         * Do not override the existing symbols (using zero priority),
                                         * since we are defining default values here
index deb5adab541542275c30a641b334a567e2b3c4df..a88bde21b545d7618c3d7d07e3a76b72229e5477 100644 (file)
@@ -285,6 +285,14 @@ regexp_module_config (struct rspamd_config *cfg)
                                        }
                                }
 
+                               elt = ucl_object_lookup (value, "one_param");
+
+                               if (elt) {
+                                       if (ucl_object_toboolean (elt)) {
+                                               flags |= RSPAMD_SYMBOL_FLAG_ONEPARAM;
+                                       }
+                               }
+
                                elt = ucl_object_lookup (value, "priority");
 
                                if (elt) {