}
ucl_object_t *
-rspamd_symcache_counters (struct rspamd_symcache *cache)
+rspamd_symcache_counters(struct rspamd_symcache *cache)
{
auto *real_cache = C_API_SYMCACHE(cache);
return real_cache->counters();
}
void *
-rspamd_symcache_start_refresh (struct rspamd_symcache *cache,
- struct ev_loop *ev_base, struct rspamd_worker *w)
+rspamd_symcache_start_refresh(struct rspamd_symcache *cache,
+ struct ev_loop *ev_base, struct rspamd_worker *w)
{
auto *real_cache = C_API_SYMCACHE(cache);
return new rspamd::symcache::cache_refresh_cbdata{real_cache, ev_base, w};
}
void
-rspamd_symcache_add_delayed_dependency (struct rspamd_symcache *cache,
- const gchar *from, const gchar *to)
+rspamd_symcache_add_delayed_dependency(struct rspamd_symcache *cache,
+ const gchar *from, const gchar *to)
{
auto *real_cache = C_API_SYMCACHE(cache);
real_cache->add_delayed_dependency(from, to);
}
const gchar *
-rspamd_symcache_get_parent (struct rspamd_symcache *cache,
- const gchar *symbol)
+rspamd_symcache_get_parent(struct rspamd_symcache *cache,
+ const gchar *symbol)
{
auto *real_cache = C_API_SYMCACHE(cache);
return nullptr;
}
-const gchar*
-rspamd_symcache_item_name (struct rspamd_symcache_item *item)
+const gchar *
+rspamd_symcache_item_name(struct rspamd_symcache_item *item)
{
auto *real_item = C_API_SYMCACHE_ITEM(item);
return real_item->get_name().c_str();
auto *sym = real_cache->get_item_by_name(symbol, false);
if (sym) {
- ucl_object_insert_key (this_sym_ucl,
+ ucl_object_insert_key(this_sym_ucl,
ucl_object_fromstring(sym->get_type_str()),
"type", strlen("type"), false);
}
void
rspamd_symcache_foreach(struct rspamd_symcache *cache,
- void (*func) (struct rspamd_symcache_item *item, gpointer /* userdata */),
- gpointer ud)
+ void (*func)(struct rspamd_symcache_item *item, gpointer /* userdata */),
+ gpointer ud)
{
auto *real_cache = C_API_SYMCACHE(cache);
- real_cache->symbols_foreach([&](const rspamd::symcache::cache_item* item) {
- func((struct rspamd_symcache_item *)item, ud);
+ real_cache->symbols_foreach([&](const rspamd::symcache::cache_item *item) {
+ func((struct rspamd_symcache_item *) item, ud);
});
}
}
gboolean
-rspamd_symcache_disable_symbol (struct rspamd_task *task,
- struct rspamd_symcache *cache,
- const gchar *symbol)
+rspamd_symcache_disable_symbol(struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
}
gboolean
-rspamd_symcache_enable_symbol (struct rspamd_task *task,
- struct rspamd_symcache *cache,
- const gchar *symbol)
+rspamd_symcache_enable_symbol(struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
}
gboolean
-rspamd_symcache_is_checked (struct rspamd_task *task,
- struct rspamd_symcache *cache,
- const gchar *symbol)
+rspamd_symcache_is_checked(struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
}
gboolean
-rspamd_symcache_process_settings (struct rspamd_task *task,
- struct rspamd_symcache *cache)
+rspamd_symcache_process_settings(struct rspamd_task *task,
+ struct rspamd_symcache *cache)
{
auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
auto *real_cache = C_API_SYMCACHE(cache);
return cache_runtime->process_settings(task, *real_cache);
+}
+
+gboolean
+rspamd_symcache_is_item_allowed(struct rspamd_task *task,
+ struct rspamd_symcache_item *item,
+ gboolean exec_only)
+{
+ auto *real_item = C_API_SYMCACHE_ITEM(item);
+
+ return real_item->is_allowed(task, exec_only);
+}
+
+gboolean
+rspamd_symcache_is_symbol_enabled(struct rspamd_task *task,
+ struct rspamd_symcache *cache,
+ const gchar *symbol)
+{
+ auto *cache_runtime = C_API_SYMCACHE_RUNTIME(task->symcache_runtime);
+ auto *real_cache = C_API_SYMCACHE(cache);
+
+ return cache_runtime->is_symbol_enabled(task, *real_cache, symbol);
}
\ No newline at end of file
g_hash_table_iter_init(&gr_it, gr->symbols);
while (g_hash_table_iter_next(&gr_it, &k, &v)) {
- functor((const char*)k);
+ functor((const char *) k);
}
}
}
it = nullptr;
while ((cur = ucl_iterate_object(enabled, &it, true)) != nullptr) {
- enable_symbol(task, cache,ucl_object_tostring(cur));
+ enable_symbol(task, cache, ucl_object_tostring(cur));
}
}
it = nullptr;
while ((cur = ucl_iterate_object (disabled, &it, true)) != nullptr) {
- disable_symbol(task, cache,ucl_object_tostring(cur));
+ disable_symbol(task, cache, ucl_object_tostring(cur));
}
}
auto symcache_runtime::disable_all_symbols(int skip_mask) -> void
{
- for (auto i = 0; i < order->size(); i ++) {
+ for (auto i = 0; i < order->size(); i++) {
auto *dyn_item = &dynamic_items[i];
const auto &item = order->d[i];
return false;
}
+auto
+symcache_runtime::is_symbol_enabled(struct rspamd_task *task, const symcache &cache, std::string_view name) -> bool
+{
+
+ const auto *item = cache.get_item_by_name(name, true);
+ if (item) {
+
+ if (!item->is_allowed(task, true)) {
+ return false;
+ }
+ else {
+ auto our_id_maybe = rspamd::find_map(order->by_cache_id, item->id);
+
+ if (our_id_maybe) {
+ auto *dyn_item = &dynamic_items[our_id_maybe.value()];
+ if (dyn_item->started) {
+ /* Already started */
+ return false;
+ }
+
+ if (!item->is_virtual()) {
+ return std::get<normal_item>(item->specific).check_conditions(item->symbol, task);
+ }
+ }
+ else {
+ /* Unknown item */
+ msg_debug_cache_task("cannot enable %s: symbol not found", name.data());
+ }
+ }
+ }
+
+ return true;
+}
+
}