00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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);
00129 }
00130 }
00131