00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "evamemo.h"
00021 #include "evautil.h"
00022
00023 EvaMemoPacket::EvaMemoPacket( const int id, const unsigned char type )
00024 :OutPacket( QQ_CMD_MEMO_OP, true ), m_Id( id ), m_Type( type )
00025 {
00026 }
00027
00028 EvaMemoPacket::EvaMemoPacket( const EvaMemoPacket &rhs )
00029 :OutPacket( rhs )
00030 {
00031 (*this) = rhs;
00032 }
00033
00034 EvaMemoPacket &EvaMemoPacket::operator=( const EvaMemoPacket & rhs )
00035 {
00036 *((OutPacket *)this) = (OutPacket)rhs;
00037 m_Id = rhs.getQQ();
00038 m_Type = rhs.getType();
00039 m_Memo = rhs.getMemo();
00040 return *this;
00041 }
00042
00043 void EvaMemoPacket::setDetails( const MemoItem &memo)
00044 {
00045 m_Infos.push_back( memo.name );
00046 m_Infos.push_back( memo.mobile );
00047 m_Infos.push_back( memo.telephone );
00048 m_Infos.push_back( memo.address );
00049 m_Infos.push_back( memo.email );
00050 m_Infos.push_back( memo.zipcode );
00051 m_Infos.push_back( memo.note );
00052 }
00053
00054 int EvaMemoPacket::putBody( unsigned char *buf )
00055 {
00056 int pos = 0;
00057 int len = 0;
00058 setDetails(m_Memo);
00059 switch(m_Type){
00060 case 0x01:{
00061 buf[pos++] = QQ_MEMO_UPLOAD;
00062 buf[pos++] = 0x00;
00063 pos += EvaUtil::write32( buf+pos, m_Id);
00064 buf[pos++] = 0x00;
00065
00066 for(int i=0; i<QQ_MEMO_FIELDS; i++){
00067 len = m_Infos.at(i).length();
00068 buf[pos++] = 0xff & len;
00069 memcpy(buf+pos, m_Infos.at(i).c_str(), len);
00070 pos += len;
00071 }
00072 }
00073 break;
00074 case 0x02:{
00075 buf[pos++] = QQ_MEMO_REMOVE;
00076 pos += EvaUtil::write32( buf+pos,m_Id);
00077 }
00078 break;
00079 case 0x03:{
00080 buf[pos++] = QQ_MEMO_DOWNLOAD;
00081 pos += EvaUtil::write32( buf+pos,m_Id);
00082 }
00083 break;
00084 }
00085 return pos;
00086 }
00087
00088
00089 EvaMemoReplyPacket::EvaMemoReplyPacket( unsigned char *buf, int len )
00090 :InPacket( buf, len )
00091 {
00092 }
00093
00094 EvaMemoReplyPacket::EvaMemoReplyPacket( const EvaMemoReplyPacket &rhs )
00095 :InPacket( rhs )
00096 {
00097 m_Memo = rhs.getMemo();
00098 }
00099
00100 EvaMemoReplyPacket &EvaMemoReplyPacket::operator=( const EvaMemoReplyPacket &rhs )
00101 {
00102 *((InPacket *)this) = (InPacket)rhs;
00103 m_Type = rhs.getType();
00104 m_ReplyCode = rhs.getReplyCode();
00105 m_Memo = rhs.getMemo();
00106 m_Id = rhs.getQQ();
00107 return *this;
00108 }
00109
00110 void EvaMemoReplyPacket::setMemo( const stringList &infos )
00111 {
00112 m_Memo.name = infos.at(0);
00113 m_Memo.mobile = infos.at(1);
00114 m_Memo.telephone = infos.at(2);
00115 m_Memo.address = infos.at(3);
00116 m_Memo.email = infos.at(4);
00117 m_Memo.zipcode = infos.at(5);
00118 m_Memo.note = infos.at(6);
00119 }
00120
00121 void EvaMemoReplyPacket::parseBody()
00122 {
00123 int pos = 0;
00124 int len = 0;
00125 switch(decryptedBuf[pos++]){
00126 case 0x01:
00127
00128 m_Type = QQ_MEMO_UPLOAD;
00129 m_ReplyCode = decryptedBuf[pos];
00130 break;
00131 case 0x02:
00132 m_Type = QQ_MEMO_REMOVE;
00133 m_ReplyCode = decryptedBuf[pos];
00134 break;
00135 case 0x03:{
00136 m_Type = QQ_MEMO_DOWNLOAD;
00137 if(bodyLength>1){
00138 m_Id = EvaUtil::read32(decryptedBuf+pos);
00139 pos += 5;
00140
00141 for( int i=0; i<QQ_MEMO_FIELDS; i++ ){
00142 len = decryptedBuf[pos++];
00143 char *str = new char[len+1];
00144 memcpy(str, decryptedBuf+pos, len); pos += len;
00145 str[len] = 0x00;
00146 m_Infos.push_back(std::string(str));
00147 delete[] str;
00148 }
00149 setMemo(m_Infos);
00150 }
00151 else{
00152 printf("no memo on the server,set user qq number to zero\n");
00153 setQQ(0);
00154 }
00155 }
00156 break;
00157 }
00158
00159 }