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

evalogintoken.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 
00021 #include "evalogintoken.h"
00022 #include "evadefines.h"
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 RequestLoginTokenPacket::RequestLoginTokenPacket()
00028         : OutPacket(QQ_CMD_REQUEST_LOGIN_TOKEN, true)
00029 {
00030 }
00031 
00032 RequestLoginTokenPacket::RequestLoginTokenPacket( const RequestLoginTokenPacket & rhs )
00033         : OutPacket(rhs)
00034 {
00035 }
00036 
00037 RequestLoginTokenPacket & RequestLoginTokenPacket::operator =( const RequestLoginTokenPacket &rhs)
00038 {
00039         *((OutPacket *)this) = (OutPacket)rhs;
00040         return *this;
00041 }
00042 
00043 int RequestLoginTokenPacket::putBody( unsigned char * buf )
00044 {
00045         buf[0]=0x00;
00046         return 1;
00047 }
00048 
00049 
00050 
00051 
00052 
00055 RequestLoginTokenReplyPacket::RequestLoginTokenReplyPacket()
00056         : InPacket(), replyCode(0x01), length(0), 
00057         token(NULL)
00058 {
00059 }
00060 
00061 RequestLoginTokenReplyPacket::RequestLoginTokenReplyPacket( unsigned char * buf, int len )
00062         : InPacket(buf, len), replyCode(0x01), length(0), 
00063         token(NULL)
00064 {
00065 }
00066 
00067 RequestLoginTokenReplyPacket::RequestLoginTokenReplyPacket( const RequestLoginTokenReplyPacket & rhs )
00068         : InPacket(rhs), replyCode(0x01), length(0), 
00069         token(NULL)
00070 {
00071         replyCode = rhs.getReplyCode();
00072         length = rhs.getTokenLength();
00073         if(length){
00074                 if(!token)
00075                         token = (unsigned char *)malloc(length * sizeof(unsigned char));
00076                 if(!token){
00077                         length = 0;
00078                         fprintf(stderr, "RequestLoginTokenReplyPacket( const RequestLoginTokenReplyPacket & rhs ): malloc() failed\n");
00079                         return;
00080                 }
00081                 memcpy(token, rhs.getToken(), length);
00082         }
00083 }
00084 
00085 RequestLoginTokenReplyPacket::~RequestLoginTokenReplyPacket()
00086 {
00087         if(token)
00088                 free(token);
00089 }
00090 
00091 RequestLoginTokenReplyPacket & RequestLoginTokenReplyPacket::operator =( const RequestLoginTokenReplyPacket & rhs )
00092 {
00093         *((InPacket *)this) = (InPacket)rhs;
00094         replyCode = rhs.getReplyCode();
00095         length = rhs.getTokenLength();
00096         if(length){
00097                 if(!token)
00098                         token = (unsigned char *)malloc(length * sizeof(unsigned char));
00099                 if(!token){
00100                         length = 0;
00101                         fprintf(stderr, "RequestLoginTokenReplyPacket( const RequestLoginTokenReplyPacket & rhs ): malloc() failed\n");
00102                         return *this;
00103                 }
00104                 memcpy(token, rhs.getToken(), length);
00105         }
00106         return *this;
00107 }
00108 
00109 const bool RequestLoginTokenReplyPacket::isReplyOk( )  const
00110 {
00111         return replyCode == QQ_REQUEST_LOGIN_TOKEN_REPLY_OK;
00112 }
00113 
00114 void RequestLoginTokenReplyPacket::parseBody( )
00115 {
00116         replyCode = decryptedBuf[0];
00117         if(replyCode == QQ_REQUEST_LOGIN_TOKEN_REPLY_OK){
00118                 length = decryptedBuf[1];
00119                 if(token)
00120                         free(token);
00121                 token = (unsigned char *)malloc(length * sizeof(unsigned char));                
00122                 if(!token){
00123                         length = 0;
00124                         fprintf(stderr, "RequestLoginTokenReplyPacket( const RequestLoginTokenReplyPacket & rhs ): malloc() failed\n");
00125                         return;
00126                 }
00127                 memcpy(token, decryptedBuf + 2, length);
00128                 setLoginToken(token, length); // we set the loginToken now
00129         }
00130 }
00131 

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