aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2010-06-16 20:43:26 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2010-06-16 20:43:26 +0400
commita639bf512e3df778fa33c49d83c3996c9fe60d77 (patch)
tree072c4167dae82382b1c8eef93e0270339635e389 /src/lua
parentc4aab3053d2839e6d3b99f8a542b0a4f54f2b856 (diff)
downloadrspamd-a639bf512e3df778fa33c49d83c3996c9fe60d77.tar.gz
rspamd-a639bf512e3df778fa33c49d83c3996c9fe60d77.zip
* Change metric logic
* Completely remove lex/yacc readers for config * Make common sense of metric/action and symbols * Sync changes with all plugins TODO: add this to documentation
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/lua_common.c1
-rw-r--r--src/lua/lua_config.c60
-rw-r--r--src/lua/lua_task.c11
3 files changed, 11 insertions, 61 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index d1a2b614b..aec72006c 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -191,7 +191,6 @@ init_lua (struct config_file *cfg)
(void)luaopen_rspamd (L);
(void)luaopen_logger (L);
(void)luaopen_config (L);
- (void)luaopen_metric (L);
(void)luaopen_radix (L);
(void)luaopen_hash_table (L);
(void)luaopen_task (L);
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index bbbab4a53..5e0148ca7 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -31,33 +31,25 @@
/* Config file methods */
LUA_FUNCTION_DEF (config, get_module_opt);
-LUA_FUNCTION_DEF (config, get_metric);
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, get_classifier);
+LUA_FUNCTION_DEF (config, register_symbol);
static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
- LUA_INTERFACE_DEF (config, get_metric),
LUA_INTERFACE_DEF (config, get_all_opt),
LUA_INTERFACE_DEF (config, register_function),
LUA_INTERFACE_DEF (config, add_radix_map),
LUA_INTERFACE_DEF (config, add_hash_map),
LUA_INTERFACE_DEF (config, get_classifier),
+ LUA_INTERFACE_DEF (config, register_symbol),
{"__tostring", lua_class_tostring},
{NULL, NULL}
};
-/* Metric methods */
-LUA_FUNCTION_DEF (metric, register_symbol);
-
-static const struct luaL_reg metriclib_m[] = {
- LUA_INTERFACE_DEF (metric, register_symbol),
- {"__tostring", lua_class_tostring},
- {NULL, NULL}
-};
/* Radix tree */
LUA_FUNCTION_DEF (radix, get_key);
@@ -85,14 +77,6 @@ lua_check_config (lua_State * L)
return *((struct config_file **)ud);
}
-static struct metric *
-lua_check_metric (lua_State * L)
-{
- void *ud = luaL_checkudata (L, 1, "rspamd{metric}");
- luaL_argcheck (L, ud != NULL, 1, "'metric' expected");
- return *((struct metric **)ud);
-}
-
static radix_tree_t *
lua_check_radix (lua_State * L)
{
@@ -217,29 +201,6 @@ lua_config_get_all_opt (lua_State * L)
static int
-lua_config_get_metric (lua_State * L)
-{
- struct config_file *cfg = lua_check_config (L);
- struct metric *metric, **pmetric;
- const char *name;
-
- if (cfg) {
- name = luaL_checkstring (L, 2);
- metric = g_hash_table_lookup (cfg->metrics, name);
- if (metric) {
- pmetric = lua_newuserdata (L, sizeof (struct metric *));
- lua_setclass (L, "rspamd{metric}", -1);
- *pmetric = metric;
- return 1;
- }
- }
-
- lua_pushnil (L);
- return 1;
-
-}
-
-static int
lua_config_get_classifier (lua_State * L)
{
struct config_file *cfg = lua_check_config (L);
@@ -413,14 +374,14 @@ lua_metric_symbol_callback (struct worker_task *task, gpointer ud)
}
static int
-lua_metric_register_symbol (lua_State * L)
+lua_config_register_symbol (lua_State * L)
{
- struct metric *metric = lua_check_metric (L);
+ struct config_file *cfg = lua_check_config (L);
const char *name, *callback;
double weight;
struct lua_callback_data *cd;
- if (metric) {
+ if (cfg) {
name = g_strdup (luaL_checkstring (L, 2));
weight = luaL_checknumber (L, 3);
callback = luaL_checkstring (L, 4);
@@ -428,7 +389,7 @@ lua_metric_register_symbol (lua_State * L)
cd = g_malloc (sizeof (struct lua_callback_data));
cd->name = g_strdup (callback);
cd->L = L;
- register_symbol (&metric->cache, name, weight, lua_metric_symbol_callback, cd);
+ register_symbol (&cfg->cache, name, weight, lua_metric_symbol_callback, cd);
}
}
return 1;
@@ -483,15 +444,6 @@ luaopen_config (lua_State * L)
}
int
-luaopen_metric (lua_State * L)
-{
- lua_newclass (L, "rspamd{metric}", metriclib_m);
- luaL_openlib (L, "rspamd_metric", null_reg, 0);
-
- return 1;
-}
-
-int
luaopen_radix (lua_State * L)
{
lua_newclass (L, "rspamd{radix}", radixlib_m);
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index dec415f9b..123cd048e 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -117,23 +117,22 @@ static int
lua_task_insert_result (lua_State * L)
{
struct worker_task *task = lua_check_task (L);
- const char *metric_name, *symbol_name, *param;
+ const char *symbol_name, *param;
double flag;
GList *params = NULL;
int i, top;
if (task != NULL) {
- metric_name = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 2));
- symbol_name = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 3));
- flag = luaL_checknumber (L, 4);
+ symbol_name = memory_pool_strdup (task->task_pool, luaL_checkstring (L, 2));
+ flag = luaL_checknumber (L, 3);
top = lua_gettop (L);
/* Get additional options */
- for (i = 5; i <= top; i++) {
+ for (i = 4; i <= top; i++) {
param = luaL_checkstring (L, i);
params = g_list_prepend (params, memory_pool_strdup (task->task_pool, param));
}
- insert_result (task, metric_name, symbol_name, flag, params);
+ insert_result (task, symbol_name, flag, params);
}
return 1;
}