X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Finclude%2Fgnunet_configuration_lib.h;h=77d6d5552f0025b2753734fa9a1ed3834453cfe0;hb=9e249590e5d750c70ec61d1100c70d325374dbd8;hp=8e2f8e6d9a2cbba44613af742d44e70c43a6eef9;hpb=60c2c502f0a4581a6f25386a8d54adb9cc8b6003;p=oweals%2Fgnunet.git diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index 8e2f8e6d9..77d6d5552 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -49,17 +49,18 @@ struct GNUNET_CONFIGURATION_Handle; * Create a new configuration object. * @return fresh configuration object */ -struct GNUNET_CONFIGURATION_Handle *GNUNET_CONFIGURATION_create (void); +struct GNUNET_CONFIGURATION_Handle * +GNUNET_CONFIGURATION_create (void); /** * Duplicate an existing configuration object. * - * @param c configuration to duplicate + * @param cfg configuration to duplicate * @return duplicate configuration */ struct GNUNET_CONFIGURATION_Handle * -GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *c); +GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -67,7 +68,8 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *c); * * @param cfg configuration to destroy */ -void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); +void +GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -76,11 +78,25 @@ void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); * to overwrite the defaults. * * @param cfg configuration to update - * @param filename name of the configuration file + * @param filename name of the configuration file, NULL to load defaults + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *filename); + + +/** + * Load default configuration. This function will parse the + * defaults from the given defaults_d directory. + * + * @param cfg configuration to update + * @param defaults_d directory with the defaults * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, - const char *filename); +int +GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *defaults_d); /** @@ -91,8 +107,40 @@ int GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, * @param filename name of the configuration file * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, - const char *filename); +int +GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *filename); + + +/** + * Serializes the given configuration. + * + * @param cfg configuration to serialize + * @param size will be set to the size of the serialized memory block + * @return the memory block where the serialized configuration is + * present. This memory should be freed by the caller + */ +char * +GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, + size_t *size); + + +/** + * De-serializes configuration + * + * @param cfg configuration to update + * @param mem the memory block of serialized configuration + * @param size the size of the memory block + * @param allow_inline set to GNUNET_YES if we recursively load configuration + * from inlined configurations; GNUNET_NO if not and raise warnings + * when we come across them + * @return GNUNET_OK on success, GNUNET_ERROR on error + */ +int +GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *mem, + const size_t size, + int allow_inline); /** @@ -102,9 +150,22 @@ int GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, * @param filename where to write the configuration * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, - const char *filename); +int +GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *filename); +/** + * Write only configuration entries that have been changed to configuration file + * @param cfgDefault default configuration + * @param cfgNew new configuration + * @param filename where to write the configuration diff between default and new + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle + *cfgDefault, + const struct GNUNET_CONFIGURATION_Handle + *cfgNew, const char *filename); /** * Test if there are configuration options that were @@ -113,7 +174,8 @@ int GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, * @param cfg configuration to inspect * @return GNUNET_NO if clean, GNUNET_YES if dirty, GNUNET_SYSERR on error (i.e. last save failed) */ -int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); +int +GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); /** @@ -124,10 +186,19 @@ int GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg * @param option name of the option * @param value value of the option */ -typedef void (*GNUNET_CONFIGURATION_Iterator)(void *cls, - const char *section, - const char *option, - const char *value); +typedef void (*GNUNET_CONFIGURATION_Iterator) (void *cls, const char *section, + const char *option, + const char *value); + + +/** + * Function to iterate over section. + * + * @param cls closure + * @param section name of the section + */ +typedef void (*GNUNET_CONFIGURATION_Section_Iterator) (void *cls, + const char *section); /** @@ -137,11 +208,36 @@ typedef void (*GNUNET_CONFIGURATION_Iterator)(void *cls, * @param iter function to call on each option * @param iter_cls closure for iter */ -void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_CONFIGURATION_Iterator iter, - void *iter_cls); +void +GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls); +/** + * Iterate over all sections in the configuration. + * + * @param cfg configuration to inspect + * @param iter function to call on each section + * @param iter_cls closure for iter + */ +void +GNUNET_CONFIGURATION_iterate_sections (const struct GNUNET_CONFIGURATION_Handle + *cfg, + GNUNET_CONFIGURATION_Section_Iterator + iter, void *iter_cls); + + +/** + * Remove the given section and all options in it. + * + * @param cfg configuration to inspect + * @param section name of the section to remove + */ +void +GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section); + /** * Get a configuration value that should be a number. * @@ -151,10 +247,11 @@ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg * @param number where to store the numeric value of the option * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - unsigned long long *number); +int +GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + unsigned long long *number); /** @@ -166,10 +263,28 @@ int GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Han * @param time set to the time value stored in the configuration * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - struct GNUNET_TIME_Relative *time); +int +GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + struct GNUNET_TIME_Relative *time); + + + +/** + * Get a configuration value that should be a size in bytes. + * + * @param cfg configuration to inspect + * @param section section of interest + * @param option option of interest + * @param size set to the size in bytes as stored in the configuration + * @return GNUNET_OK on success, GNUNET_SYSERR on error + */ +int +GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + unsigned long long *size); /** @@ -180,8 +295,9 @@ int GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handl * @param option option of interest * @return GNUNET_YES if so, GNUNET_NO if not. */ -int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *section, const char *option); +int +GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option); /** @@ -194,9 +310,10 @@ int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *c * value, or NULL if option is not specified * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, char **value); +int +GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, char **value); /** @@ -210,11 +327,11 @@ int GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Han * value, or NULL if option is not specified * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_get_value_filename (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *section, - const char *option, - char **value); +int +GNUNET_CONFIGURATION_get_value_filename (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, char **value); /** * Iterate over the set of filenames stored in a configuration value. @@ -226,13 +343,28 @@ int GNUNET_CONFIGURATION_get_value_filename (const struct * @param cb_cls closure for cb * @return number of filenames iterated over, -1 on error */ -int GNUNET_CONFIGURATION_iterate_value_filenames (const struct - GNUNET_CONFIGURATION_Handle - *cfg, - const char *section, - const char *option, - GNUNET_FileNameCallback - cb, void *cb_cls); +int +GNUNET_CONFIGURATION_iterate_value_filenames (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, + GNUNET_FileNameCallback cb, + void *cb_cls); + +/** + * Iterate over values of a section in the configuration. + * + * @param cfg configuration to inspect + * @param section the section + * @param iter function to call on each option + * @param iter_cls closure for iter + */ +void +GNUNET_CONFIGURATION_iterate_section_values (const struct + GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + GNUNET_CONFIGURATION_Iterator iter, + void *iter_cls); /** * Get a configuration value that should be in a set of @@ -246,11 +378,11 @@ int GNUNET_CONFIGURATION_iterate_value_filenames (const struct * or NULL if option is not specified and no default given * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - const char **choices, - const char **value); +int +GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, const char **choices, + const char **value); /** * Get a configuration value that should be in a set of @@ -261,9 +393,11 @@ int GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Han * @param option option of interest * @return GNUNET_YES, GNUNET_NO or if option has no valid value, GNUNET_SYSERR */ -int GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option); +int +GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option); + /** * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" @@ -274,8 +408,9 @@ int GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Hand * @param orig string to $-expand (will be freed!) * @return $-expanded string */ -char *GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle - *cfg, char *orig); +char * +GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle + *cfg, char *orig); /** @@ -287,10 +422,8 @@ char *GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Hand * @param number value to set */ void -GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle - *cfg, - const char *section, - const char *option, +GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, unsigned long long number); @@ -303,10 +436,10 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle * @param value value to set */ void -GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle - *cfg, - const char *section, - const char *option, const char *value); +GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, + const char *value); + /** * Remove a filename from a configuration value that @@ -319,12 +452,11 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle * @return GNUNET_OK on success, * GNUNET_SYSERR if the filename is not in the list */ -int GNUNET_CONFIGURATION_remove_value_filename (struct - GNUNET_CONFIGURATION_Handle - *cfg, - const char *section, - const char *option, - const char *value); +int +GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + const char *value); /** * Append a filename to a configuration value that @@ -337,11 +469,11 @@ int GNUNET_CONFIGURATION_remove_value_filename (struct * @return GNUNET_OK on success, * GNUNET_SYSERR if the filename already in the list */ -int GNUNET_CONFIGURATION_append_value_filename (struct - GNUNET_CONFIGURATION_Handle - *cfg, const char *section, - const char *option, - const char *value); +int +GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle + *cfg, const char *section, + const char *option, + const char *value); #if 0 /* keep Emacsens' auto-indent happy */