Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

evapacket.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004 by yunfan                                          *
00003  *   yunfan_zg@163.com                                                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef LIBEVAPACKET_H
00021 #define LIBEVAPACKET_H
00022 
00023 #include "evadefines.h"
00024 
00025 // this is the base class for all QQ protocol classes
00026 class Packet{
00027 public: 
00028         Packet() {};
00029         // this is for outcoming packets
00030         Packet(const short version, const short command, const short sequence) ;
00031         // this is for incoming packets
00032         Packet( unsigned char *buf, int *len);
00033         Packet(const Packet &rhs);
00034         ~Packet();
00035         
00036         bool operator==(const Packet &rhs)  const;
00037         Packet &operator=(const Packet &rhs);
00038         const int hashCode() ;
00039         
00040         const short getVersion() const {   return version;};
00041         const short getCommand() const {   return command;};
00042         const short getSequence()  const {   return sequence;};
00043         
00044         
00045         void setVersion(const short version) { this->version = version; };
00046         void setCommand(const short command) { this->command = command; };
00047         void setSequence(const short sequence) { this->sequence = sequence; };
00048         
00049 
00050         static const int getQQ() { return qqNum; }
00051         static void setQQ(const int id) { qqNum = id; }
00052 
00053         static void setUDP(bool isUDP) { mIsUDP = isUDP; };
00054         static bool isUDP() { return mIsUDP; };
00055         static void setPasswordKey(const unsigned char* pkey);
00056         static bool isLoginTokenSet() { return loginToken != 0; }
00057         static bool isClientKeySet() { return clientKeyLength != 0; }
00058         static bool isFileAgentKeySet() { return fileAgentKey != 0; }
00059         static bool isFileAgentTokenSet() { return fileAgentToken != 0; }
00060         
00061         static unsigned char * getFileAgentKey() { return fileAgentKey; }
00062         static unsigned char * getFileAgentToken() { return fileAgentToken; }
00063         static unsigned int getFileAgentTokenLength() { return fileAgentTokenLength; }
00064         static unsigned char *getFileShareToken() { return fileShareToken; }
00065         static unsigned char *getClientKey() { return clientKey; }
00066         static const int getClientKeyLength() { return clientKeyLength; }
00067         
00068         static void clearAllKeys();      // called this after logged out to release memery
00069 protected:
00070         short version;
00071         short command;
00072         short sequence; 
00073         
00074         static unsigned char iniKey[16];
00075         
00076         // any key is 16 bytes long defined in evadefines as QQ_KEY_LENGTH
00077         static unsigned char *getSessionKey()  { return sessionKey; }
00078         static unsigned char *getPasswordKey()  { return passwordKey; }
00079         static unsigned char *getFileSessionKey()  { return fileSessionKey; }
00080         static unsigned char *getLoginToken() { return loginToken; }
00081         static const int getLoginTokenLength() { return loginTokenLength; }
00082         
00083         static void setSessionKey(const unsigned char *skey); 
00084         static void setFileSessionKey(const unsigned char *fskey);
00085         static void setLoginToken(const unsigned char *token, const int length);
00086         static void setClientKey(const unsigned char *ckey, const int length);
00087         static void setFileAgentKey(const unsigned char *key);
00088         static void setFileAgentToken(const unsigned char *token, const int length);
00089         static void setFileShareToken(const unsigned char *token); // always 24 bytes long. used for Qun share disk access
00090 private: 
00091         static int qqNum;
00092         static bool mIsUDP;
00093         static unsigned char *sessionKey;
00094         static unsigned char *passwordKey;
00095         static unsigned char *fileSessionKey;  
00096         static unsigned char *loginToken;
00097         static int loginTokenLength;
00098         
00099         static unsigned char *fileAgentKey;
00100         static unsigned char *fileAgentToken;
00101         static int fileAgentTokenLength;
00102         
00103         static unsigned char *clientKey;
00104         static int clientKeyLength;
00105         
00106         static unsigned char *fileShareToken; // note: always 24 bytes long
00107 };
00108 
00109 // this is the parent class for all sent-out packets
00110 class OutPacket : public Packet {
00111 public:
00112         OutPacket() {}
00113         OutPacket(const short command, const bool needAck);  
00114         OutPacket(const OutPacket &rhs);
00115         virtual ~OutPacket() {}
00116 
00117         const int getResendCount() const { return resendCount; }
00118         
00119         bool fill(unsigned char *buf, int *len);
00120         bool needAck() const { return mNeedAck; };
00121         const bool needResend() { return (--resendCount) != 0; }
00122         OutPacket &operator=( const OutPacket &rhs);
00123         
00124 protected:
00125         virtual int putBody(unsigned char *buf);
00126 
00127 private:
00128         static short startSequenceNum;
00129         bool mNeedAck;
00130         int resendCount;
00131         int  putHead(unsigned char *buf);
00132         void encryptBody(unsigned char *b, int length, 
00133                         unsigned char *decryptedBody, int *bodyLen);
00134 };
00135 
00136 // this class is inherited by all received-in packet
00137 class InPacket : public Packet {
00138 public:
00139         InPacket();
00140         InPacket( unsigned char *buf, int len);
00141         InPacket(const InPacket &rhs);
00142         virtual ~InPacket();
00143         
00144         const bool parse();
00145         const int getLength() const { return bodyLength; };
00146         unsigned char * getBody() const { return decryptedBuf; };
00147         void setInPacket(const InPacket *packet);
00148         InPacket &operator=( const InPacket &rhs);
00149 protected:      
00150         int bodyLength;
00151         unsigned char *decryptedBuf;
00152         
00153         virtual void parseBody() {};  
00154 private: 
00155         void  decryptBody(unsigned char * buf, int len);    
00156 };
00157 
00158 #endif

Generated on Mon May 15 20:48:41 2006 for libeva by  doxygen 1.4.4