econf_erreconf_readConfig(econf_file**key_file,constchar*project,constchar*usr_subdir,constchar*config_name,constchar*config_suffix,constchar*delim,constchar*comment)
Evaluating key/values of a given configuration by reading and merging all needed/available files from
different directories. Order is:
/etc/$project/$config_name.$config_suffix does exist:
-- /etc/$project/$config_name.$config_suffix
-- $usr_subdir/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /run/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /etc/$project/$config_name.$config_suffix.d/ *.$config_suffix
/etc/$project/$config_name.$config_suffix does NOT exist:
- /run/$project/$config_name.$config_suffix does exist:
-- /run/$project/$config_name.$config_suffix
-- $usr_subdir/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /run/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /etc/$project/$config_name.$config_suffix.d/ *.$config_suffix
- /run/$project/$config_name.$config_suffix does NOT exist:
-- $usr_subdir/$project/$config_name.$config_suffix
-- $usr_subdir/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /run/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /etc/$project/$config_name.$config_suffix.d/ *.$config_suffix
No main $config_name.$config_suffix file is defined or must not be parsed:
-- $usr_subdir/$project.d/*.$config_suffix
-- /run/$project.d/*.$config_suffix
-- /etc/$project.d/*.$config_suffix
Parameters:key_file content of parsed file(s)
project name of the project used as subdirectory, can be NULL
usr_subdir absolute path of the first directory (often "/usr/lib")
config_name basename of the configuration file. If it is NULL, drop-ins without a main configuration
file will be parsed only.
config_suffix suffix of the configuration file. Can also be NULL.
delim delimiters of key/value e.g. '\t ='. If delim contains space characters AND none space
characters, multiline values are not parseable.
comment array of characters which define the start of a comment
Returns:
econf_err ECONF_SUCCESS or error code
Example: Reading content in different cases in following order:
/etc/foo/example.conf does exist:
- /etc/foo/example.conf
- /usr/lib/foo/example.conf.d/ *.conf
- /run/foo/example.conf.d/ *.conf
- /etc/foo/example.conf.d/ *.conf
/etc/foo/example.conf does NOT exist:
/run/foo/example.conf does exist:
- /run/foo/example.conf
- /usr/lib/foo/example.conf.d/ *.conf
- /run/foo/example.conf.d/ *.conf
- /etc/foo/example.conf.d/ *.conf
/run/foo/example.conf does NOT exist:
- /usr/lib/foo/example.conf
- /usr/lib/foo/example.conf.d/ *.conf
- /run/foo/example.conf.d/ *.conf
- /etc/foo/example.conf.d/ *.conf
#include "libeconf.h"
econf_file *key_file = NULL;
econf_err error;
error = econf_readConfig (&key_file,
"foo",
"/usr/lib",
"example",
"conf",
"=", "#");
econf_free (key_file);
econf_erreconf_readConfigWithCallback(econf_file**key_file,constchar*project,constchar*usr_subdir,constchar*config_name,constchar*config_suffix,constchar*delim,constchar*comment,bool(*callback)(constchar*filename,constvoid*data),constvoid*callback_data)
Evaluating key/values of a given configuration by reading and merging all needed/available files from
different directories. Order is:
/etc/$project/$config_name.$config_suffix does exist:
-- /etc/$project/$config_name.$config_suffix
-- $usr_subdir/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /run/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /etc/$project/$config_name.$config_suffix.d/ *.$config_suffix
/etc/$project/$config_name.$config_suffix does NOT exist:
- /run/$project/$config_name.$config_suffix does exist:
-- /run/$project/$config_name.$config_suffix
-- $usr_subdir/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /run/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /etc/$project/$config_name.$config_suffix.d/ *.$config_suffix
- /run/$project/$config_name.$config_suffix does NOT exist:
-- $usr_subdir/$project/$config_name.$config_suffix
-- $usr_subdir/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /run/$project/$config_name.$config_suffix.d/ *.$config_suffix
-- /etc/$project/$config_name.$config_suffix.d/ *.$config_suffix
No main $config_name.$config_suffix file is defined or must not be parsed:
-- $usr_subdir/$project.d/*.$config_suffix
-- /run/$project.d/*.$config_suffix
-- /etc/$project.d/*.$config_suffix
For each parsed file the user defined function will be called in order e.g. to check the correct file
permissions.
Parameters:key_file content of parsed file(s)
project name of the project used as subdirectory, can be NULL
usr_subdir absolute path of the first directory (often "/usr/lib")
config_name basename of the configuration file. If it is NULL, drop-ins without a main configuration
file will be parsed only.
config_suffix suffix of the configuration file. Can also be NULL.
delim delimiters of key/value e.g. '\t ='. If delim contains space characters AND none space
characters, multiline values are not parseable.
comment array of characters which define the start of a comment
callback function which will be called for each file. This user defined function has the pathname as
parameter and returns true if this file can be parsed. If not, the parsing of all files will be
aborted and ECONF_PARSING_CALLBACK_FAILED will be returned.
callback_data pointer which will be given to the callback function.
Returns:
econf_err ECONF_SUCCESS or error code
Example: Reading content in different cases in following order:
/etc/foo/example.conf does exist:
- /etc/foo/example.conf
- /usr/lib/foo/example.conf.d/ *.conf
- /run/foo/example.conf.d/ *.conf
- /etc/foo/example.conf.d/ *.conf
/etc/foo/example.conf does NOT exist:
/run/foo/example.conf does exist:
- /run/foo/example.conf
- /usr/lib/foo/example.conf.d/ *.conf
- /run/foo/example.conf.d/ *.conf
- /etc/foo/example.conf.d/ *.conf
/run/foo/example.conf does NOT exist:
- /usr/lib/foo/example.conf
- /usr/lib/foo/example.conf.d/ *.conf
- /run/foo/example.conf.d/ *.conf
- /etc/foo/example.conf.d/ *.conf
#include "libeconf.h"
bool checkFile(const char *filename, const void *data) {
/* checking code which returns true or false */
return true;
}
econf_file *key_file = NULL;
econf_err error;
error = econf_readConfigWithCallback (&key_file,
"foo",
"/usr/lib",
"example",
"conf",
"=", "#",
checkFile,
NULL);
econf_free (key_file);
econf_erreconf_readFile(econf_file**result,constchar*file_name,constchar*delim,constchar*comment)
Process the file of the given file_name and save its contents into key_file object.
Parameters:result content of parsed file
file_name absolute path of parsed file
delim delimiters of key/value e.g. '\t ='
comment array of characters which define the start of a comment
Returns:
econf_err ECONF_SUCCESS or error code
Usage:
#include "libeconf.h"
econf_file *key_file = NULL;
econf_err error;
error = econf_readFile (&key_file, "/etc/test.conf", "=", "#");
econf_free (key_file);
Default behaviour if entries have the same name in one file: The first hit will be returned. Further
entries will be ignored. This can be changed by setting the environment variable JOIN_SAME_ENTRIES (see
econf_set_opt). In that case entries with the same name will be joined to one single entry.
econf_erreconf_readFileWithCallback(econf_file**result,constchar*file_name,constchar*delim,constchar*comment,bool(*callback)(constchar*filename,constvoid*data),constvoid*callback_data)
Process the file of the given file_name and save its contents into key_file object. The user defined
function will be called in order e.g. to check the correct file permissions.
Parameters:result content of parsed file
file_name absolute path of parsed file
delim delimiters of key/value e.g. '\t ='
comment array of characters which define the start of a comment
callback function which will be called for the given filename. This user defined function has the
pathname as parameter and returns true if this file can be parsed. If not, the parsing will be
aborted and ECONF_PARSING_CALLBACK_FAILED will be returned.
callback_data pointer which will be given to the callback function.
Returns:
econf_err ECONF_SUCCESS or error code
Usage:
#include "libeconf.h"
bool checkFile(const char *filename, const void *data) {
/* checking code which returns true or false */
return true;
}
econf_file *key_file = NULL;
econf_err error;
error = econf_readFileWithCallback (&key_file, "/etc/test.conf", "=", "#", checkFile, NULL);
econf_free (key_file);
Default behaviour if entries have the same name in one file: The first hit will be returned. Further
entries will be ignored. This can be changed by setting the environment variable JOIN_SAME_ENTRIES (see
econf_set_opt). In that case entries with the same name will be joined to one single entry.
econf_erreconf_mergeFiles(econf_file**merged_file,econf_file*usr_file,econf_file*etc_file)
Merge the contents of two key_files objects. Entries in etc_file will be preferred. Comment and delimiter
tag will be taken from usr_file. This can be changed by calling the functions econf_set_comment_tag and
econf_set_delimiter_tag.
Parameters:merged_file merged data
usr_file First data block which has to be merged.
etc_file Second data block which has to be merged.
Returns:
econf_err ECONF_SUCCESS or error code
Usage:
#include "libeconf.h"
econf_file *key_file_1 = NULL, *key_file_2 = NULL, *key_file_ret = NULL
econf_err error;
error = econf_readFile (&key_file1, "/usr/etc/test.conf", "=", "#");
error = econf_readFile (&key_file2, /etc/test.conf", "=", "#");
error = econf_mergeFiles (&key_file_ret, key_file_1, key_file_2);
econf_free (key_file_ret);
econf_free (key_file_1);
econf_free (key_file_2);
econf_erreconf_newKeyFile(econf_file**result,chardelimiter,charcomment)
Create a new econf_file object.
Parameters:result Pointer to the allocated econf_file object.
delimiter delimiter of key/value e.g. '='
comment Character which defines the start of a comment.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_newIniFile(econf_file**result)
Create a new econf_file object in IniFile format. So the delimiter will be '=' and comments are beginning
with '#'.
Parameters:result Pointer to the allocated econf_file object.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_writeFile(econf_file*key_file,constchar*save_to_dir,constchar*file_name)
Write content of an econf_file struct to specified location.
Parameters:key_file Data which has to be written.
save_to_dir Directory into which the file has to be written.
file_name filename (with suffix)
Returns:
econf_err ECONF_SUCCESS or error code
char*econf_getPath(econf_file*kf)
Evaluating path name.
Parameters:kf given/parsed data
Returns:
Absolute path name or an empty string if kf is a result of already merged data (e.G. returned by
econf_readDirs).
econf_erreconf_getGroups(econf_file*kf,size_t*length,char***groups)
Evaluating all group entries.
Parameters:kf given/parsed data
length Length of the returned group array.
groups String array of evaluated groups.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getKeys(econf_file*kf,constchar*group,size_t*length,char***keys)
Evaluating all keys.
Parameters:kf given/parsed data
group Group name for which the keys have to be evaluated or NULL for keys, which do not belong to a
group.
length Length of the returned key array.
keys String array of evaluated keys.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getIntValue(econf_file*kf,constchar*group,constchar*key,int32_t*result)
Evaluating int32 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getInt64Value(econf_file*kf,constchar*group,constchar*key,int64_t*result)
Evaluating int64 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getUIntValue(econf_file*kf,constchar*group,constchar*key,uint32_t*result)
Evaluating uint32 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getUInt64Value(econf_file*kf,constchar*group,constchar*key,uint64_t*result)
Evaluating uint64 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getFloatValue(econf_file*kf,constchar*group,constchar*key,float*result)
Evaluating float value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getDoubleValue(econf_file*kf,constchar*group,constchar*key,double*result)
Evaluating double value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getStringValue(econf_file*kf,constchar*group,constchar*key,char**result)
Evaluating string value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result A newly allocated string or NULL in error case.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getBoolValue(econf_file*kf,constchar*group,constchar*key,bool*result)
Evaluating bool value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getIntValueDef(econf_file*kf,constchar*group,constchar*key,int32_t*result,int32_tdef)
Evaluating int32 value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getInt64ValueDef(econf_file*kf,constchar*group,constchar*key,int64_t*result,int64_tdef)
Evaluating int64 value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getUIntValueDef(econf_file*kf,constchar*group,constchar*key,uint32_t*result,uint32_tdef)
Evaluating uint32 value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getUInt64ValueDef(econf_file*kf,constchar*group,constchar*key,uint64_t*result,uint64_tdef)
Evaluating uint64 value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getFloatValueDef(econf_file*kf,constchar*group,constchar*key,float*result,floatdef)
Evaluating float value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getDoubleValueDef(econf_file*kf,constchar*group,constchar*key,double*result,doubledef)
Evaluating double value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getStringValueDef(econf_file*kf,constchar*group,constchar*key,char**result,char*def)
Evaluating string value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result Returns a newly allocated string, even if 'default' is returned.
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_getBoolValueDef(econf_file*kf,constchar*group,constchar*key,bool*result,booldef)
Evaluating bool value for given group/key. If key is not found, the default value is returned and error
is ECONF_NOKEY.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result determined value
def Default value if the value has not been found.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setIntValue(econf_file*kf,constchar*group,constchar*key,int32_tvalue)
Set int32 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setInt64Value(econf_file*kf,constchar*group,constchar*key,int64_tvalue)
Set int64 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setUIntValue(econf_file*kf,constchar*group,constchar*key,uint32_tvalue)
Set uint32 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setUInt64Value(econf_file*kf,constchar*group,constchar*key,uint64_tvalue)
Set uint64 value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setFloatValue(econf_file*kf,constchar*group,constchar*key,floatvalue)
Set float value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setDoubleValue(econf_file*kf,constchar*group,constchar*key,doublevalue)
Set double value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setStringValue(econf_file*kf,constchar*group,constchar*key,constchar*value)
Set string value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
econf_erreconf_setBoolValue(econf_file*kf,constchar*group,constchar*key,constchar*value)
Set bool value for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value has to be set.
value Value which has to be set.
Returns:
econf_err ECONF_SUCCESS or error code
constchar*econf_errString(consteconf_errerror)
Convert an econf_err type to a string.
Parameters:error error enum
Returns:
human readable string
voideconf_errLocation(char**filename,uint64_t*line_nr)
Info about where the error has happened.
Parameters:filename Path of the last scanned file.
line_nr Number of the last handled line.
voideconf_freeArray(char**array)
Free an array of type char** created by econf_getGroups() or econf_getKeys().
Parameters:array array of strings
Returns:
void
voideconf_freeFile(econf_file*key_file)
Free memory allocated by e.g. econf_readFile(), econf_readDirs(),...
Parameters:key_file allocated data
Returns:
void
chareconf_comment_tag(econf_file*key_file)
Returns the comment character tag of the given econf_file object. This tag will be taken while writing
comments to file.
Parameters:key_file econf_file object.
Returns:
char comment character tag
chareconf_delimiter_tag(econf_file*key_file)
Returns the delimiter character of the given econf_file object. This delimiter will be taken while
writing the data to file.
Parameters:key_file econf_file object.
Returns:
char delimiter of key/value
voideconf_set_comment_tag(econf_file*key_file,constcharcomment)
Set the comment character tag of the given econf_file object. This tag will be taken while writing
comments to file.
Parameters:key_file econf_file object.
comment comment tag
voideconf_set_delimiter_tag(econf_file*key_file,constchardelimiter)
Set the delimiter character of the given econf_file object. This delimiter will be taken while writing
the data to file.
Parameters:key_file econf_file object.
delimiter delimiter of key/value
econf_erreconf_getExtValue(econf_file*kf,constchar*group,constchar*key,econf_ext_value**result)
Evaluating more information for given group/key.
Parameters:kf given/parsed data
group Desired group or NULL if there is no group defined.
key Key for which the value is requested.
result A newly allocated struct or NULL in error case.
Returns:
econf_err ECONF_SUCCESS or error code
voideconf_freeExtValue(econf_ext_value*to_free)
Free an complete econf_ext_value struct.
Parameters:to_free struct which has to be freed
Returns:
void
econf_erreconf_set_conf_dirs(constchar**dir_postfix_list)
Set a list of directory structures (with order) which describes the directories in which the files have
to be parsed.
Parameters:dir_postfix_list list of directory structures. E.G. with the given list: {"/conf.d/", ".d/", "/",
NULL} files in following directories will be parsed: <default_dirs>/<project_name>.<suffix>.d/
<default_dirs>/<project_name>/conf.d/, <default_dirs>/<project_name>.d/,
<default_dirs>/<project_name>/. The entry <default_dirs>/<project_name>.<suffix>.d/ will be added
automatically.
Returns:
econf_err ECONF_SUCCESS or error code