aboutsummaryrefslogtreecommitdiff
path: root/src/util/configuration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r--src/util/configuration.c385
1 files changed, 52 insertions, 333 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index e5c01f81f..ecdcb3d53 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -93,7 +93,7 @@ struct GNUNET_CONFIGURATION_Handle
93 * #GNUNET_NO if clean, #GNUNET_YES if dirty, 93 * #GNUNET_NO if clean, #GNUNET_YES if dirty,
94 * #GNUNET_SYSERR on error (i.e. last save failed) 94 * #GNUNET_SYSERR on error (i.e. last save failed)
95 */ 95 */
96 int dirty; 96 enum GNUNET_GenericReturnValue dirty;
97}; 97};
98 98
99 99
@@ -109,11 +109,6 @@ struct DiffHandle
109}; 109};
110 110
111 111
112/**
113 * Create a GNUNET_CONFIGURATION_Handle.
114 *
115 * @return fresh configuration object
116 */
117struct GNUNET_CONFIGURATION_Handle * 112struct GNUNET_CONFIGURATION_Handle *
118GNUNET_CONFIGURATION_create () 113GNUNET_CONFIGURATION_create ()
119{ 114{
@@ -199,11 +194,6 @@ GNUNET_CONFIGURATION_create ()
199} 194}
200 195
201 196
202/**
203 * Destroy configuration object.
204 *
205 * @param cfg configuration to destroy
206 */
207void 197void
208GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) 198GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
209{ 199{
@@ -215,24 +205,13 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
215} 205}
216 206
217 207
218/** 208enum GNUNET_GenericReturnValue
219 * Parse a configuration file @a filename and run the function
220 * @a cb with the resulting configuration object. Then free the
221 * configuration object and return the status value from @a cb.
222 *
223 * @param filename configuration to parse, NULL for "default"
224 * @param cb function to run
225 * @param cb_cls closure for @a cb
226 * @return #GNUNET_SYSERR if parsing the configuration failed,
227 * otherwise return value from @a cb.
228 */
229int
230GNUNET_CONFIGURATION_parse_and_run (const char *filename, 209GNUNET_CONFIGURATION_parse_and_run (const char *filename,
231 GNUNET_CONFIGURATION_Callback cb, 210 GNUNET_CONFIGURATION_Callback cb,
232 void *cb_cls) 211 void *cb_cls)
233{ 212{
234 struct GNUNET_CONFIGURATION_Handle *cfg; 213 struct GNUNET_CONFIGURATION_Handle *cfg;
235 int ret; 214 enum GNUNET_GenericReturnValue ret;
236 215
237 cfg = GNUNET_CONFIGURATION_create (); 216 cfg = GNUNET_CONFIGURATION_create ();
238 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename)) 217 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename))
@@ -247,18 +226,7 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename,
247} 226}
248 227
249 228
250/** 229enum GNUNET_GenericReturnValue
251 * De-serializes configuration
252 *
253 * @param cfg configuration to update
254 * @param mem the memory block of serialized configuration
255 * @param size the size of the memory block
256 * @param basedir set to path from which we recursively load configuration
257 * from inlined configurations; NULL if not and raise warnings
258 * when we come across them
259 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
260 */
261int
262GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, 230GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
263 const char *mem, 231 const char *mem,
264 size_t size, 232 size_t size,
@@ -273,7 +241,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
273 size_t to_read; 241 size_t to_read;
274 size_t i; 242 size_t i;
275 int emptyline; 243 int emptyline;
276 int ret; 244 enum GNUNET_GenericReturnValue ret;
277 char *section; 245 char *section;
278 char *eq; 246 char *eq;
279 char *tag; 247 char *tag;
@@ -411,15 +379,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,
411} 379}
412 380
413 381
414/** 382enum GNUNET_GenericReturnValue
415 * Parse a configuration file, add all of the options in the
416 * file to the configuration environment.
417 *
418 * @param cfg configuration to update
419 * @param filename name of the configuration file
420 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
421 */
422int
423GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, 383GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
424 const char *filename) 384 const char *filename)
425{ 385{
@@ -429,7 +389,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
429 char *mem; 389 char *mem;
430 char *endsep; 390 char *endsep;
431 int dirty; 391 int dirty;
432 int ret; 392 enum GNUNET_GenericReturnValue ret;
433 ssize_t sret; 393 ssize_t sret;
434 394
435 fn = GNUNET_STRINGS_filename_expand (filename); 395 fn = GNUNET_STRINGS_filename_expand (filename);
@@ -476,28 +436,13 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
476} 436}
477 437
478 438
479/** 439enum GNUNET_GenericReturnValue
480 * Test if there are configuration options that were
481 * changed since the last save.
482 *
483 * @param cfg configuration to inspect
484 * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed)
485 */
486int
487GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) 440GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
488{ 441{
489 return cfg->dirty; 442 return cfg->dirty;
490} 443}
491 444
492 445
493/**
494 * Serializes the given configuration.
495 *
496 * @param cfg configuration to serialize
497 * @param size will be set to the size of the serialized memory block
498 * @return the memory block where the serialized configuration is
499 * present. This memory should be freed by the caller
500 */
501char * 446char *
502GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, 447GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
503 size_t *size) 448 size_t *size)
@@ -580,21 +525,13 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg,
580} 525}
581 526
582 527
583/** 528enum GNUNET_GenericReturnValue
584 * Write configuration file.
585 *
586 * @param cfg configuration to write
587 * @param filename where to write the configuration
588 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
589 */
590int
591GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, 529GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
592 const char *filename) 530 const char *filename)
593{ 531{
594 char *fn; 532 char *fn;
595 char *cfg_buf; 533 char *cfg_buf;
596 size_t size; 534 size_t size;
597 ssize_t sret;
598 535
599 fn = GNUNET_STRINGS_filename_expand (filename); 536 fn = GNUNET_STRINGS_filename_expand (filename);
600 if (fn == NULL) 537 if (fn == NULL)
@@ -604,15 +541,17 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
604 GNUNET_free (fn); 541 GNUNET_free (fn);
605 return GNUNET_SYSERR; 542 return GNUNET_SYSERR;
606 } 543 }
607 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); 544 cfg_buf = GNUNET_CONFIGURATION_serialize (cfg,
608 sret = GNUNET_DISK_fn_write (fn, 545 &size);
609 cfg_buf, 546 (void) GNUNET_DISK_directory_remove (fn);
610 size, 547 if (GNUNET_OK !=
611 GNUNET_DISK_PERM_USER_READ 548 GNUNET_DISK_fn_write (fn,
612 | GNUNET_DISK_PERM_USER_WRITE 549 cfg_buf,
613 | GNUNET_DISK_PERM_GROUP_READ 550 size,
614 | GNUNET_DISK_PERM_GROUP_WRITE); 551 GNUNET_DISK_PERM_USER_READ
615 if ((sret < 0) || (size != (size_t) sret)) 552 | GNUNET_DISK_PERM_USER_WRITE
553 | GNUNET_DISK_PERM_GROUP_READ
554 | GNUNET_DISK_PERM_GROUP_WRITE))
616 { 555 {
617 GNUNET_free (fn); 556 GNUNET_free (fn);
618 GNUNET_free (cfg_buf); 557 GNUNET_free (cfg_buf);
@@ -629,36 +568,25 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
629} 568}
630 569
631 570
632/**
633 * Iterate over all options in the configuration.
634 *
635 * @param cfg configuration to inspect
636 * @param iter function to call on each option
637 * @param iter_cls closure for @a iter
638 */
639void 571void
640GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 572GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
641 GNUNET_CONFIGURATION_Iterator iter, 573 GNUNET_CONFIGURATION_Iterator iter,
642 void *iter_cls) 574 void *iter_cls)
643{ 575{
644 struct ConfigSection *spos; 576 for (struct ConfigSection *spos = cfg->sections;
645 struct ConfigEntry *epos; 577 NULL != spos;
646 578 spos = spos->next)
647 for (spos = cfg->sections; NULL != spos; spos = spos->next) 579 for (struct ConfigEntry *epos = spos->entries;
648 for (epos = spos->entries; NULL != epos; epos = epos->next) 580 NULL != epos;
581 epos = epos->next)
649 if (NULL != epos->val) 582 if (NULL != epos->val)
650 iter (iter_cls, spos->name, epos->key, epos->val); 583 iter (iter_cls,
584 spos->name,
585 epos->key,
586 epos->val);
651} 587}
652 588
653 589
654/**
655 * Iterate over values of a section in the configuration.
656 *
657 * @param cfg configuration to inspect
658 * @param section the section
659 * @param iter function to call on each option
660 * @param iter_cls closure for @a iter
661 */
662void 590void
663GNUNET_CONFIGURATION_iterate_section_values ( 591GNUNET_CONFIGURATION_iterate_section_values (
664 const struct GNUNET_CONFIGURATION_Handle *cfg, 592 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -680,13 +608,6 @@ GNUNET_CONFIGURATION_iterate_section_values (
680} 608}
681 609
682 610
683/**
684 * Iterate over all sections in the configuration.
685 *
686 * @param cfg configuration to inspect
687 * @param iter function to call on each section
688 * @param iter_cls closure for @a iter
689 */
690void 611void
691GNUNET_CONFIGURATION_iterate_sections ( 612GNUNET_CONFIGURATION_iterate_sections (
692 const struct GNUNET_CONFIGURATION_Handle *cfg, 613 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -706,12 +627,6 @@ GNUNET_CONFIGURATION_iterate_sections (
706} 627}
707 628
708 629
709/**
710 * Remove the given section and all options in it.
711 *
712 * @param cfg configuration to inspect
713 * @param section name of the section to remove
714 */
715void 630void
716GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, 631GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg,
717 const char *section) 632 const char *section)
@@ -769,12 +684,6 @@ copy_entry (void *cls,
769} 684}
770 685
771 686
772/**
773 * Duplicate an existing configuration object.
774 *
775 * @param cfg configuration to duplicate
776 * @return duplicate configuration
777 */
778struct GNUNET_CONFIGURATION_Handle * 687struct GNUNET_CONFIGURATION_Handle *
779GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) 688GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
780{ 689{
@@ -858,13 +767,6 @@ compare_entries (void *cls,
858} 767}
859 768
860 769
861/**
862 * Compute configuration with only entries that have been changed
863 *
864 * @param cfg_default original configuration
865 * @param cfg_new new configuration
866 * @return configuration with only the differences, never NULL
867 */
868struct GNUNET_CONFIGURATION_Handle * 770struct GNUNET_CONFIGURATION_Handle *
869GNUNET_CONFIGURATION_get_diff ( 771GNUNET_CONFIGURATION_get_diff (
870 const struct GNUNET_CONFIGURATION_Handle *cfg_default, 772 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
@@ -879,15 +781,7 @@ GNUNET_CONFIGURATION_get_diff (
879} 781}
880 782
881 783
882/** 784enum GNUNET_GenericReturnValue
883 * Write only configuration entries that have been changed to configuration file
884 *
885 * @param cfg_default default configuration
886 * @param cfg_new new configuration
887 * @param filename where to write the configuration diff between default and new
888 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
889 */
890int
891GNUNET_CONFIGURATION_write_diffs ( 785GNUNET_CONFIGURATION_write_diffs (
892 const struct GNUNET_CONFIGURATION_Handle *cfg_default, 786 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
893 const struct GNUNET_CONFIGURATION_Handle *cfg_new, 787 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
@@ -903,14 +797,6 @@ GNUNET_CONFIGURATION_write_diffs (
903} 797}
904 798
905 799
906/**
907 * Set a configuration value that should be a string.
908 *
909 * @param cfg configuration to update
910 * @param section section of interest
911 * @param option option of interest
912 * @param value value to set
913 */
914void 800void
915GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, 801GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
916 const char *section, 802 const char *section,
@@ -953,14 +839,6 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg,
953} 839}
954 840
955 841
956/**
957 * Set a configuration value that should be a number.
958 *
959 * @param cfg configuration to update
960 * @param section section of interest
961 * @param option option of interest
962 * @param number value to set
963 */
964void 842void
965GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, 843GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
966 const char *section, 844 const char *section,
@@ -974,16 +852,7 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
974} 852}
975 853
976 854
977/** 855enum GNUNET_GenericReturnValue
978 * Get a configuration value that should be a number.
979 *
980 * @param cfg configuration to inspect
981 * @param section section of interest
982 * @param option option of interest
983 * @param number where to store the numeric value of the option
984 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
985 */
986int
987GNUNET_CONFIGURATION_get_value_number ( 856GNUNET_CONFIGURATION_get_value_number (
988 const struct GNUNET_CONFIGURATION_Handle *cfg, 857 const struct GNUNET_CONFIGURATION_Handle *cfg,
989 const char *section, 858 const char *section,
@@ -1003,16 +872,7 @@ GNUNET_CONFIGURATION_get_value_number (
1003} 872}
1004 873
1005 874
1006/** 875enum GNUNET_GenericReturnValue
1007 * Get a configuration value that should be a floating point number.
1008 *
1009 * @param cfg configuration to inspect
1010 * @param section section of interest
1011 * @param option option of interest
1012 * @param number where to store the floating value of the option
1013 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1014 */
1015int
1016GNUNET_CONFIGURATION_get_value_float ( 876GNUNET_CONFIGURATION_get_value_float (
1017 const struct GNUNET_CONFIGURATION_Handle *cfg, 877 const struct GNUNET_CONFIGURATION_Handle *cfg,
1018 const char *section, 878 const char *section,
@@ -1032,16 +892,7 @@ GNUNET_CONFIGURATION_get_value_float (
1032} 892}
1033 893
1034 894
1035/** 895enum GNUNET_GenericReturnValue
1036 * Get a configuration value that should be a relative time.
1037 *
1038 * @param cfg configuration to inspect
1039 * @param section section of interest
1040 * @param option option of interest
1041 * @param time set to the time value stored in the configuration
1042 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1043 */
1044int
1045GNUNET_CONFIGURATION_get_value_time ( 896GNUNET_CONFIGURATION_get_value_time (
1046 const struct GNUNET_CONFIGURATION_Handle *cfg, 897 const struct GNUNET_CONFIGURATION_Handle *cfg,
1047 const char *section, 898 const char *section,
@@ -1065,16 +916,7 @@ GNUNET_CONFIGURATION_get_value_time (
1065} 916}
1066 917
1067 918
1068/** 919enum GNUNET_GenericReturnValue
1069 * Get a configuration value that should be a size in bytes.
1070 *
1071 * @param cfg configuration to inspect
1072 * @param section section of interest
1073 * @param option option of interest
1074 * @param size set to the size in bytes as stored in the configuration
1075 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1076 */
1077int
1078GNUNET_CONFIGURATION_get_value_size ( 920GNUNET_CONFIGURATION_get_value_size (
1079 const struct GNUNET_CONFIGURATION_Handle *cfg, 921 const struct GNUNET_CONFIGURATION_Handle *cfg,
1080 const char *section, 922 const char *section,
@@ -1101,7 +943,7 @@ GNUNET_CONFIGURATION_get_value_size (
1101 * value, or NULL if option is not specified 943 * value, or NULL if option is not specified
1102 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 944 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1103 */ 945 */
1104int 946enum GNUNET_GenericReturnValue
1105GNUNET_CONFIGURATION_get_value_string ( 947GNUNET_CONFIGURATION_get_value_string (
1106 const struct GNUNET_CONFIGURATION_Handle *cfg, 948 const struct GNUNET_CONFIGURATION_Handle *cfg,
1107 const char *section, 949 const char *section,
@@ -1120,19 +962,7 @@ GNUNET_CONFIGURATION_get_value_string (
1120} 962}
1121 963
1122 964
1123/** 965enum GNUNET_GenericReturnValue
1124 * Get a configuration value that should be in a set of
1125 * predefined strings
1126 *
1127 * @param cfg configuration to inspect
1128 * @param section section of interest
1129 * @param option option of interest
1130 * @param choices NULL-terminated list of legal values
1131 * @param value will be set to an entry in the legal list,
1132 * or NULL if option is not specified and no default given
1133 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1134 */
1135int
1136GNUNET_CONFIGURATION_get_value_choice ( 966GNUNET_CONFIGURATION_get_value_choice (
1137 const struct GNUNET_CONFIGURATION_Handle *cfg, 967 const struct GNUNET_CONFIGURATION_Handle *cfg,
1138 const char *section, 968 const char *section,
@@ -1163,19 +993,7 @@ GNUNET_CONFIGURATION_get_value_choice (
1163} 993}
1164 994
1165 995
1166/** 996enum GNUNET_GenericReturnValue
1167 * Get crockford32-encoded fixed-size binary data from a configuration.
1168 *
1169 * @param cfg configuration to access
1170 * @param section section to access
1171 * @param option option to access
1172 * @param buf where to store the decoded binary result
1173 * @param buf_size exact number of bytes to store in @a buf
1174 * @return #GNUNET_OK on success
1175 * #GNUNET_NO is the value does not exist
1176 * #GNUNET_SYSERR on decoding error
1177 */
1178int
1179GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, 997GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
1180 const char *section, 998 const char *section,
1181 const char *option, 999 const char *option,
@@ -1207,15 +1025,7 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
1207} 1025}
1208 1026
1209 1027
1210/** 1028enum GNUNET_GenericReturnValue
1211 * Test if we have a value for a particular option
1212 *
1213 * @param cfg configuration to inspect
1214 * @param section section of interest
1215 * @param option option of interest
1216 * @return #GNUNET_YES if so, #GNUNET_NO if not.
1217 */
1218int
1219GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, 1029GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
1220 const char *section, 1030 const char *section,
1221 const char *option) 1031 const char *option)
@@ -1390,22 +1200,6 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg,
1390} 1200}
1391 1201
1392 1202
1393/**
1394 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
1395 * where either in the "PATHS" section or the environment "FOO" is
1396 * set to "DIRECTORY". We also support default expansion,
1397 * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is
1398 * set in PATHS or the environment, and otherwise to "default". Note
1399 * that "default" itself can also be a $-expression, thus
1400 * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined
1401 * to VAR2.
1402 *
1403 * @param cfg configuration to use for path expansion
1404 * @param orig string to $-expand (will be freed!). Note that multiple
1405 * $-expressions can be present in this string. They will all be
1406 * $-expanded.
1407 * @return $-expanded string
1408 */
1409char * 1203char *
1410GNUNET_CONFIGURATION_expand_dollar ( 1204GNUNET_CONFIGURATION_expand_dollar (
1411 const struct GNUNET_CONFIGURATION_Handle *cfg, 1205 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -1431,17 +1225,7 @@ GNUNET_CONFIGURATION_expand_dollar (
1431} 1225}
1432 1226
1433 1227
1434/** 1228enum GNUNET_GenericReturnValue
1435 * Get a configuration value that should be a string.
1436 *
1437 * @param cfg configuration to inspect
1438 * @param section section of interest
1439 * @param option option of interest
1440 * @param value will be set to a freshly allocated configuration
1441 * value, or NULL if option is not specified
1442 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1443 */
1444int
1445GNUNET_CONFIGURATION_get_value_filename ( 1229GNUNET_CONFIGURATION_get_value_filename (
1446 const struct GNUNET_CONFIGURATION_Handle *cfg, 1230 const struct GNUNET_CONFIGURATION_Handle *cfg,
1447 const char *section, 1231 const char *section,
@@ -1466,16 +1250,7 @@ GNUNET_CONFIGURATION_get_value_filename (
1466} 1250}
1467 1251
1468 1252
1469/** 1253enum GNUNET_GenericReturnValue
1470 * Get a configuration value that should be in a set of
1471 * "YES" or "NO".
1472 *
1473 * @param cfg configuration to inspect
1474 * @param section section of interest
1475 * @param option option of interest
1476 * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR
1477 */
1478int
1479GNUNET_CONFIGURATION_get_value_yesno ( 1254GNUNET_CONFIGURATION_get_value_yesno (
1480 const struct GNUNET_CONFIGURATION_Handle *cfg, 1255 const struct GNUNET_CONFIGURATION_Handle *cfg,
1481 const char *section, 1256 const char *section,
@@ -1495,16 +1270,6 @@ GNUNET_CONFIGURATION_get_value_yesno (
1495} 1270}
1496 1271
1497 1272
1498/**
1499 * Iterate over the set of filenames stored in a configuration value.
1500 *
1501 * @param cfg configuration to inspect
1502 * @param section section of interest
1503 * @param option option of interest
1504 * @param cb function to call on each filename
1505 * @param cb_cls closure for @a cb
1506 * @return number of filenames iterated over, -1 on error
1507 */
1508int 1273int
1509GNUNET_CONFIGURATION_iterate_value_filenames ( 1274GNUNET_CONFIGURATION_iterate_value_filenames (
1510 const struct GNUNET_CONFIGURATION_Handle *cfg, 1275 const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -1618,7 +1383,7 @@ escape_name (const char *value)
1618 * @param fn filename we are currently looking at 1383 * @param fn filename we are currently looking at
1619 * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do 1384 * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do
1620 */ 1385 */
1621static int 1386static enum GNUNET_GenericReturnValue
1622test_match (void *cls, const char *fn) 1387test_match (void *cls, const char *fn)
1623{ 1388{
1624 const char *of = cls; 1389 const char *of = cls;
@@ -1627,19 +1392,7 @@ test_match (void *cls, const char *fn)
1627} 1392}
1628 1393
1629 1394
1630/** 1395enum GNUNET_GenericReturnValue
1631 * Append a filename to a configuration value that
1632 * represents a list of filenames
1633 *
1634 * @param cfg configuration to update
1635 * @param section section of interest
1636 * @param option option of interest
1637 * @param value filename to append
1638 * @return #GNUNET_OK on success,
1639 * #GNUNET_NO if the filename already in the list
1640 * #GNUNET_SYSERR on error
1641 */
1642int
1643GNUNET_CONFIGURATION_append_value_filename ( 1396GNUNET_CONFIGURATION_append_value_filename (
1644 struct GNUNET_CONFIGURATION_Handle *cfg, 1397 struct GNUNET_CONFIGURATION_Handle *cfg,
1645 const char *section, 1398 const char *section,
@@ -1674,19 +1427,7 @@ GNUNET_CONFIGURATION_append_value_filename (
1674} 1427}
1675 1428
1676 1429
1677/** 1430enum GNUNET_GenericReturnValue
1678 * Remove a filename from a configuration value that
1679 * represents a list of filenames
1680 *
1681 * @param cfg configuration to update
1682 * @param section section of interest
1683 * @param option option of interest
1684 * @param value filename to remove
1685 * @return #GNUNET_OK on success,
1686 * #GNUNET_NO if the filename is not in the list,
1687 * #GNUNET_SYSERR on error
1688 */
1689int
1690GNUNET_CONFIGURATION_remove_value_filename ( 1431GNUNET_CONFIGURATION_remove_value_filename (
1691 struct GNUNET_CONFIGURATION_Handle *cfg, 1432 struct GNUNET_CONFIGURATION_Handle *cfg,
1692 const char *section, 1433 const char *section,
@@ -1771,12 +1512,11 @@ GNUNET_CONFIGURATION_remove_value_filename (
1771 * @param filename file to parse 1512 * @param filename file to parse
1772 * @return #GNUNET_OK on success 1513 * @return #GNUNET_OK on success
1773 */ 1514 */
1774static int 1515static enum GNUNET_GenericReturnValue
1775parse_configuration_file (void *cls, const char *filename) 1516parse_configuration_file (void *cls, const char *filename)
1776{ 1517{
1777 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 1518 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
1778 char *ext; 1519 char *ext;
1779 int ret;
1780 1520
1781 /* Examine file extension */ 1521 /* Examine file extension */
1782 ext = strrchr (filename, '.'); 1522 ext = strrchr (filename, '.');
@@ -1786,20 +1526,11 @@ parse_configuration_file (void *cls, const char *filename)
1786 return GNUNET_OK; 1526 return GNUNET_OK;
1787 } 1527 }
1788 1528
1789 ret = GNUNET_CONFIGURATION_parse (cfg, filename); 1529 return GNUNET_CONFIGURATION_parse (cfg, filename);
1790 return ret;
1791} 1530}
1792 1531
1793 1532
1794/** 1533enum GNUNET_GenericReturnValue
1795 * Load default configuration. This function will parse the
1796 * defaults from the given defaults_d directory.
1797 *
1798 * @param cfg configuration to update
1799 * @param defaults_d directory with the defaults
1800 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1801 */
1802int
1803GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, 1534GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
1804 const char *defaults_d) 1535 const char *defaults_d)
1805{ 1536{
@@ -1810,43 +1541,31 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg,
1810} 1541}
1811 1542
1812 1543
1813/**
1814 * Return GNUnet's default configuration. A new configuration is allocated
1815 * each time and it's up to the caller to destroy it when done. This function
1816 * returns GNUnet's configuration even when #GNUNET_OS_init has been called
1817 * with a value different from #GNUNET_OS_project_data_default.
1818 *
1819 * @return a freshly allocated configuration
1820 */
1821struct GNUNET_CONFIGURATION_Handle * 1544struct GNUNET_CONFIGURATION_Handle *
1822GNUNET_CONFIGURATION_default (void) 1545GNUNET_CONFIGURATION_default (void)
1823{ 1546{
1824 const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); 1547 const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get ();
1825 const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default (); 1548 const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default ();
1826
1827 GNUNET_OS_init (dpd);
1828
1829 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create ();
1830 const char *xdg = getenv ("XDG_CONFIG_HOME"); 1549 const char *xdg = getenv ("XDG_CONFIG_HOME");
1831 char *cfgname = NULL; 1550 char *cfgname = NULL;
1551 struct GNUNET_CONFIGURATION_Handle *cfg;
1832 1552
1553 GNUNET_OS_init (dpd);
1554 cfg = GNUNET_CONFIGURATION_create ();
1833 if (NULL != xdg) 1555 if (NULL != xdg)
1834 GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file); 1556 GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file);
1835 else 1557 else
1836 cfgname = GNUNET_strdup (pd->user_config_file); 1558 cfgname = GNUNET_strdup (pd->user_config_file);
1837 1559 if (GNUNET_OK !=
1838 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgname)) 1560 GNUNET_CONFIGURATION_load (cfg, cfgname))
1839 { 1561 {
1840 GNUNET_OS_init (pd); 1562 GNUNET_OS_init (pd);
1841 GNUNET_CONFIGURATION_destroy (cfg); 1563 GNUNET_CONFIGURATION_destroy (cfg);
1842 GNUNET_free (cfgname); 1564 GNUNET_free (cfgname);
1843 return NULL; 1565 return NULL;
1844 } 1566 }
1845
1846 GNUNET_free (cfgname); 1567 GNUNET_free (cfgname);
1847
1848 GNUNET_OS_init (pd); 1568 GNUNET_OS_init (pd);
1849
1850 return cfg; 1569 return cfg;
1851} 1570}
1852 1571