aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-28 15:53:20 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-09-28 15:53:20 +0100
commit5f00b5dd858cc602eca347c20e0b4ad828c6e819 (patch)
tree25d79eb835f003212d7258a5ba04449e1201233b
parentfdb511a4ab9810f180fc7ee1853861b803eafb43 (diff)
downloadrspamd-5f00b5dd858cc602eca347c20e0b4ad828c6e819.tar.gz
rspamd-5f00b5dd858cc602eca347c20e0b4ad828c6e819.zip
Add lua API for conditions registering.
-rw-r--r--src/lua/lua_config.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 07e10916a..ae7111f4a 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -283,6 +283,22 @@ elseif type(set_section) == "table" then
end
*/
LUA_FUNCTION_DEF (config, get_key);
+
+/***
+ * @method rspamd_config:add_condition(symbol, condition)
+ * Adds condition callback for specified symbol
+ * @param {string} symbol symbol's name
+ * @param {function} condition condition callback
+ * @return {boolean} true if condition has been added
+ * @example
+
+rspamd_config:add_condition('FUZZY_DENIED', function(task)
+ if some_map:find_key(task:get_from()) then return false end
+ return true
+end)
+ */
+LUA_FUNCTION_DEF (config, add_condition);
+
/***
* @method rspamd_config:__newindex(name, callback)
* This metamethod is called if new indicies are added to the `rspamd_config` object.
@@ -357,6 +373,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, register_post_filter),
LUA_INTERFACE_DEF (config, get_api_version),
LUA_INTERFACE_DEF (config, get_key),
+ LUA_INTERFACE_DEF (config, add_condition),
{"__tostring", rspamd_lua_class_tostring},
{"__newindex", lua_config_newindex},
{NULL, NULL}
@@ -1490,6 +1507,30 @@ lua_config_newindex (lua_State *L)
return 0;
}
+static gint
+lua_config_add_condition (lua_State *L)
+{
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+ const gchar *sym = luaL_checkstring (L, 2);
+ gboolean ret = FALSE;
+ gint condref;
+
+ if (cfg && sym && lua_type (L, 3) == LUA_TFUNCTION) {
+ lua_pushvalue (L, 3);
+ condref = luaL_ref (L, LUA_REGISTRYINDEX);
+
+ ret = rspamd_symbols_cache_add_condition_delayed (cfg->cache, sym, L,
+ condref);
+
+ if (!ret) {
+ luaL_unref (L, LUA_REGISTRYINDEX, condref);
+ }
+ }
+
+ lua_pushboolean (L, ret);
+ return 1;
+}
+
struct lua_map_callback_data {
lua_State *L;
gint ref;