00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef LIBEVAPACKET_H
00021 #define LIBEVAPACKET_H
00022
00023 #include "evadefines.h"
00024
00025
00026 class Packet{
00027 public:
00028 Packet() {};
00029
00030 Packet(const short version, const short command, const short sequence) ;
00031
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();
00069 protected:
00070 short version;
00071 short command;
00072 short sequence;
00073
00074 static unsigned char iniKey[16];
00075
00076
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);
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;
00107 };
00108
00109
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
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