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

evaextrainfo.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 "evaextrainfo.h"
00022 #include <stdlib.h>
00023 #ifdef _WIN32
00024 #include <winsock.h>
00025 #else
00026 #include <arpa/inet.h>
00027 #endif
00028 
00029 RequestExtraInfoPacket::RequestExtraInfoPacket()
00030         : OutPacket(QQ_CMD_REQUEST_EXTRA_INFORMATION, true), 
00031         mOffset(0)
00032 {
00033 }
00034 
00035 RequestExtraInfoPacket::RequestExtraInfoPacket(const unsigned short offset)
00036         : OutPacket(QQ_CMD_REQUEST_EXTRA_INFORMATION, true), 
00037         mOffset(offset)
00038 {
00039 }
00040 
00041 RequestExtraInfoPacket::RequestExtraInfoPacket(const RequestExtraInfoPacket &rhs)
00042         : OutPacket(rhs)
00043 {
00044         (*this) = rhs;
00045 }
00046  
00047 RequestExtraInfoPacket &RequestExtraInfoPacket::operator=(const RequestExtraInfoPacket &rhs)
00048 {
00049         *((OutPacket *)this) = (OutPacket)rhs;
00050         mOffset = rhs.getOffset();
00051         return *this;
00052 }
00053 
00054 int RequestExtraInfoPacket::putBody(unsigned char *buf)
00055 {
00056         int pos=0;
00057         buf[pos++]=0x01; // at the moment ,  I only find this sub-command, so just hard-code here
00058         unsigned short tmp;
00059         tmp = htons(mOffset);
00060         memcpy(buf + pos, &tmp, 2); pos+=2;
00061         return pos;
00062 }
00063 
00064 
00065 /* =========================================================== */
00066 
00067 RequestExtraInfoReplyPacket::RequestExtraInfoReplyPacket(unsigned char *buf, int len)
00068         : InPacket(buf, len)
00069 {
00070 }
00071 
00072 RequestExtraInfoReplyPacket::RequestExtraInfoReplyPacket(const RequestExtraInfoReplyPacket &rhs)
00073         : InPacket(rhs)
00074 {
00075         *this = rhs;
00076 }
00077 
00078 RequestExtraInfoReplyPacket &RequestExtraInfoReplyPacket::operator=(const RequestExtraInfoReplyPacket &rhs)
00079 {
00080         *((InPacket *)this) = (InPacket)rhs;
00081         mReplyCode = rhs.getReplyCode();
00082         mOffset = rhs.getOffset();
00083         mMembers = rhs.getMembers();
00084         return *this;
00085 }
00086 
00087 void RequestExtraInfoReplyPacket::parseBody()
00088 {
00089         int pos = 0;
00090         mReplyCode = decryptedBuf[pos++];
00091         if(mReplyCode != 1){
00092                 fprintf(stderr, "RequestExtraInfoReplyPacket::parseBody -- Unknow reply code :%4x\n", 0xffff&mReplyCode);
00093                 return;
00094         }
00095         unsigned short tmp2;
00096         memcpy(&tmp2, decryptedBuf + pos, 2); pos+=2;
00097         mOffset = ntohs(tmp2);
00098         
00099         pos++;  // ignore the 4th byte, it always was 0x03,  now this changed to 0x04, which
00100                         // should be the length of extra info unit length, I guess
00101         
00102         int tmp4, id;
00103         mMembers.clear();
00104         while(pos<bodyLength){
00105                 memcpy(&tmp4, decryptedBuf + pos, 4); pos+=4;  // QQ number
00106                 id = ntohl(tmp4);
00107                 
00108                 memcpy(&tmp4, decryptedBuf + pos, 4); pos+=4;  // information flags( signature, QQ tang, QQ album, QQ firend making ), the length should
00109                                                                                                         // be same as declared before ( 0x04 now)
00110                 mMembers[id] = tmp4;
00111         }
00112 }
00113 
00114 
00115 /* =========================================================== */
00116 
00117 SignaturePacket::SignaturePacket( const unsigned char type )
00118         : OutPacket(QQ_CMD_SIGNATURE_OP, true), mType(type)
00119 {
00120 }
00121 
00122 SignaturePacket::SignaturePacket( const SignaturePacket & rhs )
00123         : OutPacket(rhs)
00124 {
00125         (*this) = rhs;
00126 }
00127 
00128 SignaturePacket & SignaturePacket::operator =( const SignaturePacket & rhs )
00129 {
00130         *((OutPacket *)this) = (OutPacket)rhs;
00131         mType = rhs.getType();
00132         mSignature = rhs.getSignature();
00133         mMembers = rhs.getMembers();
00134         return *this;
00135 }
00136 
00137 int SignaturePacket::putBody( unsigned char * buf )
00138 {
00139         int pos=0;
00140         buf[pos++] = mType;
00141         
00142         switch(mType){
00143         case QQ_SIGNATURE_MODIFY:{
00144                 buf[pos++] = 0x00;
00145                 int len = mSignature.length();
00146                 buf[pos++] = 0xff & len;
00147                 memcpy(buf + pos, mSignature.c_str(), len); pos+=len;
00148                 }
00149                 break;
00150         case QQ_SIGNATURE_DELETE:
00151                 break;
00152         case QQ_SIGNATURE_REQUEST:{
00153                 unsigned short tmp2;
00154                 tmp2 = htons(mMembers.size());
00155                 memcpy(buf + pos, &tmp2, 2); pos+=2;
00156                 
00157                 unsigned int tmp4;
00158                 std::map<int, int>::iterator iter;
00159                 for(iter = mMembers.begin(); iter!=mMembers.end(); ++iter){
00160                         tmp4 = htonl(iter->first);   // QQ number
00161                         memcpy(buf + pos, &tmp4, 4); pos+=4;
00162                         
00163                         tmp4 = htonl(iter->second);   // time or 0x00 00 00 01 / 0x00 00 00 02
00164                         memcpy(buf + pos, &tmp4, 4); pos+=4;
00165                 }
00166                 }
00167         }
00168         return pos;
00169 }
00170 
00171 
00172 /* =========================================================== */
00173 
00174 SignatureReplyPacket::SignatureReplyPacket( unsigned char * buf, int len )
00175         : InPacket(buf, len)
00176 {
00177 }
00178 
00179 SignatureReplyPacket::SignatureReplyPacket( const SignatureReplyPacket & rhs )
00180         : InPacket(rhs)
00181 {
00182         *this = rhs;
00183 }
00184 
00185 SignatureReplyPacket & SignatureReplyPacket::operator =( const SignatureReplyPacket & rhs )
00186 {
00187         *((InPacket *)this) = (InPacket)rhs;
00188         mType = rhs.getType();
00189         mReplyCode = rhs.getReplyCode();
00190         mMembers = rhs.getMembers();
00191         return *this;
00192 }
00193 
00194 void SignatureReplyPacket::parseBody( )
00195 {
00196         int pos=0;
00197         mType = decryptedBuf[pos++];
00198         mReplyCode = decryptedBuf[pos++];
00199         if(mReplyCode != 0x00) return;
00200         
00201         switch(mType){
00202         case QQ_SIGNATURE_MODIFY:
00203         case QQ_SIGNATURE_DELETE:
00204                 break;
00205         case QQ_SIGNATURE_REQUEST:{
00206                 int tmp4;
00207                 memcpy(&tmp4, decryptedBuf+pos, 4); pos+=4; // next start QQ number must equal or greater than this number
00208                 mNextStartId = ntohl(tmp4);
00209                 int id, sigLen;
00210                 while(pos<bodyLength){
00211                         memcpy(&tmp4, decryptedBuf+pos, 4); pos+=4; // QQ
00212                         id = ntohl(tmp4);
00213                         
00214                         SignatureElement element;
00215                         
00216                         memcpy(&tmp4, decryptedBuf+pos, 4); pos+=4; // the last modify time for the QQ above
00217                         element.lastModifyTime = ntohl(tmp4);
00218                         
00219                         sigLen = decryptedBuf[pos++];        // the length of the  signature
00220                         // MEMORY LEAK!
00221                         char *str = new char[sigLen+1];
00222                         memcpy(str, decryptedBuf + pos, sigLen); pos+=sigLen;  // the signature
00223                         str[sigLen] = 0x00;
00224                         element.signature.assign(str);
00225                         
00226                         mMembers[id] = element;
00227                         delete[] str;
00228                 }
00229                 }
00230                 break;
00231         }
00232 }
00233 

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