aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2013-11-24 21:53:43 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2013-11-24 21:53:43 +0000
commit489dff2b77175db8537b32dab8e637cdea2a02af (patch)
treea63b3d9b5252dd96eb9f42ef207d8a0cce8eca92 /src
parentc3882406f1bdae1603aae312af22120cc5c261c0 (diff)
downloadrspamd-489dff2b77175db8537b32dab8e637cdea2a02af.tar.gz
rspamd-489dff2b77175db8537b32dab8e637cdea2a02af.zip
Use ucl variables.
Diffstat (limited to 'src')
-rw-r--r--src/cfg_rcl.c22
-rw-r--r--src/cfg_utils.c33
-rw-r--r--src/map.c2
-rw-r--r--src/util.c175
-rw-r--r--src/util.h1
5 files changed, 40 insertions, 193 deletions
diff --git a/src/cfg_rcl.c b/src/cfg_rcl.c
index b78a75fd6..b27dedbdd 100644
--- a/src/cfg_rcl.c
+++ b/src/cfg_rcl.c
@@ -51,7 +51,7 @@ rspamd_rcl_logging_handler (struct config_file *cfg, ucl_object_t *obj,
return FALSE;
}
cfg->log_type = RSPAMD_LOG_FILE;
- cfg->log_file = rspamd_expand_path (cfg->cfg_pool, ucl_object_tostring (val));
+ cfg->log_file = memory_pool_strdup (cfg->cfg_pool, ucl_object_tostring (val));
}
else if (g_ascii_strcasecmp (log_type, "syslog") == 0) {
/* Need to get facility */
@@ -558,7 +558,7 @@ static gboolean
rspamd_rcl_lua_handler (struct config_file *cfg, ucl_object_t *obj,
gpointer ud, struct rspamd_rcl_section *section, GError **err)
{
- const gchar *lua_src = rspamd_expand_path (cfg->cfg_pool, ucl_object_tostring (obj));
+ const gchar *lua_src = memory_pool_strdup (cfg->cfg_pool, ucl_object_tostring (obj));
gchar *cur_dir, *lua_dir, *lua_file, *tmp1, *tmp2;
lua_State *L = cfg->lua_state;
@@ -682,14 +682,14 @@ rspamd_rcl_modules_handler (struct config_file *cfg, ucl_object_t *obj,
LL_FOREACH (val, cur) {
if (ucl_object_tostring_safe (cur, &data)) {
- if (!rspamd_rcl_add_module_path (cfg, rspamd_expand_path (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_module_path (cfg, memory_pool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
}
}
else if (ucl_object_tostring_safe (obj, &data)) {
- if (!rspamd_rcl_add_module_path (cfg, rspamd_expand_path (cfg->cfg_pool, data), err)) {
+ if (!rspamd_rcl_add_module_path (cfg, memory_pool_strdup (cfg->cfg_pool, data), err)) {
return FALSE;
}
}
@@ -1241,12 +1241,7 @@ rspamd_rcl_parse_struct_string (struct config_file *cfg, ucl_object_t *obj,
target = (gchar **)(((gchar *)pd->user_struct) + pd->offset);
switch (obj->type) {
case UCL_STRING:
- if (pd->flags & RSPAMD_CL_FLAG_STRING_PATH) {
- *target = rspamd_expand_path (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
- else {
- *target = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
+ *target = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
break;
case UCL_INT:
*target = memory_pool_alloc (cfg->cfg_pool, num_str_len);
@@ -1412,12 +1407,7 @@ rspamd_rcl_parse_struct_string_list (struct config_file *cfg, ucl_object_t *obj,
for (cur = obj; cur != NULL; cur = cur->next) {
switch (cur->type) {
case UCL_STRING:
- if (pd->flags & RSPAMD_CL_FLAG_STRING_PATH) {
- val = rspamd_expand_path (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
- else {
- val = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
- }
+ val = memory_pool_strdup (cfg->cfg_pool, ucl_copy_value_trash (obj));
break;
case UCL_INT:
val = memory_pool_alloc (cfg->cfg_pool, num_str_len);
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index 1faaf08a7..765ff7f34 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -743,6 +743,38 @@ get_filename_extension (const char *filename)
return NULL;
}
+
+/*
+ * Variables:
+ * $CONFDIR - configuration directory
+ * $RUNDIR - local states directory
+ * $DBDIR - databases dir
+ * $LOGDIR - logs dir
+ * $PLUGINSDIR - pluggins dir
+ * $PREFIX - installation prefix
+ * $VERSION - rspamd version
+ */
+
+#define RSPAMD_CONFDIR_MACRO "CONFDIR"
+#define RSPAMD_RUNDIR_MACRO "RUNDIR"
+#define RSPAMD_DBDIR_MACRO "DBDIR"
+#define RSPAMD_LOGDIR_MACRO "LOGDIR"
+#define RSPAMD_PLUGINSDIR_MACRO "PLUGINSDIR"
+#define RSPAMD_PREFIX_MACRO "PREFIX"
+#define RSPAMD_VERSION_MACRO "VERSION"
+
+static void
+rspamd_ucl_add_conf_variables (struct ucl_parser *parser)
+{
+ ucl_parser_register_variable (parser, RSPAMD_CONFDIR_MACRO, RSPAMD_CONFDIR);
+ ucl_parser_register_variable (parser, RSPAMD_RUNDIR_MACRO, RSPAMD_RUNDIR);
+ ucl_parser_register_variable (parser, RSPAMD_DBDIR_MACRO, RSPAMD_DBDIR);
+ ucl_parser_register_variable (parser, RSPAMD_LOGDIR_MACRO, RSPAMD_LOGDIR);
+ ucl_parser_register_variable (parser, RSPAMD_PLUGINSDIR_MACRO, RSPAMD_PLUGINSDIR);
+ ucl_parser_register_variable (parser, RSPAMD_PREFIX_MACRO, RSPAMD_PREFIX);
+ ucl_parser_register_variable (parser, RSPAMD_VERSION_MACRO, RVERSION);
+}
+
gboolean
read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar *convert_to)
{
@@ -796,6 +828,7 @@ read_rspamd_config (struct config_file *cfg, const gchar *filename, const gchar
}
else {
parser = ucl_parser_new (0);
+ rspamd_ucl_add_conf_variables (parser);
if (!ucl_parser_add_chunk (parser, data, st.st_size)) {
msg_err ("ucl parser error: %s", ucl_parser_get_error (parser));
munmap (data, st.st_size);
diff --git a/src/map.c b/src/map.c
index 25541a7e6..2af883a7a 100644
--- a/src/map.c
+++ b/src/map.c
@@ -1048,7 +1048,7 @@ add_map (struct config_file *cfg, const gchar *map_line, const gchar *descriptio
new_map->locked = memory_pool_alloc0_shared (cfg->cfg_pool, sizeof (gint));
if (proto == MAP_PROTO_FILE) {
- new_map->uri = rspamd_expand_path (cfg->cfg_pool, def);
+ new_map->uri = memory_pool_strdup (cfg->cfg_pool, def);
def = new_map->uri;
}
else {
diff --git a/src/util.c b/src/util.c
index 46e99c309..bc2206579 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2386,181 +2386,6 @@ restart:
return p - buf;
#endif
}
-
-/*
- * Variables:
- * $CONFDIR - configuration directory
- * $RUNDIR - local states directory
- * $DBDIR - databases dir
- * $LOGDIR - logs dir
- * $PLUGINSDIR - pluggins dir
- * $PREFIX - installation prefix
- * $VERSION - rspamd version
- */
-
-#define RSPAMD_CONFDIR_MACRO "CONFDIR"
-#define RSPAMD_RUNDIR_MACRO "RUNDIR"
-#define RSPAMD_DBDIR_MACRO "DBDIR"
-#define RSPAMD_LOGDIR_MACRO "LOGDIR"
-#define RSPAMD_PLUGINSDIR_MACRO "PLUGINSDIR"
-#define RSPAMD_PREFIX_MACRO "PREFIX"
-#define RSPAMD_VERSION_MACRO "VERSION"
-
-static const gchar *
-rspamd_check_path_variable (const gchar *in, gsize *len)
-{
- switch (*in) {
- case 'C':
- if (strncmp (in, RSPAMD_CONFDIR_MACRO, sizeof (RSPAMD_CONFDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_CONFDIR) - 1;
- in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
- }
- break;
- case 'R':
- if (strncmp (in, RSPAMD_RUNDIR_MACRO, sizeof (RSPAMD_RUNDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_RUNDIR) - 1;
- in += sizeof (RSPAMD_RUNDIR_MACRO) - 1;
- }
- break;
- case 'D':
- if (strncmp (in, RSPAMD_DBDIR_MACRO, sizeof (RSPAMD_DBDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_DBDIR) - 1;
- in += sizeof (RSPAMD_DBDIR_MACRO) - 1;
- }
- break;
- case 'L':
- if (strncmp (in, RSPAMD_LOGDIR_MACRO, sizeof (RSPAMD_LOGDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_LOGDIR) - 1;
- in += sizeof (RSPAMD_LOGDIR_MACRO) - 1;
- }
- break;
- case 'P':
- if (strncmp (in, RSPAMD_PREFIX_MACRO, sizeof (RSPAMD_PREFIX_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_PREFIX) - 1;
- in += sizeof (RSPAMD_PREFIX_MACRO) - 1;
- }
- else if (strncmp (in, RSPAMD_PLUGINSDIR_MACRO, sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1) == 0) {
- *len += sizeof (RSPAMD_PLUGINSDIR) - 1;
- in += sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1;
- }
- break;
- case 'V':
- if (strncmp (in, RSPAMD_VERSION_MACRO, sizeof (RSPAMD_VERSION_MACRO) - 1) == 0) {
- *len += sizeof (RVERSION) - 1;
- in += sizeof (RSPAMD_VERSION_MACRO) - 1;
- }
- break;
- }
-
- return in;
-}
-
-static const gchar *
-rspamd_expand_path_variable (const gchar *in, gchar **dest)
-{
- gchar *d = *dest;
- const gchar *v = in + 1;
-
- *d = *v;
- in ++;
-
- switch (*v) {
- case 'C':
- if (strncmp (v, RSPAMD_CONFDIR_MACRO, sizeof (RSPAMD_CONFDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_CONFDIR, sizeof (RSPAMD_CONFDIR) - 1);
- d += sizeof (RSPAMD_CONFDIR) - 1;
- in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
- }
- break;
- case 'R':
- if (strncmp (v, RSPAMD_RUNDIR_MACRO, sizeof (RSPAMD_RUNDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_RUNDIR, sizeof (RSPAMD_RUNDIR) - 1);
- d += sizeof (RSPAMD_RUNDIR) - 1;
- in += sizeof (RSPAMD_RUNDIR_MACRO) - 1;
- }
- break;
- case 'D':
- if (strncmp (v, RSPAMD_DBDIR_MACRO, sizeof (RSPAMD_DBDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_DBDIR, sizeof (RSPAMD_DBDIR) - 1);
- d += sizeof (RSPAMD_DBDIR) - 1;
- in += sizeof (RSPAMD_DBDIR_MACRO) - 1;
- }
- break;
- case 'L':
- if (strncmp (v, RSPAMD_LOGDIR_MACRO, sizeof (RSPAMD_LOGDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_LOGDIR, sizeof (RSPAMD_LOGDIR) - 1);
- d += sizeof (RSPAMD_LOGDIR) - 1;
- in += sizeof (RSPAMD_LOGDIR_MACRO) - 1;
- }
- break;
- case 'P':
- if (strncmp (v, RSPAMD_PREFIX_MACRO, sizeof (RSPAMD_PREFIX_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_PREFIX, sizeof (RSPAMD_PREFIX) - 1);
- d += sizeof (RSPAMD_PREFIX) - 1;
- in += sizeof (RSPAMD_PREFIX_MACRO) - 1;
- }
- else if (strncmp (v, RSPAMD_PLUGINSDIR_MACRO, sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1) == 0) {
- memcpy (d, RSPAMD_PLUGINSDIR, sizeof (RSPAMD_PLUGINSDIR) - 1);
- d += sizeof (RSPAMD_PLUGINSDIR) - 1;
- in += sizeof (RSPAMD_PLUGINSDIR_MACRO) - 1;
- }
- break;
- case 'V':
- if (strncmp (v, RSPAMD_VERSION_MACRO, sizeof (RSPAMD_VERSION_MACRO) - 1) == 0) {
- memcpy (d, RVERSION, sizeof (RVERSION) - 1);
- d += sizeof (RVERSION) - 1;
- in += sizeof (RSPAMD_VERSION_MACRO) - 1;
- }
- break;
- }
-
- *dest = d;
- return in;
-}
-
-gchar*
-rspamd_expand_path (memory_pool_t *pool, const gchar *path)
-{
- const gchar *p = path;
- gchar *dest, *d;
- gsize len = 0, orig_len = 0;
-
- while (*p != '\0') {
- if (*p == '$') {
- len ++;
- p = rspamd_check_path_variable (p + 1, &len);
- }
- else {
- len ++;
- }
- orig_len ++;
- p ++;
- }
-
- if (len == orig_len) {
- return memory_pool_strdup (pool, path);
- }
-
- dest = memory_pool_alloc (pool, len + 1);
- p = path;
- d = dest;
-
- while (*p != '\0') {
- if (*p == '$') {
- p = rspamd_expand_path_variable (p, &d);
- }
- else {
- *d++ = *p++;
- }
- }
-
- *d = '\0';
-
- msg_debug ("expanded %s to %s", path, dest);
-
- return dest;
-}
-
/*
* vi:ts=4
*/
diff --git a/src/util.h b/src/util.h
index bda871c22..f2b7132af 100644
--- a/src/util.h
+++ b/src/util.h
@@ -451,6 +451,5 @@ gint rspamd_read_passphrase (gchar *buf, gint size, gint rwflag, gpointer key);
* @param pool to use
* @param path path to expand
*/
-gchar* rspamd_expand_path (memory_pool_t *pool, const gchar *path);
#endif