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

evafriend.cpp

Go to the documentation of this file.
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 #include "evafriend.h"
00021 #include "evadefines.h"
00022 #include <string.h>
00023 #ifdef _WIN32
00024 #include <winsock.h>
00025 #else
00026 #include <arpa/inet.h>
00027 #endif
00028 
00029 FriendItem::FriendItem()
00030         :qqNum(0), mIsOnline(false)
00031 {
00032         qunGroupIndex = 0;
00033         qunAdminValue = 0;
00034 }
00035 
00036 FriendItem::FriendItem(const unsigned char *buf, int *len)
00037         : mIsOnline(false)
00038 {
00039     parseData(buf, len);
00040 }
00041 
00042 FriendItem::FriendItem(const FriendItem &rhs)
00043 {
00044         *this = rhs;
00045 }
00046 
00047 FriendItem &FriendItem::operator=(const FriendItem &rhs)
00048 {
00049         qqNum = rhs.getQQ();
00050         face = rhs.getFace() ;
00051         age = rhs.getAge();
00052         gender = rhs.getGender();
00053         nick = rhs.getNick();
00054         extFlag = rhs.getExtFlag();
00055         commonFlag = rhs.getCommonFlag();
00056         loginTime = rhs.getLoginTime();
00057         idleTime = rhs.getIdleTime();
00058         lastRefreshTime = rhs.getLastRefreshTime();
00059         mIsOnline = rhs.isOnline();
00060         qunGroupIndex = rhs.getQunGroupIndex();
00061         qunAdminValue = rhs.getQunAdminValue();
00062         m_QunRealName = rhs.getQunRealName();    // original by henry
00063         return *this;
00064 }
00065 
00066 void FriendItem::parseData(const unsigned char *buf, int *len)
00067 {
00068         int qqtemp;
00069         memcpy(&qqtemp, buf, 4);
00070         qqNum = ntohl(qqtemp);
00071         short tmp2;
00072         memcpy(&tmp2, buf+4, 2);
00073         face = ntohs(tmp2);
00074         age = buf[6];
00075         gender = buf[7];
00076         int nickLen = (int)(buf[8]);
00077         char *b = (char *)malloc( (nickLen+1)*sizeof(char)); 
00078         memcpy(b, buf+9, nickLen);
00079         b[nickLen]=0x00;
00080         nick.assign(b);
00081         free(b);
00082         // 2 bits unknown, ignore
00083         extFlag = buf[9+nickLen+2];
00084         commonFlag = buf[9+nickLen+3];
00085         *len = 9+nickLen+4;
00086 }
00087 
00088 /*  ======================================================= */
00089 
00090 GetFriendListPacket::GetFriendListPacket() 
00091         : OutPacket(QQ_CMD_GET_FRIEND_LIST, true),
00092           startPosition(QQ_FRIEND_LIST_POSITION_START)
00093 { 
00094 }
00095 
00096 GetFriendListPacket::GetFriendListPacket(const short startPosition)
00097         : OutPacket(QQ_CMD_GET_FRIEND_LIST, true),
00098           startPosition(startPosition)
00099 {
00100 }
00101 
00102 GetFriendListPacket::GetFriendListPacket(const GetFriendListPacket &rhs)
00103         : OutPacket(rhs)
00104 {
00105         startPosition = rhs.getStartPosition();
00106 }
00107 
00108 GetFriendListPacket &GetFriendListPacket::operator=( const GetFriendListPacket &rhs)
00109 {
00110         *((OutPacket*)this) = (OutPacket)rhs;
00111         startPosition = rhs.getStartPosition();
00112         return *this;
00113 }
00114 
00115 int GetFriendListPacket::putBody(unsigned char *buf)
00116 {
00117         short pos = htons(startPosition);
00118         memcpy(buf, &pos, 2);
00119         
00120         buf[2] = QQ_FRIEND_LIST_SORTED;
00121         buf[3] = 0x00;
00122         buf[4] = 0x01;
00123         return 5;
00124 }
00125 
00126 /*  ======================================================= */
00127 
00128 GetFriendListReplyPacket::GetFriendListReplyPacket(unsigned char *buf, int len)
00129         : InPacket(buf, len)
00130 {    
00131 }
00132 
00133 GetFriendListReplyPacket::GetFriendListReplyPacket(const GetFriendListReplyPacket &rhs)
00134         :InPacket(rhs)
00135 {
00136         position = rhs.getPosition();
00137         friends = rhs.getFriendList();
00138 }
00139 
00140 GetFriendListReplyPacket &GetFriendListReplyPacket::operator=( const GetFriendListReplyPacket &rhs)
00141 {
00142         *((InPacket *)this) = (InPacket)rhs;
00143         position = rhs.getPosition();
00144         friends = rhs.getFriendList();
00145         return *this;
00146 }
00147 
00148 void GetFriendListReplyPacket::parseBody()
00149 {
00150         short pos;
00151         memcpy(&pos, decryptedBuf, 2);
00152         position = ntohs(pos);
00153         int offset = 2;
00154         while(bodyLength > offset) {
00155                 int tmp=0;
00156                 friends.push_back(FriendItem(decryptedBuf+offset, &tmp));       
00157                 offset+=tmp;
00158         }
00159 }
00160 
00161 
00162  

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