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.c191
1 files changed, 186 insertions, 5 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 8c32618e2..569c4adcf 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -33,6 +33,7 @@
33#include "gnunet_os_lib.h" 33#include "gnunet_os_lib.h"
34#include "gnunet_strings_lib.h" 34#include "gnunet_strings_lib.h"
35 35
36
36/** 37/**
37 * @brief configuration entry 38 * @brief configuration entry
38 */ 39 */
@@ -55,6 +56,7 @@ struct ConfigEntry
55 char *val; 56 char *val;
56}; 57};
57 58
59
58/** 60/**
59 * @brief configuration section 61 * @brief configuration section
60 */ 62 */
@@ -76,6 +78,7 @@ struct ConfigSection
76 char *name; 78 char *name;
77}; 79};
78 80
81
79/** 82/**
80 * @brief configuration data 83 * @brief configuration data
81 */ 84 */
@@ -95,8 +98,11 @@ struct GNUNET_CONFIGURATION_Handle
95 98
96}; 99};
97 100
101
98/** 102/**
99 * Create a GNUNET_CONFIGURATION_Configuration. 103 * Create a GNUNET_CONFIGURATION_Handle.
104 *
105 * @return fresh configuration object
100 */ 106 */
101struct GNUNET_CONFIGURATION_Handle * 107struct GNUNET_CONFIGURATION_Handle *
102GNUNET_CONFIGURATION_create () 108GNUNET_CONFIGURATION_create ()
@@ -104,6 +110,12 @@ GNUNET_CONFIGURATION_create ()
104 return GNUNET_malloc (sizeof (struct GNUNET_CONFIGURATION_Handle)); 110 return GNUNET_malloc (sizeof (struct GNUNET_CONFIGURATION_Handle));
105} 111}
106 112
113
114/**
115 * Destroy configuration object.
116 *
117 * @param cfg configuration to destroy
118 */
107void 119void
108GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) 120GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
109{ 121{
@@ -126,6 +138,15 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
126 GNUNET_free (cfg); 138 GNUNET_free (cfg);
127} 139}
128 140
141
142/**
143 * Parse a configuration file, add all of the options in the
144 * file to the configuration environment.
145 *
146 * @param cfg configuration to update
147 * @param filename name of the configuration file
148 * @return GNUNET_OK on success, GNUNET_SYSERR on error
149 */
129int 150int
130GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, 151GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
131 const char *filename) 152 const char *filename)
@@ -234,12 +255,28 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg,
234 return ret; 255 return ret;
235} 256}
236 257
258
259/**
260 * Test if there are configuration options that were
261 * changed since the last save.
262 *
263 * @param cfg configuration to inspect
264 * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed)
265 */
237int 266int
238GNUNET_CONFIGURATION_test_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) 267GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg)
239{ 268{
240 return cfg->dirty; 269 return cfg->dirty;
241} 270}
242 271
272
273/**
274 * Write configuration file.
275 *
276 * @param cfg configuration to write
277 * @param filename where to write the configuration
278 * @return GNUNET_OK on success, GNUNET_SYSERR on error
279 */
243int 280int
244GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *data, 281GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *data,
245 const char *filename) 282 const char *filename)
@@ -315,6 +352,13 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *data,
315} 352}
316 353
317 354
355/**
356 * Iterate over all options in the configuration.
357 *
358 * @param cfg configuration to inspect
359 * @param iter function to call on each option
360 * @param iter_cls closure for iter
361 */
318void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 362void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
319 GNUNET_CONFIGURATION_Iterator iter, 363 GNUNET_CONFIGURATION_Iterator iter,
320 void *iter_cls) 364 void *iter_cls)
@@ -336,6 +380,14 @@ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg
336} 380}
337 381
338 382
383/**
384 * FIXME.
385 *
386 * @param cls the destination configuration (struct GNUNET_CONFIGURATION_Handle*)
387 * @param section FIXME
388 * @param option FIXME
389 * @param value FIXME
390 */
339static void 391static void
340copy_entry (void *cls, 392copy_entry (void *cls,
341 const char *section, 393 const char *section,
@@ -347,6 +399,12 @@ copy_entry (void *cls,
347} 399}
348 400
349 401
402/**
403 * Duplicate an existing configuration object.
404 *
405 * @param c configuration to duplicate
406 * @return duplicate configuration
407 */
350struct GNUNET_CONFIGURATION_Handle * 408struct GNUNET_CONFIGURATION_Handle *
351GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) 409GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
352{ 410{
@@ -358,6 +416,13 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
358} 416}
359 417
360 418
419/**
420 * FIXME.
421 *
422 * @param data FIXME
423 * @param section FIXME
424 * @return matching entry, NULL if not found
425 */
361static struct ConfigSection * 426static struct ConfigSection *
362findSection (const struct GNUNET_CONFIGURATION_Handle *data, const char *section) 427findSection (const struct GNUNET_CONFIGURATION_Handle *data, const char *section)
363{ 428{
@@ -370,6 +435,14 @@ findSection (const struct GNUNET_CONFIGURATION_Handle *data, const char *section
370} 435}
371 436
372 437
438/**
439 * FIXME.
440 *
441 * @param data FIXME
442 * @param section FIXME
443 * @param key FIXME
444 * @return matching entry, NULL if not found
445 */
373static struct ConfigEntry * 446static struct ConfigEntry *
374findEntry (const struct GNUNET_CONFIGURATION_Handle *data, 447findEntry (const struct GNUNET_CONFIGURATION_Handle *data,
375 const char *section, const char *key) 448 const char *section, const char *key)
@@ -386,6 +459,15 @@ findEntry (const struct GNUNET_CONFIGURATION_Handle *data,
386 return pos; 459 return pos;
387} 460}
388 461
462
463/**
464 * Set a configuration value that should be a string.
465 *
466 * @param cfg configuration to update
467 * @param section section of interest
468 * @param option option of interest
469 * @param value value to set
470 */
389void 471void
390GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle 472GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
391 *data, 473 *data,
@@ -417,6 +499,15 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle
417 sec->entries = e; 499 sec->entries = e;
418} 500}
419 501
502
503/**
504 * Set a configuration value that should be a number.
505 *
506 * @param cfg configuration to update
507 * @param section section of interest
508 * @param option option of interest
509 * @param number value to set
510 */
420void 511void
421GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle 512GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
422 *cfg, const char *section, 513 *cfg, const char *section,
@@ -428,6 +519,16 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
428 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s); 519 GNUNET_CONFIGURATION_set_value_string (cfg, section, option, s);
429} 520}
430 521
522
523/**
524 * Get a configuration value that should be a number.
525 *
526 * @param cfg configuration to inspect
527 * @param section section of interest
528 * @param option option of interest
529 * @param number where to store the numeric value of the option
530 * @return GNUNET_OK on success, GNUNET_SYSERR on error
531 */
431int 532int
432GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle 533GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
433 *cfg, const char *section, 534 *cfg, const char *section,
@@ -444,6 +545,16 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
444 return GNUNET_OK; 545 return GNUNET_OK;
445} 546}
446 547
548
549/**
550 * Get a configuration value that should be a relative time.
551 *
552 * @param cfg configuration to inspect
553 * @param section section of interest
554 * @param option option of interest
555 * @param time set to the time value stored in the configuration
556 * @return GNUNET_OK on success, GNUNET_SYSERR on error
557 */
447int 558int
448GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle 559GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
449 *cfg, const char *section, 560 *cfg, const char *section,
@@ -462,6 +573,17 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
462 return ret; 573 return ret;
463} 574}
464 575
576
577/**
578 * Get a configuration value that should be a string.
579 *
580 * @param cfg configuration to inspect
581 * @param section section of interest
582 * @param option option of interest
583 * @param value will be set to a freshly allocated configuration
584 * value, or NULL if option is not specified
585 * @return GNUNET_OK on success, GNUNET_SYSERR on error
586 */
465int 587int
466GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle 588GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
467 *cfg, const char *section, 589 *cfg, const char *section,
@@ -479,6 +601,19 @@ GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
479 return GNUNET_OK; 601 return GNUNET_OK;
480} 602}
481 603
604
605/**
606 * Get a configuration value that should be in a set of
607 * predefined strings
608 *
609 * @param cfg configuration to inspect
610 * @param section section of interest
611 * @param option option of interest
612 * @param choices NULL-terminated list of legal values
613 * @param value will be set to an entry in the legal list,
614 * or NULL if option is not specified and no default given
615 * @return GNUNET_OK on success, GNUNET_SYSERR on error
616 */
482int 617int
483GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle 618GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
484 *cfg, const char *section, 619 *cfg, const char *section,
@@ -511,8 +646,12 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
511 return GNUNET_OK; 646 return GNUNET_OK;
512} 647}
513 648
649
514/** 650/**
515 * Test if we have a value for a particular option 651 * Test if we have a value for a particular option
652 * @param cfg configuration to inspect
653 * @param section section of interest
654 * @param option option of interest
516 * @return GNUNET_YES if so, GNUNET_NO if not. 655 * @return GNUNET_YES if so, GNUNET_NO if not.
517 */ 656 */
518int 657int
@@ -525,11 +664,13 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
525 return GNUNET_YES; 664 return GNUNET_YES;
526} 665}
527 666
667
528/** 668/**
529 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" 669 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
530 * where either in the "PATHS" section or the environtment 670 * where either in the "PATHS" section or the environtment
531 * "FOO" is set to "DIRECTORY". 671 * "FOO" is set to "DIRECTORY".
532 * 672 *
673 * @param cfg configuration to use for path expansion
533 * @param old string to $-expand (will be freed!) 674 * @param old string to $-expand (will be freed!)
534 * @return $-expanded string 675 * @return $-expanded string
535 */ 676 */
@@ -579,8 +720,13 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cf
579 return result; 720 return result;
580} 721}
581 722
723
582/** 724/**
583 * Get a configuration value that should be a string. 725 * Get a configuration value that should be a string.
726 *
727 * @param cfg configuration to inspect
728 * @param section section of interest
729 * @param option option of interest
584 * @param value will be set to a freshly allocated configuration 730 * @param value will be set to a freshly allocated configuration
585 * value, or NULL if option is not specified 731 * value, or NULL if option is not specified
586 * @return GNUNET_OK on success, GNUNET_SYSERR on error 732 * @return GNUNET_OK on success, GNUNET_SYSERR on error
@@ -612,10 +758,14 @@ GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handl
612 return ret; 758 return ret;
613} 759}
614 760
761
615/** 762/**
616 * Get a configuration value that should be in a set of 763 * Get a configuration value that should be in a set of
617 * "GNUNET_YES" or "GNUNET_NO". 764 * "GNUNET_YES" or "GNUNET_NO".
618 * 765 *
766 * @param cfg configuration to inspect
767 * @param section section of interest
768 * @param option option of interest
619 * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR 769 * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR
620 */ 770 */
621int 771int
@@ -639,15 +789,20 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *
639/** 789/**
640 * Iterate over the set of filenames stored in a configuration value. 790 * Iterate over the set of filenames stored in a configuration value.
641 * 791 *
792 * @param cfg configuration to inspect
793 * @param section section of interest
794 * @param option option of interest
795 * @param cb function to call on each filename
796 * @param cb_cls closure for cb
642 * @return number of filenames iterated over, -1 on error 797 * @return number of filenames iterated over, -1 on error
643 */ 798 */
644int 799int
645GNUNET_CONFIGURATION_iterate_value_filenames (const struct 800GNUNET_CONFIGURATION_iterate_value_filenames (const struct
646 GNUNET_CONFIGURATION_Handle 801 GNUNET_CONFIGURATION_Handle
647 *cfg, const char *section, 802 *cfg, const char *section,
648 const char *option, 803 const char *option,
649 GNUNET_FileNameCallback cb, 804 GNUNET_FileNameCallback cb,
650 void *cls) 805 void *cb_cls)
651{ 806{
652 char *list; 807 char *list;
653 char *pos; 808 char *pos;
@@ -692,7 +847,7 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct
692 if (strlen (pos) > 0) 847 if (strlen (pos) > 0)
693 { 848 {
694 ret++; 849 ret++;
695 if ((cb != NULL) && (GNUNET_OK != cb (cls, pos))) 850 if ((cb != NULL) && (GNUNET_OK != cb (cb_cls, pos)))
696 { 851 {
697 ret = GNUNET_SYSERR; 852 ret = GNUNET_SYSERR;
698 break; 853 break;
@@ -706,6 +861,13 @@ GNUNET_CONFIGURATION_iterate_value_filenames (const struct
706 return ret; 861 return ret;
707} 862}
708 863
864
865/**
866 * FIXME.
867 *
868 * @param value FIXME
869 * @return FIXME
870 */
709static char * 871static char *
710escape_name (const char *value) 872escape_name (const char *value)
711{ 873{
@@ -736,6 +898,14 @@ escape_name (const char *value)
736 return escaped; 898 return escaped;
737} 899}
738 900
901
902/**
903 * FIXME.
904 *
905 * @param cls string we compare with (const char*)
906 * @param fn filename we are currently looking at
907 * @return GNUNET_OK if the names do not match, GNUNET_SYSERR if they do
908 */
739static int 909static int
740test_match (void *cls, const char *fn) 910test_match (void *cls, const char *fn)
741{ 911{
@@ -743,10 +913,14 @@ test_match (void *cls, const char *fn)
743 return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK; 913 return (0 == strcmp (of, fn)) ? GNUNET_SYSERR : GNUNET_OK;
744} 914}
745 915
916
746/** 917/**
747 * Append a filename to a configuration value that 918 * Append a filename to a configuration value that
748 * represents a list of filenames 919 * represents a list of filenames
749 * 920 *
921 * @param cfg configuration to update
922 * @param section section of interest
923 * @param option option of interest
750 * @param value filename to append 924 * @param value filename to append
751 * @return GNUNET_OK on success, 925 * @return GNUNET_OK on success,
752 * GNUNET_NO if the filename already in the list 926 * GNUNET_NO if the filename already in the list
@@ -790,6 +964,9 @@ GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle
790 * Remove a filename from a configuration value that 964 * Remove a filename from a configuration value that
791 * represents a list of filenames 965 * represents a list of filenames
792 * 966 *
967 * @param cfg configuration to update
968 * @param section section of interest
969 * @param option option of interest
793 * @param value filename to remove 970 * @param value filename to remove
794 * @return GNUNET_OK on success, 971 * @return GNUNET_OK on success,
795 * GNUNET_NO if the filename is not in the list, 972 * GNUNET_NO if the filename is not in the list,
@@ -870,6 +1047,10 @@ GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle
870/** 1047/**
871 * Load configuration (starts with defaults, then loads 1048 * Load configuration (starts with defaults, then loads
872 * system-specific configuration). 1049 * system-specific configuration).
1050 *
1051 * @param cfg configuration to update
1052 * @param filename name of the configuration file
1053 * @return GNUNET_OK on success, GNUNET_SYSERR on error
873 */ 1054 */
874int 1055int
875GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, 1056GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,