aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-06 20:19:59 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-07-06 20:19:59 +0100
commite23e56dee179b2a0e2a0862e16203eea459c90e2 (patch)
tree3eaa91cae510a8543d08337697146648c7ee8aa1 /src
parentecdc74fd8553ccd9b9027125130a4dd83a3fc64f (diff)
downloadrspamd-e23e56dee179b2a0e2a0862e16203eea459c90e2.tar.gz
rspamd-e23e56dee179b2a0e2a0862e16203eea459c90e2.zip
Add support for extra variables in a config.
Diffstat (limited to 'src')
-rw-r--r--src/libserver/cfg_file.h5
-rw-r--r--src/libserver/cfg_rcl.c4
-rw-r--r--src/libserver/cfg_utils.c13
-rw-r--r--src/lua/lua_util.c2
4 files changed, 18 insertions, 6 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index c6087b157..da7c3088b 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -363,7 +363,8 @@ struct rspamd_statfile_config * rspamd_config_new_statfile (
*/
gboolean rspamd_config_read (struct rspamd_config *cfg,
const gchar *filename, const gchar *convert_to,
- rspamd_rcl_section_fin_t logger_fin, gpointer logger_ud);
+ rspamd_rcl_section_fin_t logger_fin, gpointer logger_ud,
+ GHashTable *vars);
/*
* Register symbols of classifiers inside metrics
@@ -385,7 +386,7 @@ struct rspamd_classifier_config * rspamd_config_find_classifier (
void rspamd_ucl_add_conf_macros (struct ucl_parser *parser,
struct rspamd_config *cfg);
-void rspamd_ucl_add_conf_variables (struct ucl_parser *parser);
+void rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars);
/**
* Initialize rspamd filtering system (lua and C filters)
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index fc8ada749..26b47442a 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -2254,7 +2254,7 @@ rspamd_rcl_register_worker_parser (struct rspamd_config *cfg, gint type,
gboolean
rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
const gchar *convert_to, rspamd_rcl_section_fin_t logger_fin,
- gpointer logger_ud)
+ gpointer logger_ud, GHashTable *vars)
{
struct stat st;
gint fd;
@@ -2282,7 +2282,7 @@ rspamd_config_read (struct rspamd_config *cfg, const gchar *filename,
close (fd);
parser = ucl_parser_new (0);
- rspamd_ucl_add_conf_variables (parser);
+ rspamd_ucl_add_conf_variables (parser, vars);
rspamd_ucl_add_conf_macros (parser, cfg);
if (!ucl_parser_add_chunk (parser, data, st.st_size)) {
msg_err ("ucl parser error: %s", ucl_parser_get_error (parser));
diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c
index 24edc45b5..1ba6b2555 100644
--- a/src/libserver/cfg_utils.c
+++ b/src/libserver/cfg_utils.c
@@ -644,8 +644,11 @@ rspamd_include_map_handler (const guchar *data, gsize len,
#define RSPAMD_VERSION_MACRO "VERSION"
void
-rspamd_ucl_add_conf_variables (struct ucl_parser *parser)
+rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
{
+ GHashTableIter it;
+ gpointer k, v;
+
ucl_parser_register_variable (parser,
RSPAMD_CONFDIR_MACRO,
RSPAMD_CONFDIR);
@@ -663,6 +666,14 @@ rspamd_ucl_add_conf_variables (struct ucl_parser *parser)
ucl_parser_register_variable (parser, RSPAMD_PREFIX_MACRO,
RSPAMD_PREFIX);
ucl_parser_register_variable (parser, RSPAMD_VERSION_MACRO, RVERSION);
+
+ if (vars != NULL) {
+ g_hash_table_iter_init (&it, vars);
+
+ while (g_hash_table_iter_next (&it, &k, &v)) {
+ ucl_parser_register_variable (parser, k, v);
+ }
+ }
}
void
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 3e6b34c81..9a670da04 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -106,7 +106,7 @@ lua_util_load_rspamd_config (lua_State *L)
rspamd_init_cfg (cfg, FALSE);
cfg->cache = rspamd_symbols_cache_new ();
- if (rspamd_config_read (cfg, cfg_name, NULL, NULL, NULL)) {
+ if (rspamd_config_read (cfg, cfg_name, NULL, NULL, NULL, NULL)) {
msg_err ("cannot load config from %s", cfg_name);
lua_pushnil (L);
}