From: leslie Date: Tue, 1 Jan 2008 20:39:00 +0000 (+0100) Subject: trigger ExternalAU on wrong key, improve logging X-Git-Tag: 0.8.7~29 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=026cb6418e2ce24e060cd7819c01b4c24e9f22ba;p=sasc-ng.git trigger ExternalAU on wrong key, improve logging --- diff --git a/data.c b/data.c index 332ec0b..84cce8f 100644 --- 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 2650064..34bc84a 100644 --- 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 { @@ -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); diff --git a/system.c b/system.c index 8b77b91..6bc52e1 100644 --- 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 -------------------------------------------------------------- diff --git a/system.h b/system.h index 4841ec9..05df7c3 100644 --- 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;