aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-26 14:12:52 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-04-26 14:12:52 +0100
commit0329cde5bda00eaf4ede9ebc9948937766ac002d (patch)
treeb057064c0d06d9f2f08b0fbd86fea7e7024074c6 /src
parentca2d20981bc6061df455f7f7a2ccb787ad595783 (diff)
downloadrspamd-0329cde5bda00eaf4ede9ebc9948937766ac002d.tar.gz
rspamd-0329cde5bda00eaf4ede9ebc9948937766ac002d.zip
[Minor] Link map and lua_map object
Diffstat (limited to 'src')
-rw-r--r--src/libutil/map_private.h1
-rw-r--r--src/lua/lua_common.h1
-rw-r--r--src/lua/lua_config.c7
-rw-r--r--src/lua/lua_map.c12
-rw-r--r--src/lua/lua_map.h1
5 files changed, 21 insertions, 1 deletions
diff --git a/src/libutil/map_private.h b/src/libutil/map_private.h
index fb1e609bd..eea616591 100644
--- a/src/libutil/map_private.h
+++ b/src/libutil/map_private.h
@@ -117,6 +117,7 @@ struct rspamd_map {
rspamd_map_dtor dtor;
gpointer dtor_data;
rspamd_map_traverse_function traverse_function;
+ gpointer lua_map;
/* Should we check HTTP or just load cached data */
struct timeval tv;
gdouble poll_timeout;
diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h
index b07bf0729..55070acf2 100644
--- a/src/lua/lua_common.h
+++ b/src/lua/lua_common.h
@@ -248,7 +248,6 @@ void rspamd_lua_add_preload (lua_State *L, const gchar *name, lua_CFunction func
void luaopen_task (lua_State *L);
void luaopen_config (lua_State *L);
-void luaopen_metric (lua_State *L);
void luaopen_map (lua_State *L);
void luaopen_trie (lua_State * L);
void luaopen_textpart (lua_State *L);
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 9a2cab536..a42f33b37 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -178,6 +178,12 @@ end
rspamd_config:add_map('http://example.com/map', "settings map", process_map)
*/
/***
+* @method rspamd_config:get_maps()
+* Get all maps defined as an array of rspamd{map} objects
+ *
+* @return {table|rspamd{map}}
+*/
+/***
* @method rspamd_config:get_classifier(name)
* Returns classifier config.
* @param {string} name name of classifier (e.g. `bayes`)
@@ -686,6 +692,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, add_hash_map),
LUA_INTERFACE_DEF (config, add_kv_map),
LUA_INTERFACE_DEF (config, add_map),
+ LUA_INTERFACE_DEF (config, get_maps),
LUA_INTERFACE_DEF (config, get_classifier),
LUA_INTERFACE_DEF (config, register_symbol),
LUA_INTERFACE_DEF (config, register_symbols),
diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c
index 8ac41bef4..27e79ac2b 100644
--- a/src/lua/lua_map.c
+++ b/src/lua/lua_map.c
@@ -138,6 +138,7 @@ lua_config_add_radix_map (lua_State *L)
}
map->map = m;
+ m->lua_map = map;
pmap = lua_newuserdata (L, sizeof (void *));
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
@@ -195,6 +196,7 @@ lua_config_radix_from_config (lua_State *L)
ucl_object_unref (fake_obj);
pmap = lua_newuserdata (L, sizeof (void *));
map->map = m;
+ m->lua_map = map;
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
}
@@ -253,6 +255,7 @@ lua_config_radix_from_ucl (lua_State *L)
ucl_object_unref (fake_obj);
pmap = lua_newuserdata (L, sizeof (void *));
map->map = m;
+ m->lua_map = map;
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
@@ -289,6 +292,7 @@ lua_config_add_hash_map (lua_State *L)
}
map->map = m;
+ m->lua_map = map;
pmap = lua_newuserdata (L, sizeof (void *));
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
@@ -327,6 +331,7 @@ lua_config_add_kv_map (lua_State *L)
}
map->map = m;
+ m->lua_map = map;
pmap = lua_newuserdata (L, sizeof (void *));
*pmap = map;
rspamd_lua_setclass (L, "rspamd{map}", -1);
@@ -472,6 +477,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
+ m->lua_map = map;
}
else if (strcmp (type, "set") == 0) {
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
@@ -487,6 +493,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
+ m->lua_map = map;
}
else if (strcmp (type, "map") == 0 || strcmp (type, "hash") == 0) {
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
@@ -502,6 +509,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
+ m->lua_map = map;
}
else if (strcmp (type, "radix") == 0) {
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
@@ -517,6 +525,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
+ m->lua_map = map;
}
else if (strcmp (type, "regexp") == 0) {
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
@@ -532,6 +541,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
+ m->lua_map = map;
}
else if (strcmp (type, "regexp_multi") == 0) {
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
@@ -547,6 +557,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
+ m->lua_map = map;
}
else if (strcmp (type, "glob") == 0) {
map = rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (*map));
@@ -562,6 +573,7 @@ lua_config_add_map (lua_State *L)
return 1;
}
+ m->lua_map = map;
}
else {
ret = luaL_error (L, "invalid arguments: unknown type '%s'", type);
diff --git a/src/lua/lua_map.h b/src/lua/lua_map.h
index bee698e08..a44bd12e9 100644
--- a/src/lua/lua_map.h
+++ b/src/lua/lua_map.h
@@ -25,5 +25,6 @@ LUA_PUBLIC_FUNCTION_DEF (config, add_map);
LUA_PUBLIC_FUNCTION_DEF (config, add_hash_map);
LUA_PUBLIC_FUNCTION_DEF (config, add_kv_map);
LUA_PUBLIC_FUNCTION_DEF (config, add_map);
+LUA_PUBLIC_FUNCTION_DEF (config, get_maps);
#endif /* SRC_LUA_LUA_MAP_H_ */