]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add glob_multi map type
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Sep 2018 15:55:36 +0000 (16:55 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 14 Sep 2018 15:55:36 +0000 (16:55 +0100)
src/libutil/map_helpers.c
src/libutil/map_helpers.h
src/lua/lua_map.c

index c43c23277a5288db802a38077f1b4f421819f168..bf18102d8d1f84e84142246ec2bae80719006e83 100644 (file)
@@ -1026,6 +1026,30 @@ rspamd_regexp_list_read_multiple (
 {
        struct rspamd_regexp_map_helper *re_map;
 
+       if (data->cur_data == NULL) {
+               re_map = rspamd_map_helper_new_regexp (data->map,
+                               RSPAMD_REGEXP_MAP_FLAG_GLOB|RSPAMD_REGEXP_MAP_FLAG_MULTIPLE);
+               data->cur_data = re_map;
+       }
+
+       return rspamd_parse_kv_list (
+                       chunk,
+                       len,
+                       data,
+                       rspamd_map_helper_insert_re,
+                       hash_fill,
+                       final);
+}
+
+gchar *
+rspamd_glob_list_read_multiple (
+               gchar *chunk,
+               gint len,
+               struct map_cb_data *data,
+               gboolean final)
+{
+       struct rspamd_regexp_map_helper *re_map;
+
        if (data->cur_data == NULL) {
                re_map = rspamd_map_helper_new_regexp (data->map, RSPAMD_REGEXP_MAP_FLAG_MULTIPLE);
                data->cur_data = re_map;
@@ -1040,6 +1064,7 @@ rspamd_regexp_list_read_multiple (
                        final);
 }
 
+
 void
 rspamd_regexp_list_fin (struct map_cb_data *data)
 {
index 28a5e336bbc9a70ccedff8803f39ba4797795138..f7c86436f0a02dec6506396ff8453c190cf05851 100644 (file)
@@ -80,11 +80,17 @@ gchar * rspamd_regexp_list_read_multiple (
                gint len,
                struct map_cb_data *data,
                gboolean final);
+
 gchar * rspamd_glob_list_read_single (
                gchar *chunk,
                gint len,
                struct map_cb_data *data,
                gboolean final);
+gchar * rspamd_glob_list_read_multiple (
+               gchar *chunk,
+               gint len,
+               struct map_cb_data *data,
+               gboolean final);
 void rspamd_regexp_list_fin (struct map_cb_data *data);
 void rspamd_regexp_list_dtor (struct map_cb_data *data);
 
index 1621abf0db1964647dd0f4fbe16a77bcb91cb7ae..9cf50f1a2e783621da7f1c49e126cc39de929f99 100644 (file)
@@ -639,6 +639,23 @@ lua_config_add_map (lua_State *L)
                        }
                        m->lua_map = map;
                }
+               else if (strcmp (type, "glob_multi") == 0) {
+                       map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
+                       map->data.re_map = NULL;
+                       map->type = RSPAMD_LUA_MAP_REGEXP_MULTIPLE;
+
+                       if ((m = rspamd_map_add_from_ucl (cfg, map_obj, description,
+                                       rspamd_glob_list_read_multiple,
+                                       rspamd_regexp_list_fin,
+                                       rspamd_regexp_list_dtor,
+                                       (void **) &map->data.re_map)) == NULL) {
+                               lua_pushnil (L);
+                               ucl_object_unref (map_obj);
+
+                               return 1;
+                       }
+                       m->lua_map = map;
+               }
                else {
                        ret = luaL_error (L, "invalid arguments: unknown type '%s'", type);
                        ucl_object_unref (map_obj);