diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/configuration.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 1360 |
1 files changed, 682 insertions, 678 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index 6d72d4fe0..cb6932b15 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -30,15 +30,16 @@ | |||
30 | #include "gnunet_configuration_lib.h" | 30 | #include "gnunet_configuration_lib.h" |
31 | #include "gnunet_disk_lib.h" | 31 | #include "gnunet_disk_lib.h" |
32 | 32 | ||
33 | #define LOG(kind, ...) GNUNET_log_from(kind, "util", __VA_ARGS__) | 33 | #define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__) |
34 | 34 | ||
35 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ | 35 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ |
36 | GNUNET_log_from_strerror_file(kind, "util", syscall, filename) | 36 | GNUNET_log_from_strerror_file (kind, "util", syscall, filename) |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * @brief configuration entry | 39 | * @brief configuration entry |
40 | */ | 40 | */ |
41 | struct ConfigEntry { | 41 | struct ConfigEntry |
42 | { | ||
42 | /** | 43 | /** |
43 | * This is a linked list. | 44 | * This is a linked list. |
44 | */ | 45 | */ |
@@ -59,7 +60,8 @@ struct ConfigEntry { | |||
59 | /** | 60 | /** |
60 | * @brief configuration section | 61 | * @brief configuration section |
61 | */ | 62 | */ |
62 | struct ConfigSection { | 63 | struct ConfigSection |
64 | { | ||
63 | /** | 65 | /** |
64 | * This is a linked list. | 66 | * This is a linked list. |
65 | */ | 67 | */ |
@@ -80,7 +82,8 @@ struct ConfigSection { | |||
80 | /** | 82 | /** |
81 | * @brief configuration data | 83 | * @brief configuration data |
82 | */ | 84 | */ |
83 | struct GNUNET_CONFIGURATION_Handle { | 85 | struct GNUNET_CONFIGURATION_Handle |
86 | { | ||
84 | /** | 87 | /** |
85 | * Configuration sections. | 88 | * Configuration sections. |
86 | */ | 89 | */ |
@@ -99,7 +102,8 @@ struct GNUNET_CONFIGURATION_Handle { | |||
99 | * Used for diffing a configuration object against | 102 | * Used for diffing a configuration object against |
100 | * the default one | 103 | * the default one |
101 | */ | 104 | */ |
102 | struct DiffHandle { | 105 | struct DiffHandle |
106 | { | ||
103 | const struct GNUNET_CONFIGURATION_Handle *cfg_default; | 107 | const struct GNUNET_CONFIGURATION_Handle *cfg_default; |
104 | 108 | ||
105 | struct GNUNET_CONFIGURATION_Handle *cfgDiff; | 109 | struct GNUNET_CONFIGURATION_Handle *cfgDiff; |
@@ -112,9 +116,9 @@ struct DiffHandle { | |||
112 | * @return fresh configuration object | 116 | * @return fresh configuration object |
113 | */ | 117 | */ |
114 | struct GNUNET_CONFIGURATION_Handle * | 118 | struct GNUNET_CONFIGURATION_Handle * |
115 | GNUNET_CONFIGURATION_create() | 119 | GNUNET_CONFIGURATION_create () |
116 | { | 120 | { |
117 | return GNUNET_new(struct GNUNET_CONFIGURATION_Handle); | 121 | return GNUNET_new (struct GNUNET_CONFIGURATION_Handle); |
118 | } | 122 | } |
119 | 123 | ||
120 | 124 | ||
@@ -124,13 +128,13 @@ GNUNET_CONFIGURATION_create() | |||
124 | * @param cfg configuration to destroy | 128 | * @param cfg configuration to destroy |
125 | */ | 129 | */ |
126 | void | 130 | void |
127 | GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg) | 131 | GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) |
128 | { | 132 | { |
129 | struct ConfigSection *sec; | 133 | struct ConfigSection *sec; |
130 | 134 | ||
131 | while (NULL != (sec = cfg->sections)) | 135 | while (NULL != (sec = cfg->sections)) |
132 | GNUNET_CONFIGURATION_remove_section(cfg, sec->name); | 136 | GNUNET_CONFIGURATION_remove_section (cfg, sec->name); |
133 | GNUNET_free(cfg); | 137 | GNUNET_free (cfg); |
134 | } | 138 | } |
135 | 139 | ||
136 | 140 | ||
@@ -146,22 +150,22 @@ GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg) | |||
146 | * otherwise return value from @a cb. | 150 | * otherwise return value from @a cb. |
147 | */ | 151 | */ |
148 | int | 152 | int |
149 | GNUNET_CONFIGURATION_parse_and_run(const char *filename, | 153 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, |
150 | GNUNET_CONFIGURATION_Callback cb, | 154 | GNUNET_CONFIGURATION_Callback cb, |
151 | void *cb_cls) | 155 | void *cb_cls) |
152 | { | 156 | { |
153 | struct GNUNET_CONFIGURATION_Handle *cfg; | 157 | struct GNUNET_CONFIGURATION_Handle *cfg; |
154 | int ret; | 158 | int ret; |
155 | 159 | ||
156 | cfg = GNUNET_CONFIGURATION_create(); | 160 | cfg = GNUNET_CONFIGURATION_create (); |
157 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, filename)) | 161 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename)) |
158 | { | 162 | { |
159 | GNUNET_break(0); | 163 | GNUNET_break (0); |
160 | GNUNET_CONFIGURATION_destroy(cfg); | 164 | GNUNET_CONFIGURATION_destroy (cfg); |
161 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
162 | } | 166 | } |
163 | ret = cb(cb_cls, cfg); | 167 | ret = cb (cb_cls, cfg); |
164 | GNUNET_CONFIGURATION_destroy(cfg); | 168 | GNUNET_CONFIGURATION_destroy (cfg); |
165 | return ret; | 169 | return ret; |
166 | } | 170 | } |
167 | 171 | ||
@@ -178,10 +182,10 @@ GNUNET_CONFIGURATION_parse_and_run(const char *filename, | |||
178 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 182 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
179 | */ | 183 | */ |
180 | int | 184 | int |
181 | GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, | 185 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, |
182 | const char *mem, | 186 | const char *mem, |
183 | size_t size, | 187 | size_t size, |
184 | const char *basedir) | 188 | const char *basedir) |
185 | { | 189 | { |
186 | char *line; | 190 | char *line; |
187 | char *line_orig; | 191 | char *line_orig; |
@@ -199,133 +203,133 @@ GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
199 | char *value; | 203 | char *value; |
200 | 204 | ||
201 | ret = GNUNET_OK; | 205 | ret = GNUNET_OK; |
202 | section = GNUNET_strdup(""); | 206 | section = GNUNET_strdup (""); |
203 | nr = 0; | 207 | nr = 0; |
204 | r_bytes = 0; | 208 | r_bytes = 0; |
205 | line_orig = NULL; | 209 | line_orig = NULL; |
206 | while (r_bytes < size) | 210 | while (r_bytes < size) |
211 | { | ||
212 | GNUNET_free_non_null (line_orig); | ||
213 | /* fgets-like behaviour on buffer */ | ||
214 | to_read = size - r_bytes; | ||
215 | pos = memchr (&mem[r_bytes], '\n', to_read); | ||
216 | if (NULL == pos) | ||
207 | { | 217 | { |
208 | GNUNET_free_non_null(line_orig); | 218 | line_orig = GNUNET_strndup (&mem[r_bytes], line_size = to_read); |
209 | /* fgets-like behaviour on buffer */ | 219 | r_bytes += line_size; |
210 | to_read = size - r_bytes; | 220 | } |
211 | pos = memchr(&mem[r_bytes], '\n', to_read); | 221 | else |
212 | if (NULL == pos) | 222 | { |
213 | { | 223 | line_orig = |
214 | line_orig = GNUNET_strndup(&mem[r_bytes], line_size = to_read); | 224 | GNUNET_strndup (&mem[r_bytes], line_size = (pos - &mem[r_bytes])); |
215 | r_bytes += line_size; | 225 | r_bytes += line_size + 1; |
216 | } | 226 | } |
217 | else | 227 | line = line_orig; |
218 | { | 228 | /* increment line number */ |
219 | line_orig = | 229 | nr++; |
220 | GNUNET_strndup(&mem[r_bytes], line_size = (pos - &mem[r_bytes])); | 230 | /* tabs and '\r' are whitespace */ |
221 | r_bytes += line_size + 1; | 231 | emptyline = GNUNET_YES; |
222 | } | 232 | for (i = 0; i < line_size; i++) |
223 | line = line_orig; | 233 | { |
224 | /* increment line number */ | 234 | if (line[i] == '\t') |
225 | nr++; | 235 | line[i] = ' '; |
226 | /* tabs and '\r' are whitespace */ | 236 | if (line[i] == '\r') |
227 | emptyline = GNUNET_YES; | 237 | line[i] = ' '; |
228 | for (i = 0; i < line_size; i++) | 238 | if (' ' != line[i]) |
229 | { | 239 | emptyline = GNUNET_NO; |
230 | if (line[i] == '\t') | 240 | } |
231 | line[i] = ' '; | 241 | /* ignore empty lines */ |
232 | if (line[i] == '\r') | 242 | if (GNUNET_YES == emptyline) |
233 | line[i] = ' '; | 243 | continue; |
234 | if (' ' != line[i]) | ||
235 | emptyline = GNUNET_NO; | ||
236 | } | ||
237 | /* ignore empty lines */ | ||
238 | if (GNUNET_YES == emptyline) | ||
239 | continue; | ||
240 | 244 | ||
241 | /* remove tailing whitespace */ | 245 | /* remove tailing whitespace */ |
242 | for (i = line_size - 1; (i >= 1) && (isspace((unsigned char)line[i])); | 246 | for (i = line_size - 1; (i >= 1) && (isspace ((unsigned char) line[i])); |
243 | i--) | 247 | i--) |
244 | line[i] = '\0'; | 248 | line[i] = '\0'; |
245 | 249 | ||
246 | /* remove leading whitespace */ | 250 | /* remove leading whitespace */ |
247 | for (; line[0] != '\0' && (isspace((unsigned char)line[0])); line++) | 251 | for (; line[0] != '\0' && (isspace ((unsigned char) line[0])); line++) |
248 | ; | 252 | ; |
249 | 253 | ||
250 | /* ignore comments */ | 254 | /* ignore comments */ |
251 | if (('#' == line[0]) || ('%' == line[0])) | 255 | if (('#' == line[0]) || ('%' == line[0])) |
252 | continue; | 256 | continue; |
253 | 257 | ||
254 | /* handle special "@INLINE@" directive */ | 258 | /* handle special "@INLINE@" directive */ |
255 | if (0 == strncasecmp(line, "@INLINE@ ", strlen("@INLINE@ "))) | 259 | if (0 == strncasecmp (line, "@INLINE@ ", strlen ("@INLINE@ "))) |
256 | { | 260 | { |
257 | /* @INLINE@ value */ | 261 | /* @INLINE@ value */ |
258 | value = &line[strlen("@INLINE@ ")]; | 262 | value = &line[strlen ("@INLINE@ ")]; |
259 | if (NULL != basedir) | 263 | if (NULL != basedir) |
260 | { | 264 | { |
261 | char *fn; | 265 | char *fn; |
262 | 266 | ||
263 | GNUNET_asprintf(&fn, "%s/%s", basedir, value); | 267 | GNUNET_asprintf (&fn, "%s/%s", basedir, value); |
264 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg, fn)) | 268 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn)) |
265 | { | ||
266 | GNUNET_free(fn); | ||
267 | ret = GNUNET_SYSERR; /* failed to parse included config */ | ||
268 | break; | ||
269 | } | ||
270 | GNUNET_free(fn); | ||
271 | } | ||
272 | else | ||
273 | { | ||
274 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
275 | "Ignoring parsing @INLINE@ configurations, not allowed!\n"); | ||
276 | ret = GNUNET_SYSERR; | ||
277 | break; | ||
278 | } | ||
279 | continue; | ||
280 | } | ||
281 | if (('[' == line[0]) && (']' == line[line_size - 1])) | ||
282 | { | ||
283 | /* [value] */ | ||
284 | line[line_size - 1] = '\0'; | ||
285 | value = &line[1]; | ||
286 | GNUNET_free(section); | ||
287 | section = GNUNET_strdup(value); | ||
288 | continue; | ||
289 | } | ||
290 | if (NULL != (eq = strchr(line, '='))) | ||
291 | { | 269 | { |
292 | /* tag = value */ | 270 | GNUNET_free (fn); |
293 | tag = GNUNET_strndup(line, eq - line); | 271 | ret = GNUNET_SYSERR; /* failed to parse included config */ |
294 | /* remove tailing whitespace */ | 272 | break; |
295 | for (i = strlen(tag) - 1; (i >= 1) && (isspace((unsigned char)tag[i])); | ||
296 | i--) | ||
297 | tag[i] = '\0'; | ||
298 | |||
299 | /* Strip whitespace */ | ||
300 | value = eq + 1; | ||
301 | while (isspace((unsigned char)value[0])) | ||
302 | value++; | ||
303 | for (i = strlen(value) - 1; | ||
304 | (i >= 1) && (isspace((unsigned char)value[i])); | ||
305 | i--) | ||
306 | value[i] = '\0'; | ||
307 | |||
308 | /* remove quotes */ | ||
309 | i = 0; | ||
310 | if (('"' == value[0]) && ('"' == value[strlen(value) - 1])) | ||
311 | { | ||
312 | value[strlen(value) - 1] = '\0'; | ||
313 | value++; | ||
314 | } | ||
315 | GNUNET_CONFIGURATION_set_value_string(cfg, section, tag, &value[i]); | ||
316 | GNUNET_free(tag); | ||
317 | continue; | ||
318 | } | 273 | } |
319 | /* parse error */ | 274 | GNUNET_free (fn); |
320 | LOG(GNUNET_ERROR_TYPE_WARNING, | 275 | } |
321 | _("Syntax error while deserializing in line %u\n"), | 276 | else |
322 | nr); | 277 | { |
323 | ret = GNUNET_SYSERR; | 278 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
324 | break; | 279 | "Ignoring parsing @INLINE@ configurations, not allowed!\n"); |
280 | ret = GNUNET_SYSERR; | ||
281 | break; | ||
282 | } | ||
283 | continue; | ||
284 | } | ||
285 | if (('[' == line[0]) && (']' == line[line_size - 1])) | ||
286 | { | ||
287 | /* [value] */ | ||
288 | line[line_size - 1] = '\0'; | ||
289 | value = &line[1]; | ||
290 | GNUNET_free (section); | ||
291 | section = GNUNET_strdup (value); | ||
292 | continue; | ||
325 | } | 293 | } |
326 | GNUNET_free_non_null(line_orig); | 294 | if (NULL != (eq = strchr (line, '='))) |
327 | GNUNET_free(section); | 295 | { |
328 | GNUNET_assert((GNUNET_OK != ret) || (r_bytes == size)); | 296 | /* tag = value */ |
297 | tag = GNUNET_strndup (line, eq - line); | ||
298 | /* remove tailing whitespace */ | ||
299 | for (i = strlen (tag) - 1; (i >= 1) && (isspace ((unsigned char) tag[i])); | ||
300 | i--) | ||
301 | tag[i] = '\0'; | ||
302 | |||
303 | /* Strip whitespace */ | ||
304 | value = eq + 1; | ||
305 | while (isspace ((unsigned char) value[0])) | ||
306 | value++; | ||
307 | for (i = strlen (value) - 1; | ||
308 | (i >= 1) && (isspace ((unsigned char) value[i])); | ||
309 | i--) | ||
310 | value[i] = '\0'; | ||
311 | |||
312 | /* remove quotes */ | ||
313 | i = 0; | ||
314 | if (('"' == value[0]) && ('"' == value[strlen (value) - 1])) | ||
315 | { | ||
316 | value[strlen (value) - 1] = '\0'; | ||
317 | value++; | ||
318 | } | ||
319 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]); | ||
320 | GNUNET_free (tag); | ||
321 | continue; | ||
322 | } | ||
323 | /* parse error */ | ||
324 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
325 | _ ("Syntax error while deserializing in line %u\n"), | ||
326 | nr); | ||
327 | ret = GNUNET_SYSERR; | ||
328 | break; | ||
329 | } | ||
330 | GNUNET_free_non_null (line_orig); | ||
331 | GNUNET_free (section); | ||
332 | GNUNET_assert ((GNUNET_OK != ret) || (r_bytes == size)); | ||
329 | return ret; | 333 | return ret; |
330 | } | 334 | } |
331 | 335 | ||
@@ -339,8 +343,8 @@ GNUNET_CONFIGURATION_deserialize(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
339 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 343 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
340 | */ | 344 | */ |
341 | int | 345 | int |
342 | GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, | 346 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, |
343 | const char *filename) | 347 | const char *filename) |
344 | { | 348 | { |
345 | uint64_t fs64; | 349 | uint64_t fs64; |
346 | size_t fs; | 350 | size_t fs; |
@@ -351,43 +355,43 @@ GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
351 | int ret; | 355 | int ret; |
352 | ssize_t sret; | 356 | ssize_t sret; |
353 | 357 | ||
354 | fn = GNUNET_STRINGS_filename_expand(filename); | 358 | fn = GNUNET_STRINGS_filename_expand (filename); |
355 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn); | 359 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to parse config file `%s'\n", fn); |
356 | if (NULL == fn) | 360 | if (NULL == fn) |
357 | return GNUNET_SYSERR; | 361 | return GNUNET_SYSERR; |
358 | dirty = cfg->dirty; /* back up value! */ | 362 | dirty = cfg->dirty; /* back up value! */ |
359 | if (GNUNET_SYSERR == | 363 | if (GNUNET_SYSERR == |
360 | GNUNET_DISK_file_size(fn, &fs64, GNUNET_YES, GNUNET_YES)) | 364 | GNUNET_DISK_file_size (fn, &fs64, GNUNET_YES, GNUNET_YES)) |
361 | { | 365 | { |
362 | LOG(GNUNET_ERROR_TYPE_WARNING, | 366 | LOG (GNUNET_ERROR_TYPE_WARNING, |
363 | "Error while determining the file size of `%s'\n", | 367 | "Error while determining the file size of `%s'\n", |
364 | fn); | 368 | fn); |
365 | GNUNET_free(fn); | 369 | GNUNET_free (fn); |
366 | return GNUNET_SYSERR; | 370 | return GNUNET_SYSERR; |
367 | } | 371 | } |
368 | if (fs64 > SIZE_MAX) | 372 | if (fs64 > SIZE_MAX) |
369 | { | 373 | { |
370 | GNUNET_break(0); /* File size is more than the heap size */ | 374 | GNUNET_break (0); /* File size is more than the heap size */ |
371 | GNUNET_free(fn); | 375 | GNUNET_free (fn); |
372 | return GNUNET_SYSERR; | 376 | return GNUNET_SYSERR; |
373 | } | 377 | } |
374 | fs = fs64; | 378 | fs = fs64; |
375 | mem = GNUNET_malloc(fs); | 379 | mem = GNUNET_malloc (fs); |
376 | sret = GNUNET_DISK_fn_read(fn, mem, fs); | 380 | sret = GNUNET_DISK_fn_read (fn, mem, fs); |
377 | if ((sret < 0) || (fs != (size_t)sret)) | 381 | if ((sret < 0) || (fs != (size_t) sret)) |
378 | { | 382 | { |
379 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Error while reading file `%s'\n"), fn); | 383 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Error while reading file `%s'\n"), fn); |
380 | GNUNET_free(fn); | 384 | GNUNET_free (fn); |
381 | GNUNET_free(mem); | 385 | GNUNET_free (mem); |
382 | return GNUNET_SYSERR; | 386 | return GNUNET_SYSERR; |
383 | } | 387 | } |
384 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn); | 388 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Deserializing contents of file `%s'\n", fn); |
385 | endsep = strrchr(fn, (int)'/'); | 389 | endsep = strrchr (fn, (int) '/'); |
386 | if (NULL != endsep) | 390 | if (NULL != endsep) |
387 | *endsep = '\0'; | 391 | *endsep = '\0'; |
388 | ret = GNUNET_CONFIGURATION_deserialize(cfg, mem, fs, fn); | 392 | ret = GNUNET_CONFIGURATION_deserialize (cfg, mem, fs, fn); |
389 | GNUNET_free(fn); | 393 | GNUNET_free (fn); |
390 | GNUNET_free(mem); | 394 | GNUNET_free (mem); |
391 | /* restore dirty flag - anything we set in the meantime | 395 | /* restore dirty flag - anything we set in the meantime |
392 | * came from disk */ | 396 | * came from disk */ |
393 | cfg->dirty = dirty; | 397 | cfg->dirty = dirty; |
@@ -403,7 +407,7 @@ GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
403 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) | 407 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) |
404 | */ | 408 | */ |
405 | int | 409 | int |
406 | GNUNET_CONFIGURATION_is_dirty(const struct GNUNET_CONFIGURATION_Handle *cfg) | 410 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) |
407 | { | 411 | { |
408 | return cfg->dirty; | 412 | return cfg->dirty; |
409 | } | 413 | } |
@@ -418,8 +422,8 @@ GNUNET_CONFIGURATION_is_dirty(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
418 | * present. This memory should be freed by the caller | 422 | * present. This memory should be freed by the caller |
419 | */ | 423 | */ |
420 | char * | 424 | char * |
421 | GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, | 425 | GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, |
422 | size_t *size) | 426 | size_t *size) |
423 | { | 427 | { |
424 | struct ConfigSection *sec; | 428 | struct ConfigSection *sec; |
425 | struct ConfigEntry *ent; | 429 | struct ConfigEntry *ent; |
@@ -433,67 +437,67 @@ GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
433 | /* Pass1 : calculate the buffer size required */ | 437 | /* Pass1 : calculate the buffer size required */ |
434 | m_size = 0; | 438 | m_size = 0; |
435 | for (sec = cfg->sections; NULL != sec; sec = sec->next) | 439 | for (sec = cfg->sections; NULL != sec; sec = sec->next) |
440 | { | ||
441 | /* For each section we need to add 3 charaters: {'[',']','\n'} */ | ||
442 | m_size += strlen (sec->name) + 3; | ||
443 | for (ent = sec->entries; NULL != ent; ent = ent->next) | ||
436 | { | 444 | { |
437 | /* For each section we need to add 3 charaters: {'[',']','\n'} */ | 445 | if (NULL != ent->val) |
438 | m_size += strlen(sec->name) + 3; | 446 | { |
439 | for (ent = sec->entries; NULL != ent; ent = ent->next) | 447 | /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */ |
448 | pos = ent->val; | ||
449 | while (NULL != (pos = strstr (pos, "\n"))) | ||
440 | { | 450 | { |
441 | if (NULL != ent->val) | 451 | m_size++; |
442 | { | 452 | pos++; |
443 | /* if val has any '\n' then they occupy +1 character as '\n'->'\\','n' */ | ||
444 | pos = ent->val; | ||
445 | while (NULL != (pos = strstr(pos, "\n"))) | ||
446 | { | ||
447 | m_size++; | ||
448 | pos++; | ||
449 | } | ||
450 | /* For each key = value pair we need to add 4 characters (2 | ||
451 | spaces and 1 equal-to character and 1 new line) */ | ||
452 | m_size += strlen(ent->key) + strlen(ent->val) + 4; | ||
453 | } | ||
454 | } | 453 | } |
455 | /* A new line after section end */ | 454 | /* For each key = value pair we need to add 4 characters (2 |
456 | m_size++; | 455 | spaces and 1 equal-to character and 1 new line) */ |
456 | m_size += strlen (ent->key) + strlen (ent->val) + 4; | ||
457 | } | ||
457 | } | 458 | } |
459 | /* A new line after section end */ | ||
460 | m_size++; | ||
461 | } | ||
458 | 462 | ||
459 | /* Pass2: Allocate memory and write the configuration to it */ | 463 | /* Pass2: Allocate memory and write the configuration to it */ |
460 | mem = GNUNET_malloc(m_size); | 464 | mem = GNUNET_malloc (m_size); |
461 | sec = cfg->sections; | 465 | sec = cfg->sections; |
462 | c_size = 0; | 466 | c_size = 0; |
463 | *size = c_size; | 467 | *size = c_size; |
464 | while (NULL != sec) | 468 | while (NULL != sec) |
469 | { | ||
470 | int len; | ||
471 | |||
472 | len = GNUNET_asprintf (&cbuf, "[%s]\n", sec->name); | ||
473 | GNUNET_assert (0 < len); | ||
474 | GNUNET_memcpy (mem + c_size, cbuf, len); | ||
475 | c_size += len; | ||
476 | GNUNET_free (cbuf); | ||
477 | for (ent = sec->entries; NULL != ent; ent = ent->next) | ||
465 | { | 478 | { |
466 | int len; | 479 | if (NULL != ent->val) |
467 | 480 | { | |
468 | len = GNUNET_asprintf(&cbuf, "[%s]\n", sec->name); | 481 | val = GNUNET_malloc (strlen (ent->val) * 2 + 1); |
469 | GNUNET_assert(0 < len); | 482 | strcpy (val, ent->val); |
470 | GNUNET_memcpy(mem + c_size, cbuf, len); | 483 | while (NULL != (pos = strstr (val, "\n"))) |
471 | c_size += len; | ||
472 | GNUNET_free(cbuf); | ||
473 | for (ent = sec->entries; NULL != ent; ent = ent->next) | ||
474 | { | 484 | { |
475 | if (NULL != ent->val) | 485 | memmove (&pos[2], &pos[1], strlen (&pos[1])); |
476 | { | 486 | pos[0] = '\\'; |
477 | val = GNUNET_malloc(strlen(ent->val) * 2 + 1); | 487 | pos[1] = 'n'; |
478 | strcpy(val, ent->val); | ||
479 | while (NULL != (pos = strstr(val, "\n"))) | ||
480 | { | ||
481 | memmove(&pos[2], &pos[1], strlen(&pos[1])); | ||
482 | pos[0] = '\\'; | ||
483 | pos[1] = 'n'; | ||
484 | } | ||
485 | len = GNUNET_asprintf(&cbuf, "%s = %s\n", ent->key, val); | ||
486 | GNUNET_free(val); | ||
487 | GNUNET_memcpy(mem + c_size, cbuf, len); | ||
488 | c_size += len; | ||
489 | GNUNET_free(cbuf); | ||
490 | } | ||
491 | } | 488 | } |
492 | GNUNET_memcpy(mem + c_size, "\n", 1); | 489 | len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val); |
493 | c_size++; | 490 | GNUNET_free (val); |
494 | sec = sec->next; | 491 | GNUNET_memcpy (mem + c_size, cbuf, len); |
492 | c_size += len; | ||
493 | GNUNET_free (cbuf); | ||
494 | } | ||
495 | } | 495 | } |
496 | GNUNET_assert(c_size == m_size); | 496 | GNUNET_memcpy (mem + c_size, "\n", 1); |
497 | c_size++; | ||
498 | sec = sec->next; | ||
499 | } | ||
500 | GNUNET_assert (c_size == m_size); | ||
497 | *size = c_size; | 501 | *size = c_size; |
498 | return mem; | 502 | return mem; |
499 | } | 503 | } |
@@ -507,42 +511,42 @@ GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
507 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 511 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
508 | */ | 512 | */ |
509 | int | 513 | int |
510 | GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, | 514 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, |
511 | const char *filename) | 515 | const char *filename) |
512 | { | 516 | { |
513 | char *fn; | 517 | char *fn; |
514 | char *cfg_buf; | 518 | char *cfg_buf; |
515 | size_t size; | 519 | size_t size; |
516 | ssize_t sret; | 520 | ssize_t sret; |
517 | 521 | ||
518 | fn = GNUNET_STRINGS_filename_expand(filename); | 522 | fn = GNUNET_STRINGS_filename_expand (filename); |
519 | if (fn == NULL) | 523 | if (fn == NULL) |
520 | return GNUNET_SYSERR; | 524 | return GNUNET_SYSERR; |
521 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(fn)) | 525 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)) |
522 | { | 526 | { |
523 | GNUNET_free(fn); | 527 | GNUNET_free (fn); |
524 | return GNUNET_SYSERR; | 528 | return GNUNET_SYSERR; |
525 | } | 529 | } |
526 | cfg_buf = GNUNET_CONFIGURATION_serialize(cfg, &size); | 530 | cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); |
527 | sret = GNUNET_DISK_fn_write(fn, | 531 | sret = GNUNET_DISK_fn_write (fn, |
528 | cfg_buf, | 532 | cfg_buf, |
529 | size, | 533 | size, |
530 | GNUNET_DISK_PERM_USER_READ | | 534 | GNUNET_DISK_PERM_USER_READ |
531 | GNUNET_DISK_PERM_USER_WRITE | | 535 | | GNUNET_DISK_PERM_USER_WRITE |
532 | GNUNET_DISK_PERM_GROUP_READ | | 536 | | GNUNET_DISK_PERM_GROUP_READ |
533 | GNUNET_DISK_PERM_GROUP_WRITE); | 537 | | GNUNET_DISK_PERM_GROUP_WRITE); |
534 | if ((sret < 0) || (size != (size_t)sret)) | 538 | if ((sret < 0) || (size != (size_t) sret)) |
535 | { | 539 | { |
536 | GNUNET_free(fn); | 540 | GNUNET_free (fn); |
537 | GNUNET_free(cfg_buf); | 541 | GNUNET_free (cfg_buf); |
538 | LOG(GNUNET_ERROR_TYPE_WARNING, | 542 | LOG (GNUNET_ERROR_TYPE_WARNING, |
539 | "Writing configuration to file `%s' failed\n", | 543 | "Writing configuration to file `%s' failed\n", |
540 | filename); | 544 | filename); |
541 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ | 545 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ |
542 | return GNUNET_SYSERR; | 546 | return GNUNET_SYSERR; |
543 | } | 547 | } |
544 | GNUNET_free(fn); | 548 | GNUNET_free (fn); |
545 | GNUNET_free(cfg_buf); | 549 | GNUNET_free (cfg_buf); |
546 | cfg->dirty = GNUNET_NO; /* last write succeeded */ | 550 | cfg->dirty = GNUNET_NO; /* last write succeeded */ |
547 | return GNUNET_OK; | 551 | return GNUNET_OK; |
548 | } | 552 | } |
@@ -556,9 +560,9 @@ GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
556 | * @param iter_cls closure for @a iter | 560 | * @param iter_cls closure for @a iter |
557 | */ | 561 | */ |
558 | void | 562 | void |
559 | GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, | 563 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
560 | GNUNET_CONFIGURATION_Iterator iter, | 564 | GNUNET_CONFIGURATION_Iterator iter, |
561 | void *iter_cls) | 565 | void *iter_cls) |
562 | { | 566 | { |
563 | struct ConfigSection *spos; | 567 | struct ConfigSection *spos; |
564 | struct ConfigEntry *epos; | 568 | struct ConfigEntry *epos; |
@@ -566,7 +570,7 @@ GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
566 | for (spos = cfg->sections; NULL != spos; spos = spos->next) | 570 | for (spos = cfg->sections; NULL != spos; spos = spos->next) |
567 | for (epos = spos->entries; NULL != epos; epos = epos->next) | 571 | for (epos = spos->entries; NULL != epos; epos = epos->next) |
568 | if (NULL != epos->val) | 572 | if (NULL != epos->val) |
569 | iter(iter_cls, spos->name, epos->key, epos->val); | 573 | iter (iter_cls, spos->name, epos->key, epos->val); |
570 | } | 574 | } |
571 | 575 | ||
572 | 576 | ||
@@ -579,7 +583,7 @@ GNUNET_CONFIGURATION_iterate(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
579 | * @param iter_cls closure for @a iter | 583 | * @param iter_cls closure for @a iter |
580 | */ | 584 | */ |
581 | void | 585 | void |
582 | GNUNET_CONFIGURATION_iterate_section_values( | 586 | GNUNET_CONFIGURATION_iterate_section_values ( |
583 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 587 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
584 | const char *section, | 588 | const char *section, |
585 | GNUNET_CONFIGURATION_Iterator iter, | 589 | GNUNET_CONFIGURATION_Iterator iter, |
@@ -589,13 +593,13 @@ GNUNET_CONFIGURATION_iterate_section_values( | |||
589 | struct ConfigEntry *epos; | 593 | struct ConfigEntry *epos; |
590 | 594 | ||
591 | spos = cfg->sections; | 595 | spos = cfg->sections; |
592 | while ((spos != NULL) && (0 != strcasecmp(spos->name, section))) | 596 | while ((spos != NULL) && (0 != strcasecmp (spos->name, section))) |
593 | spos = spos->next; | 597 | spos = spos->next; |
594 | if (NULL == spos) | 598 | if (NULL == spos) |
595 | return; | 599 | return; |
596 | for (epos = spos->entries; NULL != epos; epos = epos->next) | 600 | for (epos = spos->entries; NULL != epos; epos = epos->next) |
597 | if (NULL != epos->val) | 601 | if (NULL != epos->val) |
598 | iter(iter_cls, spos->name, epos->key, epos->val); | 602 | iter (iter_cls, spos->name, epos->key, epos->val); |
599 | } | 603 | } |
600 | 604 | ||
601 | 605 | ||
@@ -607,7 +611,7 @@ GNUNET_CONFIGURATION_iterate_section_values( | |||
607 | * @param iter_cls closure for @a iter | 611 | * @param iter_cls closure for @a iter |
608 | */ | 612 | */ |
609 | void | 613 | void |
610 | GNUNET_CONFIGURATION_iterate_sections( | 614 | GNUNET_CONFIGURATION_iterate_sections ( |
611 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 615 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
612 | GNUNET_CONFIGURATION_Section_Iterator iter, | 616 | GNUNET_CONFIGURATION_Section_Iterator iter, |
613 | void *iter_cls) | 617 | void *iter_cls) |
@@ -617,11 +621,11 @@ GNUNET_CONFIGURATION_iterate_sections( | |||
617 | 621 | ||
618 | next = cfg->sections; | 622 | next = cfg->sections; |
619 | while (next != NULL) | 623 | while (next != NULL) |
620 | { | 624 | { |
621 | spos = next; | 625 | spos = next; |
622 | next = spos->next; | 626 | next = spos->next; |
623 | iter(iter_cls, spos->name); | 627 | iter (iter_cls, spos->name); |
624 | } | 628 | } |
625 | } | 629 | } |
626 | 630 | ||
627 | 631 | ||
@@ -632,8 +636,8 @@ GNUNET_CONFIGURATION_iterate_sections( | |||
632 | * @param section name of the section to remove | 636 | * @param section name of the section to remove |
633 | */ | 637 | */ |
634 | void | 638 | void |
635 | GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, | 639 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, |
636 | const char *section) | 640 | const char *section) |
637 | { | 641 | { |
638 | struct ConfigSection *spos; | 642 | struct ConfigSection *spos; |
639 | struct ConfigSection *prev; | 643 | struct ConfigSection *prev; |
@@ -642,28 +646,28 @@ GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
642 | prev = NULL; | 646 | prev = NULL; |
643 | spos = cfg->sections; | 647 | spos = cfg->sections; |
644 | while (NULL != spos) | 648 | while (NULL != spos) |
649 | { | ||
650 | if (0 == strcasecmp (section, spos->name)) | ||
645 | { | 651 | { |
646 | if (0 == strcasecmp(section, spos->name)) | 652 | if (NULL == prev) |
647 | { | 653 | cfg->sections = spos->next; |
648 | if (NULL == prev) | 654 | else |
649 | cfg->sections = spos->next; | 655 | prev->next = spos->next; |
650 | else | 656 | while (NULL != (ent = spos->entries)) |
651 | prev->next = spos->next; | 657 | { |
652 | while (NULL != (ent = spos->entries)) | 658 | spos->entries = ent->next; |
653 | { | 659 | GNUNET_free (ent->key); |
654 | spos->entries = ent->next; | 660 | GNUNET_free_non_null (ent->val); |
655 | GNUNET_free(ent->key); | 661 | GNUNET_free (ent); |
656 | GNUNET_free_non_null(ent->val); | 662 | cfg->dirty = GNUNET_YES; |
657 | GNUNET_free(ent); | 663 | } |
658 | cfg->dirty = GNUNET_YES; | 664 | GNUNET_free (spos->name); |
659 | } | 665 | GNUNET_free (spos); |
660 | GNUNET_free(spos->name); | 666 | return; |
661 | GNUNET_free(spos); | ||
662 | return; | ||
663 | } | ||
664 | prev = spos; | ||
665 | spos = spos->next; | ||
666 | } | 667 | } |
668 | prev = spos; | ||
669 | spos = spos->next; | ||
670 | } | ||
667 | } | 671 | } |
668 | 672 | ||
669 | 673 | ||
@@ -677,14 +681,14 @@ GNUNET_CONFIGURATION_remove_section(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
677 | * @param value value to copy | 681 | * @param value value to copy |
678 | */ | 682 | */ |
679 | static void | 683 | static void |
680 | copy_entry(void *cls, | 684 | copy_entry (void *cls, |
681 | const char *section, | 685 | const char *section, |
682 | const char *option, | 686 | const char *option, |
683 | const char *value) | 687 | const char *value) |
684 | { | 688 | { |
685 | struct GNUNET_CONFIGURATION_Handle *dst = cls; | 689 | struct GNUNET_CONFIGURATION_Handle *dst = cls; |
686 | 690 | ||
687 | GNUNET_CONFIGURATION_set_value_string(dst, section, option, value); | 691 | GNUNET_CONFIGURATION_set_value_string (dst, section, option, value); |
688 | } | 692 | } |
689 | 693 | ||
690 | 694 | ||
@@ -695,12 +699,12 @@ copy_entry(void *cls, | |||
695 | * @return duplicate configuration | 699 | * @return duplicate configuration |
696 | */ | 700 | */ |
697 | struct GNUNET_CONFIGURATION_Handle * | 701 | struct GNUNET_CONFIGURATION_Handle * |
698 | GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg) | 702 | GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) |
699 | { | 703 | { |
700 | struct GNUNET_CONFIGURATION_Handle *ret; | 704 | struct GNUNET_CONFIGURATION_Handle *ret; |
701 | 705 | ||
702 | ret = GNUNET_CONFIGURATION_create(); | 706 | ret = GNUNET_CONFIGURATION_create (); |
703 | GNUNET_CONFIGURATION_iterate(cfg, ©_entry, ret); | 707 | GNUNET_CONFIGURATION_iterate (cfg, ©_entry, ret); |
704 | return ret; | 708 | return ret; |
705 | } | 709 | } |
706 | 710 | ||
@@ -713,13 +717,13 @@ GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
713 | * @return matching entry, NULL if not found | 717 | * @return matching entry, NULL if not found |
714 | */ | 718 | */ |
715 | static struct ConfigSection * | 719 | static struct ConfigSection * |
716 | find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, | 720 | find_section (const struct GNUNET_CONFIGURATION_Handle *cfg, |
717 | const char *section) | 721 | const char *section) |
718 | { | 722 | { |
719 | struct ConfigSection *pos; | 723 | struct ConfigSection *pos; |
720 | 724 | ||
721 | pos = cfg->sections; | 725 | pos = cfg->sections; |
722 | while ((pos != NULL) && (0 != strcasecmp(section, pos->name))) | 726 | while ((pos != NULL) && (0 != strcasecmp (section, pos->name))) |
723 | pos = pos->next; | 727 | pos = pos->next; |
724 | return pos; | 728 | return pos; |
725 | } | 729 | } |
@@ -734,17 +738,17 @@ find_section(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
734 | * @return matching entry, NULL if not found | 738 | * @return matching entry, NULL if not found |
735 | */ | 739 | */ |
736 | static struct ConfigEntry * | 740 | static struct ConfigEntry * |
737 | find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, | 741 | find_entry (const struct GNUNET_CONFIGURATION_Handle *cfg, |
738 | const char *section, | 742 | const char *section, |
739 | const char *key) | 743 | const char *key) |
740 | { | 744 | { |
741 | struct ConfigSection *sec; | 745 | struct ConfigSection *sec; |
742 | struct ConfigEntry *pos; | 746 | struct ConfigEntry *pos; |
743 | 747 | ||
744 | if (NULL == (sec = find_section(cfg, section))) | 748 | if (NULL == (sec = find_section (cfg, section))) |
745 | return NULL; | 749 | return NULL; |
746 | pos = sec->entries; | 750 | pos = sec->entries; |
747 | while ((pos != NULL) && (0 != strcasecmp(key, pos->key))) | 751 | while ((pos != NULL) && (0 != strcasecmp (key, pos->key))) |
748 | pos = pos->next; | 752 | pos = pos->next; |
749 | return pos; | 753 | return pos; |
750 | } | 754 | } |
@@ -761,19 +765,19 @@ find_entry(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
761 | * @param value value to copy (of the default conf.) | 765 | * @param value value to copy (of the default conf.) |
762 | */ | 766 | */ |
763 | static void | 767 | static void |
764 | compare_entries(void *cls, | 768 | compare_entries (void *cls, |
765 | const char *section, | 769 | const char *section, |
766 | const char *option, | 770 | const char *option, |
767 | const char *value) | 771 | const char *value) |
768 | { | 772 | { |
769 | struct DiffHandle *dh = cls; | 773 | struct DiffHandle *dh = cls; |
770 | struct ConfigEntry *entNew; | 774 | struct ConfigEntry *entNew; |
771 | 775 | ||
772 | entNew = find_entry(dh->cfg_default, section, option); | 776 | entNew = find_entry (dh->cfg_default, section, option); |
773 | if ((NULL != entNew) && (NULL != entNew->val) && | 777 | if ((NULL != entNew) && (NULL != entNew->val) && |
774 | (0 == strcmp(entNew->val, value))) | 778 | (0 == strcmp (entNew->val, value))) |
775 | return; | 779 | return; |
776 | GNUNET_CONFIGURATION_set_value_string(dh->cfgDiff, section, option, value); | 780 | GNUNET_CONFIGURATION_set_value_string (dh->cfgDiff, section, option, value); |
777 | } | 781 | } |
778 | 782 | ||
779 | 783 | ||
@@ -785,15 +789,15 @@ compare_entries(void *cls, | |||
785 | * @return configuration with only the differences, never NULL | 789 | * @return configuration with only the differences, never NULL |
786 | */ | 790 | */ |
787 | struct GNUNET_CONFIGURATION_Handle * | 791 | struct GNUNET_CONFIGURATION_Handle * |
788 | GNUNET_CONFIGURATION_get_diff( | 792 | GNUNET_CONFIGURATION_get_diff ( |
789 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, | 793 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, |
790 | const struct GNUNET_CONFIGURATION_Handle *cfg_new) | 794 | const struct GNUNET_CONFIGURATION_Handle *cfg_new) |
791 | { | 795 | { |
792 | struct DiffHandle diffHandle; | 796 | struct DiffHandle diffHandle; |
793 | 797 | ||
794 | diffHandle.cfgDiff = GNUNET_CONFIGURATION_create(); | 798 | diffHandle.cfgDiff = GNUNET_CONFIGURATION_create (); |
795 | diffHandle.cfg_default = cfg_default; | 799 | diffHandle.cfg_default = cfg_default; |
796 | GNUNET_CONFIGURATION_iterate(cfg_new, &compare_entries, &diffHandle); | 800 | GNUNET_CONFIGURATION_iterate (cfg_new, &compare_entries, &diffHandle); |
797 | return diffHandle.cfgDiff; | 801 | return diffHandle.cfgDiff; |
798 | } | 802 | } |
799 | 803 | ||
@@ -807,7 +811,7 @@ GNUNET_CONFIGURATION_get_diff( | |||
807 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 811 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
808 | */ | 812 | */ |
809 | int | 813 | int |
810 | GNUNET_CONFIGURATION_write_diffs( | 814 | GNUNET_CONFIGURATION_write_diffs ( |
811 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, | 815 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, |
812 | const struct GNUNET_CONFIGURATION_Handle *cfg_new, | 816 | const struct GNUNET_CONFIGURATION_Handle *cfg_new, |
813 | const char *filename) | 817 | const char *filename) |
@@ -815,9 +819,9 @@ GNUNET_CONFIGURATION_write_diffs( | |||
815 | int ret; | 819 | int ret; |
816 | struct GNUNET_CONFIGURATION_Handle *diff; | 820 | struct GNUNET_CONFIGURATION_Handle *diff; |
817 | 821 | ||
818 | diff = GNUNET_CONFIGURATION_get_diff(cfg_default, cfg_new); | 822 | diff = GNUNET_CONFIGURATION_get_diff (cfg_default, cfg_new); |
819 | ret = GNUNET_CONFIGURATION_write(diff, filename); | 823 | ret = GNUNET_CONFIGURATION_write (diff, filename); |
820 | GNUNET_CONFIGURATION_destroy(diff); | 824 | GNUNET_CONFIGURATION_destroy (diff); |
821 | return ret; | 825 | return ret; |
822 | } | 826 | } |
823 | 827 | ||
@@ -831,42 +835,42 @@ GNUNET_CONFIGURATION_write_diffs( | |||
831 | * @param value value to set | 835 | * @param value value to set |
832 | */ | 836 | */ |
833 | void | 837 | void |
834 | GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, | 838 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, |
835 | const char *section, | 839 | const char *section, |
836 | const char *option, | 840 | const char *option, |
837 | const char *value) | 841 | const char *value) |
838 | { | 842 | { |
839 | struct ConfigSection *sec; | 843 | struct ConfigSection *sec; |
840 | struct ConfigEntry *e; | 844 | struct ConfigEntry *e; |
841 | char *nv; | 845 | char *nv; |
842 | 846 | ||
843 | e = find_entry(cfg, section, option); | 847 | e = find_entry (cfg, section, option); |
844 | if (NULL != e) | 848 | if (NULL != e) |
849 | { | ||
850 | if (NULL == value) | ||
845 | { | 851 | { |
846 | if (NULL == value) | 852 | GNUNET_free_non_null (e->val); |
847 | { | 853 | e->val = NULL; |
848 | GNUNET_free_non_null(e->val); | ||
849 | e->val = NULL; | ||
850 | } | ||
851 | else | ||
852 | { | ||
853 | nv = GNUNET_strdup(value); | ||
854 | GNUNET_free_non_null(e->val); | ||
855 | e->val = nv; | ||
856 | } | ||
857 | return; | ||
858 | } | 854 | } |
859 | sec = find_section(cfg, section); | 855 | else |
860 | if (sec == NULL) | ||
861 | { | 856 | { |
862 | sec = GNUNET_new(struct ConfigSection); | 857 | nv = GNUNET_strdup (value); |
863 | sec->name = GNUNET_strdup(section); | 858 | GNUNET_free_non_null (e->val); |
864 | sec->next = cfg->sections; | 859 | e->val = nv; |
865 | cfg->sections = sec; | ||
866 | } | 860 | } |
867 | e = GNUNET_new(struct ConfigEntry); | 861 | return; |
868 | e->key = GNUNET_strdup(option); | 862 | } |
869 | e->val = GNUNET_strdup(value); | 863 | sec = find_section (cfg, section); |
864 | if (sec == NULL) | ||
865 | { | ||
866 | sec = GNUNET_new (struct ConfigSection); | ||
867 | sec->name = GNUNET_strdup (section); | ||
868 | sec->next = cfg->sections; | ||
869 | cfg->sections = sec; | ||
870 | } | ||
871 | e = GNUNET_new (struct ConfigEntry); | ||
872 | e->key = GNUNET_strdup (option); | ||
873 | e->val = GNUNET_strdup (value); | ||
870 | e->next = sec->entries; | 874 | e->next = sec->entries; |
871 | sec->entries = e; | 875 | sec->entries = e; |
872 | } | 876 | } |
@@ -881,15 +885,15 @@ GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
881 | * @param number value to set | 885 | * @param number value to set |
882 | */ | 886 | */ |
883 | void | 887 | void |
884 | GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, | 888 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, |
885 | const char *section, | 889 | const char *section, |
886 | const char *option, | 890 | const char *option, |
887 | unsigned long long number) | 891 | unsigned long long number) |
888 | { | 892 | { |
889 | char s[64]; | 893 | char s[64]; |
890 | 894 | ||
891 | GNUNET_snprintf(s, 64, "%llu", number); | 895 | GNUNET_snprintf (s, 64, "%llu", number); |
892 | GNUNET_CONFIGURATION_set_value_string(cfg, section, option, s); | 896 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); |
893 | } | 897 | } |
894 | 898 | ||
895 | 899 | ||
@@ -903,7 +907,7 @@ GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, | |||
903 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 907 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
904 | */ | 908 | */ |
905 | int | 909 | int |
906 | GNUNET_CONFIGURATION_get_value_number( | 910 | GNUNET_CONFIGURATION_get_value_number ( |
907 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 911 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
908 | const char *section, | 912 | const char *section, |
909 | const char *option, | 913 | const char *option, |
@@ -912,11 +916,11 @@ GNUNET_CONFIGURATION_get_value_number( | |||
912 | struct ConfigEntry *e; | 916 | struct ConfigEntry *e; |
913 | char dummy[2]; | 917 | char dummy[2]; |
914 | 918 | ||
915 | if (NULL == (e = find_entry(cfg, section, option))) | 919 | if (NULL == (e = find_entry (cfg, section, option))) |
916 | return GNUNET_SYSERR; | 920 | return GNUNET_SYSERR; |
917 | if (NULL == e->val) | 921 | if (NULL == e->val) |
918 | return GNUNET_SYSERR; | 922 | return GNUNET_SYSERR; |
919 | if (1 != sscanf(e->val, "%llu%1s", number, dummy)) | 923 | if (1 != sscanf (e->val, "%llu%1s", number, dummy)) |
920 | return GNUNET_SYSERR; | 924 | return GNUNET_SYSERR; |
921 | return GNUNET_OK; | 925 | return GNUNET_OK; |
922 | } | 926 | } |
@@ -932,7 +936,7 @@ GNUNET_CONFIGURATION_get_value_number( | |||
932 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 936 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
933 | */ | 937 | */ |
934 | int | 938 | int |
935 | GNUNET_CONFIGURATION_get_value_float( | 939 | GNUNET_CONFIGURATION_get_value_float ( |
936 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 940 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
937 | const char *section, | 941 | const char *section, |
938 | const char *option, | 942 | const char *option, |
@@ -941,11 +945,11 @@ GNUNET_CONFIGURATION_get_value_float( | |||
941 | struct ConfigEntry *e; | 945 | struct ConfigEntry *e; |
942 | char dummy[2]; | 946 | char dummy[2]; |
943 | 947 | ||
944 | if (NULL == (e = find_entry(cfg, section, option))) | 948 | if (NULL == (e = find_entry (cfg, section, option))) |
945 | return GNUNET_SYSERR; | 949 | return GNUNET_SYSERR; |
946 | if (NULL == e->val) | 950 | if (NULL == e->val) |
947 | return GNUNET_SYSERR; | 951 | return GNUNET_SYSERR; |
948 | if (1 != sscanf(e->val, "%f%1s", number, dummy)) | 952 | if (1 != sscanf (e->val, "%f%1s", number, dummy)) |
949 | return GNUNET_SYSERR; | 953 | return GNUNET_SYSERR; |
950 | return GNUNET_OK; | 954 | return GNUNET_OK; |
951 | } | 955 | } |
@@ -961,7 +965,7 @@ GNUNET_CONFIGURATION_get_value_float( | |||
961 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 965 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
962 | */ | 966 | */ |
963 | int | 967 | int |
964 | GNUNET_CONFIGURATION_get_value_time( | 968 | GNUNET_CONFIGURATION_get_value_time ( |
965 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 969 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
966 | const char *section, | 970 | const char *section, |
967 | const char *option, | 971 | const char *option, |
@@ -970,16 +974,16 @@ GNUNET_CONFIGURATION_get_value_time( | |||
970 | struct ConfigEntry *e; | 974 | struct ConfigEntry *e; |
971 | int ret; | 975 | int ret; |
972 | 976 | ||
973 | if (NULL == (e = find_entry(cfg, section, option))) | 977 | if (NULL == (e = find_entry (cfg, section, option))) |
974 | return GNUNET_SYSERR; | 978 | return GNUNET_SYSERR; |
975 | if (NULL == e->val) | 979 | if (NULL == e->val) |
976 | return GNUNET_SYSERR; | 980 | return GNUNET_SYSERR; |
977 | ret = GNUNET_STRINGS_fancy_time_to_relative(e->val, time); | 981 | ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, time); |
978 | if (GNUNET_OK != ret) | 982 | if (GNUNET_OK != ret) |
979 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 983 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
980 | section, | 984 | section, |
981 | option, | 985 | option, |
982 | _("Not a valid relative time specification")); | 986 | _ ("Not a valid relative time specification")); |
983 | return ret; | 987 | return ret; |
984 | } | 988 | } |
985 | 989 | ||
@@ -994,7 +998,7 @@ GNUNET_CONFIGURATION_get_value_time( | |||
994 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 998 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
995 | */ | 999 | */ |
996 | int | 1000 | int |
997 | GNUNET_CONFIGURATION_get_value_size( | 1001 | GNUNET_CONFIGURATION_get_value_size ( |
998 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1002 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
999 | const char *section, | 1003 | const char *section, |
1000 | const char *option, | 1004 | const char *option, |
@@ -1002,11 +1006,11 @@ GNUNET_CONFIGURATION_get_value_size( | |||
1002 | { | 1006 | { |
1003 | struct ConfigEntry *e; | 1007 | struct ConfigEntry *e; |
1004 | 1008 | ||
1005 | if (NULL == (e = find_entry(cfg, section, option))) | 1009 | if (NULL == (e = find_entry (cfg, section, option))) |
1006 | return GNUNET_SYSERR; | 1010 | return GNUNET_SYSERR; |
1007 | if (NULL == e->val) | 1011 | if (NULL == e->val) |
1008 | return GNUNET_SYSERR; | 1012 | return GNUNET_SYSERR; |
1009 | return GNUNET_STRINGS_fancy_size_to_bytes(e->val, size); | 1013 | return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size); |
1010 | } | 1014 | } |
1011 | 1015 | ||
1012 | 1016 | ||
@@ -1021,7 +1025,7 @@ GNUNET_CONFIGURATION_get_value_size( | |||
1021 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1025 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1022 | */ | 1026 | */ |
1023 | int | 1027 | int |
1024 | GNUNET_CONFIGURATION_get_value_string( | 1028 | GNUNET_CONFIGURATION_get_value_string ( |
1025 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1029 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1026 | const char *section, | 1030 | const char *section, |
1027 | const char *option, | 1031 | const char *option, |
@@ -1029,12 +1033,12 @@ GNUNET_CONFIGURATION_get_value_string( | |||
1029 | { | 1033 | { |
1030 | struct ConfigEntry *e; | 1034 | struct ConfigEntry *e; |
1031 | 1035 | ||
1032 | if ((NULL == (e = find_entry(cfg, section, option))) || (NULL == e->val)) | 1036 | if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val)) |
1033 | { | 1037 | { |
1034 | *value = NULL; | 1038 | *value = NULL; |
1035 | return GNUNET_SYSERR; | 1039 | return GNUNET_SYSERR; |
1036 | } | 1040 | } |
1037 | *value = GNUNET_strdup(e->val); | 1041 | *value = GNUNET_strdup (e->val); |
1038 | return GNUNET_OK; | 1042 | return GNUNET_OK; |
1039 | } | 1043 | } |
1040 | 1044 | ||
@@ -1052,7 +1056,7 @@ GNUNET_CONFIGURATION_get_value_string( | |||
1052 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1056 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1053 | */ | 1057 | */ |
1054 | int | 1058 | int |
1055 | GNUNET_CONFIGURATION_get_value_choice( | 1059 | GNUNET_CONFIGURATION_get_value_choice ( |
1056 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1060 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1057 | const char *section, | 1061 | const char *section, |
1058 | const char *option, | 1062 | const char *option, |
@@ -1062,21 +1066,21 @@ GNUNET_CONFIGURATION_get_value_choice( | |||
1062 | struct ConfigEntry *e; | 1066 | struct ConfigEntry *e; |
1063 | unsigned int i; | 1067 | unsigned int i; |
1064 | 1068 | ||
1065 | if (NULL == (e = find_entry(cfg, section, option))) | 1069 | if (NULL == (e = find_entry (cfg, section, option))) |
1066 | return GNUNET_SYSERR; | 1070 | return GNUNET_SYSERR; |
1067 | for (i = 0; NULL != choices[i]; i++) | 1071 | for (i = 0; NULL != choices[i]; i++) |
1068 | if (0 == strcasecmp(choices[i], e->val)) | 1072 | if (0 == strcasecmp (choices[i], e->val)) |
1069 | break; | 1073 | break; |
1070 | if (NULL == choices[i]) | 1074 | if (NULL == choices[i]) |
1071 | { | 1075 | { |
1072 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1076 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1073 | _("Configuration value '%s' for '%s'" | 1077 | _ ("Configuration value '%s' for '%s'" |
1074 | " in section '%s' is not in set of legal choices\n"), | 1078 | " in section '%s' is not in set of legal choices\n"), |
1075 | e->val, | 1079 | e->val, |
1076 | option, | 1080 | option, |
1077 | section); | 1081 | section); |
1078 | return GNUNET_SYSERR; | 1082 | return GNUNET_SYSERR; |
1079 | } | 1083 | } |
1080 | *value = choices[i]; | 1084 | *value = choices[i]; |
1081 | return GNUNET_OK; | 1085 | return GNUNET_OK; |
1082 | } | 1086 | } |
@@ -1095,11 +1099,11 @@ GNUNET_CONFIGURATION_get_value_choice( | |||
1095 | * #GNUNET_SYSERR on decoding error | 1099 | * #GNUNET_SYSERR on decoding error |
1096 | */ | 1100 | */ |
1097 | int | 1101 | int |
1098 | GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, | 1102 | GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1099 | const char *section, | 1103 | const char *section, |
1100 | const char *option, | 1104 | const char *option, |
1101 | void *buf, | 1105 | void *buf, |
1102 | size_t buf_size) | 1106 | size_t buf_size) |
1103 | { | 1107 | { |
1104 | char *enc; | 1108 | char *enc; |
1105 | int res; | 1109 | int res; |
@@ -1107,21 +1111,21 @@ GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1107 | 1111 | ||
1108 | if (GNUNET_OK != | 1112 | if (GNUNET_OK != |
1109 | (res = | 1113 | (res = |
1110 | GNUNET_CONFIGURATION_get_value_string(cfg, section, option, &enc))) | 1114 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &enc))) |
1111 | return res; | 1115 | return res; |
1112 | data_size = (strlen(enc) * 5) / 8; | 1116 | data_size = (strlen (enc) * 5) / 8; |
1113 | if (data_size != buf_size) | 1117 | if (data_size != buf_size) |
1114 | { | 1118 | { |
1115 | GNUNET_free(enc); | 1119 | GNUNET_free (enc); |
1116 | return GNUNET_SYSERR; | 1120 | return GNUNET_SYSERR; |
1117 | } | 1121 | } |
1118 | if (GNUNET_OK != | 1122 | if (GNUNET_OK != |
1119 | GNUNET_STRINGS_string_to_data(enc, strlen(enc), buf, buf_size)) | 1123 | GNUNET_STRINGS_string_to_data (enc, strlen (enc), buf, buf_size)) |
1120 | { | 1124 | { |
1121 | GNUNET_free(enc); | 1125 | GNUNET_free (enc); |
1122 | return GNUNET_SYSERR; | 1126 | return GNUNET_SYSERR; |
1123 | } | 1127 | } |
1124 | GNUNET_free(enc); | 1128 | GNUNET_free (enc); |
1125 | return GNUNET_OK; | 1129 | return GNUNET_OK; |
1126 | } | 1130 | } |
1127 | 1131 | ||
@@ -1135,13 +1139,13 @@ GNUNET_CONFIGURATION_get_data(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1135 | * @return #GNUNET_YES if so, #GNUNET_NO if not. | 1139 | * @return #GNUNET_YES if so, #GNUNET_NO if not. |
1136 | */ | 1140 | */ |
1137 | int | 1141 | int |
1138 | GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, | 1142 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1139 | const char *section, | 1143 | const char *section, |
1140 | const char *option) | 1144 | const char *option) |
1141 | { | 1145 | { |
1142 | struct ConfigEntry *e; | 1146 | struct ConfigEntry *e; |
1143 | 1147 | ||
1144 | if ((NULL == (e = find_entry(cfg, section, option))) || (NULL == e->val)) | 1148 | if ((NULL == (e = find_entry (cfg, section, option))) || (NULL == e->val)) |
1145 | return GNUNET_NO; | 1149 | return GNUNET_NO; |
1146 | return GNUNET_YES; | 1150 | return GNUNET_YES; |
1147 | } | 1151 | } |
@@ -1163,9 +1167,9 @@ GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1163 | * @return $-expanded string | 1167 | * @return $-expanded string |
1164 | */ | 1168 | */ |
1165 | static char * | 1169 | static char * |
1166 | expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, | 1170 | expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1167 | char *orig, | 1171 | char *orig, |
1168 | unsigned int depth) | 1172 | unsigned int depth) |
1169 | { | 1173 | { |
1170 | char *prefix; | 1174 | char *prefix; |
1171 | char *result; | 1175 | char *result; |
@@ -1182,129 +1186,129 @@ expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1182 | if (NULL == orig) | 1186 | if (NULL == orig) |
1183 | return NULL; | 1187 | return NULL; |
1184 | if (depth > 128) | 1188 | if (depth > 128) |
1185 | { | 1189 | { |
1186 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1190 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1187 | _( | 1191 | _ ( |
1188 | "Recursive expansion suspected, aborting $-expansion for term `%s'\n"), | 1192 | "Recursive expansion suspected, aborting $-expansion for term `%s'\n"), |
1189 | orig); | 1193 | orig); |
1190 | return orig; | 1194 | return orig; |
1191 | } | 1195 | } |
1192 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig); | 1196 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Asked to $-expand %s\n", orig); |
1193 | if ('$' != orig[0]) | 1197 | if ('$' != orig[0]) |
1194 | { | 1198 | { |
1195 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n"); | 1199 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Doesn't start with $ - not expanding\n"); |
1196 | return orig; | 1200 | return orig; |
1197 | } | 1201 | } |
1198 | erased_char = 0; | 1202 | erased_char = 0; |
1199 | erased_pos = NULL; | 1203 | erased_pos = NULL; |
1200 | if ('{' == orig[1]) | 1204 | if ('{' == orig[1]) |
1205 | { | ||
1206 | start = &orig[2]; | ||
1207 | lopen = 1; | ||
1208 | end = &orig[1]; | ||
1209 | while (lopen > 0) | ||
1201 | { | 1210 | { |
1202 | start = &orig[2]; | 1211 | end++; |
1203 | lopen = 1; | 1212 | switch (*end) |
1204 | end = &orig[1]; | 1213 | { |
1205 | while (lopen > 0) | 1214 | case '}': |
1206 | { | 1215 | lopen--; |
1207 | end++; | 1216 | break; |
1208 | switch (*end) | 1217 | |
1209 | { | 1218 | case '{': |
1210 | case '}': | 1219 | lopen++; |
1211 | lopen--; | 1220 | break; |
1212 | break; | 1221 | |
1213 | 1222 | case '\0': | |
1214 | case '{': | 1223 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1215 | lopen++; | 1224 | _ ("Missing closing `%s' in option `%s'\n"), |
1216 | break; | 1225 | "}", |
1217 | 1226 | orig); | |
1218 | case '\0': | 1227 | return orig; |
1219 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1228 | |
1220 | _("Missing closing `%s' in option `%s'\n"), | 1229 | default: |
1221 | "}", | 1230 | break; |
1222 | orig); | 1231 | } |
1223 | return orig; | ||
1224 | |||
1225 | default: | ||
1226 | break; | ||
1227 | } | ||
1228 | } | ||
1229 | erased_char = *end; | ||
1230 | erased_pos = end; | ||
1231 | *end = '\0'; | ||
1232 | post = end + 1; | ||
1233 | def = strchr(orig, ':'); | ||
1234 | if (NULL != def) | ||
1235 | { | ||
1236 | *def = '\0'; | ||
1237 | def++; | ||
1238 | if (('-' == *def) || ('=' == *def)) | ||
1239 | def++; | ||
1240 | def = GNUNET_strdup(def); | ||
1241 | } | ||
1242 | } | 1232 | } |
1233 | erased_char = *end; | ||
1234 | erased_pos = end; | ||
1235 | *end = '\0'; | ||
1236 | post = end + 1; | ||
1237 | def = strchr (orig, ':'); | ||
1238 | if (NULL != def) | ||
1239 | { | ||
1240 | *def = '\0'; | ||
1241 | def++; | ||
1242 | if (('-' == *def) || ('=' == *def)) | ||
1243 | def++; | ||
1244 | def = GNUNET_strdup (def); | ||
1245 | } | ||
1246 | } | ||
1243 | else | 1247 | else |
1248 | { | ||
1249 | int i; | ||
1250 | |||
1251 | start = &orig[1]; | ||
1252 | def = NULL; | ||
1253 | i = 0; | ||
1254 | while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') && | ||
1255 | (orig[i] != ' ')) | ||
1256 | i++; | ||
1257 | if (orig[i] == '\0') | ||
1244 | { | 1258 | { |
1245 | int i; | 1259 | post = ""; |
1246 | 1260 | } | |
1247 | start = &orig[1]; | 1261 | else |
1248 | def = NULL; | 1262 | { |
1249 | i = 0; | 1263 | erased_char = orig[i]; |
1250 | while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0') && | 1264 | erased_pos = &orig[i]; |
1251 | (orig[i] != ' ')) | 1265 | orig[i] = '\0'; |
1252 | i++; | 1266 | post = &orig[i + 1]; |
1253 | if (orig[i] == '\0') | ||
1254 | { | ||
1255 | post = ""; | ||
1256 | } | ||
1257 | else | ||
1258 | { | ||
1259 | erased_char = orig[i]; | ||
1260 | erased_pos = &orig[i]; | ||
1261 | orig[i] = '\0'; | ||
1262 | post = &orig[i + 1]; | ||
1263 | } | ||
1264 | } | 1267 | } |
1265 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1268 | } |
1266 | "Split into `%s' and `%s' with default %s\n", | 1269 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1267 | start, | 1270 | "Split into `%s' and `%s' with default %s\n", |
1268 | post, | 1271 | start, |
1269 | def); | 1272 | post, |
1273 | def); | ||
1270 | if (GNUNET_OK != | 1274 | if (GNUNET_OK != |
1271 | GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", start, &prefix)) | 1275 | GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", start, &prefix)) |
1276 | { | ||
1277 | if (NULL == (env = getenv (start))) | ||
1272 | { | 1278 | { |
1273 | if (NULL == (env = getenv(start))) | 1279 | /* try default */ |
1274 | { | 1280 | def = expand_dollar (cfg, def, depth + 1); |
1275 | /* try default */ | 1281 | env = def; |
1276 | def = expand_dollar(cfg, def, depth + 1); | ||
1277 | env = def; | ||
1278 | } | ||
1279 | if (NULL == env) | ||
1280 | { | ||
1281 | start = GNUNET_strdup(start); | ||
1282 | if (erased_pos) | ||
1283 | *erased_pos = erased_char; | ||
1284 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
1285 | _( | ||
1286 | "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"), | ||
1287 | start, | ||
1288 | orig); | ||
1289 | GNUNET_free(start); | ||
1290 | return orig; | ||
1291 | } | ||
1292 | prefix = GNUNET_strdup(env); | ||
1293 | } | 1282 | } |
1294 | prefix = GNUNET_CONFIGURATION_expand_dollar(cfg, prefix); | 1283 | if (NULL == env) |
1295 | if ((erased_pos) && ('}' != erased_char)) | ||
1296 | { | 1284 | { |
1297 | len = strlen(prefix) + 1; | 1285 | start = GNUNET_strdup (start); |
1298 | prefix = GNUNET_realloc(prefix, len + 1); | 1286 | if (erased_pos) |
1299 | prefix[len - 1] = erased_char; | 1287 | *erased_pos = erased_char; |
1300 | prefix[len] = '\0'; | 1288 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1289 | _ ( | ||
1290 | "Failed to expand `%s' in `%s' as it is neither found in [PATHS] nor defined as an environmental variable\n"), | ||
1291 | start, | ||
1292 | orig); | ||
1293 | GNUNET_free (start); | ||
1294 | return orig; | ||
1301 | } | 1295 | } |
1302 | result = GNUNET_malloc(strlen(prefix) + strlen(post) + 1); | 1296 | prefix = GNUNET_strdup (env); |
1303 | strcpy(result, prefix); | 1297 | } |
1304 | strcat(result, post); | 1298 | prefix = GNUNET_CONFIGURATION_expand_dollar (cfg, prefix); |
1305 | GNUNET_free_non_null(def); | 1299 | if ((erased_pos) && ('}' != erased_char)) |
1306 | GNUNET_free(prefix); | 1300 | { |
1307 | GNUNET_free(orig); | 1301 | len = strlen (prefix) + 1; |
1302 | prefix = GNUNET_realloc (prefix, len + 1); | ||
1303 | prefix[len - 1] = erased_char; | ||
1304 | prefix[len] = '\0'; | ||
1305 | } | ||
1306 | result = GNUNET_malloc (strlen (prefix) + strlen (post) + 1); | ||
1307 | strcpy (result, prefix); | ||
1308 | strcat (result, post); | ||
1309 | GNUNET_free_non_null (def); | ||
1310 | GNUNET_free (prefix); | ||
1311 | GNUNET_free (orig); | ||
1308 | return result; | 1312 | return result; |
1309 | } | 1313 | } |
1310 | 1314 | ||
@@ -1326,7 +1330,7 @@ expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1326 | * @return $-expanded string | 1330 | * @return $-expanded string |
1327 | */ | 1331 | */ |
1328 | char * | 1332 | char * |
1329 | GNUNET_CONFIGURATION_expand_dollar( | 1333 | GNUNET_CONFIGURATION_expand_dollar ( |
1330 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1334 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1331 | char *orig) | 1335 | char *orig) |
1332 | { | 1336 | { |
@@ -1335,16 +1339,16 @@ GNUNET_CONFIGURATION_expand_dollar( | |||
1335 | size_t len; | 1339 | size_t len; |
1336 | 1340 | ||
1337 | for (i = 0; '\0' != orig[i]; i++) | 1341 | for (i = 0; '\0' != orig[i]; i++) |
1338 | { | 1342 | { |
1339 | if ('$' != orig[i]) | 1343 | if ('$' != orig[i]) |
1340 | continue; | 1344 | continue; |
1341 | dup = GNUNET_strdup(orig + i); | 1345 | dup = GNUNET_strdup (orig + i); |
1342 | dup = expand_dollar(cfg, dup, 0); | 1346 | dup = expand_dollar (cfg, dup, 0); |
1343 | len = strlen(dup) + 1; | 1347 | len = strlen (dup) + 1; |
1344 | orig = GNUNET_realloc(orig, i + len); | 1348 | orig = GNUNET_realloc (orig, i + len); |
1345 | GNUNET_memcpy(orig + i, dup, len); | 1349 | GNUNET_memcpy (orig + i, dup, len); |
1346 | GNUNET_free(dup); | 1350 | GNUNET_free (dup); |
1347 | } | 1351 | } |
1348 | return orig; | 1352 | return orig; |
1349 | } | 1353 | } |
1350 | 1354 | ||
@@ -1360,7 +1364,7 @@ GNUNET_CONFIGURATION_expand_dollar( | |||
1360 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1364 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1361 | */ | 1365 | */ |
1362 | int | 1366 | int |
1363 | GNUNET_CONFIGURATION_get_value_filename( | 1367 | GNUNET_CONFIGURATION_get_value_filename ( |
1364 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1368 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1365 | const char *section, | 1369 | const char *section, |
1366 | const char *option, | 1370 | const char *option, |
@@ -1369,15 +1373,15 @@ GNUNET_CONFIGURATION_get_value_filename( | |||
1369 | char *tmp; | 1373 | char *tmp; |
1370 | 1374 | ||
1371 | if (GNUNET_OK != | 1375 | if (GNUNET_OK != |
1372 | GNUNET_CONFIGURATION_get_value_string(cfg, section, option, &tmp)) | 1376 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) |
1373 | { | 1377 | { |
1374 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n"); | 1378 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to retrieve filename\n"); |
1375 | *value = NULL; | 1379 | *value = NULL; |
1376 | return GNUNET_SYSERR; | 1380 | return GNUNET_SYSERR; |
1377 | } | 1381 | } |
1378 | tmp = GNUNET_CONFIGURATION_expand_dollar(cfg, tmp); | 1382 | tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp); |
1379 | *value = GNUNET_STRINGS_filename_expand(tmp); | 1383 | *value = GNUNET_STRINGS_filename_expand (tmp); |
1380 | GNUNET_free(tmp); | 1384 | GNUNET_free (tmp); |
1381 | if (*value == NULL) | 1385 | if (*value == NULL) |
1382 | return GNUNET_SYSERR; | 1386 | return GNUNET_SYSERR; |
1383 | return GNUNET_OK; | 1387 | return GNUNET_OK; |
@@ -1394,7 +1398,7 @@ GNUNET_CONFIGURATION_get_value_filename( | |||
1394 | * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR | 1398 | * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR |
1395 | */ | 1399 | */ |
1396 | int | 1400 | int |
1397 | GNUNET_CONFIGURATION_get_value_yesno( | 1401 | GNUNET_CONFIGURATION_get_value_yesno ( |
1398 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1402 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1399 | const char *section, | 1403 | const char *section, |
1400 | const char *option) | 1404 | const char *option) |
@@ -1404,7 +1408,7 @@ GNUNET_CONFIGURATION_get_value_yesno( | |||
1404 | int ret; | 1408 | int ret; |
1405 | 1409 | ||
1406 | ret = | 1410 | ret = |
1407 | GNUNET_CONFIGURATION_get_value_choice(cfg, section, option, yesno, &val); | 1411 | GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val); |
1408 | if (ret == GNUNET_SYSERR) | 1412 | if (ret == GNUNET_SYSERR) |
1409 | return ret; | 1413 | return ret; |
1410 | if (val == yesno[0]) | 1414 | if (val == yesno[0]) |
@@ -1424,7 +1428,7 @@ GNUNET_CONFIGURATION_get_value_yesno( | |||
1424 | * @return number of filenames iterated over, -1 on error | 1428 | * @return number of filenames iterated over, -1 on error |
1425 | */ | 1429 | */ |
1426 | int | 1430 | int |
1427 | GNUNET_CONFIGURATION_iterate_value_filenames( | 1431 | GNUNET_CONFIGURATION_iterate_value_filenames ( |
1428 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1432 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1429 | const char *section, | 1433 | const char *section, |
1430 | const char *option, | 1434 | const char *option, |
@@ -1438,55 +1442,55 @@ GNUNET_CONFIGURATION_iterate_value_filenames( | |||
1438 | int ret; | 1442 | int ret; |
1439 | 1443 | ||
1440 | if (GNUNET_OK != | 1444 | if (GNUNET_OK != |
1441 | GNUNET_CONFIGURATION_get_value_string(cfg, section, option, &list)) | 1445 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list)) |
1442 | return 0; | 1446 | return 0; |
1443 | GNUNET_assert(list != NULL); | 1447 | GNUNET_assert (list != NULL); |
1444 | ret = 0; | 1448 | ret = 0; |
1445 | pos = list; | 1449 | pos = list; |
1446 | while (1) | 1450 | while (1) |
1451 | { | ||
1452 | while (pos[0] == ' ') | ||
1453 | pos++; | ||
1454 | if (strlen (pos) == 0) | ||
1455 | break; | ||
1456 | end = pos + 1; | ||
1457 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1447 | { | 1458 | { |
1448 | while (pos[0] == ' ') | 1459 | if (end[0] == '\\') |
1449 | pos++; | 1460 | { |
1450 | if (strlen(pos) == 0) | 1461 | switch (end[1]) |
1451 | break; | ||
1452 | end = pos + 1; | ||
1453 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1454 | { | 1462 | { |
1455 | if (end[0] == '\\') | 1463 | case '\\': |
1456 | { | 1464 | case ' ': |
1457 | switch (end[1]) | 1465 | memmove (end, &end[1], strlen (&end[1]) + 1); |
1458 | { | 1466 | |
1459 | case '\\': | 1467 | case '\0': |
1460 | case ' ': | 1468 | /* illegal, but just keep it */ |
1461 | memmove(end, &end[1], strlen(&end[1]) + 1); | 1469 | break; |
1462 | 1470 | ||
1463 | case '\0': | 1471 | default: |
1464 | /* illegal, but just keep it */ | 1472 | /* illegal, but just ignore that there was a '/' */ |
1465 | break; | 1473 | break; |
1466 | |||
1467 | default: | ||
1468 | /* illegal, but just ignore that there was a '/' */ | ||
1469 | break; | ||
1470 | } | ||
1471 | } | ||
1472 | end++; | ||
1473 | } | ||
1474 | old = end[0]; | ||
1475 | end[0] = '\0'; | ||
1476 | if (strlen(pos) > 0) | ||
1477 | { | ||
1478 | ret++; | ||
1479 | if ((cb != NULL) && (GNUNET_OK != cb(cb_cls, pos))) | ||
1480 | { | ||
1481 | ret = GNUNET_SYSERR; | ||
1482 | break; | ||
1483 | } | ||
1484 | } | 1474 | } |
1485 | if (old == '\0') | 1475 | } |
1476 | end++; | ||
1477 | } | ||
1478 | old = end[0]; | ||
1479 | end[0] = '\0'; | ||
1480 | if (strlen (pos) > 0) | ||
1481 | { | ||
1482 | ret++; | ||
1483 | if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos))) | ||
1484 | { | ||
1485 | ret = GNUNET_SYSERR; | ||
1486 | break; | 1486 | break; |
1487 | pos = end + 1; | 1487 | } |
1488 | } | 1488 | } |
1489 | GNUNET_free(list); | 1489 | if (old == '\0') |
1490 | break; | ||
1491 | pos = end + 1; | ||
1492 | } | ||
1493 | GNUNET_free (list); | ||
1490 | return ret; | 1494 | return ret; |
1491 | } | 1495 | } |
1492 | 1496 | ||
@@ -1498,33 +1502,33 @@ GNUNET_CONFIGURATION_iterate_value_filenames( | |||
1498 | * @return FIXME | 1502 | * @return FIXME |
1499 | */ | 1503 | */ |
1500 | static char * | 1504 | static char * |
1501 | escape_name(const char *value) | 1505 | escape_name (const char *value) |
1502 | { | 1506 | { |
1503 | char *escaped; | 1507 | char *escaped; |
1504 | const char *rpos; | 1508 | const char *rpos; |
1505 | char *wpos; | 1509 | char *wpos; |
1506 | 1510 | ||
1507 | escaped = GNUNET_malloc(strlen(value) * 2 + 1); | 1511 | escaped = GNUNET_malloc (strlen (value) * 2 + 1); |
1508 | memset(escaped, 0, strlen(value) * 2 + 1); | 1512 | memset (escaped, 0, strlen (value) * 2 + 1); |
1509 | rpos = value; | 1513 | rpos = value; |
1510 | wpos = escaped; | 1514 | wpos = escaped; |
1511 | while (rpos[0] != '\0') | 1515 | while (rpos[0] != '\0') |
1516 | { | ||
1517 | switch (rpos[0]) | ||
1512 | { | 1518 | { |
1513 | switch (rpos[0]) | 1519 | case '\\': |
1514 | { | 1520 | case ' ': |
1515 | case '\\': | 1521 | wpos[0] = '\\'; |
1516 | case ' ': | 1522 | wpos[1] = rpos[0]; |
1517 | wpos[0] = '\\'; | 1523 | wpos += 2; |
1518 | wpos[1] = rpos[0]; | 1524 | break; |
1519 | wpos += 2; | ||
1520 | break; | ||
1521 | 1525 | ||
1522 | default: | 1526 | default: |
1523 | wpos[0] = rpos[0]; | 1527 | wpos[0] = rpos[0]; |
1524 | wpos++; | 1528 | wpos++; |
1525 | } | ||
1526 | rpos++; | ||
1527 | } | 1529 | } |
1530 | rpos++; | ||
1531 | } | ||
1528 | return escaped; | 1532 | return escaped; |
1529 | } | 1533 | } |
1530 | 1534 | ||
@@ -1537,11 +1541,11 @@ escape_name(const char *value) | |||
1537 | * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do | 1541 | * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do |
1538 | */ | 1542 | */ |
1539 | static int | 1543 | static int |
1540 | test_match(void *cls, const char *fn) | 1544 | test_match (void *cls, const char *fn) |
1541 | { | 1545 | { |
1542 | const char *of = cls; | 1546 | const char *of = cls; |
1543 | 1547 | ||
1544 | return (0 == strcmp(of, fn)) ? GNUNET_SYSERR : GNUNET_OK; | 1548 | return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK; |
1545 | } | 1549 | } |
1546 | 1550 | ||
1547 | 1551 | ||
@@ -1558,7 +1562,7 @@ test_match(void *cls, const char *fn) | |||
1558 | * #GNUNET_SYSERR on error | 1562 | * #GNUNET_SYSERR on error |
1559 | */ | 1563 | */ |
1560 | int | 1564 | int |
1561 | GNUNET_CONFIGURATION_append_value_filename( | 1565 | GNUNET_CONFIGURATION_append_value_filename ( |
1562 | struct GNUNET_CONFIGURATION_Handle *cfg, | 1566 | struct GNUNET_CONFIGURATION_Handle *cfg, |
1563 | const char *section, | 1567 | const char *section, |
1564 | const char *option, | 1568 | const char *option, |
@@ -1569,25 +1573,25 @@ GNUNET_CONFIGURATION_append_value_filename( | |||
1569 | char *nw; | 1573 | char *nw; |
1570 | 1574 | ||
1571 | if (GNUNET_SYSERR == | 1575 | if (GNUNET_SYSERR == |
1572 | GNUNET_CONFIGURATION_iterate_value_filenames(cfg, | 1576 | GNUNET_CONFIGURATION_iterate_value_filenames (cfg, |
1573 | section, | 1577 | section, |
1574 | option, | 1578 | option, |
1575 | &test_match, | 1579 | &test_match, |
1576 | (void *)value)) | 1580 | (void *) value)) |
1577 | return GNUNET_NO; /* already exists */ | 1581 | return GNUNET_NO; /* already exists */ |
1578 | if (GNUNET_OK != | 1582 | if (GNUNET_OK != |
1579 | GNUNET_CONFIGURATION_get_value_string(cfg, section, option, &old)) | 1583 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) |
1580 | old = GNUNET_strdup(""); | 1584 | old = GNUNET_strdup (""); |
1581 | escaped = escape_name(value); | 1585 | escaped = escape_name (value); |
1582 | nw = GNUNET_malloc(strlen(old) + strlen(escaped) + 2); | 1586 | nw = GNUNET_malloc (strlen (old) + strlen (escaped) + 2); |
1583 | strcpy(nw, old); | 1587 | strcpy (nw, old); |
1584 | if (strlen(old) > 0) | 1588 | if (strlen (old) > 0) |
1585 | strcat(nw, " "); | 1589 | strcat (nw, " "); |
1586 | strcat(nw, escaped); | 1590 | strcat (nw, escaped); |
1587 | GNUNET_CONFIGURATION_set_value_string(cfg, section, option, nw); | 1591 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, nw); |
1588 | GNUNET_free(old); | 1592 | GNUNET_free (old); |
1589 | GNUNET_free(nw); | 1593 | GNUNET_free (nw); |
1590 | GNUNET_free(escaped); | 1594 | GNUNET_free (escaped); |
1591 | return GNUNET_OK; | 1595 | return GNUNET_OK; |
1592 | } | 1596 | } |
1593 | 1597 | ||
@@ -1605,7 +1609,7 @@ GNUNET_CONFIGURATION_append_value_filename( | |||
1605 | * #GNUNET_SYSERR on error | 1609 | * #GNUNET_SYSERR on error |
1606 | */ | 1610 | */ |
1607 | int | 1611 | int |
1608 | GNUNET_CONFIGURATION_remove_value_filename( | 1612 | GNUNET_CONFIGURATION_remove_value_filename ( |
1609 | struct GNUNET_CONFIGURATION_Handle *cfg, | 1613 | struct GNUNET_CONFIGURATION_Handle *cfg, |
1610 | const char *section, | 1614 | const char *section, |
1611 | const char *option, | 1615 | const char *option, |
@@ -1618,64 +1622,64 @@ GNUNET_CONFIGURATION_remove_value_filename( | |||
1618 | char old; | 1622 | char old; |
1619 | 1623 | ||
1620 | if (GNUNET_OK != | 1624 | if (GNUNET_OK != |
1621 | GNUNET_CONFIGURATION_get_value_string(cfg, section, option, &list)) | 1625 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &list)) |
1622 | return GNUNET_NO; | 1626 | return GNUNET_NO; |
1623 | match = escape_name(value); | 1627 | match = escape_name (value); |
1624 | pos = list; | 1628 | pos = list; |
1625 | while (1) | 1629 | while (1) |
1630 | { | ||
1631 | while (pos[0] == ' ') | ||
1632 | pos++; | ||
1633 | if (strlen (pos) == 0) | ||
1634 | break; | ||
1635 | end = pos + 1; | ||
1636 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1626 | { | 1637 | { |
1627 | while (pos[0] == ' ') | 1638 | if (end[0] == '\\') |
1628 | pos++; | 1639 | { |
1629 | if (strlen(pos) == 0) | 1640 | switch (end[1]) |
1630 | break; | ||
1631 | end = pos + 1; | ||
1632 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1633 | { | 1641 | { |
1634 | if (end[0] == '\\') | 1642 | case '\\': |
1635 | { | 1643 | case ' ': |
1636 | switch (end[1]) | ||
1637 | { | ||
1638 | case '\\': | ||
1639 | case ' ': | ||
1640 | end++; | ||
1641 | break; | ||
1642 | |||
1643 | case '\0': | ||
1644 | /* illegal, but just keep it */ | ||
1645 | break; | ||
1646 | |||
1647 | default: | ||
1648 | /* illegal, but just ignore that there was a '/' */ | ||
1649 | break; | ||
1650 | } | ||
1651 | } | ||
1652 | end++; | 1644 | end++; |
1645 | break; | ||
1646 | |||
1647 | case '\0': | ||
1648 | /* illegal, but just keep it */ | ||
1649 | break; | ||
1650 | |||
1651 | default: | ||
1652 | /* illegal, but just ignore that there was a '/' */ | ||
1653 | break; | ||
1653 | } | 1654 | } |
1654 | old = end[0]; | 1655 | } |
1655 | end[0] = '\0'; | 1656 | end++; |
1656 | if (0 == strcmp(pos, match)) | 1657 | } |
1657 | { | 1658 | old = end[0]; |
1658 | if (old != '\0') | 1659 | end[0] = '\0'; |
1659 | memmove(pos, &end[1], strlen(&end[1]) + 1); | 1660 | if (0 == strcmp (pos, match)) |
1660 | else | 1661 | { |
1661 | { | 1662 | if (old != '\0') |
1662 | if (pos != list) | 1663 | memmove (pos, &end[1], strlen (&end[1]) + 1); |
1663 | pos[-1] = '\0'; | 1664 | else |
1664 | else | 1665 | { |
1665 | pos[0] = '\0'; | 1666 | if (pos != list) |
1666 | } | 1667 | pos[-1] = '\0'; |
1667 | GNUNET_CONFIGURATION_set_value_string(cfg, section, option, list); | 1668 | else |
1668 | GNUNET_free(list); | 1669 | pos[0] = '\0'; |
1669 | GNUNET_free(match); | 1670 | } |
1670 | return GNUNET_OK; | 1671 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list); |
1671 | } | 1672 | GNUNET_free (list); |
1672 | if (old == '\0') | 1673 | GNUNET_free (match); |
1673 | break; | 1674 | return GNUNET_OK; |
1674 | end[0] = old; | ||
1675 | pos = end + 1; | ||
1676 | } | 1675 | } |
1677 | GNUNET_free(list); | 1676 | if (old == '\0') |
1678 | GNUNET_free(match); | 1677 | break; |
1678 | end[0] = old; | ||
1679 | pos = end + 1; | ||
1680 | } | ||
1681 | GNUNET_free (list); | ||
1682 | GNUNET_free (match); | ||
1679 | return GNUNET_NO; | 1683 | return GNUNET_NO; |
1680 | } | 1684 | } |
1681 | 1685 | ||
@@ -1690,21 +1694,21 @@ GNUNET_CONFIGURATION_remove_value_filename( | |||
1690 | * @return #GNUNET_OK on success | 1694 | * @return #GNUNET_OK on success |
1691 | */ | 1695 | */ |
1692 | static int | 1696 | static int |
1693 | parse_configuration_file(void *cls, const char *filename) | 1697 | parse_configuration_file (void *cls, const char *filename) |
1694 | { | 1698 | { |
1695 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1699 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1696 | char *ext; | 1700 | char *ext; |
1697 | int ret; | 1701 | int ret; |
1698 | 1702 | ||
1699 | /* Examine file extension */ | 1703 | /* Examine file extension */ |
1700 | ext = strrchr(filename, '.'); | 1704 | ext = strrchr (filename, '.'); |
1701 | if ((NULL == ext) || (0 != strcmp(ext, ".conf"))) | 1705 | if ((NULL == ext) || (0 != strcmp (ext, ".conf"))) |
1702 | { | 1706 | { |
1703 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename); | 1707 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Skipping file `%s'\n", filename); |
1704 | return GNUNET_OK; | 1708 | return GNUNET_OK; |
1705 | } | 1709 | } |
1706 | 1710 | ||
1707 | ret = GNUNET_CONFIGURATION_parse(cfg, filename); | 1711 | ret = GNUNET_CONFIGURATION_parse (cfg, filename); |
1708 | return ret; | 1712 | return ret; |
1709 | } | 1713 | } |
1710 | 1714 | ||
@@ -1718,11 +1722,11 @@ parse_configuration_file(void *cls, const char *filename) | |||
1718 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1722 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1719 | */ | 1723 | */ |
1720 | int | 1724 | int |
1721 | GNUNET_CONFIGURATION_load_from(struct GNUNET_CONFIGURATION_Handle *cfg, | 1725 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, |
1722 | const char *defaults_d) | 1726 | const char *defaults_d) |
1723 | { | 1727 | { |
1724 | if (GNUNET_SYSERR == | 1728 | if (GNUNET_SYSERR == |
1725 | GNUNET_DISK_directory_scan(defaults_d, &parse_configuration_file, cfg)) | 1729 | GNUNET_DISK_directory_scan (defaults_d, &parse_configuration_file, cfg)) |
1726 | return GNUNET_SYSERR; /* no configuration at all found */ | 1730 | return GNUNET_SYSERR; /* no configuration at all found */ |
1727 | return GNUNET_OK; | 1731 | return GNUNET_OK; |
1728 | } | 1732 | } |