diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-18 14:48:01 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-11-18 14:48:01 +0000 |
commit | b33f3fa4cfa42f1b92192ff18eb893b8bd93a1e9 (patch) | |
tree | b147e77e51cfa86b6468a4d721f5d94cd6d820ed /src/libserver/cfg_utils.c | |
parent | 3cfbb45a4a84836e118992099cea233920b6f92e (diff) | |
download | rspamd-b33f3fa4cfa42f1b92192ff18eb893b8bd93a1e9.tar.gz rspamd-b33f3fa4cfa42f1b92192ff18eb893b8bd93a1e9.zip |
Start refcounting rework for rspamd_config
Diffstat (limited to 'src/libserver/cfg_utils.c')
-rw-r--r-- | src/libserver/cfg_utils.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index b85534dd7..5d0eb06ae 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -144,9 +144,13 @@ rspamd_parse_bind_line (struct rspamd_config *cfg, return ret; } -void -rspamd_config_defaults (struct rspamd_config *cfg) +struct rspamd_config * +rspamd_config_defaults (void) { + struct rspamd_config *cfg; + + cfg = g_slice_alloc0 (sizeof (*cfg)); + cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "cfg"); cfg->dns_timeout = 1000; cfg->dns_retransmits = 5; /* After 20 errors do throttling for 10 seconds */ @@ -190,6 +194,11 @@ rspamd_config_defaults (struct rspamd_config *cfg) cfg->words_decay = DEFAULT_WORDS_DECAY; cfg->min_word_len = DEFAULT_MIN_WORD; cfg->max_word_len = DEFAULT_MAX_WORD; + + cfg->lua_state = rspamd_lua_init (cfg); + cfg->cache = rspamd_symbols_cache_new (cfg); + + REF_INIT_RETAIN (cfg, rspamd_config_free); } void @@ -215,6 +224,9 @@ rspamd_config_free (struct rspamd_config *cfg) g_list_free (cfg->classifiers); g_list_free (cfg->metrics_list); + lua_close (cfg->lua_state); + rspamd_symbols_cache_destroy (cfg->cache); + REF_RELEASE (cfg->libs_ctx); rspamd_mempool_delete (cfg->cfg_pool); } @@ -578,8 +590,8 @@ rspamd_config_parse_log_format (struct rspamd_config *cfg) /* * Perform post load actions */ -void -rspamd_config_post_load (struct rspamd_config *cfg) +gboolean +rspamd_config_post_load (struct rspamd_config *cfg, gboolean validate_cache) { #ifdef HAVE_CLOCK_GETTIME struct timespec ts; @@ -649,6 +661,16 @@ rspamd_config_post_load (struct rspamd_config *cfg) if (!rspamd_config_parse_log_format (cfg)) { msg_err_config ("cannot parse log format, task logging will not be available"); } + + /* Init config cache */ + rspamd_symbols_cache_init (cfg->cache); + + /* Validate cache */ + if (validate_cache) { + return rspamd_symbols_cache_validate (cfg->cache, cfg, FALSE); + } + + return TRUE; } #if 0 @@ -1180,19 +1202,6 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) return rspamd_init_lua_filters (cfg); } -void -rspamd_init_cfg (struct rspamd_config *cfg, gboolean init_lua) -{ - cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "cfg"); - rspamd_config_defaults (cfg); - - if (init_lua) { - cfg->lua_state = rspamd_lua_init (cfg); - rspamd_mempool_add_destructor (cfg->cfg_pool, - (rspamd_mempool_destruct_t)lua_close, cfg->lua_state); - } -} - gboolean rspamd_config_add_metric_symbol (struct rspamd_config *cfg, const gchar *metric_name, const gchar *symbol, |