]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow dedicated groups registration
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 29 Sep 2018 13:50:55 +0000 (14:50 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 29 Sep 2018 13:50:55 +0000 (14:50 +0100)
src/lua/lua_config.c

index 9bfaee0d296170e2991ef0fc924c5dd3be21685f..f15c04e467422c710850fc2566951262e32974a3 100644 (file)
@@ -1739,14 +1739,21 @@ lua_config_register_symbol (lua_State * L)
                                FALSE,
                                no_squeeze);
 
-               if (!isnan (score)) {
+               if (!isnan (score) || group) {
                        if (one_shot) {
                                nshots = 1;
                        }
 
-                       rspamd_config_add_symbol (cfg, name,
-                                       score, description, group, flags,
-                                       (guint) priority, nshots);
+                       if (!isnan (score)) {
+                               rspamd_config_add_symbol (cfg, name,
+                                               score, description, group, flags,
+                                               (guint) priority, nshots);
+                       }
+                       else {
+                               rspamd_config_add_symbol (cfg, name,
+                                               0.0, description, group, flags,
+                                               (guint) priority, nshots);
+                       }
 
                        lua_pushstring (L, "groups");
                        lua_gettable (L, 2);
@@ -2385,7 +2392,7 @@ lua_config_newindex (lua_State *L)
                }
                else if (lua_type (L, 3) == LUA_TTABLE) {
                        gint type = SYMBOL_TYPE_NORMAL, priority = 0, idx;
-                       gdouble weight = 1.0, score;
+                       gdouble weight = 1.0, score = NAN;
                        const char *type_str, *group = NULL, *description = NULL;
                        guint flags = 0;
 
@@ -2500,22 +2507,23 @@ lua_config_newindex (lua_State *L)
                         */
                        if (g_hash_table_lookup (cfg->symbols, name) == NULL) {
                                nshots = cfg->default_max_shots;
+
                                lua_pushstring (L, "score");
                                lua_gettable (L, -2);
-
                                if (lua_type (L, -1) == LUA_TNUMBER) {
                                        score = lua_tonumber (L, -1);
-                                       lua_pop (L, 1);
 
-                                       /* If score defined, then we can check other metric fields */
-                                       lua_pushstring (L, "group");
-                                       lua_gettable (L, -2);
+                               }
+                               lua_pop (L, 1);
 
-                                       if (lua_type (L, -1) == LUA_TSTRING) {
-                                               group = lua_tostring (L, -1);
-                                       }
-                                       lua_pop (L, 1);
+                               lua_pushstring (L, "group");
+                               lua_gettable (L, -2);
+                               if (lua_type (L, -1) == LUA_TSTRING) {
+                                       group = lua_tostring (L, -1);
+                               }
+                               lua_pop (L, 1);
 
+                               if (!isnan (score) || group != NULL) {
                                        lua_pushstring (L, "description");
                                        lua_gettable (L, -2);
 
@@ -2548,8 +2556,15 @@ lua_config_newindex (lua_State *L)
                                         * Do not override the existing symbols (using zero priority),
                                         * since we are defining default values here
                                         */
-                                       rspamd_config_add_symbol (cfg, name, score,
-                                                       description, group, flags, 0, nshots);
+                                       if (!isnan (score)) {
+                                               rspamd_config_add_symbol (cfg, name, score,
+                                                               description, group, flags, 0, nshots);
+                                       }
+                                       else if (group) {
+                                               /* Add with zero score */
+                                               rspamd_config_add_symbol (cfg, name, 0.0,
+                                                               description, group, flags, 0, nshots);
+                                       }
 
                                        lua_pushstring (L, "groups");
                                        lua_gettable (L, -2);
@@ -2568,9 +2583,6 @@ lua_config_newindex (lua_State *L)
 
                                        lua_pop (L, 1);
                                }
-                               else {
-                                       lua_pop (L, 1);
-                               }
                        }
 
                        /* Remove table from stack */