source: trunk/oscam-config-global.c@ 8464

Last change on this file since 8464 was 8464, checked in by gf, 9 years ago

cfg: Remove camd35 vars from struct s_config when the module is disabled.

File size: 30.1 KB
Line 
1#include "globals.h"
2#include "module-dvbapi.h"
3#include "oscam-conf.h"
4#include "oscam-conf-chk.h"
5#include "oscam-conf-mk.h"
6#include "oscam-config.h"
7#include "oscam-net.h"
8#include "oscam-string.h"
9
10#define cs_conf "oscam.conf"
11
12static void disablelog_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
13 if (value) {
14 cs_disable_log(strToIntVal(value, 0));
15 return;
16 }
17 if (cfg.disablelog || cfg.http_full_cfg)
18 fprintf_conf(f, token, "%d\n", cfg.disablelog);
19}
20
21#if defined(WEBIF) || defined(MODULE_MONITOR)
22static void loghistorysize_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
23 if (value) {
24 uint32_t newsize = strToUIntVal(value, 4096);
25 if (newsize < 1024 && newsize != 0) {
26 fprintf(stderr, "WARNING: loghistorysize is too small, adjusted to 1024\n");
27 newsize = 1024;
28 }
29 cs_reinit_loghist(newsize);
30 return;
31 }
32 if (cfg.loghistorysize != 4096 || cfg.http_full_cfg)
33 fprintf_conf(f, token, "%u\n", cfg.loghistorysize);
34}
35#endif
36
37static void serverip_fn(const char *token, char *value, void *setting, FILE *f) {
38 IN_ADDR_T srvip = *(IN_ADDR_T *)setting;
39 if (value) {
40 if (strlen(value) == 0) {
41 set_null_ip((IN_ADDR_T *)setting);
42 } else {
43 cs_inet_addr(value, (IN_ADDR_T *)setting);
44 }
45 return;
46 }
47 if (IP_ISSET(srvip) || cfg.http_full_cfg)
48 fprintf_conf(f, token, "%s\n", cs_inet_ntoa(srvip));
49}
50
51void iprange_fn(const char *token, char *value, void *setting, FILE *f) {
52 struct s_ip **ip = setting;
53 if (value) {
54 if(strlen(value) == 0) {
55 clear_sip(ip);
56 } else {
57 chk_iprange(value, ip);
58 }
59 return;
60 }
61 value = mk_t_iprange(*ip);
62 if (strlen(value) > 0 || cfg.http_full_cfg)
63 fprintf_conf(f, token, "%s\n", value);
64 free_mk_t(value);
65}
66
67static void logfile_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
68 if (value) {
69 char *saveptr1 = NULL;
70 cfg.logtostdout = 0;
71 cfg.logtosyslog = 0;
72 NULLFREE(cfg.logfile);
73 if (strlen(value) > 0) {
74 char *pch;
75 for(pch = strtok_r(value, ";", &saveptr1); pch != NULL; pch = strtok_r(NULL, ";", &saveptr1)){
76 pch=trim(pch);
77 if(!strcmp(pch, "stdout")) cfg.logtostdout = 1;
78 else if(!strcmp(pch, "syslog")) cfg.logtosyslog = 1;
79 else {
80 NULLFREE(cfg.logfile);
81 if (!(cfg.logfile = cs_strdup(pch)))
82 continue;
83 }
84 }
85 } else {
86 if (!(cfg.logfile = cs_strdup(CS_LOGFILE)))
87 cfg.logtostdout = 1;
88 }
89 return;
90 }
91 if (cfg.logfile || cfg.logtostdout == 1 || cfg.logtosyslog == 1 || cfg.http_full_cfg) {
92 value = mk_t_logfile();
93 fprintf_conf(f, token, "%s\n", value);
94 free_mk_t(value);
95 }
96}
97
98void check_caidtab_fn(const char *token, char *value, void *setting, FILE *f) {
99 CAIDTAB *caid_table = setting;
100 if (value) {
101 if (strlen(value) == 0)
102 clear_caidtab(caid_table);
103 else
104 chk_caidtab(value, caid_table);
105 return;
106 }
107 if (caid_table->caid[0] || cfg.http_full_cfg) {
108 value = mk_t_caidtab(caid_table);
109 fprintf_conf(f, token, "%s\n", value);
110 free_mk_t(value);
111 }
112}
113
114#ifdef WITH_LB
115static void caidvaluetab_fn(const char *token, char *value, void *setting, FILE *f) {
116 CAIDVALUETAB *caid_value_table = setting;
117 int limit = streq(token, "lb_retrylimits") ? 50 : 1;
118 if (value) {
119 chk_caidvaluetab(value, caid_value_table, limit);
120 return;
121 }
122 if (caid_value_table->n > 0 || cfg.http_full_cfg) {
123 value = mk_t_caidvaluetab(caid_value_table);
124 fprintf_conf(f, token, "%s\n", value);
125 free_mk_t(value);
126 }
127}
128#endif
129
130#ifdef CS_CACHEEX
131void cacheex_valuetab_fn(const char *token, char *value, void *setting, FILE *f) {
132 CECSPVALUETAB *cacheex_value_table = setting;
133 if (value) {
134 if (strlen(value) == 0)
135 clear_cacheextab(cacheex_value_table);
136 else
137 chk_cacheex_valuetab(value, cacheex_value_table);
138 return;
139 }
140 if (cacheex_value_table->n || cfg.http_full_cfg) {
141 value = mk_t_cacheex_valuetab(cacheex_value_table);
142 fprintf_conf(f, token, "%s\n", value);
143 free_mk_t(value);
144 }
145}
146
147void cacheex_hitvaluetab_fn(const char *token, char *value, void *setting, FILE *f) {
148 CECSPVALUETAB *cacheex_value_table = setting;
149 if (value) {
150 if (strlen(value) == 0)
151 clear_cacheextab(cacheex_value_table);
152 else
153 chk_cacheex_hitvaluetab(value, cacheex_value_table);
154 return;
155 }
156 if (cacheex_value_table->n || cfg.http_full_cfg) {
157 value = mk_t_cacheex_hitvaluetab(cacheex_value_table);
158 fprintf_conf(f, token, "%s\n", value);
159 free_mk_t(value);
160 }
161}
162#endif
163
164#ifdef __CYGWIN__
165#include <windows.h>
166#else
167#include <sys/resource.h> // for setpriority
168#endif
169
170void global_fixups_fn(void *UNUSED(var)) {
171 if (!cfg.usrfile) cfg.disableuserfile = 1;
172 if (!cfg.mailfile) cfg.disablemail = 1;
173 if (cfg.ctimeout < 100) cfg.ctimeout *= 1000;
174 if (cfg.ftimeout < 100) cfg.ftimeout *= 1000;
175 if (cfg.nice < -20 || cfg.nice > 20) cfg.nice = 99;
176 if (cfg.nice != 99) {
177#ifndef __CYGWIN__
178 setpriority(PRIO_PROCESS, 0, cfg.nice);
179#else
180 HANDLE WinId;
181 uint32_t wprio;
182 switch ((cfg.nice + 20) / 10) {
183 case 0: wprio = REALTIME_PRIORITY_CLASS; break;
184 case 1: wprio = HIGH_PRIORITY_CLASS; break;
185 case 2: wprio = NORMAL_PRIORITY_CLASS; break;
186 default: wprio = IDLE_PRIORITY_CLASS; break;
187 }
188 WinId = GetCurrentProcess();
189 SetPriorityClass(WinId, wprio);
190#endif
191 }
192 if (cfg.srtimeout <= 0) cfg.srtimeout = 1500;
193 if (cfg.srtimeout < 100) cfg.srtimeout *= 1000;
194 if (cfg.max_log_size != 0 && cfg.max_log_size <= 10) cfg.max_log_size = 10;
195 if (cfg.ftimeout >= cfg.ctimeout) cfg.ftimeout = cfg.ctimeout - 100;
196 if (cfg.ftimeout < cfg.srtimeout) cfg.ftimeout = cfg.srtimeout + 100;
197 if (cfg.ctimeout < cfg.srtimeout) cfg.ctimeout = cfg.srtimeout + 100;
198#ifdef WITH_LB
199 if (cfg.lb_save > 0 && cfg.lb_save < 100) cfg.lb_save = 100;
200 if (cfg.lb_nbest_readers < 2) cfg.lb_nbest_readers = DEFAULT_NBEST;
201#endif
202}
203
204#define OFS(X) offsetof(struct s_config, X)
205#define SIZEOF(X) sizeof(((struct s_config *)0)->X)
206
207static const struct config_list global_opts[] = {
208 DEF_OPT_FIXUP_FUNC(global_fixups_fn),
209#ifdef LEDSUPPORT
210 DEF_OPT_INT8("enableled" , OFS(enableled), 0 ),
211#endif
212 DEF_OPT_FUNC("disablelog" , OFS(disablelog), disablelog_fn ),
213#if defined(WEBIF) || defined(MODULE_MONITOR)
214 DEF_OPT_FUNC("loghistorysize" , OFS(loghistorysize), loghistorysize_fn ),
215#endif
216 DEF_OPT_FUNC("serverip" , OFS(srvip), serverip_fn ),
217 DEF_OPT_FUNC("logfile" , OFS(logfile), logfile_fn ),
218 DEF_OPT_INT8("logduplicatelines" , OFS(logduplicatelines), 0 ),
219 DEF_OPT_STR("pidfile" , OFS(pidfile), NULL ),
220 DEF_OPT_INT8("disableuserfile" , OFS(disableuserfile), 1 ),
221 DEF_OPT_INT8("disablemail" , OFS(disablemail), 1 ),
222 DEF_OPT_INT8("usrfileflag" , OFS(usrfileflag), 0 ),
223 DEF_OPT_UINT32("clienttimeout" , OFS(ctimeout), CS_CLIENT_TIMEOUT ),
224 DEF_OPT_UINT32("fallbacktimeout" , OFS(ftimeout), CS_CLIENT_TIMEOUT / 2 ),
225 DEF_OPT_UINT32("clientmaxidle" , OFS(cmaxidle), CS_CLIENT_MAXIDLE ),
226 DEF_OPT_INT32("bindwait" , OFS(bindwait), CS_BIND_TIMEOUT ),
227 DEF_OPT_UINT32("netprio" , OFS(netprio), 0 ),
228 DEF_OPT_INT32("sleep" , OFS(tosleep), 0 ),
229 DEF_OPT_INT32("unlockparental" , OFS(ulparent), 0 ),
230 DEF_OPT_INT32("nice" , OFS(nice), 99 ),
231 DEF_OPT_UINT32("serialreadertimeout" , OFS(srtimeout), 1500 ),
232 DEF_OPT_INT32("maxlogsize" , OFS(max_log_size), 10 ),
233 DEF_OPT_INT8("waitforcards" , OFS(waitforcards), 1 ),
234 DEF_OPT_INT32("waitforcards_extra_delay" , OFS(waitforcards_extra_delay), 500 ),
235 DEF_OPT_INT8("preferlocalcards" , OFS(preferlocalcards), 0 ),
236 DEF_OPT_INT32("readerrestartseconds" , OFS(reader_restart_seconds), 5 ),
237 DEF_OPT_INT8("dropdups" , OFS(dropdups), 0 ),
238 DEF_OPT_INT8("block_same_ip" , OFS(block_same_ip), 1 ),
239 DEF_OPT_INT8("block_same_name" , OFS(block_same_name), 1 ),
240 DEF_OPT_STR("usrfile" , OFS(usrfile), NULL ),
241 DEF_OPT_STR("mailfile" , OFS(mailfile), NULL ),
242 DEF_OPT_STR("cwlogdir" , OFS(cwlogdir), NULL ),
243 DEF_OPT_STR("emmlogdir" , OFS(emmlogdir), NULL ),
244#ifdef WITH_LB
245 DEF_OPT_INT32("lb_mode" , OFS(lb_mode), DEFAULT_LB_MODE ),
246 DEF_OPT_INT32("lb_save" , OFS(lb_save), 0 ),
247 DEF_OPT_INT32("lb_nbest_readers" , OFS(lb_nbest_readers), DEFAULT_NBEST ),
248 DEF_OPT_INT32("lb_nfb_readers" , OFS(lb_nfb_readers), DEFAULT_NFB ),
249 DEF_OPT_INT32("lb_min_ecmcount" , OFS(lb_min_ecmcount), DEFAULT_MIN_ECM_COUNT ),
250 DEF_OPT_INT32("lb_max_ecmcount" , OFS(lb_max_ecmcount), DEFAULT_MAX_ECM_COUNT ),
251 DEF_OPT_INT32("lb_reopen_seconds" , OFS(lb_reopen_seconds), DEFAULT_REOPEN_SECONDS ),
252 DEF_OPT_INT32("lb_retrylimit" , OFS(lb_retrylimit), DEFAULT_RETRYLIMIT ),
253 DEF_OPT_INT32("lb_stat_cleanup" , OFS(lb_stat_cleanup), DEFAULT_LB_STAT_CLEANUP ),
254 DEF_OPT_INT32("lb_reopen_mode" , OFS(lb_reopen_mode), DEFAULT_LB_REOPEN_MODE ),
255 DEF_OPT_INT32("lb_max_readers" , OFS(lb_max_readers), 0 ),
256 DEF_OPT_INT32("lb_auto_betatunnel" , OFS(lb_auto_betatunnel), DEFAULT_LB_AUTO_BETATUNNEL ),
257 DEF_OPT_INT32("lb_auto_betatunnel_mode" , OFS(lb_auto_betatunnel_mode), DEFAULT_LB_AUTO_BETATUNNEL_MODE ),
258 DEF_OPT_INT32("lb_auto_betatunnel_prefer_beta" , OFS(lb_auto_betatunnel_prefer_beta), DEFAULT_LB_AUTO_BETATUNNEL_PREFER_BETA ),
259 DEF_OPT_STR("lb_savepath" , OFS(lb_savepath), NULL ),
260 DEF_OPT_FUNC("lb_retrylimits" , OFS(lb_retrylimittab), caidvaluetab_fn ),
261 DEF_OPT_FUNC("lb_nbest_percaid" , OFS(lb_nbest_readers_tab), caidvaluetab_fn ),
262 DEF_OPT_FUNC("lb_noproviderforcaid" , OFS(lb_noproviderforcaid), check_caidtab_fn ),
263 DEF_OPT_INT32("lb_auto_timeout" , OFS(lb_auto_timeout), DEFAULT_LB_AUTO_TIMEOUT ),
264 DEF_OPT_INT32("lb_auto_timeout_p" , OFS(lb_auto_timeout_p), DEFAULT_LB_AUTO_TIMEOUT_P ),
265 DEF_OPT_INT32("lb_auto_timeout_t" , OFS(lb_auto_timeout_t), DEFAULT_LB_AUTO_TIMEOUT_T ),
266#endif
267 DEF_OPT_FUNC("double_check_caid" , OFS(double_check_caid), check_caidtab_fn ),
268 DEF_OPT_STR("ecmfmt" , OFS(ecmfmt), NULL ),
269 DEF_OPT_INT32("resolvegethostbyname" , OFS(resolve_gethostbyname), 0 ),
270 DEF_OPT_INT32("failbantime" , OFS(failbantime), 0 ),
271 DEF_OPT_INT32("failbancount" , OFS(failbancount), 0 ),
272 DEF_OPT_INT8("suppresscmd08" , OFS(c35_suppresscmd08), 0 ),
273 DEF_OPT_INT8("double_check" , OFS(double_check), 0 ),
274 DEF_LAST_OPT
275};
276
277#ifdef CS_ANTICASC
278static void anticasc_fixups_fn(void *UNUSED(var)) {
279 if (cfg.ac_users < 0) cfg.ac_users = 0;
280 if (cfg.ac_stime < 0) cfg.ac_stime = 2;
281 if (cfg.ac_samples < 2 || cfg.ac_samples > 10) cfg.ac_samples = 10;
282 if (cfg.ac_penalty < 0 || cfg.ac_penalty > 3) cfg.ac_penalty = 0;
283 if (cfg.ac_fakedelay < 100 || cfg.ac_fakedelay > 3000) cfg.ac_fakedelay = 1000;
284 if (cfg.ac_denysamples < 2 || cfg.ac_denysamples > cfg.ac_samples - 1) cfg.ac_denysamples = cfg.ac_samples - 1;
285 if (cfg.ac_denysamples + 1 > cfg.ac_samples) cfg.ac_denysamples = cfg.ac_samples - 1;
286}
287
288static bool anticasc_should_save_fn(void *UNUSED(var)) { return cfg.ac_enabled; }
289
290static const struct config_list anticasc_opts[] = {
291 DEF_OPT_SAVE_FUNC(anticasc_should_save_fn),
292 DEF_OPT_FIXUP_FUNC(anticasc_fixups_fn),
293 DEF_OPT_INT8("enabled" , OFS(ac_enabled), 0 ),
294 DEF_OPT_INT32("numusers" , OFS(ac_users), 0 ),
295 DEF_OPT_INT32("sampletime" , OFS(ac_stime), 2 ),
296 DEF_OPT_INT32("samples" , OFS(ac_samples), 10 ),
297 DEF_OPT_INT8("penalty" , OFS(ac_penalty), 0 ),
298 DEF_OPT_STR("aclogfile" , OFS(ac_logfile), NULL ),
299 DEF_OPT_INT32("fakedelay" , OFS(ac_fakedelay), 3000 ),
300 DEF_OPT_INT32("denysamples" , OFS(ac_denysamples), 8 ),
301 DEF_LAST_OPT
302};
303#else
304static const struct config_list anticasc_opts[] = { DEF_LAST_OPT };
305#endif
306
307#ifdef MODULE_MONITOR
308static bool monitor_should_save_fn(void *UNUSED(var)) { return cfg.mon_port; }
309
310static const struct config_list monitor_opts[] = {
311 DEF_OPT_SAVE_FUNC(monitor_should_save_fn),
312 DEF_OPT_INT32("port" , OFS(mon_port), 0 ),
313 DEF_OPT_FUNC("serverip" , OFS(mon_srvip), serverip_fn ),
314 DEF_OPT_FUNC("nocrypt" , OFS(mon_allowed), iprange_fn ),
315 DEF_OPT_INT32("aulow" , OFS(aulow), 30 ),
316 DEF_OPT_UINT8("monlevel" , OFS(mon_level), 2 ),
317 DEF_OPT_INT32("hideclient_to" , OFS(hideclient_to), 15 ),
318 DEF_OPT_INT8("appendchaninfo" , OFS(appendchaninfo), 0 ),
319 DEF_LAST_OPT
320};
321#else
322static const struct config_list monitor_opts[] = { DEF_LAST_OPT };
323#endif
324
325#ifdef WEBIF
326static void http_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
327 if (value) {
328 cfg.http_port = 0;
329 if (value[0]) {
330 if (value[0] == '+') {
331 if (config_enabled(WITH_SSL)) {
332 cfg.http_use_ssl = 1;
333 } else {
334 fprintf(stderr, "Warning: OSCam compiled without SSL support.\n");
335 }
336 cfg.http_port = strtoul(value + 1, NULL, 10);
337 } else {
338 cfg.http_port = strtoul(value, NULL, 10);
339 }
340 }
341 return;
342 }
343 fprintf_conf(f, token, "%s%d\n", cfg.http_use_ssl ? "+" : "", cfg.http_port);
344}
345
346static void http_dyndns_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
347 int i;
348 if (value) {
349 char *ptr, *saveptr1 = NULL;
350 memset(cfg.http_dyndns, 0, sizeof(cfg.http_dyndns));
351 for (i = 0, ptr = strtok_r(value, ",", &saveptr1); (i < MAX_HTTP_DYNDNS) && (ptr); ptr = strtok_r(NULL, ",", &saveptr1), i++) {
352 trim(ptr);
353 cs_strncpy((char *)cfg.http_dyndns[i], ptr, sizeof(cfg.http_dyndns[i]));
354 }
355 return;
356 }
357 if (strlen((const char *)(cfg.http_dyndns[0])) > 0 || cfg.http_full_cfg) {
358 fprintf_conf(f, token, "%s", ""); // it should not have \n at the end
359 for (i = 0; i < MAX_HTTP_DYNDNS; i++) {
360 if (cfg.http_dyndns[i][0]) {
361 fprintf(f, "%s%s", i > 0 ? "," : "", cfg.http_dyndns[i]);
362 }
363 }
364 fprintf(f, "\n");
365 }
366}
367
368static bool webif_should_save_fn(void *UNUSED(var)) { return cfg.http_port; }
369
370static const struct config_list webif_opts[] = {
371 DEF_OPT_SAVE_FUNC(webif_should_save_fn),
372 DEF_OPT_FUNC("httpport" , OFS(http_port), http_port_fn ),
373 DEF_OPT_STR("httpuser" , OFS(http_user), NULL ),
374 DEF_OPT_STR("httppwd" , OFS(http_pwd), NULL ),
375 DEF_OPT_STR("httpcss" , OFS(http_css), NULL ),
376 DEF_OPT_STR("httpjscript" , OFS(http_jscript), NULL ),
377 DEF_OPT_STR("httpscript" , OFS(http_script), NULL ),
378 DEF_OPT_STR("httptpl" , OFS(http_tpl), NULL ),
379 DEF_OPT_STR("httphelplang" , OFS(http_help_lang), "en" ),
380 DEF_OPT_STR("httpcert" , OFS(http_cert), NULL ),
381 DEF_OPT_INT32("http_prepend_embedded_css" , OFS(http_prepend_embedded_css), 0 ),
382 DEF_OPT_INT32("httprefresh" , OFS(http_refresh), 0 ),
383 DEF_OPT_INT8("httphideidleclients" , OFS(http_hide_idle_clients), 0 ),
384 DEF_OPT_STR("httphidetype" , OFS(http_hide_type), NULL ),
385 DEF_OPT_INT8("httpshowpicons" , OFS(http_showpicons), 0 ),
386 DEF_OPT_FUNC("httpallowed" , OFS(http_allowed), iprange_fn ),
387 DEF_OPT_INT8("httpreadonly" , OFS(http_readonly), 0 ),
388 DEF_OPT_INT8("httpsavefullcfg" , OFS(http_full_cfg), 0 ),
389 DEF_OPT_INT8("httpforcesslv3" , OFS(http_force_sslv3), 0 ),
390 DEF_OPT_FUNC("httpdyndns" , OFS(http_dyndns), http_dyndns_fn ),
391 DEF_OPT_INT32("aulow" , OFS(aulow), 30 ),
392 DEF_OPT_INT32("hideclient_to" , OFS(hideclient_to), 15 ),
393 DEF_OPT_INT8("appendchaninfo" , OFS(appendchaninfo), 0 ),
394 DEF_LAST_OPT
395};
396#else
397static const struct config_list webif_opts[] = { DEF_LAST_OPT };
398#endif
399
400#ifdef MODULE_CAMD33
401static bool camd33_should_save_fn(void *UNUSED(var)) { return cfg.c33_port; }
402
403static const struct config_list camd33_opts[] = {
404 DEF_OPT_SAVE_FUNC(camd33_should_save_fn),
405 DEF_OPT_INT32("port" , OFS(c33_port), 0 ),
406 DEF_OPT_FUNC("serverip" , OFS(c33_srvip), serverip_fn ),
407 DEF_OPT_FUNC("nocrypt" , OFS(c33_plain), iprange_fn ),
408 DEF_OPT_INT32("passive" , OFS(c33_passive), 0 ),
409 DEF_OPT_HEX("key" , OFS(c33_key), SIZEOF(c33_key) ),
410 DEF_LAST_OPT
411};
412#else
413static const struct config_list camd33_opts[] = { DEF_LAST_OPT };
414#endif
415
416
417void cache_fixups_fn(void *UNUSED(var)) {
418 if (cfg.max_cache_time < (cfg.ctimeout / 1000 + 1)) cfg.max_cache_time = cfg.ctimeout / 1000 + 2;
419#ifdef CW_CYCLE_CHECK
420 if (cfg.maxcyclelist > 4000) cfg.maxcyclelist = 4000;
421 if (cfg.keepcycletime > 15) cfg.keepcycletime = 15;
422#endif
423}
424
425static bool cache_should_save_fn(void *UNUSED(var)) {
426 return cfg.delay > 0 || cfg.max_cache_time != 15 || cfg.max_cache_count != 1000
427#ifdef CS_CACHEEX
428 || cfg.cacheex_wait_timetab.n || cfg.cacheex_enable_stats > 0 || cfg.csp_port || cfg.csp.filter_caidtab.n || cfg.csp.allow_request==0
429#endif
430#ifdef CW_CYCLE_CHECK
431 || !cfg.cwcycle_check_enable || cfg.cwcycle_check_caidtab.caid[0] || cfg.maxcyclelist != 500 || cfg.keepcycletime || cfg.onbadcycle || cfg.cwcycle_dropold
432#endif
433 ;
434}
435
436static const struct config_list cache_opts[] = {
437 DEF_OPT_SAVE_FUNC(cache_should_save_fn),
438 DEF_OPT_FIXUP_FUNC(cache_fixups_fn),
439 DEF_OPT_UINT32("delay" , OFS(delay), CS_DELAY ),
440 DEF_OPT_UINT32("max_time" , OFS(max_cache_time), DEFAULT_MAX_CACHE_TIME ),
441 DEF_OPT_UINT32("max_count" , OFS(max_cache_count), DEFAULT_MAX_CACHE_COUNT ),
442#ifdef CS_CACHEEX
443 DEF_OPT_FUNC("wait_time" , OFS(cacheex_wait_timetab), cacheex_valuetab_fn ),
444 DEF_OPT_UINT8("cacheexenablestats" , OFS(cacheex_enable_stats), 0 ),
445 DEF_OPT_INT32("csp_port" , OFS(csp_port), 0 ),
446 DEF_OPT_FUNC("csp_serverip" , OFS(csp_srvip), serverip_fn ),
447 DEF_OPT_FUNC("csp_ecm_filter" , OFS(csp.filter_caidtab), cacheex_hitvaluetab_fn ),
448 DEF_OPT_UINT8("csp_allow_request" , OFS(csp.allow_request), 1 ),
449#endif
450#ifdef CW_CYCLE_CHECK
451 DEF_OPT_INT8("cwcycle_check_enable" , OFS(cwcycle_check_enable), 1 ),
452 DEF_OPT_FUNC("cwcycle_check_caid" , OFS(cwcycle_check_caidtab), check_caidtab_fn ),
453 DEF_OPT_INT32("cwcycle_maxlist" , OFS(maxcyclelist), 500 ),
454 DEF_OPT_INT32("cwcycle_keeptime" , OFS(keepcycletime), 0 ),
455 DEF_OPT_INT8("cwcycle_onbad" , OFS(onbadcycle), 0 ),
456 DEF_OPT_INT8("cwcycle_dropold" , OFS(cwcycle_dropold), 0 ),
457#endif
458 DEF_LAST_OPT
459};
460
461#ifdef MODULE_CAMD35
462static bool camd35_should_save_fn(void *UNUSED(var)) { return cfg.c35_port; }
463
464static const struct config_list camd35_opts[] = {
465 DEF_OPT_SAVE_FUNC(camd35_should_save_fn),
466 DEF_OPT_INT32("port" , OFS(c35_port), 0 ),
467 DEF_OPT_FUNC("serverip" , OFS(c35_srvip), serverip_fn ),
468 DEF_OPT_INT8("suppresscmd08" , OFS(c35_udp_suppresscmd08), 0 ),
469 DEF_LAST_OPT
470};
471#else
472static const struct config_list camd35_opts[] = { DEF_LAST_OPT };
473#endif
474
475#if defined(MODULE_CAMD35_TCP) || defined(MODULE_NEWCAMD)
476#define PORTTAB_CS378X 1
477#define PORTTAB_NEWCAMD 2
478static void porttab_fn(const char *token, char *value, void *setting, long type, FILE *f) {
479 PTAB *ptab = setting;
480 if (value) {
481 if(strlen(value) == 0) {
482 clear_ptab(ptab);
483 } else {
484 chk_port_tab(value, ptab);
485 }
486 return;
487 }
488 value = (type == PORTTAB_CS378X) ? mk_t_camd35tcp_port() : mk_t_newcamd_port();
489 fprintf_conf(f, token, "%s\n", value);
490 free_mk_t(value);
491}
492#endif
493
494#ifdef MODULE_CAMD35_TCP
495static bool cs378x_should_save_fn(void *UNUSED(var)) { return cfg.c35_tcp_ptab.nports && cfg.c35_tcp_ptab.ports[0].s_port; }
496
497static const struct config_list cs378x_opts[] = {
498 DEF_OPT_SAVE_FUNC(cs378x_should_save_fn),
499 DEF_OPT_FUNC_X("port" , OFS(c35_tcp_ptab), porttab_fn, PORTTAB_CS378X ),
500 DEF_OPT_FUNC("serverip" , OFS(c35_tcp_srvip), serverip_fn ),
501 DEF_OPT_INT8("suppresscmd08" , OFS(c35_tcp_suppresscmd08), 0 ),
502 DEF_LAST_OPT
503};
504#else
505static const struct config_list cs378x_opts[] = { DEF_LAST_OPT };
506#endif
507
508#ifdef MODULE_NEWCAMD
509static bool newcamd_should_save_fn(void *UNUSED(var)) { return cfg.ncd_ptab.nports && cfg.ncd_ptab.ports[0].s_port; }
510
511static const struct config_list newcamd_opts[] = {
512 DEF_OPT_SAVE_FUNC(newcamd_should_save_fn),
513 DEF_OPT_FUNC_X("port" , OFS(ncd_ptab), porttab_fn, PORTTAB_NEWCAMD ),
514 DEF_OPT_FUNC("serverip" , OFS(ncd_srvip), serverip_fn ),
515 DEF_OPT_FUNC("allowed" , OFS(ncd_allowed), iprange_fn ),
516 DEF_OPT_HEX("key" , OFS(ncd_key), SIZEOF(ncd_key) ),
517 DEF_OPT_INT8("keepalive" , OFS(ncd_keepalive), DEFAULT_NCD_KEEPALIVE ),
518 DEF_OPT_INT8("mgclient" , OFS(ncd_mgclient), 0 ),
519 DEF_LAST_OPT
520};
521#else
522static const struct config_list newcamd_opts[] = { DEF_LAST_OPT };
523#endif
524
525#ifdef MODULE_CCCAM
526static void cccam_port_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
527 if (value) {
528 int i;
529 char *ptr, *saveptr1 = NULL;
530 memset(cfg.cc_port, 0, sizeof(cfg.cc_port));
531 for (i = 0, ptr = strtok_r(value, ",", &saveptr1); ptr && i < CS_MAXPORTS; ptr = strtok_r(NULL, ",", &saveptr1)) {
532 cfg.cc_port[i] = strtoul(ptr, NULL, 10);
533 if (cfg.cc_port[i])
534 i++;
535 }
536 return;
537 }
538 value = mk_t_cccam_port();
539 fprintf_conf(f, token, "%s\n", value);
540 free_mk_t(value);
541}
542
543static bool cccam_should_save_fn(void *UNUSED(var)) { return cfg.cc_port[0]; }
544
545static const struct config_list cccam_opts[] = {
546 DEF_OPT_SAVE_FUNC(cccam_should_save_fn),
547 DEF_OPT_FUNC("port" , OFS(cc_port), cccam_port_fn ),
548 DEF_OPT_HEX("nodeid" , OFS(cc_fixed_nodeid), SIZEOF(cc_fixed_nodeid) ),
549 DEF_OPT_SSTR("version" , OFS(cc_version), "", SIZEOF(cc_version) ),
550 DEF_OPT_INT8("reshare" , OFS(cc_reshare), 10 ),
551 DEF_OPT_INT8("reshare_mode" , OFS(cc_reshare_services), 0 ),
552 DEF_OPT_INT8("ignorereshare" , OFS(cc_ignore_reshare), 0 ),
553 DEF_OPT_INT8("forward_origin_card" , OFS(cc_forward_origin_card), 0 ),
554 DEF_OPT_INT8("stealth" , OFS(cc_stealth), 0 ),
555 DEF_OPT_INT32("updateinterval" , OFS(cc_update_interval), DEFAULT_UPDATEINTERVAL ),
556 DEF_OPT_INT8("minimizecards" , OFS(cc_minimize_cards), 0 ),
557 DEF_OPT_INT8("keepconnected" , OFS(cc_keep_connected), 1 ),
558 DEF_OPT_UINT32("recv_timeout" , OFS(cc_recv_timeout), DEFAULT_CC_RECV_TIMEOUT ),
559 DEF_LAST_OPT
560};
561#else
562static const struct config_list cccam_opts[] = { DEF_LAST_OPT };
563#endif
564
565#ifdef MODULE_PANDORA
566static bool pandora_should_save_fn(void *UNUSED(var)) { return cfg.pand_port; }
567
568static const struct config_list pandora_opts[] = {
569 DEF_OPT_SAVE_FUNC(pandora_should_save_fn),
570 DEF_OPT_INT32("pand_port" , OFS(pand_port), 0 ),
571 DEF_OPT_FUNC("pand_srvid" , OFS(pand_srvip), serverip_fn ),
572 DEF_OPT_STR("pand_usr" , OFS(pand_usr), NULL ),
573 DEF_OPT_STR("pand_pass" , OFS(pand_pass), NULL ),
574 DEF_OPT_INT8("pand_ecm" , OFS(pand_ecm), 0 ),
575 DEF_OPT_INT8("pand_skip_send_dw" , OFS(pand_skip_send_dw), 0 ),
576 DEF_OPT_FUNC("pand_allowed" , OFS(pand_allowed), iprange_fn ),
577 DEF_LAST_OPT
578};
579#else
580static const struct config_list pandora_opts[] = { DEF_LAST_OPT };
581#endif
582
583#ifdef MODULE_RADEGAST
584static bool radegast_should_save_fn(void *UNUSED(var)) { return cfg.rad_port; }
585
586static const struct config_list radegast_opts[] = {
587 DEF_OPT_SAVE_FUNC(radegast_should_save_fn),
588 DEF_OPT_INT32("port" , OFS(rad_port), 0 ),
589 DEF_OPT_FUNC("serverip" , OFS(rad_srvip), serverip_fn ),
590 DEF_OPT_FUNC("allowed" , OFS(rad_allowed), iprange_fn ),
591 DEF_OPT_STR("user" , OFS(rad_usr), NULL ),
592 DEF_LAST_OPT
593};
594#else
595static const struct config_list radegast_opts[] = { DEF_LAST_OPT };
596#endif
597
598#ifdef MODULE_SERIAL
599static bool serial_should_save_fn(void *UNUSED(var)) { return cfg.ser_device != NULL; }
600
601static const struct config_list serial_opts[] = {
602 DEF_OPT_SAVE_FUNC(serial_should_save_fn),
603 DEF_OPT_STR("device" , OFS(ser_device), NULL ),
604 DEF_LAST_OPT
605};
606#else
607static const struct config_list serial_opts[] = { DEF_LAST_OPT };
608#endif
609
610#ifdef MODULE_GBOX
611static bool gbox_should_save_fn(void *UNUSED(var)) { return cfg.gbox_hostname; }
612
613static void gbox_localcard_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
614 if (value) {
615 char *ptr1, *saveptr1 = NULL;
616 memset(cfg.gbox_card, 0, sizeof(cfg.gbox_card));
617 int n = 0, i;
618 for (i = 0, ptr1 = strtok_r(value, ",", &saveptr1); (i < CS_GBOX_MAX_LOCAL_CARDS) && (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) {
619 cfg.gbox_card[n++] = a2i(ptr1, 8);
620 }
621 cfg.gbox_local_cards_num = n;
622 return;
623 }
624
625 if (cfg.gbox_local_cards_num > 0) {
626 int i;
627 char *dot = "";
628 fprintf_conf(f, token, " ");
629 for (i = 0; i < cfg.gbox_local_cards_num; i++) {
630 fprintf(f, "%s%08lX", dot, cfg.gbox_card[i]);
631 dot = ",";
632 }
633 fprintf(f, "\n");
634 }
635}
636
637
638static const struct config_list gbox_opts[] = {
639 DEF_OPT_SAVE_FUNC(gbox_should_save_fn),
640 DEF_OPT_STR("gbox_hostname" , OFS(gbox_hostname), NULL ),
641 DEF_OPT_INT32("gbox_reconnect" , OFS(gbox_reconnect), DEFAULT_GBOX_RECONNECT ),
642 DEF_OPT_FUNC("gbox_local_cards" , OFS(gbox_card), gbox_localcard_fn ),
643 DEF_LAST_OPT
644};
645#else
646static const struct config_list gbox_opts[] = { DEF_LAST_OPT };
647#endif
648
649#ifdef HAVE_DVBAPI
650extern const char *boxdesc[];
651
652static void dvbapi_boxtype_fn(const char *token, char *value, void *UNUSED(setting), FILE *f) {
653 if (value) {
654 int i;
655 cfg.dvbapi_boxtype = 0;
656 for (i = 1; i <= BOXTYPES; i++) {
657 if (streq(value, boxdesc[i])) {
658 cfg.dvbapi_boxtype = i;
659 break;
660 }
661 }
662 return;
663 }
664 if (cfg.dvbapi_boxtype)
665 fprintf_conf(f, token, "%s\n", boxdesc[cfg.dvbapi_boxtype]);
666}
667
668static void dvbapi_services_fn(const char *UNUSED(token), char *value, void *UNUSED(setting), FILE *UNUSED(f)) {
669 if (value)
670 chk_services(value, &cfg.dvbapi_sidtabs);
671 // THIS OPTION IS NOT SAVED
672}
673
674extern struct s_dvbapi_priority *dvbapi_priority;
675
676static void dvbapi_caidtab_fn(const char *UNUSED(token), char *caidasc, void *UNUSED(setting), long cmd, FILE *UNUSED(f)) {
677 char *ptr1, *ptr3, *saveptr1 = NULL;
678 if (!caidasc)
679 return;
680 char type = (char)cmd;
681 for (ptr1 = strtok_r(caidasc, ",", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1)) {
682 uint32_t caid, prov;
683 if ( (ptr3 = strchr(trim(ptr1), ':')) )
684 *ptr3++ = '\0';
685 else
686 ptr3 = "";
687 if ( ((caid = a2i(ptr1, 2)) | (prov = a2i(ptr3, 3))) ) {
688 struct s_dvbapi_priority *entry;
689 if (!cs_malloc(&entry, sizeof(struct s_dvbapi_priority)))
690 return;
691 entry->caid=caid;
692 if (type == 'd') {
693 char tmp1[5];
694 snprintf(tmp1, sizeof(tmp1), "%04X", (uint)prov);
695 int32_t cw_delay = strtol(tmp1, '\0', 10);
696 entry->delay = cw_delay;
697 } else {
698 entry->provid = prov;
699 }
700 entry->type = type;
701 entry->next = NULL;
702 if (!dvbapi_priority) {
703 dvbapi_priority = entry;
704 } else {
705 struct s_dvbapi_priority *p;
706 for (p = dvbapi_priority; p->next != NULL; p = p->next)
707 ;
708 p->next = entry;
709 }
710 }
711 }
712 // THIS OPTION IS NOT SAVED
713}
714
715static bool dvbapi_should_save_fn(void *UNUSED(var)) { return cfg.dvbapi_enabled; }
716
717static const struct config_list dvbapi_opts[] = {
718 DEF_OPT_SAVE_FUNC(dvbapi_should_save_fn),
719 DEF_OPT_INT8("enabled" , OFS(dvbapi_enabled), 0 ),
720 DEF_OPT_INT8("au" , OFS(dvbapi_au), 0 ),
721 DEF_OPT_INT8("pmt_mode" , OFS(dvbapi_pmtmode), 0 ),
722 DEF_OPT_INT8("request_mode" , OFS(dvbapi_requestmode), 0 ),
723 DEF_OPT_INT8("reopenonzap" , OFS(dvbapi_reopenonzap), 0 ),
724 DEF_OPT_INT8("decodeforever" , OFS(dvbapi_decodeforever),0 ),
725 DEF_OPT_INT32("delayer" , OFS(dvbapi_delayer), 0 ),
726 DEF_OPT_STR("user" , OFS(dvbapi_usr), NULL ),
727 DEF_OPT_FUNC("boxtype" , OFS(dvbapi_boxtype), dvbapi_boxtype_fn ),
728 DEF_OPT_FUNC("services" , OFS(dvbapi_sidtabs.ok), dvbapi_services_fn ),
729 // OBSOLETE OPTIONS
730 DEF_OPT_FUNC_X("priority" , 0, dvbapi_caidtab_fn, 'p' ),
731 DEF_OPT_FUNC_X("ignore" , 0, dvbapi_caidtab_fn, 'i' ),
732 DEF_OPT_FUNC_X("cw_delay" , 0, dvbapi_caidtab_fn, 'd' ),
733 DEF_LAST_OPT
734};
735#else
736static const struct config_list dvbapi_opts[] = { DEF_LAST_OPT };
737#endif
738
739#ifdef LCDSUPPORT
740static void lcd_fixups_fn(void *UNUSED(var)) {
741 if (cfg.lcd_write_intervall < 5) cfg.lcd_write_intervall = 5;
742}
743
744static bool lcd_should_save_fn(void *UNUSED(var)) { return cfg.enablelcd; }
745
746static const struct config_list lcd_opts[] = {
747 DEF_OPT_SAVE_FUNC(lcd_should_save_fn),
748 DEF_OPT_FIXUP_FUNC(lcd_fixups_fn),
749 DEF_OPT_INT8("enablelcd" , OFS(enablelcd), 0 ),
750 DEF_OPT_STR("lcd_outputpath" , OFS(lcd_output_path), NULL ),
751 DEF_OPT_INT32("lcd_hideidle" , OFS(lcd_hide_idle), 0 ),
752 DEF_OPT_INT32("lcd_writeintervall" , OFS(lcd_write_intervall), 10 ),
753 DEF_LAST_OPT
754};
755#else
756static const struct config_list lcd_opts[] = { DEF_LAST_OPT };
757#endif
758
759static const struct config_sections oscam_conf[] = {
760 { "global", global_opts }, // *** MUST BE FIRST ***
761 { "anticasc", anticasc_opts },
762 { "cache", cache_opts },
763 { "lcd", lcd_opts },
764 { "camd33", camd33_opts },
765 { "cs357x", camd35_opts },
766 { "cs378x", cs378x_opts },
767 { "newcamd", newcamd_opts },
768 { "radegast", radegast_opts },
769 { "serial", serial_opts },
770 { "gbox", gbox_opts },
771 { "cccam", cccam_opts },
772 { "pandora", pandora_opts },
773 { "dvbapi", dvbapi_opts },
774 { "monitor", monitor_opts },
775 { "webif", webif_opts },
776 { NULL, NULL }
777};
778
779void config_set(char *section, const char *token, char *value) {
780 config_set_value(oscam_conf, section, token, value, &cfg);
781}
782
783void config_free(void) {
784 config_sections_free(oscam_conf, &cfg);
785 clear_ptab(&cfg.ncd_ptab);
786#ifdef MODULE_CAMD35_TCP
787 clear_ptab(&cfg.c35_tcp_ptab);
788#endif
789}
790
791int32_t init_config(void)
792{
793 FILE *fp = open_config_file_or_die(cs_conf);
794
795 const struct config_sections *cur_section = oscam_conf; // Global
796 char *token;
797
798 if (!cs_malloc(&token, MAXLINESIZE))
799 return 1;
800
801 config_sections_set_defaults(oscam_conf, &cfg);
802
803 int line = 0;
804 int valid_section = 1;
805 while (fgets(token, MAXLINESIZE, fp)) {
806 ++line;
807 int len = strlen(trim(token));
808 if (len < 3) // a=b or [a] are at least 3 chars
809 continue;
810 if (token[0] == '#') // Skip comments
811 continue;
812 if (token[0] == '[' && token[len - 1] == ']') {
813 token[len - 1] = '\0';
814 valid_section = 0;
815 const struct config_sections *newconf = config_find_section(oscam_conf, token + 1);
816 if (config_section_is_active(newconf) && cur_section) {
817 config_list_apply_fixups(cur_section->config, &cfg);
818 cur_section = newconf;
819 valid_section = 1;
820 }
821 if (!newconf) {
822 fprintf(stderr, "WARNING: %s line %d unknown section [%s].\n",
823 cs_conf, line, token + 1);
824 continue;
825 }
826 if (!config_section_is_active(newconf)) {
827 fprintf(stderr, "WARNING: %s line %d section [%s] is ignored (support not compiled in).\n",
828 cs_conf, line, newconf->section);
829 }
830 continue;
831 }
832 if (!valid_section)
833 continue;
834 char *value = strchr(token, '=');
835 if (!value) // No = found, well go on
836 continue;
837 *value++ ='\0';
838 char *tvalue = trim(value);
839 char *ttoken = trim(strtolower(token));
840 if (cur_section && !config_list_parse(cur_section->config, ttoken, tvalue, &cfg)) {
841 fprintf(stderr, "WARNING: %s line %d section [%s] contains unknown setting '%s=%s'\n",
842 cs_conf, line, cur_section->section, ttoken, tvalue);
843 }
844 }
845 free(token);
846 fclose(fp);
847 if (cur_section) config_list_apply_fixups(cur_section->config, &cfg);
848 return 0;
849}
850
851int32_t write_config(void)
852{
853 FILE *f = create_config_file(cs_conf);
854 if (!f)
855 return 1;
856 config_sections_save(oscam_conf, f, &cfg);
857 return flush_config_file(f, cs_conf);
858}
Note: See TracBrowser for help on using the repository browser.