g_assert (cache != NULL);
g_assert (symbol != NULL);
- item = g_hash_table_lookup (cache->items_by_symbol, symbol);
+ item = rspamd_symcache_find_filter (cache, symbol);
if (item) {
item->enabled = FALSE;
g_assert (cache != NULL);
g_assert (symbol != NULL);
- item = g_hash_table_lookup (cache->items_by_symbol, symbol);
+ item = rspamd_symcache_find_filter (cache, symbol);
if (item) {
item->enabled = TRUE;
}
return FALSE;
+}
+
+gboolean
+rspamd_symcache_add_symbol_flags (struct rspamd_symcache *cache,
+ const gchar *symbol,
+ guint flags)
+{
+ struct rspamd_symcache_item *item;
+
+ g_assert (cache != NULL);
+ g_assert (symbol != NULL);
+
+ item = rspamd_symcache_find_filter (cache, symbol);
+
+ if (item) {
+ item->type |= flags;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+gboolean
+rspamd_symcache_set_symbol_flags (struct rspamd_symcache *cache,
+ const gchar *symbol,
+ guint flags)
+{
+ struct rspamd_symcache_item *item;
+
+ g_assert (cache != NULL);
+ g_assert (symbol != NULL);
+
+ item = rspamd_symcache_find_filter (cache, symbol);
+
+ if (item) {
+ item->type = flags;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+guint
+rspamd_symcache_get_symbol_flags (struct rspamd_symcache *cache,
+ const gchar *symbol)
+{
+ struct rspamd_symcache_item *item;
+
+ g_assert (cache != NULL);
+ g_assert (symbol != NULL);
+
+ item = rspamd_symcache_find_filter (cache, symbol);
+
+ if (item) {
+ return item->type;
+ }
+
+ return 0;
}
\ No newline at end of file
* + `skip` if symbol should be skipped now
* + `nostat` if symbol should be excluded from stat tokens
* + `trivial` symbol is trivial (e.g. no network requests)
+ * + `explicit_disable` requires explicit disabling (e.g. via settings)
+ * + `ignore_passthrough` executed even if passthrough result has been set
* - `parent`: id of parent symbol (useful for virtual symbols)
*
* @return {number} id of symbol registered
*/
LUA_FUNCTION_DEF (config, register_dependency);
+/***
+ * @method rspamd_config:get_symbol_flags(name)
+ * Returns symbol flags
+ * @param {string} name symbols's name
+ * @return {table|string} list of flags for symbol or nil
+ */
+LUA_FUNCTION_DEF (config, get_symbol_flags);
+
+/***
+ * @method rspamd_config:add_symbol_flags(name, flags)
+ * Adds flags to a symbol
+ * @param {string} name symbols's name
+ * @param {table|string} flags flags to add
+ * @return {table|string} new set of flags
+ */
+LUA_FUNCTION_DEF (config, add_symbol_flags);
+
/**
* @method rspamd_config:register_re_selector(name, selector_str)
* Registers selector with the specific name to use in regular expressions in form
LUA_INTERFACE_DEF (config, register_callback_symbol),
LUA_INTERFACE_DEF (config, register_callback_symbol_priority),
LUA_INTERFACE_DEF (config, register_dependency),
+ LUA_INTERFACE_DEF (config, get_symbol_flags),
+ LUA_INTERFACE_DEF (config, add_symbol_flags),
LUA_INTERFACE_DEF (config, set_metric_symbol),
{"set_symbol", lua_config_set_metric_symbol},
LUA_INTERFACE_DEF (config, set_metric_action),
lua_pushboolean (L, true);
lua_settable (L, -3);
}
+ if (type & SYMBOL_TYPE_EXPLICIT_DISABLE) {
+ lua_pushstring (L, "explicit_disable");
+ lua_pushboolean (L, true);
+ lua_settable (L, -3);
+ }
/* Now call for squeeze function */
if (lua_pcall (L, 3, 1, err_idx) != 0) {
if (strstr (str, "mime") != NULL) {
ret |= SYMBOL_TYPE_MIME_ONLY;
}
+ if (strstr (str, "ignore_passthrough") != NULL) {
+ ret |= SYMBOL_TYPE_IGNORE_PASSTHROUGH;
+ }
+ if (strstr (str, "explicit_disable") != NULL) {
+ ret |= SYMBOL_TYPE_EXPLICIT_DISABLE;
+ }
}
return ret;
return ret;
}
+static void
+lua_push_symbol_flags (lua_State *L, guint flags)
+{
+ guint i = 1;
+
+ lua_newtable (L);
+
+ if (flags & SYMBOL_TYPE_FINE) {
+ lua_pushstring (L, "fine");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_EMPTY) {
+ lua_pushstring (L, "empty");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_SQUEEZED) {
+ lua_pushstring (L, "squeezed");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_EXPLICIT_DISABLE) {
+ lua_pushstring (L, "explicit_disable");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_IGNORE_PASSTHROUGH) {
+ lua_pushstring (L, "ignore_passthrough");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_NOSTAT) {
+ lua_pushstring (L, "nostat");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_IDEMPOTENT) {
+ lua_pushstring (L, "idempotent");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_MIME_ONLY) {
+ lua_pushstring (L, "mime");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_TRIVIAL) {
+ lua_pushstring (L, "trivial");
+ lua_rawseti (L, -2, i++);
+ }
+
+ if (flags & SYMBOL_TYPE_SKIPPED) {
+ lua_pushstring (L, "skip");
+ lua_rawseti (L, -2, i++);
+ }
+}
+
+static gint
+lua_config_get_symbol_flags (lua_State *L)
+{
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+ const gchar *name = luaL_checkstring (L, 2);
+ guint flags;
+
+ if (cfg && name) {
+ flags = rspamd_symcache_get_symbol_flags (cfg->cache,
+ name);
+
+ if (flags != 0) {
+ lua_push_symbol_flags (L, flags);
+ }
+ else {
+ lua_pushnil (L);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
+lua_config_add_symbol_flags (lua_State *L)
+{
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+ const gchar *name = luaL_checkstring (L, 2);
+ guint flags, new_flags = 0;
+
+ if (cfg && name && lua_istable (L, 3)) {
+
+ for (lua_pushnil (L); lua_next (L, 3); lua_pop (L, 1)) {
+ new_flags |= lua_parse_symbol_flags (lua_tostring (L, -1));
+ }
+
+ flags = rspamd_symcache_get_symbol_flags (cfg->cache,
+ name);
+
+ if (flags != 0) {
+ rspamd_symcache_add_symbol_flags (cfg->cache, name, new_flags);
+ /* Push old flags */
+ lua_push_symbol_flags (L, flags);
+ }
+ else {
+ lua_pushnil (L);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
static gint
lua_config_register_symbol (lua_State * L)
{