SELKIELogger  1.0.0
LoggerConfig.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inih/ini.h"
Include dependency graph for LoggerConfig.h:
This graph shows which files directly or indirectly include this file:

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_sectionconfig_get_section (const ini_config *in, const char *sn)
 Find configuration section by name. More...
 
config_kvconfig_get_key (const config_section *cs, const char *kn)
 Find configugration key within specific section, by name. More...
 
config_kvconfig_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...
 

Detailed Description

Configuration parsing functions and types

Definition in file LoggerConfig.h.

Function Documentation

◆ config_get_key()

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.

Parameters
[in]csPointer to config_section structure to search
[in]knPointer to null-terminated search string
Returns
Pointer to first config_kv found, or NULL if no matches

Definition at line 204 of file LoggerConfig.c.

◆ config_get_option()

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.

Parameters
[in]inPointer to ini_config structure to search
[in]snPointer to null-terminated section name
[in]knPointer to null-terminated key name
Returns
Pointer to first config_kv found, or NULL if no matches

Definition at line 222 of file LoggerConfig.c.

◆ config_get_section()

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.

Parameters
[in]inPointer to ini_config structure to search
[in]snPointer to null-terminated search string
Returns
Pointer to first config_section found, or NULL if no matches

Definition at line 186 of file LoggerConfig.c.

◆ config_handler()

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.

Parameters
[in]userPointer to ini_config structure passed to ini_parse()
[in]sectionSection name
[in]nameKey name
[in]valueKey value, as string
Returns
0 on error (abort parsing), 1 on success

Definition at line 36 of file LoggerConfig.c.

◆ config_parse_bool()

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.

Parameters
[in]bPointer to null-terminated string
Returns
1 for true, 0 for false and -1 for unknown

Definition at line 240 of file LoggerConfig.c.

◆ config_qstrdup()

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.

Parameters
[in]cString to duplicate
Returns
Pointer to new string or NULL on failure.

Definition at line 271 of file LoggerConfig.c.

◆ destroy_config()

void destroy_config ( ini_config c)

Destroy ini_config instance.

Recursively frees memory within an ini_config structure.

Parameters
cPointer to ini_config structure to be destroyed

Definition at line 142 of file LoggerConfig.c.

◆ new_config()

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.

Parameters
cPointer to ini_config structure to be initialised.
Returns
True on success, false on failure.

Definition at line 108 of file LoggerConfig.c.

◆ print_config()

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.

Parameters
[in]cPointer to ini_config structure

Definition at line 163 of file LoggerConfig.c.