]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Registering symbols now returns their id.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 May 2015 07:44:40 +0000 (08:44 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 28 May 2015 07:44:40 +0000 (08:44 +0100)
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h
src/lua/lua_config.c

index be7ef98d97609daa463886f521ece389d433fd40..f7e4e5d7b50b57e06b3beb509693d89dd1520c6f 100644 (file)
@@ -305,7 +305,7 @@ rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name)
        return ret;
 }
 
-void
+gint
 rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
        const gchar *name,
        double weight,
@@ -320,7 +320,7 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
 
        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,
@@ -349,13 +349,15 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache,
        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,
@@ -364,12 +366,12 @@ rspamd_symbols_cache_add_symbol_normal (struct symbols_cache *cache, const gchar
                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,
@@ -378,14 +380,14 @@ rspamd_symbols_cache_add_symbol_virtual (struct symbols_cache *cache,
                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,
@@ -394,7 +396,7 @@ rspamd_symbols_cache_add_symbol_callback (struct symbols_cache *cache,
                SYMBOL_TYPE_CALLBACK);
 }
 
-void
+gint
 rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
        const gchar *name,
        double weight,
@@ -402,7 +404,7 @@ rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
        symbol_func_t func,
        gpointer user_data)
 {
-       rspamd_symbols_cache_add_symbol (cache,
+       return rspamd_symbols_cache_add_symbol (cache,
                name,
                weight,
                priority,
index c0b43ee6b68e6589ebb64d1bed6e0e9ff09e00bd..b3ebcc55978a19a4b3cb16880f9bbec4be3b9ca8 100644 (file)
@@ -68,7 +68,7 @@ gboolean rspamd_symbols_cache_init (struct symbols_cache* cache,
  * @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,
@@ -79,7 +79,7 @@ void rspamd_symbols_cache_add_symbol_normal (struct symbols_cache *cache,
  * 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);
 
@@ -89,7 +89,7 @@ void rspamd_symbols_cache_add_symbol_virtual (struct symbols_cache *cache,
  * @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,
@@ -101,7 +101,7 @@ void rspamd_symbols_cache_add_symbol_callback (struct symbols_cache *cache,
  * @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,
@@ -118,7 +118,7 @@ void rspamd_symbols_cache_add_symbol_callback_prio (struct symbols_cache *cache,
  * @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,
index 247805f984a04fa454c388a8a4b5716e230a73f5..845c3740dfc334713947e58438ea46ec5629eee0 100644 (file)
@@ -848,7 +848,7 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
        }
 }
 
-static void
+static gint
 rspamd_register_symbol_fromlua (lua_State *L,
                struct rspamd_config *cfg,
                const gchar *name,
@@ -858,6 +858,7 @@ rspamd_register_symbol_fromlua (lua_State *L,
                enum rspamd_symbol_type type)
 {
        struct lua_callback_data *cd;
+       gint ret = -1;
 
        if (name) {
                cd = rspamd_mempool_alloc0 (cfg->cfg_pool,
@@ -867,7 +868,7 @@ rspamd_register_symbol_fromlua (lua_State *L,
                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,
@@ -879,7 +880,7 @@ rspamd_register_symbol_fromlua (lua_State *L,
                                cd);
        }
 
-
+       return ret;
 }
 
 static gint
@@ -888,6 +889,7 @@ lua_config_register_symbol (lua_State * L)
        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));
@@ -900,7 +902,7 @@ lua_config_register_symbol (lua_State * L)
                        lua_pushvalue (L, 4);
                }
                if (name) {
-                       rspamd_register_symbol_fromlua (L,
+                       ret = rspamd_register_symbol_fromlua (L,
                                        cfg,
                                        name,
                                        luaL_ref (L, LUA_REGISTRYINDEX),
@@ -910,14 +912,16 @@ lua_config_register_symbol (lua_State * L)
                }
        }
 
-       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;
 
@@ -942,7 +946,7 @@ lua_config_register_symbols (lua_State *L)
                        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,
@@ -970,7 +974,9 @@ lua_config_register_symbols (lua_State *L)
                }
        }
 
-       return 0;
+       lua_pushnumber (L, ret);
+
+       return 1;
 }
 
 static gint
@@ -979,15 +985,19 @@ lua_config_register_virtual_symbol (lua_State * L)
        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
@@ -996,6 +1006,7 @@ lua_config_register_callback_symbol (lua_State * L)
        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));
@@ -1008,7 +1019,7 @@ lua_config_register_callback_symbol (lua_State * L)
                        lua_pushvalue (L, 4);
                }
                if (name) {
-                       rspamd_register_symbol_fromlua (L,
+                       ret = rspamd_register_symbol_fromlua (L,
                                        cfg,
                                        name,
                                        luaL_ref (L, LUA_REGISTRYINDEX),
@@ -1018,7 +1029,9 @@ lua_config_register_callback_symbol (lua_State * L)
                }
        }
 
-       return 0;
+       lua_pushnumber (L, ret);
+
+       return 1;
 }
 
 static gint
@@ -1027,7 +1040,7 @@ lua_config_register_callback_symbol_priority (lua_State * L)
        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));
@@ -1041,7 +1054,7 @@ lua_config_register_callback_symbol_priority (lua_State * L)
                        lua_pushvalue (L, 5);
                }
                if (name) {
-                       rspamd_register_symbol_fromlua (L,
+                       ret = rspamd_register_symbol_fromlua (L,
                                        cfg,
                                        name,
                                        luaL_ref (L, LUA_REGISTRYINDEX),
@@ -1051,7 +1064,9 @@ lua_config_register_callback_symbol_priority (lua_State * L)
                }
        }
 
-       return 0;
+       lua_pushnumber (L, ret);
+
+       return 1;
 }
 
 static gint