]> www.vanbest.org Git - sasc-ng.git/commitdiff
cardclient: vitual logout
authorleslie <unknown>
Mon, 7 Sep 2009 12:35:21 +0000 (20:35 +0800)
committerleslie <unknown>
Mon, 7 Sep 2009 12:35:21 +0000 (20:35 +0800)
systems/cardclient/aroureos.c
systems/cardclient/camd.c
systems/cardclient/cc.c
systems/cardclient/cc.h
systems/cardclient/cccam.c
systems/cardclient/cccam2.c
systems/cardclient/gbox.c
systems/cardclient/newcamd.c
systems/cardclient/radegast.c

index 60da8a5990264868624066c2251252d38c08b33f..59eddd318b66ba2e26e7df7c9d13c12f4dc5f6d9 100644 (file)
@@ -65,7 +65,7 @@ bool cCardClientAroureos::ParseCardConfig(const char *config, int *num)
 bool cCardClientAroureos::Init(const char *config)
 {
   cMutexLock lock(this);
-  so.Disconnect();
+  Logout();
   int num=0;
   return ParseStdConfig(config,&num) &&
          ParseCardConfig(config,&num);
@@ -73,7 +73,7 @@ bool cCardClientAroureos::Init(const char *config)
 
 bool cCardClientAroureos::Login(void)
 {
-  so.Disconnect();
+  Logout();
   if(!so.Connect(hostname,port)) return false;
   PRINTF(L_CC_LOGIN,"%s: connected to %s:%d",name,hostname,port);
   if(!emmAllowed) PRINTF(L_CC_EMM,"%s: EMM disabled from config",name);
index 22f3c6dc01647769c0a00213f93ce261f59f4d6b..374161d303b901d6134734102af4ae0856b3aad3 100644 (file)
@@ -125,7 +125,7 @@ int cCardClientCommon::RecvMsg(unsigned char *data, int len, int to)
 bool cCardClientCommon::Init(const char *config)
 {
   cMutexLock lock(this);
-  so.Disconnect();
+  Logout();
   int num=0;
   if(ParseStdConfig(config,&num) &&
      ParseUserConfig(config,&num) &&
@@ -137,7 +137,7 @@ bool cCardClientCommon::Init(const char *config)
 
 bool cCardClientCommon::Login(void)
 {
-  so.Disconnect();
+  Logout();
   if(!so.Connect(hostname,port)) return false;
   PRINTF(L_CC_LOGIN,"%s: connected to %s:%d (%s)",name,hostname,port,name);
   emmProcessing=false;
@@ -515,14 +515,14 @@ int cCardClientCamd35::RecvBlock(struct CmdBlock *cb, int maxlen, int to)
 bool cCardClientCamd35::Init(const char *config)
 {
   cMutexLock lock(this);
-  so.Disconnect();
+  Logout();
   int num=0;
   return (ParseStdConfig(config,&num) && ParseUserConfig(config,&num));
 }
 
 bool cCardClientCamd35::Login(void)
 {
-  so.Disconnect();
+  Logout();
   if(!so.Connect(hostname,port)) return false;
   PRINTF(L_CC_LOGIN,"%s: connected to %s:%d (%s)",name,hostname,port,name);
   emmProcessing=false; lastEmmReq=0;
index e0b9a0c13417f7066a2f807656ebf0db2c1a7045..7ae1f913503a7395da685f11e80e4f287661dccd 100644 (file)
@@ -101,12 +101,17 @@ bool cCardClient::CanHandle(unsigned short SysId)
   return false;
 }
 
+void cCardClient::Logout(void)
+{
+  so.Disconnect();
+}
+
 bool cCardClient::SendMsg(const unsigned char *data, int len)
 {
   if(!so.Connected() && !Login()) return false;
   if(so.Write(data,len)<0) {
     PRINTF(L_CC_CORE,"send error. reconnecting...");;
-    so.Disconnect();
+    Logout();
     return false;
     }
   return true;
@@ -118,7 +123,7 @@ int cCardClient::RecvMsg(unsigned char *data, int len, int to)
   int n=so.Read(data,len,to);
   if(n<0) {
     PRINTF(L_CC_CORE,"recv error. reconnecting...");;
-    so.Disconnect();
+    Logout();
     }
   return n;
 }
index 06b137231d02b72ab78cff174cf97c7f4b5be993..170954691cc8b2615aa6a1675b86b61c4985a45e 100644 (file)
@@ -71,6 +71,7 @@ protected:
   virtual bool SendMsg(const unsigned char *data, int len);
   virtual int RecvMsg(unsigned char *data, int len, int to=-1);
   virtual bool Login(void) { return false; }
+  virtual void Logout(void);
   bool Immediate(void);
   void CaidsChanged(void);
 public:
index f6a0fba3f82741899b92e62d21ca3bb333fbf36d..645b2a6a7d61f0118544d0986521b2ddeed804ff 100644 (file)
@@ -199,6 +199,7 @@ bool cCardClientCCcam::Init(const char *config)
   cMutexLock lock(this);\r
   int num=0;\r
   char path[256];\r
+  Logout();\r
   if(!ParseStdConfig(config,&num)\r
      || sscanf(&config[num],":%255[^:]",path)!=1) return false;\r
   PRINTF(L_CC_CORE,"%s: socket=%s",name,path);\r
@@ -209,8 +210,7 @@ bool cCardClientCCcam::Init(const char *config)
 \r
 bool cCardClientCCcam::Login(void)\r
 {\r
-  cMutexLock lock(this);\r
-  so.Disconnect();\r
+  Logout();\r
   if(!so.Bind("127.0.0.1",port)) return false;\r
   so.SetQuietLog(true);\r
   PRINTF(L_CC_CCCAM,"Bound to port %d, starting UDP listener",port);\r
index cbbd120514cf9da6f6222e5da4393923e3393e9f..b82ea307a827c119969c9da2dce99456184fd9a3 100644 (file)
@@ -442,10 +442,10 @@ private:
   cMutex cwmutex;
   cCondVar cwwait;
   //
-  void Logout(void);
   void PacketAnalyzer(const struct CmdHeader *hdr, int length);
 protected:
   virtual bool Login(void);
+  virtual void Logout(void);
   virtual void Action(void);
 public:
   cCardClientCCcam2(const char *Name);
@@ -577,6 +577,7 @@ bool cCardClientCCcam2::Init(const char *config)
 {
   cMutexLock lock(this);
   int num=0;
+  Logout();
   if(!ParseStdConfig(config,&num)
      || sscanf(&config[num],":%20[^:]:%63[^:]",username,password)!=2 ) return false;
   PRINTF(L_CC_CORE,"%s: username=%s password=%s",name,username,password);
@@ -589,7 +590,7 @@ void cCardClientCCcam2::Logout(void)
 {
   login=false;
   Cancel(3);
-  so.Disconnect();
+  cCardClient::Logout();
 }
 
 bool cCardClientCCcam2::Login(void)
@@ -603,9 +604,8 @@ bool cCardClientCCcam2::Login(void)
 
   unsigned char buffer[512];
   int len;
-  if((len=so.Read(buffer,16))<0) {
+  if((len=RecvMsg(buffer,16))<0) {
     PRINTF(L_CC_CCCAM2,"no welcome from server");
-    Logout();
     return false;
     }
   LDUMP(L_CC_CCCAM2DT,buffer,len,"welcome answer:");
@@ -626,9 +626,8 @@ bool cCardClientCCcam2::Login(void)
 
   LDUMP(L_CC_CCCAM2DT,buff2,20,"welcome response:");
   encr.Encrypt(buff2,buffer,20);
-  if(so.Write(buffer,20)<0) {
+  if(!SendMsg(buffer,20)) {
     PRINTF(L_CC_CCCAM2,"failed to send welcome response");
-    Logout();
     return false;
     }
 
@@ -636,23 +635,20 @@ bool cCardClientCCcam2::Login(void)
   strcpy((char *)buff2,username);
   LDUMP(L_CC_CCCAM2DT,buff2,20,"send username:");
   encr.Encrypt(buff2,buffer,20);
-  if(so.Write(buffer,20)<0) {
+  if(!SendMsg(buffer,20)) {
     PRINTF(L_CC_CCCAM2,"failed to send username");
-    Logout();
     return false;
     }
 
   encr.Encrypt((unsigned char *)password,buffer,strlen(password));
   encr.Encrypt((unsigned char *)cccamstr,buffer,6);
-  if(so.Write(buffer,6)<0) {
+  if(!SendMsg(buffer,6)) {
     PRINTF(L_CC_CCCAM2,"failed to send password hash");
-    Logout();
     return false;
     }
 
-  if((len=so.Read(buffer,20))<0) {
+  if((len=RecvMsg(buffer,20))<0) {
     PRINTF(L_CC_CCCAM2,"no login answer from server");
-    Logout();
     return false;
     }
   decr.Decrypt(buffer,buffer,len);
@@ -675,9 +671,8 @@ bool cCardClientCCcam2::Login(void)
   memcpy(clt.nodeid,nodeid,8);
   LDUMP(L_CC_CCCAM2DT,&clt,sizeof(clt),"send clientinfo:");
   encr.Encrypt((unsigned char*)&clt,buffer,sizeof(clt));
-  if(so.Write(buffer,sizeof(clt))<0) {
+  if(!SendMsg(buffer,sizeof(clt))) {
     PRINTF(L_CC_CCCAM2,"failed to send clientinfo");
-    Logout();
     return false;
     }
   login=true;
@@ -724,9 +719,8 @@ bool cCardClientCCcam2::ProcessECM(const cEcmInfo *ecm, const unsigned char *dat
     PRINTF(L_CC_CCCAM2EX,"now try shareid %08x",shareid);
     LDUMP(L_CC_CCCAM2DT,req,ecm_len,"send ecm:");
     encr.Encrypt((unsigned char *)req,netbuff,ecm_len);
-    if(so.Write(netbuff,ecm_len)<0) {
+    if(!SendMsg(netbuff,ecm_len)) {
       PRINTF(L_CC_CCCAM2,"failed so send ecm request");
-      Logout();
       break;
       }
     cwmutex.Lock();
@@ -762,7 +756,7 @@ void cCardClientCCcam2::Action(void)
   int cnt=0;
   while(Running() && so.Connected()) {
     unsigned char recvbuff[1024];
-    int len=so.Read(recvbuff+cnt,-(sizeof(recvbuff)-cnt),200);
+    int len=RecvMsg(recvbuff+cnt,-(sizeof(recvbuff)-cnt),200);
     if(len>0) {
       decr.Decrypt(recvbuff+cnt,recvbuff+cnt,len);
       HEXDUMP(L_CC_CCCAM2DT,recvbuff+cnt,len,"net read: len=%d cnt=%d",len,cnt+len);
index 4e816374f0ebd40681d1719e5de1ed2f6377ec54..5dcd13df3200d1b8d971e05c96f0430b8e6dc6e5 100644 (file)
@@ -55,6 +55,7 @@ cCardClientGbox::cCardClientGbox(const char *Name)
 bool cCardClientGbox::Init(const char *config) 
 { 
   cMutexLock lock(this); 
+  Logout();
   int num=0;
   if(!ParseStdConfig(config,&num)) return false;
   return Immediate() ? Login() : true; 
@@ -62,7 +63,7 @@ bool cCardClientGbox::Init(const char *config)
  
 bool cCardClientGbox::Login(void) 
 { 
-  so.Disconnect();
+  Logout();
   if(!so.Bind("127.0.0.1",8003)) return false;
   return true;
 } 
index 029a2acd9f69ffb22959f619e0a99d02a44d369b..306ff10160f804904791209d3e410d3e0cf467f1 100644 (file)
@@ -355,6 +355,7 @@ bool cCardClientNewCamd::CanHandle(unsigned short SysId)
 bool cCardClientNewCamd::Init(const char *config)
 {
   cMutexLock lock(this);
+  Logout();
   int num=0;
   char key[29];
   const char *tmp=key;
@@ -368,14 +369,14 @@ bool cCardClientNewCamd::Init(const char *config)
 
 bool cCardClientNewCamd::Login(void)
 {
-  so.Disconnect();
+  Logout();
   if(!so.Connect(hostname,port)) return false;
 
   InitVars();
   unsigned char randData[14];
   if(so.Read(randData,sizeof(randData))<0) {
     PRINTF(L_CC_NEWCAMD,"no connect answer from %s:%d",hostname,port);
-    so.Disconnect();
+    Logout();
     return false;
     }
 
index e41db884ebf4682b4013aceae0d4cc7466f44c69..3a71b219f06b64318a6c5677f6c3947a0fa73c31 100644 (file)
@@ -80,7 +80,7 @@ bool cCardClientRadegast::CanHandle(unsigned short SysId)
 bool cCardClientRadegast::Init(const char *config)
 {
   cMutexLock lock(this);
-  so.Disconnect();
+  Logout();
   return ParseStdConfig(config) && (Immediate() ? Login() : true);
 }
 
@@ -170,7 +170,7 @@ int cCardClientRadegast::Recv(unsigned char *buff, int len)
 
 bool cCardClientRadegast::Login(void)
 {
-  so.Disconnect();
+  Logout();
   if(!so.Connect(hostname,port)) return false;
   PRINTF(L_CC_LOGIN,"%s: connected to %s:%d",name,hostname,port);