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

evapicpacket.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 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  
00021 #ifndef LIBCUSTOMPIC_EVAPICPACKET_H
00022 #define LIBCUSTOMPIC_EVAPICPACKET_H
00023 #include "../evadefines.h"
00024 
00025 const unsigned char FAMILY_05_TAG   =  0x05;
00026 const unsigned char FAMILY_05_TAIL  =  0x03;
00027 const int NO_CRYPTOGRAPH = -1;
00028 
00029 static const unsigned short QQ_05_CMD_REQUEST_AGENT = 0x0021;
00030 static const unsigned short QQ_05_CMD_REQUEST_FACE  = 0x0022;
00031 static const unsigned short QQ_05_CMD_TRANSFER      = 0x0023;
00032 static const unsigned short QQ_05_CMD_REQUEST_START = 0x0026;
00033 
00035 static const unsigned short QQ_REQUEST_AGENT_REPLY_OK       = 0x0000;
00037 static const unsigned short QQ_REQUEST_AGENT_REPLY_REDIRECT = 0x0001;
00039 static const unsigned short QQ_REQUEST_AGENT_REPLY_TOO_LONG = 0x0003;
00040 
00041 static const char GROUP_FILE_AGENT[] = "219.133.40.128"; // GroupFile.tencent.com
00042 
00043 
00044 class EvaPicPacket {
00045 public:
00046         EvaPicPacket(){};
00047         EvaPicPacket( unsigned char *buf, int len);
00048         // this is for outcoming packets
00049         EvaPicPacket(const unsigned short source, const unsigned short command, const unsigned short sequence) ;
00050         // this is for incoming packets
00051         EvaPicPacket( unsigned char *buf, int *len, const int cryptStart);
00052         
00053         EvaPicPacket(const EvaPicPacket &rhs);
00054         ~EvaPicPacket();
00055         
00056         EvaPicPacket &operator=(const EvaPicPacket &rhs);
00057         
00058         const int hashCode();
00059         static void setQQ(const unsigned int id) { myQQ = id; }
00060         static unsigned int getQQ() { return myQQ;}
00061         
00062         const unsigned char getHeader() const { return header; }
00063         const unsigned char getTail() const { return tail; }
00064         const unsigned short getSource() const { return source; }
00065         const unsigned short getCommand() const { return command; }
00066         const unsigned short getSequence() const { return sequence; }
00067         
00068         const int getCryptPosition() const { return cryptPosition; }
00069         
00070         static void setFileAgentKey(const unsigned char *key);
00071         static void clearKey();
00072         void setKey(const unsigned char *key);
00073         
00074         const bool isValid() const { return header==FAMILY_05_TAG && tail==FAMILY_05_TAIL ;}
00075         const unsigned short getPacketLength() const { return packetLength; }
00076 protected:
00077         void setCryptPosition(const int position) {cryptPosition = position; }
00078         const int parseHeader(unsigned char *buf);
00079         static unsigned char *fileAgentKey;
00080         static unsigned int myQQ;
00081 
00082         
00083         unsigned char header;
00084         unsigned short source;
00085         unsigned short command;
00086         unsigned short sequence;
00087         unsigned char *key;
00088         unsigned char tail;
00089         unsigned int cryptPosition;
00090         unsigned short packetLength;
00091 };
00092 
00093 class EvaPicOutPacket : public EvaPicPacket{
00094 public:
00095         EvaPicOutPacket() {};
00096         EvaPicOutPacket(const unsigned short command, const bool ack);
00097         EvaPicOutPacket(const EvaPicOutPacket &rhs);
00098         
00099         virtual ~EvaPicOutPacket() {}
00100         
00101         EvaPicOutPacket &operator=(const EvaPicOutPacket &rhs);
00102         
00103         const int getResendCount() const { return resendCount; }
00104         const bool fill(unsigned char *buf, int *len);
00105         const bool needAck() const { return mNeedAck; };
00106         const bool needResend() { return (--resendCount) != 0; }
00107 protected:
00108         virtual int putBody(unsigned char *buf);
00109 private:
00110         static short sequenceStart;
00111         bool mNeedAck;
00112         int resendCount;
00113         int  putHead(unsigned char *buf);
00114         void encryptBody(unsigned char *b, int length, 
00115                         unsigned char *decryptedBody, int *bodyLen);
00116 };
00117 
00118 class EvaPicInPacket : public EvaPicPacket{
00119 public:
00120         EvaPicInPacket() {}
00121         EvaPicInPacket( unsigned char *buf, int len);
00122         EvaPicInPacket( unsigned char *buf, int len, const unsigned int cryptStart);
00123         EvaPicInPacket(const EvaPicInPacket &rhs);
00124         virtual ~EvaPicInPacket();
00125         
00126         void parse() { parseBody(); }
00127         const int getLength() const { return bodyLength; };
00128         unsigned char * getBody() const { return decryptedBuf; };
00129         void setInPacket(const EvaPicInPacket *packet);
00130         
00131         void cutOffPacketData();
00132         
00133         EvaPicInPacket &operator=( const EvaPicInPacket &rhs);
00134         
00135         unsigned char *getRawBody() const { return rawBody; }
00136         unsigned int getRawBodyLength() const { return rawLength; }
00137         void printRawData();
00138 protected:
00139         int bodyLength;
00140         unsigned char *decryptedBuf;
00141         
00142         virtual void parseBody() {};  
00143 private: 
00144         void  decryptBody(unsigned char * buf, int len); 
00145         unsigned char *rawBody;
00146         unsigned int rawLength;
00147 };
00148 
00149 #endif 

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