*/
struct classifier_config* find_classifier_conf (struct config_file *cfg, const gchar *name);
-/*
- * Expand path that may contain configuration variables:
- * $CONFDIR - configuration directory
- * $LOCALSTATESDIR - local states directory
- * $INSTALLPREFIX - installation prefix
- * $VERSION - rspamd version
- */
-const gchar* rspamd_expand_path (memory_pool_t *pool, const gchar *path);
-
#endif /* ifdef CFG_FILE_H */
/*
* vi:ts=4
target = (gchar **)(((gchar *)pd->user_struct) + pd->offset);
switch (obj->type) {
case UCL_STRING:
- /* Direct assigning is safe, as object is likely linked to the cfg mem_pool */
- *target = ucl_copy_value_trash (obj);
+ 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));
+ }
break;
case UCL_INT:
*target = memory_pool_alloc (cfg->cfg_pool, num_str_len);
return FALSE;
}
- if (pd->flags & RSPAMD_CL_FLAG_STRING_PATH) {
- *target = (gchar *)rspamd_expand_path (cfg->cfg_pool, *target);
- }
-
return TRUE;
}
for (cur = obj; cur != NULL; cur = cur->next) {
switch (cur->type) {
case UCL_STRING:
- /* Direct assigning is safe, as curect is likely linked to the cfg mem_pool */
- val = ucl_copy_value_trash (obj);
+ 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));
+ }
break;
case UCL_INT:
val = memory_pool_alloc (cfg->cfg_pool, num_str_len);
return res;
}
-/*
- * Variables:
- * $CONFDIR - configuration directory
- * $LOCALSTATESDIR - local states directory
- * $INSTALLPREFIX - installation prefix
- * $VERSION - rspamd version
- */
-
-#define RSPAMD_CONFDIR_MACRO "CONFDIR"
-#define RSPAMD_LOCALSTATESDIR_MACRO "LOCALSTATESDIR"
-#define RSPAMD_INSTALLPREFIX_MACRO "INSTALLPREFIX"
-#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 (ETC_PREFIX) - 1;
- in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
- }
- break;
- case 'L':
- if (strncmp (in, RSPAMD_LOCALSTATESDIR_MACRO, sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1) == 0) {
- *len += sizeof (LOCALSTATES_PREFIX) - 1;
- in += sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1;
- }
- break;
- case 'I':
- if (strncmp (in, RSPAMD_INSTALLPREFIX_MACRO, sizeof (RSPAMD_INSTALLPREFIX_MACRO) - 1) == 0) {
- *len += sizeof (CMAKE_PREFIX) - 1;
- in += sizeof (RSPAMD_INSTALLPREFIX_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, ETC_PREFIX, sizeof (ETC_PREFIX) - 1);
- d += sizeof (ETC_PREFIX) - 1;
- in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
- }
- break;
- case 'L':
- if (strncmp (v, RSPAMD_LOCALSTATESDIR_MACRO, sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1) == 0) {
- memcpy (d, LOCALSTATES_PREFIX, sizeof (LOCALSTATES_PREFIX) - 1);
- d += sizeof (LOCALSTATES_PREFIX) - 1;
- in += sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1;
- }
- break;
- case 'I':
- if (strncmp (v, RSPAMD_INSTALLPREFIX_MACRO, sizeof (RSPAMD_INSTALLPREFIX_MACRO) - 1) == 0) {
- memcpy (d, CMAKE_PREFIX, sizeof (CMAKE_PREFIX) - 1);
- d += sizeof (CMAKE_PREFIX) - 1;
- in += sizeof (RSPAMD_INSTALLPREFIX_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;
-}
-
-const 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 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
*/
new_map->user_data = user_data;
new_map->protocol = proto;
new_map->cfg = cfg;
- new_map->uri = memory_pool_strdup (cfg->cfg_pool, proto == MAP_PROTO_FILE ? def : map_line);
new_map->id = g_random_int ();
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);
+ def = new_map->uri;
+ }
+ else {
+ new_map->uri = memory_pool_strdup (cfg->cfg_pool, map_line);
+ }
if (description != NULL) {
new_map->description = memory_pool_strdup (cfg->cfg_pool, description);
}
#endif
}
+/*
+ * Variables:
+ * $CONFDIR - configuration directory
+ * $LOCALSTATESDIR - local states directory
+ * $INSTALLPREFIX - installation prefix
+ * $VERSION - rspamd version
+ */
+
+#define RSPAMD_CONFDIR_MACRO "CONFDIR"
+#define RSPAMD_LOCALSTATESDIR_MACRO "LOCALSTATESDIR"
+#define RSPAMD_INSTALLPREFIX_MACRO "INSTALLPREFIX"
+#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 (ETC_PREFIX) - 1;
+ in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
+ }
+ break;
+ case 'L':
+ if (strncmp (in, RSPAMD_LOCALSTATESDIR_MACRO, sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1) == 0) {
+ *len += sizeof (LOCALSTATES_PREFIX) - 1;
+ in += sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1;
+ }
+ break;
+ case 'I':
+ if (strncmp (in, RSPAMD_INSTALLPREFIX_MACRO, sizeof (RSPAMD_INSTALLPREFIX_MACRO) - 1) == 0) {
+ *len += sizeof (CMAKE_PREFIX) - 1;
+ in += sizeof (RSPAMD_INSTALLPREFIX_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, ETC_PREFIX, sizeof (ETC_PREFIX) - 1);
+ d += sizeof (ETC_PREFIX) - 1;
+ in += sizeof (RSPAMD_CONFDIR_MACRO) - 1;
+ }
+ break;
+ case 'L':
+ if (strncmp (v, RSPAMD_LOCALSTATESDIR_MACRO, sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1) == 0) {
+ memcpy (d, LOCALSTATES_PREFIX, sizeof (LOCALSTATES_PREFIX) - 1);
+ d += sizeof (LOCALSTATES_PREFIX) - 1;
+ in += sizeof (RSPAMD_LOCALSTATESDIR_MACRO) - 1;
+ }
+ break;
+ case 'I':
+ if (strncmp (v, RSPAMD_INSTALLPREFIX_MACRO, sizeof (RSPAMD_INSTALLPREFIX_MACRO) - 1) == 0) {
+ memcpy (d, CMAKE_PREFIX, sizeof (CMAKE_PREFIX) - 1);
+ d += sizeof (CMAKE_PREFIX) - 1;
+ in += sizeof (RSPAMD_INSTALLPREFIX_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
*/
*/
gint rspamd_read_passphrase (gchar *buf, gint size, gint rwflag, gpointer key);
+/**
+ * Expand path that may contain configuration variables:
+ * $CONFDIR - configuration directory
+ * $LOCALSTATESDIR - local states directory
+ * $INSTALLPREFIX - installation prefix
+ * $VERSION - rspamd version
+ * @param pool to use
+ * @param path path to expand
+ */
+gchar* rspamd_expand_path (memory_pool_t *pool, const gchar *path);
+
#endif