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 00021 #ifndef LIBEVAIMSEND_H 00022 #define LIBEVAIMSEND_H 00023 00024 #include "evapacket.h" 00025 #include "evautil.h" 00026 #include <string> 00027 #include <time.h> 00028 00029 // note that all text in SendIMPacket class is assumed as 00030 // encoded in locale "GB18030" 00031 class SendIM : public OutPacket 00032 { 00033 public: 00034 SendIM() {} 00035 SendIM(const unsigned short type); 00036 SendIM(const SendIM &rhs) ; 00037 virtual ~SendIM() {} 00038 00039 const int getReceiver() const { return receiver; }; // your friend's qq number 00040 void setReceiver(int receiver) { this->receiver = receiver; } 00041 00042 const short getFaceCode() const { return face; } 00043 void setFaceCode(short face) { this->face = face; } // set my face code 00044 00045 const unsigned short getContentType() const { return contentType; } 00046 const time_t getSendTime() const { return m_SendTime; } 00047 00048 const unsigned short getMsgSequence() const { return m_MsgSequence; } 00049 void setMsgSequence(const unsigned short seq) { m_MsgSequence = seq; } 00050 00051 SendIM &operator=(const SendIM &rhs); 00052 protected: 00053 virtual int putBody(unsigned char *buf); 00054 virtual int putContents(unsigned char *buf); 00055 private: 00056 int receiver; 00057 short face; 00058 unsigned short contentType; 00059 unsigned short m_MsgSequence; 00060 time_t m_SendTime; 00061 }; 00062 00063 00064 class SendTextIMPacket : public SendIM 00065 { 00066 public: 00067 SendTextIMPacket(); 00068 SendTextIMPacket(const SendTextIMPacket &rhs) ; 00069 virtual ~SendTextIMPacket() {} 00070 00071 00072 OutPacket * copy() { return new SendTextIMPacket(*this);} 00073 SendTextIMPacket &operator=(const SendTextIMPacket &rhs); 00074 00075 const std::string &getFontName() const { return fontName; } // font setting 00076 void setFontName(std::string &fontName) { this->fontName = fontName; } 00077 const char getFontSize() const { return fontSize; } 00078 void setFontSize(char fontSize); 00079 const short getEncoding() const { return encoding; } 00080 void setEncoding(short encoding) { this->encoding = encoding; } 00081 00082 const bool isUnderline() const { return underline;} // U B I setting 00083 void setUnderline(bool underline) ; 00084 const bool isItalic() const { return italic; } 00085 void setItalic(bool italic); 00086 const bool isBold() const { return bold; }; 00087 void setBold(bool bold); 00088 00089 const char getBlue() const { return blue; } // color setting 00090 void setBlue(char blue) { this->blue = blue; } 00091 const char getGreen() const { return green; } 00092 void setGreen(char green) {this->green = green; } 00093 const char getRed() const { return red; } 00094 void setRed(char red) { this->red = red; } 00095 00096 /* 00097 the message is plain text, which means the smiley code is already 00098 replaced with plain text. 00099 */ 00100 const std::string &getMessage() const { return message; } // message you want to send 00101 void setMessage(std::string message) { this->message = message; } // and just put your plain text message here 00102 const char getReplyType() const { return replyType; } 00103 void setReplyType(char replyType) { this->replyType = replyType; } 00104 void setAutoReply(const bool isNormal); 00105 00106 00107 protected: 00108 virtual int putContents(unsigned char *buf); 00109 private: 00110 //std::string convertToSend(const std::string &text); 00111 short encoding; 00112 std::string fontName; 00113 char red, green, blue; 00114 bool bold, italic, underline; 00115 unsigned char fontSize; 00116 unsigned char fontFlag; 00117 00118 std::string message; 00119 char replyType; 00120 //EvaUtil util; 00121 00122 }; 00123 00124 class SendIMReplyPacket : public InPacket 00125 { 00126 public: 00127 SendIMReplyPacket() {}; 00128 SendIMReplyPacket(unsigned char *buf, int len); 00129 SendIMReplyPacket(const SendIMReplyPacket &rhs ); 00130 virtual ~SendIMReplyPacket() {} 00131 00132 const char getReplyCode() const { return replyCode; }; 00133 const bool isSentOK() const ; 00134 00135 SendIMReplyPacket &operator=(const SendIMReplyPacket &rhs ); 00136 00137 protected: 00138 virtual void parseBody(); 00139 private: 00140 char replyCode; 00141 }; 00142 00143 class SendFileRequestPacket : public SendIM 00144 { 00145 public: 00146 SendFileRequestPacket(); 00147 SendFileRequestPacket(const SendFileRequestPacket &rhs) ; 00148 virtual ~SendFileRequestPacket() {} 00149 00150 00151 OutPacket * copy() { return new SendFileRequestPacket(*this);} 00152 SendFileRequestPacket &operator=(const SendFileRequestPacket &rhs); 00153 00154 inline void setFileName(const std::string &filename) { m_FileName = filename; } 00155 inline void setFileSize(const unsigned int size) { m_FileSize = size; } 00156 inline void setDirectPort(const unsigned short port) { m_DirectPort = port; } 00157 inline void setWanPort(const unsigned short port) { m_WanPort = port; } 00158 inline void setWanIp( const unsigned int ip) { m_WanIp = ip; } 00159 inline void setTransferType(const unsigned char type) { m_TransferType = type; } 00160 00161 inline const std::string getFileName() const { return m_FileName; } 00162 inline const unsigned int getFileSize() const { return m_FileSize; } 00163 inline const unsigned short getDirectPort() const { return m_DirectPort; } 00164 inline const unsigned short getWanPort() const { return m_WanPort; } 00165 inline const unsigned int getWanIp() const { return m_WanIp; } 00166 inline const unsigned char getTransferType() const { return m_TransferType; } 00167 00168 protected: 00169 virtual int putContents(unsigned char *buf); 00170 private: 00171 std::string m_FileName; 00172 unsigned int m_FileSize; 00173 unsigned short m_DirectPort; 00174 unsigned short m_WanPort; 00175 unsigned int m_WanIp; 00176 unsigned char m_TransferType; 00177 }; 00178 00179 00180 // QQ_IM_EX_UDP_REQUEST, QQ_IM_EX_REQUEST_ACCEPTED or QQ_IM_EX_REQUEST_CANCELED 00181 class SendFileExRequestPacket : public SendIM 00182 { 00183 public: 00184 SendFileExRequestPacket( const short cmd ); 00185 SendFileExRequestPacket(const SendFileExRequestPacket &rhs) ; 00186 virtual ~SendFileExRequestPacket() {} 00187 00188 00189 OutPacket * copy() { return new SendFileExRequestPacket(*this);} 00190 SendFileExRequestPacket &operator=(const SendFileExRequestPacket &rhs); 00191 00192 inline void setFileName(const std::string &filename) { m_FileName = filename; } 00193 inline void setFileSize(const unsigned int size) { m_FileSize = size; } 00194 inline void setWanPort(const unsigned short port) { m_WanPort = port; } 00195 inline void setWanIp( const unsigned int ip) { m_WanIp = ip; } 00196 inline void setTransferType(const unsigned char type) { m_TransferType = type; } 00197 inline void setSessionId(const unsigned short session) { m_SessionId = session; } 00198 00199 inline const std::string getFileName() const { return m_FileName; } 00200 inline const unsigned int getFileSize() const { return m_FileSize; } 00201 inline const unsigned short getWanPort() const { return m_WanPort; } 00202 inline const unsigned int getWanIp() const { return m_WanIp; } 00203 inline const unsigned char getTransferType() const { return m_TransferType; } 00204 inline const unsigned short getSessionId() const { return m_SessionId; } 00205 00206 protected: 00207 virtual int putContents(unsigned char *buf); 00208 private: 00209 unsigned short m_SessionId; 00210 std::string m_FileName; 00211 unsigned int m_FileSize; 00212 unsigned short m_WanPort; 00213 unsigned int m_WanIp; 00214 unsigned char m_TransferType; 00215 }; 00216 00217 class SendFileAcceptPacket : public SendIM 00218 { 00219 public: 00220 SendFileAcceptPacket(); 00221 SendFileAcceptPacket(const SendFileAcceptPacket &rhs) ; 00222 virtual ~SendFileAcceptPacket() {} 00223 00224 00225 OutPacket * copy() { return new SendFileAcceptPacket(*this);} 00226 SendFileAcceptPacket &operator=(const SendFileAcceptPacket &rhs); 00227 00228 inline void setTransferType(const unsigned char type) { m_TransferType = type; } 00229 inline void setConnectMode(const unsigned char mode) { m_ConnectMode = mode; } 00230 inline void setSessionId(const unsigned short session) { m_SessionId = session; } 00231 00232 inline const unsigned char getTransferType() const { return m_TransferType; } 00233 inline const unsigned char getConnectMode() const { return m_ConnectMode; } 00234 inline const unsigned short getSessionId() const { return m_SessionId; } 00235 00236 protected: 00237 virtual int putContents(unsigned char *buf); 00238 private: 00239 unsigned short m_SessionId; 00240 unsigned char m_TransferType; 00241 unsigned char m_ConnectMode; 00242 }; 00243 00244 class SendIpExNotifyPacket : public SendIM 00245 { 00246 public: 00247 SendIpExNotifyPacket(const bool isSender = true); 00248 SendIpExNotifyPacket(const SendIpExNotifyPacket &rhs) ; 00249 virtual ~SendIpExNotifyPacket() {} 00250 00251 00252 OutPacket * copy() { return new SendIpExNotifyPacket(*this);} 00253 SendIpExNotifyPacket &operator=(const SendIpExNotifyPacket &rhs); 00254 00255 inline void setTransferType(const unsigned char type) { m_TransferType = type; } 00256 inline void setConnectMode(const unsigned char mode) { m_ConnectMode = mode; } 00257 inline void setSessionId(const unsigned int session) { m_SessionId = session; } 00258 00259 inline void setWanIp1( const unsigned int ip) { m_WanIp1 = ip; } 00260 inline void setWanPort1(const unsigned short port) { m_WanPort1 = port; } 00261 inline void setWanIp2( const unsigned int ip) { m_WanIp2 = ip; } 00262 inline void setWanPort2(const unsigned short port) { m_WanPort2 = port; } 00263 inline void setWanIp3( const unsigned int ip) { m_WanIp3 = ip; } 00264 inline void setWanPort3(const unsigned short port) { m_WanPort3 = port; } 00265 00266 inline void setLanIp1( const unsigned int ip) { m_LanIp1 = ip; } 00267 inline void setLanPort1(const unsigned short port) { m_LanPort1 = port; } 00268 inline void setLanIp2( const unsigned int ip) { m_LanIp2 = ip; } 00269 inline void setLanPort2(const unsigned short port) { m_LanPort2 = port; } 00270 inline void setLanIp3( const unsigned int ip) { m_LanIp3 = ip; } 00271 inline void setLanPort3(const unsigned short port) { m_LanPort3 = port; } 00272 00273 inline void setSender(const bool sender) { m_IsSender = sender; } 00274 inline const bool isSender() const { return m_IsSender; } 00275 00276 inline const unsigned char getTransferType() const { return m_TransferType; } 00277 inline const unsigned char getConnectMode() const { return m_ConnectMode; } 00278 inline const unsigned int getSessionId() const { return m_SessionId; } 00279 00280 inline const unsigned int getWanIp1() const { return m_WanIp1; } 00281 inline const unsigned short getWanPort1() const { return m_WanPort1; } 00282 inline const unsigned int getWanIp2() const { return m_WanIp2; } 00283 inline const unsigned short getWanPort2() const { return m_WanPort2; } 00284 inline const unsigned int getWanIp3() const { return m_WanIp3; } 00285 inline const unsigned short getWanPort3() const { return m_WanPort3; } 00286 00287 inline const unsigned int getLanIp1() const { return m_LanIp1; } 00288 inline const unsigned short getLanPort1() const { return m_LanPort1; } 00289 // in most cases, just leave lan ip 2 & port 2 as default ( 0.0.0.0:0) 00290 inline const unsigned int getLanIp2() const { return m_LanIp2; } 00291 inline const unsigned short getLanPort2() const { return m_LanPort2; } 00292 inline const unsigned int getLanIp3() const { return m_LanIp3; } 00293 inline const unsigned short getLanPort3() const { return m_LanPort3; } 00294 00295 inline void setSyncSession(const unsigned int session) { m_SyncSession = session; } 00296 inline const unsigned int getSyncSession() const { return m_SyncSession; } 00297 00298 inline void setSyncIp( const unsigned int ip) { m_SyncIp = ip; } 00299 inline void setSyncPort(const unsigned short port) { m_SyncPort = port; } 00300 inline const unsigned int getSyncIp() const { return m_SyncIp; } 00301 inline const unsigned short getSyncPort() const { return m_SyncPort; } 00302 00303 protected: 00304 virtual int putContents(unsigned char *buf); 00305 private: 00306 bool m_IsSender; 00307 unsigned char m_TransferType; 00308 unsigned char m_ConnectMode; 00309 unsigned int m_SessionId; 00310 00311 unsigned int m_WanIp1; 00312 unsigned short m_WanPort1; 00313 unsigned int m_WanIp2; 00314 unsigned short m_WanPort2; 00315 unsigned int m_WanIp3; 00316 unsigned short m_WanPort3; 00317 00318 unsigned int m_LanIp1; 00319 unsigned short m_LanPort1; 00320 unsigned int m_LanIp2; 00321 unsigned short m_LanPort2; 00322 unsigned int m_LanIp3; 00323 unsigned short m_LanPort3; 00324 00325 00326 unsigned int m_SyncIp; 00327 unsigned short m_SyncPort; 00328 unsigned int m_SyncSession; 00329 }; 00330 00331 class SendFileNotifyAgentPacket : public SendIM 00332 { 00333 public: 00334 SendFileNotifyAgentPacket(); 00335 SendFileNotifyAgentPacket(const SendFileAcceptPacket &rhs) ; 00336 virtual ~SendFileNotifyAgentPacket() {} 00337 00338 00339 OutPacket * copy() { return new SendFileNotifyAgentPacket(*this);} 00340 SendFileNotifyAgentPacket &operator=(const SendFileNotifyAgentPacket &rhs); 00341 00342 inline void setTransferType(const unsigned char type) { m_TransferType = type; } 00343 inline void setConnectMode(const unsigned char mode) { m_ConnectMode = mode; } 00344 inline void setAgentServer(const unsigned int ip, const unsigned short port) 00345 { m_Ip = ip; m_Port = port; printf("========== ip:%8x, port:%4x\n", ip, 0xffff&port);} 00346 inline void setAgentSession(const unsigned int session) { m_Session = session; } 00347 00348 inline const unsigned char getTransferType() const { return m_TransferType; } 00349 inline const unsigned char getConnectMode() const { return m_ConnectMode; } 00350 inline const unsigned int getAgentIp() const { return m_Ip; } 00351 inline const unsigned short getAgentPort() const { return m_Port; } 00352 inline const unsigned int getAgentSession() const { return m_Session; } 00353 00354 protected: 00355 virtual int putContents(unsigned char *buf); 00356 private: 00357 unsigned int m_Ip; 00358 unsigned short m_Port; 00359 unsigned int m_Session; 00360 unsigned char m_TransferType; 00361 unsigned char m_ConnectMode; 00362 }; 00363 00364 00365 #endif 00366
1.4.4