[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdenetwork/kopete/protocols/qq
From:       Hui Jin <blueangel.jin () gmail ! com>
Date:       2006-07-12 7:55:07
Message-ID: 1152690907.633204.23957.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 561489 by blueangel:

Bravo, login successfully.

Refactored the Packet::duplicate for easy use.
TODO: fetch the group list.




 M  +34 -10    libeva.h  
 M  +20 -16    qqnotifysocket.cpp  
 M  +1 -0      qqnotifysocket.h  


--- trunk/KDE/kdenetwork/kopete/protocols/qq/libeva.h #561488:561489
@@ -137,14 +137,11 @@
 			copyAt( m_size, d, s );
 		}
 
-		void duplicate( const char* d, int s )
+		static ByteArray duplicate( const char* d, int s )
 		{
-			if( m_itsOwn )
-				free( m_data );
-			m_data = (char*)malloc(s);
-			memcpy( m_data, d, s );
-			m_size = m_capacity = s;
-			m_itsOwn = true;
+			ByteArray x(s);
+			x.append( d, s );
+			return x;
 		}
 
         int size() const { return m_size; }
@@ -194,7 +191,7 @@
 			pos += 2;
 
 			int len = size - pos - 1; // 1 is tail
-			m_body.duplicate( buffer+pos, len );
+			m_body = ByteArray::duplicate( buffer+pos, len );
 		}
 
 		short version() const { return m_version; }
@@ -203,10 +200,37 @@
 		ByteArray& body() { return m_body; }
 
 		static inline char replyCode( ByteArray& data ) { return data.data()[0]; }
-		static inline int redirectedIP( ByteArray& data ) { return ntohl( type_cast<int> \
                (data.data()+5) ); }
-		static inline int redirectedPort( ByteArray& data ) { return ntohs( \
type_cast<short> (data.data()+9) ); }  
+		static inline int redirectedIP( ByteArray& data ) 
+		{ return ntohl( type_cast<int> (data.data()+5) ); }
 
+		static inline int redirectedPort( ByteArray& data ) 
+		{ return ntohs( type_cast<short> (data.data()+9) ); }
+
+		static inline ByteArray sessionKey( ByteArray& data ) 
+		{ return ByteArray::duplicate( data.data()+1, KeyLength ); }
+
+		static inline int remoteIP( ByteArray& data ) 
+		{ return ntohl( type_cast<int> (data.data()+27) ); }
+
+		static inline int remotePort( ByteArray& data ) 
+		{ return ntohs( type_cast<short> (data.data()+31) ); }
+
+		static inline int localIP( ByteArray& data ) 
+		{ return ntohl( type_cast<int> (data.data()+21) ); }
+
+		static inline int localPort( ByteArray& data ) 
+		{ return ntohs( type_cast<short> (data.data()+25) ); }
+
+		static inline int loginTime( ByteArray& data ) 
+		{ return ntohl( type_cast<int> (data.data()+33) ); }
+
+		static inline int lastLoginFrom( ByteArray& data ) 
+		{ return ntohl( type_cast<int> (data.data()+123) ); }
+
+		static inline int lastLoginTime( ByteArray& data ) 
+		{ return ntohl( type_cast<int> (data.data()+127) ); }
+
 	private:
 		short m_version;
 		short m_command;
--- trunk/KDE/kdenetwork/kopete/protocols/qq/qqnotifysocket.cpp #561488:561489
@@ -135,18 +135,13 @@
 	kDebug( 14140 ) << k_funcinfo << rawdata << endl;
 	Eva::Packet packet( rawdata.data(), rawdata.size() );
 	Eva::ByteArray text;
-	
-	char login_test[] = {
-		0x1, 0xdf, 0x25, 0xd2, 0x9e, 0xdb, 0x9, 0xef, 0xd4, 0xf1, 0x12, 0x8f, 0x61, 0x21, \
                0x63, 0x68, 0x37, 0xed, 0x88, 0x36, 0x3, 0xb2, 0x6c, 0x44 };
-		
-	Eva::ByteArray test( login_test, 24);
-	test.release();
 
 	Eva::ByteArray initKey((char*) Eva::getInitKey(), 16 );
 	initKey.release();
 
 	switch( packet.command() )
 	{
+		// FIXME: use table-driven pattern ?
 		case Eva::Logout :
 		case Eva::KeepAlive :
 		case Eva::UpdateInfo :
@@ -162,19 +157,14 @@
 		case Eva::RemoveMe :
 		case Eva::RequestKey :
 		case Eva::GetCell :
+			break;
+
 		case Eva::Login :
-			//kDebug( 14140 ) << packet.command() << ": crypted body = " <<
-			//	QByteArray( packet.body().data(), packet.body().size() ) << endl;
-			// insert the testing:
-
-			kDebug( 14140 ) << packet.command() << ": crypted body = " <<
-				QByteArray( test.data(), test.size() ) << endl;
-			// text = Eva::decrypt( packet.body(), m_passwordKey );
-			text = Eva::decrypt( test, m_passwordKey );
+			text = Eva::decrypt( packet.body(), m_passwordKey );
 			if ( text.size() == 0 )
 			{
 			kDebug( 14140 ) << "initKey size = " << initKey.size() << ", data =" << \
                QByteArray( initKey.data(), initKey.size() ) << endl;
-				text = Eva::decrypt( test, initKey );
+				text = Eva::decrypt( packet.body(), initKey );
 			}
 			
 			kDebug( 14140 ) << "text size = " << text.size() << ", data =" <<
@@ -183,10 +173,24 @@
 			switch( Eva::Packet::replyCode(text)  )
 			{
 				case Eva::LoginOK:
+					kDebug( 14140 ) << "Bingo! QQ:#" << m_qqId << " logged in!" << endl;
+					// show off some meta data :
+					m_sessionKey = Eva::Packet::sessionKey(text);
+					kDebug( 14140 ) << "sessionKey = " << 
+						QByteArray( m_sessionKey.data(), m_sessionKey.size() ) << endl;
+
+					kDebug( 14140 )  << "remote IP: " << QHostAddress( Eva::Packet::remoteIP(text) \
).toString() << endl; +					kDebug( 14140 )  << "remote port: " << \
Eva::Packet::remotePort(text) << endl; +					kDebug( 14140 )  << "local IP: " << \
QHostAddress( Eva::Packet::localIP(text) ).toString() << endl; +					kDebug( 14140 )  \
<< "local port: " << Eva::Packet::localPort(text) << endl; +					kDebug( 14140 )  << \
"login time: " << Eva::Packet::loginTime(text) << endl; +					kDebug( 14140 )  << \
"last login from: " << QHostAddress( Eva::Packet::lastLoginFrom(text) ).toString() << \
endl; +					kDebug( 14140 )  << "last login time: " << \
Eva::Packet::lastLoginTime(text) << endl; +					// TODO: set the client status to \
connected. +					
 					break;
 
 				case Eva::LoginRedirect :
-					// TODO: do we need to call htonl ?
 					kDebug( 14140 ) << "Redirect to " 
 						<< QHostAddress(Eva::Packet::redirectedIP(text)).toString()
 						<< " : " << Eva::Packet::redirectedPort(text) << endl;
--- trunk/KDE/kdenetwork/kopete/protocols/qq/qqnotifysocket.h #561488:561489
@@ -107,6 +107,7 @@
 	 * Twice Md5 hashed password
 	 */
 	Eva::ByteArray m_passwordKey;
+	Eva::ByteArray m_sessionKey;
 	char m_loginMode;
 	// FIXME: Do we need this ?
 	QString m_password;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic