From: mirv <unknown>
Date: Fri, 4 Jan 2008 18:06:45 +0000 (+0100)
Subject: switch smartcard.conf to new loader code
X-Git-Tag: 0.9.0~55
X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=4296940689dd0086b140d87f92578b149110a55d;p=sasc-ng.git

switch smartcard.conf to new loader code
---

diff --git a/cam.c b/cam.c
index a400200..4030e72 100644
--- a/cam.c
+++ b/cam.c
@@ -575,7 +575,7 @@ class cEcmData : public cEcmInfo {
 public:
   cEcmData(void):cEcmInfo() {}
   cEcmData(cEcmInfo *e):cEcmInfo(e) {}
-  virtual cString ToString(bool hide=false);
+  virtual cString ToString(bool hide);
   bool Parse(const char *buf);
   };
 
diff --git a/data.c b/data.c
index 86c6c15..7427078 100644
--- a/data.c
+++ b/data.c
@@ -169,7 +169,6 @@ bool cStructItem::Save(FILE *f)
 class cCommentItem : public cStructItem {
 public:
   cCommentItem(void);
-  virtual cString ToString(bool hide=false) { return ""; }
   };
 
 cCommentItem::cCommentItem(void)
diff --git a/data.h b/data.h
index 26ba4b6..1e7a879 100644
--- a/data.h
+++ b/data.h
@@ -78,7 +78,7 @@ protected:
 public:
   cStructItem(void);
   virtual ~cStructItem();
-  virtual cString ToString(bool hide=false)=0;
+  virtual cString ToString(bool hide) { return ""; }
   bool Save(FILE *f);
   //
   void SetComment(const char *com);
@@ -272,7 +272,7 @@ public:
   //
   cPlainKey(bool CanSupersede);
   virtual bool Parse(const char *line)=0;
-  virtual cString ToString(bool hide=false);
+  virtual cString ToString(bool hide);
   virtual bool Cmp(void *Key, int Keylen)=0;
   virtual bool Cmp(cPlainKey *k)=0;
   virtual void Get(void *mem)=0;
diff --git a/sc.c b/sc.c
index 001fae5..4fe2901 100644
--- a/sc.c
+++ b/sc.c
@@ -1006,12 +1006,11 @@ bool cScSetup::Ignore(unsigned short caid)
 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;
-  if(Feature.SmartCard()) smartcards.LoadData(cfgdir);
   return true;
 }
 
diff --git a/smartcard.c b/smartcard.c
index 50d43a3..14cd9be 100644
--- a/smartcard.c
+++ b/smartcard.c
@@ -1107,6 +1107,7 @@ static const char *serModes[] = { 0,"8e2","8o2","8n2" };
 
 cSmartCards::cSmartCards(void)
 :cThread("SmartcardWatcher")
+,cStructList<cSmartCardData>("smartcard data",DATAFILE,SL_MISSINGOK|SL_WATCH)
 {
   for(int i=0 ; i<MAX_PORTS ; i++) ports[i].Serial=0;
   firstRun=true;
@@ -1138,8 +1139,8 @@ void cSmartCards::Shutdown(void)
       ports[i].Serial=0;
       }
     }
-  dataList.Clear();
   mutex.Unlock();
+  ListLock(true); Clear(); ListUnlock();
 }
 
 bool cSmartCards::AddPort(const char *devName, bool invCD, bool invRST, int clock)
@@ -1173,41 +1174,28 @@ bool cSmartCards::AddPort(const char *devName, bool invCD, bool invRST, int cloc
   return false;
 }
 
-void cSmartCards::LoadData(const char *cfgdir)
-{
-  mutex.Lock();
-  dataList.Clear();
-  ConfRead("smartcard data",AddDirectory(cfgdir,DATAFILE),true);
-  mutex.Unlock();
-}
-
-bool cSmartCards::ParseLine(const char *line, bool fromCache)
+cStructItem *cSmartCards::ParseLine(char *line)
 {
   char *r=index(line,':');
-  if(!r) return false;
-  for(cSmartCardLink *scl=first; scl; scl=scl->next) {
-    if(!strncasecmp(scl->name,line,r-line)) {
-      cSmartCardData *scd=scl->CreateData();
-      if(scd && scd->Parse(r+1)) {
-        dataList.Add(scd);
-        break;
-        }
-      else {
+  if(r)
+    for(cSmartCardLink *scl=first; scl; scl=scl->next)
+      if(!strncasecmp(scl->name,line,r-line)) {
+        cSmartCardData *scd=scl->CreateData();
+        if(scd && scd->Parse(r+1)) return scd;
         delete scd;
-        return false;
+        break;
         }
-      }
-    }
-  return true;
+  return 0;
 }
 
 cSmartCardData *cSmartCards::FindCardData(cSmartCardData *param)
 {
-  cMutexLock lock(&mutex);
-  for(cSmartCardData *cd=dataList.First(); cd; cd=dataList.Next(cd))
-    if(cd->ident==param->ident && cd->Matches(param))
-      return cd;
-  return 0;
+  ListLock(false);
+  cSmartCardData *cd;
+  for(cd=First(); cd; cd=Next(cd))
+    if(cd->ident==param->ident && cd->Matches(param)) break;
+  ListUnlock();
+  return cd;
 }
 
 bool cSmartCards::HaveCard(int id)
diff --git a/smartcard.h b/smartcard.h
index 5c87de3..184cef4 100644
--- a/smartcard.h
+++ b/smartcard.h
@@ -155,7 +155,7 @@ public:
 
 // ----------------------------------------------------------------
 
-class cSmartCardData : public cSimpleItem {
+class cSmartCardData : public cStructItem {
 friend class cSmartCards;
 protected:
   int ident;
@@ -194,7 +194,7 @@ struct Port {
   struct Atr Atr;
   };
 
-class cSmartCards : private cThread, private cConfRead {
+class cSmartCards : private cThread, public cStructList<cSmartCardData> {
 friend class cSmartCardLink;
 private:
   static cSmartCardLink *first;
@@ -202,7 +202,6 @@ private:
   cCondVar cond;
   struct Port ports[MAX_PORTS];
   bool firstRun;
-  cSimpleList<cSmartCardData> dataList;
   //
   static void Register(cSmartCardLink *scl);
   bool CardInserted(cSerial *ser);
@@ -212,7 +211,7 @@ private:
   void SetPort(struct Port *port, cSmartCard *sc, int id, bool dead);
 protected:
   virtual void Action(void);
-  virtual bool ParseLine(const char *line, bool fromCache);
+  virtual cStructItem *ParseLine(char *line);
 public:
   cSmartCards(void);
   void Shutdown(void);
@@ -224,7 +223,6 @@ public:
   // to be called ONLY from frontend thread!
   bool AddPort(const char *devName, bool invCD, bool invRST, int clock);
   void LaunchWatcher(void);
-  void LoadData(const char *cfgdir);
   bool ListCard(int num, char *str, int len);
   bool CardInfo(int num, char *str, int len);
   void CardReset(int num);
diff --git a/system.c b/system.c
index 920217c..36e83c6 100644
--- a/system.c
+++ b/system.c
@@ -239,7 +239,7 @@ void cSystem::CheckECMResult(const cEcmInfo *ecm, const unsigned char *data, boo
 void cSystem::KeyOK(cPlainKey *pk)
 {
   if(lastkey.NotLast(pk->type,pk->id,pk->keynr)) {
-    strn0cpy(currentKeyStr,pk->ToString(),sizeof(currentKeyStr));
+    strn0cpy(currentKeyStr,pk->ToString(false),sizeof(currentKeyStr));
     PRINTF(L_CORE_ECM,"system: using key %s",*pk->ToString(true));
     doLog=true;
     }
diff --git a/systems/irdeto/irdeto.c b/systems/irdeto/irdeto.c
index 543ccec..9414976 100644
--- a/systems/irdeto/irdeto.c
+++ b/systems/irdeto/irdeto.c
@@ -54,7 +54,7 @@ public:
   bool haveHMK;
   //
   bool Parse(const char *line);
-  virtual cString ToString(bool hide=false);
+  virtual cString ToString(bool hide);
   };
 
 bool cIrdCardInfo::Parse(const char *line)
diff --git a/systems/seca/seca.c b/systems/seca/seca.c
index afd5e55..b91650d 100644
--- a/systems/seca/seca.c
+++ b/systems/seca/seca.c
@@ -174,7 +174,6 @@ public:
   unsigned char key[16];
   //
   bool Parse(const char *line);
-  virtual cString ToString(bool hide=false) { return ""; }
   int KeySize(void) { return len; }
   };
 
diff --git a/systems/viaccess/viaccess.c b/systems/viaccess/viaccess.c
index cd7a316..d083894 100644
--- a/systems/viaccess/viaccess.c
+++ b/systems/viaccess/viaccess.c
@@ -130,7 +130,6 @@ public:
   unsigned char keyno, key[8];
   //
   bool Parse(const char *line);
-  virtual cString ToString(bool hide=false) { return ""; }
   };
 
 bool cViaccessCardInfo::Parse(const char *line)