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

evauserinfo.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 "evauserinfo.h"
00021 #include "evadefines.h"
00022 
00023 // important: all string stored are encoded by "GB18030"
00024 
00025 ContactInfo::ContactInfo() 
00026 { 
00027         infos.reserve(QQ_CONTACT_FIELDS); 
00028         infos.push_back("-");   // qq number 
00029         infos.push_back("EVA");   // nick
00030 };
00031 
00032 ContactInfo::ContactInfo(const unsigned char *buf, const int len)  
00033 {
00034         parseData(buf, len);
00035 }
00036 
00037 ContactInfo::ContactInfo( const ContactInfo &rhs)
00038 {
00039         infos = rhs.details();  
00040 }
00041 
00042 void ContactInfo::parseData(const unsigned char *buf, const int len)  
00043 {
00044         int start = 0;
00045         infos.clear();
00046         for(int i = 0; i< len; i++){
00047                 if(buf[i]!= DIVIDER) continue;
00048                 char *tmp = (char *)malloc( (i-start+1) *sizeof(char));
00049                 memcpy(tmp, buf+start, i-start);
00050                 tmp[i-start] = 0x00;
00051                 infos.push_back(std::string(tmp));
00052                 start = i+1;
00053                 free(tmp);
00054         }
00055         if(infos.size()< (uint)QQ_CONTACT_FIELDS){
00056                 char *tmp = (char *)malloc( (len-start+1) *sizeof(char));
00057                 memcpy(tmp, buf+start, len-start);
00058                 tmp[len-start]=0x00;
00059                 infos.push_back(std::string(tmp));
00060                 free(tmp);
00061         }
00062 }
00063 
00064 bool ContactInfo::operator== ( const ContactInfo &rhs ) const
00065 {
00066     if( infos.size() != rhs.details().size() ) return false;    
00067     return (infos==rhs.details());
00068 }
00069 
00070 ContactInfo &ContactInfo::operator= ( const ContactInfo &rhs )
00071 {
00072         if( this == &rhs)   return *this;    
00073         infos = rhs.details();    
00074         return *this;
00075 }
00076 
00077 /*  ======================================================= */
00078 
00079 GetUserInfoPacket::GetUserInfoPacket()
00080         : OutPacket(QQ_CMD_GET_USER_INFO, true),
00081           qqNum(-1)
00082 {
00083 }
00084 
00085 GetUserInfoPacket::GetUserInfoPacket(const int id)
00086         : OutPacket(QQ_CMD_GET_USER_INFO, true),
00087           qqNum(id)
00088 {
00089 }
00090 
00091 GetUserInfoPacket::GetUserInfoPacket(const GetUserInfoPacket &rhs)
00092         : OutPacket(rhs)
00093 {
00094         qqNum = rhs.getUserQQ();
00095 }
00096 
00097 GetUserInfoPacket &GetUserInfoPacket::operator=(const GetUserInfoPacket &rhs)
00098 {
00099         *((OutPacket *)this) = (OutPacket)rhs;
00100         qqNum = rhs.getUserQQ();
00101         return *this;
00102 }
00103 
00104 int GetUserInfoPacket::putBody(unsigned char *buf)
00105 {
00106     sprintf((char *)buf, "%d", qqNum);
00107     return strlen((char *)buf);
00108 }
00109 
00110 /*  ======================================================= */
00111 
00112 GetUserInfoReplyPacket::GetUserInfoReplyPacket(unsigned char *buf, int len)
00113         : InPacket( buf, len)
00114 {
00115 }
00116 
00117 GetUserInfoReplyPacket::GetUserInfoReplyPacket( const GetUserInfoReplyPacket &rhs)
00118         : InPacket(rhs)
00119 {
00120         mContactInfo = rhs.contactInfo();
00121 }
00122 
00123 GetUserInfoReplyPacket &GetUserInfoReplyPacket::operator=(const GetUserInfoReplyPacket &rhs)
00124 {
00125         *((InPacket *)this) = (InPacket)rhs;
00126         mContactInfo = rhs.contactInfo();
00127         return *this;
00128 }
00129 
00130 void GetUserInfoReplyPacket::parseBody() 
00131 {
00132         mContactInfo.parseData(decryptedBuf, bodyLength);
00133         int j = mContactInfo.details().size();
00134         if(j < QQ_CONTACT_FIELDS)
00135                 fprintf(stderr, "GetUserInfoReply->parseBody: number of fields wrong\n");
00136         else if(j > QQ_CONTACT_FIELDS)
00137                 fprintf(stderr, "GetUserInfoReply->parseBody: number of fields might be wrong!\n");
00138 }
00139 
00140 /*  ======================================================= */
00141 
00142 ModifyInfoPacket::ModifyInfoPacket( ) 
00143         : OutPacket(QQ_CMD_MODIFY_INFO, true)
00144 {
00145 }
00146 
00147 ModifyInfoPacket::ModifyInfoPacket( const ContactInfo & info )
00148         : OutPacket(QQ_CMD_MODIFY_INFO, true),
00149         newInfo(info), currentPwd(""), newPwd("")
00150 {
00151 }
00152 
00153 ModifyInfoPacket::ModifyInfoPacket( const ModifyInfoPacket & rhs )
00154         : OutPacket(rhs)
00155 {
00156         currentPwd = rhs.getPassword();
00157         newPwd = rhs.getNewPassword();
00158         newInfo = rhs.getContactInfo();
00159 }
00160 
00161 ModifyInfoPacket & ModifyInfoPacket::operator =( const ModifyInfoPacket & rhs )
00162 {
00163         *((OutPacket*)this) = (OutPacket)rhs;
00164         currentPwd = rhs.getPassword();
00165         newPwd = rhs.getNewPassword();
00166         newInfo = rhs.getContactInfo(); 
00167         return *this;
00168 }
00169 
00170 int ModifyInfoPacket::putBody( unsigned char * buf )
00171 {
00172         int pos=0;      
00173         if( currentPwd != "" && newPwd != ""){
00174                 memcpy(buf, currentPwd.c_str(), currentPwd.length());
00175                 pos+=currentPwd.length();
00176                 buf[pos++] = DELIMIT;
00177                 memcpy(buf+pos, newPwd.c_str(), newPwd.length());
00178                 pos+=newPwd.length();
00179         }else
00180                 buf[pos++] = DELIMIT;
00181         
00182         buf[pos++] = DELIMIT;
00183         
00184         for(int i=1; i<QQ_CONTACT_FIELDS; i++){
00185                 memcpy(buf+pos, newInfo.at(i).c_str(),newInfo.at(i).length());
00186                 pos+=newInfo.at(i).length();
00187                 buf[pos++] = DELIMIT;
00188         }
00189         return pos;
00190 }
00191 
00192 /*  ======================================================= */
00193 
00194 ModifyInfoReplyPacket::ModifyInfoReplyPacket( unsigned char * buf, int len )
00195         : InPacket(buf, len),
00196         accepted(false)
00197 {
00198 }
00199 
00200 ModifyInfoReplyPacket::ModifyInfoReplyPacket( const ModifyInfoReplyPacket & rhs )
00201         : InPacket(rhs)
00202 {
00203         accepted = rhs.isAccepted();
00204 }
00205 
00206 ModifyInfoReplyPacket & ModifyInfoReplyPacket::operator =( const ModifyInfoReplyPacket & rhs )
00207 {
00208         *((InPacket*)this) = (InPacket)rhs;
00209         accepted = rhs.isAccepted();
00210         return *this;
00211 }
00212 
00213 void ModifyInfoReplyPacket::parseBody( )
00214 {
00215         char *str = (char *)malloc((bodyLength+1) * sizeof(char));
00216         memcpy(str, decryptedBuf, bodyLength);
00217         str[bodyLength]=0x00;
00218         
00219         char myQQ[20];
00220         sprintf(myQQ, "%d", getQQ());
00221         char *pos = strstr(str, myQQ);
00222         if( pos != str )
00223                 accepted = false;
00224         else
00225                 accepted = true;
00226 }
00227 

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