return ret;
}
-void
+gint
rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
const gchar *name,
double weight,
if (g_hash_table_lookup (cache->items_by_symbol, name) != NULL) {
msg_err ("skip duplicate symbol registration for %s", name);
- return;
+ return -1;
}
item = rspamd_mempool_alloc0_shared (cache->static_pool,
rspamd_set_counter (item, 0);
g_hash_table_insert (cache->items_by_symbol, item->symbol, item);
g_ptr_array_add (cache->items_by_order, item);
+
+ return item->id;
}
-void
+gint
rspamd_symbols_cache_add_symbol_normal (struct symbols_cache *cache, const gchar *name, double weight,
symbol_func_t func, gpointer user_data)
{
- rspamd_symbols_cache_add_symbol (cache,
+ return rspamd_symbols_cache_add_symbol (cache,
name,
weight,
0,
SYMBOL_TYPE_NORMAL);
}
-void
+gint
rspamd_symbols_cache_add_symbol_virtual (struct symbols_cache *cache,
const gchar *name,
double weight)
{
- rspamd_symbols_cache_add_symbol (cache,
+ return rspamd_symbols_cache_add_symbol (cache,
name,
weight,
0,
SYMBOL_TYPE_VIRTUAL);
}
-void
+gint
rspamd_symbols_cache_add_symbol_callback (struct symbols_cache *cache,
const gchar *name,
double weight,
symbol_func_t func,
gpointer user_data)
{
- rspamd_symbols_cache_add_symbol (cache,
+ return rspamd_symbols_cache_add_symbol (cache,
name,
weight,
0,
SYMBOL_TYPE_CALLBACK);
}
-void
+gint
rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
const gchar *name,
double weight,
symbol_func_t func,
gpointer user_data)
{
- rspamd_symbols_cache_add_symbol (cache,
+ return rspamd_symbols_cache_add_symbol (cache,
name,
weight,
priority,
* @param func pointer to handler
* @param user_data pointer to user_data
*/
-void rspamd_symbols_cache_add_symbol_normal (struct symbols_cache *cache,
+gint rspamd_symbols_cache_add_symbol_normal (struct symbols_cache *cache,
const gchar *name,
double weight,
symbol_func_t func,
* Register virtual symbol
* @param name name of symbol
*/
-void rspamd_symbols_cache_add_symbol_virtual (struct symbols_cache *cache,
+gint rspamd_symbols_cache_add_symbol_virtual (struct symbols_cache *cache,
const gchar *name,
double weight);
* @param func pointer to handler
* @param user_data pointer to user_data
*/
-void rspamd_symbols_cache_add_symbol_callback (struct symbols_cache *cache,
+gint rspamd_symbols_cache_add_symbol_callback (struct symbols_cache *cache,
const gchar *name,
double weight,
symbol_func_t func,
* @param func pointer to handler
* @param user_data pointer to user_data
*/
-void rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
+gint rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
const gchar *name,
double weight,
gint priority,
* @param user_data
* @param type
*/
-void rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
+gint rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
const gchar *name,
double weight,
gint priority,
}
}
-static void
+static gint
rspamd_register_symbol_fromlua (lua_State *L,
struct rspamd_config *cfg,
const gchar *name,
enum rspamd_symbol_type type)
{
struct lua_callback_data *cd;
+ gint ret = -1;
if (name) {
cd = rspamd_mempool_alloc0 (cfg->cfg_pool,
cd->L = L;
cd->symbol = rspamd_mempool_strdup (cfg->cfg_pool, name);
- rspamd_symbols_cache_add_symbol (cfg->cache,
+ ret = rspamd_symbols_cache_add_symbol (cfg->cache,
name,
weight,
priority,
cd);
}
-
+ return ret;
}
static gint
struct rspamd_config *cfg = lua_check_config (L, 1);
gchar *name;
double weight;
+ gint ret = -1;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
lua_pushvalue (L, 4);
}
if (name) {
- rspamd_register_symbol_fromlua (L,
+ ret = rspamd_register_symbol_fromlua (L,
cfg,
name,
luaL_ref (L, LUA_REGISTRYINDEX),
}
}
- return 0;
+ lua_pushnumber (L, ret);
+
+ return 1;
}
static gint
lua_config_register_symbols (lua_State *L)
{
struct rspamd_config *cfg = lua_check_config (L, 1);
- gint i, top, idx;
+ gint i, top, idx, ret = -1;
gchar *sym;
gdouble weight = 1.0;
top = 3;
}
sym = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, top ++));
- rspamd_register_symbol_fromlua (L,
+ ret = rspamd_register_symbol_fromlua (L,
cfg,
sym,
idx,
}
}
- return 0;
+ lua_pushnumber (L, ret);
+
+ return 1;
}
static gint
struct rspamd_config *cfg = lua_check_config (L, 1);
gchar *name;
double weight;
+ gint ret = -1;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
weight = luaL_checknumber (L, 3);
if (name) {
- rspamd_symbols_cache_add_symbol_virtual (cfg->cache, name, weight);
+ ret = rspamd_symbols_cache_add_symbol_virtual (cfg->cache, name, weight);
}
}
- return 0;
+
+ lua_pushnumber (L, ret);
+
+ return 1;
}
static gint
struct rspamd_config *cfg = lua_check_config (L, 1);
gchar *name;
double weight;
+ gint ret = -1;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
lua_pushvalue (L, 4);
}
if (name) {
- rspamd_register_symbol_fromlua (L,
+ ret = rspamd_register_symbol_fromlua (L,
cfg,
name,
luaL_ref (L, LUA_REGISTRYINDEX),
}
}
- return 0;
+ lua_pushnumber (L, ret);
+
+ return 1;
}
static gint
struct rspamd_config *cfg = lua_check_config (L, 1);
gchar *name;
double weight;
- gint priority;
+ gint priority, ret = -1;
if (cfg) {
name = rspamd_mempool_strdup (cfg->cfg_pool, luaL_checkstring (L, 2));
lua_pushvalue (L, 5);
}
if (name) {
- rspamd_register_symbol_fromlua (L,
+ ret = rspamd_register_symbol_fromlua (L,
cfg,
name,
luaL_ref (L, LUA_REGISTRYINDEX),
}
}
- return 0;
+ lua_pushnumber (L, ret);
+
+ return 1;
}
static gint