- fix Building without Nagra not possible at Nagra_Merlin https://trac.streamboard...
[oscam.git] / oscam-conf.h
blobe5b894fff65aff5bda53de244f8e34dab26f1777
1 #ifndef OSCAM_CONF_H
2 #define OSCAM_CONF_H
4 #define MAXLINESIZE 16384
6 enum opt_types
8 OPT_UNKNOWN = 0,
9 OPT_INT8,
10 OPT_UINT8,
11 OPT_INT32,
12 OPT_UINT32,
13 OPT_STRING,
14 OPT_SSTRING,
15 OPT_HEX_ARRAY,
16 OPT_FUNC,
17 OPT_FUNC_EXTRA,
18 OPT_SAVE_FUNC,
19 OPT_FIXUP_FUNC,
22 struct config_list
24 enum opt_types opt_type;
25 char *config_name;
26 size_t var_offset;
27 unsigned int str_size;
29 union {
30 int8_t d_int8;
31 uint8_t d_uint8;
32 int32_t d_int32;
33 uint32_t d_uint32;
34 char *d_char;
35 long d_extra;
36 uint32_t array_size;
37 } def;
39 union {
40 void (*process_fn)(const char *token, char *value, void *setting, FILE *config_file);
41 void (*process_fn_extra)(const char *token, char *value, void *setting, long extra, FILE *config_file);
42 bool (*should_save_fn)(void *var);
43 void (*fixup_fn)(void *var);
44 } ops;
46 void (*free_value)(void *setting);
49 #define DEF_OPT_INT8(__name, __var_ofs, __default) \
50 { \
51 .opt_type = OPT_INT8, \
52 .config_name = __name, \
53 .var_offset = __var_ofs, \
54 .def.d_int8 = __default \
57 #define DEF_OPT_UINT8(__name, __var_ofs, __default) \
58 { \
59 .opt_type = OPT_UINT8, \
60 .config_name = __name, \
61 .var_offset = __var_ofs, \
62 .def.d_uint8 = __default \
65 #define DEF_OPT_INT32(__name, __var_ofs, __default) \
66 { \
67 .opt_type = OPT_INT32, \
68 .config_name = __name, \
69 .var_offset = __var_ofs, \
70 .def.d_int32 = __default \
73 #define DEF_OPT_UINT32(__name, __var_ofs, __default) \
74 { \
75 .opt_type = OPT_UINT32, \
76 .config_name = __name, \
77 .var_offset = __var_ofs, \
78 .def.d_uint32 = __default \
81 #define DEF_OPT_STR(__name, __var_ofs, __default) \
82 { \
83 .opt_type = OPT_STRING, \
84 .config_name = __name, \
85 .var_offset = __var_ofs, \
86 .def.d_char = __default \
89 #define DEF_OPT_SSTR(__name, __var_ofs, __default, __str_size) \
90 { \
91 .opt_type = OPT_SSTRING, \
92 .config_name = __name, \
93 .var_offset = __var_ofs, \
94 .str_size = __str_size, \
95 .def.d_char = __default \
98 #define DEF_OPT_HEX(__name, __var_ofs, __array_size) \
99 { \
100 .opt_type = OPT_HEX_ARRAY, \
101 .config_name = __name, \
102 .var_offset = __var_ofs, \
103 .def.array_size = __array_size \
106 #define DEF_OPT_FUNC(__name, __var_ofs, __process_fn, ...) \
108 .opt_type = OPT_FUNC, \
109 .config_name = __name, \
110 .var_offset = __var_ofs, \
111 .ops.process_fn = __process_fn, \
112 ##__VA_ARGS__ \
115 #define DEF_OPT_FUNC_X(__name, __var_ofs, __process_fn_extra, __extra, ...) \
117 .opt_type = OPT_FUNC_EXTRA, \
118 .config_name = __name, \
119 .var_offset = __var_ofs, \
120 .ops.process_fn_extra = __process_fn_extra, \
121 .def.d_extra = __extra, \
122 ##__VA_ARGS__ \
125 #define DEF_OPT_SAVE_FUNC(__fn) \
127 .opt_type = OPT_SAVE_FUNC, \
128 .ops.should_save_fn = __fn \
131 #define DEF_OPT_FIXUP_FUNC(__fn) \
133 .opt_type = OPT_FIXUP_FUNC, \
134 .ops.fixup_fn = __fn \
137 #define DEF_LAST_OPT \
139 .opt_type = OPT_UNKNOWN \
142 struct config_sections
144 const char *section;
145 const struct config_list *config;
148 int32_t strToIntVal(char *value, int32_t defaultvalue);
149 uint32_t strToUIntVal(char *value, uint32_t defaultvalue);
151 void fprintf_conf(FILE *f, const char *varname, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
153 int config_list_parse(const struct config_list *clist, const char *token, char *value, void *config_data);
154 void config_list_save_ex(FILE *f, const struct config_list *clist, void *config_data, int save_all,
155 bool (*check_func)(const struct config_list *clist, void *config_data, const char *setting)
157 static inline void config_list_save(FILE *f, const struct config_list *clist, void *config_data, int save_all)
159 config_list_save_ex(f, clist, config_data, save_all, NULL);
161 void config_list_apply_fixups(const struct config_list *clist, void *var);
162 bool config_list_should_be_saved(const struct config_list *clist, void *var);
163 void config_list_set_defaults(const struct config_list *clist, void *config_data);
164 void config_list_free_values(const struct config_list *clist, void *config_data);
165 void config_list_gc_values(const struct config_list *clist, void *config_data);
167 int config_section_is_active(const struct config_sections *sec);
168 const struct config_sections *config_find_section(const struct config_sections *conf, char *section_name);
169 void config_sections_save(const struct config_sections *conf, FILE *f, void *var);
170 void config_sections_set_defaults(const struct config_sections *conf, void *var);
171 void config_sections_free(const struct config_sections *conf, void *var);
173 void config_set_value(const struct config_sections *conf, char *section, const char *token, char *value, void *var);
175 FILE *open_config_file(const char *conf_filename);
176 FILE *open_config_file_or_die(const char *conf_filename);
177 FILE *create_config_file(const char *conf_filename);
178 bool flush_config_file(FILE *f, const char *conf_filename);
180 #endif