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

evaftpacket.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 EVAFTPACKET_H
00022 #define EVAFTPACKET_H
00023 
00024 #define QQ_FILE_AGENT_PACKET_TAG           0x04
00025 #define QQ_FILE_AGENT_PACKET_TAIL          0x03
00026 
00027 #define QQ_FILE_AGENT_CMD_CREATE           0x0001
00028 #define QQ_FILE_AGENT_CMD_LOGIN            0x0002
00029 #define QQ_FILE_AGENT_CMD_TRANSFER         0x0003
00030 #define QQ_FILE_AGENT_CMD_READY            0x0005
00031 #define QQ_FILE_AGENT_CMD_START            0x0006
00032 
00033 #define QQ_FILE_SYN_CMD_CREATE             0x0001
00034 #define QQ_FILE_SYN_CMD_REGISTER           0x0002
00035 
00036 
00037 class EvaFTPacket {
00038 public:
00039         // for incoming packets
00040         EvaFTPacket(const unsigned char *buf, const int len);
00041         // for outcoming packets
00042         EvaFTPacket();
00043         virtual ~EvaFTPacket();
00044 
00045         // for incoming packets
00046         const bool parse();
00047         // for outcoming packets
00048         const bool fill(unsigned char *buf, int *len);
00049 
00050         // for incoming packets
00051         const unsigned char *getBody() const { return m_Buffer; }
00052         const int getBodyLength() const { return m_BufferLength; }
00053 protected:
00054         void setPacketTag(const unsigned char tag, const unsigned char tail);
00055         virtual const int parseHeader(unsigned char *buf);
00056         virtual const bool parseBody(unsigned char *buf, const int len);
00057         virtual const int fillHeader(unsigned char *buf);
00058         virtual const int fillBody(unsigned char *buf);
00059 
00060         inline const unsigned char getTag() const { return m_Tag; }
00061         inline const unsigned char getTail() const { return m_Tail; }
00062 
00063         int m_HeaderLength;
00064         bool m_HasTags;
00065         bool m_HasLength;
00066         unsigned int m_LengthOffset;
00067 private:
00068         unsigned char m_Tag, m_Tail;
00069 
00070         // for incoming packets
00071         unsigned char *m_Buffer;
00072         int m_BufferLength;
00073 };
00074 
00075 class EvaFTAgentPacket : public EvaFTPacket{
00076 public:
00077         EvaFTAgentPacket(const unsigned char *buf, const int len);
00078         EvaFTAgentPacket(const short cmd);
00079 
00080 
00081         inline void setVersion(const unsigned short version) { m_Version = version; }
00082         inline void setSequence(const unsigned short seq) { m_Sequence = seq; }
00083         inline void setCommand(const unsigned short cmd) { m_Command = cmd; }
00084         inline void setQQ(const int qq) { m_Id = qq; }
00085         inline void setSessionId(const unsigned int sid) { m_Session = sid; }
00086         inline const unsigned short getVersion() const { return m_Version; }
00087         inline const unsigned short getSequence() const { return m_Sequence; }
00088         inline const unsigned short getCommand() const { return m_Command; }
00089         inline const int getQQ() const { return m_Id; }
00090         inline const unsigned int getSessionId() const { return m_Session; }
00091 
00092         void setFileAgentKey(const unsigned char *key);
00093 protected:
00094         const int parseHeader(unsigned char *buf);
00095         //virtual const bool pareseBody();
00096         const int fillHeader(unsigned char *buf);
00097         //virtual const unsigned int fillBody(unsigned char *buf);
00098 
00099         unsigned char m_FileAgentKey[16];
00100         unsigned int m_Session;
00101 private:
00102         unsigned short m_Version;
00103         unsigned short m_Command;
00104         unsigned short m_Sequence;
00105         int m_Id;
00106 };
00107 
00108 class EvaFTSynPacket : public EvaFTPacket{
00109 public:
00110         EvaFTSynPacket(const unsigned char *buf, const int len);
00111         EvaFTSynPacket(const short cmd);
00112 
00113         inline void setVersion(const unsigned short version) { m_Version = version; }
00114         inline void setSequence(const unsigned short seq) { m_Sequence = seq; }
00115         inline void setCommand(const unsigned short cmd) { m_Command = cmd; }
00116         inline void setQQ(const int qq) { m_Id = qq; }
00117         inline void setSessionId(const unsigned int sid) { m_Session = sid; }
00118         inline const unsigned short getVersion() const { return m_Version; }
00119         inline const unsigned short getSequence() const { return m_Sequence; }
00120         inline const unsigned short getCommand() const { return m_Command; }
00121         inline const int getQQ() const { return m_Id; }
00122         inline const unsigned int getSessionId() const { return m_Session; }
00123 
00124         void setFileAgentKey(const unsigned char *key);
00125 protected:
00126         const int parseHeader(unsigned char *buf);
00127         const int fillHeader(unsigned char *buf);
00128 
00129         unsigned char m_FileAgentKey[16];
00130         unsigned int m_Session;
00131 private:
00132         static const unsigned char m_StartTag = 0x02;
00133         unsigned short m_Version;
00134         unsigned short m_Command;
00135         unsigned short m_Sequence;
00136         // for sending , m_Id is my qq number
00137         int m_Id;
00138 };
00139 
00140 #endif // #ifndef EVAFTPACKET_H
00141 

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