]> www.vanbest.org Git - sasc-ng.git/commitdiff
switch KID files to new loading code
authormirv <unknown>
Thu, 3 Jan 2008 17:41:14 +0000 (18:41 +0100)
committermirv <unknown>
Thu, 3 Jan 2008 17:41:14 +0000 (18:41 +0100)
system-common.h
system.h
systems/irdeto/irdeto.c
systems/seca/seca.c
systems/viaccess/viaccess.c

index 396a0b779db5bb952ed312a259c24e7ac449165a..c79ecd63226de27f9c3d57025106f850077d7947 100644 (file)
@@ -88,6 +88,19 @@ public:
 
 // ----------------------------------------------------------------
 
+template<class T> class cCardInfos : public cStructList<T> {
+public:
+  cCardInfos(const char *Type, const char *Filename, bool rw):cStructList<T>(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;
index 05df7c37bff17c3a246af041d128a76e873e2126..03283e30996eb914269089bb2d9f9c6e4aad2322 100644 (file)
--- a/system.h
+++ b/system.h
 #ifndef ___SYSTEM_H
 #define ___SYSTEM_H
 
-#include <stdio.h>
-#include <ctype.h>
-
 #include <vdr/tools.h>
 
 #include "data.h"
 #include "misc.h"
-#include "log-core.h"
-#include "i18n.h"
 
 // ----------------------------------------------------------------
 
@@ -192,63 +187,6 @@ public:
 
 // ----------------------------------------------------------------
 
-template<class T> class cCardInfos : public cSimpleList<T>, 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 {
index 9f180730db0ea5e39d64f86747b97587e807b244..0de55da42d5dbf5fee500b06a2fd53d5cca5cc9d 100644 (file)
@@ -17,7 +17,7 @@
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  */
 
-#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "system-common.h"
@@ -48,27 +48,15 @@ static cPlainKeyTypeReg<cPlainKeyStd,'I',false> 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<cIrdCardInfo> {
 public:
-  cIrdCardInfos(void):cCardInfos<cIrdCardInfo>(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<cIrdCardInfo>("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;
-}
index bae282adf44ad7b2c17c70e2b9c392964ffea4a3..b22f7f00f553c6cc2963fc9cf81b7c1bc7cfe2b7 100644 (file)
@@ -17,7 +17,6 @@
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  */
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
@@ -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<cSecaCardInfo> {
 public:
-  cSecaCardInfos(void):cCardInfos<cSecaCardInfo>(SYSTEM_NAME) {}
+  cSecaCardInfos(void):cCardInfos<cSecaCardInfo>("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;
-}
index cee8c8bd8303871d209365040bc54abe972f2607..28e7475c1f9a46de1b360969b708b6fb3e2b17b6 100644 (file)
  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
  */
 
-#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
 
-#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<cViaccessCardInfo> {
 public:
-  cViaccessCardInfos(void):cCardInfos<cViaccessCardInfo>(SYSTEM_NAME) {}
+  cViaccessCardInfos(void):cCardInfos<cViaccessCardInfo>("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;
-}