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