SELKIELogger
1.0.0
|
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inih/ini.h"
Go to the source code of this file.
Classes | |
struct | config_kv |
Represent a key=value pair. More... | |
struct | config_section |
Configuration file section. More... | |
struct | ini_config |
Representation of a parsed .ini file. More... | |
Functions | |
int | config_handler (void *user, const char *section, const char *name, const char *value) |
Populate ini_config instance with values from file. More... | |
bool | new_config (ini_config *c) |
Initialise a new ini_config instance. More... | |
void | destroy_config (ini_config *c) |
Destroy ini_config instance. More... | |
void | print_config (ini_config *c) |
Print ini_config instance to stdout. More... | |
config_section * | config_get_section (const ini_config *in, const char *sn) |
Find configuration section by name. More... | |
config_kv * | config_get_key (const config_section *cs, const char *kn) |
Find configugration key within specific section, by name. More... | |
config_kv * | config_get_option (const ini_config *in, const char *sn, const char *kn) |
Find configuration option by section and key names. More... | |
int | config_parse_bool (const char *b) |
Parse string to boolean. More... | |
char * | config_qstrdup (const char *c) |
Duplicate string, stripping optional leading/trailing quote marks. More... | |
Configuration parsing functions and types
Definition in file LoggerConfig.h.
config_kv* config_get_key | ( | const config_section * | cs, |
const char * | kn | ||
) |
Find configugration key within specific section, by name.
Iterates over all entries in the supplied config_section structure and checks for a matching key name.
Comparison between search key and key names is case insensitive.
[in] | cs | Pointer to config_section structure to search |
[in] | kn | Pointer to null-terminated search string |
Definition at line 204 of file LoggerConfig.c.
config_kv* config_get_option | ( | const ini_config * | in, |
const char * | sn, | ||
const char * | kn | ||
) |
Find configuration option by section and key names.
Convenience wrapper around config_get_section and config_get_key.
Will search for section, then search that section for a matching key.
[in] | in | Pointer to ini_config structure to search |
[in] | sn | Pointer to null-terminated section name |
[in] | kn | Pointer to null-terminated key name |
Definition at line 222 of file LoggerConfig.c.
config_section* config_get_section | ( | const ini_config * | in, |
const char * | sn | ||
) |
Find configuration section by name.
Iterates over all sections in the supplied ini_config structure and checks for a matching section name.
Comparison between search key and section names is case insensitive.
[in] | in | Pointer to ini_config structure to search |
[in] | sn | Pointer to null-terminated search string |
Definition at line 186 of file LoggerConfig.c.
int config_handler | ( | void * | user, |
const char * | section, | ||
const char * | name, | ||
const char * | value | ||
) |
Populate ini_config instance with values from file.
Not called directly. This function is called by ini_parse() and used to populate an ini_config structure that is passed in as the first parameter. The ini_config structure must have been initialised before passing to the initial ini_parse() call.
[in] | user | Pointer to ini_config structure passed to ini_parse() |
[in] | section | Section name |
[in] | name | Key name |
[in] | value | Key value, as string |
Definition at line 36 of file LoggerConfig.c.
int config_parse_bool | ( | const char * | b | ) |
Parse string to boolean.
Provides a consistent approach for parsing strings to boolean values.
This is a very simple test - any string starting with 1, Y, y, t, or T is considered to be True and anything starting with 0, N, n, F, or f will be considered False.
Any other initial character is treated as unknown.
[in] | b | Pointer to null-terminated string |
Definition at line 240 of file LoggerConfig.c.
char* config_qstrdup | ( | const char * | c | ) |
Duplicate string, stripping optional leading/trailing quote marks.
Checks for matching single or double quotes around a string and duplicates the enclosed value.
If no quotes are present (or if the leading and trailing quotes don't match) then the string is duplicated in its entirety.
Input string is not modified. Returned string must be freed by caller.
[in] | c | String to duplicate |
Definition at line 271 of file LoggerConfig.c.
void destroy_config | ( | ini_config * | c | ) |
Destroy ini_config instance.
Recursively frees memory within an ini_config structure.
c | Pointer to ini_config structure to be destroyed |
Definition at line 142 of file LoggerConfig.c.
bool new_config | ( | ini_config * | c | ) |
Initialise a new ini_config instance.
Allocates memory and initialises the structure with sensible defaults.
Allocates space for 10 sections and initialises section 0 as a blank/unnamed section with space for up to 10 key=value pairs.
c | Pointer to ini_config structure to be initialised. |
Definition at line 108 of file LoggerConfig.c.
void print_config | ( | ini_config * | c | ) |
Print ini_config instance to stdout.
Will print formatted configuration to stdout, suitable for reuse in a configuration file.
[in] | c | Pointer to ini_config structure |
Definition at line 163 of file LoggerConfig.c.