From: Vsevolod Stakhov Date: Thu, 7 Apr 2016 15:20:42 +0000 (+0100) Subject: [Feature] Allow to get and set callback data for rspamd symbols X-Git-Tag: 1.2.3~36 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ef9d7cfd85fa422a86acd0d92bf7f637e5dabc3a;p=rspamd.git [Feature] Allow to get and set callback data for rspamd symbols --- diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index eea7f84b2..0ee9ed74c 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -1747,3 +1747,45 @@ rspamd_symbols_cache_disable_symbol (struct rspamd_task *task, msg_info_task ("cannot disable %s: not found", symbol); } } + +struct rspamd_abstract_callback_data* rspamd_symbols_cache_get_cbdata ( + struct symbols_cache *cache, const gchar *symbol) +{ + gint id; + struct cache_item *item; + + g_assert (cache != NULL); + g_assert (symbol != NULL); + + id = rspamd_symbols_cache_find_symbol_parent (cache, symbol); + + if (id < 0) { + return NULL; + } + + item = g_ptr_array_index (cache->items_by_id, id); + + return item->user_data; +} + +gboolean +rspamd_symbols_cache_set_cbdata (struct symbols_cache *cache, + const gchar *symbol, struct rspamd_abstract_callback_data *cbdata) +{ + gint id; + struct cache_item *item; + + g_assert (cache != NULL); + g_assert (symbol != NULL); + + id = rspamd_symbols_cache_find_symbol_parent (cache, symbol); + + if (id < 0) { + return FALSE; + } + + item = g_ptr_array_index (cache->items_by_id, id); + item->user_data = cbdata; + + return TRUE; +} diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h index 0d94a77a3..692d6c060 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/symbols_cache.h @@ -199,4 +199,24 @@ void rspamd_symbols_cache_add_delayed_dependency (struct symbols_cache *cache, void rspamd_symbols_cache_disable_symbol (struct rspamd_task *task, struct symbols_cache *cache, const gchar *symbol); + +/** + * Get abstract callback data for a symbol (or its parent symbol) + * @param cache cache object + * @param symbol symbol name + * @return abstract callback data or NULL if symbol is absent or has no data attached + */ +struct rspamd_abstract_callback_data* rspamd_symbols_cache_get_cbdata ( + struct symbols_cache *cache, const gchar *symbol); + +/** + * Sets new callback data for a symbol in cache + * @param cache + * @param symbol + * @param cbdata + * @return + */ +gboolean rspamd_symbols_cache_set_cbdata (struct symbols_cache *cache, + const gchar *symbol, struct rspamd_abstract_callback_data *cbdata); + #endif