diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-12-03 16:18:59 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-12-03 16:18:59 +0000 |
commit | eaf94aa54ca60731906c6143289212836c3e2b48 (patch) | |
tree | 9179efbf53774ff0b54e79c0da9bf36a3a765f46 /src/util/configuration.c | |
parent | 1695e22c1880e52273dccc544a576b025dae2132 (diff) | |
download | gnunet-eaf94aa54ca60731906c6143289212836c3e2b48.tar.gz gnunet-eaf94aa54ca60731906c6143289212836c3e2b48.zip |
- allow $-expressions anywhere in the given string
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index 80ad02e36..c69b933a3 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -1056,6 +1056,7 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1056 | unsigned int lopen; | 1056 | unsigned int lopen; |
1057 | char erased_char; | 1057 | char erased_char; |
1058 | char *erased_pos; | 1058 | char *erased_pos; |
1059 | size_t len; | ||
1059 | 1060 | ||
1060 | if (NULL == orig) | 1061 | if (NULL == orig) |
1061 | return NULL; | 1062 | return NULL; |
@@ -1124,7 +1125,8 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1124 | i = 0; | 1125 | i = 0; |
1125 | while ( (orig[i] != '/') && | 1126 | while ( (orig[i] != '/') && |
1126 | (orig[i] != '\\') && | 1127 | (orig[i] != '\\') && |
1127 | (orig[i] != '\0') ) | 1128 | (orig[i] != '\0') && |
1129 | (orig[i] != ' ') ) | ||
1128 | i++; | 1130 | i++; |
1129 | if (orig[i] == '\0') | 1131 | if (orig[i] == '\0') |
1130 | { | 1132 | { |
@@ -1144,10 +1146,10 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1144 | post, | 1146 | post, |
1145 | def); | 1147 | def); |
1146 | if (GNUNET_OK != | 1148 | if (GNUNET_OK != |
1147 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 1149 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1148 | "PATHS", | 1150 | "PATHS", |
1149 | start, | 1151 | start, |
1150 | &prefix)) | 1152 | &prefix)) |
1151 | { | 1153 | { |
1152 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1154 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1153 | "Filename for `%s' is not in PATHS config section\n", | 1155 | "Filename for `%s' is not in PATHS config section\n", |
@@ -1174,15 +1176,19 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1174 | } | 1176 | } |
1175 | prefix = GNUNET_strdup (env); | 1177 | prefix = GNUNET_strdup (env); |
1176 | } | 1178 | } |
1179 | prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix); | ||
1177 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1180 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1178 | "Prefix is `%s'\n", | 1181 | "Prefix is `%s'\n", |
1179 | prefix); | 1182 | prefix); |
1180 | result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2); | 1183 | if ( (erased_pos) && ('}' != erased_char) ) |
1184 | { | ||
1185 | len = strlen (prefix) + 1; | ||
1186 | prefix = GNUNET_realloc (prefix, len + 1); | ||
1187 | prefix[len - 1] = erased_char; | ||
1188 | prefix[len] = '\0'; | ||
1189 | } | ||
1190 | result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1); | ||
1181 | strcpy (result, prefix); | 1191 | strcpy (result, prefix); |
1182 | if ( (0 == strlen (prefix)) || | ||
1183 | ( (prefix[strlen (prefix) - 1] != DIR_SEPARATOR) && | ||
1184 | (strlen (post) > 0) ) ) | ||
1185 | strcat (result, DIR_SEPARATOR_STR); | ||
1186 | strcat (result, post); | 1192 | strcat (result, post); |
1187 | GNUNET_free_non_null (def); | 1193 | GNUNET_free_non_null (def); |
1188 | GNUNET_free (prefix); | 1194 | GNUNET_free (prefix); |
@@ -1205,14 +1211,31 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1205 | * to VAR2. | 1211 | * to VAR2. |
1206 | * | 1212 | * |
1207 | * @param cfg configuration to use for path expansion | 1213 | * @param cfg configuration to use for path expansion |
1208 | * @param orig string to $-expand (will be freed!) | 1214 | * @param orig string to $-expand (will be freed!). Note that multiple |
1215 | * $-expressions can be present in this string. They will all be | ||
1216 | * $-expanded. | ||
1209 | * @return $-expanded string | 1217 | * @return $-expanded string |
1210 | */ | 1218 | */ |
1211 | char * | 1219 | char * |
1212 | GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1220 | GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1213 | char *orig) | 1221 | char *orig) |
1214 | { | 1222 | { |
1215 | return expand_dollar (cfg, orig, 0); | 1223 | char *dup; |
1224 | size_t i; | ||
1225 | size_t len; | ||
1226 | |||
1227 | for (i = 0; '\0' != orig[i]; i++) | ||
1228 | { | ||
1229 | if ('$' != orig[i]) | ||
1230 | continue; | ||
1231 | dup = GNUNET_strdup (orig + i); | ||
1232 | dup = expand_dollar (cfg, dup, 0); | ||
1233 | len = strlen (dup) + 1; | ||
1234 | orig = GNUNET_realloc (orig, i + len); | ||
1235 | memcpy (orig + i, dup, len); | ||
1236 | GNUNET_free (dup); | ||
1237 | } | ||
1238 | return orig; | ||
1216 | } | 1239 | } |
1217 | 1240 | ||
1218 | 1241 | ||