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

evarequestagent.cpp

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 #include "evarequestagent.h" 
00022 #include "../evautil.h"
00023 #include <string.h>
00024 #ifdef _WIN32
00025 #include <winsock.h>
00026 #else
00027 #include <arpa/inet.h>
00028 #endif
00029 
00030 EvaRequestAgentPacket::EvaRequestAgentPacket( const unsigned char *token, const unsigned short length)
00031         : EvaPicOutPacket(QQ_05_CMD_REQUEST_AGENT, false)
00032 {
00033         tokenLength = length;
00034         cryptPosition = 14 + tokenLength;
00035         fileAgentToken = new unsigned char [ tokenLength ];
00036         memcpy(fileAgentToken, token, length);
00037 }
00038 
00039 EvaRequestAgentPacket::EvaRequestAgentPacket( const EvaRequestAgentPacket &rhs )
00040         : EvaPicOutPacket(rhs)
00041 {
00042         *this = rhs;
00043 }
00044 
00045 EvaRequestAgentPacket::~ EvaRequestAgentPacket( )
00046 {
00047         delete fileAgentToken;
00048 }
00049 
00050 EvaRequestAgentPacket &EvaRequestAgentPacket::operator=(const EvaRequestAgentPacket &rhs)
00051 {
00052         *((EvaPicOutPacket*)this) = (EvaPicOutPacket)rhs;
00053         qunID = rhs.getQunID();
00054         memcpy(md5, rhs.getMD5(), 16);
00055         imageLength = rhs.getImageLength();
00056         fileName = rhs.getFileName();
00057         tokenLength = rhs.getTokenLength();
00058         memcpy(fileAgentToken, rhs.getFileAgentToken(), tokenLength);
00059         return *this;
00060 }
00061 
00062 void EvaRequestAgentPacket::setMd5(const unsigned char *value)
00063 {
00064         memcpy(md5, value, 16);
00065 }
00066 
00067 int EvaRequestAgentPacket::putBody(unsigned char *buf)
00068 {
00069         int pos=0;
00070         unsigned int tmp4_1 = htonl(0x01000000), tmp4_2 = 0;
00071         memcpy(buf+pos, &tmp4_1, 4);
00072         pos+=4;
00073         memcpy(buf+pos, &tmp4_2, 4);
00074         pos+=4;                    // ignore 8 bytes
00075         
00076         memset(buf+pos, 0, 4); pos+=4;
00077         
00078         unsigned short tmp2;
00079         tmp2 = htons(tokenLength);
00080         memcpy(buf+pos, &tmp2, 2); pos+=2;
00081         
00082         memcpy(buf+pos, fileAgentToken, tokenLength); pos+=tokenLength;
00083         
00084         buf[pos++] = 0x04;
00085         buf[pos++] = 0x4c;
00086         
00087         tmp4_1 = htonl(qunID);
00088         memcpy(buf+pos, &tmp4_1, 4); pos+=4;
00089         
00090         tmp4_1 = htonl(imageLength);
00091         memcpy(buf+pos, &tmp4_1, 4); pos+=4;
00092         
00093         memcpy(buf+pos, md5, 16); pos+=4;
00094         
00095         memcpy(buf+pos, EvaUtil::doMd5((char*)fileName.c_str(), fileName.length()), 16); pos+=16;
00096         
00097         memset(buf+pos, 0, 2); pos+=2;
00098         
00099         return pos;
00100 }
00101 
00102 
00103 /****************************************************************************************************************************************************/
00104 
00105 RequestAgentReplyPacket::RequestAgentReplyPacket(unsigned char *buf, int len)
00106         : EvaPicInPacket(buf, len, 8)
00107 {
00108 }
00109 
00110 RequestAgentReplyPacket::RequestAgentReplyPacket(const RequestAgentReplyPacket &rhs)
00111         : EvaPicInPacket(rhs)
00112 {
00113         *this = rhs;
00114 }
00115 
00116 RequestAgentReplyPacket &RequestAgentReplyPacket::operator=(const RequestAgentReplyPacket &rhs)
00117 {
00118         *((EvaPicInPacket *)this) = (EvaPicInPacket)rhs;
00119         replyCode = rhs.getReplyCode();
00120         sessionID = rhs.getSessionID();
00121         redirectIP = rhs.getRedirectIP();
00122         redirectPort = rhs.getRedirectPort();
00123         message = rhs.getMessage();
00124         return *this;
00125 }
00126 
00127 void RequestAgentReplyPacket::parseBody()
00128 {
00129         int pos = 0;
00130         
00131         pos+=8; // ignore 8 bytes;
00132         
00133         unsigned short tmp2;
00134         memcpy(&tmp2, decryptedBuf+pos, 2); pos+=2;
00135         replyCode = ntohs(tmp2);
00136         
00137         pos+=4; // ignore the reply server ip
00138         pos+=2; // ignore the reply server port
00139         
00140         unsigned int tmp4;
00141         memcpy(&tmp4, decryptedBuf+pos, 4); pos+=4;
00142         sessionID = ntohl(tmp4);
00143         
00144         memcpy(&tmp4, decryptedBuf+pos, 4); pos+=4;
00145         redirectIP = tmp4;  // note that: the ip is already in little endian format, so we don't need ntohl
00146         
00147         memcpy(&tmp2, decryptedBuf+pos, 2); pos+=2;
00148         redirectPort = ntohs(tmp2);
00149         
00150         memcpy(&tmp2, decryptedBuf+pos, 2); pos+=2;
00151         unsigned short len = ntohs(tmp2);
00152         
00153         char *str = new char [len + 1];
00154         memcpy(str, decryptedBuf+pos, len); pos += len;
00155         str[len] = 0x00;
00156         message.assign(str);
00157         delete str;
00158 }

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