auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_item = C_API_SYMCACHE_ITEM(item);
- return (struct rspamd_symcache_item *)cache_runtime->set_cur_item(real_item);
+ return (struct rspamd_symcache_item *) cache_runtime->set_cur_item(real_item);
}
void
}
return FALSE;
+}
+
+struct rspamd_abstract_callback_data *
+rspamd_symcache_get_cbdata(struct rspamd_symcache *cache,
+ const gchar *symbol)
+{
+ auto *real_cache = C_API_SYMCACHE(cache);
+
+ auto *item = real_cache->get_item_by_name(symbol, true);
+
+ if (item) {
+ return (struct rspamd_abstract_callback_data *) item->get_cbdata();
+ }
+
+ return nullptr;
+}
+
+void
+rspamd_symcache_composites_foreach(struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ GHFunc func,
+ gpointer fd)
+{
+ auto *real_cache = C_API_SYMCACHE(cache);
+ auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
+
+ real_cache->composites_foreach([&](const auto *item) {
+ auto *dyn_item = cache_runtime->get_dynamic_item(item->id, false);
+
+ if (dyn_item->started) {
+ func((void *)item->get_name().c_str(), item->get_cbdata(), fd);
+ dyn_item->finished = true;
+ }
+ });
}
\ No newline at end of file
}
}
+ /**
+ * Iterate over all composites using a specific functor
+ * @tparam Functor
+ * @param f
+ */
+ template<typename Functor>
+ auto composites_foreach(Functor f) -> void {
+ for (const auto &sym_it : composites) {
+ f(sym_it.get());
+ }
+ }
+
/**
* Resort cache if anything has been changed since last time
* @return
return std::all_of(std::begin(conditions), std::end(conditions),
[&](const auto &cond) { return cond.check(sym_name, task); });
}
+
+ auto get_cbdata() const -> auto {
+ return user_data;
+ }
};
class virtual_item {
*/
auto is_allowed(struct rspamd_task *task, bool exec_only) const -> bool;
+ /**
+ * Returns callback data
+ * @return
+ */
+ auto get_cbdata() const -> void * {
+ if (std::holds_alternative<normal_item>(specific)) {
+ const auto &filter_data = std::get<normal_item>(specific);
+
+ return filter_data.get_cbdata();
+ }
+
+ return nullptr;
+ }
+
private:
/**
* Constructor for a normal symbols with callback
priority(_priority),
specific(normal_item{func, user_data})
{
+ /* These structures are kept trivial, so they need to be explicitly reset */
forbidden_ids.reset();
allowed_ids.reset();
exec_only_ids.reset();
flags(_flags),
specific(virtual_item{parent})
{
+ /* These structures are kept trivial, so they need to be explicitly reset */
forbidden_ids.reset();
allowed_ids.reset();
exec_only_ids.reset();