aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_config.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2011-05-25 18:04:10 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2011-05-25 18:04:10 +0400
commite9d62e613936de7d8402c190321eed7903c093fe (patch)
tree69bb91896b7a55ceef90fb51ac16a7f75fc3c2b5 /src/lua/lua_config.c
parent3b0487ad7ca4227133c495f26b3a6ee6a08a5831 (diff)
downloadrspamd-e9d62e613936de7d8402c190321eed7903c093fe.tar.gz
rspamd-e9d62e613936de7d8402c190321eed7903c093fe.zip
* Add new key-value map
* Add lua api support for key-value map * Fix problem in lua configuration initialization to allow `rspamd_config' global work properly
Diffstat (limited to 'src/lua/lua_config.c')
-rw-r--r--src/lua/lua_config.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index d69036e09..4ca3b7e45 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -38,6 +38,7 @@ LUA_FUNCTION_DEF (config, get_all_opt);
LUA_FUNCTION_DEF (config, register_function);
LUA_FUNCTION_DEF (config, add_radix_map);
LUA_FUNCTION_DEF (config, add_hash_map);
+LUA_FUNCTION_DEF (config, add_kv_map);
LUA_FUNCTION_DEF (config, get_classifier);
LUA_FUNCTION_DEF (config, register_symbol);
LUA_FUNCTION_DEF (config, register_virtual_symbol);
@@ -53,6 +54,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, register_function),
LUA_INTERFACE_DEF (config, add_radix_map),
LUA_INTERFACE_DEF (config, add_hash_map),
+ LUA_INTERFACE_DEF (config, add_kv_map),
LUA_INTERFACE_DEF (config, get_classifier),
LUA_INTERFACE_DEF (config, register_symbol),
LUA_INTERFACE_DEF (config, register_virtual_symbol),
@@ -495,6 +497,36 @@ lua_config_add_hash_map (lua_State *L)
}
+static gint
+lua_config_add_kv_map (lua_State *L)
+{
+ struct config_file *cfg = lua_check_config (L);
+ const gchar *map_line;
+ GHashTable **r, ***ud;
+
+ if (cfg) {
+ map_line = luaL_checkstring (L, 2);
+ r = g_malloc (sizeof (GHashTable *));
+ *r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
+ if (!add_map (map_line, read_kv_list, fin_kv_list, (void **)r)) {
+ msg_warn ("invalid hash map %s", map_line);
+ g_hash_table_destroy (*r);
+ g_free (r);
+ lua_pushnil (L);
+ return 1;
+ }
+ ud = lua_newuserdata (L, sizeof (GHashTable *));
+ *ud = r;
+ lua_setclass (L, "rspamd{hash_table}", -1);
+
+ return 1;
+ }
+
+ lua_pushnil (L);
+ return 1;
+
+}
+
/*** Metric functions ***/
@@ -625,18 +657,18 @@ static gint
lua_hash_table_get_key (lua_State * L)
{
GHashTable *tbl = lua_check_hash_table (L);
- const gchar *key;
+ const gchar *key, *value;
if (tbl) {
key = luaL_checkstring (L, 2);
- if (g_hash_table_lookup (tbl, key) != NULL) {
- lua_pushboolean (L, 1);
+ if ((value = g_hash_table_lookup (tbl, key)) != NULL) {
+ lua_pushstring (L, value);
return 1;
}
}
- lua_pushboolean (L, 0);
+ lua_pushnil (L);
return 1;
}