00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "evauserinfo.h"
00021 #include "evadefines.h"
00022
00023
00024
00025 ContactInfo::ContactInfo()
00026 {
00027 infos.reserve(QQ_CONTACT_FIELDS);
00028 infos.push_back("-");
00029 infos.push_back("EVA");
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