-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsc.c
1499 lines (1324 loc) · 37.2 KB
/
sc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Softcam plugin to VDR (C++)
*
* This code is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
*/
#include <malloc.h>
#include <stdlib.h>
#include <limits.h>
#include <getopt.h>
#include <typeinfo>
#ifndef STATICBUILD
#include <dlfcn.h>
#include <dirent.h>
#include <fnmatch.h>
#endif
#include <vdr/plugin.h>
#include <vdr/menuitems.h>
#include <vdr/status.h>
#include <vdr/dvbdevice.h>
#include <vdr/channels.h>
#include <vdr/interface.h>
#include <vdr/menu.h>
#include <vdr/tools.h>
#include <vdr/config.h>
#include "scsetup.h"
#include "filter.h"
#include "system.h"
#include "cam.h"
#include "global.h"
#include "device.h"
#include "smartcard.h"
#include "data.h"
#include "network.h"
#include "misc.h"
#include "opts.h"
#include "i18n.h"
#include "log-core.h"
#include "sc-version.h"
#define MIN_VERS 1 // required VDR version
#define MIN_MAJOR 6
#define MIN_MINOR 0
#define MINAPIVERSNUM 10600
// some sanity checks
#ifdef HAVE_SOFTCSA
#error softcsa/ffdecsa patch MUST NOT be applied. Next time read the README first.
#endif
#ifdef VDR_IS_SC_PATCHED
#error You MUST NOT patch the VDR core. Next time read the README first.
#endif
#if APIVERSNUM<MINAPIVERSNUM
#error Your VDR API version is too old. See README.
#endif
static cPlugin *ScPlugin;
static cOpts *ScOpts, *LogOpts;
static const char * const cfgsub="sc";
static const struct LogModule lm_core = {
(LMOD_ENABLE|L_CORE_ALL)&LOPT_MASK,
(LMOD_ENABLE|L_CORE_LOAD|L_CORE_ECM|L_CORE_PIDS|L_CORE_AU|L_CORE_AUSTATS|L_CORE_NET|L_CORE_CI|L_CORE_SC|L_CORE_HOOK|L_CORE_OVER)&LOPT_MASK,
"core",
{ "load","action","ecm","ecmProc","pids","au","auStats","auExtra","auExtern",
"caids","keys","dynamic","csa","ci","av7110","net","netData","msgcache",
"serial","smartcard","hook","ciFull","csaVerb","override" }
};
ADD_MODULE(L_CORE,lm_core)
// --- cMenuEditCapItem --------------------------------------------------------
class cMenuEditCapItem : public cMenuEditIntItem {
protected:
virtual void Set(void);
public:
cMenuEditCapItem(const char *Name, int *Value);
eOSState ProcessKey(eKeys Key);
};
cMenuEditCapItem::cMenuEditCapItem(const char *Name, int *Value)
:cMenuEditIntItem(Name, Value, 0)
{
Set();
}
void cMenuEditCapItem::Set(void)
{
if(!*value) SetValue(tr("off"));
else cMenuEditIntItem::Set();
}
eOSState cMenuEditCapItem::ProcessKey(eKeys Key)
{
eOSState state = cMenuEditItem::ProcessKey(Key);
if(state==osUnknown)
state=cMenuEditIntItem::ProcessKey(Key);
return state;
}
// --- cMenuEditHexItem ------------------------------------------------------
class cMenuEditHexItem : public cMenuEditItem {
private:
bool abc, isOn;
//
void SetButtons(bool on);
protected:
int *value;
int min, max;
//
virtual void Set(void);
public:
cMenuEditHexItem(const char *Name, int *Value, int Min=0, int Max=INT_MAX);
virtual eOSState ProcessKey(eKeys Key);
};
cMenuEditHexItem::cMenuEditHexItem(const char *Name, int *Value, int Min, int Max)
:cMenuEditItem(Name)
{
value=Value; min=Min; max=Max;
if(*value<min) *value=min;
else if(*value>max) *value=max;
Set();
abc=true; isOn=false;
}
void cMenuEditHexItem::SetButtons(bool on)
{
if(on) {
if(abc) cSkinDisplay::Current()->SetButtons("A","B","C","D-F");
else cSkinDisplay::Current()->SetButtons("D","E","F","A-C");
isOn=true;
}
else {
cSkinDisplay::Current()->SetButtons(0);
isOn=false;
}
}
void cMenuEditHexItem::Set(void)
{
char buf[16];
snprintf(buf,sizeof(buf),"%X",*value);
SetValue(buf);
}
eOSState cMenuEditHexItem::ProcessKey(eKeys Key)
{
switch(NORMALKEY(Key)) {
case kUp:
case kDown:
if(isOn) SetButtons(false);
break;
default:
if(!isOn) SetButtons(true);
break;
}
eOSState state=cMenuEditItem::ProcessKey(Key);
if(state!=osUnknown) return state;
int newValue=*value;
bool IsRepeat=Key & k_Repeat;
Key=NORMALKEY(Key);
switch(Key) {
case kBlue:
abc=!abc; SetButtons(true);
break;
case kRed:
case kGreen:
case kYellow:
case k0 ... k9:
{
if(fresh) { newValue=0; fresh=false; }
int add;
if(Key>=kRed && Key<=kYellow) add=(abc ? 10:13)+(Key-kRed);
else add=(Key-k0);
newValue=newValue*16+add;
break;
}
case kLeft:
newValue=*value-1; fresh=true;
if(!IsRepeat && newValue<min) newValue=max;
break;
case kRight:
newValue=*value+1; fresh=true;
if(!IsRepeat && newValue>max) newValue=min;
break;
default:
if(*value<min) { *value=min; Set(); }
if(*value>max) { *value=max; Set(); }
return osUnknown;
}
if(newValue!=*value && (!fresh || min<=newValue) && newValue<=max) {
*value=newValue;
Set();
}
return osContinue;
}
// --- cScInfoItem -------------------------------------------------------------
class cScInfoItem : public cOsdItem {
private:
void SetValue(const char *Name, const char *Value);
//
int ident;
public:
cScInfoItem(const char *Name, int Value, eOSState State=osUnknown);
cScInfoItem(const char *Name, const char *Value=0, eOSState State=osUnknown);
void Ident(int id) { ident=id; }
int Ident(void) { return ident; }
};
cScInfoItem::cScInfoItem(const char *Name, int Value, eOSState State)
:cOsdItem(State)
{
char buf[16];
snprintf(buf,sizeof(buf),"%d",Value);
SetValue(Name,buf);
if(State==osUnknown) SetSelectable(false);
}
cScInfoItem::cScInfoItem(const char *Name, const char *Value, eOSState State)
:cOsdItem(State)
{
SetValue(Name,Value);
if(State==osUnknown) SetSelectable(false);
}
void cScInfoItem::SetValue(const char *Name, const char *Value)
{
char *buff=bprintf(Value ? "%s:\t%s":"%s",Name,Value);
SetText(buff,false);
cStatus::MsgOsdCurrentItem(buff);
ident=-1;
}
// --- cOpt --------------------------------------------------------------------
cOpt::cOpt(const char *Name, const char *Title)
{
name=Name; title=Title;
fullname=0; persistant=true;
}
cOpt::~cOpt()
{
free(fullname);
}
const char *cOpt::FullName(const char *PreStr)
{
if(PreStr) {
free(fullname);
fullname=bprintf("%s.%s",PreStr,name);
return fullname;
}
else return name;
}
// --- cOptInt -----------------------------------------------------------------
cOptInt::cOptInt(const char *Name, const char *Title, int *Storage, int Min, int Max)
:cOpt(Name,Title)
{
storage=Storage; min=Min; max=Max;
}
void cOptInt::Parse(const char *Value)
{
*storage=atoi(Value);
}
void cOptInt::Backup(void)
{
value=*storage;
}
bool cOptInt::Set(void)
{
if(value!=*storage) { *storage=value; return true; }
return false;
}
void cOptInt::Store(const char *PreStr)
{
ScPlugin->SetupStore(FullName(PreStr),*storage);
}
void cOptInt::Create(cOsdMenu *menu)
{
menu->Add(new cMenuEditIntItem(tr(title),&value,min,max));
}
// --- cOptSel -----------------------------------------------------------------
cOptSel::cOptSel(const char *Name, const char *Title, int *Storage, int NumStr, const char * const *Strings)
:cOptInt(Name,Title,Storage,0,NumStr)
{
strings=Strings;
trStrings=0;
}
cOptSel::~cOptSel()
{
free(trStrings);
}
void cOptSel::Create(cOsdMenu *menu)
{
free(trStrings);
if((trStrings=MALLOC(const char *,max))) {
for(int i=0; i<max ; i++) trStrings[i]=tr(strings[i]);
menu->Add(new cMenuEditStraItem(tr(title),&value,max,trStrings));
}
}
// --- cOptBool -----------------------------------------------------------------
cOptBool::cOptBool(const char *Name, const char *Title, int *Storage)
:cOptInt(Name,Title,Storage,0,1)
{}
void cOptBool::Create(cOsdMenu *menu)
{
menu->Add(new cMenuEditBoolItem(tr(title),&value));
}
// --- cOptStr -----------------------------------------------------------------
cOptStr::cOptStr(const char *Name, const char *Title, char *Storage, int Size, const char *Allowed)
:cOpt(Name,Title)
{
storage=Storage; size=Size; allowed=Allowed;
value=MALLOC(char,size);
}
cOptStr::~cOptStr()
{
free(value);
}
void cOptStr::Parse(const char *Value)
{
strn0cpy(storage,Value,size);
}
void cOptStr::Backup(void)
{
strn0cpy(value,storage,size);
}
bool cOptStr::Set(void)
{
if(strcmp(value,storage)) { strn0cpy(storage,value,size); return true; }
return false;
}
void cOptStr::Store(const char *PreStr)
{
ScPlugin->SetupStore(FullName(PreStr),storage);
}
void cOptStr::Create(cOsdMenu *menu)
{
menu->Add(new cMenuEditStrItem(tr(title),value,size,allowed));
}
// --- cOptMInt ----------------------------------------------------------------
class cOptMInt : public cOpt {
protected:
int *storage, *value;
int size, mode, len;
public:
cOptMInt(const char *Name, const char *Title, int *Storage, int Size, int Mode);
virtual ~cOptMInt();
virtual void Parse(const char *Value);
virtual void Backup(void);
virtual bool Set(void);
virtual void Store(const char *PreStr);
virtual void Create(cOsdMenu *menu);
};
// mode: 0-Cap 1-Int 2-Hex
cOptMInt::cOptMInt(const char *Name, const char *Title, int *Storage, int Size, int Mode)
:cOpt(Name,Title)
{
storage=Storage; size=Size; mode=Mode; len=sizeof(int)*size;
value=MALLOC(int,size);
}
cOptMInt::~cOptMInt()
{
free(value);
}
void cOptMInt::Parse(const char *Value)
{
memset(storage,0,len);
int i=0;
while(1) {
char *p;
const int c=strtol(Value,&p,mode>1 ? 16:10);
if(p==Value || i>=size) return;
if(c>0) storage[i++]=c;
Value=p;
}
}
void cOptMInt::Backup(void)
{
memcpy(value,storage,len);
}
bool cOptMInt::Set(void)
{
if(memcmp(value,storage,len)) {
memset(storage,0,len);
for(int i=0, k=0; i<size; i++) if(value[i]>0) storage[k++]=value[i];
return true;
}
return false;
}
void cOptMInt::Store(const char *PreStr)
{
char b[256];
int p=0;
for(int i=0; i<size; i++)
if(storage[i] || mode==0) p+=snprintf(b+p,sizeof(b)-p,mode>1 ? "%x ":"%d ",storage[i]);
ScPlugin->SetupStore(FullName(PreStr),p>0?b:0);
}
void cOptMInt::Create(cOsdMenu *menu)
{
for(int i=0; i<size; i++) {
const char *buff=tr(title);
switch(mode) {
case 0: menu->Add(new cMenuEditCapItem(buff,&value[i])); break;
case 1: menu->Add(new cMenuEditIntItem(buff,&value[i],0,65535)); break;
case 2: menu->Add(new cMenuEditHexItem(buff,&value[i],0,65535)); break;
}
if(value[i]==0) break;
}
}
// --- cOpts -------------------------------------------------------------------
cOpts::cOpts(const char *PreStr, int NumOpts)
{
preStr=PreStr;
numOpts=NumOpts; numAdd=0;
if((opts=MALLOC(cOpt *,numOpts))) memset(opts,0,sizeof(cOpt *)*numOpts);
}
cOpts::~cOpts()
{
if(opts) {
for(int i=0; i<numOpts; i++) delete opts[i];
free(opts);
}
}
void cOpts::Add(cOpt *opt)
{
if(opts && numAdd<numOpts) opts[numAdd++]=opt;
}
bool cOpts::Parse(const char *Name, const char *Value)
{
if(opts) {
for(int i=0; i<numAdd; i++)
if(opts[i] && opts[i]->Persistant() && !strcasecmp(Name,opts[i]->Name())) {
opts[i]->Parse(Value);
return true;
}
}
return false;
}
bool cOpts::Store(bool AsIs)
{
bool res=false;
if(opts) {
for(int i=0; i<numAdd; i++)
if(opts[i]) {
if(!AsIs && opts[i]->Set()) res=true;
if(opts[i]->Persistant()) opts[i]->Store(preStr);
}
}
return res;
}
void cOpts::Backup(void)
{
if(opts) {
for(int i=0; i<numAdd; i++)
if(opts[i]) opts[i]->Backup();
}
}
void cOpts::Create(cOsdMenu *menu)
{
if(opts) {
for(int i=0; i<numAdd; i++)
if(opts[i]) opts[i]->Create(menu);
}
}
// --- cSoftCAM ---------------------------------------------------------------
class cSoftCAM {
public:
static bool Load(const char *cfgdir);
static void Shutdown(void);
};
bool cSoftCAM::Load(const char *cfgdir)
{
if(!Feature.KeyFile()) keys.Disable();
if(!Feature.SmartCard()) smartcards.Disable();
cStructLoaders::Load(false);
if(Feature.KeyFile() && keys.Count()<1)
PRINTF(L_GEN_ERROR,"no keys loaded for softcam!");
if(!cSystems::Init(cfgdir)) return false;
srand(time(0));
return true;
}
void cSoftCAM::Shutdown(void)
{
cStructLoaders::Save(true);
cSystems::Clean();
smartcards.Shutdown();
keys.SafeClear();
}
// --- cMenuInfoSc -------------------------------------------------------------
class cMenuInfoSc : public cOsdMenu {
public:
cMenuInfoSc(void);
virtual eOSState ProcessKey(eKeys Key);
};
cMenuInfoSc::cMenuInfoSc(void)
:cOsdMenu(tr("SoftCAM"),25)
{
Add(new cScInfoItem(tr("Current keys:")));
int d=0, n;
do {
n=0;
char *ks;
do {
const char *id;
if((ks=cGlobal::CurrKeyStr(d,n,&id))) {
char buffer[32];
snprintf(buffer,sizeof(buffer)," [%s.%d]",id,n);
Add(new cScInfoItem(buffer,ks));
free(ks);
n++;
}
} while(ks);
d++;
} while(n>0);
if(Feature.KeyFile()) {
Add(new cScInfoItem(tr("Key update status:")));
int fk, nk;
cSystem::KeyStats(fk,nk);
// TRANSLATORS: 2 leading spaces!
Add(new cScInfoItem(tr(" [Seen keys]"),fk));
// TRANSLATORS: 2 leading spaces!
Add(new cScInfoItem(tr(" [New keys]"), nk));
}
Display();
}
eOSState cMenuInfoSc::ProcessKey(eKeys Key)
{
eOSState state=cOsdMenu::ProcessKey(Key);
if(state==osUnknown && Key==kOk) state=osBack;
return state;
}
// --- cMenuInfoCard -----------------------------------------------------------
class cMenuInfoCard : public cMenuText {
private:
int port;
char infoStr[4096];
public:
cMenuInfoCard(int Port);
virtual eOSState ProcessKey(eKeys Key);
};
cMenuInfoCard::cMenuInfoCard(int Port)
:cMenuText(tr("Smartcard"),0,fontFix)
{
port=Port;
smartcards.CardInfo(port,infoStr,sizeof(infoStr));
SetText(infoStr);
SetHelp(tr("Reset card"));
Display();
}
eOSState cMenuInfoCard::ProcessKey(eKeys Key)
{
if(Key==kRed && Interface->Confirm(tr("Really reset card?"))) {
smartcards.CardReset(port);
return osEnd;
}
eOSState state=cMenuText::ProcessKey(Key);
if(state==osUnknown) state=osContinue;
return state;
}
// --- cLogOptItem -------------------------------------------------------------
class cLogOptItem : public cMenuEditBoolItem {
private:
int o;
public:
cLogOptItem(const char *Name, int O, int *val);
int Option(void) { return o; }
};
cLogOptItem::cLogOptItem(const char *Name, int O, int *val)
:cMenuEditBoolItem(Name,val)
{
o=O;
}
// --- cMenuLogMod -------------------------------------------------------------
class cMenuLogMod : public cOsdMenu {
private:
int m;
int v[LOPT_NUM], cfg[LOPT_NUM];
//
void Store(void);
public:
cMenuLogMod(int M);
virtual eOSState ProcessKey(eKeys Key);
};
cMenuLogMod::cMenuLogMod(int M)
:cOsdMenu(tr("Module config"),33)
{
m=M;
Add(new cOsdItem(tr("Reset module to default"),osUser9));
const char *name=cLogging::GetModuleName(LCLASS(m,0));
int o=cLogging::GetModuleOptions(LCLASS(m,0));
if(o>=0) {
for(int i=0; i<LOPT_NUM; i++) {
const char *opt;
if(i==0) opt="enable";
else opt=cLogging::GetOptionName(LCLASS(m,1<<i));
if(opt) {
char buff[64];
snprintf(buff,sizeof(buff),"%s.%s",name,opt);
cfg[i]=(o&(1<<i)) ? 1:0;
v[i]=1;
Add(new cLogOptItem(buff,i,&cfg[i]));
}
else v[i]=0;
}
}
Display();
}
void cMenuLogMod::Store(void)
{
int o=0;
for(int i=0; i<LOPT_NUM; i++) if(v[i] && cfg[i]) o|=(1<<i);
cLogging::SetModuleOptions(LCLASS(m,o));
ScSetup.Store(false);
}
eOSState cMenuLogMod::ProcessKey(eKeys Key)
{
eOSState state=cOsdMenu::ProcessKey(Key);
switch(state) {
case osUser9:
if(Interface->Confirm(tr("Really reset module to default?"))) {
cLogging::SetModuleDefault(LCLASS(m,0));
ScSetup.Store(false); state=osBack;
}
break;
case osContinue:
if(NORMALKEY(Key)==kLeft || NORMALKEY(Key)==kRight) {
cLogOptItem *item=dynamic_cast<cLogOptItem *>(Get(Current()));
if(item) {
int o=item->Option();
cLogging::SetModuleOption(LCLASS(m,1<<o),cfg[o]);
}
}
break;
case osUnknown:
if(Key==kOk) { Store(); state=osBack; }
break;
default:
break;
}
return state;
}
// --- cLogModItem -------------------------------------------------------------
class cLogModItem : public cOsdItem {
private:
int m;
public:
cLogModItem(const char *Name, int M);
int Module(void) { return m; }
};
cLogModItem::cLogModItem(const char *Name, int M)
:cOsdItem(osUnknown)
{
m=M;
char buf[64];
snprintf(buf,sizeof(buf),"%s '%s'...",tr("Module"),Name);
SetText(buf,true);
}
// --- cMenuLogSys -------------------------------------------------------------
class cMenuLogSys : public cOsdMenu {
private:
void Store(void);
public:
cMenuLogSys(void);
virtual eOSState ProcessKey(eKeys Key);
};
cMenuLogSys::cMenuLogSys(void)
:cOsdMenu(tr("Message logging"),33)
{
LogOpts->Backup(); LogOpts->Create(this);
Add(new cOsdItem(tr("Disable ALL modules"),osUser9));
Add(new cOsdItem(tr("Reset ALL modules to default"),osUser8));
for(int m=1; m<LMOD_MAX; m++) {
const char *name=cLogging::GetModuleName(LCLASS(m,0));
if(name)
Add(new cLogModItem(name,m));
}
Display();
}
void cMenuLogSys::Store(void)
{
char *lf=strdup(logcfg.logFilename);
ScSetup.Store(false);
if(!lf || strcmp(lf,logcfg.logFilename))
cLogging::ReopenLogfile();
free(lf);
}
eOSState cMenuLogSys::ProcessKey(eKeys Key)
{
eOSState state=cOsdMenu::ProcessKey(Key);
switch(state) {
case osUser9:
if(Interface->Confirm(tr("Really disable ALL modules?"))) {
for(int m=1; m<LMOD_MAX; m++)
cLogging::SetModuleOption(LCLASS(m,LMOD_ENABLE),false);
Store(); state=osBack;
}
break;
case osUser8:
if(Interface->Confirm(tr("Really reset ALL modules to default?"))) {
for(int m=1; m<LMOD_MAX; m++)
cLogging::SetModuleDefault(LCLASS(m,0));
Store(); state=osBack;
}
break;
case osUnknown:
if(Key==kOk) {
cLogModItem *item=dynamic_cast<cLogModItem *>(Get(Current()));
if(item) state=AddSubMenu(new cMenuLogMod(item->Module()));
else { Store(); state=osBack; }
}
break;
default:
break;
}
return state;
}
// --- cMenuSysOpts -------------------------------------------------------------
class cMenuSysOpts : public cOsdMenu {
public:
cMenuSysOpts(void);
virtual eOSState ProcessKey(eKeys Key);
};
cMenuSysOpts::cMenuSysOpts(void)
:cOsdMenu(tr("Cryptsystem options"),33)
{
for(cOpts *opts=0; (opts=cSystems::GetSystemOpts(opts==0));) {
opts->Backup();
opts->Create(this);
}
Display();
}
eOSState cMenuSysOpts::ProcessKey(eKeys Key)
{
eOSState state=cOsdMenu::ProcessKey(Key);
switch(state) {
case osContinue:
if(NORMALKEY(Key)==kUp || NORMALKEY(Key)==kDown) {
cOsdItem *item=Get(Current());
if(item) item->ProcessKey(kNone);
}
break;
case osUnknown:
if(Key==kOk) { ScSetup.Store(false); state=osBack; }
break;
default:
break;
}
return state;
}
// --- cMenuSetupSc ------------------------------------------------------------
class cMenuSetupSc : public cMenuSetupPage {
private:
char *cfgdir;
protected:
virtual void Store(void);
public:
cMenuSetupSc(const char *CfgDir);
virtual ~cMenuSetupSc();
virtual eOSState ProcessKey(eKeys Key);
};
cMenuSetupSc::cMenuSetupSc(const char *CfgDir)
{
cfgdir=strdup(CfgDir);
SetSection(tr("SoftCAM"));
ScOpts->Backup(); LogOpts->Backup();
for(cOpts *opts=0; (opts=cSystems::GetSystemOpts(opts==0));) opts->Backup();
ScOpts->Create(this);
Add(new cOsdItem(tr("Cryptsystem options..."),osUser5));
Add(new cOsdItem(tr("Message logging..."),osUser6));
if(Feature.SmartCard()) {
char id[IDSTR_LEN];
for(int i=0; smartcards.ListCard(i,id,sizeof(id)); i++) {
char buff[32];
snprintf(buff,sizeof(buff),"%s %d",tr("Smartcard interface"),i);
cScInfoItem *ii;
if(id[0]) ii=new cScInfoItem(buff,id,osUser4);
else ii=new cScInfoItem(buff,tr("(empty)"));
ii->Ident(i);
Add(ii);
}
}
Add(new cOsdItem(tr("Status information..."),osUser8));
Add(new cOsdItem(tr("Flush ECM cache"),osUser7));
Add(new cOsdItem(tr("Reload files"),osUser9));
}
cMenuSetupSc::~cMenuSetupSc()
{
free(cfgdir);
}
void cMenuSetupSc::Store(void)
{
ScSetup.Store(false);
}
eOSState cMenuSetupSc::ProcessKey(eKeys Key)
{
eOSState state = cOsdMenu::ProcessKey(Key);
switch(state) {
case osUser4:
if(Feature.SmartCard()) {
cScInfoItem *ii=dynamic_cast<cScInfoItem *>(Get(Current()));
if(ii) return(AddSubMenu(new cMenuInfoCard(ii->Ident())));
}
state=osContinue;
break;
case osUser7:
state=osContinue;
if(Interface->Confirm(tr("Really flush ECM cache?"))) {
ecmcache.Flush();
state=osEnd;
}
break;
case osUser8:
return AddSubMenu(new cMenuInfoSc);
case osUser6:
return AddSubMenu(new cMenuLogSys);
case osUser5:
return AddSubMenu(new cMenuSysOpts);
case osUser9:
state=osContinue;
if(!cGlobal::Active(true)) {
if(Interface->Confirm(tr("Really reload files?"))) {
Store();
cSoftCAM::Load(cfgdir);
state=osEnd;
}
}
else
Skins.Message(mtError,tr("Active! Can't reload files now"));
break;
case osContinue:
if(NORMALKEY(Key)==kUp || NORMALKEY(Key)==kDown) {
cOsdItem *item=Get(Current());
if(item) item->ProcessKey(kNone);
}
break;
case osUnknown:
if(Key==kOk) { Store(); state=osBack; }
break;
default:
break;
}
return state;
}
// --- cScSetup ---------------------------------------------------------------
cScSetup ScSetup;
cScSetup::cScSetup(void)
{
AutoUpdate=1;
memset(ScCaps,0,sizeof(ScCaps));
ScCaps[0]=1;
ScCaps[1]=2;
ConcurrentFF=0;
LocalPriority=0;
ForceTransfer=1;
PrestartAU=0;
SuperKeys=0;
EcmCache=0;
DeCsaTsBuffSize=4;
}
void cScSetup::Check(void)
{
if(AutoUpdate==0)
PRINTF(L_GEN_WARN,"Keys updates (AU) are disabled.");
for(int i=0; i<MAXSCCAPS; i++)
if(ScCaps[i]>=16) {
PRINTF(L_GEN_WARN,"ScCaps contains unusual value. Check your config! (You can ignore this message if you have more than 16 dvb cards in your system ;)");
break;
}
PRINTF(L_CORE_LOAD,"** Plugin config:");
PRINTF(L_CORE_LOAD,"** Key updates (AU) are %s (%sprestart)",AutoUpdate?(AutoUpdate==1?"enabled (active CAIDs)":"enabled (all CAIDs)"):"DISABLED",PrestartAU?"":"no ");
PRINTF(L_CORE_LOAD,"** Local systems %stake priority over cached remote",LocalPriority?"":"DON'T ");
PRINTF(L_CORE_LOAD,"** Concurrent FF recordings are %sallowed",ConcurrentFF?"":"NOT ");
PRINTF(L_CORE_LOAD,"** %sorce transfermode with digital audio",ForceTransfer?"F":"DON'T f");
PRINTF(L_CORE_LOAD,"** ECM cache is set to %s",EcmCache ? (EcmCache==1?"READ-ONLY":"DISABLED"):"enabled");
PRINTF(L_CORE_LOAD,"** TsBufferSize is %d MB",DeCsaTsBuffSize);
LBSTART(L_CORE_LOAD);
LBPUT("** ScCaps are"); for(int i=0; i<MAXSCCAPS ; i++) LBPUT(" %d",ScCaps[i]);