summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-07 16:20:42 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-04-07 16:20:42 +0100
commitef9d7cfd85fa422a86acd0d92bf7f637e5dabc3a (patch)
tree771619b2676606859508dd266abc22eb96733672
parent93e08dc6e00459b2fda6119bfc630b0fb996758c (diff)
downloadrspamd-ef9d7cfd85fa422a86acd0d92bf7f637e5dabc3a.tar.gz
rspamd-ef9d7cfd85fa422a86acd0d92bf7f637e5dabc3a.zip
[Feature] Allow to get and set callback data for rspamd symbols
-rw-r--r--src/libserver/symbols_cache.c42
-rw-r--r--src/libserver/symbols_cache.h20
2 files changed, 62 insertions, 0 deletions
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