diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-29 12:22:46 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-10-29 12:22:46 +0000 |
commit | 4929e73f2baaa0dd29759a6705ac8dd1b06beb90 (patch) | |
tree | e5ea92f88a12cb3ad667ef92eda62b643f2adcc9 | |
parent | c16f6393333532ceeb65fdc7f62efbc14a987329 (diff) | |
download | rspamd-4929e73f2baaa0dd29759a6705ac8dd1b06beb90.tar.gz rspamd-4929e73f2baaa0dd29759a6705ac8dd1b06beb90.zip |
[Project] Another rework for symbols cache
34 files changed, 353 insertions, 343 deletions
diff --git a/src/controller.c b/src/controller.c index e533c12ce..26d12e14b 100644 --- a/src/controller.c +++ b/src/controller.c @@ -822,7 +822,7 @@ rspamd_controller_handle_symbols (struct rspamd_http_connection_entry *conn_ent, "description", 0, false); } - if (rspamd_symbols_cache_stat_symbol (session->ctx->cfg->cache, + if (rspamd_symcache_stat_symbol (session->ctx->cfg->cache, sym->name, &freq, &freq_dev, &tm, NULL)) { ucl_object_insert_key (sym_obj, ucl_object_fromdouble (freq), @@ -2743,7 +2743,7 @@ rspamd_controller_handle_counters ( { struct rspamd_controller_session *session = conn_ent->ud; ucl_object_t *top; - struct symbols_cache *cache; + struct rspamd_symcache *cache; if (!rspamd_controller_check_password (conn_ent, session, msg, FALSE)) { return 0; @@ -2752,7 +2752,7 @@ rspamd_controller_handle_counters ( cache = session->ctx->cfg->cache; if (cache != NULL) { - top = rspamd_symbols_cache_counters (cache); + top = rspamd_symcache_counters (cache); rspamd_controller_send_ucl (conn_ent, top); ucl_object_unref (top); } @@ -3837,7 +3837,7 @@ start_controller_worker (struct rspamd_worker *worker) rspamd_upstreams_library_config (worker->srv->cfg, worker->srv->cfg->ups_ctx, ctx->ev_base, ctx->resolver->r); - rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base, + rspamd_symcache_start_refresh (worker->srv->cfg->cache, ctx->ev_base, worker); rspamd_stat_init (worker->srv->cfg, ctx->ev_base); diff --git a/src/libmime/filter.c b/src/libmime/filter.c index 5f47a5c6a..94c9ac223 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -420,7 +420,7 @@ rspamd_task_insert_result_full (struct rspamd_task *task, /* Process cache item */ if (task->cfg->cache) { - rspamd_symbols_cache_inc_frequency (task->cfg->cache, symbol); + rspamd_symcache_inc_frequency (task->cfg->cache, symbol); } return s; diff --git a/src/libmime/filter.h b/src/libmime/filter.h index 78d67e77c..73f8269fa 100644 --- a/src/libmime/filter.h +++ b/src/libmime/filter.h @@ -7,7 +7,7 @@ #define RSPAMD_FILTER_H #include "config.h" -#include "symbols_cache.h" +#include "rspamd_symcache.h" #include "task.h" #include "khash.h" diff --git a/src/libserver/CMakeLists.txt b/src/libserver/CMakeLists.txt index ac2c123dc..ccedbcdb3 100644 --- a/src/libserver/CMakeLists.txt +++ b/src/libserver/CMakeLists.txt @@ -16,7 +16,7 @@ SET(LIBRSPAMDSERVERSRC ${CMAKE_CURRENT_SOURCE_DIR}/re_cache.c ${CMAKE_CURRENT_SOURCE_DIR}/roll_history.c ${CMAKE_CURRENT_SOURCE_DIR}/spf.c - ${CMAKE_CURRENT_SOURCE_DIR}/symbols_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/rspamd_symcache.c ${CMAKE_CURRENT_SOURCE_DIR}/task.c ${CMAKE_CURRENT_SOURCE_DIR}/url.c ${CMAKE_CURRENT_SOURCE_DIR}/worker_util.c) diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index cb3581e97..f1d9eb939 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -20,7 +20,7 @@ #include "config.h" #include "mem_pool.h" #include "upstream.h" -#include "symbols_cache.h" +#include "rspamd_symcache.h" #include "cfg_rcl.h" #include "ucl.h" #include "regexp.h" @@ -375,7 +375,7 @@ struct rspamd_config { gdouble monitored_interval; /**< interval between monitored checks */ gboolean disable_monitored; /**< disable monitoring completely */ - struct symbols_cache *cache; /**< symbols cache object */ + struct rspamd_symcache *cache; /**< symbols cache object */ gchar *cache_filename; /**< filename of cache file */ gdouble cache_reload_time; /**< how often cache reload should be performed */ gchar * checksum; /**< real checksum of config file */ diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index a96cd6b67..e44051c9d 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -1223,7 +1223,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, composite); if (new) { - rspamd_symbols_cache_add_symbol (cfg->cache, composite_name, 0, + rspamd_symcache_add_symbol (cfg->cache, composite_name, 0, NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1); } diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index ff1e77d15..198e55530 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -179,7 +179,7 @@ rspamd_config_new (enum rspamd_config_init_flags flags) cfg->lua_thread_pool = lua_thread_pool_new (cfg->lua_state); } - cfg->cache = rspamd_symbols_cache_new (cfg); + cfg->cache = rspamd_symcache_new (cfg); cfg->ups_ctx = rspamd_upstreams_library_init (); cfg->re_cache = rspamd_re_cache_new (); cfg->doc_strings = ucl_object_typed_new (UCL_OBJECT); @@ -228,7 +228,7 @@ rspamd_config_free (struct rspamd_config *cfg) g_list_free (cfg->classifiers); g_list_free (cfg->workers); - rspamd_symbols_cache_destroy (cfg->cache); + rspamd_symcache_destroy (cfg->cache); ucl_object_unref (cfg->rcl_obj); ucl_object_unref (cfg->config_comments); ucl_object_unref (cfg->doc_strings); @@ -804,7 +804,7 @@ rspamd_config_post_load (struct rspamd_config *cfg, lua_settop (L, err_idx - 1); /* Init config cache */ - rspamd_symbols_cache_init (cfg->cache); + rspamd_symcache_init (cfg->cache); /* Init re cache */ rspamd_re_cache_init (cfg->re_cache, cfg); @@ -861,7 +861,7 @@ rspamd_config_post_load (struct rspamd_config *cfg, ret = FALSE; } - ret = rspamd_symbols_cache_validate (cfg->cache, cfg, FALSE) && ret; + ret = rspamd_symcache_validate (cfg->cache, cfg, FALSE) && ret; } if (opts & RSPAMD_CONFIG_INIT_PRELOAD_MAPS) { @@ -1229,8 +1229,8 @@ symbols_classifiers_callback (gpointer key, gpointer value, gpointer ud) struct rspamd_config *cfg = ud; /* Actually, statistics should act like any ordinary symbol */ - rspamd_symbols_cache_add_symbol (cfg->cache, key, 0, NULL, NULL, - SYMBOL_TYPE_CLASSIFIER|SYMBOL_TYPE_NOSTAT, -1); + rspamd_symcache_add_symbol (cfg->cache, key, 0, NULL, NULL, + SYMBOL_TYPE_CLASSIFIER | SYMBOL_TYPE_NOSTAT, -1); } void diff --git a/src/libserver/composites.c b/src/libserver/composites.c index 308383605..f46f8276d 100644 --- a/src/libserver/composites.c +++ b/src/libserver/composites.c @@ -424,7 +424,7 @@ composites_foreach_callback (gpointer key, gpointer value, void *data) task = cd->task; if (!isset (cd->checked, cd->composite->id * 2)) { - if (rspamd_symbols_cache_is_checked (cd->task, cd->task->cfg->cache, + if (rspamd_symcache_is_checked (cd->task, cd->task->cfg->cache, key)) { msg_debug_composites ("composite %s is checked in symcache but not " "in composites bitfield", cd->composite->sym); diff --git a/src/libserver/dns.c b/src/libserver/dns.c index 966ced377..02cf0d4d7 100644 --- a/src/libserver/dns.c +++ b/src/libserver/dns.c @@ -63,7 +63,7 @@ rspamd_dns_fin_cb (gpointer arg) struct rspamd_dns_request_ud *reqdata = (struct rspamd_dns_request_ud *)arg; if (reqdata->item) { - rspamd_symbols_cache_set_cur_item (reqdata->task, reqdata->item); + rspamd_symcache_set_cur_item (reqdata->task, reqdata->item); } if (reqdata->reply) { @@ -198,7 +198,7 @@ make_dns_request_task_common (struct rspamd_task *task, task->dns_requests ++; reqdata->task = task; - reqdata->item = rspamd_symbols_cache_get_cur_item (task); + reqdata->item = rspamd_symcache_get_cur_item (task); if (reqdata->item) { /* We are inside some session */ diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index c83451058..76a41445b 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -1570,7 +1570,7 @@ rspamd_protocol_write_log_pipe (struct rspamd_task *task) i = 0; kh_foreach_value_ptr (mres->symbols, sym, { - id = rspamd_symbols_cache_find_symbol (task->cfg->cache, + id = rspamd_symcache_find_symbol (task->cfg->cache, sym->name); if (id >= 0) { diff --git a/src/libserver/symbols_cache.c b/src/libserver/rspamd_symcache.c index dac24a1cf..70aff0d1b 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/rspamd_symcache.c @@ -17,7 +17,7 @@ #include "util.h" #include "rspamd.h" #include "message.h" -#include "symbols_cache.h" +#include "rspamd_symcache.h" #include "cfg_file.h" #include "lua/lua_common.h" #include "unix-std.h" @@ -64,7 +64,7 @@ INIT_LOG_MODULE(symcache) static const guchar rspamd_symbols_cache_magic[8] = {'r', 's', 'c', 2, 0, 0, 0, 0 }; -static gint rspamd_symbols_cache_find_filter (struct symbols_cache *cache, +static gint rspamd_symbols_cache_find_filter (struct rspamd_symcache *cache, const gchar *name); struct rspamd_symbols_cache_header { @@ -80,9 +80,10 @@ struct symbols_cache_order { ref_entry_t ref; }; -struct symbols_cache { +struct rspamd_symcache { /* Hash table for fast access */ GHashTable *items_by_symbol; + GPtrArray *items_by_id; struct symbols_cache_order *items_by_order; GPtrArray *filters; GPtrArray *prefilters; @@ -116,14 +117,19 @@ struct item_stat { gdouble stddev_frequency; }; +struct rspamd_symcache_dynamic_item { + guint16 start_msec; /* Relative to task time */ + unsigned started:1; + unsigned finished:1; + /* unsigned pad:14; */ + guint32 async_events; +}; + struct rspamd_symcache_item { /* This block is likely shared */ struct item_stat *st; guint64 last_count; - /* Per process counter */ - gdouble start_ticks; - guint async_events; struct rspamd_counter_data *cd; gchar *symbol; enum rspamd_symbol_type type; @@ -185,17 +191,6 @@ enum rspamd_cache_savepoint_stage { RSPAMD_CACHE_PASS_DONE, }; -struct cache_bits { -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L - _Alignas(guint64) guint8 *started; - _Alignas(guint64) guint8 *finished; -#else -#warning "outdated compiler, please use C11 compiler" - guint8 *started; - guint8 *finished; -#endif -}; - struct cache_savepoint { enum rspamd_cache_savepoint_stage pass; guint version; @@ -205,19 +200,14 @@ struct cache_savepoint { gdouble lim; struct rspamd_symcache_item *cur_item; - struct cache_bits *cur_bits; struct symbols_cache_order *order; - - struct cache_bits prefilters; - struct cache_bits filters; - struct cache_bits postfilters; - struct cache_bits idempotent; + GArray *dynamic_items; }; struct rspamd_cache_refresh_cbdata { gdouble last_resort; struct event resort_ev; - struct symbols_cache *cache; + struct rspamd_symcache *cache; struct rspamd_worker *w; struct event_base *ev_base; }; @@ -231,21 +221,21 @@ struct rspamd_cache_refresh_cbdata { / (t > TIME_ALPHA ? t : TIME_ALPHA)) static gboolean rspamd_symbols_cache_check_symbol (struct rspamd_task *task, - struct symbols_cache *cache, + struct rspamd_symcache *cache, struct rspamd_symcache_item *item, struct cache_savepoint *checkpoint); static gboolean rspamd_symbols_cache_check_deps (struct rspamd_task *task, - struct symbols_cache *cache, + struct rspamd_symcache *cache, struct rspamd_symcache_item *item, struct cache_savepoint *checkpoint, guint recursion, gboolean check_only); static void rspamd_symbols_cache_disable_symbol_checkpoint (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol); + struct rspamd_symcache *cache, const gchar *symbol); static void rspamd_symbols_cache_enable_symbol_checkpoint (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol); + struct rspamd_symcache *cache, const gchar *symbol); static void rspamd_symbols_cache_disable_all_symbols (struct rspamd_task *task, - struct symbols_cache *cache); + struct rspamd_symcache *cache); static void rspamd_symbols_cache_order_dtor (gpointer p) @@ -265,7 +255,7 @@ rspamd_symbols_cache_order_unref (gpointer p) } static struct symbols_cache_order * -rspamd_symbols_cache_order_new (struct symbols_cache *cache, +rspamd_symbols_cache_order_new (struct rspamd_symcache *cache, gsize nelts) { struct symbols_cache_order *ord; @@ -278,6 +268,14 @@ rspamd_symbols_cache_order_new (struct symbols_cache *cache, return ord; } +static inline struct rspamd_symcache_item* +rspamd_symcache_get_dynamic (struct cache_savepoint *checkpoint, + struct rspamd_symcache_item *item) +{ + return &g_array_index (checkpoint->dynamic_items, + struct rspamd_symcache_item, item->id); +} + static gint postfilters_cmp (const void *p1, const void *p2, gpointer ud) { @@ -329,7 +327,7 @@ cache_logic_cmp (const void *p1, const void *p2, gpointer ud) { const struct rspamd_symcache_item *i1 = *(struct rspamd_symcache_item **)p1, *i2 = *(struct rspamd_symcache_item **)p2; - struct symbols_cache *cache = ud; + struct rspamd_symcache *cache = ud; double w1, w2; double weight1, weight2; double f1 = 0, f2 = 0, t1, t2, avg_freq, avg_weight; @@ -371,7 +369,7 @@ cache_logic_cmp (const void *p1, const void *p2, gpointer ud) } static void -rspamd_symbols_cache_tsort_visit (struct symbols_cache *cache, +rspamd_symbols_cache_tsort_visit (struct rspamd_symcache *cache, struct rspamd_symcache_item *it, guint cur_order) { @@ -408,7 +406,7 @@ rspamd_symbols_cache_tsort_visit (struct symbols_cache *cache, } static void -rspamd_symbols_cache_resort (struct symbols_cache *cache) +rspamd_symbols_cache_resort (struct rspamd_symcache *cache) { struct symbols_cache_order *ord; guint i; @@ -453,7 +451,7 @@ rspamd_symbols_cache_resort (struct symbols_cache *cache) /* Sort items in logical order */ static void -rspamd_symbols_cache_post_init (struct symbols_cache *cache) +rspamd_symbols_cache_post_init (struct rspamd_symcache *cache) { struct rspamd_symcache_item *it, *dit; struct cache_dependency *dep, *rdep; @@ -483,7 +481,7 @@ rspamd_symbols_cache_post_init (struct symbols_cache *cache) else { msg_debug_cache ("delayed between %s(%d) -> %s", ddep->from, it->id, ddep->to); - rspamd_symbols_cache_add_dependency (cache, it->id, ddep->to); + rspamd_symcache_add_dependency (cache, it->id, ddep->to); } cur = g_list_next (cur); @@ -565,7 +563,7 @@ rspamd_symbols_cache_post_init (struct symbols_cache *cache) } static gboolean -rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name) +rspamd_symbols_cache_load_items (struct rspamd_symcache *cache, const gchar *name) { struct rspamd_symbols_cache_header *hdr; struct stat st; @@ -731,7 +729,7 @@ rspamd_symbols_cache_load_items (struct symbols_cache *cache, const gchar *name) #define ROUND_DOUBLE(x) (floor((x) * 100.0) / 100.0) static gboolean -rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name) +rspamd_symbols_cache_save_items (struct rspamd_symcache *cache, const gchar *name) { struct rspamd_symbols_cache_header hdr; ucl_object_t *top, *elt, *freq; @@ -824,13 +822,13 @@ rspamd_symbols_cache_save_items (struct symbols_cache *cache, const gchar *name) #undef ROUND_DOUBLE gint -rspamd_symbols_cache_add_symbol (struct symbols_cache *cache, - const gchar *name, - gint priority, - symbol_func_t func, - gpointer user_data, - enum rspamd_symbol_type type, - gint parent) +rspamd_symcache_add_symbol (struct rspamd_symcache *cache, + const gchar *name, + gint priority, + symbol_func_t func, + gpointer user_data, + enum rspamd_symbol_type type, + gint parent) { struct rspamd_symcache_item *item = NULL; @@ -882,23 +880,22 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache, g_assert (parent == -1); if (item->type & SYMBOL_TYPE_PREFILTER) { - item->id = cache->prefilters->len; g_ptr_array_add (cache->prefilters, item); } else if (item->type & SYMBOL_TYPE_IDEMPOTENT) { - item->id = cache->idempotent->len; g_ptr_array_add (cache->idempotent, item); } else if (item->type & SYMBOL_TYPE_POSTFILTER) { - item->id = cache->postfilters->len; g_ptr_array_add (cache->postfilters, item); } else { - item->id = cache->filters->len; item->is_filter = TRUE; g_ptr_array_add (cache->filters, item); } + item->id = cache->items_by_id->len; + g_ptr_array_add (cache->items_by_id, item); + item->specific.normal.func = func; item->specific.normal.user_data = user_data; item->specific.normal.condition_cb = -1; @@ -911,14 +908,17 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache, * - composite symbol */ if (item->type & SYMBOL_TYPE_COMPOSITE) { - item->id = cache->composites->len; item->specific.normal.condition_cb = -1; g_ptr_array_add (cache->composites, item); + + item->id = cache->items_by_id->len; + g_ptr_array_add (cache->items_by_id, item); } else if (item->type & SYMBOL_TYPE_CLASSIFIER) { /* Treat it as normal symbol to allow enable/disable */ - item->id = cache->filters->len; - g_ptr_array_add (cache->filters, item); + item->id = cache->items_by_id->len; + g_ptr_array_add (cache->items_by_id, item); + item->is_filter = TRUE; item->specific.normal.func = NULL; item->specific.normal.user_data = NULL; @@ -983,8 +983,8 @@ rspamd_symbols_cache_add_symbol (struct symbols_cache *cache, } void -rspamd_symbols_cache_set_peak_callback (struct symbols_cache *cache, - gint cbref) +rspamd_symcache_set_peak_callback (struct rspamd_symcache *cache, + gint cbref) { g_assert (cache != NULL); @@ -998,8 +998,8 @@ rspamd_symbols_cache_set_peak_callback (struct symbols_cache *cache, } gboolean -rspamd_symbols_cache_add_condition_delayed (struct symbols_cache *cache, - const gchar *sym, lua_State *L, gint cbref) +rspamd_symcache_add_condition_delayed (struct rspamd_symcache *cache, + const gchar *sym, lua_State *L, gint cbref) { struct delayed_cache_condition *ncond; @@ -1018,7 +1018,7 @@ rspamd_symbols_cache_add_condition_delayed (struct symbols_cache *cache, } void -rspamd_symbols_cache_save (struct symbols_cache *cache) +rspamd_symcache_save (struct rspamd_symcache *cache) { if (cache != NULL) { @@ -1034,14 +1034,14 @@ rspamd_symbols_cache_save (struct symbols_cache *cache) } void -rspamd_symbols_cache_destroy (struct symbols_cache *cache) +rspamd_symcache_destroy (struct rspamd_symcache *cache) { GList *cur; struct delayed_cache_dependency *ddep; struct delayed_cache_condition *dcond; if (cache != NULL) { - rspamd_symbols_cache_save (cache); + rspamd_symcache_save (cache); if (cache->delayed_deps) { cur = cache->delayed_deps; @@ -1071,6 +1071,7 @@ rspamd_symbols_cache_destroy (struct symbols_cache *cache) } g_hash_table_destroy (cache->items_by_symbol); + g_ptr_array_free (cache->items_by_order, TRUE); rspamd_mempool_delete (cache->static_pool); g_ptr_array_free (cache->filters, TRUE); g_ptr_array_free (cache->prefilters, TRUE); @@ -1088,16 +1089,17 @@ rspamd_symbols_cache_destroy (struct symbols_cache *cache) } } -struct symbols_cache* -rspamd_symbols_cache_new (struct rspamd_config *cfg) +struct rspamd_symcache* +rspamd_symcache_new (struct rspamd_config *cfg) { - struct symbols_cache *cache; + struct rspamd_symcache *cache; - cache = g_malloc0 (sizeof (struct symbols_cache)); + cache = g_malloc0 (sizeof (struct rspamd_symcache)); cache->static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "symcache"); cache->items_by_symbol = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); + cache->items_by_order = g_ptr_array_new (); cache->filters = g_ptr_array_new (); cache->prefilters = g_ptr_array_new (); cache->postfilters = g_ptr_array_new (); @@ -1117,7 +1119,7 @@ rspamd_symbols_cache_new (struct rspamd_config *cfg) } gboolean -rspamd_symbols_cache_init (struct symbols_cache* cache) +rspamd_symcache_init (struct rspamd_symcache *cache) { gboolean res; @@ -1144,7 +1146,7 @@ rspamd_symbols_cache_validate_cb (gpointer k, gpointer v, gpointer ud) { struct rspamd_symcache_item *item = v, *parent; struct rspamd_config *cfg; - struct symbols_cache *cache = (struct symbols_cache *)ud; + struct rspamd_symcache *cache = (struct rspamd_symcache *)ud; struct rspamd_symbol *s; gboolean skipped, ghost; gint p1, p2; @@ -1220,7 +1222,7 @@ rspamd_symbols_cache_validate_cb (gpointer k, gpointer v, gpointer ud) static void rspamd_symbols_cache_metric_validate_cb (gpointer k, gpointer v, gpointer ud) { - struct symbols_cache *cache = (struct symbols_cache *)ud; + struct rspamd_symcache *cache = (struct rspamd_symcache *)ud; const gchar *sym = k; struct rspamd_symbol *s = (struct rspamd_symbol *)v; gdouble weight; @@ -1235,9 +1237,9 @@ rspamd_symbols_cache_metric_validate_cb (gpointer k, gpointer v, gpointer ud) } gboolean -rspamd_symbols_cache_validate (struct symbols_cache *cache, - struct rspamd_config *cfg, - gboolean strict) +rspamd_symcache_validate (struct rspamd_symcache *cache, + struct rspamd_config *cfg, + gboolean strict) { struct rspamd_symcache_item *item; GHashTableIter it; @@ -1328,7 +1330,7 @@ rspamd_symbols_cache_metric_limit (struct rspamd_task *task, static gboolean rspamd_symbols_cache_check_symbol (struct rspamd_task *task, - struct symbols_cache *cache, + struct rspamd_symcache *cache, struct rspamd_symcache_item *item, struct cache_savepoint *checkpoint) { @@ -1421,7 +1423,7 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task, static gboolean rspamd_symbols_cache_check_deps (struct rspamd_task *task, - struct symbols_cache *cache, + struct rspamd_symcache *cache, struct rspamd_symcache_item *item, struct cache_savepoint *checkpoint, guint recursion, @@ -1521,7 +1523,7 @@ rspamd_symbols_cache_check_deps (struct rspamd_task *task, static struct cache_savepoint * rspamd_symbols_cache_make_checkpoint (struct rspamd_task *task, - struct symbols_cache *cache) + struct rspamd_symcache *cache) { struct cache_savepoint *checkpoint; @@ -1559,8 +1561,8 @@ rspamd_symbols_cache_make_checkpoint (struct rspamd_task *task, } gboolean -rspamd_symbols_cache_process_settings (struct rspamd_task *task, - struct symbols_cache *cache) +rspamd_symcache_process_settings (struct rspamd_task *task, + struct rspamd_symcache *cache) { const ucl_object_t *wl, *cur, *disabled, *enabled; struct rspamd_symbols_group *gr; @@ -1654,8 +1656,8 @@ rspamd_symbols_cache_process_settings (struct rspamd_task *task, } gboolean -rspamd_symbols_cache_process_symbols (struct rspamd_task * task, - struct symbols_cache *cache, gint stage) +rspamd_symcache_process_symbols (struct rspamd_task *task, + struct rspamd_symcache *cache, gint stage) { struct rspamd_symcache_item *item = NULL; struct cache_savepoint *checkpoint; @@ -1732,7 +1734,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task, } if (stage == RSPAMD_TASK_STAGE_FILTERS) { - return rspamd_symbols_cache_process_symbols (task, cache, stage); + return rspamd_symcache_process_symbols (task, cache, stage); } break; @@ -1792,7 +1794,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task, if (stage == RSPAMD_TASK_STAGE_POST_FILTERS) { - return rspamd_symbols_cache_process_symbols (task, cache, stage); + return rspamd_symcache_process_symbols (task, cache, stage); } break; @@ -1846,7 +1848,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task, } if (stage == RSPAMD_TASK_STAGE_IDEMPOTENT) { - return rspamd_symbols_cache_process_symbols (task, cache, stage); + return rspamd_symcache_process_symbols (task, cache, stage); } break; @@ -1914,7 +1916,7 @@ rspamd_symbols_cache_process_symbols (struct rspamd_task * task, struct counters_cbdata { ucl_object_t *top; - struct symbols_cache *cache; + struct rspamd_symcache *cache; }; #define ROUND_DOUBLE(x) (floor((x) * 100.0) / 100.0) @@ -1970,7 +1972,7 @@ rspamd_symbols_cache_counters_cb (gpointer k, gpointer v, gpointer ud) #undef ROUND_DOUBLE ucl_object_t * -rspamd_symbols_cache_counters (struct symbols_cache * cache) +rspamd_symcache_counters (struct rspamd_symcache *cache) { ucl_object_t *top; struct counters_cbdata cbd; @@ -1987,7 +1989,7 @@ rspamd_symbols_cache_counters (struct symbols_cache * cache) static void rspamd_symbols_cache_call_peak_cb (struct event_base *ev_base, - struct symbols_cache *cache, + struct rspamd_symcache *cache, struct rspamd_symcache_item *item, gdouble cur_value, gdouble cur_err) @@ -2018,7 +2020,7 @@ rspamd_symbols_cache_resort_cb (gint fd, short what, gpointer ud) struct timeval tv; gdouble tm; struct rspamd_cache_refresh_cbdata *cbdata = ud; - struct symbols_cache *cache; + struct rspamd_symcache *cache; struct rspamd_symcache_item *item; guint i; gdouble cur_ticks; @@ -2103,8 +2105,8 @@ rspamd_symbols_cache_resort_cb (gint fd, short what, gpointer ud) } void -rspamd_symbols_cache_start_refresh (struct symbols_cache * cache, - struct event_base *ev_base, struct rspamd_worker *w) +rspamd_symcache_start_refresh (struct rspamd_symcache *cache, + struct event_base *ev_base, struct rspamd_worker *w) { struct timeval tv; gdouble tm; @@ -2129,8 +2131,8 @@ rspamd_symbols_cache_start_refresh (struct symbols_cache * cache, } void -rspamd_symbols_cache_inc_frequency (struct symbols_cache *cache, - const gchar *symbol) +rspamd_symcache_inc_frequency (struct rspamd_symcache *cache, + const gchar *symbol) { struct rspamd_symcache_item *item; @@ -2144,8 +2146,8 @@ rspamd_symbols_cache_inc_frequency (struct symbols_cache *cache, } void -rspamd_symbols_cache_add_dependency (struct symbols_cache *cache, - gint id_from, const gchar *to) +rspamd_symcache_add_dependency (struct rspamd_symcache *cache, + gint id_from, const gchar *to) { struct rspamd_symcache_item *source; struct cache_dependency *dep; @@ -2162,8 +2164,8 @@ rspamd_symbols_cache_add_dependency (struct symbols_cache *cache, } void -rspamd_symbols_cache_add_delayed_dependency (struct symbols_cache *cache, - const gchar *from, const gchar *to) +rspamd_symcache_add_delayed_dependency (struct rspamd_symcache *cache, + const gchar *from, const gchar *to) { struct delayed_cache_dependency *ddep; @@ -2178,7 +2180,7 @@ rspamd_symbols_cache_add_delayed_dependency (struct symbols_cache *cache, } gint -rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, const gchar *name) +rspamd_symcache_find_symbol (struct rspamd_symcache *cache, const gchar *name) { struct rspamd_symcache_item *item; @@ -2198,9 +2200,9 @@ rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, const gchar *name } gboolean -rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache, - const gchar *name, gdouble *frequency, gdouble *freq_stddev, - gdouble *tm, guint *nhits) +rspamd_symcache_stat_symbol (struct rspamd_symcache *cache, + const gchar *name, gdouble *frequency, gdouble *freq_stddev, + gdouble *tm, guint *nhits) { struct rspamd_symcache_item *item; @@ -2228,7 +2230,7 @@ rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache, } static gint -rspamd_symbols_cache_find_filter (struct symbols_cache *cache, +rspamd_symbols_cache_find_filter (struct rspamd_symcache *cache, const gchar *name) { struct rspamd_symcache_item *item; @@ -2259,8 +2261,8 @@ rspamd_symbols_cache_find_filter (struct symbols_cache *cache, } const gchar * -rspamd_symbols_cache_symbol_by_id (struct symbols_cache *cache, - gint id) +rspamd_symcache_symbol_by_id (struct rspamd_symcache *cache, + gint id) { struct rspamd_symcache_item *item; @@ -2276,7 +2278,7 @@ rspamd_symbols_cache_symbol_by_id (struct symbols_cache *cache, } guint -rspamd_symbols_cache_stats_symbols_count (struct symbols_cache *cache) +rspamd_symcache_stats_symbols_count (struct rspamd_symcache *cache) { g_assert (cache != NULL); @@ -2290,7 +2292,7 @@ rspamd_symbols_cache_stats_symbols_count (struct symbols_cache *cache) static void rspamd_symbols_cache_disable_all_symbols (struct rspamd_task *task, - struct symbols_cache *cache) + struct rspamd_symcache *cache) { struct cache_savepoint *checkpoint; guint i; @@ -2321,7 +2323,7 @@ rspamd_symbols_cache_disable_all_symbols (struct rspamd_task *task, static struct rspamd_symcache_item * rspamd_symbols_cache_get_item_and_bits (struct rspamd_task *task, - struct symbols_cache *cache, + struct rspamd_symcache *cache, struct cache_savepoint *checkpoint, const gchar *symbol, struct cache_bits **bits) @@ -2356,7 +2358,7 @@ rspamd_symbols_cache_get_item_and_bits (struct rspamd_task *task, static void rspamd_symbols_cache_disable_symbol_checkpoint (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol) + struct rspamd_symcache *cache, const gchar *symbol) { struct cache_savepoint *checkpoint; struct rspamd_symcache_item *item; @@ -2391,7 +2393,7 @@ rspamd_symbols_cache_disable_symbol_checkpoint (struct rspamd_task *task, static void rspamd_symbols_cache_enable_symbol_checkpoint (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol) + struct rspamd_symcache *cache, const gchar *symbol) { struct cache_savepoint *checkpoint; struct rspamd_symcache_item *item; @@ -2425,8 +2427,8 @@ rspamd_symbols_cache_enable_symbol_checkpoint (struct rspamd_task *task, } struct rspamd_abstract_callback_data* -rspamd_symbols_cache_get_cbdata (struct symbols_cache *cache, - const gchar *symbol) +rspamd_symcache_get_cbdata (struct rspamd_symcache *cache, + const gchar *symbol) { struct rspamd_symcache_item *item; @@ -2448,8 +2450,8 @@ rspamd_symbols_cache_get_cbdata (struct symbols_cache *cache, } gboolean -rspamd_symbols_cache_is_checked (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol) +rspamd_symcache_is_checked (struct rspamd_task *task, + struct rspamd_symcache *cache, const gchar *symbol) { struct cache_savepoint *checkpoint; struct rspamd_symcache_item *item; @@ -2477,8 +2479,8 @@ rspamd_symbols_cache_is_checked (struct rspamd_task *task, } void -rspamd_symbols_cache_disable_symbol (struct symbols_cache *cache, - const gchar *symbol) +rspamd_symcache_disable_symbol (struct rspamd_symcache *cache, + const gchar *symbol) { struct rspamd_symcache_item *item; @@ -2493,8 +2495,8 @@ rspamd_symbols_cache_disable_symbol (struct symbols_cache *cache, } void -rspamd_symbols_cache_enable_symbol (struct symbols_cache *cache, - const gchar *symbol) +rspamd_symcache_enable_symbol (struct rspamd_symcache *cache, + const gchar *symbol) { struct rspamd_symcache_item *item; @@ -2509,7 +2511,7 @@ rspamd_symbols_cache_enable_symbol (struct symbols_cache *cache, } guint64 -rspamd_symbols_cache_get_cksum (struct symbols_cache *cache) +rspamd_symcache_get_cksum (struct rspamd_symcache *cache) { g_assert (cache != NULL); @@ -2518,8 +2520,8 @@ rspamd_symbols_cache_get_cksum (struct symbols_cache *cache) gboolean -rspamd_symbols_cache_is_symbol_enabled (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol) +rspamd_symcache_is_symbol_enabled (struct rspamd_task *task, + struct rspamd_symcache *cache, const gchar *symbol) { struct cache_savepoint *checkpoint; struct rspamd_symcache_item *item; @@ -2570,9 +2572,9 @@ rspamd_symbols_cache_is_symbol_enabled (struct rspamd_task *task, } void -rspamd_symbols_cache_foreach (struct symbols_cache *cache, - void (*func)(gint , const gchar *, gint , gpointer ), - gpointer ud) +rspamd_symcache_foreach (struct rspamd_symcache *cache, + void (*func) (gint, const gchar *, gint, gpointer), + gpointer ud) { struct rspamd_symcache_item *item; GHashTableIter it; @@ -2587,7 +2589,7 @@ rspamd_symbols_cache_foreach (struct symbols_cache *cache, } struct rspamd_symcache_item * -rspamd_symbols_cache_get_cur_item (struct rspamd_task *task) +rspamd_symcache_get_cur_item (struct rspamd_task *task) { struct cache_savepoint *checkpoint = task->checkpoint; @@ -2606,8 +2608,8 @@ rspamd_symbols_cache_get_cur_item (struct rspamd_task *task) * @return */ struct rspamd_symcache_item * -rspamd_symbols_cache_set_cur_item (struct rspamd_task *task, - struct rspamd_symcache_item *item) +rspamd_symcache_set_cur_item (struct rspamd_task *task, + struct rspamd_symcache_item *item) { struct cache_savepoint *checkpoint = task->checkpoint; struct rspamd_symcache_item *ex; @@ -2623,8 +2625,8 @@ rspamd_symbols_cache_set_cur_item (struct rspamd_task *task, * Finalize the current async element potentially calling its deps */ void -rspamd_symbols_cache_finalize_item (struct rspamd_task *task, - struct rspamd_symcache_item *item) +rspamd_symcache_finalize_item (struct rspamd_task *task, + struct rspamd_symcache_item *item) { struct cache_savepoint *checkpoint = task->checkpoint; struct cache_dependency *rdep; @@ -2737,7 +2739,7 @@ rspamd_symcache_item_async_dec_check_full (struct rspamd_task *task, const gchar *loc) { if (rspamd_symcache_item_async_dec_full (task, item, subsystem, loc) == 0) { - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return TRUE; } diff --git a/src/libserver/symbols_cache.h b/src/libserver/rspamd_symcache.h index d3983f91d..0542f86b4 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/rspamd_symcache.h @@ -23,7 +23,7 @@ struct rspamd_task; struct rspamd_config; -struct symbols_cache; +struct rspamd_symcache; struct rspamd_worker; struct rspamd_symcache_item; @@ -61,24 +61,24 @@ struct rspamd_abstract_callback_data { * Creates new cache structure * @return */ -struct symbols_cache* rspamd_symbols_cache_new (struct rspamd_config *cfg); +struct rspamd_symcache* rspamd_symcache_new (struct rspamd_config *cfg); /** * Remove the cache structure syncing data if needed * @param cache */ -void rspamd_symbols_cache_destroy (struct symbols_cache *cache); +void rspamd_symcache_destroy (struct rspamd_symcache *cache); /** * Saves symbols cache to disk if possible * @param cache */ -void rspamd_symbols_cache_save (struct symbols_cache *cache); +void rspamd_symcache_save (struct rspamd_symcache *cache); /** * Load symbols cache from file, must be called _after_ init_symbols_cache */ -gboolean rspamd_symbols_cache_init (struct symbols_cache* cache); +gboolean rspamd_symcache_init (struct rspamd_symcache *cache); /** * Generic function to register a symbol @@ -91,21 +91,21 @@ gboolean rspamd_symbols_cache_init (struct symbols_cache* cache); * @param type * @param parent */ -gint rspamd_symbols_cache_add_symbol (struct symbols_cache *cache, - const gchar *name, - gint priority, - symbol_func_t func, - gpointer user_data, - enum rspamd_symbol_type type, - gint parent); +gint rspamd_symcache_add_symbol (struct rspamd_symcache *cache, + const gchar *name, + gint priority, + symbol_func_t func, + gpointer user_data, + enum rspamd_symbol_type type, + gint parent); /** * Add callback to be executed whenever symbol has peak value * @param cache * @param cbref */ -void rspamd_symbols_cache_set_peak_callback (struct symbols_cache *cache, - gint cbref); +void rspamd_symcache_set_peak_callback (struct rspamd_symcache *cache, + gint cbref); /** * Add delayed condition to the specific symbol in cache. So symbol can be absent * to the moment of addition @@ -115,8 +115,9 @@ void rspamd_symbols_cache_set_peak_callback (struct symbols_cache *cache, * @param cbref callback reference (returned by luaL_ref) * @return TRUE if condition has been added */ -gboolean rspamd_symbols_cache_add_condition_delayed (struct symbols_cache *cache, - const gchar *sym, lua_State *L, gint cbref); +gboolean rspamd_symcache_add_condition_delayed (struct rspamd_symcache *cache, + const gchar *sym, + lua_State *L, gint cbref); /** * Find symbol in cache by id and returns its id resolving virtual symbols if @@ -125,8 +126,8 @@ gboolean rspamd_symbols_cache_add_condition_delayed (struct symbols_cache *cache * @param name * @return id of symbol or (-1) if a symbol has not been found */ -gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, - const gchar *name); +gint rspamd_symcache_find_symbol (struct rspamd_symcache *cache, + const gchar *name); /** * Get statistics for a specific symbol @@ -136,24 +137,27 @@ gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache, * @param tm * @return */ -gboolean rspamd_symbols_cache_stat_symbol (struct symbols_cache *cache, - const gchar *name, gdouble *frequency, gdouble *freq_stddev, - gdouble *tm, guint *nhits); +gboolean rspamd_symcache_stat_symbol (struct rspamd_symcache *cache, + const gchar *name, + gdouble *frequency, + gdouble *freq_stddev, + gdouble *tm, + guint *nhits); /** * Find symbol in cache by its id * @param cache * @param id * @return symbol's name or NULL */ -const gchar * rspamd_symbols_cache_symbol_by_id (struct symbols_cache *cache, - gint id); +const gchar * rspamd_symcache_symbol_by_id (struct rspamd_symcache *cache, + gint id); /** * Returns number of symbols registered in symbols cache * @param cache * @return number of symbols in the cache */ -guint rspamd_symbols_cache_stats_symbols_count (struct symbols_cache *cache); +guint rspamd_symcache_stats_symbols_count (struct rspamd_symcache *cache); /** * Call function for cached symbol using saved callback @@ -161,8 +165,9 @@ guint rspamd_symbols_cache_stats_symbols_count (struct symbols_cache *cache); * @param cache symbols cache * @param saved_item pointer to currently saved item */ -gboolean rspamd_symbols_cache_process_symbols (struct rspamd_task *task, - struct symbols_cache *cache, gint stage); +gboolean rspamd_symcache_process_symbols (struct rspamd_task *task, + struct rspamd_symcache *cache, + gint stage); /** * Validate cache items against theirs weights defined in metrics @@ -170,32 +175,33 @@ gboolean rspamd_symbols_cache_process_symbols (struct rspamd_task *task, * @param cfg configuration * @param strict do strict checks - symbols MUST be described in metrics */ -gboolean rspamd_symbols_cache_validate (struct symbols_cache *cache, - struct rspamd_config *cfg, - gboolean strict); +gboolean rspamd_symcache_validate (struct rspamd_symcache *cache, + struct rspamd_config *cfg, + gboolean strict); /** * Return statistics about the cache as ucl object (array of objects one per item) * @param cache * @return */ -ucl_object_t *rspamd_symbols_cache_counters (struct symbols_cache * cache); +ucl_object_t *rspamd_symcache_counters (struct rspamd_symcache *cache); /** * Start cache reloading * @param cache * @param ev_base */ -void rspamd_symbols_cache_start_refresh (struct symbols_cache * cache, - struct event_base *ev_base, struct rspamd_worker *w); +void rspamd_symcache_start_refresh (struct rspamd_symcache *cache, + struct event_base *ev_base, + struct rspamd_worker *w); /** * Increases counter for a specific symbol * @param cache * @param symbol */ -void rspamd_symbols_cache_inc_frequency (struct symbols_cache *cache, - const gchar *symbol); +void rspamd_symcache_inc_frequency (struct rspamd_symcache *cache, + const gchar *symbol); /** * Add dependency relation between two symbols identified by id (source) and @@ -204,8 +210,8 @@ void rspamd_symbols_cache_inc_frequency (struct symbols_cache *cache, * @param id_from source symbol * @param to destination name */ -void rspamd_symbols_cache_add_dependency (struct symbols_cache *cache, - gint id_from, const gchar *to); +void rspamd_symcache_add_dependency (struct rspamd_symcache *cache, + gint id_from, const gchar *to); /** * Add delayed dependency that is resolved on cache post-load routine @@ -213,32 +219,32 @@ void rspamd_symbols_cache_add_dependency (struct symbols_cache *cache, * @param from * @param to */ -void rspamd_symbols_cache_add_delayed_dependency (struct symbols_cache *cache, - const gchar *from, const gchar *to); +void rspamd_symcache_add_delayed_dependency (struct rspamd_symcache *cache, + const gchar *from, const gchar *to); /** * Disable specific symbol in the cache * @param cache * @param symbol */ -void rspamd_symbols_cache_disable_symbol (struct symbols_cache *cache, - const gchar *symbol); +void rspamd_symcache_disable_symbol (struct rspamd_symcache *cache, + const gchar *symbol); /** * Enable specific symbol in the cache * @param cache * @param symbol */ -void rspamd_symbols_cache_enable_symbol (struct symbols_cache *cache, - const gchar *symbol); +void rspamd_symcache_enable_symbol (struct rspamd_symcache *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); +struct rspamd_abstract_callback_data* rspamd_symcache_get_cbdata ( + struct rspamd_symcache *cache, const gchar *symbol); /** @@ -247,8 +253,8 @@ struct rspamd_abstract_callback_data* rspamd_symbols_cache_get_cbdata ( * @param cache * @return */ -gboolean rspamd_symbols_cache_process_settings (struct rspamd_task *task, - struct symbols_cache *cache); +gboolean rspamd_symcache_process_settings (struct rspamd_task *task, + struct rspamd_symcache *cache); /** @@ -258,15 +264,16 @@ gboolean rspamd_symbols_cache_process_settings (struct rspamd_task *task, * @param symbol * @return */ -gboolean rspamd_symbols_cache_is_checked (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol); +gboolean rspamd_symcache_is_checked (struct rspamd_task *task, + struct rspamd_symcache *cache, + const gchar *symbol); /** * Returns checksum for all cache items * @param cache * @return */ -guint64 rspamd_symbols_cache_get_cksum (struct symbols_cache *cache); +guint64 rspamd_symcache_get_cksum (struct rspamd_symcache *cache); /** * Checks if a symbols is enabled (not checked and conditions return true if present) @@ -275,25 +282,26 @@ guint64 rspamd_symbols_cache_get_cksum (struct symbols_cache *cache); * @param symbol * @return */ -gboolean rspamd_symbols_cache_is_symbol_enabled (struct rspamd_task *task, - struct symbols_cache *cache, const gchar *symbol); +gboolean rspamd_symcache_is_symbol_enabled (struct rspamd_task *task, + struct rspamd_symcache *cache, + const gchar *symbol); /** * Process specific function for each cache element (in order they are added) * @param cache * @param func * @param ud */ -void rspamd_symbols_cache_foreach (struct symbols_cache *cache, - void (*func)(gint /* id */, const gchar * /* name */, - gint /* flags */, gpointer /* userdata */), - gpointer ud); +void rspamd_symcache_foreach (struct rspamd_symcache *cache, + void (*func) (gint /* id */, const gchar * /* name */, + gint /* flags */, gpointer /* userdata */), + gpointer ud); /** * Returns the current item being processed (if any) * @param task * @return */ -struct rspamd_symcache_item *rspamd_symbols_cache_get_cur_item (struct rspamd_task *task); +struct rspamd_symcache_item *rspamd_symcache_get_cur_item (struct rspamd_task *task); /** * Replaces the current item being processed. @@ -302,15 +310,15 @@ struct rspamd_symcache_item *rspamd_symbols_cache_get_cur_item (struct rspamd_ta * @param item * @return */ -struct rspamd_symcache_item *rspamd_symbols_cache_set_cur_item (struct rspamd_task *task, - struct rspamd_symcache_item *item); +struct rspamd_symcache_item *rspamd_symcache_set_cur_item (struct rspamd_task *task, + struct rspamd_symcache_item *item); /** * Finalize the current async element potentially calling its deps */ -void rspamd_symbols_cache_finalize_item (struct rspamd_task *task, - struct rspamd_symcache_item *item); +void rspamd_symcache_finalize_item (struct rspamd_task *task, + struct rspamd_symcache_item *item); /* * Increase number of async events pending for an item diff --git a/src/libserver/task.c b/src/libserver/task.c index f4a09fd30..061feaded 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -744,7 +744,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages) break; case RSPAMD_TASK_STAGE_PRE_FILTERS: - rspamd_symbols_cache_process_symbols (task, task->cfg->cache, + rspamd_symcache_process_symbols (task, task->cfg->cache, RSPAMD_TASK_STAGE_PRE_FILTERS); break; @@ -755,7 +755,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages) break; case RSPAMD_TASK_STAGE_FILTERS: - rspamd_symbols_cache_process_symbols (task, task->cfg->cache, + rspamd_symcache_process_symbols (task, task->cfg->cache, RSPAMD_TASK_STAGE_FILTERS); break; @@ -776,7 +776,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages) break; case RSPAMD_TASK_STAGE_POST_FILTERS: - rspamd_symbols_cache_process_symbols (task, task->cfg->cache, + rspamd_symcache_process_symbols (task, task->cfg->cache, RSPAMD_TASK_STAGE_POST_FILTERS); if ((task->flags & RSPAMD_TASK_FLAG_LEARN_AUTO) && @@ -827,7 +827,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages) rspamd_make_composites (task); break; case RSPAMD_TASK_STAGE_IDEMPOTENT: - rspamd_symbols_cache_process_symbols (task, task->cfg->cache, + rspamd_symcache_process_symbols (task, task->cfg->cache, RSPAMD_TASK_STAGE_IDEMPOTENT); break; diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c index ea032a229..b63b9bc36 100644 --- a/src/libstat/backends/redis_backend.c +++ b/src/libstat/backends/redis_backend.c @@ -1605,7 +1605,7 @@ rspamd_redis_process_tokens (struct rspamd_task *task, rt->redis_object_expanded, learned_key) == REDIS_OK) { rspamd_session_add_event (task->s, rspamd_redis_fin, rt, M); - rt->item = rspamd_symbols_cache_get_cur_item (task); + rt->item = rspamd_symcache_get_cur_item (task); rt->has_event = TRUE; if (rspamd_event_pending (&rt->timeout_event, EV_TIMEOUT)) { @@ -1810,7 +1810,7 @@ rspamd_redis_learn_tokens (struct rspamd_task *task, GPtrArray *tokens, } rspamd_session_add_event (task->s, rspamd_redis_fin_learn, rt, M); - rt->item = rspamd_symbols_cache_get_cur_item (task); + rt->item = rspamd_symcache_get_cur_item (task); rt->has_event = TRUE; /* Set timeout */ diff --git a/src/libstat/learn_cache/redis_cache.c b/src/libstat/learn_cache/redis_cache.c index 2fbf8bc4e..d8b7c9c37 100644 --- a/src/libstat/learn_cache/redis_cache.c +++ b/src/libstat/learn_cache/redis_cache.c @@ -466,7 +466,7 @@ rspamd_stat_cache_redis_check (struct rspamd_task *task, rspamd_redis_cache_fin, rt, M); - rt->item = rspamd_symbols_cache_get_cur_item (task); + rt->item = rspamd_symcache_get_cur_item (task); event_add (&rt->timeout_event, &tv); rt->has_event = TRUE; } @@ -500,7 +500,7 @@ rspamd_stat_cache_redis_learn (struct rspamd_task *task, rt->ctx->redis_object, h, flag) == REDIS_OK) { rspamd_session_add_event (task->s, rspamd_redis_cache_fin, rt, M); - rt->item = rspamd_symbols_cache_get_cur_item (task); + rt->item = rspamd_symcache_get_cur_item (task); event_add (&rt->timeout_event, &tv); rt->has_event = TRUE; } diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index ca51d7b02..2641226d5 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -445,7 +445,7 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, continue; } - if (!rspamd_symbols_cache_is_symbol_enabled (task, task->cfg->cache, + if (!rspamd_symcache_is_symbol_enabled (task, task->cfg->cache, st->stcf->symbol)) { g_ptr_array_index (task->stat_runtimes, i) = NULL; msg_debug_task ("symbol %s is disabled, skip classification", diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index bfe82f7ea..60e1076db 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -1246,7 +1246,7 @@ rspamd_register_symbol_fromlua (lua_State *L, priority = 1; } - if ((ret = rspamd_symbols_cache_find_symbol (cfg->cache, name)) != -1) { + if ((ret = rspamd_symcache_find_symbol (cfg->cache, name)) != -1) { if (optional) { msg_debug_config ("duplicate symbol: %s, skip registering", name); @@ -1303,7 +1303,7 @@ rspamd_register_symbol_fromlua (lua_State *L, cd->symbol = rspamd_mempool_strdup (cfg->cfg_pool, name); } - ret = rspamd_symbols_cache_add_symbol (cfg->cache, + ret = rspamd_symcache_add_symbol (cfg->cache, name, priority, lua_metric_symbol_callback, @@ -1327,7 +1327,7 @@ rspamd_register_symbol_fromlua (lua_State *L, cd->symbol = rspamd_mempool_strdup (cfg->cfg_pool, name); } - ret = rspamd_symbols_cache_add_symbol (cfg->cache, + ret = rspamd_symcache_add_symbol (cfg->cache, name, priority, lua_metric_symbol_callback, @@ -1343,7 +1343,7 @@ rspamd_register_symbol_fromlua (lua_State *L, lua_settop (L, err_idx - 1); } else { - ret = rspamd_symbols_cache_add_symbol (cfg->cache, + ret = rspamd_symcache_add_symbol (cfg->cache, name, priority, NULL, @@ -1720,7 +1720,7 @@ lua_config_register_symbols (lua_State *L) while (lua_next (L, -2)) { lua_pushvalue (L, -2); sym = luaL_checkstring (L, -2); - rspamd_symbols_cache_add_symbol (cfg->cache, sym, + rspamd_symcache_add_symbol (cfg->cache, sym, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, ret); lua_pop (L, 2); @@ -1729,7 +1729,7 @@ lua_config_register_symbols (lua_State *L) } else if (lua_type (L, i) == LUA_TSTRING) { sym = luaL_checkstring (L, i); - rspamd_symbols_cache_add_symbol (cfg->cache, sym, + rspamd_symcache_add_symbol (cfg->cache, sym, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, ret); } @@ -1759,7 +1759,7 @@ lua_config_register_virtual_symbol (lua_State * L) } if (name) { - ret = rspamd_symbols_cache_add_symbol (cfg->cache, name, + ret = rspamd_symcache_add_symbol (cfg->cache, name, weight > 0 ? 0 : -1, NULL, NULL, SYMBOL_TYPE_VIRTUAL, parent); } @@ -1920,9 +1920,9 @@ lua_config_register_dependency (lua_State * L) if (child_id > 0 && parent != NULL) { if (skip_squeeze || !rspamd_lua_squeeze_dependency (L, cfg, - rspamd_symbols_cache_symbol_by_id (cfg->cache, child_id), + rspamd_symcache_symbol_by_id (cfg->cache, child_id), parent)) { - rspamd_symbols_cache_add_dependency (cfg->cache, child_id, parent); + rspamd_symcache_add_dependency (cfg->cache, child_id, parent); } } } @@ -1937,7 +1937,7 @@ lua_config_register_dependency (lua_State * L) if (child != NULL && parent != NULL) { if (skip_squeeze || !rspamd_lua_squeeze_dependency (L, cfg, child, parent)) { - rspamd_symbols_cache_add_delayed_dependency (cfg->cache, child, + rspamd_symcache_add_delayed_dependency (cfg->cache, child, parent); } @@ -2233,7 +2233,7 @@ lua_config_add_composite (lua_State * L) composite); if (new) { - rspamd_symbols_cache_add_symbol (cfg->cache, name, + rspamd_symcache_add_symbol (cfg->cache, name, 0, NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1); } @@ -2380,7 +2380,7 @@ lua_config_newindex (lua_State *L) /* Here we pop function from the stack, so no lua_pop is required */ condref = luaL_ref (L, LUA_REGISTRYINDEX); g_assert (name != NULL); - rspamd_symbols_cache_add_condition_delayed (cfg->cache, + rspamd_symcache_add_condition_delayed (cfg->cache, name, L, condref); } else { @@ -2496,7 +2496,7 @@ lua_config_add_condition (lua_State *L) lua_pushvalue (L, 3); condref = luaL_ref (L, LUA_REGISTRYINDEX); - ret = rspamd_symbols_cache_add_condition_delayed (cfg->cache, sym, L, + ret = rspamd_symcache_add_condition_delayed (cfg->cache, sym, L, condref); if (!ret) { @@ -2518,7 +2518,7 @@ lua_config_set_peak_cb (lua_State *L) if (cfg && lua_type (L, 2) == LUA_TFUNCTION) { lua_pushvalue (L, 2); condref = luaL_ref (L, LUA_REGISTRYINDEX); - rspamd_symbols_cache_set_peak_callback (cfg->cache, + rspamd_symcache_set_peak_callback (cfg->cache, condref); } @@ -2533,7 +2533,7 @@ lua_config_enable_symbol (lua_State *L) const gchar *sym = luaL_checkstring (L, 2); if (cfg && sym) { - rspamd_symbols_cache_enable_symbol (cfg->cache, sym); + rspamd_symcache_enable_symbol (cfg->cache, sym); } else { return luaL_error (L, "invalid arguments"); @@ -2550,7 +2550,7 @@ lua_config_disable_symbol (lua_State *L) const gchar *sym = luaL_checkstring (L, 2); if (cfg && sym) { - rspamd_symbols_cache_disable_symbol (cfg->cache, sym); + rspamd_symcache_disable_symbol (cfg->cache, sym); } else { return luaL_error (L, "invalid arguments"); @@ -2865,7 +2865,7 @@ lua_config_get_symbols_count (lua_State *L) guint res = 0; if (cfg != NULL) { - res = rspamd_symbols_cache_stats_symbols_count (cfg->cache); + res = rspamd_symcache_stats_symbols_count (cfg->cache); } else { return luaL_error (L, "invalid arguments"); @@ -2884,7 +2884,7 @@ lua_config_get_symbols_cksum (lua_State *L) guint64 res = 0, *pres; if (cfg != NULL) { - res = rspamd_symbols_cache_get_cksum (cfg->cache); + res = rspamd_symcache_get_cksum (cfg->cache); } else { return luaL_error (L, "invalid arguments"); @@ -2905,7 +2905,7 @@ lua_config_get_symbols_counters (lua_State *L) ucl_object_t *counters; if (cfg != NULL) { - counters = rspamd_symbols_cache_counters (cfg->cache); + counters = rspamd_symcache_counters (cfg->cache); ucl_object_push_lua (L, counters, true); ucl_object_unref (counters); } @@ -2965,7 +2965,7 @@ lua_config_get_symbol_callback (lua_State *L) struct lua_callback_data *cbd; if (cfg != NULL && sym != NULL) { - abs_cbdata = rspamd_symbols_cache_get_cbdata (cfg->cache, sym); + abs_cbdata = rspamd_symcache_get_cbdata (cfg->cache, sym); if (abs_cbdata == NULL || abs_cbdata->magic != rspamd_lua_callback_magic) { lua_pushnil (L); @@ -2998,7 +2998,7 @@ lua_config_set_symbol_callback (lua_State *L) struct lua_callback_data *cbd; if (cfg != NULL && sym != NULL && lua_type (L, 3) == LUA_TFUNCTION) { - abs_cbdata = rspamd_symbols_cache_get_cbdata (cfg->cache, sym); + abs_cbdata = rspamd_symcache_get_cbdata (cfg->cache, sym); if (abs_cbdata == NULL || abs_cbdata->magic != rspamd_lua_callback_magic) { lua_pushboolean (L, FALSE); @@ -3035,7 +3035,7 @@ lua_config_get_symbol_stat (lua_State *L) guint hits; if (cfg != NULL && sym != NULL) { - if (!rspamd_symbols_cache_stat_symbol (cfg->cache, sym, &freq, + if (!rspamd_symcache_stat_symbol (cfg->cache, sym, &freq, &stddev, &tm, &hits)) { lua_pushnil (L); } diff --git a/src/lua/lua_dns.c b/src/lua/lua_dns.c index 632ff6f1b..f9b8ff9c6 100644 --- a/src/lua/lua_dns.c +++ b/src/lua/lua_dns.c @@ -140,7 +140,7 @@ lua_dns_request (lua_State *L) cbdata->s = session; if (task) { - cbdata->item = rspamd_symbols_cache_get_cur_item (task); + cbdata->item = rspamd_symcache_get_cur_item (task); rspamd_symcache_item_async_inc (task, cbdata->item, M); } diff --git a/src/lua/lua_dns_resolver.c b/src/lua/lua_dns_resolver.c index 5d1043d75..ffc4cd738 100644 --- a/src/lua/lua_dns_resolver.c +++ b/src/lua/lua_dns_resolver.c @@ -188,7 +188,7 @@ lua_dns_resolver_callback (struct rdns_reply *reply, gpointer arg) if (cd->item) { /* We also need to restore the item in case there are some chains */ - rspamd_symbols_cache_set_cur_item (cd->task, cd->item); + rspamd_symcache_set_cur_item (cd->task, cd->item); } if (lua_pcall (L, 6, 0, err_idx) != 0) { @@ -373,7 +373,7 @@ lua_dns_resolver_resolve_common (lua_State *L, if (task) { pool = task->task_pool; session = task->s; - item = rspamd_symbols_cache_get_cur_item (task); + item = rspamd_symcache_get_cur_item (task); } if (to_resolve != NULL) { diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 9da25bc71..806322449 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -179,7 +179,7 @@ lua_http_push_error (struct lua_http_cbdata *cbd, const char *err) if (cbd->item) { - rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item); + rspamd_symcache_set_cur_item (cbd->task, cbd->item); } if (lua_pcall (L, 1, 0, 0) != 0) { @@ -267,7 +267,7 @@ lua_http_finish_handler (struct rspamd_http_connection *conn, if (cbd->item) { /* Replace watcher to deal with nested calls */ - rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item); + rspamd_symcache_set_cur_item (cbd->task, cbd->item); } if (lua_pcall (L, 4, 0, 0) != 0) { @@ -358,7 +358,7 @@ lua_http_resume_handler (struct rspamd_http_connection *conn, if (cbd->item) { /* Replace watcher to deal with nested calls */ - rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item); + rspamd_symcache_set_cur_item (cbd->task, cbd->item); } lua_thread_resume (cbd->thread, 2); @@ -895,7 +895,7 @@ lua_http_request (lua_State *L) cbd->task = task; if (task) { - cbd->item = rspamd_symbols_cache_get_cur_item (task); + cbd->item = rspamd_symcache_get_cur_item (task); } if (msg->host) { diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index ecf97c459..f87878837 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -283,7 +283,7 @@ lua_redis_push_error (const gchar *err, lua_pushnil (cbs.L); if (ud->item) { - rspamd_symbols_cache_set_cur_item (ud->task, ud->item); + rspamd_symcache_set_cur_item (ud->task, ud->item); } if (lua_pcall (cbs.L, 2, 0, 0) != 0) { @@ -373,7 +373,7 @@ lua_redis_push_data (const redisReply *r, struct lua_redis_ctx *ctx, lua_redis_push_reply (cbs.L, r, ctx->flags & LUA_REDIS_TEXTDATA); if (ud->item) { - rspamd_symbols_cache_set_cur_item (ud->task, ud->item); + rspamd_symcache_set_cur_item (ud->task, ud->item); } if (lua_pcall (cbs.L, 2, 0, 0) != 0) { @@ -939,7 +939,7 @@ rspamd_lua_redis_prepare_connection (lua_State *L, gint *pcbref, gboolean is_asy ud->task = task; if (task) { - ud->item = rspamd_symbols_cache_get_cur_item (task); + ud->item = rspamd_symcache_get_cur_item (task); } ret = TRUE; diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 18754ee6b..15af4cf5a 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -3609,7 +3609,7 @@ lua_task_get_symbols_numeric (lua_State *L) kh_foreach_value_ptr (mres->symbols, s, { if (!(s->flags & RSPAMD_SYMBOL_RESULT_IGNORED)) { - id = rspamd_symbols_cache_find_symbol (task->cfg->cache, + id = rspamd_symcache_find_symbol (task->cfg->cache, s->name); lua_pushinteger (L, id); lua_rawseti (L, -3, i); @@ -3683,8 +3683,8 @@ lua_task_get_symbols_tokens (lua_State *L) } lua_createtable (L, - rspamd_symbols_cache_stats_symbols_count (task->cfg->cache), 0); - rspamd_symbols_cache_foreach (task->cfg->cache, tokens_foreach_cb, &cbd); + rspamd_symcache_stats_symbols_count (task->cfg->cache), 0); + rspamd_symcache_foreach (task->cfg->cache, tokens_foreach_cb, &cbd); return 1; } @@ -4189,7 +4189,7 @@ lua_task_set_settings (lua_State *L) } } - rspamd_symbols_cache_process_settings (task, task->cfg->cache); + rspamd_symcache_process_settings (task, task->cfg->cache); } else { return luaL_error (L, "invalid arguments"); diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 8d657b466..b9406111a 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -574,7 +574,7 @@ lua_tcp_push_error (struct lua_tcp_cbdata *cbd, gboolean is_fatal, TCP_RETAIN (cbd); if (cbd->item) { - rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item); + rspamd_symcache_set_cur_item (cbd->task, cbd->item); } if (lua_pcall (L, 3, 0, 0) != 0) { @@ -657,7 +657,7 @@ lua_tcp_push_data (struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) TCP_RETAIN (cbd); if (cbd->item) { - rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item); + rspamd_symcache_set_cur_item (cbd->task, cbd->item); } if (lua_pcall (L, arg_cnt, 0, 0) != 0) { @@ -722,7 +722,7 @@ lua_tcp_resume_thread (struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) lua_thread_pool_set_running_entry (cbd->cfg->lua_thread_pool, cbd->thread); if (cbd->item) { - rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item); + rspamd_symcache_set_cur_item (cbd->task, cbd->item); } lua_thread_resume (cbd->thread, 2); @@ -1034,7 +1034,7 @@ lua_tcp_handler (int fd, short what, gpointer ud) rspamd_lua_setclass (L, "rspamd{tcp}", -1); if (cbd->item) { - rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item); + rspamd_symcache_set_cur_item (cbd->task, cbd->item); } if (lua_pcall (L, 1, 0, 0) != 0) { @@ -1558,7 +1558,7 @@ lua_tcp_request (lua_State *L) cbd->task = task; if (task) { - cbd->item = rspamd_symbols_cache_get_cur_item (task); + cbd->item = rspamd_symcache_get_cur_item (task); } cbd->cfg = cfg; @@ -1833,7 +1833,7 @@ lua_tcp_connect_sync (lua_State *L) } } else { - cbd->item = rspamd_symbols_cache_get_cur_item (task); + cbd->item = rspamd_symcache_get_cur_item (task); if (!make_dns_request_task (task, lua_tcp_dns_handler, cbd, RDNS_REQUEST_A, host)) { diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 925cb07ca..ace99048e 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -734,7 +734,7 @@ lua_util_config_from_ucl (lua_State *L) cfg->lua_state = L; cfg->rcl_obj = obj; - cfg->cache = rspamd_symbols_cache_new (cfg); + cfg->cache = rspamd_symcache_new (cfg); top = rspamd_rcl_config_init (cfg, NULL); if (!rspamd_rcl_parse (top, cfg, cfg, cfg->cfg_pool, cfg->rcl_obj, &err)) { diff --git a/src/plugins/chartable.c b/src/plugins/chartable.c index 208b78d49..ce80b2e66 100644 --- a/src/plugins/chartable.c +++ b/src/plugins/chartable.c @@ -150,14 +150,14 @@ chartable_module_config (struct rspamd_config *cfg) chartable_module_ctx->threshold = DEFAULT_THRESHOLD; } - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, chartable_module_ctx->symbol, 0, chartable_symbol_callback, NULL, SYMBOL_TYPE_NORMAL, -1); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, chartable_module_ctx->url_symbol, 0, chartable_url_symbol_callback, @@ -668,7 +668,7 @@ chartable_symbol_callback (struct rspamd_task *task, utext_close (&utxt); } - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); } static void @@ -739,5 +739,5 @@ chartable_url_symbol_callback (struct rspamd_task *task, } - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); } diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index ae4b0f04d..72091fccb 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -504,50 +504,50 @@ dkim_module_config (struct rspamd_config *cfg) return TRUE; } - cb_id = rspamd_symbols_cache_add_symbol (cfg->cache, + cb_id = rspamd_symcache_add_symbol (cfg->cache, "DKIM_CHECK", 0, dkim_symbol_callback, NULL, SYMBOL_TYPE_CALLBACK, -1); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, dkim_module_ctx->symbol_reject, 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_FINE, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, dkim_module_ctx->symbol_na, 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_FINE, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, dkim_module_ctx->symbol_permfail, 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_FINE, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, dkim_module_ctx->symbol_tempfail, 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_FINE, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, dkim_module_ctx->symbol_allow, 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_FINE, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, "DKIM_TRACE", 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_NOSTAT, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_NOSTAT, cb_id); rspamd_config_add_symbol (cfg, "DKIM_TRACE", @@ -585,12 +585,12 @@ dkim_module_config (struct rspamd_config *cfg) cfg->cfg_pool, dkim_module_ctx->sign_condition_ref); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, "DKIM_SIGN", 0, dkim_sign_callback, NULL, - SYMBOL_TYPE_CALLBACK|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_CALLBACK | SYMBOL_TYPE_FINE, -1); msg_info_config ("init condition script for DKIM signing"); @@ -598,7 +598,7 @@ dkim_module_config (struct rspamd_config *cfg) * Allow dkim signing to be executed only after dkim check */ if (cb_id > 0) { - rspamd_symbols_cache_add_delayed_dependency (cfg->cache, + rspamd_symcache_add_delayed_dependency (cfg->cache, "DKIM_SIGN", dkim_module_ctx->symbol_reject); } @@ -1119,7 +1119,7 @@ dkim_symbol_callback (struct rspamd_task *task, || (!dkim_module_ctx->check_local && rspamd_inet_address_is_local (task->from_addr, TRUE))) { msg_info_task ("skip DKIM checks for local networks and authorized users"); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1127,7 +1127,7 @@ dkim_symbol_callback (struct rspamd_task *task, if (rspamd_match_radix_map_addr (dkim_module_ctx->whitelist_ip, task->from_addr) != NULL) { msg_info_task ("skip DKIM checks for whitelisted address"); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1300,7 +1300,7 @@ dkim_sign_callback (struct rspamd_task *task, msg_err_task ("invalid return value from sign condition: %e", err); g_error_free (err); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1323,7 +1323,7 @@ dkim_sign_callback (struct rspamd_task *task, lua_settop (L, 0); luaL_error (L, "unknown key type: %s", key_type); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1338,7 +1338,7 @@ dkim_sign_callback (struct rspamd_task *task, if (arc_idx == 0) { lua_settop (L, 0); luaL_error (L, "no arc idx specified"); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1348,14 +1348,14 @@ dkim_sign_callback (struct rspamd_task *task, if (arc_cv == NULL) { lua_settop (L, 0); luaL_error (L, "no arc cv specified"); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } if (arc_idx == 0) { lua_settop (L, 0); luaL_error (L, "no arc idx specified"); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1364,7 +1364,7 @@ dkim_sign_callback (struct rspamd_task *task, lua_settop (L, 0); luaL_error (L, "unknown sign type: %s", sign_type_str); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1397,7 +1397,7 @@ dkim_sign_callback (struct rspamd_task *task, msg_err_task ("cannot load dkim key %s: %e", lru_key, err); g_error_free (err); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1422,7 +1422,7 @@ dkim_sign_callback (struct rspamd_task *task, msg_err_task ("cannot load dkim key %s: %e", lru_key, err); g_error_free (err); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1442,7 +1442,7 @@ dkim_sign_callback (struct rspamd_task *task, msg_err_task ("cannot create sign context: %e", err); g_error_free (err); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1470,13 +1470,13 @@ dkim_sign_callback (struct rspamd_task *task, if (!sign) { msg_debug_task ("skip signing as dkim condition callback returned" " false"); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } } - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); } struct rspamd_dkim_lua_verify_cbdata { diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index e61fa7ce3..1f16c5a48 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -248,10 +248,10 @@ parse_flags (struct fuzzy_rule *rule, /* Add flag to hash table */ g_hash_table_insert (rule->mappings, GINT_TO_POINTER (map->fuzzy_flag), map); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, map->symbol, 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_FINE, cb_id); } else { @@ -686,10 +686,10 @@ fuzzy_parse_rule (struct rspamd_config *cfg, const ucl_object_t *obj, g_ptr_array_add (fuzzy_module_ctx->fuzzy_rules, rule); if (rule->symbol != fuzzy_module_ctx->default_symbol) { - rspamd_symbols_cache_add_symbol (cfg->cache, rule->symbol, + rspamd_symcache_add_symbol (cfg->cache, rule->symbol, 0, NULL, NULL, - SYMBOL_TYPE_VIRTUAL|SYMBOL_TYPE_FINE, + SYMBOL_TYPE_VIRTUAL | SYMBOL_TYPE_FINE, cb_id); } @@ -1090,10 +1090,10 @@ fuzzy_check_module_config (struct rspamd_config *cfg) if ((value = rspamd_config_get_module_opt (cfg, "fuzzy_check", "rule")) != NULL) { - cb_id = rspamd_symbols_cache_add_symbol (cfg->cache, - "FUZZY_CALLBACK", 0, fuzzy_symbol_callback, NULL, - SYMBOL_TYPE_CALLBACK|SYMBOL_TYPE_FINE, - -1); + cb_id = rspamd_symcache_add_symbol (cfg->cache, + "FUZZY_CALLBACK", 0, fuzzy_symbol_callback, NULL, + SYMBOL_TYPE_CALLBACK | SYMBOL_TYPE_FINE, + -1); /* * Here we can have 2 possibilities: @@ -2885,7 +2885,7 @@ register_fuzzy_client_call (struct rspamd_task *task, event_add (&session->timev, &session->tv); rspamd_session_add_event (task->s, fuzzy_io_fin, session, M); - session->item = rspamd_symbols_cache_get_cur_item (task); + session->item = rspamd_symcache_get_cur_item (task); if (session->item) { rspamd_symcache_item_async_inc (task, session->item, M); @@ -2907,7 +2907,7 @@ fuzzy_symbol_callback (struct rspamd_task *task, struct fuzzy_ctx *fuzzy_module_ctx = fuzzy_get_context (task->cfg); if (!fuzzy_module_ctx->enabled) { - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -2919,7 +2919,7 @@ fuzzy_symbol_callback (struct rspamd_task *task, msg_info_task ("<%s>, address %s is whitelisted, skip fuzzy check", task->message_id, rspamd_inet_address_to_string (task->from_addr)); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 0f7bb4ff8..b40c9c468 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -172,7 +172,7 @@ regexp_module_config (struct rspamd_config *cfg) res = FALSE; } else { - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, cur_item->symbol, 0, process_regexp_item, @@ -189,12 +189,12 @@ regexp_module_config (struct rspamd_config *cfg) cur_item->symbol = ucl_object_key (value); cur_item->lua_function = ucl_object_toclosure (value); - rspamd_symbols_cache_add_symbol (cfg->cache, - cur_item->symbol, - 0, - process_regexp_item, - cur_item, - SYMBOL_TYPE_NORMAL, -1); + rspamd_symcache_add_symbol (cfg->cache, + cur_item->symbol, + 0, + process_regexp_item, + cur_item, + SYMBOL_TYPE_NORMAL, -1); nlua ++; } else if (value->type == UCL_OBJECT) { @@ -245,7 +245,7 @@ regexp_module_config (struct rspamd_config *cfg) } if (cur_item && (is_lua || valid_expression)) { - id = rspamd_symbols_cache_add_symbol (cfg->cache, + id = rspamd_symcache_add_symbol (cfg->cache, cur_item->symbol, 0, process_regexp_item, @@ -259,7 +259,7 @@ regexp_module_config (struct rspamd_config *cfg) g_assert (cur_item->symbol != NULL); conddata = ucl_object_toclosure (elt); - rspamd_symbols_cache_add_condition_delayed (cfg->cache, + rspamd_symcache_add_condition_delayed (cfg->cache, cur_item->symbol, conddata->L, conddata->idx); } @@ -456,5 +456,5 @@ process_regexp_item (struct rspamd_task *task, rspamd_task_insert_result (task, item->symbol, res, NULL); } - rspamd_symbols_cache_finalize_item (task, symcache_item); + rspamd_symcache_finalize_item (task, symcache_item); } diff --git a/src/plugins/spf.c b/src/plugins/spf.c index 271fd1892..eedaf6c2e 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -299,38 +299,38 @@ spf_module_config (struct rspamd_config *cfg) &spf_module_ctx->whitelist_ip, NULL); } - cb_id = rspamd_symbols_cache_add_symbol (cfg->cache, - spf_module_ctx->symbol_fail, - 0, - spf_symbol_callback, - NULL, - SYMBOL_TYPE_NORMAL|SYMBOL_TYPE_FINE|SYMBOL_TYPE_EMPTY, -1); - rspamd_symbols_cache_add_symbol (cfg->cache, + cb_id = rspamd_symcache_add_symbol (cfg->cache, + spf_module_ctx->symbol_fail, + 0, + spf_symbol_callback, + NULL, + SYMBOL_TYPE_NORMAL | SYMBOL_TYPE_FINE | SYMBOL_TYPE_EMPTY, -1); + rspamd_symcache_add_symbol (cfg->cache, spf_module_ctx->symbol_softfail, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, spf_module_ctx->symbol_permfail, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, spf_module_ctx->symbol_na, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, spf_module_ctx->symbol_neutral, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, spf_module_ctx->symbol_allow, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, cb_id); - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, spf_module_ctx->symbol_dnsfail, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, @@ -596,7 +596,7 @@ spf_symbol_callback (struct rspamd_task *task, if (rspamd_match_radix_map_addr (spf_module_ctx->whitelist_ip, task->from_addr) != NULL) { - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -604,7 +604,7 @@ spf_symbol_callback (struct rspamd_task *task, || (!spf_module_ctx->check_local && rspamd_inet_address_is_local (task->from_addr, TRUE))) { msg_info_task ("skip SPF checks for local networks and authorized users"); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 4c3fbefa1..61cda5665 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -611,7 +611,7 @@ register_bit_symbols (struct rspamd_config *cfg, struct suffix_item *suffix, while (g_hash_table_iter_next (&it, &k, &v)) { bit = v; - rspamd_symbols_cache_add_symbol (cfg->cache, bit->symbol, + rspamd_symcache_add_symbol (cfg->cache, bit->symbol, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, parent_id); msg_debug_config ("bit: %d", bit->bit); @@ -620,13 +620,13 @@ register_bit_symbols (struct rspamd_config *cfg, struct suffix_item *suffix, else if (suffix->bits != NULL) { for (i = 0; i < suffix->bits->len; i++) { bit = &g_array_index (suffix->bits, struct surbl_bit_item, i); - rspamd_symbols_cache_add_symbol (cfg->cache, bit->symbol, + rspamd_symcache_add_symbol (cfg->cache, bit->symbol, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, parent_id); } } else { - rspamd_symbols_cache_add_symbol (cfg->cache, suffix->symbol, + rspamd_symcache_add_symbol (cfg->cache, suffix->symbol, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, parent_id); } @@ -762,9 +762,9 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg) continue; } - cb_id = rspamd_symbols_cache_add_symbol (cfg->cache, "SURBL_CALLBACK", + cb_id = rspamd_symcache_add_symbol (cfg->cache, "SURBL_CALLBACK", 0, surbl_test_url, new_suffix, SYMBOL_TYPE_CALLBACK, -1); - rspamd_symbols_cache_add_dependency (cfg->cache, cb_id, + rspamd_symcache_add_dependency (cfg->cache, cb_id, SURBL_REDIRECTOR_CALLBACK); nrules++; new_suffix->callback_id = cb_id; @@ -895,7 +895,7 @@ surbl_module_parse_rule (const ucl_object_t* value, struct rspamd_config* cfg) if (new_suffix->symbol) { /* Register just a symbol itself */ - rspamd_symbols_cache_add_symbol (cfg->cache, + rspamd_symcache_add_symbol (cfg->cache, new_suffix->symbol, 0, NULL, NULL, SYMBOL_TYPE_VIRTUAL, cb_id); nrules++; @@ -949,7 +949,7 @@ surbl_module_config (struct rspamd_config *cfg) lua_pop (L, 1); /* Remove global function */ - (void)rspamd_symbols_cache_add_symbol (cfg->cache, SURBL_REDIRECTOR_CALLBACK, + (void) rspamd_symcache_add_symbol (cfg->cache, SURBL_REDIRECTOR_CALLBACK, 0, surbl_test_redirector, NULL, SYMBOL_TYPE_CALLBACK, -1); @@ -973,9 +973,9 @@ surbl_module_config (struct rspamd_config *cfg) rspamd_config_get_module_opt (cfg, "surbl", "redirector_symbol")) != NULL) { surbl_module_ctx->redirector_symbol = ucl_obj_tostring (value); - rspamd_symbols_cache_add_symbol (cfg->cache, - surbl_module_ctx->redirector_symbol, - 0, NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1); + rspamd_symcache_add_symbol (cfg->cache, + surbl_module_ctx->redirector_symbol, + 0, NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1); } else { surbl_module_ctx->redirector_symbol = NULL; @@ -1090,7 +1090,7 @@ surbl_module_config (struct rspamd_config *cfg) } if (cur_suffix->options & SURBL_OPTION_CHECKDKIM) { - rspamd_symbols_cache_add_dependency (cfg->cache, + rspamd_symcache_add_dependency (cfg->cache, cur_suffix->callback_id, "DKIM_TRACE"); } @@ -1715,7 +1715,7 @@ register_redirector_call (struct rspamd_url *url, struct rspamd_task *task, rspamd_session_add_event (task->s, free_redirector_session, param, M); - param->item = rspamd_symbols_cache_get_cur_item (task); + param->item = rspamd_symcache_get_cur_item (task); if (param->item) { rspamd_symcache_item_async_inc (param->task, param->item, M); @@ -1838,7 +1838,7 @@ surbl_tree_redirector_callback (gpointer key, gpointer value, void *data) *purl = url; rspamd_lua_setclass (L, "rspamd{url}", -1); lua_pushlightuserdata (L, nparam); - rspamd_symbols_cache_set_cur_item (task, param->item); + rspamd_symcache_set_cur_item (task, param->item); if (lua_pcall (L, 3, 0, 0) != 0) { msg_err_task ("cannot call for redirector script: %s", @@ -1904,7 +1904,7 @@ surbl_test_url (struct rspamd_task *task, if (!rspamd_monitored_alive (suffix->m)) { msg_info_surbl ("disable surbl %s as it is reported to be offline", suffix->suffix); - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } @@ -1984,7 +1984,7 @@ surbl_test_redirector (struct rspamd_task *task, struct surbl_ctx *surbl_module_ctx = surbl_get_context (task->cfg); if (!surbl_module_ctx->use_redirector || !surbl_module_ctx->redirector_tlds) { - rspamd_symbols_cache_finalize_item (task, item); + rspamd_symcache_finalize_item (task, item); return; } diff --git a/src/rspamadm/configdump.c b/src/rspamadm/configdump.c index cf08ceac0..a255994a5 100644 --- a/src/rspamadm/configdump.c +++ b/src/rspamadm/configdump.c @@ -279,7 +279,7 @@ rspamadm_configdump (gint argc, gchar **argv, const struct rspamadm_command *cmd pworker++; } - cfg->cache = rspamd_symbols_cache_new (cfg); + cfg->cache = rspamd_symcache_new (cfg); cfg->compiled_modules = modules; cfg->compiled_workers = workers; cfg->cfg_name = config; diff --git a/src/rspamadm/configtest.c b/src/rspamadm/configtest.c index 72a8f4945..0fe0a23ad 100644 --- a/src/rspamadm/configtest.c +++ b/src/rspamadm/configtest.c @@ -136,7 +136,7 @@ rspamadm_configtest (gint argc, gchar **argv, const struct rspamadm_command *cmd (void) g_quark_from_static_string ((*pworker)->name); pworker++; } - cfg->cache = rspamd_symbols_cache_new (cfg); + cfg->cache = rspamd_symcache_new (cfg); cfg->compiled_modules = modules; cfg->compiled_workers = workers; cfg->cfg_name = config; @@ -156,7 +156,7 @@ rspamadm_configtest (gint argc, gchar **argv, const struct rspamadm_command *cmd ret = rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE); } - if (!rspamd_symbols_cache_validate (rspamd_main->cfg->cache, + if (!rspamd_symcache_validate (rspamd_main->cfg->cache, rspamd_main->cfg, FALSE)) { ret = FALSE; diff --git a/src/rspamd.c b/src/rspamd.c index 09523b90c..88b44d773 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -280,7 +280,7 @@ reread_config (struct rspamd_main *rspamd_main) struct rspamd_config *tmp_cfg, *old_cfg; gchar *cfg_file; - rspamd_symbols_cache_save (rspamd_main->cfg->cache); + rspamd_symcache_save (rspamd_main->cfg->cache); tmp_cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT); tmp_cfg->libs_ctx = rspamd_main->cfg->libs_ctx; REF_RETAIN (tmp_cfg->libs_ctx); @@ -1323,7 +1323,7 @@ main (gint argc, gchar **argv, gchar **env) res = TRUE; - if (!rspamd_symbols_cache_validate (rspamd_main->cfg->cache, + if (!rspamd_symcache_validate (rspamd_main->cfg->cache, rspamd_main->cfg, FALSE)) { res = FALSE; diff --git a/src/worker.c b/src/worker.c index 2ce029779..26ce63a94 100644 --- a/src/worker.c +++ b/src/worker.c @@ -670,7 +670,7 @@ start_worker (struct rspamd_worker *worker) ctx->cfg = worker->srv->cfg; ctx->ev_base = rspamd_prepare_worker (worker, "normal", accept_socket); msec_to_tv (ctx->timeout, &ctx->io_tv); - rspamd_symbols_cache_start_refresh (worker->srv->cfg->cache, ctx->ev_base, + rspamd_symcache_start_refresh (worker->srv->cfg->cache, ctx->ev_base, worker); ctx->resolver = dns_resolver_init (worker->srv->logger, |