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

evamemo.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 "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; //0x01 is the upload memo option
00062                 buf[pos++] = 0x00; //unknow byte
00063                 pos += EvaUtil::write32( buf+pos, m_Id);//qq number
00064                 buf[pos++] = 0x00; //unknow byte
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; //0x02 is the remove memo option
00076                 pos += EvaUtil::write32( buf+pos,m_Id);//qq number
00077                 }
00078                 break;
00079         case 0x03:{
00080                 buf[pos++] = QQ_MEMO_DOWNLOAD; //0x03 is the download memo option
00081                 pos += EvaUtil::write32( buf+pos,m_Id);//qq number
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);//get the qq number
00139                         pos += 5; //included an ignored unknow byte
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);//if there is no user memo on the server,then set the qq number zero;
00154                         }
00155                 }
00156                 break;
00157         }
00158         
00159 }

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