]> www.vanbest.org Git - sasc-ng.git/commitdiff
trigger ExternalAU on wrong key, improve logging
authorleslie <unknown>
Tue, 1 Jan 2008 20:39:00 +0000 (21:39 +0100)
committerleslie <unknown>
Tue, 1 Jan 2008 20:39:00 +0000 (21:39 +0100)
data.c
data.h
system.c
system.h

diff --git a/data.c b/data.c
index 332ec0b40848672e83d2d03e6c02f33958542a4d..84cce8f3aab064190d2065e01ef8060d379e8344 100644 (file)
--- a/data.c
+++ b/data.c
@@ -629,6 +629,22 @@ cPlainKeyType::cPlainKeyType(int Type, bool Super)
   cPlainKeys::Register(this,Super);
 }
 
+// -- cLastKey -----------------------------------------------------------------
+
+cLastKey::cLastKey(void)
+{
+  lastType=lastId=lastKeynr=-1;
+}
+
+bool cLastKey::NotLast(int Type, int Id, int Keynr)
+{
+  if(lastType!=Type || lastId!=Id || lastKeynr!=Keynr) {
+    lastType=Type; lastId=Id; lastKeynr=Keynr;
+    return true;
+    }
+  return false;
+}
+
 // -- cPlainKeys ---------------------------------------------------------------
 
 const char *externalAU=0;
@@ -651,17 +667,17 @@ void cPlainKeys::Register(cPlainKeyType *pkt, bool Super)
   first=pkt;
 }
 
+void cPlainKeys::Trigger(int Type, int Id, int Keynr)
+{
+  if(lastkey.NotLast(Type,Id,Keynr))
+    PRINTF(L_CORE_AUEXTERN,"triggered from findkey (%s)",*KeyString(Type,Id,Keynr));
+  ExternalUpdate();
+}
+
 cPlainKey *cPlainKeys::FindKey(int Type, int Id, int Keynr, int Size, cPlainKey *key)
 {
   key=FindKeyNoTrig(Type,Id,Keynr,Size,key);
-  if(!key) {
-    static int lastType=-1, lastId=-1, lastKeynr=-1;
-    if(externalAU && (lastType!=Type || lastId!=Id || lastKeynr!=Keynr)) {
-      PRINTF(L_CORE_AUEXTERN,"triggered from findkey (type=%X id=%X keynr=%X)",Type,Id,Keynr);
-      lastType=Type; lastId=Id; lastKeynr=Keynr;
-      }
-    ExternalUpdate();
-    }
+  if(!key) Trigger(Type,Id,Keynr);
   return key;
 }
 
@@ -808,6 +824,16 @@ cPlainKey *cPlainKeys::NewFromType(int type)
   return pkt->Create();
 }
 
+cString cPlainKeys::KeyString(int Type, int Id, int Keynr)
+{
+  cPlainKey *pk=NewFromType(Type);
+  if(pk) {
+    pk->type=Type; pk->id=Id; pk->keynr=Keynr;
+    return cString::sprintf("%c %.*X %s",Type,pk->IdSize(),Id,*pk->PrintKeyNr());
+    }
+  return "unknown";
+}
+
 bool cPlainKeys::ParseLine(const char *line, bool fromCache)
 {
   char *s=skipspace(line);
diff --git a/data.h b/data.h
index 26500648473884248bb436d7e8f1575c09c29921..34bc84a272f106d2cceb872308bdaa4337f79c5c 100644 (file)
--- a/data.h
+++ b/data.h
@@ -240,6 +240,16 @@ public:
 
 // ----------------------------------------------------------------
 
+class cLastKey {
+private:
+  int lastType, lastId, lastKeynr;
+public:
+  cLastKey(void);
+  bool NotLast(int Type, int Id, int Keynr);
+  };
+
+// ----------------------------------------------------------------
+
 extern const char *externalAU;
 
 class cPlainKeys : public cLoader, private cConfRead, private cThread, public cSimpleList<cPlainKey> {
@@ -248,6 +258,7 @@ private:
   static cPlainKeyType *first;
   cPlainKey *mark;
   cTimeMs trigger, last;
+  cLastKey lastkey;
   //
   static void Register(cPlainKeyType *pkt, bool Super);
   cPlainKey *NewFromType(int type);
@@ -262,6 +273,8 @@ public:
   virtual bool ParseLine(const char *line, bool Au);
   cPlainKey *FindKey(int Type, int Id, int Keynr, int Size, cPlainKey *key=0);
   cPlainKey *FindKeyNoTrig(int Type, int Id, int Keynr, int Size, cPlainKey *key=0);
+  void Trigger(int Type, int Id, int Keynr);
+  cString KeyString(int Type, int Id, int Keynr);
   bool NewKey(int Type, int Id, int Keynr, void *Key, int Keylen);
   bool NewKeyParse(const char *line);
   void HouseKeeping(void);
index 8b77b91922fd7ef44ab62ca74153e29d9e5f6779..6bc52e11f52d1bd9eee4826f547844bb19f03d31 100644 (file)
--- a/system.c
+++ b/system.c
@@ -95,7 +95,7 @@ int cSystem::newKeys=0;
 cSystem::cSystem(const char *Name, int Pri)
 {
   name=Name; pri=Pri;
-  lastType=0; currentKeyStr[0]=0; doLog=true; cardNum=-1; logecm=0;
+  currentKeyStr[0]=0; doLog=true; cardNum=-1; logecm=0;
   check=new struct EcmCheck;
   memset(check,0,sizeof(struct EcmCheck));
   // default config
@@ -237,8 +237,7 @@ void cSystem::CheckECMResult(const cEcmInfo *ecm, const unsigned char *data, boo
 
 void cSystem::KeyOK(cPlainKey *pk)
 {
-  if(pk->type!=lastType || pk->id!=lastId || pk->keynr!=lastKeynr) {
-    lastType=pk->type; lastId=pk->id; lastKeynr=pk->keynr;
+  if(lastkey.NotLast(pk->type,pk->id,pk->keynr)) {
     strn0cpy(currentKeyStr,pk->ToString(),sizeof(currentKeyStr));
     PRINTF(L_CORE_ECM,"system: using key %s",*pk->ToString(true));
     doLog=true;
@@ -253,11 +252,9 @@ void cSystem::KeyOK(const char *txt)
 
 void cSystem::KeyFail(int type, int id, int keynr)
 {
-  if(type!=lastType || id!=lastId || keynr!=lastKeynr) {
-    lastType=type; lastId=id; lastKeynr=keynr;
-    if(doLog)
-      PRINTF(L_CORE_ECM,"system: no key found for %c %.2x %.2x",lastType,lastId,lastKeynr);
-    }
+  keys.Trigger(type,id,keynr);
+  if(lastkey.NotLast(type,id,keynr) && doLog)
+    PRINTF(L_CORE_ECM,"system: no key found for %s",*keys.KeyString(type,id,keynr));
 }
 
 // -- cSystemLink --------------------------------------------------------------
index 4841ec996452fe5d846abec9e967ac98e6a9bd48..05df7c37bff17c3a246af041d128a76e873e2126 100644 (file)
--- a/system.h
+++ b/system.h
@@ -98,7 +98,7 @@ friend class cKeySnoop;
 private:
   static int foundKeys, newKeys;
   int pri, cardNum;
-  int lastType, lastId, lastKeynr;
+  cLastKey lastkey;
   char *lastTxt;
   char currentKeyStr[48];
   struct EcmCheck *check;