libini_config 0.6.2
|
Data Structures | |
struct | ini_validator |
Structure used to define application specific (external to libini) validator. More... | |
Functions | |
int | ini_get_config_valueobj (const char *section, const char *name, struct ini_cfgobj *ini_config, int mode, struct value_obj **vo) |
Retrieve a value object form the configuration. | |
int | ini_get_int_config_value (struct value_obj *vo, int strict, int def, int *error) |
Convert value to integer number. | |
unsigned | ini_get_unsigned_config_value (struct value_obj *vo, int strict, unsigned def, int *error) |
Convert value object to a unsigned number. | |
long | ini_get_long_config_value (struct value_obj *vo, int strict, long def, int *error) |
Convert value to long number. | |
unsigned long | ini_get_ulong_config_value (struct value_obj *vo, int strict, unsigned long def, int *error) |
Convert value to unsigned long number. | |
int32_t | ini_get_int32_config_value (struct value_obj *vo, int strict, int32_t def, int *error) |
Convert value to int32_t number. | |
uint32_t | ini_get_uint32_config_value (struct value_obj *vo, int strict, uint32_t def, int *error) |
Convert value to uint32_t number. | |
int64_t | ini_get_int64_config_value (struct value_obj *vo, int strict, int64_t def, int *error) |
Convert value to integer number. | |
uint64_t | ini_get_uint64_config_value (struct value_obj *vo, int strict, uint64_t def, int *error) |
Convert value to integer number. | |
double | ini_get_double_config_value (struct value_obj *vo, int strict, double def, int *error) |
Convert value to floating point number. | |
unsigned char | ini_get_bool_config_value (struct value_obj *vo, unsigned char def, int *error) |
Convert value into a logical value. | |
char * | ini_get_string_config_value (struct value_obj *vo, int *error) |
Get the copy of string stored in the configuration value. | |
const char * | ini_get_const_string_config_value (struct value_obj *vo, int *error) |
Get the string stored in the configuration value. | |
char * | ini_get_bin_config_value (struct value_obj *vo, int *length, int *error) |
Convert value into a binary sequence. | |
void | ini_free_bin_config_value (char *bin) |
Free binary buffer. | |
char ** | ini_get_string_config_array (struct value_obj *vo, const char *sep, int *size, int *error) |
Convert value to an array of strings. | |
char ** | ini_get_raw_string_config_array (struct value_obj *vo, const char *sep, int *size, int *error) |
Convert value to an array of strings. | |
long * | ini_get_long_config_array (struct value_obj *vo, int *size, int *error) |
Convert value to an array of long values. | |
double * | ini_get_double_config_array (struct value_obj *vo, int *size, int *error) |
Convert value to an array of floating point values. | |
void | ini_free_string_config_array (char **str_config) |
Free array of string values. | |
void | ini_free_long_config_array (long *array) |
Free array of long values. | |
void | ini_free_double_config_array (double *array) |
Free array of floating pointer values. | |
int | ini_errobj_create (struct ini_errobj **_errobj) |
Create structure to hold error messages. | |
void | ini_errobj_destroy (struct ini_errobj **errobj) |
Free structure that holds error messages. | |
int | ini_errobj_add_msg (struct ini_errobj *errobj, const char *format,...) DING_ATTR_FORMAT(2 |
Add new printf formated message to errobj. | |
int void | ini_errobj_reset (struct ini_errobj *errobj) |
Reset iterator in errobj. | |
const char * | ini_errobj_get_msg (struct ini_errobj *errobj) |
Get pointer to current message in errobj. | |
void | ini_errobj_next (struct ini_errobj *errobj) |
Move to the next message in errobj. | |
int | ini_errobj_no_more_msgs (struct ini_errobj *errobj) |
Check if errobj has more messages. | |
size_t | ini_errobj_count (struct ini_errobj *errobj) |
Return number of messages in errobj. | |
int | ini_rules_read_from_file (const char *filename, struct ini_cfgobj **_rules_obj) |
Read rules from INI file. | |
int | ini_rules_check (struct ini_cfgobj *rules_obj, struct ini_cfgobj *config_obj, struct ini_validator **extra_validators, struct ini_errobj *errobj) |
Check configuration file using rules. | |
void | ini_rules_destroy (struct ini_cfgobj *ini_config) |
Free the rules. | |
This section contains value management functions. These functions can be used to interpret values that are stored in the configuration object in memory.
int ini_get_config_valueobj | ( | const char * | section, |
const char * | name, | ||
struct ini_cfgobj * | ini_config, | ||
int | mode, | ||
struct value_obj ** | vo ) |
Retrieve a value object form the configuration.
Check return error code first. If the function returns an error there is a serious problem. Then check if object is found. Function will set vo parameter to NULL if no attribute with provided name is found in the collection.
[in] | section | Section name. If NULL assumed default. |
[in] | name | Attribute name to find. |
[in] | ini_config | Configuration object to search. |
[in] | mode | See search mode section for more info. |
[out] | vo | Value object. Will be set to NULL if element with the given name is not found. |
int ini_get_int_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
int | def, | ||
int * | error ) |
Convert value to integer number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an int number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from INT_MIN to INT_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
unsigned ini_get_unsigned_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
unsigned | def, | ||
int * | error ) |
Convert value object to a unsigned number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an unsigned number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from 0 to UINT_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
long ini_get_long_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
long | def, | ||
int * | error ) |
Convert value to long number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into a long number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from LONG_MIN to LONG_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
unsigned long ini_get_ulong_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
unsigned long | def, | ||
int * | error ) |
Convert value to unsigned long number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an unsigned long number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from 0 to ULONG_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
int32_t ini_get_int32_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
int32_t | def, | ||
int * | error ) |
Convert value to int32_t number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an int32_t number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from INT_MIN to INT_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
uint32_t ini_get_uint32_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
uint32_t | def, | ||
int * | error ) |
Convert value to uint32_t number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration value into an uint32_t number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from 0 to ULONG_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
int64_t ini_get_int64_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
int64_t | def, | ||
int * | error ) |
Convert value to integer number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an int64_t number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from LLONG_MIN to LLONG_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
uint64_t ini_get_uint64_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
uint64_t | def, | ||
int * | error ) |
Convert value to integer number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an uint64_t number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit. The value range is from 0 to ULLONG_MAX.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
double ini_get_double_config_value | ( | struct value_obj * | vo, |
int | strict, | ||
double | def, | ||
int * | error ) |
Convert value to floating point number.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into a floating point number. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value. If "strict" parameter is non zero the function will fail if there are more characters after the last digit.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | strict | Fail the function if the symbol after last digit is not valid. |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
unsigned char ini_get_bool_config_value | ( | struct value_obj * | vo, |
unsigned char | def, | ||
int * | error ) |
Convert value into a logical value.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into a Boolean. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | def | Default value to use if conversion failed. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
char * ini_get_string_config_value | ( | struct value_obj * | vo, |
int * | error ) |
Get the copy of string stored in the configuration value.
Function creates a copy of the string value stored in the configuration element. Returned value needs to be freed after use. If error occurred the returned value will be NULL.
[in] | vo | Value object to use. It must be retrieved using ini_get_config_valueobj(). |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
const char * ini_get_const_string_config_value | ( | struct value_obj * | vo, |
int * | error ) |
Get the string stored in the configuration value.
Function returns a reference to the string value stored inside the configuration element. This string can't be altered. The string will go out of scope if the value object is deleted.
[in] | vo | Value object to use. It must be retrieved using ini_get_config_valueobj(). |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
char * ini_get_bin_config_value | ( | struct value_obj * | vo, |
int * | length, | ||
int * | error ) |
Convert value into a binary sequence.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into a sequence of bytes. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value.
The function allocates memory. It is the responsibility of the caller to free it after use. Use ini_free_bin_config_value() for this purpose. Functions will return NULL if conversion failed.
Function assumes that the value being interpreted has a special format. The string should be taken in single quotes and consist of hex encoded value represented by two hex digits per byte. Case does not matter.
Example: '0a2BFeCc'
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[out] | length | Variable that optionally receives the length of the binary sequence. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
void ini_free_bin_config_value | ( | char * | bin | ) |
Free binary buffer.
Free binary value returned by ini_get_bin_config_value().
[in] | bin | Binary buffer to free. |
char ** ini_get_string_config_array | ( | struct value_obj * | vo, |
const char * | sep, | ||
int * | size, | ||
int * | error ) |
Convert value to an array of strings.
This is a conversion function. It converts the value read from the INI file and stored in the configuration value object into an array of strings. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value.
Separator string includes up to three different separators. If separator NULL, comma is assumed. The spaces are trimmed automatically around separators in the string. The function drops empty tokens from the list. This means that the string like this: "apple, ,banana, ,orange ," will be translated into the list of three items: "apple","banana" and "orange".
The length of the allocated array is returned in "size". Size and error parameters can be NULL. Use ini_free_string_config_array() to free the array after use.
The array is always NULL terminated so it is safe not to get size and just loop until array element is NULL.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | sep | String cosisting of separator symbols. For example: ",.;" would mean that comma, dot and semicolon should be treated as separators in the value. |
[out] | size | Variable that optionally receives the size of the array. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
char ** ini_get_raw_string_config_array | ( | struct value_obj * | vo, |
const char * | sep, | ||
int * | size, | ||
int * | error ) |
Convert value to an array of strings.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an array of strings. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value.
Separator string includes up to three different separators. If separator NULL, comma is assumed. The spaces are trimmed automatically around separators in the string. The function does not drop empty tokens from the list. This means that the string like this: "apple, ,banana, ,orange ," will be translated into the list of five items: "apple", "", "banana", "" and "orange".
The length of the allocated array is returned in "size". Size and error parameters can be NULL. Use ini_free_string_config_array() to free the array after use.
The array is always NULL terminated so it is safe not to get size and just loop until array element is NULL.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[in] | sep | String cosisting of separator symbols. For example: ",.;" would mean that comma, dot and semicolon should be treated as separators in the value. |
[out] | size | Variable that optionally receives the size of the array. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
long * ini_get_long_config_array | ( | struct value_obj * | vo, |
int * | size, | ||
int * | error ) |
Convert value to an array of long values.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an array of long values. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value.
Separators inside the string are detected automatically. The spaces are trimmed automatically around separators in the string.
The length of the allocated array is returned in "size". Size parameter can't be NULL.
Use ini_free_long_config_array() to free the array after use.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[out] | size | Variable that receives the size of the array. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
double * ini_get_double_config_array | ( | struct value_obj * | vo, |
int * | size, | ||
int * | error ) |
Convert value to an array of floating point values.
This is a conversion function. It converts the value read from the INI file and stored in the configuration element into an array of floating point values. Any of the conversion functions can be used to try to convert the value stored as a string inside the value object. The result can be different depending upon how the caller tries to interpret the value.
Separators inside the string are detected automatically. The spaces are trimmed automatically around separators in the string.
The length of the allocated array is returned in "size". Size parameter can't be NULL.
Use ini_free_double_config_array() to free the array after use.
[in] | vo | Value object to interpret. It must be retrieved using ini_get_config_valueobj(). |
[out] | size | Variable that receives the size of the array. |
[out] | error | Variable will get the value of the error code if error happened. Can be NULL. In this case function does not set the code. Codes:
|
void ini_free_string_config_array | ( | char ** | str_config | ) |
Free array of string values.
Use this function to free the array returned by ini_get_string_config_array() or by ini_get_raw_string_config_array().
[in] | str_config | Array of string values. |
void ini_free_long_config_array | ( | long * | array | ) |
Free array of long values.
Use this function to free the array returned by ini_get_long_config_array().
[in] | array | Array of long values. |
void ini_free_double_config_array | ( | double * | array | ) |
Free array of floating pointer values.
Use this function to free the array returned by ini_get_double_config_array().
[in] | array | Array of floating pointer values. |
int ini_errobj_create | ( | struct ini_errobj ** | _errobj | ) |
Create structure to hold error messages.
This function initiates structure that can be used to hold error messages from generators. To add messages to the structure use ini_errobj_add_msg.
[out] | _errobj | container for errors. |
void ini_errobj_destroy | ( | struct ini_errobj ** | errobj | ) |
Free structure that holds error messages.
This function is used to free structure previously created by ini_errobj_create.
[in] | errobj | container for errors. |
int ini_errobj_add_msg | ( | struct ini_errobj * | errobj, |
const char * | format, | ||
... ) |
Add new printf formated message to errobj.
This function initiates structure that can be used to hold error messages from generators. To add messages to the structure use ini_errobj_add_msg.
[in] | errobj | container for errors previously created by ini_errobj_create. |
[in] | format | printf format string |
int void ini_errobj_reset | ( | struct ini_errobj * | errobj | ) |
Reset iterator in errobj.
After calling this function, the iterator in errobj will point to the first error message. Use this if you need to accesss the list multiple times in a loop.
[in] | errobj | container for errors previously created by ini_errobj_create. |
const char * ini_errobj_get_msg | ( | struct ini_errobj * | errobj | ) |
Get pointer to current message in errobj.
This function returns pointer to current message pointed by the internal iterator. The returned string can not be changed and will point to valid data only until ini_errobj_destroy is called.
[in] | errobj | container for errors previously created by ini_errobj_create. |
void ini_errobj_next | ( | struct ini_errobj * | errobj | ) |
Move to the next message in errobj.
This function moves the internal iterator of errobj to the next message in list.
[in] | errobj | container for errors previously created by ini_errobj_create. |
int ini_errobj_no_more_msgs | ( | struct ini_errobj * | errobj | ) |
Check if errobj has more messages.
This function returns true if errobj's internal iterator reached end of list and no longer points to a message
[in] | errobj | container for errors previously created by ini_errobj_create. |
size_t ini_errobj_count | ( | struct ini_errobj * | errobj | ) |
Return number of messages in errobj.
This function returns number of messages inside errobj
[in] | errobj | container for errors previously created by ini_errobj_create. |
int ini_rules_read_from_file | ( | const char * | filename, |
struct ini_cfgobj ** | _rules_obj ) |
Read rules from INI file.
This function is used to read rules from INI file and store them in config object. This special config object is passed to ini_rules_check together with config object representing the configuration that will be checked.
[in] | filename | Name of file with rules |
[out] | _rules_obj | config object representing the rules |
int ini_rules_check | ( | struct ini_cfgobj * | rules_obj, |
struct ini_cfgobj * | config_obj, | ||
struct ini_validator ** | extra_validators, | ||
struct ini_errobj * | errobj ) |
Check configuration file using rules.
This function is used to check if configuration file applies to rules previously loaded by ini_rules_read_from_file. Any errors detected in the configuration are stored in the errobj structure. Error code returned by this function indicates some internal error with validators or memory allocation error (not rule violation).
[in] | rules_obj | config object representing the rules |
[in] | config_obj | config object representing the configuration |
[in] | extra_validators | NULL terminated array of external validators. Can be NULL if no external validators are used. |
[in] | errobj | errobj to store generated errors from validators. |
void ini_rules_destroy | ( | struct ini_cfgobj * | ini_config | ) |
Free the rules.
This function is just wrapper around ini_config_destroy