return TRUE;
}
-gboolean rspamd_symbols_cache_add_condition_delayed (struct symbols_cache *cache,
+gboolean
+rspamd_symbols_cache_add_condition_delayed (struct symbols_cache *cache,
const gchar *sym, lua_State *L, gint cbref)
{
gint id;
gdouble weight,
gint priority,
enum rspamd_symbol_type type,
- gint parent)
+ gint parent,
+ gboolean optional)
{
struct lua_callback_data *cd;
gint ret = -1;
priority = 1;
}
+ if ((ret = rspamd_symbols_cache_find_symbol (cfg->cache, name)) != -1) {
+ if (optional) {
+ msg_debug_config ("duplicate symbol: %s, skip registering", name);
+
+ return ret;
+ }
+ else {
+ msg_err_config ("duplicate symbol: %s, skip registering", name);
+
+ return -1;
+ }
+ }
+
ret = rspamd_symbols_cache_add_symbol (cfg->cache,
name,
priority,
weight,
0,
SYMBOL_TYPE_NORMAL,
- -1);
+ -1,
+ FALSE);
}
}
weight,
0,
SYMBOL_TYPE_CALLBACK,
- -1);
+ -1,
+ FALSE);
+
for (i = top; i <= lua_gettop (L); i++) {
if (lua_type (L, i) == LUA_TTABLE) {
lua_pushvalue (L, i);
weight,
0,
SYMBOL_TYPE_CALLBACK,
- -1);
+ -1,
+ FALSE);
}
lua_pushnumber (L, ret);
weight,
priority,
SYMBOL_TYPE_CALLBACK,
- -1);
+ -1,
+ FALSE);
}
lua_pushnumber (L, ret);
struct rspamd_config *cfg = lua_check_config (L, 1);
const gchar *name;
gint id;
+ gboolean optional = FALSE;
name = luaL_checkstring (L, 2);
1.0,
0,
SYMBOL_TYPE_NORMAL,
- -1);
+ -1,
+ FALSE);
}
else if (lua_type (L, 3) == LUA_TTABLE) {
gint type = SYMBOL_TYPE_NORMAL, priority = 0, idx;
}
lua_pop (L, 1);
+ lua_pushstring (L, "optional");
+ lua_gettable (L, -2);
+
+ if (lua_type (L, -1) == LUA_TBOOLEAN) {
+ optional = lua_toboolean (L, -1);
+ }
+ lua_pop (L, 1);
+
lua_pushstring (L, "type");
lua_gettable (L, -2);
weight,
priority,
type,
- -1);
+ -1,
+ optional);
if (id != -1) {
/* Check for condition */