00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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;
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;
00132
00133 unsigned short tmp2;
00134 memcpy(&tmp2, decryptedBuf+pos, 2); pos+=2;
00135 replyCode = ntohs(tmp2);
00136
00137 pos+=4;
00138 pos+=2;
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;
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 }