source: trunk/oscam-config.c@ 1685

Last change on this file since 1685 was 1685, checked in by merek, 11 years ago

Code Cleanup in chk_reader

File size: 48.8 KB
Line 
1#include "globals.h"
2#ifdef CS_WITH_BOXKEYS
3# include "oscam-boxkeys.np"
4#endif
5
6#define CONFVARWIDTH 20
7
8static char *cs_conf="oscam.conf";
9static char *cs_user="oscam.user";
10static char *cs_srvr="oscam.server";
11static char *cs_srid="oscam.srvid";
12static char *cs_l4ca="oscam.guess";
13static char *cs_cert="oscam.cert";
14static char *cs_sidt="oscam.services";
15//static char *cs_ird="oscam.ird";
16#ifdef CS_ANTICASC
17static char *cs_ac="oscam.ac";
18#endif
19
20static char token[4096];
21
22typedef enum cs_proto_type
23{
24 TAG_GLOBAL, // must be first !
25 TAG_MONITOR, // monitor
26 TAG_CAMD33, // camd 3.3x
27 TAG_CAMD35, // camd 3.5x UDP
28 TAG_NEWCAMD, // newcamd
29 TAG_RADEGAST, // radegast
30 TAG_SERIAL, // serial (static)
31 TAG_CS357X, // camd 3.5x UDP
32 TAG_CS378X, // camd 3.5x TCP
33#ifdef CS_WITH_GBOX
34 TAG_GBOX, // gbox
35#endif
36 TAG_CCCAM, // cccam
37 TAG_DVBAPI
38#ifdef CS_ANTICASC
39 ,TAG_ANTICASC // anti-cascading
40#endif
41} cs_proto_type_t;
42
43static char *cctag[]={"global", "monitor", "camd33", "camd35",
44 "newcamd", "radegast", "serial", "cs357x", "cs378x",
45#ifdef CS_WITH_GBOX
46 "gbox",
47#endif
48 "cccam", "dvbapi",
49#ifdef CS_ANTICASC
50 "anticasc",
51#endif
52 NULL};
53
54#ifdef DEBUG_SIDTAB
55static void show_sidtab(struct s_sidtab *sidtab)
56{
57 for (; sidtab; sidtab=sidtab->next)
58 {
59 int i;
60 char buf[1024];
61 cs_log("label=%s", sidtab->label);
62 sprintf(buf, "caid(%d)=", sidtab->num_caid);
63 for (i=0; i<sidtab->num_caid; i++)
64 sprintf(buf+strlen(buf), "%04X ", sidtab->caid[i]);
65 cs_log("%s", buf);
66 sprintf(buf, "provider(%d)=", sidtab->num_provid);
67 for (i=0; i<sidtab->num_provid; i++)
68 sprintf(buf+strlen(buf), "%08X ", sidtab->provid[i]);
69 cs_log("%s", buf);
70 sprintf(buf, "services(%d)=", sidtab->num_srvid);
71 for (i=0; i<sidtab->num_srvid; i++)
72 sprintf(buf+strlen(buf), "%04X ", sidtab->srvid[i]);
73 cs_log("%s", buf);
74 }
75}
76#endif
77
78void chk_iprange(char *value, struct s_ip **base)
79{
80 int i = 0;
81 char *ptr1, *ptr2;
82 struct s_ip *lip, *cip;
83
84 for (cip=lip=*base; cip; cip=cip->next)
85 lip = cip;
86 if (!(cip=malloc(sizeof(struct s_ip)))) {
87 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
88 exit(1);
89 }
90 if (*base)
91 lip->next = cip;
92 else
93 *base = cip;
94
95 memset(cip, 0, sizeof(struct s_ip));
96 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
97 if (i == 0)
98 ++i;
99 else {
100 if (!(cip=malloc(sizeof(struct s_ip)))) {
101 fprintf(stderr, "Error allocating memory (errno=%d)\n", errno);
102 exit(1);
103 }
104 lip->next = cip;
105 memset(cip, 0, sizeof(struct s_ip));
106 }
107
108 if( (ptr2=strchr(trim(ptr1), '-')) ) {
109 *ptr2++ ='\0';
110 cip->ip[0]=cs_inet_addr(trim(ptr1));
111 cip->ip[1]=cs_inet_addr(trim(ptr2));
112 } else {
113 cip->ip[0]=cip->ip[1]=cs_inet_addr(ptr1);
114 }
115 lip = cip;
116 }
117}
118
119void chk_caidtab(char *caidasc, CAIDTAB *ctab)
120{
121 int i;
122 char *ptr1, *ptr2, *ptr3;
123
124 for (i = 0, ptr1 = strtok(caidasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
125 ulong caid, mask, cmap;
126 if( (ptr3 = strchr(trim(ptr1), ':')) )
127 *ptr3++ = '\0';
128 else
129 ptr3 = "";
130
131 if( (ptr2 = strchr(trim(ptr1), '&')) )
132 *ptr2++ = '\0';
133 else
134 ptr2 = "";
135
136 if (((caid = a2i(ptr1, 2)) | (mask = a2i(ptr2,-2)) | (cmap = a2i(ptr3, 2))) < 0x10000) {
137 ctab->caid[i] = caid;
138 ctab->mask[i] = mask;
139 ctab->cmap[i++] = cmap;
140 }
141 }
142}
143
144void chk_tuntab(char *tunasc, TUNTAB *ttab)
145{
146 int i;
147 char *ptr1, *ptr2, *ptr3;
148
149 for (i = 0, ptr1 = strtok(tunasc, ","); (i < CS_MAXTUNTAB) && (ptr1); ptr1 = strtok(NULL, ",")) {
150 ulong bt_caidfrom, bt_caidto, bt_srvid;
151 if( (ptr3 = strchr(trim(ptr1), ':')) )
152 *ptr3++ = '\0';
153 else
154 ptr3 = "";
155
156 if( (ptr2 = strchr(trim(ptr1), '.')) )
157 *ptr2++ = '\0';
158 else
159 ptr2 = "";
160
161 if ((bt_caidfrom = a2i(ptr1, 2)) | (bt_srvid = a2i(ptr2,-2)) | (bt_caidto = a2i(ptr3, 2))) {
162 ttab->bt_caidfrom[i] = bt_caidfrom;
163 ttab->bt_caidto[i] = bt_caidto;
164 ttab->bt_srvid[i++] = bt_srvid;
165 }
166 }
167}
168
169void chk_services(char *labels, ulong *sidok, ulong *sidno)
170{
171 int i;
172 char *ptr;
173 SIDTAB *sidtab;
174 *sidok = *sidno = 0;
175 for (ptr=strtok(labels, ","); ptr; ptr=strtok(NULL, ",")) {
176 for (trim(ptr), i = 0, sidtab = cfg->sidtab; sidtab; sidtab = sidtab->next, i++) {
177 if (!strcmp(sidtab->label, ptr)) *sidok|=(1<<i);
178 if ((ptr[0]=='!') && (!strcmp(sidtab->label, ptr+1))) *sidno|=(1<<i);
179 }
180 }
181}
182
183void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName)
184{
185 int i, j;
186 char *ptr1, *ptr2, *ptr3;
187 char *ptr[CS_MAXFILTERS] = {0};
188
189 memset(ftab, 0, sizeof(FTAB));
190 for( i = 0, ptr1 = strtok(zFilterAsc, ";"); (i < CS_MAXFILTERS) && (ptr1); ptr1 = strtok(NULL, ";"), i++ ) {
191 ptr[i] = ptr1;
192 if( (ptr2 = strchr(trim(ptr1), ':')) ) {
193 *ptr2++ ='\0';
194 ftab->filts[i].caid = (ushort)a2i(ptr1, 4);
195 ptr[i] = ptr2;
196 }
197 else if (zFiltName && zFiltName[0] == 'c') {
198 cs_log("PANIC: CAID field not found in CHID parameter!");
199 cs_exit(1);
200 }
201 ftab->nfilts++;
202 }
203
204 if( ftab->nfilts ) cs_debug("%s '%s' %s filter(s):", zType, zName, zFiltName);
205 for( i = 0; i < ftab->nfilts; i++ ) {
206 cs_debug("CAID #%d: %04X", i, ftab->filts[i].caid);
207 for( j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++ ) {
208 ftab->filts[i].prids[j] = a2i(ptr3,6);
209 ftab->filts[i].nprids++;
210 cs_debug("%s #%d: %06X", zFiltName, j, ftab->filts[i].prids[j]);
211 }
212 }
213}
214
215void chk_cltab(char *classasc, CLASSTAB *clstab)
216{
217 int i;
218 char *ptr1;
219 for( i = 0, ptr1 = strtok(classasc, ","); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ",") ) {
220 ptr1 = trim(ptr1);
221 if( ptr1[0] == '!' )
222 clstab->bclass[clstab->bn++] = (uchar)a2i(ptr1+1, 2);
223 else
224 clstab->aclass[clstab->an++] = (uchar)a2i(ptr1, 2);
225 }
226}
227
228void chk_port_tab(char *portasc, PTAB *ptab)
229{
230 int i, j, nfilts, ifilt, iport;
231 char *ptr1, *ptr2, *ptr3;
232 char *ptr[CS_MAXPORTS] = {0};
233 int port[CS_MAXPORTS] = {0};
234 int previous_nports = ptab->nports;
235
236 for (nfilts = i = previous_nports, ptr1 = strtok(portasc, ";"); (i < CS_MAXCAIDTAB) && (ptr1); ptr1 = strtok(NULL, ";"), i++) {
237 ptr[i] = ptr1;
238 if( (ptr2=strchr(trim(ptr1), '@')) ) {
239 *ptr2++ ='\0';
240 ptab->ports[i].s_port = atoi(ptr1);
241 ptr[i] = ptr2;
242 port[i] = ptab->ports[i].s_port;
243 ptab->nports++;
244 }
245 nfilts++;
246 }
247
248 if( nfilts == 1 && strlen(portasc) < 6 && ptab->ports[0].s_port == 0 ) {
249 ptab->ports[0].s_port = atoi(portasc);
250 ptab->nports = 1;
251 }
252
253 iport = ifilt = previous_nports;
254 for (i=previous_nports; i<nfilts; i++) {
255 if( port[i] != 0 )
256 iport = i;
257 for (j = 0, ptr3 = strtok(ptr[i], ","); (j < CS_MAXPROV) && (ptr3); ptr3 = strtok(NULL, ","), j++) {
258 if( (ptr2=strchr(trim(ptr3), ':')) ) {
259 *ptr2++='\0';
260 ptab->ports[iport].ftab.nfilts++;
261 ifilt = ptab->ports[iport].ftab.nfilts-1;
262 ptab->ports[iport].ftab.filts[ifilt].caid = (ushort)a2i(ptr3, 4);
263 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr2, 6);
264 } else {
265 ptab->ports[iport].ftab.filts[ifilt].prids[j] = a2i(ptr3, 6);
266 }
267 ptab->ports[iport].ftab.filts[ifilt].nprids++;
268 }
269 }
270}
271
272#ifdef NOTUSED
273static void chk_srvip(char *value, in_addr_t *ip)
274{
275 int i;
276 char *ptr;
277 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
278 if (i<8) ip[i++]=inet_addr(ptr);
279}
280#endif
281
282void chk_t_global(char *token, char *value)
283{
284 if (!strcmp(token, "serverip")) {
285 if (strlen(value) == 0) {
286 cfg->srvip = 0;
287 return;
288 } else {
289 cfg->srvip=inet_addr(value);
290 return;
291 }
292 }
293
294 if (!strcmp(token, "logfile")) {
295 if (cfg->logfile != NULL) {
296 free(cfg->logfile);
297 cfg->logfile = NULL;
298 }
299 if (strlen(value) > 0)
300 asprintf(&(cfg->logfile), "%s", value);
301 return;
302 }
303
304 if (!strcmp(token, "pidfile")) {
305 if (cfg->pidfile != NULL) {
306 free(cfg->pidfile);
307 cfg->pidfile = NULL;
308 }
309 if (strlen(value) > 0)
310 asprintf(&(cfg->pidfile), "%s", value);
311 return;
312 }
313
314 if (!strcmp(token, "usrfile")) {
315 if (cfg->usrfile != NULL) {
316 free(cfg->usrfile);
317 cfg->usrfile = NULL;
318 }
319 if (strlen(value) > 0)
320 asprintf(&(cfg->usrfile), "%s", value);
321 return;
322 }
323
324 if (!strcmp(token, "cwlogdir")) {
325 if (cfg->cwlogdir != NULL) {
326 free(cfg->cwlogdir);
327 cfg->cwlogdir = NULL;
328 }
329 if (strlen(value) > 0)
330 asprintf(&(cfg->cwlogdir), "%s", value);
331 return;
332 }
333
334 if (!strcmp(token, "clienttimeout")) {
335 if (strlen(value) == 0) {
336 cfg->ctimeout = CS_CLIENT_TIMEOUT;
337 return;
338 } else {
339 cfg->ctimeout = atoi(value);
340 if (cfg->ctimeout < 100)
341 cfg->ctimeout *= 1000;
342 return;
343 }
344 }
345
346 if (!strcmp(token, "fallbacktimeout")) {
347 if (strlen(value) == 0) {
348 cfg->ftimeout = CS_CLIENT_TIMEOUT;
349 return;
350 } else {
351 cfg->ftimeout = atoi(value);
352 if (cfg->ftimeout < 100)
353 cfg->ftimeout *= 1000;
354 return;
355 }
356 }
357
358 if (!strcmp(token, "clientmaxidle")) {
359 if (strlen(value) == 0) {
360 cfg->cmaxidle = CS_CLIENT_MAXIDLE;
361 return;
362 } else {
363 cfg->cmaxidle = atoi(value);
364 return;
365 }
366 }
367
368 if (!strcmp(token, "cachedelay")) {
369 if (strlen(value) == 0) {
370 cfg->delay = CS_DELAY;
371 return;
372 } else {
373 cfg->delay = atoi(value);
374 return;
375 }
376 }
377
378 if (!strcmp(token, "bindwait")) {
379 if (strlen(value) == 0) {
380 cfg->bindwait = CS_BIND_TIMEOUT;
381 return;
382 } else {
383 cfg->bindwait = atoi(value);
384 return;
385 }
386 }
387
388 if (!strcmp(token, "netprio")) {
389 if (strlen(value) == 0) {
390 cfg->netprio = 0;
391 return;
392 } else {
393 cfg->netprio = atoi(value);
394 return;
395 }
396 }
397
398 if (!strcmp(token, "resolvedelay")) {
399 if (strlen(value) == 0) {
400 cfg->resolvedelay = CS_RESOLVE_DELAY;
401 return;
402 } else {
403 cfg->resolvedelay = atoi(value);
404 return;
405 }
406 }
407
408 if (!strcmp(token, "sleep")) {
409 if (strlen(value) == 0) {
410 cfg->tosleep = 0;
411 return;
412 } else {
413 cfg->tosleep = atoi(value);
414 return;
415 }
416 }
417
418 if (!strcmp(token, "unlockparental")) {
419 if (strlen(value) == 0) {
420 cfg->ulparent = 0;
421 return;
422 } else {
423 cfg->ulparent = atoi(value);
424 return;
425 }
426 }
427
428 if (!strcmp(token, "nice")) {
429 if (strlen(value) == 0) {
430 cfg->nice = 99;
431 return;
432 } else {
433 cfg->nice = atoi(value);
434 if ((cfg->nice<-20) || (cfg->nice>20)) cfg->nice = 99;
435 if (cfg->nice != 99) cs_setpriority(cfg->nice); // ignore errors
436 return;
437 }
438 }
439
440 if (!strcmp(token, "serialreadertimeout")) {
441 if (cfg->srtimeout < 100)
442 cfg->srtimeout = atoi(value) * 1000;
443 else
444 cfg->srtimeout = atoi(value);
445 if (cfg->srtimeout <= 0)
446 cfg->srtimeout = 1500;
447 return;
448 }
449
450 if (!strcmp(token, "maxlogsize")) {
451 if (strlen(value) == 0) {
452 cfg->max_log_size = 10;
453 return;
454 } else {
455 cfg->max_log_size = atoi(value);
456 if( cfg->max_log_size <= 10 )
457 cfg->max_log_size = 10;
458 return;
459 }
460 }
461
462 if( !strcmp(token, "waitforcards")) {
463 if (strlen(value) == 0) {
464 cfg->waitforcards = 0;
465 return;
466 } else {
467 cfg->waitforcards = atoi(value);
468 return;
469 }
470 }
471
472 if( !strcmp(token, "preferlocalcards")) {
473 if (strlen(value) == 0) {
474 cfg->preferlocalcards = 0;
475 return;
476 } else {
477 cfg->preferlocalcards = atoi(value);
478 return;
479 }
480 }
481
482 if (token[0] != '#')
483 cs_log("Warning: keyword '%s' in global section not recognized", token);
484}
485
486#ifdef CS_ANTICASC
487void chk_t_ac(char *token, char *value)
488{
489 if (!strcmp(token, "enabled")) {
490 cfg->ac_enabled = atoi(value);
491 if( cfg->ac_enabled <= 0 )
492 cfg->ac_enabled = 0;
493 else
494 cfg->ac_enabled = 1;
495 return;
496 }
497
498 if (!strcmp(token, "numusers")) {
499 cfg->ac_users = atoi(value);
500 if( cfg->ac_users < 0 )
501 cfg->ac_users = 0;
502 return;
503 }
504
505 if (!strcmp(token, "sampletime")) {
506 cfg->ac_stime = atoi(value);
507 if( cfg->ac_stime < 0 )
508 cfg->ac_stime = 2;
509 return;
510 }
511
512 if (!strcmp(token, "samples")) {
513 cfg->ac_samples = atoi(value);
514 if( cfg->ac_samples < 2 || cfg->ac_samples > 10)
515 cfg->ac_samples = 10;
516 return;
517 }
518
519 if (!strcmp(token, "penalty")) {
520 cfg->ac_penalty = atoi(value);
521 if( cfg->ac_penalty < 0 )
522 cfg->ac_penalty = 0;
523 return;
524 }
525
526 if (!strcmp(token, "aclogfile")) {
527 cs_strncpy(cfg->ac_logfile, value, sizeof(cfg->ac_logfile));
528 return;
529 }
530
531 if( !strcmp(token, "fakedelay") ) {
532 cfg->ac_fakedelay = atoi(value);
533 if( cfg->ac_fakedelay < 100 || cfg->ac_fakedelay > 1000 )
534 cfg->ac_fakedelay = 1000;
535 return;
536 }
537
538 if( !strcmp(token, "denysamples") ) {
539 cfg->ac_denysamples = atoi(value);
540 if( cfg->ac_denysamples < 2 || cfg->ac_denysamples > cfg->ac_samples - 1 )
541 cfg->ac_denysamples=cfg->ac_samples-1;
542 return;
543 }
544
545 if (token[0] != '#')
546 cs_log( "Warning: keyword '%s' in anticascading section not recognized",token);
547}
548#endif
549
550void chk_t_monitor(char *token, char *value)
551{
552 if (!strcmp(token, "port")) {
553 if(strlen(value) == 0) {
554 cfg->mon_port = 0;
555 return;
556 } else {
557 cfg->mon_port=atoi(value);
558 return;
559 }
560 }
561
562 if (!strcmp(token, "serverip")) {
563 if(strlen(value) == 0) {
564 cfg->mon_srvip = 0;
565 return;
566 } else {
567 cfg->mon_srvip=inet_addr(value);
568 return;
569 }
570 }
571
572 if (!strcmp(token, "nocrypt")) {
573 if(strlen(value) == 0) {
574 clear_sip(&cfg->mon_allowed);
575 return;
576 } else {
577 chk_iprange(value, &cfg->mon_allowed);
578 return;
579 }
580 }
581
582 if (!strcmp(token, "aulow")) {
583 if(strlen(value) == 0) {
584 cfg->mon_aulow = 0;
585 return;
586 } else {
587 cfg->mon_aulow = atoi(value);
588 return;
589 }
590 }
591
592 if (!strcmp(token, "monlevel")) {
593 if(strlen(value) == 0) {
594 cfg->mon_level = 0;
595 return;
596 } else {
597 cfg->mon_level = atoi(value);
598 return;
599 }
600 }
601
602 if (!strcmp(token, "hideclient_to")) {
603 if(strlen(value) == 0) {
604 cfg->mon_hideclient_to = 0;
605 return;
606 } else {
607 cfg->mon_hideclient_to = atoi(value);
608 return;
609 }
610 }
611
612 if (token[0] != '#')
613 cs_log("Warning: keyword '%s' in monitor section not recognized",token);
614}
615
616void chk_t_camd33(char *token, char *value)
617{
618 if (!strcmp(token, "port")) {
619 if(strlen(value) == 0) {
620 cfg->c33_port = 0;
621 return;
622 } else {
623 cfg->c33_port = atoi(value);
624 return;
625 }
626 }
627
628 if (!strcmp(token, "serverip")) {
629 if(strlen(value) == 0) {
630 cfg->c33_srvip = 0;
631 return;
632 } else {
633 cfg->c33_srvip = inet_addr(value);
634 return;
635 }
636 }
637
638 if (!strcmp(token, "nocrypt")) {
639 if(strlen(value) == 0) {
640 return;
641 } else {
642 chk_iprange(value, &cfg->c33_plain);
643 return;
644 }
645 }
646
647 if (!strcmp(token, "passive")) {
648 cfg->c33_passive = (value[0]!='0');
649 return;
650 }
651
652 if (!strcmp(token, "key")) {
653 if (key_atob(value, cfg->c33_key)) {
654 fprintf(stderr, "Configuration camd3.3x: Error in Key\n");
655 exit(1);
656 }
657 cfg->c33_crypted=1;
658 return;
659 }
660
661 if (token[0] != '#')
662 cs_log( "Warning: keyword '%s' in camd33 section not recognized",token);
663}
664
665void chk_t_camd35(char *token, char *value)
666{
667 if (!strcmp(token, "port")) {
668 if(strlen(value) == 0) {
669 cfg->c35_port = 0;
670 return;
671 } else {
672 cfg->c35_port = atoi(value);
673 return;
674 }
675 }
676
677 if (!strcmp(token, "serverip")) {
678 if(strlen(value) == 0) {
679 cfg->c35_tcp_srvip = 0;
680 return;
681 } else {
682 cfg->c35_tcp_srvip = inet_addr(value);
683 return;
684 }
685 }
686
687 if (!strcmp(token, "suppresscmd08")) {
688 if(strlen(value) == 0) {
689 cfg->c35_suppresscmd08 = 0;
690 return;
691 } else {
692 cfg->c35_suppresscmd08=atoi(value);
693 return;
694 }
695 }
696
697 if (token[0] != '#')
698 cs_log( "Warning: keyword '%s' in camd35 section not recognized", token);
699}
700
701void chk_t_camd35_tcp(char *token, char *value)
702{
703 if (!strcmp(token, "port")) {
704 if(strlen(value) == 0) {
705 clear_ptab(&cfg->c35_tcp_ptab);
706 return;
707 } else {
708 chk_port_tab(value, &cfg->c35_tcp_ptab);
709 return;
710 }
711 }
712
713 if (!strcmp(token, "serverip")) {
714 if(strlen(value) == 0) {
715 cfg->c35_tcp_srvip = 0;
716 return;
717 } else {
718 cfg->c35_tcp_srvip = inet_addr(value);
719 return;
720 }
721 }
722
723 if (!strcmp(token, "suppresscmd08")) {
724 if(strlen(value) == 0) {
725 cfg->c35_suppresscmd08 = 0;
726 return;
727 } else {
728 cfg->c35_suppresscmd08 = atoi(value);
729 return;
730 }
731 }
732
733 if (token[0] != '#')
734 cs_log( "Warning: keyword '%s' in camd35 tcp section not recognized", token);
735}
736
737void chk_t_newcamd(char *token, char *value)
738{
739 if (!strcmp(token, "port")) {
740 if(strlen(value) == 0) {
741 clear_ptab(&cfg->ncd_ptab);
742 return;
743 } else {
744 chk_port_tab(value, &cfg->ncd_ptab);
745 return;
746 }
747 }
748
749 if (!strcmp(token, "serverip")) {
750 if(strlen(value) == 0) {
751 cfg->ncd_srvip = 0;
752 return;
753 } else {
754 cfg->ncd_srvip = inet_addr(value);
755 return;
756 }
757 }
758
759 if (!strcmp(token, "allowed")) {
760 if(strlen(value) == 0) {
761 clear_sip(&cfg->ncd_allowed);
762 return;
763 } else {
764 chk_iprange(value, &cfg->ncd_allowed);
765 return;
766 }
767 }
768
769 if (!strcmp(token, "key")) {
770 if (key_atob14(value, cfg->ncd_key)) {
771 fprintf(stderr, "Configuration newcamd: Error in Key\n");
772 exit(1);
773 }
774 return;
775 }
776
777 if (!strcmp(token, "keepalive")) {
778 if(strlen(value) == 0) {
779 cfg->ncd_keepalive = 1;
780 return;
781 } else {
782 cfg->ncd_keepalive = atoi(value);
783 return;
784 }
785 }
786
787 if (token[0] != '#')
788 cs_log( "Warning: keyword '%s' in newcamd section not recognized", token);
789}
790
791void chk_t_cccam(char *token, char *value)
792{
793 if (!strcmp(token, "port")) {
794 if(strlen(value) == 0) {
795 cfg->cc_port = 0;
796 return;
797 } else {
798 cfg->cc_port = atoi(value);
799 return;
800 }
801 }
802 //if (!strcmp(token, "serverip")) { cfg->cc_srvip=inet_addr(value); return; }
803
804 if (!strcmp(token, "reshare")) {
805 if(strlen(value) == 0) {
806 cfg->cc_reshare = 0;
807 return;
808 } else {
809 cfg->cc_reshare=atoi(value);
810 return;
811 }
812 }
813 // cccam version
814 if (!strcmp(token, "version")) {
815 if (strlen(value) > sizeof(cfg->cc_version) - 1) {
816 fprintf(stderr, "cccam config: version too long\n");
817 exit(1);
818 }
819 memset(cfg->cc_version, 0, sizeof(cfg->cc_version));
820 strncpy((char*)cfg->cc_version, value, sizeof(cfg->cc_version) - 1);
821 return;
822 }
823 // cccam build number
824 if (!strcmp(token, "build")) {
825 if (strlen(value) > sizeof(cfg->cc_build) - 1) {
826 fprintf(stderr, "cccam config build number too long\n");
827 exit(1);
828 }
829 memset(cfg->cc_build, 0, sizeof(cfg->cc_build));
830 strncpy((char*)cfg->cc_build, value, sizeof(cfg->cc_build)-1);
831 return;
832 }
833
834 if (token[0] != '#')
835 cs_log( "Warning: keyword '%s' in cccam section not recognized",token);
836}
837
838void chk_t_radegast(char *token, char *value)
839{
840 if (!strcmp(token, "port")) {
841 if(strlen(value) == 0) {
842 cfg->rad_port = 0;
843 return;
844 } else {
845 cfg->rad_port = atoi(value);
846 return;
847 }
848 }
849
850 if (!strcmp(token, "serverip")) {
851 if(strlen(value) == 0) {
852 cfg->rad_srvip = 0;
853 return;
854 } else {
855 cfg->rad_srvip = inet_addr(value);
856 return;
857 }
858 }
859
860 if (!strcmp(token, "allowed")) {
861 if(strlen(value) == 0) {
862 clear_sip(&cfg->rad_allowed);
863 return;
864 } else {
865 chk_iprange(value, &cfg->rad_allowed);
866 return;
867 }
868 }
869
870 if (!strcmp(token, "user")) {
871 cs_strncpy(cfg->rad_usr, value, sizeof(cfg->rad_usr));
872 return;
873 }
874
875 if (token[0] != '#')
876 cs_log( "Warning: keyword '%s' in radegast section not recognized", token);
877}
878
879void chk_t_serial(char *token, char *value)
880{
881 if (!strcmp(token, "device")) {
882 int l;
883 l = strlen(cfg->ser_device);
884 if (l)
885 cfg->ser_device[l++]=1; // use ctrl-a as delimiter
886 cs_strncpy(cfg->ser_device+l, value, sizeof(cfg->ser_device)-l);
887 return;
888 }
889 if (token[0] != '#')
890 cs_log( "Warning: keyword '%s' in serial section not recognized", token);
891}
892
893#ifdef CS_WITH_GBOX
894static void chk_t_gbox(char *token, char *value)
895{
896// if (!strcmp(token, "password")) strncpy(cfg->gbox_pwd, i2b(4, a2i(value, 4)), 4);
897 if (!strcmp(token, "password")) { cs_atob(cfg->gbox_pwd, value, 4); return; }
898 if (!strcmp(token, "maxdist")) { cfg->maxdist=atoi(value); return; }
899 if (!strcmp(token, "ignorelist")) { cs_strncpy((char *)cfg->ignorefile, value, sizeof(cfg->ignorefile)); return; }
900 if (!strcmp(token, "onlineinfos")) { cs_strncpy((char *)cfg->gbxShareOnl, value, sizeof(cfg->gbxShareOnl)); return; }
901 if (!strcmp(token, "cardinfos")) { cs_strncpy((char *)cfg->cardfile, value, sizeof(cfg->cardfile)); return; }
902 if (!strcmp(token, "locals"))
903 {
904 char *ptr1;
905 int n=0, i;
906 for (i=0, ptr1=strtok(value, ","); (i<CS_MAXLOCALS) && (ptr1); ptr1=strtok(NULL, ","))
907 {
908 cfg->locals[n++]=a2i(ptr1, 8);
909 //printf("%i %08X",n,cfg->locals[n-1]);
910 }
911 cfg->num_locals=n;
912 return;
913 }
914 if (token[0] != '#')
915 fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token);
916}
917#endif
918
919#ifdef HAVE_DVBAPI
920void chk_t_dvbapi(char *token, char *value)
921{
922 if (!strcmp(token, "enabled")) { cfg->dvbapi_enabled=atoi(value); return; }
923 if (!strcmp(token, "au")) { cfg->dvbapi_au=atoi(value); return; }
924 if (!strcmp(token, "boxtype")) { cs_strncpy(cfg->dvbapi_boxtype, value, sizeof(cfg->dvbapi_boxtype)); return; }
925 if (!strcmp(token, "user")) { cs_strncpy(cfg->dvbapi_usr, value, sizeof(cfg->dvbapi_usr)); return; }
926 if (!strcmp(token, "priority")) { cs_strncpy(cfg->dvbapi_priority, value, sizeof(cfg->dvbapi_priority)); return; }
927 if (!strcmp(token, "ignore")) { cs_strncpy(cfg->dvbapi_ignore, value, sizeof(cfg->dvbapi_ignore)); return; }
928
929 if (token[0] != '#')
930 fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token);
931}
932#endif
933
934static void chk_token(char *token, char *value, int tag)
935{
936 switch(tag) {
937 case TAG_GLOBAL : chk_t_global(token, value); break;
938 case TAG_MONITOR : chk_t_monitor(token, value); break;
939 case TAG_CAMD33 : chk_t_camd33(token, value); break;
940 case TAG_CAMD35 :
941 case TAG_CS357X : chk_t_camd35(token, value); break;
942 case TAG_NEWCAMD : chk_t_newcamd(token, value); break;
943 case TAG_RADEGAST: chk_t_radegast(token, value); break;
944 case TAG_SERIAL : chk_t_serial(token, value); break;
945 case TAG_CS378X : chk_t_camd35_tcp(token, value); break;
946#ifdef CS_WITH_GBOX
947 case TAG_GBOX : chk_t_gbox(token, value); break;
948#endif
949 case TAG_CCCAM : chk_t_cccam(token, value); break;
950#ifdef HAVE_DVBAPI
951 case TAG_DVBAPI : chk_t_dvbapi(token, value); break;
952#else
953 case TAG_DVBAPI : fprintf(stderr, "Warning: OSCam compiled without DVB API support.\n"); break;
954#endif
955#ifdef CS_ANTICASC
956 case TAG_ANTICASC: chk_t_ac(token, value); break;
957#endif
958 }
959}
960
961void init_len4caid()
962{
963 int nr;
964 FILE *fp;
965 char *value;
966
967 memset(len4caid, 0, sizeof(ushort)<<8);
968 sprintf(token, "%s%s", cs_confdir, cs_l4ca);
969 if (!(fp = fopen(token, "r")))
970 return;
971 for(nr = 0; fgets(token, sizeof(token), fp);) {
972 int i, c;
973 char *ptr;
974 if (!(value=strchr(token, ':')))
975 continue;
976 *value++ ='\0';
977 if( (ptr = strchr(value, '#')) )
978 *ptr = '\0';
979 if (strlen(trim(token)) != 2)
980 continue;
981 if (strlen(trim(value)) != 4)
982 continue;
983 if ((i = byte_atob(token)) < 0)
984 continue;
985 if ((c = word_atob(value)) < 0)
986 continue;
987 len4caid[i] = c;
988 nr++;
989 }
990 fclose(fp);
991 cs_log("%d lengths for caid guessing loaded", nr);
992 return;
993}
994
995int search_boxkey(ushort caid, char *key)
996{
997 int i, rc = 0;
998 FILE *fp;
999 char c_caid[512];
1000
1001 sprintf(c_caid, "%s%s", cs_confdir, cs_cert);
1002 fp = fopen(c_caid, "r");
1003 if (fp) {
1004 for (; (!rc) && fgets(c_caid, sizeof(c_caid), fp);) {
1005 char *c_provid, *c_key;
1006
1007 c_provid = strchr(c_caid, '#');
1008 if (c_provid)
1009 *c_provid = '\0';
1010 if (!(c_provid = strchr(c_caid, ':')))
1011 continue;
1012 *c_provid++ ='\0';
1013 if (!(c_key = strchr(c_provid, ':')))
1014 continue;
1015 *c_key++ ='\0';
1016 if (word_atob(trim(c_caid))!=caid)
1017 continue;
1018 if ((i=(strlen(trim(c_key))>>1)) > 256)
1019 continue;
1020 if (cs_atob((uchar *)key, c_key, i) < 0) {
1021 cs_log("wrong key in \"%s\"", cs_cert);
1022 continue;
1023 }
1024 rc = 1;
1025 }
1026 fclose(fp);
1027 }
1028#ifdef OSCAM_INBUILD_KEYS
1029 for(i=0; (!rc) && (npkey[i].keylen); i++)
1030 if (rc=((caid==npkey[i].caid) && (npkey[i].provid==0)))
1031 memcpy(key, npkey[i].key, npkey[i].keylen);
1032#endif
1033 return(rc);
1034}
1035
1036int init_config()
1037{
1038 int tag=TAG_GLOBAL;
1039 FILE *fp;
1040 char *value;
1041
1042#ifndef CS_EMBEDDED
1043#ifdef PRIO_PROCESS
1044 errno=0;
1045 if ((cfg->nice = getpriority(PRIO_PROCESS, 0)) == (-1))
1046 if (errno)
1047#endif
1048#endif
1049 cfg->nice = 99;
1050 cfg->ctimeout = CS_CLIENT_TIMEOUT;
1051 cfg->ftimeout = CS_CLIENT_TIMEOUT / 2;
1052 cfg->cmaxidle = CS_CLIENT_MAXIDLE;
1053 cfg->delay = CS_DELAY;
1054 cfg->bindwait = CS_BIND_TIMEOUT;
1055 cfg->resolvedelay = CS_RESOLVE_DELAY;
1056 cfg->mon_level = 2;
1057 cfg->mon_hideclient_to = 0;
1058 cfg->srtimeout = 1500;
1059 cfg->ulparent = 0;
1060 cfg->logfile = NULL;
1061 cfg->pidfile = NULL;
1062 cfg->usrfile = NULL;
1063 cfg->cwlogdir = NULL;
1064 cfg->ncd_keepalive = 1;
1065#ifdef CS_ANTICASC
1066 cfg->ac_enabled = 0;
1067 cfg->ac_users = 0;
1068 cfg->ac_stime = 2;
1069 cfg->ac_samples = 10;
1070 cfg->ac_denysamples = 8;
1071 cfg->ac_fakedelay = 1000;
1072 strcpy(cfg->ac_logfile, "./oscam_ac.log");
1073#endif
1074 sprintf(token, "%s%s", cs_confdir, cs_conf);
1075 if (!(fp = fopen(token, "r"))) {
1076 fprintf(stderr, "Cannot open config file '%s' (errno=%d)\n", token, errno);
1077 exit(1);
1078 }
1079 while (fgets(token, sizeof(token), fp)) {
1080 int i, l;
1081 //void *ptr;
1082 if ((l = strlen(trim(token))) < 3)
1083 continue;
1084 if ((token[0] == '[') && (token[l-1] == ']')) {
1085 for (token[l-1] = 0, tag = -1, i = TAG_GLOBAL; cctag[i]; i++)
1086 if (!strcmp(cctag[i], strtolower(token+1)))
1087 tag = i;
1088 continue;
1089 }
1090 if (!(value=strchr(token, '=')))
1091 continue;
1092 *value++ ='\0';
1093 chk_token(trim(strtolower(token)), trim(value), tag);
1094 }
1095 fclose(fp);
1096#ifdef CS_LOGFILE
1097 if (cfg->logfile == NULL)
1098 asprintf(&(cfg->logfile), "%s", CS_LOGFILE);
1099#endif
1100 cs_init_log(cfg->logfile);
1101 if (cfg->ftimeout >= cfg->ctimeout) {
1102 cfg->ftimeout = cfg->ctimeout - 100;
1103 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be smaller than clienttimeout (%lu ms))", cfg->ftimeout, cfg->ctimeout);
1104 }
1105 if(cfg->ftimeout < cfg->srtimeout) {
1106 cfg->ftimeout = cfg->srtimeout + 100;
1107 cs_log("WARNING: fallbacktimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ftimeout, cfg->srtimeout);
1108 }
1109 if(cfg->ctimeout < cfg->srtimeout) {
1110 cfg->ctimeout = cfg->srtimeout + 100;
1111 cs_log("WARNING: clienttimeout adjusted to %lu ms (must be greater than serialreadertimeout (%lu ms))", cfg->ctimeout, cfg->srtimeout);
1112 }
1113#ifdef CS_ANTICASC
1114 if( cfg->ac_denysamples+1 > cfg->ac_samples ) {
1115 cfg->ac_denysamples = cfg->ac_samples - 1;
1116 cs_log("WARNING: DenySamples adjusted to %d", cfg->ac_denysamples);
1117 }
1118#endif
1119 return 0;
1120}
1121
1122void chk_account(char *token, char *value, struct s_auth *account)
1123{
1124 int i;
1125 char *ptr1;
1126
1127 if (!strcmp(token, "user")) {
1128 cs_strncpy(account->usr, value, sizeof(account->usr));
1129 return;
1130 }
1131
1132 if (!strcmp(token, "pwd")) {
1133 cs_strncpy(account->pwd, value, sizeof(account->pwd));
1134 return;
1135 }
1136
1137 if (!strcmp(token, "hostname")) {
1138 cs_strncpy((char *)account->dyndns, value, sizeof(account->dyndns));
1139 return;
1140 }
1141
1142 if (!strcmp(token, "betatunnel")) {
1143 if(strlen(value) == 0) {
1144 clear_tuntab(&account->ttab);
1145 return;
1146 } else {
1147 chk_tuntab(value, &account->ttab);
1148 return;
1149 }
1150 }
1151
1152 if (!strcmp(token, "uniq")) {
1153 if(strlen(value) == 0) {
1154 account->uniq = 0;
1155 return;
1156 } else {
1157 account->uniq = atoi(value);
1158 return;
1159 }
1160 }
1161
1162 if (!strcmp(token, "sleep")) {
1163 if(strlen(value) == 0) {
1164 account->tosleep = 0;
1165 return;
1166 } else {
1167 account->tosleep=atoi(value);
1168 return;
1169 }
1170 }
1171
1172 if (!strcmp(token, "monlevel")) {
1173 if(strlen(value) == 0) {
1174 account->monlvl = 0;
1175 return;
1176 } else {
1177 account->monlvl = atoi(value);
1178 return;
1179 }
1180 }
1181
1182 if (!strcmp(token, "caid")) {
1183 if(strlen(value) == 0) {
1184 clear_caidtab(&account->ctab);
1185 return;
1186 } else {
1187 chk_caidtab(value, &account->ctab);
1188 return;
1189 }
1190 }
1191
1192 if (!strcmp(token, "disabled")) {
1193 if(strlen(value) == 0) {
1194 account->disabled = 0;
1195 return;
1196 } else {
1197 account->disabled = atoi(value);
1198 return;
1199 }
1200 }
1201
1202 if (!strcmp(token, "suppresscmd08")) {
1203 if(strlen(value) == 0) {
1204 account->c35_suppresscmd08 = 0;
1205 return;
1206 } else {
1207 account->c35_suppresscmd08=atoi(value);
1208 return;
1209 }
1210 }
1211
1212 if (!strcmp(token, "keepalive")) {
1213 if(strlen(value) == 0) {
1214 account->ncd_keepalive = 1;
1215 return;
1216 } else {
1217 account->ncd_keepalive = atoi(value);
1218 return;
1219 }
1220 }
1221 /*
1222 * case insensitive
1223 */
1224 strtolower(value);
1225
1226 if (!strcmp(token, "au")) {
1227 //set default values for usage during runtime from Webif
1228 account->au=-1;
1229 account->autoau=0;
1230
1231 if(value && value[0]=='1') account->autoau=1;
1232 for (i=0; i<CS_MAXREADER; i++)
1233 if ((reader[i].label[0]) && (!strncmp(reader[i].label, value, strlen(reader[i].label))))
1234 account->au=i;
1235 return;
1236 }
1237
1238 if (!strcmp(token, "group")) {
1239 account->grp = 0;
1240 for (ptr1=strtok(value, ","); ptr1; ptr1=strtok(NULL, ",")) {
1241 int g;
1242 g = atoi(ptr1);
1243 if ((g>0) && (g < 33)) account->grp|=(1<<(g-1));
1244 }
1245 return;
1246 }
1247
1248 if(!strcmp(token, "services")) {
1249 chk_services(value, &account->sidtabok, &account->sidtabno);
1250 return;
1251 }
1252
1253 if(!strcmp(token, "ident")) { /*ToDo ftab clear*/
1254 chk_ftab(value, &account->ftab, "user", account->usr, "provid");
1255 return;
1256 }
1257
1258 if(!strcmp(token, "class")) {
1259 chk_cltab(value, &account->cltab);
1260 return;
1261 }
1262
1263 if(!strcmp(token, "chid")) {
1264 chk_ftab(value, &account->fchid, "user", account->usr, "chid");
1265 return;
1266 }
1267
1268 if (!strcmp(token, "expdate")) {
1269 if (!value[0]) {
1270 account->expirationdate=(time_t)NULL;
1271 return;
1272 }
1273 struct tm cstime;
1274 memset(&cstime,0,sizeof(cstime));
1275 for (i=0, ptr1=strtok(value, "-/"); (i<3)&&(ptr1); ptr1=strtok(NULL, "-/"), i++) {
1276 switch(i) {
1277 case 0: cstime.tm_year=atoi(ptr1)-1900; break;
1278 case 1: cstime.tm_mon =atoi(ptr1)-1; break;
1279 case 2: cstime.tm_mday=atoi(ptr1); break;
1280 }
1281 }
1282 account->expirationdate=mktime(&cstime);
1283 return;
1284 }
1285
1286#ifdef CS_ANTICASC
1287 if( !strcmp(token, "numusers") ) {
1288 account->ac_users = atoi(value);
1289 return;
1290 }
1291
1292 if( !strcmp(token, "penalty") ) {
1293 account->ac_penalty = atoi(value);
1294 return;
1295 }
1296#endif
1297
1298 if (token[0] != '#')
1299 cs_log( "Warning: keyword '%s' in account section not recognized",token);
1300}
1301
1302int init_userdb()
1303{
1304 int tag = 0, nr, nro, expired, disabled;
1305 //int first=1;
1306 FILE *fp;
1307 char *value;
1308 struct s_auth *ptr;
1309 /*static */struct s_auth *account=(struct s_auth *)0;
1310
1311 sprintf(token, "%s%s", cs_confdir, cs_user);
1312 if (!(fp = fopen(token, "r"))) {
1313 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
1314 return(1);
1315 }
1316
1317 for (nro = 0, ptr = cfg->account; ptr; nro++) {
1318 struct s_auth *ptr_next;
1319 ptr_next = ptr->next;
1320 free(ptr);
1321 ptr = ptr_next;
1322 }
1323 nr = 0;
1324
1325 while (fgets(token, sizeof(token), fp)) {
1326 int i, l;
1327 void *ptr;
1328
1329 if ((l=strlen(trim(token))) < 3)
1330 continue;
1331
1332 if ((token[0] == '[') && (token[l-1] == ']')) {
1333 token[l - 1] = 0;
1334 tag = (!strcmp("account", strtolower(token + 1)));
1335
1336 if (!(ptr=malloc(sizeof(struct s_auth)))) {
1337 cs_log("Error allocating memory (errno=%d)", errno);
1338 return(1);
1339 }
1340
1341 if (account)
1342 account->next = ptr;
1343 else
1344 cfg->account = ptr;
1345
1346 account = ptr;
1347 memset(account, 0, sizeof(struct s_auth));
1348 account->au = (-1);
1349 account->monlvl = cfg->mon_level;
1350 account->tosleep = cfg->tosleep;
1351 account->c35_suppresscmd08 = cfg->c35_suppresscmd08;
1352 account->ncd_keepalive = cfg->ncd_keepalive;
1353 for (i = 1; i < CS_MAXCAIDTAB; account->ctab.mask[i++] = 0xffff);
1354 for (i = 1; i < CS_MAXTUNTAB; account->ttab.bt_srvid[i++] = 0x0000);
1355 nr++;
1356
1357#ifdef CS_ANTICASC
1358 account->ac_users = cfg->ac_users;
1359 account->ac_penalty = cfg->ac_penalty;
1360 account->ac_idx = nr;
1361#endif
1362 continue;
1363 }
1364
1365 if (!tag)
1366 continue;
1367
1368 if (!(value=strchr(token, '=')))
1369 continue;
1370
1371 *value++ = '\0';
1372 chk_account(trim(strtolower(token)), trim(value), account);
1373 }
1374
1375 fclose(fp);
1376
1377 for (expired = 0, disabled = 0, ptr = cfg->account; ptr;) {
1378
1379 if(ptr->expirationdate && ptr->expirationdate < time(NULL))
1380 expired++;
1381
1382 if(ptr->disabled != 0)
1383 disabled++;
1384
1385 ptr = ptr->next;
1386 }
1387
1388 cs_log("userdb reloaded: %d accounts freed, %d accounts loaded, %d expired, %d disabled", nro, nr, expired, disabled);
1389 return(0);
1390}
1391
1392static void chk_entry4sidtab(char *value, struct s_sidtab *sidtab, int what)
1393{
1394 int i, b;
1395 char *ptr;
1396 ushort *slist=(ushort *) 0;
1397 ulong *llist=(ulong *) 0;
1398 ulong caid;
1399 char buf[strlen(value) + 1];
1400 cs_strncpy(buf, value, sizeof(buf));
1401 b=(what==1) ? sizeof(ulong) : sizeof(ushort);
1402 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1403 {
1404 caid=a2i(ptr, b);
1405 if (!errno) i++;
1406 }
1407 //if (!i) return(0);
1408 if (b==sizeof(ushort))
1409 slist=malloc(i*sizeof(ushort));
1410 else
1411 llist=malloc(i*sizeof(ulong));
1412 strcpy(value, buf);
1413 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ","))
1414 {
1415 caid=a2i(ptr, b);
1416 if (errno) continue;
1417 if (b==sizeof(ushort))
1418 slist[i++]=(ushort) caid;
1419 else
1420 llist[i++]=caid;
1421 }
1422 switch (what)
1423 {
1424 case 0: sidtab->caid=slist;
1425 sidtab->num_caid=i;
1426 break;
1427 case 1: sidtab->provid=llist;
1428 sidtab->num_provid=i;
1429 break;
1430 case 2: sidtab->srvid=slist;
1431 sidtab->num_srvid=i;
1432 break;
1433 }
1434}
1435
1436void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab)
1437{
1438 if (!strcmp(token, "caid")) { chk_entry4sidtab(value, sidtab, 0); return; }
1439 if (!strcmp(token, "provid")) { chk_entry4sidtab(value, sidtab, 1); return; }
1440 if (!strcmp(token, "ident")) { chk_entry4sidtab(value, sidtab, 1); return; }
1441 if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; }
1442 if (token[0] != '#')
1443 fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token);
1444}
1445
1446int init_sidtab()
1447{
1448 int nr, nro;
1449 FILE *fp;
1450 char *value;
1451 struct s_sidtab *ptr;
1452 struct s_sidtab *sidtab=(struct s_sidtab *)0;
1453
1454 sprintf(token, "%s%s", cs_confdir, cs_sidt);
1455 if (!(fp=fopen(token, "r")))
1456 {
1457 cs_log("Cannot open file \"%s\" (errno=%d)", token, errno);
1458 return(1);
1459 }
1460 for (nro=0, ptr=cfg->sidtab; ptr; nro++)
1461 {
1462 struct s_sidtab *ptr_next;
1463 ptr_next=ptr->next;
1464 if (ptr->caid) free(ptr->caid);
1465 if (ptr->provid) free(ptr->provid);
1466 if (ptr->srvid) free(ptr->srvid);
1467 free(ptr);
1468 ptr=ptr_next;
1469 }
1470 nr=0;
1471 while (fgets(token, sizeof(token), fp))
1472 {
1473 int l;
1474 void *ptr;
1475 if ((l=strlen(trim(token)))<3) continue;
1476 if ((token[0]=='[') && (token[l-1]==']'))
1477 {
1478 token[l-1]=0;
1479 if (!(ptr=malloc(sizeof(struct s_sidtab))))
1480 {
1481 cs_log("Error allocating memory (errno=%d)", errno);
1482 return(1);
1483 }
1484 if (sidtab)
1485 sidtab->next=ptr;
1486 else
1487 cfg->sidtab=ptr;
1488 sidtab=ptr;
1489 nr++;
1490 memset(sidtab, 0, sizeof(struct s_sidtab));
1491 cs_strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label));
1492 continue;
1493 }
1494 if (!sidtab) continue;
1495 if (!(value=strchr(token, '='))) continue;
1496 *value++='\0';
1497 chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
1498 }
1499 fclose(fp);
1500
1501#ifdef DEBUG_SIDTAB
1502 show_sidtab(cfg->sidtab);
1503#endif
1504 cs_log("services reloaded: %d services freed, %d services loaded", nro, nr);
1505 return(0);
1506}
1507
1508int init_srvid()
1509{
1510 int nr;
1511 FILE *fp;
1512 char *payload;
1513 static struct s_srvid *srvid=(struct s_srvid *)0;
1514 sprintf(token, "%s%s", cs_confdir, cs_srid);
1515
1516 if (!(fp=fopen(token, "r"))) {
1517 cs_log("can't open file \"%s\" (err=%d), no service-id's loaded", token, errno);
1518 return(0);
1519 }
1520
1521 nr=0;
1522 while (fgets(token, sizeof(token), fp)) {
1523
1524 int l;
1525 void *ptr;
1526 char *tmp;
1527 tmp = trim(token);
1528
1529 if (tmp[0] == '#') continue;
1530 if ((l=strlen(tmp)) < 6) continue;
1531 if (!(payload=strchr(token, '|'))) continue;
1532 *payload++ = '\0';
1533
1534 if (!(ptr = malloc(sizeof(struct s_srvid)))) {
1535 cs_log("Error allocating memory (errno=%d)", errno);
1536 return(1);
1537 }
1538
1539 if (srvid)
1540 srvid->next = ptr;
1541 else
1542 cfg->srvid = ptr;
1543
1544 srvid = ptr;
1545 memset(srvid, 0, sizeof(struct s_srvid));
1546
1547 int i;
1548 char *ptr1;
1549 for (i = 0, ptr1 = strtok(payload, "|"); ptr1; ptr1 = strtok(NULL, "|"), i++){
1550 switch(i){
1551 case 0:
1552 cs_strncpy(srvid->prov, trim(ptr1), sizeof(srvid->prov));
1553 break;
1554 case 1:
1555 cs_strncpy(srvid->name, trim(ptr1), sizeof(srvid->name));
1556 break;
1557 case 2:
1558 cs_strncpy(srvid->type, trim(ptr1), sizeof(srvid->type));
1559 break;
1560 case 3:
1561 cs_strncpy(srvid->desc, trim(ptr1), sizeof(srvid->desc));
1562 break;
1563 }
1564 }
1565
1566 char *srvidasc = strchr(token, ':');
1567 *srvidasc++ = '\0';
1568 srvid->srvid = word_atob(srvidasc);
1569
1570 srvid->ncaid = 0;
1571 for (i = 0, ptr1 = strtok(token, ","); (ptr1) && (i < 10) ; ptr1 = strtok(NULL, ","), i++){
1572 srvid->caid[i] = word_atob(ptr1);
1573 srvid->ncaid = i+1;
1574 //cs_debug("ld caid: %04X srvid: %04X Prov: %s Chan: %s",srvid->caid[i],srvid->srvid,srvid->prov,srvid->name);
1575 }
1576 nr++;
1577 }
1578
1579 fclose(fp);
1580 if (nr>0)
1581 cs_log("%d service-id's loaded", nr);
1582 else{
1583 cs_log("oscam.srvid loading failed, old format");
1584 }
1585 return(0);
1586}
1587
1588static void chk_reader(char *token, char *value, struct s_reader *rdr)
1589{
1590 int i;
1591 char *ptr;
1592 /*
1593 * case sensitive first
1594 */
1595 if (!strcmp(token, "device")) {
1596 for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
1597 trim(ptr);
1598 switch(i) {
1599 case 0:
1600 cs_strncpy(rdr->device, ptr, sizeof(rdr->device));
1601 break;
1602
1603 case 1:
1604 rdr->r_port = atoi(ptr);
1605 break;
1606
1607 case 2:
1608 rdr->l_port = atoi(ptr);
1609 break;
1610 }
1611 }
1612 return;
1613 }
1614
1615 if (!strcmp(token, "key")) {
1616 if (key_atob14(value, rdr->ncd_key)) {
1617 fprintf(stderr, "Configuration newcamd: Error in Key\n");
1618 exit(1);
1619 }
1620 return;
1621 }
1622
1623#ifdef CS_WITH_GBOX
1624 if (!strcmp(token, "password")) {
1625 cs_strncpy((char *)rdr->gbox_pwd, (const char *)i2b(4, a2i(value, 4)), 4);
1626 return;
1627 }
1628
1629 if (!strcmp(token, "premium")) {
1630 rdr->gbox_prem = 1;
1631 return;
1632 }
1633#endif
1634 if (!strcmp(token, "account")) {
1635 for (i = 0, ptr = strtok(value, ","); (i < 2) && (ptr); ptr = strtok(NULL, ","), i++) {
1636 trim(ptr);
1637 switch(i) {
1638 case 0:
1639 cs_strncpy(rdr->r_usr, ptr, sizeof(rdr->r_usr));
1640 break;
1641
1642 case 1:
1643 cs_strncpy(rdr->r_pwd, ptr, sizeof(rdr->r_pwd));
1644 break;
1645 }
1646 }
1647 return;
1648 }
1649
1650 if (!strcmp(token, "pincode")) {
1651 strncpy(rdr->pincode, value, sizeof(rdr->pincode) - 1);
1652 return;
1653 }
1654
1655 if (!strcmp(token, "readnano") && value[0]) {
1656 asprintf(&(rdr->emmfile), "%s", value);
1657 return;
1658 }
1659
1660 /*
1661 * case insensitive
1662 */
1663 strtolower(value);
1664
1665 if (!strcmp(token, "enable")) {
1666 rdr->enable = atoi(value) ? 1 : 0;
1667 return;
1668 }
1669
1670 if (!strcmp(token, "services")) {
1671 chk_services(value, &rdr->sidtabok, &rdr->sidtabno);
1672 return;
1673 }
1674
1675 if (!strcmp(token, "inactivitytimeout")) {
1676 rdr->tcp_ito = atoi(value);
1677 return;
1678 }
1679
1680 if (!strcmp(token, "reconnecttimeout")) {
1681 rdr->tcp_rto = atoi(value);
1682 return;
1683 }
1684
1685 if (!strcmp(token, "disableserverfilter")) {
1686 rdr->ncd_disable_server_filt = atoi(value);
1687 return;
1688 }
1689
1690 //FIXME workaround for Smargo until native mode works
1691 if (!strcmp(token, "smargopatch")) {
1692 rdr->smargopatch = atoi(value);
1693 return;
1694 }
1695
1696 if (!strcmp(token, "label")) {
1697 cs_strncpy(rdr->label, value, sizeof(rdr->label));
1698 return;
1699 }
1700
1701 if (!strcmp(token, "fallback")) {
1702 rdr->fallback = atoi(value) ? 1 : 0;
1703 return;
1704 }
1705
1706 if (!strcmp(token, "logport")) {
1707 rdr->log_port = atoi(value);
1708 return;
1709 }
1710
1711 if (!strcmp(token, "caid")) {
1712 chk_caidtab(value, &rdr->ctab);
1713 return;
1714 }
1715
1716 if (!strcmp(token, "boxid")) {
1717 rdr->boxid = a2i(value, 4);
1718 return;
1719 }
1720
1721 if (!strcmp(token, "aeskey")) {
1722 if (key_atob(value, rdr->aes_key)) {
1723 fprintf(stderr, "Configuration reader: Error in AES Key\n");
1724 exit(1);
1725 }
1726 return;
1727 }
1728
1729 if ((!strcmp(token, "n3_rsakey")) || (!strcmp(token, "rsakey"))) {
1730 rdr->has_rsa = 1;
1731 if (key_atob_l(value, rdr->rsa_mod, 128)) {
1732 fprintf(stderr, "Configuration reader: Error in rsakey\n");
1733 exit(1);
1734 }
1735 return;
1736 }
1737
1738 if (!strcmp(token, "tiger_rsakey")) {
1739 if (key_atob_l(value, rdr->rsa_mod, 240)) {
1740 fprintf(stderr, "Configuration reader: Error in tiger_rsakey\n");
1741 exit(1);
1742 }
1743 return;
1744 }
1745
1746 if ((!strcmp(token, "n3_boxkey")) || (!strcmp(token, "boxkey"))) {
1747 if (key_atob_l(value, rdr->nagra_boxkey, 16)) {
1748 fprintf(stderr, "Configuration reader: Error in boxkey\n");
1749 exit(1);
1750 }
1751 return;
1752 }
1753
1754 if (!strcmp(token, "detect")) {
1755 for (i = 0; RDR_CD_TXT[i]; i++) {
1756 if (!strcmp(value, RDR_CD_TXT[i])) {
1757 rdr->detect = i;
1758 }
1759 else {
1760 if ((value[0] == '!') && (!strcmp(value+1, RDR_CD_TXT[i])))
1761 rdr->detect = i|0x80;
1762 }
1763 }
1764 return;
1765 }
1766
1767 if (!strcmp(token, "mhz")) {
1768 rdr->mhz = atoi(value);
1769 return;
1770 }
1771
1772 if (!strcmp(token, "cardmhz")) {
1773 rdr->cardmhz = atoi(value);
1774 return;
1775 }
1776
1777 if (!strcmp(token, "protocol")) {
1778
1779 if (!strcmp(value, "mouse")) {
1780 rdr->typ = R_MOUSE;
1781 return;
1782 }
1783
1784 if (!strcmp(value, "smartreader")) {
1785 rdr->typ = R_SMART;
1786 return;
1787 }
1788
1789 if (!strcmp(value, "internal")) {
1790 rdr->typ = R_INTERNAL;
1791 return;
1792 }
1793
1794#ifdef HAVE_PCSC
1795 if (!strcmp(value, "pcsc")) {
1796 rdr->typ = R_PCSC;
1797 return;
1798 }
1799#endif
1800
1801 if (!strcmp(value, "serial")) {
1802 rdr->typ = R_SERIAL;
1803 return;
1804 }
1805
1806 if (!strcmp(value, "camd35")) {
1807 rdr->typ = R_CAMD35;
1808 return;
1809 }
1810
1811 if (!strcmp(value, "cs378x")) {
1812 rdr->typ = R_CS378X;
1813 return;
1814 }
1815
1816 if (!strcmp(value, "cs357x")) {
1817 rdr->typ = R_CAMD35;
1818 return;
1819 }
1820
1821 if (!strcmp(value, "gbox")) {
1822 rdr->typ = R_GBOX;
1823 return;
1824 }
1825
1826 if (!strcmp(value, "cccam")) {
1827 rdr->typ = R_CCCAM;
1828 //strcpy(value, "1");
1829 //chk_caidtab(value, &rdr->ctab);
1830 //this is a MAJOR hack for auto multiple caid support (not currently working due to ncd table issue)
1831 return;
1832 }
1833
1834 if (!strcmp(value, "radegast")) {
1835 rdr->typ = R_RADEGAST;
1836 return;
1837 }
1838
1839 if (!strcmp(value, "newcamd") || !strcmp(value, "newcamd525")) {
1840 rdr->typ = R_NEWCAMD;
1841 rdr->ncd_proto = NCD_525;
1842 return;
1843 }
1844
1845 if (!strcmp(value, "newcamd524")) {
1846 rdr->typ = R_NEWCAMD;
1847 rdr->ncd_proto = NCD_524;
1848 return;
1849 }
1850
1851 fprintf(stderr, "WARNING: value '%s' in protocol-line not recognized, assuming MOUSE\n",value);
1852 rdr->typ = R_MOUSE;
1853 return;
1854 }
1855
1856 if (!strcmp(token, "loadbalanced")) {
1857 rdr->loadbalanced = atoi(value);
1858 return;
1859 }
1860
1861 if (!strcmp(token, "ident")) {
1862 chk_ftab(value, &rdr->ftab,"reader",rdr->label,"provid");
1863 return;
1864 }
1865
1866 if (!strcmp(token, "class")) {
1867 chk_cltab(value, &rdr->cltab);
1868 return;
1869 }
1870
1871 if (!strcmp(token, "chid")) {
1872 chk_ftab(value, &rdr->fchid,"reader",rdr->label,"chid");
1873 return;
1874 }
1875
1876 if (!strcmp(token, "showcls")) {
1877 rdr->show_cls = atoi(value);
1878 return;
1879 }
1880
1881 if (!strcmp(token, "maxqlen")) {
1882 rdr->maxqlen = atoi(value);
1883 if( rdr->maxqlen < 0 || rdr->maxqlen > CS_MAXQLEN) {
1884 rdr->maxqlen = CS_MAXQLEN;
1885 }
1886 return;
1887 }
1888
1889 if (!strcmp(token, "group"))
1890 {
1891 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
1892 int g;
1893 g = atoi(ptr);
1894 if ((g>0) && (g<33)) {
1895 rdr->grp |= (1<<(g-1));
1896 }
1897 }
1898 return;
1899 }
1900
1901 if (!strcmp(token, "emmcache")) {
1902 for (i = 0, ptr = strtok(value, ","); (i < 3) && (ptr); ptr = strtok(NULL, ","), i++) {
1903 switch(i)
1904 {
1905 case 0:
1906 rdr->cachemm = atoi(ptr);
1907 break;
1908
1909 case 1:
1910 rdr->rewritemm = atoi(ptr);
1911 break;
1912
1913 case 2: rdr->logemm = atoi(ptr);
1914 break;
1915 }
1916 }
1917
1918 if (rdr->rewritemm <= 0) {
1919 fprintf(stderr, "Notice: Setting EMMCACHE to %i,1,%i instead of %i,%i,%i. ",
1920 rdr->cachemm, rdr->logemm,
1921 rdr->cachemm, rdr->rewritemm,
1922 rdr->logemm);
1923
1924 fprintf(stderr, "Zero or negative number of rewrites is silly\n");
1925 rdr->rewritemm = 1;
1926 }
1927 return;
1928 }
1929
1930 if (!strcmp(token, "blocknano")) {
1931 //wildcard is used
1932 if (!strcmp(value,"all")) {
1933 for (i = 0 ; i < 256; i++) {
1934 rdr->b_nano[i] |= 0x01; //set all lsb's to block all nanos
1935 }
1936 }
1937 else {
1938 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
1939 if ((i = byte_atob(ptr)) >= 0) {
1940 rdr->b_nano[i] |= 0x01; //lsb is set when to block nano
1941 }
1942 }
1943 }
1944 return;
1945 }
1946
1947 if (!strcmp(token, "savenano")) {
1948 //wildcard is used
1949 if (!strcmp(value,"all")) {
1950 for (i = 0 ; i < 256; i++) {
1951 rdr->b_nano[i] |= 0x02; //set all lsb+1 to save all nanos to file
1952 }
1953 }
1954 else {
1955 for (ptr = strtok(value, ","); ptr; ptr = strtok(NULL, ",")) {
1956 if ((i = byte_atob(ptr)) >= 0) {
1957 rdr->b_nano[i] |= 0x02; //lsb+1 is set when to save nano to file
1958 }
1959 }
1960 }
1961 return;
1962 }
1963
1964 if (!strcmp(token, "cccversion")) {
1965 // cccam version
1966 if (strlen(value) > sizeof(rdr->cc_version) - 1) {
1967 fprintf(stderr, "cccam config: version too long\n");
1968 exit(1);
1969 }
1970 memset(rdr->cc_version, 0, sizeof(rdr->cc_version));
1971 cs_strncpy(rdr->cc_version, value, sizeof(rdr->cc_version));
1972 return;
1973 }
1974
1975 if (!strcmp(token, "cccbuild")) {
1976 // cccam build number
1977 if (strlen(value) > sizeof(rdr->cc_build) - 1) {
1978 fprintf(stderr, "cccam config build number too long\n");
1979 exit(1);
1980 }
1981
1982 memset(rdr->cc_build, 0, sizeof(rdr->cc_build));
1983 cs_strncpy(rdr->cc_build, value, sizeof(rdr->cc_build));
1984 return;
1985 }
1986
1987 if (!strcmp(token, "cccmaxhop")) {
1988 // cccam max card distance
1989 rdr->cc_maxhop = atoi(value);
1990 return;
1991 }
1992
1993 if (!strcmp(token, "deprecated")) {
1994 rdr->deprecated = atoi(value);
1995 return;
1996 }
1997
1998 if (token[0] != '#')
1999 cs_log("Warning: keyword '%s' in reader section not recognized",token);
2000}
2001
2002int init_readerdb()
2003{
2004 int tag = 0, nr;
2005 FILE *fp;
2006 char *value;
2007
2008 sprintf(token, "%s%s", cs_confdir, cs_srvr);
2009 if (!(fp=fopen(token, "r"))) {
2010 cs_log("can't open file \"%s\" (errno=%d)\n", token, errno);
2011 return(1);
2012 }
2013 nr = 0;
2014 while (fgets(token, sizeof(token), fp)) {
2015 int i, l;
2016 if ((l = strlen(trim(token))) < 3)
2017 continue;
2018 if ((token[0] == '[') && (token[l-1] == ']')) {
2019 token[l-1] = 0;
2020 tag = (!strcmp("reader", strtolower(token+1)));
2021 if (reader[nr].label[0] && reader[nr].typ) nr++;
2022 memset(&reader[nr], 0, sizeof(struct s_reader));
2023 reader[nr].enable = 1;
2024 reader[nr].tcp_rto = 30;
2025 reader[nr].show_cls = 10;
2026 reader[nr].maxqlen = CS_MAXQLEN;
2027 reader[nr].mhz = 357;
2028 reader[nr].cardmhz = 357;
2029 reader[nr].deprecated = 0;
2030 strcpy(reader[nr].pincode, "none");
2031 for (i=1; i<CS_MAXCAIDTAB; reader[nr].ctab.mask[i++]=0xffff);
2032 continue;
2033 }
2034
2035 if (!tag)
2036 continue;
2037 if (!(value=strchr(token, '=')))
2038 continue;
2039 *value++ ='\0';
2040 chk_reader(trim(strtolower(token)), trim(value), &reader[nr]);
2041 }
2042 fclose(fp);
2043 return(0);
2044}
2045
2046/*
2047int init_irdeto_guess_tab()
2048{
2049 int i, j, skip;
2050 int b47;
2051 FILE *fp;
2052 char token[128], *value, *ptr;
2053 char zSid[5];
2054 uchar b3;
2055 ushort caid, sid;
2056 struct s_irdeto_quess *ird_row, *head;
2057
2058 memset(cfg->itab, 0, sizeof(cfg->itab));
2059 sprintf(token, "%s%s", cs_confdir, cs_ird);
2060 if (!(fp=fopen(token, "r")))
2061 {
2062 cs_log("can't open file \"%s\" (errno=%d) irdeto guessing not loaded",
2063 token, errno);
2064 return(1);
2065 }
2066 while (fgets(token, sizeof(token), fp))
2067 {
2068 if( strlen(token)<20 ) continue;
2069 for( i=b3=b47=caid=sid=skip=0, ptr=strtok(token, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
2070 {
2071 trim(ptr);
2072 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
2073 skip=1;
2074 break;
2075 }
2076 switch(i)
2077 {
2078 case 0: b3 = a2i(ptr, 2); break;
2079 case 1: b47 = a2i(ptr, 8); break;
2080 case 2: caid = a2i(ptr, 4); break;
2081 case 3:
2082 for( j=0; j<4; j++ )
2083 zSid[j]=ptr[j];
2084 zSid[4]=0;
2085 sid = a2i(zSid, 4);
2086 break;
2087 }
2088 }
2089 if( !skip )
2090 {
2091 if (!(ird_row=(struct s_irdeto_quess*)malloc(sizeof(struct s_irdeto_quess))))
2092 {
2093 cs_log("Error allocating memory (errno=%d)", errno);
2094 return;
2095 }
2096 ird_row->b47 = b47;
2097 ird_row->caid = caid;
2098 ird_row->sid = sid;
2099 ird_row->next = 0;
2100
2101 head = cfg->itab[b3];
2102 if( head ) {
2103 while( head->next )
2104 head=head->next;
2105 head->next=ird_row;
2106 }
2107 else
2108 cfg->itab[b3]=ird_row;
2109
2110 //cs_debug("%02X:%08X:%04X:%04X", b3, b47, caid, sid);
2111 }
2112 }
2113 fclose(fp);
2114
2115 for( i=0; i<0xff; i++ )
2116 {
2117 head=cfg->itab[i];
2118 while(head)
2119 {
2120 cs_debug("itab[%02X]: b47=%08X, caid=%04X, sid=%04X",
2121 i, head->b47, head->caid, head->sid);
2122 head=head->next;
2123 }
2124 }
2125 return(0);
2126}
2127*/
2128
2129#ifdef CS_ANTICASC
2130void init_ac()
2131{
2132 int nr;
2133 FILE *fp;
2134 //char *value;
2135
2136 sprintf(token, "%s%s", cs_confdir, cs_ac);
2137 if (!(fp=fopen(token, "r")))
2138 {
2139 cs_log("can't open file \"%s\" (errno=%d) anti-cascading table not loaded",
2140 token, errno);
2141 return;
2142 }
2143
2144 for(nr=0; fgets(token, sizeof(token), fp);)
2145 {
2146 int i, skip;
2147 ushort caid, sid, chid, dwtime;
2148 ulong provid;
2149 char *ptr, *ptr1;
2150 struct s_cpmap *ptr_cpmap;
2151 static struct s_cpmap *cpmap=(struct s_cpmap *)0;
2152
2153 if( strlen(token)<4 ) continue;
2154
2155 caid=sid=chid=dwtime=0;
2156 provid=0;
2157 skip=0;
2158 ptr1=0;
2159 for( i=0, ptr=strtok(token, "="); (i<2)&&(ptr); ptr=strtok(NULL, "="), i++ )
2160 {
2161 trim(ptr);
2162 if( *ptr==';' || *ptr=='#' || *ptr=='-' ) {
2163 skip=1;
2164 break;
2165 }
2166 switch( i )
2167 {
2168 case 0:
2169 ptr1=ptr;
2170 break;
2171 case 1:
2172 dwtime = atoi(ptr);
2173 break;
2174 }
2175 }
2176
2177 if( !skip )
2178 {
2179 for( i=0, ptr=strtok(ptr1, ":"); (i<4)&&(ptr); ptr=strtok(NULL, ":"), i++ )
2180 {
2181 trim(ptr);
2182 switch( i )
2183 {
2184 case 0:
2185 if( *ptr=='*' ) caid = 0;
2186 else caid = a2i(ptr, 4);
2187 break;
2188 case 1:
2189 if( *ptr=='*' ) provid = 0;
2190 else provid = a2i(ptr, 6);
2191 break;
2192 case 2:
2193 if( *ptr=='*' ) sid = 0;
2194 else sid = a2i(ptr, 4);
2195 break;
2196 case 3:
2197 if( *ptr=='*' ) chid = 0;
2198 else chid = a2i(ptr, 4);
2199 break;
2200 }
2201 }
2202 if (!(ptr_cpmap=(struct s_cpmap*)malloc(sizeof(struct s_cpmap))))
2203 {
2204 cs_log("Error allocating memory (errno=%d)", errno);
2205 return;
2206 }
2207 if( cpmap )
2208 cpmap->next=ptr_cpmap;
2209 else
2210 cfg->cpmap=ptr_cpmap;
2211 cpmap=ptr_cpmap;
2212
2213 cpmap->caid = caid;
2214 cpmap->provid = provid;
2215 cpmap->sid = sid;
2216 cpmap->chid = chid;
2217 cpmap->dwtime = dwtime;
2218 cpmap->next = 0;
2219
2220 cs_debug("nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
2221 nr, caid, provid, sid, chid, dwtime);
2222 nr++;
2223 }
2224 }
2225 fclose(fp);
2226 //cs_log("%d lengths for caid guessing loaded", nr);
2227 return;
2228}
2229#endif
Note: See TracBrowser for help on using the repository browser.