SELKIELogger  1.0.0
LoggerConfig.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SL_LOGGER_CONFIG_H
22 #define SL_LOGGER_CONFIG_H
23 
24 #include <stdbool.h>
25 #include <stddef.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 
30 #include "inih/ini.h"
31 
42 typedef struct {
43  char *key;
44  char *value;
45 } config_kv;
46 
54 typedef struct {
55  char *name;
56  size_t optsize;
57  int numopts;
60 
72 typedef struct {
73  size_t sectsize;
74  int numsects;
76 } ini_config;
77 
79 int config_handler(void *user, const char *section, const char *name, const char *value);
80 
82 bool new_config(ini_config *c);
83 
85 void destroy_config(ini_config *c);
86 
88 void print_config(ini_config *c);
89 
91 config_section *config_get_section(const ini_config *in, const char *sn);
92 
94 config_kv *config_get_key(const config_section *cs, const char *kn);
95 
97 config_kv *config_get_option(const ini_config *in, const char *sn, const char *kn);
98 
100 int config_parse_bool(const char *b);
101 
103 char *config_qstrdup(const char *c);
104 #endif
bool new_config(ini_config *c)
Initialise a new ini_config instance.
Definition: LoggerConfig.c:108
void destroy_config(ini_config *c)
Destroy ini_config instance.
Definition: LoggerConfig.c:142
void print_config(ini_config *c)
Print ini_config instance to stdout.
Definition: LoggerConfig.c:163
int config_parse_bool(const char *b)
Parse string to boolean.
Definition: LoggerConfig.c:240
char * config_qstrdup(const char *c)
Duplicate string, stripping optional leading/trailing quote marks.
Definition: LoggerConfig.c:271
config_kv * config_get_option(const ini_config *in, const char *sn, const char *kn)
Find configuration option by section and key names.
Definition: LoggerConfig.c:222
int config_handler(void *user, const char *section, const char *name, const char *value)
Populate ini_config instance with values from file.
Definition: LoggerConfig.c:36
config_section * config_get_section(const ini_config *in, const char *sn)
Find configuration section by name.
Definition: LoggerConfig.c:186
config_kv * config_get_key(const config_section *cs, const char *kn)
Find configugration key within specific section, by name.
Definition: LoggerConfig.c:204
Represent a key=value pair.
Definition: LoggerConfig.h:42
char * value
Configuration item value.
Definition: LoggerConfig.h:44
char * key
Configuration item key.
Definition: LoggerConfig.h:43
Configuration file section.
Definition: LoggerConfig.h:54
int numopts
Number of *opts in use.
Definition: LoggerConfig.h:57
config_kv * opts
Key=value pairs belonging to this section.
Definition: LoggerConfig.h:58
char * name
Section [tag].
Definition: LoggerConfig.h:55
size_t optsize
Allocated size of *opts.
Definition: LoggerConfig.h:56
Representation of a parsed .ini file.
Definition: LoggerConfig.h:72
config_section * sects
Array of sections.
Definition: LoggerConfig.h:75
int numsects
Number of sections defined.
Definition: LoggerConfig.h:74
size_t sectsize
Allocated size of *sects.
Definition: LoggerConfig.h:73