From: mirv Date: Thu, 3 Jan 2008 17:41:14 +0000 (+0100) Subject: switch KID files to new loading code X-Git-Tag: 0.9.0~64 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=03c436ef2001587569d269b3b303696f20b9b9cc;p=sasc-ng.git switch KID files to new loading code --- diff --git a/system-common.h b/system-common.h index 396a0b7..c79ecd6 100644 --- a/system-common.h +++ b/system-common.h @@ -88,6 +88,19 @@ public: // ---------------------------------------------------------------- +template class cCardInfos : public cStructList { +public: + cCardInfos(const char *Type, const char *Filename, bool rw):cStructList(Type,Filename,rw,true,true,false) {} + virtual cStructItem *ParseLine(char *line) + { + T *k=new T; + if(k && !k->Parse(line)) { delete k; k=0; } + return k; + } + }; + +// ---------------------------------------------------------------- + class cSystemScCore : public cSystem { private: int scId; diff --git a/system.h b/system.h index 05df7c3..03283e3 100644 --- a/system.h +++ b/system.h @@ -20,15 +20,10 @@ #ifndef ___SYSTEM_H #define ___SYSTEM_H -#include -#include - #include #include "data.h" #include "misc.h" -#include "log-core.h" -#include "i18n.h" // ---------------------------------------------------------------- @@ -192,63 +187,6 @@ public: // ---------------------------------------------------------------- -template class cCardInfos : public cSimpleList, public cLoader, cConfRead { -private: - const char *sysname; -public: - cCardInfos(const char *id):cLoader(id) {} - virtual ~cCardInfos() {} - bool HaveCards(void) { return (this->Count()!=0); } - bool Load(const char *cfgdir, const char *SysName, const char *kidName) - { - sysname=SysName; - this->Clear(); - char type[32]; - snprintf(type,sizeof(type),"%s card infos",SysName); - cString cname=AddDirectory(cfgdir,kidName); - ConfRead(type,cname,true); - PRINTF(L_CORE_LOAD,"loaded %d %s cards from %s",this->Count(),SysName,*cname); - return HaveCards(); - } - virtual bool ParseLine(const char *line, bool fromCache) - { - T *k=new T; - if(k) { - if(k->Parse((char *)line)) { - if(!fromCache) { Add(k); k=0; } - else { - T *o=this->First(); - while(o) { - if(o->Cmp(k)) { - Add(k,o); k->Updated(); k=0; - Del(o); - break; - } - o=this->Next(o); - } - } - } - delete k; - return true; - } - PRINTF(L_GEN_ERROR,"not enough memory for %s card infos!",sysname); - return false; - } - virtual bool Save(FILE *f) - { - bool res=true; - T *k=this->First(); - while(k) { - if(k->IsUpdated() && !k->Save(f)) { res=false; break; } - k=this->Next(k); - } - Modified(!res); - return res; - } - }; - -// ---------------------------------------------------------------- - struct Cache; class cMsgCache { diff --git a/systems/irdeto/irdeto.c b/systems/irdeto/irdeto.c index 9f18073..0de55da 100644 --- a/systems/irdeto/irdeto.c +++ b/systems/irdeto/irdeto.c @@ -17,7 +17,7 @@ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html */ -#include +#include #include #include "system-common.h" @@ -48,27 +48,15 @@ static cPlainKeyTypeReg KeyReg; // -- cIrdCardInfo ------------------------------------------------------------- -class cIrdCardInfo : public cProviderIrdeto, public cCardIrdeto { -private: - bool updated; +class cIrdCardInfo : public cStructItem, public cProviderIrdeto, public cCardIrdeto { public: unsigned char PMK[8], HMK[10]; bool haveHMK; // - cIrdCardInfo(void); bool Parse(const char *line); - bool Save(FILE *f); - bool Update(unsigned char *pmk, unsigned char *id); - bool IsUpdated(void) { return updated; } - void Updated(void) { updated=true; } - bool Cmp(cIrdCardInfo *ci); + virtual cString ToString(bool hide=false); }; -cIrdCardInfo::cIrdCardInfo(void) -{ - updated=false; -} - bool cIrdCardInfo::Parse(const char *line) { haveHMK=false; @@ -78,51 +66,42 @@ bool cIrdCardInfo::Parse(const char *line) GetHex(line,PMK,sizeof(PMK)); } -bool cIrdCardInfo::Save(FILE *f) +cString cIrdCardInfo::ToString(bool hide) { char s1[20], s2[20], s3[20], s4[20]; - fprintf(f,"%s %s %02x %s %s\n", + return cString::sprintf("%s %s %02x %s %s", HexStr(s1,hexSer,sizeof(hexSer)),HexStr(s2,HMK,sizeof(HMK)),provBase, HexStr(s3,provId,sizeof(provId)),HexStr(s4,PMK,sizeof(PMK))); - return ferror(f)==0; -} - -bool cIrdCardInfo::Cmp(cIrdCardInfo *ci) -{ - return (!memcmp(hexSer,ci->hexSer,sizeof(hexSer)) && - !memcmp(HMK,ci->HMK,sizeof(HMK))); -} - -bool cIrdCardInfo::Update(unsigned char *pmk, unsigned char *id) -{ - bool res=false; - char str[20], str2[12]; - if(memcmp(PMK,pmk,sizeof(PMK))) { - PRINTF(L_GEN_INFO,"new PMK for I card %s: %s",HexStr(str2,hexSer,sizeof(hexSer)),KeyStr(str,pmk)); - memcpy(PMK,pmk,sizeof(PMK)); - Updated(); res=true; - } - if(id && memcmp(provId,id,sizeof(provId))) { - PRINTF(L_GEN_INFO,"new PrvID for I card %s: %s",HexStr(str2,hexSer,sizeof(hexSer)),HexStr(str,id,sizeof(provId))); - memcpy(provId,id,sizeof(provId)); - Updated(); res=true; - } - return res; } // -- cIrdCardInfos ------------------------------------------------------------ class cIrdCardInfos : public cCardInfos { public: - cIrdCardInfos(void):cCardInfos(SYSTEM_NAME) {} - bool Update(cIrdCardInfo *ci, unsigned char *pmk, unsigned char *id); + cIrdCardInfos(void); + bool Update(cIrdCardInfo *ci, const unsigned char *pmk, const unsigned char *id); }; static cIrdCardInfos Icards; -bool cIrdCardInfos::Update(cIrdCardInfo *ci, unsigned char *pmk, unsigned char *id) +cIrdCardInfos::cIrdCardInfos(void) +:cCardInfos("Irdeto cards","Ird-Beta.KID",true) +{} + +bool cIrdCardInfos::Update(cIrdCardInfo *ci, const unsigned char *pmk, const unsigned char *id) { - bool res=ci->Update(pmk,id); + bool res=false; + char str[20], str2[12]; + if(memcmp(ci->PMK,pmk,sizeof(ci->PMK))) { + PRINTF(L_GEN_INFO,"new PMK for I card %s: %s",HexStr(str2,ci->hexSer,sizeof(ci->hexSer)),KeyStr(str,pmk)); + memcpy(ci->PMK,pmk,sizeof(ci->PMK)); + res=true; + } + if(id && memcmp(ci->provId,id,sizeof(ci->provId))) { + PRINTF(L_GEN_INFO,"new PrvID for I card %s: %s",HexStr(str2,ci->hexSer,sizeof(ci->hexSer)),HexStr(str,id,sizeof(ci->provId))); + memcpy(ci->provId,id,sizeof(ci->provId)); + res=true; + } if(res) Modified(); return res; } @@ -490,7 +469,6 @@ public: cSystemLinkIrd(void); virtual bool CanHandle(unsigned short SysId); virtual cSystem *Create(void) { return new cSystemIrd; } - virtual bool Init(const char *cfgdir); }; static cSystemLinkIrd staticInit; @@ -506,9 +484,3 @@ bool cSystemLinkIrd::CanHandle(unsigned short SysId) SysId&=SYSTEM_MASK; return SYSTEM_CAN_HANDLE(SysId); } - -bool cSystemLinkIrd::Init(const char *cfgdir) -{ - Icards.Load(cfgdir,SYSTEM_NAME,"Ird-Beta.KID"); - return true; -} diff --git a/systems/seca/seca.c b/systems/seca/seca.c index bae282a..b22f7f0 100644 --- a/systems/seca/seca.c +++ b/systems/seca/seca.c @@ -17,7 +17,6 @@ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html */ -#include #include #include #include @@ -168,17 +167,14 @@ cString cPlainKeySeca::PrintKeyNr(void) // -- cSecaCardInfo ------------------------------------------------------------ -class cSecaCardInfo : public cProviderSeca { +class cSecaCardInfo : public cStructItem, public cProviderSeca { private: int len; public: unsigned char key[16]; // bool Parse(const char *line); - bool Save(FILE *f) { return true; } - bool IsUpdated(void) { return false; } - void Updated(void) {} - bool Cmp(cSecaCardInfo *ci) { return false; } + virtual cString ToString(bool hide=false) { return ""; } int KeySize(void) { return len; } }; @@ -194,7 +190,7 @@ bool cSecaCardInfo::Parse(const char *line) class cSecaCardInfos : public cCardInfos { public: - cSecaCardInfos(void):cCardInfos(SYSTEM_NAME) {} + cSecaCardInfos(void):cCardInfos("Seca cards","Seca.KID",false) {} }; static cSecaCardInfos Scards; @@ -1633,7 +1629,6 @@ public: cSystemLinkSeca(void); virtual bool CanHandle(unsigned short SysId); virtual cSystem *Create(void) { return new cSystemSeca; } - virtual bool Init(const char *cfgdir); }; static cSystemLinkSeca staticInit; @@ -1649,9 +1644,3 @@ bool cSystemLinkSeca::CanHandle(unsigned short SysId) SysId&=SYSTEM_MASK; return SYSTEM_CAN_HANDLE(SysId); } - -bool cSystemLinkSeca::Init(const char *cfgdir) -{ - Scards.Load(cfgdir,SYSTEM_NAME,"Seca.KID"); - return true; -} diff --git a/systems/viaccess/viaccess.c b/systems/viaccess/viaccess.c index cee8c8b..28e7475 100644 --- a/systems/viaccess/viaccess.c +++ b/systems/viaccess/viaccess.c @@ -17,14 +17,17 @@ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html */ -#include +#include #include +#include -#include "viaccess.h" -#include "tps.h" #include "system-common.h" #include "misc.h" #include "parse.h" +#include "log-core.h" + +#include "viaccess.h" +#include "tps.h" #include "log-viaccess.h" #define SYSTEM_NAME "Viaccess" @@ -122,15 +125,12 @@ cString cPlainKeyVia::PrintKeyNr(void) // -- cViaccessCardInfo -------------------------------------------------------- -class cViaccessCardInfo : public cProviderViaccess, public cCardViaccess { +class cViaccessCardInfo : public cStructItem, public cProviderViaccess, public cCardViaccess { public: unsigned char keyno, key[8]; // bool Parse(const char *line); - bool Save(FILE *f) { return true; } - bool IsUpdated(void) { return false; } - void Updated(void) {} - bool Cmp(cViaccessCardInfo *ci) { return false; } + virtual cString ToString(bool hide=false) { return ""; } }; bool cViaccessCardInfo::Parse(const char *line) @@ -146,7 +146,7 @@ bool cViaccessCardInfo::Parse(const char *line) class cViaccessCardInfos : public cCardInfos { public: - cViaccessCardInfos(void):cCardInfos(SYSTEM_NAME) {} + cViaccessCardInfos(void):cCardInfos("Viaccess cards","Viaccess.KID",false) {} }; static cViaccessCardInfos Vcards; @@ -525,7 +525,6 @@ public: cSystemLinkViaccess(void); virtual bool CanHandle(unsigned short SysId); virtual cSystem *Create(void) { return new cSystemViaccess; } - virtual bool Init(const char *cfgdir); }; static cSystemLinkViaccess staticInit; @@ -541,9 +540,3 @@ bool cSystemLinkViaccess::CanHandle(unsigned short SysId) SysId&=SYSTEM_MASK; return SYSTEM_CAN_HANDLE(SysId); } - -bool cSystemLinkViaccess::Init(const char *cfgdir) -{ - Vcards.Load(cfgdir,SYSTEM_NAME,"Viaccess.KID"); - return true; -}