SASC-NG
DVBSoftCAM

cTpsKeys Class Reference

#include <tps.h>

Inheritance diagram for cTpsKeys:

List of all members.

Public Member Functions

 cTpsKeys (void)
 ~cTpsKeys ()
const cTpsKey * GetKey (time_t t)
const cTpsKey * GetV2Key (int id)
void Check (time_t now, cSystem *sys)

Protected Member Functions

virtual bool ParseLinePlain (const char *line)
virtual void PreLoad (void)
virtual void PostLoad (void)
virtual void PostSave (FILE *f)

Friends

class cTpsAuHook

Detailed Description

Definition at line 94 of file tps.h.


Constructor & Destructor Documentation

cTpsKeys::cTpsKeys ( void  )

Definition at line 526 of file tps.c.

:cStructListPlain<cTpsKey>("TPS keys","tps.cache",SL_READWRITE|SL_MISSINGOK|SL_WATCH|SL_NOPURGE)
,lastLoad(-LOADBIN_TIME)
,lastAu(-TPSAU_TIME)
{
  first=last=0; algomem=0; loadlist=0;
}
cTpsKeys::~cTpsKeys ( )

Definition at line 534 of file tps.c.

References free.

{
  free(algomem);
  delete loadlist;
}

Member Function Documentation

void cTpsKeys::Check ( time_t  now,
cSystem *  sys 
)

Definition at line 568 of file tps.c.

References cSystem::AddHook(), AU_STREAM, AU_TPSBIN, cScSetup::AutoUpdate, CHECK_TIME, cSimpleListBase::Count(), cTpsAuHook, cTimeMs::Elapsed(), HOOK_TPSAU, L_SYS_TPSAU, LOADBIN_TIME, cMutex::Lock(), PRINTF, cStructLoader::Purge(), ScSetup, cTimeMs::Set(), TPSAU_TIME, TPSBIN, cSystem::TriggerHook(), and cMutex::Unlock().

Referenced by cTPS::Decrypt().

{
  checkMutex.Lock();
  if(first==0 && last==0 && Count()>0)
    GetFirstLast();
  if(now>0 && lastCheck.Elapsed()>CHECK_TIME) {
    Purge(now);
    lastCheck.Set();
    }
  bool nokey=now+2*3600>last;
  if(tpsAuMode==AU_TPSBIN && lastLoad.Elapsed()>(nokey ? LOADBIN_TIME/60 : LOADBIN_TIME)) {
    PRINTF(L_SYS_TPSAU,"loading "TPSBIN" triggered");
    LoadBin();
    if(now>0) Purge(now);
    lastLoad.Set();
    }
  if(tpsAuMode==AU_STREAM && lastAu.Elapsed()>(nokey ? TPSAU_TIME/60 : TPSAU_TIME)) {
    if(ScSetup.AutoUpdate>0) {
      PRINTF(L_SYS_TPSAU,"TPS AU triggered");
      if(!sys->TriggerHook(HOOK_TPSAU)) {
        cTpsAuHook *hook=new cTpsAuHook;
        sys->AddHook(hook);
        PRINTF(L_SYS_TPSAU,"TPS AU hook added");
        }
      }
    lastAu.Set();
    }
  checkMutex.Unlock();
}
const cTpsKey * cTpsKeys::GetKey ( time_t  t)

Definition at line 540 of file tps.c.

References cStructListPlain< cTpsKey >::First(), k, cStructLoader::ListLock(), cStructLoader::ListUnlock(), and cStructListPlain< cTpsKey >::Next().

Referenced by cTPS::Decrypt().

{
  ListLock(false);
  cTpsKey *k;
  for(k=First(); k; k=Next(k)) if(t<k->Timestamp()) break;
  ListUnlock();
  return k;
}
const cTpsKey * cTpsKeys::GetV2Key ( int  id)

Definition at line 549 of file tps.c.

References cPlainKeys::FindKey(), cPlainKey::Get(), keys, L_SYS_KEY, MBC3, PRINTF, and cTpsKey::Set().

Referenced by cTPS::Decrypt().

{
  unsigned char tmp[56];
  memset(tmp,0,sizeof(tmp));
  cPlainKey *pk=keys.FindKey('V',id,MBC3('T','P','S'),16,0);
  if(pk) {
    pk->Get(&tmp[4+2*16]);
    tmp[52+2]=1;
    tmp[52+3]=0x1C;
    cTpsKey *tk=new cTpsKey;
    if(tk) {
      tk->Set(tmp);
      return tk;
      }
    }
  else PRINTF(L_SYS_KEY,"missing %.4x TPS key\n",id);
  return 0;
}
bool cTpsKeys::ParseLinePlain ( const char *  line) [protected, virtual]

Implements cStructLoaderPlain.

Definition at line 884 of file tps.c.

References cSimpleListBase::Add(), crc32_le(), free, GetHex(), L_SYS_TPS, MALLOC, PRINTF, cTPSDecrypt::RegisterAlgo3(), and cTpsKey::Set().

{
  unsigned char tmp[60];
  if(line[0]=='X') {
    if(line[1]=='S') {
      if(algomem) PRINTF(L_SYS_TPS,"multiple start extentions during cache load");
      if(sscanf(&line[2],"%x %x %x %x",&algolen,&cb1off,&cb2off,&cb3off)==4) {
        free(algomem);
        if((algomem=MALLOC(unsigned char,algolen))) {
          algoread=0;
          return true;
          }
        else PRINTF(L_SYS_TPS,"no memory for algo");
        }
      else PRINTF(L_SYS_TPS,"bad format in start extention");
      }
    else if(line[1]=='C') {
      if(algomem) {
        int off, len;
        unsigned int crc;
        if(sscanf(&line[2],"%x %x %n",&off,&crc,&len)==2) {
          line+=len+2;
          unsigned char buff[210];
          if((len=GetHex(line,buff,200,false))) {
            if(crc==crc32_le(0,buff,len) && off>=0 && off+len<=algolen) {
              memcpy(&algomem[off],buff,len);
              algoread+=len;
              if(algoread==algolen) {
                RegisterAlgo3(algomem,cb1off,cb2off,cb3off,algolen);
                free(algomem); algomem=0;
                }
              return true;
              }
            }
          }
        PRINTF(L_SYS_TPS,"bad format in code extention");
        }
      else PRINTF(L_SYS_TPS,"unexpected code extention");
      }
    else PRINTF(L_SYS_TPS,"unknown extention during cache load");
    }
  else {
    if(GetHex(line,tmp,sizeof(tmp))) {
      unsigned int crc=crc32_le(0,&tmp[4],sizeof(tmp)-4);
      if(*((unsigned int *)tmp)==crc) {
        cTpsKey *k=new cTpsKey;
        if(k) { k->Set(&tmp[4]); if(loadlist) loadlist->Add(k); }
        return true;
        }
      else PRINTF(L_SYS_TPS,"CRC failed during cache load");
      }
    }
  return false;
}
void cTpsKeys::PostLoad ( void  ) [protected, virtual]

Reimplemented from cStructLoader.

Definition at line 879 of file tps.c.

{
  if(loadlist) { Join(loadlist); loadlist=0; }
}
void cTpsKeys::PostSave ( FILE *  f) [protected, virtual]

Reimplemented from cStructLoaderPlain.

Definition at line 939 of file tps.c.

References crc32_le(), cTPSDecrypt::DumpAlgo3(), free, HexStr(), and min().

{
  char str[420];
  unsigned char *mem;
  int len=0, cb1=0, cb2=0, cb3=0;
  if((mem=DumpAlgo3(len,cb1,cb2,cb3))) {
    fprintf(f,"XS %04X %04X %04X %04X\n",len,cb1,cb2,cb3);
    for(int i=0; i<len; i+=200) {
      int l=min(200,len-i);
      fprintf(f,"XC %04X %08X %s\n",i,crc32_le(0,&mem[i],l),HexStr(str,&mem[i],l));
      }
    free(mem);
    }
}
void cTpsKeys::PreLoad ( void  ) [protected, virtual]

Reimplemented from cStructLoaderPlain.

Definition at line 872 of file tps.c.

References L_SYS_TPS, and PRINTF.

{
  delete loadlist;
  loadlist=new cSimpleList<cTpsKey>;
  if(!loadlist) PRINTF(L_SYS_TPS,"no memory for loadlist");
}

Friends And Related Function Documentation

friend class cTpsAuHook [friend]

Definition at line 95 of file tps.h.

Referenced by Check().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines