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

evagroup.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 "evagroup.h"
00022 #include "evadefines.h"
00023 #include <stdio.h>
00024 #ifdef _WIN32
00025 #include <winsock.h>
00026 #else
00027 #include <arpa/inet.h>
00028 #endif
00029 
00030 GroupNameOpPacket::GroupNameOpPacket( )
00031         : OutPacket(QQ_CMD_GROUP_NAME_OP, true),
00032         type(QQ_UPLOAD_GROUP_NAME)
00033 {
00034 } 
00035 
00036 GroupNameOpPacket::GroupNameOpPacket(const char cmdType)
00037         : OutPacket(QQ_CMD_GROUP_NAME_OP, true),
00038         type(cmdType)
00039 {
00040 }
00041 
00042 GroupNameOpPacket::GroupNameOpPacket(const GroupNameOpPacket &rhs)
00043         : OutPacket(rhs)
00044 {
00045         groups = rhs.getGroups();
00046         type = rhs.getType();
00047 }
00048 
00049 GroupNameOpPacket &GroupNameOpPacket::operator=(const GroupNameOpPacket &rhs)
00050 {
00051         *((OutPacket*)this) = (OutPacket)rhs;
00052         groups = rhs.getGroups();
00053         type = rhs.getType();
00054         return *this;
00055 }
00056 
00057 int GroupNameOpPacket::putBody( unsigned char * buf )
00058 {
00059     int pos = 0;
00060     buf[pos++] = type;
00061     if(type == QQ_UPLOAD_GROUP_NAME) {
00062             unsigned char groupIndex = 0x00;
00063             std::list<std::string>::iterator iter = groups.begin();
00064             for(++iter; iter != groups.end(); ++iter){  // we should ignore the first group name(default fixed string)
00065                     buf[pos++]=(unsigned char)(++groupIndex);
00066                     if(iter->length() > (uint)QQ_MAX_GROUP_NAME_BYTE){
00067                             memcpy(buf+pos, iter->c_str(), QQ_MAX_GROUP_NAME_BYTE);                                     
00068                             pos+=QQ_MAX_GROUP_NAME_BYTE;
00069                     }else {
00070                             memcpy(buf+pos, iter->c_str(), iter->length());
00071                             pos+=iter->length();
00072                             int j = QQ_MAX_GROUP_NAME_BYTE - iter->length();
00073                             while(j-- > 0)
00074                                     buf[pos++]=0x00;
00075                     }
00076             }
00077     } else {
00078             buf[pos++]=0x02;
00079             memset(buf+pos, 0, 4);
00080             pos+=4;
00081     }
00082     return pos;
00083 }
00084 
00085 /* =========================================================== */
00086 
00087 GroupNameOpReplyPacket::GroupNameOpReplyPacket(unsigned char* buf, int len)
00088         : InPacket(buf, len),
00089         type(QQ_DOWNLOAD_GROUP_NAME)
00090 {
00091 }
00092 
00093 GroupNameOpReplyPacket::GroupNameOpReplyPacket(const GroupNameOpReplyPacket &rhs)
00094         : InPacket(rhs)
00095 {
00096         type = rhs.getType();
00097         groupNames = rhs.getGroupNames();
00098 }
00099 
00100 GroupNameOpReplyPacket &GroupNameOpReplyPacket::operator=( const GroupNameOpReplyPacket &rhs )
00101 {
00102         *((InPacket *)this) = (InPacket)rhs;
00103         type = rhs.getType();
00104         groupNames = rhs.getGroupNames();
00105         return *this;   
00106 }
00107 
00108 void GroupNameOpReplyPacket::parseBody()
00109 {
00110         groupNames.clear();     
00111         type = decryptedBuf[0];
00112         if(type == QQ_DOWNLOAD_GROUP_NAME) {
00113                 int offset=7;
00114                 while(bodyLength>offset) {
00115                         std::string name((char*)(decryptedBuf+offset));
00116                         groupNames.push_back(name);
00117                         offset += 17;
00118                 }
00119         }
00120 }
00121 
00122 const bool GroupNameOpReplyPacket::isDownloadReply() const 
00123 { 
00124         return type == QQ_DOWNLOAD_GROUP_NAME; 
00125 } 
00126 
00127 /* =========================================================== */
00128 
00129 DownloadFriendEntry::DownloadFriendEntry(const char *buf)
00130 {
00131         readData(buf);
00132 }
00133 
00134 DownloadFriendEntry::DownloadFriendEntry(const DownloadFriendEntry &rhs)
00135 {
00136         *this = rhs;
00137 }
00138 
00139 DownloadFriendEntry &DownloadFriendEntry::operator=(const DownloadFriendEntry &rhs)
00140 {
00141         qqNum = rhs.getQQ();
00142         type = rhs.getType();
00143         groupID = rhs.getGroupID();
00144         return *this;   
00145 }
00146 
00147 const int DownloadFriendEntry::readData(const char *buf)
00148 {
00149         int tmp4;
00150         memcpy(&tmp4, buf, 4);  
00151         qqNum = ntohl(tmp4);
00152         type = buf[4];
00153         groupID = ( buf[5] >> 2) & 0x3f;  
00154         return 6;
00155 }
00156 
00157 const bool DownloadFriendEntry::isQun() const
00158 {
00159         return type == QQ_ID_IS_QUN;
00160 }
00161 
00162 /* =========================================================== */
00163 
00164 DownloadGroupFriendPacket::DownloadGroupFriendPacket()
00165         : OutPacket(QQ_CMD_DOWNLOAD_GROUP_FRIEND, true),
00166         startID(0)
00167 {
00168 }
00169 
00170 DownloadGroupFriendPacket::DownloadGroupFriendPacket(const int start)
00171         : OutPacket(QQ_CMD_DOWNLOAD_GROUP_FRIEND, true),
00172         startID(start)
00173 {
00174 }
00175 
00176 DownloadGroupFriendPacket::DownloadGroupFriendPacket(const DownloadGroupFriendPacket &rhs)
00177         : OutPacket(rhs)
00178 {
00179         startID = rhs.getStartID();
00180 }
00181 
00182 DownloadGroupFriendPacket &DownloadGroupFriendPacket::operator=(const DownloadGroupFriendPacket &rhs)
00183 {
00184         *( (OutPacket *)this) = (OutPacket)rhs;
00185         startID = rhs.getStartID();
00186         return *this;
00187 }
00188 
00189 int DownloadGroupFriendPacket::putBody(unsigned char* buf)
00190 {
00191         buf[0]=0x01;
00192         buf[1]=0x02;
00193         memset(buf+2, 0, 4); 
00194         int tmp4 = htonl(startID);
00195         memcpy(buf+6, &tmp4, 4);
00196         return 10;
00197 }
00198 
00199 /* =========================================================== */
00200 
00201 DownloadGroupFriendReplyPacket::DownloadGroupFriendReplyPacket(unsigned char* buf, int len)
00202         : InPacket(buf, len)
00203 {       
00204 }
00205 
00206 DownloadGroupFriendReplyPacket::DownloadGroupFriendReplyPacket( const DownloadGroupFriendReplyPacket &rhs)
00207         : InPacket(rhs)
00208 {
00209         nextStartID = rhs.getNextStartID();
00210         friends = rhs.getGroupedFriends();
00211 }
00212 
00213 DownloadGroupFriendReplyPacket &DownloadGroupFriendReplyPacket::operator=( const DownloadGroupFriendReplyPacket &rhs)
00214 {
00215         *((InPacket *)this) = (InPacket)rhs;
00216         nextStartID = rhs.getNextStartID();
00217         friends = rhs.getGroupedFriends();
00218         return *this;
00219 }
00220 
00221 void DownloadGroupFriendReplyPacket::parseBody()
00222 {
00223         friends.clear();
00224         int offset = 6;
00225         int tmp4;
00226         memcpy(&tmp4, decryptedBuf +offset, 4);
00227         offset+=4;
00228         nextStartID = ntohl(tmp4);
00229         
00230         while(bodyLength>offset) {
00231                 DownloadFriendEntry f((char *)(decryptedBuf+offset));
00232                 friends.push_back(f);   
00233                 offset+=f.numberOfBytesRead();
00234         }
00235 }
00236 
00237 /* =========================================================== */
00238 
00239 UploadGroupFriendPacket::UploadGroupFriendPacket()
00240         : OutPacket(QQ_CMD_UPLOAD_GROUP_FRIEND, true)
00241 {
00242 }
00243 
00244 UploadGroupFriendPacket::UploadGroupFriendPacket(const UploadGroupFriendPacket &rhs)
00245         : OutPacket(rhs)
00246 {
00247         privateList = rhs.getGroupedFriends();
00248 }
00249 
00250 UploadGroupFriendPacket::~UploadGroupFriendPacket()
00251 {
00252 }
00253 
00254 UploadGroupFriendPacket &UploadGroupFriendPacket::operator=( const UploadGroupFriendPacket &rhs)
00255 {
00256         *( (OutPacket *)this) = (OutPacket)rhs;
00257         privateList = rhs.getGroupedFriends();
00258         return *this;
00259 }
00260 
00261 int UploadGroupFriendPacket::putBody(unsigned char* buf)
00262 {
00263         std::map<int, int>::iterator iter;
00264         int tmp4;
00265         int pos = 0;
00266         for(iter =privateList.begin(); iter != privateList.end(); ++iter){
00267                 tmp4 = htonl(iter->first);
00268                 memcpy(buf+pos, &tmp4, 4);
00269                 pos+=4;
00270                 buf[pos++] = (unsigned char)(iter->second);
00271         }
00272         return pos;
00273 }
00274 
00275 /* =========================================================== */
00276 
00277 UploadGroupFriendReplyPacket::UploadGroupFriendReplyPacket(unsigned char* buf, int len)
00278         : InPacket(buf, len)
00279 {
00280 }
00281 
00282 UploadGroupFriendReplyPacket::UploadGroupFriendReplyPacket(const UploadGroupFriendReplyPacket &rhs)
00283         : InPacket(rhs)
00284 {
00285         replyCode = rhs.getReplyCode();
00286 }
00287 
00288 UploadGroupFriendReplyPacket::~UploadGroupFriendReplyPacket()
00289 {
00290 }
00291 
00292 UploadGroupFriendReplyPacket &UploadGroupFriendReplyPacket::operator=(const UploadGroupFriendReplyPacket &rhs)
00293 {
00294         *((InPacket *)this) = (InPacket)rhs;
00295         replyCode = rhs.getReplyCode();
00296         return *this;
00297 }
00298 
00299 void UploadGroupFriendReplyPacket::parseBody()
00300 {
00301         replyCode = decryptedBuf[0];
00302 }
00303 
00304 
00305 
00306 
00307 
00308 
00309 
00310 

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