]> source.dussan.org Git - rspamd.git/commitdiff
Use ucl variables.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 24 Nov 2013 21:53:43 +0000 (21:53 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 24 Nov 2013 21:53:43 +0000 (21:53 +0000)
src/cfg_rcl.c
src/cfg_utils.c
src/map.c
src/util.c
src/util.h

index b78a75fd64660d0b81c953b47f25889d24dee15e..b27dedbdd3da9855d97db1dcca7fadc1e6b5340a 100644 (file)
@@ -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);
index 1faaf08a7606d10988e95d211acb77009adc53ef..765ff7f34f4985b3440a67d6c7cc4dfee9860deb 100644 (file)
@@ -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);
index 25541a7e69432af5fb5c35be8e5735812e826c42..2af883a7a37a5be78dc126b588bfdf6e23b0060b 100644 (file)
--- 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 {
index 46e99c3095c0ed8385b45c1e1441588716f70baa..bc220657975ff80f4448a7de78ef869fa58b15ed 100644 (file)
@@ -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
  */
index bda871c22fc6e0ec557aaa6c979c4808ccbc8819..f2b7132af0151026e2ace210d54ddf7479d674e9 100644 (file)
@@ -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