From: mirv Date: Thu, 3 Jan 2008 19:43:49 +0000 (+0100) Subject: switch ECM cache to new loading code (now ecm.cache) X-Git-Tag: 0.9.0~63 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=527740009f41345c50871ed45469f6535c9c86eb;p=sasc-ng.git switch ECM cache to new loading code (now ecm.cache) --- diff --git a/cam.c b/cam.c index 0474603..bd5e178 100644 --- a/cam.c +++ b/cam.c @@ -61,6 +61,8 @@ #define MAX_ECM_HOLD 15000 // delay before an idle handler stops processing #define CAID_TIME 300000 // time between caid scans +#define ECMCACHE_FILE "ecm.cache" + #define L_HEX 2 #define L_HEX_ECM LCLASS(L_HEX,2) #define L_HEX_EMM LCLASS(L_HEX,4) @@ -570,29 +572,13 @@ void cLogger::Process(cPidFilter *filter, unsigned char *data, int len) // -- cEcmData ----------------------------------------------------------------- class cEcmData : public cEcmInfo { -private: - bool del; public: - cEcmData(void); - cEcmData(cEcmInfo *e); - bool Save(FILE *f); + cEcmData(void):cEcmInfo() {} + cEcmData(cEcmInfo *e):cEcmInfo(e) {} + virtual cString ToString(bool hide=false); bool Parse(const char *buf); - void Delete(void) { del=true; } - bool IsDeleted(void) const { return del; } }; -cEcmData::cEcmData(void) -:cEcmInfo() -{ - del=false; -} - -cEcmData::cEcmData(cEcmInfo *e) -:cEcmInfo(e) -{ - del=false; -} - bool cEcmData::Parse(const char *buf) { char Name[64]; @@ -610,16 +596,21 @@ bool cEcmData::Parse(const char *buf) return false; } -bool cEcmData::Save(FILE *f) +cString cEcmData::ToString(bool hide) { - fprintf(f,"%d:%x:%x:%s:%x/%x:%x:%x/%x",prgId,source,transponder,name,caId,emmCaId,provId,ecm_pid,ecm_table); + char *str; if(data) { - char *str=AUTOARRAY(char,dataLen*2+2); - fprintf(f,":%d:%s\n",dataLen,HexStr(str,data,dataLen)); + str=AUTOARRAY(char,dataLen*2+2); + sprintf(str,":%d:%s",dataLen,HexStr(str,data,dataLen)); + } + else { + str=AUTOARRAY(char,4); + strcpy(str,":0"); } - else - fprintf(f,":0\n"); - return ferror(f)==0; + return cString::sprintf("%d:%x:%x:%s:%x/%x:%x:%x/%x%s", + prgId,source,transponder,name, + caId,emmCaId,provId,ecm_pid,ecm_table, + str); } // -- cEcmCache ---------------------------------------------------------------- @@ -627,17 +618,18 @@ bool cEcmData::Save(FILE *f) cEcmCache ecmcache; cEcmCache::cEcmCache(void) -:cLoader("ECM") +:cStructList("ecm cache",ECMCACHE_FILE,true,true,false,false) {} void cEcmCache::New(cEcmInfo *e) { - Lock(); + ListLock(true); cEcmData *dat; if(!(dat=Exists(e))) { + ListUnlock(); + AutoGenWarn(); dat=new cEcmData(e); - Add(dat); - Modified(); + AddItem(dat,0,0); PRINTF(L_CORE_ECM,"cache add prgId=%d source=%x transponder=%x ecm=%x/%x",e->prgId,e->source,e->transponder,e->ecm_pid,e->ecm_table); } else { @@ -647,25 +639,26 @@ void cEcmCache::New(cEcmInfo *e) } if(dat->Update(e)) Modified(); + ListUnlock(); } e->SetCached(); - Unlock(); } cEcmData *cEcmCache::Exists(cEcmInfo *e) { - for(cEcmData *dat=First(); dat; dat=Next(dat)) - if(!dat->IsDeleted() && dat->Compare(e)) return dat; - return 0; + cEcmData *dat; + for(dat=First(); dat; dat=Next(dat)) + if(dat->Valid() && dat->Compare(e)) break; + return dat; } int cEcmCache::GetCached(cSimpleList *list, int sid, int Source, int Transponder) { int n=0; list->Clear(); - Lock(); + ListLock(false); for(cEcmData *dat=First(); dat; dat=Next(dat)) { - if(!dat->IsDeleted() && dat->prgId==sid && dat->source==Source && dat->transponder==Transponder) { + if(dat->Valid() && dat->prgId==sid && dat->source==Source && dat->transponder==Transponder) { cEcmInfo *e=new cEcmInfo(dat); if(e) { PRINTF(L_CORE_ECM,"from cache: system %s (%04x) id %04x with ecm %x/%x",e->name,e->caId,e->provId,e->ecm_pid,e->ecm_table); @@ -675,68 +668,36 @@ int cEcmCache::GetCached(cSimpleList *list, int sid, int Source, int T } } } - Unlock(); + ListUnlock(); return n; } void cEcmCache::Delete(cEcmInfo *e) { - Lock(); + ListLock(false); cEcmData *dat=Exists(e); + ListUnlock(); if(dat) { - dat->Delete(); - Modified(); + DelItem(dat); PRINTF(L_CORE_ECM,"invalidated cached prgId=%d source=%x transponder=%x ecm=%x/%x",dat->prgId,dat->source,dat->transponder,dat->ecm_pid,dat->ecm_table); } - Unlock(); } void cEcmCache::Flush(void) { - Lock(); + ListLock(true); Clear(); Modified(); PRINTF(L_CORE_ECM,"cache flushed"); - Unlock(); + ListUnlock(); } -void cEcmCache::Load(void) +cStructItem *cEcmCache::ParseLine(char *line) { - Lock(); - Clear(); - Unlock(); -} - -bool cEcmCache::Save(FILE *f) -{ - bool res=true; - Lock(); - for(cEcmData *dat=First(); dat;) { - if(!dat->IsDeleted()) { - if(!dat->Save(f)) { res=false; break; } - dat=Next(dat); - } - else { - cEcmData *n=Next(dat); - Del(dat); - dat=n; - } - } - Modified(!res); - Unlock(); - return res; -} - -bool cEcmCache::ParseLine(const char *line, bool fromCache) -{ - bool res=false; cEcmData *dat=new cEcmData; - if(dat && dat->Parse(line)) { - if(!Exists(dat)) { Add(dat); dat=0; } - res=true; - } + if(dat && dat->Parse(line) && !Exists(dat)) return dat; delete dat; - return res; + return 0; } // -- cEcmSys ------------------------------------------------------------------ diff --git a/cam.h b/cam.h index 18e6b88..697823c 100644 --- a/cam.h +++ b/cam.h @@ -41,18 +41,16 @@ class cPrg; // ---------------------------------------------------------------- -class cEcmCache : public cLoader, cMutex, cSimpleList { +class cEcmCache : public cStructList { private: cEcmData *Exists(cEcmInfo *e); public: cEcmCache(void); - void Load(void); void New(cEcmInfo *e); int GetCached(cSimpleList *list, int sid, int Source, int Transponder); void Delete(cEcmInfo *e); void Flush(void); - virtual bool Save(FILE *f); - virtual bool ParseLine(const char *line, bool fromCache); + virtual cStructItem *ParseLine(char *line); }; extern cEcmCache ecmcache; diff --git a/data.c b/data.c index 2b6a777..85af8f6 100644 --- a/data.c +++ b/data.c @@ -156,7 +156,7 @@ cStructItem::~cStructItem() void cStructItem::SetComment(const char *com) { free(comment); - comment=strdup(com); + comment=com ? strdup(com):0; } bool cStructItem::Save(FILE *f) @@ -222,12 +222,28 @@ void cStructLoader::DelItem(cStructItem *d, bool keep) if(keep) { cStructItem *n=new cCommentItem; n->SetComment(cString::sprintf(";%s%s",*d->ToString(false),d->Comment()?d->Comment():"")); + ListLock(true); Add(n,d); + ListUnlock(); } Modified(); } } +void cStructLoader::AutoGenWarn(void) +{ + if(Count()==0) { + cStructItem *n=new cCommentItem; + n->SetComment("## This is a generated file. DO NOT EDIT!!"); + cStructItem *n2=new cCommentItem; + n2->SetComment("## This file will be OVERWRITTEN WITHOUT WARNING!!"); + ListLock(true); + Add(n); + Add(n2); + ListUnlock(); + } +} + void cStructLoader::SetCfgDir(const char *cfgdir) { free(path); diff --git a/data.h b/data.h index 1dbaadb..ca6c5cd 100644 --- a/data.h +++ b/data.h @@ -109,6 +109,7 @@ protected: bool IsModified(void) const { return modified; } void ListLock(bool rw) { lock.Lock(rw); } void ListUnlock(void) { lock.Unlock(); } + void AutoGenWarn(void); virtual void PostLoad(void) {} public: cStructLoader(const char *Type, const char *Filename, bool rw, bool miok, bool wat, bool verb); @@ -214,7 +215,7 @@ public: // ---------------------------------------------------------------- -class cEcmInfo : public cSimpleItem { +class cEcmInfo : public cStructItem { private: bool cached, failed; // @@ -234,6 +235,7 @@ public: cEcmInfo(const cEcmInfo *e); cEcmInfo(const char *Name, int Pid, int CaId, int ProvId); ~cEcmInfo(); + virtual cString ToString(bool hide=false) { return ""; } bool Compare(const cEcmInfo *e); bool Update(const cEcmInfo *e); void SetSource(int PrgId, int Source, int Transponder); diff --git a/sc.c b/sc.c index d2c0a07..ddf1eb4 100644 --- a/sc.c +++ b/sc.c @@ -1006,7 +1006,6 @@ bool cScSetup::Ignore(unsigned short caid) bool cSoftCAM::Load(const char *cfgdir) { - ecmcache.Load(); if(!Feature.KeyFile()) keys.Disable(); cStructLoaders::Load(false); if(Feature.KeyFile() && keys.Count()<1)