-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconf.h
138 lines (121 loc) · 3.48 KB
/
conf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef __CONF_H__
#define __CONF_H__
#include <stdint.h>
#include <stdio.h>
#include "common.h"
#include "list.h"
/**
* @brief configuation element type
*/
typedef enum {
CONF_TYPE_INT = 1,
CONF_TYPE_STRING,
CONF_TYPE_MAX,
} conf_element_type_t;
/**
* @brief desc. of conf. element that is expected
* to be found in configuration file
*/
struct conf_element_s {
char * name;
uint32_t id;
conf_element_type_t type;
};
#define CONF_ELEMENT_END {NULL, 0, 0}
/**
* @brief configuration element value, either int_val
* or str_val should be used depending on type of given
* element
*/
typedef union {
uint32_t int_val;
char * str_val;
} conf_value_t;
/**
* @brief configuration strings for given protocol
* these will be looked for in section with matching name,
* upon fiding the parameter, handler will be called with
* value passed in union, and the configuration element as first
* parameter. The value passed needs to be copied in handler (ex. strings
* need to be copied with strdup) as after parsing all data belongign
* to this group will be freed.
* The list of configuration elements shall end with one empty element
* that is all fields are 0
*/
struct conf_desc_s {
char * name;
int (*handler)(struct conf_element_s * s, conf_value_t val, void * data);
struct conf_element_s * conf;
};
/**
* @brief wrapper for section
*/
struct conf_group_s {
char * name;
struct conf_desc_s * desc; /**< @brief reference to possible desc if later
matching one is registered by some plugin */
struct list_head_s values;
struct list_head_s groups_list;
};
/**
* @brief
* wrapper for tuples id = value within one config section
*/
struct conf_value_s {
char * name;
struct conf_element_s * elem; /**< @brief reference to conf. element if
matching happens to be found during plugin registration */
conf_value_t value;
conf_element_type_t detected_type; /**< @brief type of element that was determined
during parsing */
struct list_head_s values_list;
};
/**
* @brief
* wrapper for configuration
*/
struct conf_s {
char * source;
struct list_head_s groups;
};
#define INIT_CONF_S {NULL}
/**
* @brief reload config file
* @return true or false
*/
int conf_load(struct conf_s * c);
/**
* @brief release configuration structure
* should be called at exit
* @return none
*/
int conf_unload(struct conf_s * c);
/**
* @brief release unnecessary data that could have been allocated
* and is not needed anymore; should be called only after each module has
* gone through the configuration
*/
void conf_release_left(struct conf_s * c);
/**
* @brief create config section with given section
* name
*/
struct conf_group_s * conf_create_section(struct conf_s * c, char * name);
/**
* @brief create value wrapper
*/
struct conf_value_s * conf_create_value(struct conf_group_s * c, char * name);
/**
* @brief store string value in config element, if a string is already exists,
* the new value will be added to the old one
*/
void conf_value_add_str(struct conf_value_s * c, const char * strval);
/**
* @brief store int value in config element
*/
void conf_value_set_int(struct conf_value_s * c, int intval);
/**
* @brief register module within config, and initialte fetching of parameters
*/
int conf_register(struct conf_s * conf, struct conf_desc_s * cdesc, void * data);
#endif /* __CONF_H__ */