diff options
-rw-r--r-- | src/libstat/backends/backends.h | 1 | ||||
-rw-r--r-- | src/libstat/stat_config.c | 53 | ||||
-rw-r--r-- | src/libstat/stat_process.c | 6 |
3 files changed, 45 insertions, 15 deletions
diff --git a/src/libstat/backends/backends.h b/src/libstat/backends/backends.h index 7b61093bb..434377850 100644 --- a/src/libstat/backends/backends.h +++ b/src/libstat/backends/backends.h @@ -36,6 +36,7 @@ struct rspamd_task; struct rspamd_stat_backend { const char *name; + bool read_only; gpointer (*init) (struct rspamd_stat_ctx *ctx, struct rspamd_config *cfg, struct rspamd_statfile *st); diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 0c9ae2ed0..5f48cf1f9 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -55,9 +55,10 @@ static struct rspamd_stat_tokenizer stat_tokenizers[] = { }; #define RSPAMD_STAT_BACKEND_ELT(nam, eltn) { \ - .name = #nam, \ - .init = rspamd_##eltn##_init, \ - .runtime = rspamd_##eltn##_runtime, \ + .name = #nam, \ + .read_only = false, \ + .init = rspamd_##eltn##_init, \ + .runtime = rspamd_##eltn##_runtime, \ .process_tokens = rspamd_##eltn##_process_tokens, \ .finalize_process = rspamd_##eltn##_finalize_process, \ .learn_tokens = rspamd_##eltn##_learn_tokens, \ @@ -69,10 +70,27 @@ static struct rspamd_stat_tokenizer stat_tokenizers[] = { .load_tokenizer_config = rspamd_##eltn##_load_tokenizer_config, \ .close = rspamd_##eltn##_close \ } +#define RSPAMD_STAT_BACKEND_ELT_READONLY(nam, eltn) { \ + .name = #nam, \ + .read_only = true, \ + .init = rspamd_##eltn##_init, \ + .runtime = rspamd_##eltn##_runtime, \ + .process_tokens = rspamd_##eltn##_process_tokens, \ + .finalize_process = rspamd_##eltn##_finalize_process, \ + .learn_tokens = NULL, \ + .finalize_learn = NULL, \ + .total_learns = rspamd_##eltn##_total_learns, \ + .inc_learns = NULL, \ + .dec_learns = NULL, \ + .get_stat = rspamd_##eltn##_get_stat, \ + .load_tokenizer_config = rspamd_##eltn##_load_tokenizer_config, \ + .close = rspamd_##eltn##_close \ + } static struct rspamd_stat_backend stat_backends[] = { RSPAMD_STAT_BACKEND_ELT(mmap, mmaped_file), RSPAMD_STAT_BACKEND_ELT(sqlite3, sqlite3), + RSPAMD_STAT_BACKEND_ELT_READONLY(cdb, cdb), #ifdef WITH_HIREDIS RSPAMD_STAT_BACKEND_ELT(redis, redis) #endif @@ -275,24 +293,29 @@ rspamd_stat_init (struct rspamd_config *cfg, struct ev_loop *ev_base) /* Init classifier cache */ cache_name = NULL; - if (clf->opts) { - cache_obj = ucl_object_lookup (clf->opts, "cache"); - cache_name_obj = NULL; + if (!bk->read_only) { + if (clf->opts) { + cache_obj = ucl_object_lookup(clf->opts, "cache"); + cache_name_obj = NULL; - if (cache_obj && ucl_object_type (cache_obj) == UCL_NULL) { - skip_cache = TRUE; - } - else { - if (cache_obj) { - cache_name_obj = ucl_object_lookup_any (cache_obj, - "name", "type", NULL); + if (cache_obj && ucl_object_type(cache_obj) == UCL_NULL) { + skip_cache = TRUE; } + else { + if (cache_obj) { + cache_name_obj = ucl_object_lookup_any(cache_obj, + "name", "type", NULL); + } - if (cache_name_obj) { - cache_name = ucl_object_tostring (cache_name_obj); + if (cache_name_obj) { + cache_name = ucl_object_tostring(cache_name_obj); + } } } } + else { + skip_cache = true; + } if (cache_name == NULL && !skip_cache) { /* We assume that learn cache is the same as backend */ diff --git a/src/libstat/stat_process.c b/src/libstat/stat_process.c index 2ebc8f599..35c9d1215 100644 --- a/src/libstat/stat_process.c +++ b/src/libstat/stat_process.c @@ -314,6 +314,12 @@ rspamd_stat_preprocess (struct rspamd_stat_ctx *st_ctx, continue; } + if (st->backend->read_only) { + /* Read only backend, skip it */ + g_ptr_array_index (task->stat_runtimes, i) = NULL; + continue; + } + if (!rspamd_symcache_is_symbol_enabled (task, task->cfg->cache, st->stcf->symbol)) { g_ptr_array_index (task->stat_runtimes, i) = NULL; |