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

evasearchuser.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 #include "evasearchuser.h"
00021 
00022 OnlineUser::OnlineUser()
00023 {
00024         qqNum = -1;
00025         nick = "";
00026         province = "";
00027         face = 0;
00028 }
00029 
00030 OnlineUser & OnlineUser::operator =( const OnlineUser & rhs )
00031 {
00032         qqNum = rhs.getQQ();
00033         nick = rhs.getNick();
00034         face = rhs.getFace();
00035         return *this;
00036 }
00037 
00038 int OnlineUser::readData( unsigned char * buf )
00039 {
00040         int i = 0;
00041         int start = 0;
00042         int offset=0;
00043         char tmp[256];
00044         while(1){
00045                 if(offset>60) break;
00046                 if(buf[offset]!=0x1e && buf[offset]!=0x1f)
00047                         offset++;
00048                 else{
00049                         memset(tmp, 0, 256);
00050                         memcpy(tmp, buf+start, offset-start);
00051                         tmp[offset]=0x00;
00052                         if(i==0)
00053                                 qqNum = atoi(tmp);
00054                         if(i==1)
00055                                 nick = tmp;
00056                         if(i==2)
00057                                 province = tmp;
00058                         if(i==3){
00059                                 face = atoi(tmp);
00060                                 break;
00061                         }
00062                         i++;                            
00063                         start = ++offset;
00064                 }
00065         }        
00066         // the last byte is 0x1f
00067         return offset+1;
00068 }
00069 
00070 /*----------------------------------------------------------------------------------------------*/
00071 
00072 SearchUserPacket::SearchUserPacket( )
00073         :OutPacket(QQ_CMD_SEARCH_USER, true),
00074         searchType(QQ_SEARCH_ALL),
00075         page("0"),
00076         qqStr(""), nick(""), email(""),
00077         matchEntireString(false)
00078 {
00079 }
00080 
00081 SearchUserPacket::SearchUserPacket( SearchUserPacket & rhs )
00082         : OutPacket(rhs)
00083 {
00084         page = rhs.getPage();
00085         searchType = rhs.getSearchType();
00086         qqStr = rhs.getQQ();
00087         nick = rhs.getNick();
00088         email = rhs.getEmail();
00089         matchEntireString = rhs.getMatchEntireString();
00090 }
00091 
00092 void SearchUserPacket::setPage( const int p )
00093 {
00094         char tmp[255];
00095         sprintf(tmp,"%d", p);
00096         page = tmp;
00097 }
00098 
00099 void SearchUserPacket::setQQ( const int qqNum )
00100 {
00101         char tmp[255];
00102         sprintf(tmp,"%d", qqNum);
00103         qqStr = tmp;    
00104 }
00105 
00106 SearchUserPacket & SearchUserPacket::operator =( const SearchUserPacket & rhs )
00107 {
00108         *((OutPacket *)this) = (OutPacket)rhs;
00109         page = rhs.getPage();
00110         searchType = rhs.getSearchType();
00111         qqStr = rhs.getQQ();
00112         nick = rhs.getNick();
00113         email = rhs.getEmail();
00114         matchEntireString = rhs.getMatchEntireString(); 
00115         return *this;
00116 }
00117 
00118 int SearchUserPacket::putBody( unsigned char * buf )
00119 {
00120         int offset = 0;      
00121         
00122         if(searchType == QQ_SEARCH_ALL) {
00123                 buf[offset++] = searchType;
00124                 buf[offset++] = DIVIDER;
00125                 memcpy(buf+offset, page.c_str(), page.length());
00126                 offset+=page.length();                  
00127         } else if(searchType == QQ_SEARCH_CUSTOM) {
00128                 buf[offset++] = searchType;
00129                 buf[offset++] = DIVIDER;
00130                                                 
00131                 if(!qqStr.length()) 
00132                         buf[offset++] = NULL_FIELD;
00133                 else{ 
00134                         memcpy(buf+offset, qqStr.c_str(), qqStr.length());
00135                         offset+=qqStr.length(); 
00136                 }
00137                 
00138                 buf[offset++] = DIVIDER;                        
00139                 
00140                 if(!nick.length()) 
00141                         buf[offset++] = NULL_FIELD;
00142                 else {
00143                         memcpy(buf+offset, nick.c_str(),  nick.length());
00144                         offset+= nick.length();
00145                         if(!matchEntireString)
00146                                 buf[offset++] = PERCENT;
00147                 }
00148                 buf[offset++] = DIVIDER;                        
00149                 
00150                 if(!email.length())
00151                         buf[offset++] = NULL_FIELD;
00152                 else {
00153                         memcpy(buf+offset, email.c_str(), email.length());
00154                         offset+=email.length();
00155                         if(!matchEntireString)
00156                                 buf[offset++] = PERCENT;
00157                 }
00158                 buf[offset++] = DIVIDER;        
00159         
00160                 memcpy(buf+offset, page.c_str(), page.length());
00161                 offset+=page.length();          
00162                 
00163                 buf[offset++] = 0x00;
00164         }
00165         return offset;
00166 }
00167 
00168 
00169 /*----------------------------------------------------------------------------------------------*/
00170 
00171 
00172 SearchUserReplyPacket::SearchUserReplyPacket( unsigned char * buf, int len )
00173         : InPacket(buf, len),
00174         finished(false)
00175 {
00176 }
00177 
00178 SearchUserReplyPacket::SearchUserReplyPacket( const SearchUserReplyPacket & rhs )
00179         : InPacket(rhs)
00180 {
00181         finished = rhs.isFinished();
00182         users = rhs.getUsers();
00183 }
00184 
00185 SearchUserReplyPacket & SearchUserReplyPacket::operator =( const SearchUserReplyPacket & rhs )
00186 {
00187         *((InPacket *)this) = (InPacket)rhs;
00188         finished = rhs.isFinished();
00189         users = rhs.getUsers(); 
00190         return *this;
00191 }
00192 
00193 void SearchUserReplyPacket::parseBody( )
00194 {
00195         if( bodyLength == 0 || decryptedBuf[0] == 0x2D && decryptedBuf[1] == 0x31) {
00196                 finished = true;
00197                 return;
00198         }
00199         finished = false;
00200         int offset=0;
00201         users.clear();
00202         while(offset<bodyLength) {
00203                 OnlineUser onlineUser;
00204                 offset+=onlineUser.readData(decryptedBuf + offset);
00205                 users.push_back(onlineUser);
00206         }
00207 }
00208 
00209 

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