item = rspamd_mempool_alloc0_shared (cache->static_pool,
sizeof (struct cache_item));
+ item->condition_cb = -1;
/*
* We do not share cd to skip locking, instead we'll just calculate it on
* save or accumulate
return item->id;
}
+gboolean
+rspamd_symbols_cache_add_condition (struct symbols_cache *cache, gint id, lua_State *L, gint cbref)
+{
+ struct cache_item *item;
+
+ g_assert (cache != NULL);
+
+ if (id < 0 || id >= cache->items_by_id->len) {
+ return FALSE;
+ }
+
+ item = g_ptr_array_index (cache->items_by_id, id);
+
+ if (item->condition_cb != -1) {
+ /* We already have a condition, so we need to remove old cbref first */
+ msg_warn ("rewriting condition for symbol %s", item->symbol);
+ luaL_unref (L, LUA_REGISTRYINDEX, item->condition_cb);
+ }
+
+ item->condition_cb = cbref;
+
+ return TRUE;
+}
void
rspamd_symbols_cache_destroy (struct symbols_cache *cache)
cache->delayed_deps = g_list_prepend (cache->delayed_deps, ddep);
}
+
+gint
+rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, const gchar *name)
+{
+ struct cache_item *item;
+
+ g_assert (cache != NULL);
+
+ if (name == NULL) {
+ return -1;
+ }
+
+ item = g_hash_table_lookup (cache->items_by_symbol, name);
+
+ if (item != NULL) {
+ return item->id;
+ }
+
+ return -1;
+}
#include "config.h"
#include "ucl.h"
+#include "lua/lua_common.h"
#define MAX_SYMBOL 128
enum rspamd_symbol_type type,
gint parent);
+/**
+ * Add condition to the specific symbol in cache
+ * @param cache
+ * @param id id of symbol
+ * @param L lua state pointer
+ * @param cbref callback reference (returned by luaL_ref)
+ * @return TRUE if condition has been added
+ */
+gboolean rspamd_symbols_cache_add_condition (struct symbols_cache *cache, gint id, lua_State *L, gint cbref);
+
+/**
+ * Find symbol in cache by id and returns its id
+ * @param cache
+ * @param name
+ * @return id of symbol or (-1) if a symbol has not been found
+ */
+gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, const gchar *name);
+
/**
* Call function for cached symbol using saved callback
* @param task task object