settings: Add methods and a constructor to parse settings from strings

This commit is contained in:
Tobias Brunner
2015-07-28 13:27:32 +02:00
parent 0dba2690c4
commit 08b45fc516
2 changed files with 112 additions and 11 deletions
+54
View File
@@ -334,6 +334,50 @@ struct settings_t {
bool (*load_files_section)(settings_t *this, char *pattern, bool merge,
char *section, ...);
/**
* Load settings from the given string.
*
* If merge is TRUE, existing sections are extended, existing values
* replaced, by those found in the string. If it is FALSE, existing
* sections are purged before reading the new config.
*
* @note If the string contains _include_ statements they should be
* absolute paths.
*
* @note If any failures occur, no settings are added at all. So, it's all
* or nothing.
*
* @param settings string to parse
* @param merge TRUE to merge config with existing values
* @return TRUE, if settings were loaded successfully
*/
bool (*load_string)(settings_t *this, char *settings, bool merge);
/**
* Load settings from the given string.
*
* If merge is TRUE, existing sections are extended, existing values
* replaced, by those found in the string. If it is FALSE, existing
* sections are purged before reading the new config.
*
* All settings are loaded relative to the given section. The section is
* created, if it does not yet exist.
*
* @note If the string contains _include_ statements they should be
* absolute paths.
*
* @note If any failures occur, no settings are added at all. So, it's all
* or nothing.
*
* @param settings string to parse
* @param merge TRUE to merge config with existing values
* @param section section name of parent section, printf style
* @param ... argument list for section
* @return TRUE, if settings were loaded successfully
*/
bool (*load_string_section)(settings_t *this, char *settings, bool merge,
char *section, ...);
/**
* Destroy a settings instance.
*/
@@ -350,4 +394,14 @@ struct settings_t {
*/
settings_t *settings_create(char *file);
/**
* Load settings from a string.
*
* @note If parsing the file fails the object is still created.
*
* @param settings string to read settings from
* @return settings object, or NULL
*/
settings_t *settings_create_string(char *settings);
#endif /** SETTINGS_H_ @}*/