diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-04 14:00:32 +0000 |
commit | 83b19539f4d322b43683f5838b72e9ec2c8e6073 (patch) | |
tree | d0ab9329fcbefe360d9d14e2ace21a6b3396dfe9 /src/util/configuration.c | |
parent | 28a2eb43281a1f08a67954f07beb9af3a9bc9a35 (diff) | |
download | gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.tar.gz gnunet-83b19539f4d322b43683f5838b72e9ec2c8e6073.zip |
curly wars / auto-indentation
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 768 |
1 files changed, 376 insertions, 392 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index 9a131fb50..41a4e1975 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -150,7 +150,7 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
150 | */ | 150 | */ |
151 | int | 151 | int |
152 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | 152 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, |
153 | const char *filename) | 153 | const char *filename) |
154 | { | 154 | { |
155 | int dirty; | 155 | int dirty; |
156 | char line[256]; | 156 | char line[256]; |
@@ -167,89 +167,87 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
167 | fn = GNUNET_STRINGS_filename_expand (filename); | 167 | fn = GNUNET_STRINGS_filename_expand (filename); |
168 | if (fn == NULL) | 168 | if (fn == NULL) |
169 | return GNUNET_SYSERR; | 169 | return GNUNET_SYSERR; |
170 | dirty = cfg->dirty; /* back up value! */ | 170 | dirty = cfg->dirty; /* back up value! */ |
171 | if (NULL == (fp = FOPEN (fn, "r"))) | 171 | if (NULL == (fp = FOPEN (fn, "r"))) |
172 | { | 172 | { |
173 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); | 173 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); |
174 | GNUNET_free (fn); | 174 | GNUNET_free (fn); |
175 | return GNUNET_SYSERR; | 175 | return GNUNET_SYSERR; |
176 | } | 176 | } |
177 | GNUNET_free (fn); | 177 | GNUNET_free (fn); |
178 | ret = GNUNET_OK; | 178 | ret = GNUNET_OK; |
179 | section = GNUNET_strdup (""); | 179 | section = GNUNET_strdup (""); |
180 | memset (line, 0, 256); | 180 | memset (line, 0, 256); |
181 | nr = 0; | 181 | nr = 0; |
182 | while (NULL != fgets (line, 255, fp)) | 182 | while (NULL != fgets (line, 255, fp)) |
183 | { | ||
184 | nr++; | ||
185 | for (i = 0; i < 255; i++) | ||
186 | if (line[i] == '\t') | ||
187 | line[i] = ' '; | ||
188 | if (line[0] == '\n' || line[0] == '#' || line[0] == '%' || line[0] == '\r') | ||
189 | continue; | ||
190 | emptyline = 1; | ||
191 | for (i = 0; (i < 255 && line[i] != 0); i++) | ||
192 | if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r') | ||
193 | emptyline = 0; | ||
194 | if (emptyline == 1) | ||
195 | continue; | ||
196 | /* remove tailing whitespace */ | ||
197 | for (i = strlen (line) - 1; (i >= 0) && (isspace ((unsigned char) line[i])); | ||
198 | i--) | ||
199 | line[i] = '\0'; | ||
200 | if (1 == sscanf (line, "@INLINE@ %191[^\n]", value)) | ||
183 | { | 201 | { |
184 | nr++; | 202 | /* @INLINE@ value */ |
185 | for (i = 0; i < 255; i++) | 203 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) |
186 | if (line[i] == '\t') | 204 | ret = GNUNET_SYSERR; /* failed to parse included config */ |
187 | line[i] = ' '; | 205 | } |
188 | if (line[0] == '\n' || line[0] == '#' || line[0] == '%' | 206 | else if (1 == sscanf (line, "[%99[^]]]", value)) |
189 | || line[0] == '\r') | 207 | { |
190 | continue; | 208 | /* [value] */ |
191 | emptyline = 1; | 209 | GNUNET_free (section); |
192 | for (i = 0; (i < 255 && line[i] != 0); i++) | 210 | section = GNUNET_strdup (value); |
193 | if (line[i] != ' ' && line[i] != '\n' && line[i] != '\r') | 211 | } |
194 | emptyline = 0; | 212 | else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value)) |
195 | if (emptyline == 1) | 213 | { |
196 | continue; | 214 | /* tag = value */ |
197 | /* remove tailing whitespace */ | 215 | /* Strip LF */ |
198 | for (i = strlen (line) - 1; | 216 | i = strlen (value) - 1; |
199 | (i >= 0) && (isspace ((unsigned char) line[i])); i--) | 217 | while ((i >= 0) && (isspace ((unsigned char) value[i]))) |
200 | line[i] = '\0'; | 218 | value[i--] = '\0'; |
201 | if (1 == sscanf (line, "@INLINE@ %191[^\n]", value)) | 219 | /* remove quotes */ |
202 | { | 220 | i = 0; |
203 | /* @INLINE@ value */ | 221 | if (value[0] == '"') |
204 | if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, value)) | 222 | { |
205 | ret = GNUNET_SYSERR; /* failed to parse included config */ | 223 | i = 1; |
206 | } | 224 | while ((value[i] != '\0') && (value[i] != '"')) |
207 | else if (1 == sscanf (line, "[%99[^]]]", value)) | 225 | i++; |
208 | { | 226 | if (value[i] == '"') |
209 | /* [value] */ | 227 | { |
210 | GNUNET_free (section); | 228 | value[i] = '\0'; |
211 | section = GNUNET_strdup (value); | 229 | i = 1; |
212 | } | 230 | } |
213 | else if (2 == sscanf (line, " %63[^= ] = %191[^\n]", tag, value)) | 231 | else |
214 | { | 232 | i = 0; |
215 | /* tag = value */ | 233 | } |
216 | /* Strip LF */ | 234 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, &value[i]); |
217 | i = strlen (value) - 1; | 235 | } |
218 | while ((i >= 0) && (isspace ((unsigned char) value[i]))) | 236 | else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag)) |
219 | value[i--] = '\0'; | 237 | { |
220 | /* remove quotes */ | 238 | /* tag = */ |
221 | i = 0; | 239 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, ""); |
222 | if (value[0] == '"') | 240 | } |
223 | { | 241 | else |
224 | i = 1; | 242 | { |
225 | while ((value[i] != '\0') && (value[i] != '"')) | 243 | /* parse error */ |
226 | i++; | 244 | LOG (GNUNET_ERROR_TYPE_WARNING, |
227 | if (value[i] == '"') | 245 | _("Syntax error in configuration file `%s' at line %u.\n"), filename, |
228 | { | 246 | nr); |
229 | value[i] = '\0'; | 247 | ret = GNUNET_SYSERR; |
230 | i = 1; | 248 | break; |
231 | } | ||
232 | else | ||
233 | i = 0; | ||
234 | } | ||
235 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, | ||
236 | &value[i]); | ||
237 | } | ||
238 | else if (1 == sscanf (line, " %63[^= ] =[^\n]", tag)) | ||
239 | { | ||
240 | /* tag = */ | ||
241 | GNUNET_CONFIGURATION_set_value_string (cfg, section, tag, ""); | ||
242 | } | ||
243 | else | ||
244 | { | ||
245 | /* parse error */ | ||
246 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
247 | _("Syntax error in configuration file `%s' at line %u.\n"), | ||
248 | filename, nr); | ||
249 | ret = GNUNET_SYSERR; | ||
250 | break; | ||
251 | } | ||
252 | } | 249 | } |
250 | } | ||
253 | GNUNET_assert (0 == fclose (fp)); | 251 | GNUNET_assert (0 == fclose (fp)); |
254 | /* restore dirty flag - anything we set in the meantime | 252 | /* restore dirty flag - anything we set in the meantime |
255 | * came from disk */ | 253 | * came from disk */ |
@@ -282,7 +280,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
282 | */ | 280 | */ |
283 | int | 281 | int |
284 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | 282 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, |
285 | const char *filename) | 283 | const char *filename) |
286 | { | 284 | { |
287 | struct ConfigSection *sec; | 285 | struct ConfigSection *sec; |
288 | struct ConfigEntry *ent; | 286 | struct ConfigEntry *ent; |
@@ -296,67 +294,67 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
296 | if (fn == NULL) | 294 | if (fn == NULL) |
297 | return GNUNET_SYSERR; | 295 | return GNUNET_SYSERR; |
298 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)) | 296 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn)) |
299 | { | 297 | { |
300 | GNUNET_free (fn); | 298 | GNUNET_free (fn); |
301 | return GNUNET_SYSERR; | 299 | return GNUNET_SYSERR; |
302 | } | 300 | } |
303 | if (NULL == (fp = FOPEN (fn, "w"))) | 301 | if (NULL == (fp = FOPEN (fn, "w"))) |
304 | { | 302 | { |
305 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); | 303 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fopen", fn); |
306 | GNUNET_free (fn); | 304 | GNUNET_free (fn); |
307 | return GNUNET_SYSERR; | 305 | return GNUNET_SYSERR; |
308 | } | 306 | } |
309 | GNUNET_free (fn); | 307 | GNUNET_free (fn); |
310 | error = 0; | 308 | error = 0; |
311 | sec = cfg->sections; | 309 | sec = cfg->sections; |
312 | while (sec != NULL) | 310 | while (sec != NULL) |
311 | { | ||
312 | if (0 > fprintf (fp, "[%s]\n", sec->name)) | ||
313 | { | 313 | { |
314 | if (0 > fprintf (fp, "[%s]\n", sec->name)) | 314 | error = 1; |
315 | { | 315 | break; |
316 | error = 1; | ||
317 | break; | ||
318 | } | ||
319 | ent = sec->entries; | ||
320 | while (ent != NULL) | ||
321 | { | ||
322 | if (ent->val != NULL) | ||
323 | { | ||
324 | val = GNUNET_malloc (strlen (ent->val) * 2 + 1); | ||
325 | strcpy (val, ent->val); | ||
326 | while (NULL != (pos = strstr (val, "\n"))) | ||
327 | { | ||
328 | memmove (&pos[2], &pos[1], strlen (&pos[1])); | ||
329 | pos[0] = '\\'; | ||
330 | pos[1] = 'n'; | ||
331 | } | ||
332 | if (0 > fprintf (fp, "%s = %s\n", ent->key, val)) | ||
333 | { | ||
334 | error = 1; | ||
335 | GNUNET_free (val); | ||
336 | break; | ||
337 | } | ||
338 | GNUNET_free (val); | ||
339 | } | ||
340 | ent = ent->next; | ||
341 | } | ||
342 | if (error != 0) | ||
343 | break; | ||
344 | if (0 > fprintf (fp, "\n")) | ||
345 | { | ||
346 | error = 1; | ||
347 | break; | ||
348 | } | ||
349 | sec = sec->next; | ||
350 | } | 316 | } |
317 | ent = sec->entries; | ||
318 | while (ent != NULL) | ||
319 | { | ||
320 | if (ent->val != NULL) | ||
321 | { | ||
322 | val = GNUNET_malloc (strlen (ent->val) * 2 + 1); | ||
323 | strcpy (val, ent->val); | ||
324 | while (NULL != (pos = strstr (val, "\n"))) | ||
325 | { | ||
326 | memmove (&pos[2], &pos[1], strlen (&pos[1])); | ||
327 | pos[0] = '\\'; | ||
328 | pos[1] = 'n'; | ||
329 | } | ||
330 | if (0 > fprintf (fp, "%s = %s\n", ent->key, val)) | ||
331 | { | ||
332 | error = 1; | ||
333 | GNUNET_free (val); | ||
334 | break; | ||
335 | } | ||
336 | GNUNET_free (val); | ||
337 | } | ||
338 | ent = ent->next; | ||
339 | } | ||
340 | if (error != 0) | ||
341 | break; | ||
342 | if (0 > fprintf (fp, "\n")) | ||
343 | { | ||
344 | error = 1; | ||
345 | break; | ||
346 | } | ||
347 | sec = sec->next; | ||
348 | } | ||
351 | if (error != 0) | 349 | if (error != 0) |
352 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename); | 350 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", filename); |
353 | GNUNET_assert (0 == fclose (fp)); | 351 | GNUNET_assert (0 == fclose (fp)); |
354 | if (error != 0) | 352 | if (error != 0) |
355 | { | 353 | { |
356 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ | 354 | cfg->dirty = GNUNET_SYSERR; /* last write failed */ |
357 | return GNUNET_SYSERR; | 355 | return GNUNET_SYSERR; |
358 | } | 356 | } |
359 | cfg->dirty = GNUNET_NO; /* last write succeeded */ | 357 | cfg->dirty = GNUNET_NO; /* last write succeeded */ |
360 | return GNUNET_OK; | 358 | return GNUNET_OK; |
361 | } | 359 | } |
362 | 360 | ||
@@ -370,23 +368,23 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
370 | */ | 368 | */ |
371 | void | 369 | void |
372 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 370 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
373 | GNUNET_CONFIGURATION_Iterator iter, | 371 | GNUNET_CONFIGURATION_Iterator iter, |
374 | void *iter_cls) | 372 | void *iter_cls) |
375 | { | 373 | { |
376 | struct ConfigSection *spos; | 374 | struct ConfigSection *spos; |
377 | struct ConfigEntry *epos; | 375 | struct ConfigEntry *epos; |
378 | 376 | ||
379 | spos = cfg->sections; | 377 | spos = cfg->sections; |
380 | while (spos != NULL) | 378 | while (spos != NULL) |
379 | { | ||
380 | epos = spos->entries; | ||
381 | while (epos != NULL) | ||
381 | { | 382 | { |
382 | epos = spos->entries; | 383 | iter (iter_cls, spos->name, epos->key, epos->val); |
383 | while (epos != NULL) | 384 | epos = epos->next; |
384 | { | ||
385 | iter (iter_cls, spos->name, epos->key, epos->val); | ||
386 | epos = epos->next; | ||
387 | } | ||
388 | spos = spos->next; | ||
389 | } | 385 | } |
386 | spos = spos->next; | ||
387 | } | ||
390 | } | 388 | } |
391 | 389 | ||
392 | 390 | ||
@@ -400,10 +398,10 @@ GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
400 | */ | 398 | */ |
401 | void | 399 | void |
402 | GNUNET_CONFIGURATION_iterate_section_values (const struct | 400 | GNUNET_CONFIGURATION_iterate_section_values (const struct |
403 | GNUNET_CONFIGURATION_Handle *cfg, | 401 | GNUNET_CONFIGURATION_Handle *cfg, |
404 | const char *section, | 402 | const char *section, |
405 | GNUNET_CONFIGURATION_Iterator | 403 | GNUNET_CONFIGURATION_Iterator iter, |
406 | iter, void *iter_cls) | 404 | void *iter_cls) |
407 | { | 405 | { |
408 | struct ConfigSection *spos; | 406 | struct ConfigSection *spos; |
409 | struct ConfigEntry *epos; | 407 | struct ConfigEntry *epos; |
@@ -417,10 +415,10 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct | |||
417 | 415 | ||
418 | epos = spos->entries; | 416 | epos = spos->entries; |
419 | while (epos != NULL) | 417 | while (epos != NULL) |
420 | { | 418 | { |
421 | iter (iter_cls, spos->name, epos->key, epos->val); | 419 | iter (iter_cls, spos->name, epos->key, epos->val); |
422 | epos = epos->next; | 420 | epos = epos->next; |
423 | } | 421 | } |
424 | } | 422 | } |
425 | 423 | ||
426 | 424 | ||
@@ -432,21 +430,21 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct | |||
432 | * @param iter_cls closure for iter | 430 | * @param iter_cls closure for iter |
433 | */ | 431 | */ |
434 | void | 432 | void |
435 | GNUNET_CONFIGURATION_iterate_sections (const struct | 433 | GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle |
436 | GNUNET_CONFIGURATION_Handle *cfg, | 434 | *cfg, |
437 | GNUNET_CONFIGURATION_Section_Iterator | 435 | GNUNET_CONFIGURATION_Section_Iterator |
438 | iter, void *iter_cls) | 436 | iter, void *iter_cls) |
439 | { | 437 | { |
440 | struct ConfigSection *spos; | 438 | struct ConfigSection *spos; |
441 | struct ConfigSection *next; | 439 | struct ConfigSection *next; |
442 | 440 | ||
443 | next = cfg->sections; | 441 | next = cfg->sections; |
444 | while (next != NULL) | 442 | while (next != NULL) |
445 | { | 443 | { |
446 | spos = next; | 444 | spos = next; |
447 | next = spos->next; | 445 | next = spos->next; |
448 | iter (iter_cls, spos->name); | 446 | iter (iter_cls, spos->name); |
449 | } | 447 | } |
450 | } | 448 | } |
451 | 449 | ||
452 | /** | 450 | /** |
@@ -457,7 +455,7 @@ GNUNET_CONFIGURATION_iterate_sections (const struct | |||
457 | */ | 455 | */ |
458 | void | 456 | void |
459 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | 457 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, |
460 | const char *section) | 458 | const char *section) |
461 | { | 459 | { |
462 | struct ConfigSection *spos; | 460 | struct ConfigSection *spos; |
463 | struct ConfigSection *prev; | 461 | struct ConfigSection *prev; |
@@ -466,28 +464,28 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
466 | prev = NULL; | 464 | prev = NULL; |
467 | spos = cfg->sections; | 465 | spos = cfg->sections; |
468 | while (spos != NULL) | 466 | while (spos != NULL) |
467 | { | ||
468 | if (0 == strcmp (section, spos->name)) | ||
469 | { | 469 | { |
470 | if (0 == strcmp (section, spos->name)) | 470 | if (prev == NULL) |
471 | { | 471 | cfg->sections = spos->next; |
472 | if (prev == NULL) | 472 | else |
473 | cfg->sections = spos->next; | 473 | prev->next = spos->next; |
474 | else | 474 | while (NULL != (ent = spos->entries)) |
475 | prev->next = spos->next; | 475 | { |
476 | while (NULL != (ent = spos->entries)) | 476 | spos->entries = ent->next; |
477 | { | 477 | GNUNET_free (ent->key); |
478 | spos->entries = ent->next; | 478 | GNUNET_free_non_null (ent->val); |
479 | GNUNET_free (ent->key); | 479 | GNUNET_free (ent); |
480 | GNUNET_free_non_null (ent->val); | 480 | cfg->dirty = GNUNET_YES; |
481 | GNUNET_free (ent); | 481 | } |
482 | cfg->dirty = GNUNET_YES; | 482 | GNUNET_free (spos->name); |
483 | } | 483 | GNUNET_free (spos); |
484 | GNUNET_free (spos->name); | 484 | return; |
485 | GNUNET_free (spos); | ||
486 | return; | ||
487 | } | ||
488 | prev = spos; | ||
489 | spos = spos->next; | ||
490 | } | 485 | } |
486 | prev = spos; | ||
487 | spos = spos->next; | ||
488 | } | ||
491 | } | 489 | } |
492 | 490 | ||
493 | 491 | ||
@@ -502,7 +500,7 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
502 | */ | 500 | */ |
503 | static void | 501 | static void |
504 | copy_entry (void *cls, const char *section, const char *option, | 502 | copy_entry (void *cls, const char *section, const char *option, |
505 | const char *value) | 503 | const char *value) |
506 | { | 504 | { |
507 | struct GNUNET_CONFIGURATION_Handle *dst = cls; | 505 | struct GNUNET_CONFIGURATION_Handle *dst = cls; |
508 | 506 | ||
@@ -535,8 +533,7 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
535 | * @return matching entry, NULL if not found | 533 | * @return matching entry, NULL if not found |
536 | */ | 534 | */ |
537 | static struct ConfigSection * | 535 | static struct ConfigSection * |
538 | findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, | 536 | findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) |
539 | const char *section) | ||
540 | { | 537 | { |
541 | struct ConfigSection *pos; | 538 | struct ConfigSection *pos; |
542 | 539 | ||
@@ -557,7 +554,7 @@ findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
557 | */ | 554 | */ |
558 | static struct ConfigEntry * | 555 | static struct ConfigEntry * |
559 | findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, | 556 | findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, |
560 | const char *key) | 557 | const char *key) |
561 | { | 558 | { |
562 | struct ConfigSection *sec; | 559 | struct ConfigSection *sec; |
563 | struct ConfigEntry *pos; | 560 | struct ConfigEntry *pos; |
@@ -584,7 +581,7 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, | |||
584 | */ | 581 | */ |
585 | static void | 582 | static void |
586 | compareEntries (void *cls, const char *section, const char *option, | 583 | compareEntries (void *cls, const char *section, const char *option, |
587 | const char *value) | 584 | const char *value) |
588 | { | 585 | { |
589 | struct DiffHandle *dh = cls; | 586 | struct DiffHandle *dh = cls; |
590 | struct ConfigEntry *entNew; | 587 | struct ConfigEntry *entNew; |
@@ -605,9 +602,9 @@ compareEntries (void *cls, const char *section, const char *option, | |||
605 | */ | 602 | */ |
606 | int | 603 | int |
607 | GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle | 604 | GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle |
608 | *cfgDefault, | 605 | *cfgDefault, |
609 | const struct GNUNET_CONFIGURATION_Handle | 606 | const struct GNUNET_CONFIGURATION_Handle |
610 | *cfgNew, const char *filename) | 607 | *cfgNew, const char *filename) |
611 | { | 608 | { |
612 | int ret; | 609 | int ret; |
613 | struct DiffHandle diffHandle; | 610 | struct DiffHandle diffHandle; |
@@ -630,28 +627,28 @@ GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle | |||
630 | * @param value value to set | 627 | * @param value value to set |
631 | */ | 628 | */ |
632 | void | 629 | void |
633 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle | 630 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, |
634 | *cfg, const char *section, | 631 | const char *section, const char *option, |
635 | const char *option, const char *value) | 632 | const char *value) |
636 | { | 633 | { |
637 | struct ConfigSection *sec; | 634 | struct ConfigSection *sec; |
638 | struct ConfigEntry *e; | 635 | struct ConfigEntry *e; |
639 | 636 | ||
640 | e = findEntry (cfg, section, option); | 637 | e = findEntry (cfg, section, option); |
641 | if (e != NULL) | 638 | if (e != NULL) |
642 | { | 639 | { |
643 | GNUNET_free_non_null (e->val); | 640 | GNUNET_free_non_null (e->val); |
644 | e->val = GNUNET_strdup (value); | 641 | e->val = GNUNET_strdup (value); |
645 | return; | 642 | return; |
646 | } | 643 | } |
647 | sec = findSection (cfg, section); | 644 | sec = findSection (cfg, section); |
648 | if (sec == NULL) | 645 | if (sec == NULL) |
649 | { | 646 | { |
650 | sec = GNUNET_malloc (sizeof (struct ConfigSection)); | 647 | sec = GNUNET_malloc (sizeof (struct ConfigSection)); |
651 | sec->name = GNUNET_strdup (section); | 648 | sec->name = GNUNET_strdup (section); |
652 | sec->next = cfg->sections; | 649 | sec->next = cfg->sections; |
653 | cfg->sections = sec; | 650 | cfg->sections = sec; |
654 | } | 651 | } |
655 | e = GNUNET_malloc (sizeof (struct ConfigEntry)); | 652 | e = GNUNET_malloc (sizeof (struct ConfigEntry)); |
656 | e->key = GNUNET_strdup (option); | 653 | e->key = GNUNET_strdup (option); |
657 | e->val = GNUNET_strdup (value); | 654 | e->val = GNUNET_strdup (value); |
@@ -669,10 +666,9 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle | |||
669 | * @param number value to set | 666 | * @param number value to set |
670 | */ | 667 | */ |
671 | void | 668 | void |
672 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle | 669 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, |
673 | *cfg, const char *section, | 670 | const char *section, const char *option, |
674 | const char *option, | 671 | unsigned long long number) |
675 | unsigned long long number) | ||
676 | { | 672 | { |
677 | char s[64]; | 673 | char s[64]; |
678 | 674 | ||
@@ -691,11 +687,10 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle | |||
691 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 687 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
692 | */ | 688 | */ |
693 | int | 689 | int |
694 | GNUNET_CONFIGURATION_get_value_number (const struct | 690 | GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle |
695 | GNUNET_CONFIGURATION_Handle *cfg, | 691 | *cfg, const char *section, |
696 | const char *section, | 692 | const char *option, |
697 | const char *option, | 693 | unsigned long long *number) |
698 | unsigned long long *number) | ||
699 | { | 694 | { |
700 | struct ConfigEntry *e; | 695 | struct ConfigEntry *e; |
701 | 696 | ||
@@ -719,9 +714,9 @@ GNUNET_CONFIGURATION_get_value_number (const struct | |||
719 | */ | 714 | */ |
720 | int | 715 | int |
721 | GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle | 716 | GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle |
722 | *cfg, const char *section, | 717 | *cfg, const char *section, |
723 | const char *option, | 718 | const char *option, |
724 | struct GNUNET_TIME_Relative *time) | 719 | struct GNUNET_TIME_Relative *time) |
725 | { | 720 | { |
726 | struct ConfigEntry *e; | 721 | struct ConfigEntry *e; |
727 | 722 | ||
@@ -729,8 +724,7 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle | |||
729 | if (e == NULL) | 724 | if (e == NULL) |
730 | return GNUNET_SYSERR; | 725 | return GNUNET_SYSERR; |
731 | 726 | ||
732 | return GNUNET_STRINGS_fancy_time_to_relative (e->val, | 727 | return GNUNET_STRINGS_fancy_time_to_relative (e->val, time); |
733 | time); | ||
734 | } | 728 | } |
735 | 729 | ||
736 | 730 | ||
@@ -754,8 +748,7 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle | |||
754 | e = findEntry (cfg, section, option); | 748 | e = findEntry (cfg, section, option); |
755 | if (e == NULL) | 749 | if (e == NULL) |
756 | return GNUNET_SYSERR; | 750 | return GNUNET_SYSERR; |
757 | return GNUNET_STRINGS_fancy_size_to_bytes (e->val, | 751 | return GNUNET_STRINGS_fancy_size_to_bytes (e->val, size); |
758 | size); | ||
759 | } | 752 | } |
760 | 753 | ||
761 | 754 | ||
@@ -770,19 +763,18 @@ GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle | |||
770 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 763 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
771 | */ | 764 | */ |
772 | int | 765 | int |
773 | GNUNET_CONFIGURATION_get_value_string (const struct | 766 | GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle |
774 | GNUNET_CONFIGURATION_Handle *cfg, | 767 | *cfg, const char *section, |
775 | const char *section, | 768 | const char *option, char **value) |
776 | const char *option, char **value) | ||
777 | { | 769 | { |
778 | struct ConfigEntry *e; | 770 | struct ConfigEntry *e; |
779 | 771 | ||
780 | e = findEntry (cfg, section, option); | 772 | e = findEntry (cfg, section, option); |
781 | if ((e == NULL) || (e->val == NULL)) | 773 | if ((e == NULL) || (e->val == NULL)) |
782 | { | 774 | { |
783 | *value = NULL; | 775 | *value = NULL; |
784 | return GNUNET_SYSERR; | 776 | return GNUNET_SYSERR; |
785 | } | 777 | } |
786 | *value = GNUNET_strdup (e->val); | 778 | *value = GNUNET_strdup (e->val); |
787 | return GNUNET_OK; | 779 | return GNUNET_OK; |
788 | } | 780 | } |
@@ -801,12 +793,10 @@ GNUNET_CONFIGURATION_get_value_string (const struct | |||
801 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | 793 | * @return GNUNET_OK on success, GNUNET_SYSERR on error |
802 | */ | 794 | */ |
803 | int | 795 | int |
804 | GNUNET_CONFIGURATION_get_value_choice (const struct | 796 | GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle |
805 | GNUNET_CONFIGURATION_Handle *cfg, | 797 | *cfg, const char *section, |
806 | const char *section, | 798 | const char *option, const char **choices, |
807 | const char *option, | 799 | const char **value) |
808 | const char **choices, | ||
809 | const char **value) | ||
810 | { | 800 | { |
811 | struct ConfigEntry *e; | 801 | struct ConfigEntry *e; |
812 | int i; | 802 | int i; |
@@ -816,19 +806,19 @@ GNUNET_CONFIGURATION_get_value_choice (const struct | |||
816 | return GNUNET_SYSERR; | 806 | return GNUNET_SYSERR; |
817 | i = 0; | 807 | i = 0; |
818 | while (choices[i] != NULL) | 808 | while (choices[i] != NULL) |
819 | { | 809 | { |
820 | if (0 == strcasecmp (choices[i], e->val)) | 810 | if (0 == strcasecmp (choices[i], e->val)) |
821 | break; | 811 | break; |
822 | i++; | 812 | i++; |
823 | } | 813 | } |
824 | if (choices[i] == NULL) | 814 | if (choices[i] == NULL) |
825 | { | 815 | { |
826 | LOG (GNUNET_ERROR_TYPE_ERROR, | 816 | LOG (GNUNET_ERROR_TYPE_ERROR, |
827 | _("Configuration value '%s' for '%s'" | 817 | _("Configuration value '%s' for '%s'" |
828 | " in section '%s' is not in set of legal choices\n"), e->val, | 818 | " in section '%s' is not in set of legal choices\n"), e->val, option, |
829 | option, section); | 819 | section); |
830 | return GNUNET_SYSERR; | 820 | return GNUNET_SYSERR; |
831 | } | 821 | } |
832 | *value = choices[i]; | 822 | *value = choices[i]; |
833 | return GNUNET_OK; | 823 | return GNUNET_OK; |
834 | } | 824 | } |
@@ -842,9 +832,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct | |||
842 | * @return GNUNET_YES if so, GNUNET_NO if not. | 832 | * @return GNUNET_YES if so, GNUNET_NO if not. |
843 | */ | 833 | */ |
844 | int | 834 | int |
845 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle | 835 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, |
846 | *cfg, const char *section, | 836 | const char *section, const char *option) |
847 | const char *option) | ||
848 | { | 837 | { |
849 | struct ConfigEntry *e; | 838 | struct ConfigEntry *e; |
850 | 839 | ||
@@ -865,7 +854,7 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle | |||
865 | */ | 854 | */ |
866 | char * | 855 | char * |
867 | GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle | 856 | GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle |
868 | *cfg, char *orig) | 857 | *cfg, char *orig) |
869 | { | 858 | { |
870 | int i; | 859 | int i; |
871 | char *prefix; | 860 | char *prefix; |
@@ -879,25 +868,24 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle | |||
879 | while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0')) | 868 | while ((orig[i] != '/') && (orig[i] != '\\') && (orig[i] != '\0')) |
880 | i++; | 869 | i++; |
881 | if (orig[i] == '\0') | 870 | if (orig[i] == '\0') |
882 | { | 871 | { |
883 | post = ""; | 872 | post = ""; |
884 | } | 873 | } |
885 | else | 874 | else |
886 | { | 875 | { |
887 | orig[i] = '\0'; | 876 | orig[i] = '\0'; |
888 | post = &orig[i + 1]; | 877 | post = &orig[i + 1]; |
889 | } | 878 | } |
890 | if (GNUNET_OK != | 879 | if (GNUNET_OK != |
891 | GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], | 880 | GNUNET_CONFIGURATION_get_value_filename (cfg, "PATHS", &orig[1], &prefix)) |
892 | &prefix)) | 881 | { |
882 | if (NULL == (env = getenv (&orig[1]))) | ||
893 | { | 883 | { |
894 | if (NULL == (env = getenv (&orig[1]))) | 884 | orig[i] = DIR_SEPARATOR; |
895 | { | 885 | return orig; |
896 | orig[i] = DIR_SEPARATOR; | ||
897 | return orig; | ||
898 | } | ||
899 | prefix = GNUNET_strdup (env); | ||
900 | } | 886 | } |
887 | prefix = GNUNET_strdup (env); | ||
888 | } | ||
901 | result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2); | 889 | result = GNUNET_malloc (strlen (prefix) + strlen (post) + 2); |
902 | strcpy (result, prefix); | 890 | strcpy (result, prefix); |
903 | if ((strlen (prefix) == 0) || | 891 | if ((strlen (prefix) == 0) || |
@@ -922,18 +910,18 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle | |||
922 | */ | 910 | */ |
923 | int | 911 | int |
924 | GNUNET_CONFIGURATION_get_value_filename (const struct | 912 | GNUNET_CONFIGURATION_get_value_filename (const struct |
925 | GNUNET_CONFIGURATION_Handle *cfg, | 913 | GNUNET_CONFIGURATION_Handle *cfg, |
926 | const char *section, | 914 | const char *section, |
927 | const char *option, char **value) | 915 | const char *option, char **value) |
928 | { | 916 | { |
929 | char *tmp; | 917 | char *tmp; |
930 | 918 | ||
931 | if (GNUNET_OK != | 919 | if (GNUNET_OK != |
932 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) | 920 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &tmp)) |
933 | { | 921 | { |
934 | *value = NULL; | 922 | *value = NULL; |
935 | return GNUNET_SYSERR; | 923 | return GNUNET_SYSERR; |
936 | } | 924 | } |
937 | tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp); | 925 | tmp = GNUNET_CONFIGURATION_expand_dollar (cfg, tmp); |
938 | *value = GNUNET_STRINGS_filename_expand (tmp); | 926 | *value = GNUNET_STRINGS_filename_expand (tmp); |
939 | GNUNET_free (tmp); | 927 | GNUNET_free (tmp); |
@@ -954,15 +942,15 @@ GNUNET_CONFIGURATION_get_value_filename (const struct | |||
954 | */ | 942 | */ |
955 | int | 943 | int |
956 | GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle | 944 | GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle |
957 | *cfg, const char *section, | 945 | *cfg, const char *section, |
958 | const char *option) | 946 | const char *option) |
959 | { | 947 | { |
960 | static const char *yesno[] = { "YES", "NO", NULL }; | 948 | static const char *yesno[] = { "YES", "NO", NULL }; |
961 | const char *val; | 949 | const char *val; |
962 | int ret; | 950 | int ret; |
963 | 951 | ||
964 | ret = | 952 | ret = |
965 | GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val); | 953 | GNUNET_CONFIGURATION_get_value_choice (cfg, section, option, yesno, &val); |
966 | if (ret == GNUNET_SYSERR) | 954 | if (ret == GNUNET_SYSERR) |
967 | return ret; | 955 | return ret; |
968 | if (val == yesno[0]) | 956 | if (val == yesno[0]) |
@@ -983,11 +971,11 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle | |||
983 | */ | 971 | */ |
984 | int | 972 | int |
985 | GNUNET_CONFIGURATION_iterate_value_filenames (const struct | 973 | GNUNET_CONFIGURATION_iterate_value_filenames (const struct |
986 | GNUNET_CONFIGURATION_Handle | 974 | GNUNET_CONFIGURATION_Handle *cfg, |
987 | *cfg, const char *section, | 975 | const char *section, |
988 | const char *option, | 976 | const char *option, |
989 | GNUNET_FileNameCallback cb, | 977 | GNUNET_FileNameCallback cb, |
990 | void *cb_cls) | 978 | void *cb_cls) |
991 | { | 979 | { |
992 | char *list; | 980 | char *list; |
993 | char *pos; | 981 | char *pos; |
@@ -1002,46 +990,46 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct | |||
1002 | ret = 0; | 990 | ret = 0; |
1003 | pos = list; | 991 | pos = list; |
1004 | while (1) | 992 | while (1) |
993 | { | ||
994 | while (pos[0] == ' ') | ||
995 | pos++; | ||
996 | if (strlen (pos) == 0) | ||
997 | break; | ||
998 | end = pos + 1; | ||
999 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1005 | { | 1000 | { |
1006 | while (pos[0] == ' ') | 1001 | if (end[0] == '\\') |
1007 | pos++; | 1002 | { |
1008 | if (strlen (pos) == 0) | 1003 | switch (end[1]) |
1009 | break; | 1004 | { |
1010 | end = pos + 1; | 1005 | case '\\': |
1011 | while ((end[0] != ' ') && (end[0] != '\0')) | 1006 | case ' ': |
1012 | { | 1007 | memmove (end, &end[1], strlen (&end[1]) + 1); |
1013 | if (end[0] == '\\') | 1008 | case '\0': |
1014 | { | 1009 | /* illegal, but just keep it */ |
1015 | switch (end[1]) | 1010 | break; |
1016 | { | 1011 | default: |
1017 | case '\\': | 1012 | /* illegal, but just ignore that there was a '/' */ |
1018 | case ' ': | 1013 | break; |
1019 | memmove (end, &end[1], strlen (&end[1]) + 1); | 1014 | } |
1020 | case '\0': | 1015 | } |
1021 | /* illegal, but just keep it */ | 1016 | end++; |
1022 | break; | ||
1023 | default: | ||
1024 | /* illegal, but just ignore that there was a '/' */ | ||
1025 | break; | ||
1026 | } | ||
1027 | } | ||
1028 | end++; | ||
1029 | } | ||
1030 | old = end[0]; | ||
1031 | end[0] = '\0'; | ||
1032 | if (strlen (pos) > 0) | ||
1033 | { | ||
1034 | ret++; | ||
1035 | if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos))) | ||
1036 | { | ||
1037 | ret = GNUNET_SYSERR; | ||
1038 | break; | ||
1039 | } | ||
1040 | } | ||
1041 | if (old == '\0') | ||
1042 | break; | ||
1043 | pos = end + 1; | ||
1044 | } | 1017 | } |
1018 | old = end[0]; | ||
1019 | end[0] = '\0'; | ||
1020 | if (strlen (pos) > 0) | ||
1021 | { | ||
1022 | ret++; | ||
1023 | if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos))) | ||
1024 | { | ||
1025 | ret = GNUNET_SYSERR; | ||
1026 | break; | ||
1027 | } | ||
1028 | } | ||
1029 | if (old == '\0') | ||
1030 | break; | ||
1031 | pos = end + 1; | ||
1032 | } | ||
1045 | GNUNET_free (list); | 1033 | GNUNET_free (list); |
1046 | return ret; | 1034 | return ret; |
1047 | } | 1035 | } |
@@ -1065,21 +1053,21 @@ escape_name (const char *value) | |||
1065 | rpos = value; | 1053 | rpos = value; |
1066 | wpos = escaped; | 1054 | wpos = escaped; |
1067 | while (rpos[0] != '\0') | 1055 | while (rpos[0] != '\0') |
1056 | { | ||
1057 | switch (rpos[0]) | ||
1068 | { | 1058 | { |
1069 | switch (rpos[0]) | 1059 | case '\\': |
1070 | { | 1060 | case ' ': |
1071 | case '\\': | 1061 | wpos[0] = '\\'; |
1072 | case ' ': | 1062 | wpos[1] = rpos[0]; |
1073 | wpos[0] = '\\'; | 1063 | wpos += 2; |
1074 | wpos[1] = rpos[0]; | 1064 | break; |
1075 | wpos += 2; | 1065 | default: |
1076 | break; | 1066 | wpos[0] = rpos[0]; |
1077 | default: | 1067 | wpos++; |
1078 | wpos[0] = rpos[0]; | ||
1079 | wpos++; | ||
1080 | } | ||
1081 | rpos++; | ||
1082 | } | 1068 | } |
1069 | rpos++; | ||
1070 | } | ||
1083 | return escaped; | 1071 | return escaped; |
1084 | } | 1072 | } |
1085 | 1073 | ||
@@ -1114,9 +1102,9 @@ test_match (void *cls, const char *fn) | |||
1114 | */ | 1102 | */ |
1115 | int | 1103 | int |
1116 | GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle | 1104 | GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle |
1117 | *cfg, const char *section, | 1105 | *cfg, const char *section, |
1118 | const char *option, | 1106 | const char *option, |
1119 | const char *value) | 1107 | const char *value) |
1120 | { | 1108 | { |
1121 | char *escaped; | 1109 | char *escaped; |
1122 | char *old; | 1110 | char *old; |
@@ -1124,9 +1112,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle | |||
1124 | 1112 | ||
1125 | if (GNUNET_SYSERR == | 1113 | if (GNUNET_SYSERR == |
1126 | GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option, | 1114 | GNUNET_CONFIGURATION_iterate_value_filenames (cfg, section, option, |
1127 | &test_match, | 1115 | &test_match, |
1128 | (void *) value)) | 1116 | (void *) value)) |
1129 | return GNUNET_NO; /* already exists */ | 1117 | return GNUNET_NO; /* already exists */ |
1130 | if (GNUNET_OK != | 1118 | if (GNUNET_OK != |
1131 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) | 1119 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &old)) |
1132 | old = GNUNET_strdup (""); | 1120 | old = GNUNET_strdup (""); |
@@ -1158,9 +1146,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle | |||
1158 | */ | 1146 | */ |
1159 | int | 1147 | int |
1160 | GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle | 1148 | GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle |
1161 | *cfg, const char *section, | 1149 | *cfg, const char *section, |
1162 | const char *option, | 1150 | const char *option, |
1163 | const char *value) | 1151 | const char *value) |
1164 | { | 1152 | { |
1165 | char *list; | 1153 | char *list; |
1166 | char *pos; | 1154 | char *pos; |
@@ -1174,55 +1162,55 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle | |||
1174 | match = escape_name (value); | 1162 | match = escape_name (value); |
1175 | pos = list; | 1163 | pos = list; |
1176 | while (1) | 1164 | while (1) |
1165 | { | ||
1166 | while (pos[0] == ' ') | ||
1167 | pos++; | ||
1168 | if (strlen (pos) == 0) | ||
1169 | break; | ||
1170 | end = pos + 1; | ||
1171 | while ((end[0] != ' ') && (end[0] != '\0')) | ||
1172 | { | ||
1173 | if (end[0] == '\\') | ||
1174 | { | ||
1175 | switch (end[1]) | ||
1176 | { | ||
1177 | case '\\': | ||
1178 | case ' ': | ||
1179 | end++; | ||
1180 | break; | ||
1181 | case '\0': | ||
1182 | /* illegal, but just keep it */ | ||
1183 | break; | ||
1184 | default: | ||
1185 | /* illegal, but just ignore that there was a '/' */ | ||
1186 | break; | ||
1187 | } | ||
1188 | } | ||
1189 | end++; | ||
1190 | } | ||
1191 | old = end[0]; | ||
1192 | end[0] = '\0'; | ||
1193 | if (0 == strcmp (pos, match)) | ||
1177 | { | 1194 | { |
1178 | while (pos[0] == ' ') | 1195 | if (old != '\0') |
1179 | pos++; | 1196 | memmove (pos, &end[1], strlen (&end[1]) + 1); |
1180 | if (strlen (pos) == 0) | 1197 | else |
1181 | break; | 1198 | { |
1182 | end = pos + 1; | 1199 | if (pos != list) |
1183 | while ((end[0] != ' ') && (end[0] != '\0')) | 1200 | pos[-1] = '\0'; |
1184 | { | 1201 | else |
1185 | if (end[0] == '\\') | 1202 | pos[0] = '\0'; |
1186 | { | 1203 | } |
1187 | switch (end[1]) | 1204 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list); |
1188 | { | 1205 | GNUNET_free (list); |
1189 | case '\\': | 1206 | GNUNET_free (match); |
1190 | case ' ': | 1207 | return GNUNET_OK; |
1191 | end++; | ||
1192 | break; | ||
1193 | case '\0': | ||
1194 | /* illegal, but just keep it */ | ||
1195 | break; | ||
1196 | default: | ||
1197 | /* illegal, but just ignore that there was a '/' */ | ||
1198 | break; | ||
1199 | } | ||
1200 | } | ||
1201 | end++; | ||
1202 | } | ||
1203 | old = end[0]; | ||
1204 | end[0] = '\0'; | ||
1205 | if (0 == strcmp (pos, match)) | ||
1206 | { | ||
1207 | if (old != '\0') | ||
1208 | memmove (pos, &end[1], strlen (&end[1]) + 1); | ||
1209 | else | ||
1210 | { | ||
1211 | if (pos != list) | ||
1212 | pos[-1] = '\0'; | ||
1213 | else | ||
1214 | pos[0] = '\0'; | ||
1215 | } | ||
1216 | GNUNET_CONFIGURATION_set_value_string (cfg, section, option, list); | ||
1217 | GNUNET_free (list); | ||
1218 | GNUNET_free (match); | ||
1219 | return GNUNET_OK; | ||
1220 | } | ||
1221 | if (old == '\0') | ||
1222 | break; | ||
1223 | end[0] = old; | ||
1224 | pos = end + 1; | ||
1225 | } | 1208 | } |
1209 | if (old == '\0') | ||
1210 | break; | ||
1211 | end[0] = old; | ||
1212 | pos = end + 1; | ||
1213 | } | ||
1226 | GNUNET_free (list); | 1214 | GNUNET_free (list); |
1227 | GNUNET_free (match); | 1215 | GNUNET_free (match); |
1228 | return GNUNET_NO; | 1216 | return GNUNET_NO; |
@@ -1237,8 +1225,7 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle | |||
1237 | * @return GNUNET_OK on success | 1225 | * @return GNUNET_OK on success |
1238 | */ | 1226 | */ |
1239 | static int | 1227 | static int |
1240 | parse_configuration_file (void *cls, | 1228 | parse_configuration_file (void *cls, const char *filename) |
1241 | const char *filename) | ||
1242 | { | 1229 | { |
1243 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1230 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1244 | int ret; | 1231 | int ret; |
@@ -1258,7 +1245,7 @@ parse_configuration_file (void *cls, | |||
1258 | */ | 1245 | */ |
1259 | int | 1246 | int |
1260 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | 1247 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, |
1261 | const char *filename) | 1248 | const char *filename) |
1262 | { | 1249 | { |
1263 | char *baseconfig; | 1250 | char *baseconfig; |
1264 | char *ipath; | 1251 | char *ipath; |
@@ -1267,29 +1254,26 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1267 | if (ipath == NULL) | 1254 | if (ipath == NULL) |
1268 | return GNUNET_SYSERR; | 1255 | return GNUNET_SYSERR; |
1269 | baseconfig = NULL; | 1256 | baseconfig = NULL; |
1270 | GNUNET_asprintf (&baseconfig, "%s%s", ipath, | 1257 | GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d"); |
1271 | "config.d"); | ||
1272 | GNUNET_free (ipath); | 1258 | GNUNET_free (ipath); |
1273 | if (GNUNET_SYSERR == | 1259 | if (GNUNET_SYSERR == |
1274 | GNUNET_DISK_directory_scan (baseconfig, | 1260 | GNUNET_DISK_directory_scan (baseconfig, &parse_configuration_file, cfg)) |
1275 | &parse_configuration_file, | ||
1276 | cfg)) | ||
1277 | { | 1261 | { |
1278 | GNUNET_free (baseconfig); | 1262 | GNUNET_free (baseconfig); |
1279 | return GNUNET_SYSERR; /* no configuration at all found */ | 1263 | return GNUNET_SYSERR; /* no configuration at all found */ |
1280 | } | 1264 | } |
1281 | GNUNET_free (baseconfig); | 1265 | GNUNET_free (baseconfig); |
1282 | if ( (filename != NULL) && | 1266 | if ((filename != NULL) && |
1283 | (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename)) ) | 1267 | (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) |
1284 | { | 1268 | { |
1285 | /* specified configuration not found */ | 1269 | /* specified configuration not found */ |
1286 | return GNUNET_SYSERR; | 1270 | return GNUNET_SYSERR; |
1287 | } | 1271 | } |
1288 | if (((GNUNET_YES != | 1272 | if (((GNUNET_YES != |
1289 | GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) && | 1273 | GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "DEFAULTCONFIG"))) && |
1290 | (filename != NULL)) | 1274 | (filename != NULL)) |
1291 | GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", | 1275 | GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", |
1292 | filename); | 1276 | filename); |
1293 | if ((GNUNET_YES == | 1277 | if ((GNUNET_YES == |
1294 | GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) && | 1278 | GNUNET_CONFIGURATION_have_value (cfg, "TESTING", "WEAKRANDOM")) && |
1295 | (GNUNET_YES == | 1279 | (GNUNET_YES == |