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

evaftprotocols.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 EVAFTPROTOCOLS_H
00022 #define EVAFTPROTOCOLS_H
00023 
00024 #include "evaftpacket.h"
00025 #include <string>
00026 
00027 #define QQ_FILE_AGENT_CREATE_OK           0x0000
00028 #define QQ_FILE_AGENT_CREATE_REDIRECT     0x0001
00029 #define QQ_FILE_AGENT_CREATE_ERROR        0x0002
00030 #define QQ_FILE_AGENT_OPERATION_OK        0x00000000
00031 
00032 #define QQ_FILE_AGENT_TRANSFER_INFO       1
00033 #define QQ_FILE_AGENT_TRANSFER_DATA       2
00034 #define QQ_FILE_AGENT_TRANSFER_REPLY      3
00035 #define QQ_FILE_AGENT_TRANSFER_START      4
00036 
00037 class EvaFTAgentCreate : public EvaFTAgentPacket
00038 {
00039 public:
00040         EvaFTAgentCreate();
00041         virtual ~EvaFTAgentCreate();
00042         void setFileAgentToken(const unsigned char *token, const int len);
00043         inline void setBuddyQQ(const int id) { m_Id = id; }
00044         inline void setIp(const unsigned int ip) { m_Ip = ip; }
00045 protected:
00046         const int fillBody(unsigned char *buf);
00047 private:
00048         unsigned char *m_Token;
00049         int m_TokenLength;
00050         int m_Id;
00051         unsigned int m_Ip;
00052 };
00053 
00054 
00055 class EvaFTAgentCreateReply : public EvaFTAgentPacket
00056 {
00057 public:
00058         EvaFTAgentCreateReply(const unsigned char *buf, const int len);
00059         
00060         inline const bool isConnected() const { return m_ReplyCode==QQ_FILE_AGENT_CREATE_OK; }
00061         const unsigned short getReplyCode() const { return m_ReplyCode; }
00062 
00063         // if isConnect() returns true, the followings are for the server you are connecting with
00064         // otherwise, they will be another proper server's ip and port
00065         // also, getSessionId() will return the session id for this operation
00066         inline const unsigned int getIp() const { return m_Ip; }
00067         inline const unsigned short getPort() const { return m_Port; }
00068 
00069         const std::string &getMessage() const { return m_ErrMessage; }
00070 protected:
00071         const bool parseBody(unsigned char *buf, const int len);
00072 private:
00073         unsigned short m_ReplyCode;
00074         unsigned int m_Ip;
00075         unsigned short m_Port;
00076         std::string m_ErrMessage;
00077 };
00078 
00079 
00080 class EvaFTAgentLogin : public EvaFTAgentPacket
00081 {
00082 public:
00083         EvaFTAgentLogin();
00084         ~EvaFTAgentLogin();
00085         void setFileAgentToken(const unsigned char *token, const int len);
00086 protected:
00087         const int fillBody(unsigned char *buf);
00088 private:
00089         unsigned char *m_Token;
00090         int m_TokenLength;
00091 };
00092 
00093 
00094 class EvaFTAgentLoginReply : public EvaFTAgentPacket
00095 {
00096 public:
00097         EvaFTAgentLoginReply(const unsigned char *buf, const int len);
00098         ~EvaFTAgentLoginReply() {};
00099         inline const bool isConnected() const { return m_ReplyCode==QQ_FILE_AGENT_OPERATION_OK ;}
00100 protected:
00101         const bool parseBody(unsigned char *buf, const int len);
00102 private:
00103         unsigned int m_ReplyCode;
00104 };
00105 
00106 
00107 // note: whenever we got 50 packets we need to send a reply packet to server
00108 class EvaFTAgentTransfer : public EvaFTAgentPacket
00109 {
00110 public:
00111         EvaFTAgentTransfer(const int type);
00112         ~EvaFTAgentTransfer();
00113         
00114         // for file info
00115         void setInfo(const std::string &file, const unsigned char *fileMd5, 
00116                         const unsigned int size);
00117 
00118         // for file data
00119         void setData(const unsigned char *data, const unsigned int len);
00120 
00121         // ask start at offset
00122         inline void setOffset(const unsigned int offset) { m_StartOffset = offset; }
00123 protected:
00124         const int fillBody(unsigned char *buf);
00125 private:
00126         int m_Type;
00127 
00128         // for file info
00129         std::string m_FileName;
00130         unsigned char *m_FMd5;
00131         unsigned int m_FileSize;
00132 
00133         // for file data
00134         unsigned char *m_Data;
00135         unsigned int m_DataLength; // should be always 0x0800
00136 
00137         unsigned int m_StartOffset;
00138 };
00139 
00140 
00141 // we receive this from agent server ( relay server)
00142 class EvaFTAgentTransferReply : public EvaFTAgentPacket
00143 {
00144 public:
00145         EvaFTAgentTransferReply(const int type, const unsigned char *buf, const int len);
00146         ~EvaFTAgentTransferReply();
00147 
00148         // ask sender to start sending contents at position
00149         inline unsigned int getStartPosition() const { return m_ReplyCode;}
00150         //inline const bool isTransferNow() const { return m_ReplyCode == QQ_FILE_AGENT_OPERATION_OK; }
00151 
00152         // ask sender to sending next 50 packets
00153         inline const bool isReceivedOk() const { return m_NextReplyCode == 0x02; }
00154 
00155         // tell receiver the file information, sequence always be 0x0001
00156         const unsigned char * getFileMd5();
00157         const unsigned char * getFileNameMd5();
00158         inline const std::string &getFileName() const { return m_FileName; }
00159         inline const unsigned int getFileSize() const { return m_FileSize; }
00160 
00161         // data packet, also you should check the sequence number
00162         // the file info has the number 1, the data packet starts 2 till
00163         // the last packet
00164         inline const unsigned int getDataLength() const { return m_DataLength; }
00165         //void getData(unsigned char *buf);
00166         inline const unsigned char *getData() const { return m_Data; }
00167          
00168 protected:
00169         const bool parseBody(unsigned char *buf, const int len);
00170 private:
00171         int m_Type;
00172 
00173         // ask sender to start sending contents
00174         unsigned int m_ReplyCode;
00175 
00176         // ask sender to sending next 50 packets
00177         unsigned char m_NextReplyCode;
00178 
00179         // tell receiver the file information
00180         unsigned char *m_FileMd5;
00181         unsigned char *m_FileNameMd5;
00182         std::string m_FileName;
00183         unsigned int m_FileSize;
00184 
00185         // data packet
00186         unsigned char *m_Data;
00187         unsigned int m_DataLength;
00188 };
00189 
00190 
00191 class EvaFTAgentAckReady : public EvaFTAgentPacket
00192 {
00193 public:
00194         EvaFTAgentAckReady();
00195         ~EvaFTAgentAckReady();
00196 protected:
00197         const int fillBody(unsigned char *buf);
00198 };
00199 
00200 
00201 class EvaFTAgentAskReady : public EvaFTAgentPacket
00202 {
00203 public:
00204         EvaFTAgentAskReady(const unsigned char *buf, const int len);
00205         ~EvaFTAgentAskReady() {};
00206         inline const bool isAskReady() const { return m_ReplyCode==QQ_FILE_AGENT_OPERATION_OK ;}
00207 protected:
00208         const bool parseBody(unsigned char *buf, const int len);
00209 private:
00210         unsigned int m_ReplyCode;
00211 };
00212 
00213 
00214 class EvaFTAgentStart : public EvaFTAgentPacket
00215 {
00216 public:
00217         EvaFTAgentStart();
00218         ~EvaFTAgentStart();
00219 protected:
00220         const int fillBody(unsigned char *buf);
00221 };
00222 
00223 
00224 class EvaFTAgentStartReply : public EvaFTAgentPacket
00225 {
00226 public:
00227         EvaFTAgentStartReply(const unsigned char *buf, const int len);
00228         ~EvaFTAgentStartReply() {};
00229 protected:
00230         const bool parseBody(unsigned char *buf, const int len);
00231 };
00232 
00233 
00237 class EvaFTSynCreate : public EvaFTSynPacket
00238 {
00239 public:
00240         EvaFTSynCreate();
00241         ~EvaFTSynCreate();
00242         void setFileAgentToken(const unsigned char *token, const int len);
00243         inline void setBuddyQQ(const int id) { m_BuddyId = id; }
00244 protected:
00245         const int fillBody(unsigned char *buf);
00246 private:
00247         unsigned char *m_Token;
00248         int m_TokenLength;
00249         int m_BuddyId;  
00250 };
00251 
00252 class EvaFTSynCreateReply : public EvaFTSynPacket
00253 {
00254 public:
00255         EvaFTSynCreateReply(const unsigned char *buf, const int len);
00256         
00257         inline const bool isSuccessful() const { return m_ReplyCode==QQ_FILE_AGENT_CREATE_OK; }
00258         const unsigned short getReplyCode() const { return m_ReplyCode; }
00259 
00260         inline const unsigned int getIp() const { return m_Ip; }
00261         inline const unsigned short getPort() const { return m_Port; }
00262 protected:
00263         const bool parseBody(unsigned char *buf, const int len);
00264 private:
00265         unsigned short m_ReplyCode;
00266         unsigned int m_Ip;
00267         unsigned short m_Port;
00268 };
00269 
00270 
00271 #endif //#ifndef EVAFTPROTOCOL_H

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