1 #ifndef CONFIG_H
 2 #define CONFIG_H
 3 
 4 #include "rh_buffer.h"
 5 #include "queue.h"
 6 
 7 typedef struct config_base      config_t;
 8 typedef struct config_entry     config_entry_t;
 9 typedef struct config_value     config_value_t;
10 
11 typedef
12 enum config_key {
13         CONFIG_KEY_TYPES_CONFIG,
14         CONFIG_KEY_DEFAULT_TYPE,
15 
16         CONFIG_KEY_VIRTUAL_DOCUMENT_ROOT,
17 
18         CONFIG_KEY_SERVER_NAME,
19         
20         CONFIG_KEY_LOADMODULE,
21         
22         CONFIG_KEY_DIRECTORYINDEX,
23         
24         CONFIG_KEY_MAX
25 } config_key_t;
26 
27 struct config_key_definition {
28         config_key_t    idx;
29         const char      *name;
30         size_t          nname;
31         
32         size_t          min_values;
33         size_t          max_values;
34 
35         unsigned int    type;
36 };
37 
38 struct config_base {
39         rh_buffer_t     filename;
40         size_t          used;
41         config_entry_t  *entries[CONFIG_KEY_MAX];
42 };
43 
44 struct config_entry {
45         config_t                                *config;
46         const struct config_key_definition      *key;
47         int                                     idx;
48         size_t                                  used;
49         size_t                                  nvalues;
50         TAILQ_HEAD(,config_value)               values;
51 };
52 
53 struct config_value {
54         config_entry_t                  *entry;
55         rh_buffer_t                     value;
56         TAILQ_ENTRY(config_value)       list;
57 };
58 
59 #define CONFIG_ENTRY_FOREACH_VALUE(_value, _entry)      \
60         TAILQ_FOREACH(_value, &(_entry)->values, list)
61 
62 config_t * config_alloc (const char *filename);
63 void       config_free  (config_t *config);
64 void       config_reset (config_t *config);
65 
66 int config_reload (config_t *config);
67 
68 const config_entry_t * config_pop (config_t *config, config_key_t key);
69 const config_value_t * config_pop_value (config_t *config, config_key_t key);
70 
71 #define CONFIG_POP(_config,_key)                        \
72         config_pop((_config), CONFIG_KEY_ ## _key)
73 
74 #define CONFIG_POP_VALUE(_config,_key)                  \
75         config_pop_value((_config), CONFIG_KEY_ ## _key)
76 
77 void config_push       (const config_entry_t * entry);
78 void config_push_value (const config_value_t * value);
79 
80 #endif /* CONFIG_H */


syntax highlighted by Code2HTML, v. 0.9.1