]> source.dussan.org Git - rspamd.git/commitdiff
Allow multiply statfiles with a same label.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 2 Oct 2012 13:35:42 +0000 (17:35 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 2 Oct 2012 13:35:42 +0000 (17:35 +0400)
src/cfg_utils.c
src/cfg_xml.c
src/lua/lua_classifier.c

index 440fb65e6200a84b3b198b7f205f97677beeb1f0..1576cb9fbef2ece2daf62e3764b590ba863b24b5 100644 (file)
@@ -827,7 +827,7 @@ check_classifier_conf (struct config_file *cfg, struct classifier_config *c)
                memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func) g_hash_table_destroy, c->opts);
        }
        if (c->labels == NULL) {
-               c->labels = g_hash_table_new (g_str_hash, g_str_equal);
+               c->labels = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)g_list_free);
                memory_pool_add_destructor (cfg->cfg_pool, (pool_destruct_func) g_hash_table_destroy, c->labels);
        }
 
index bcec06c1d29fe0cabe68ebbe6beb936bd3f0935e..60bfbf96f657e4b46916ebb3acf8e5d6d45af424 100644 (file)
@@ -1907,6 +1907,7 @@ rspamd_xml_end_element (GMarkupParseContext       *context, const gchar *element_name,
        gpointer                    tptr;
        struct wrk_cbdata           wcd;
        struct xml_subparser       *subparser;
+       GList                                      *labels;
        
        if (g_ascii_strcasecmp (element_name, "if") == 0) {
                tptr = g_queue_pop_head (ud->if_stack);
@@ -1962,11 +1963,11 @@ rspamd_xml_end_element (GMarkupParseContext     *context, const gchar *element_name,
                                ud->cfg->statfiles = g_list_prepend (ud->cfg->statfiles, st);
                                g_hash_table_insert (ud->cfg->classifiers_symbols, st->symbol, ccf);
                                if (st->label) {
-                                       if (g_hash_table_lookup (ccf->labels, st->label)) {
-                                               msg_warn ("duplicate statfile label %s with symbol %s, ignoring", st->label, st->symbol);
+                                       if ((labels = g_hash_table_lookup (ccf->labels, st->label))) {
+                                               labels = g_list_append (labels, st);
                                        }
                                        else {
-                                               g_hash_table_insert (ccf->labels, st->label, st);
+                                               g_hash_table_insert (ccf->labels, st->label, g_list_prepend (NULL, st));
                                        }
                                }
                                ud->section_pointer = ccf;
index c6eb2cf18a099a026597625578b0c8c360a5e795..be18cda0d05a93178311a5c79dd2bf9db3f2a16e 100644 (file)
@@ -278,14 +278,23 @@ lua_classifier_get_statfile_by_label (lua_State *L)
        struct classifier_config       *ccf = lua_check_classifier (L);
        struct statfile                *st, **pst;
        const gchar                                        *label;
+       GList                                              *cur;
+       gint                                                    i;
 
        label = luaL_checkstring (L, 2);
        if (ccf && label) {
-               st = g_hash_table_lookup (ccf->labels, label);
-               if (st) {
-                       pst = lua_newuserdata (L, sizeof (struct statfile *));
-                       lua_setclass (L, "rspamd{statfile}", -1);
-                       *pst = st;
+               cur = g_hash_table_lookup (ccf->labels, label);
+               if (cur) {
+                       lua_newtable (L);
+                       i = 1;
+                       while (cur) {
+                               st = cur->data;
+                               pst = lua_newuserdata (L, sizeof (struct statfile *));
+                               lua_setclass (L, "rspamd{statfile}", -1);
+                               *pst = st;
+                               lua_rawseti (L, -2, i++);
+                               cur = g_list_next (cur);
+                       }
                        return 1;
                }
        }