]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow to get and set callback data for rspamd symbols
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Apr 2016 15:20:42 +0000 (16:20 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Apr 2016 15:20:42 +0000 (16:20 +0100)
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h

index eea7f84b29fdfab26a08191e8e80a7550862dad0..0ee9ed74c49d13c82b987585b5a1c1159fa55dfc 100644 (file)
@@ -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;
+}
index 0d94a77a3e947616e1bc82174b995c822e3f1f75..692d6c060fe0b71d7993ab812bad5096dcc95de6 100644 (file)
@@ -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