pidgin: 4076ab07: Patch from ccpaging to clean up some QQ ...

khc at pidgin.im khc at pidgin.im
Mon Mar 24 03:21:18 EDT 2008


-----------------------------------------------------------------
Revision: 4076ab075803f1be812f973fd8b7d6e9d3ebaf27
Ancestor: 86f8b3e5d789c691f873f515a92fe8e111dcab6e
Author: khc at pidgin.im
Date: 2008-03-24T07:14:29
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/4076ab075803f1be812f973fd8b7d6e9d3ebaf27

Modified files:
        libpurple/protocols/qq/buddy_info.c
        libpurple/protocols/qq/buddy_list.c
        libpurple/protocols/qq/buddy_opt.c
        libpurple/protocols/qq/buddy_status.c
        libpurple/protocols/qq/crypt.c
        libpurple/protocols/qq/crypt.h
        libpurple/protocols/qq/file_trans.c
        libpurple/protocols/qq/group_network.c
        libpurple/protocols/qq/im.c
        libpurple/protocols/qq/keep_alive.c
        libpurple/protocols/qq/login_logout.c
        libpurple/protocols/qq/recv_core.c
        libpurple/protocols/qq/send_core.c
        libpurple/protocols/qq/sys_msg.c

ChangeLog: 

Patch from ccpaging to clean up some QQ stuff. I removed the now commented
out qq_crypt() instead of, well, comment it out.


-------------- next part --------------
============================================================
--- libpurple/protocols/qq/buddy_info.c	2d7a65e45a4de016930d039a2644b33d0395b8b3
+++ libpurple/protocols/qq/buddy_info.c	01b0633b978de57a1c5807db1e9188f6e2387497
@@ -541,7 +541,7 @@ void qq_process_modify_info_reply(guint8
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		data[len] = '\0';
 		if (qd->uid == atoi((gchar *) data)) {	/* return should be my uid */
 			purple_debug(PURPLE_DEBUG_INFO, "QQ", "Update info ACK OK\n");
@@ -718,7 +718,7 @@ void qq_process_get_info_reply(guint8 *b
 	data = g_newa(guint8, len);
 	info = NULL;
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		if (NULL == (segments = split_data(data, len, "\x1e", QQ_CONTACT_FIELDS)))
 			return;
 
@@ -828,7 +828,7 @@ void qq_process_get_level_reply(guint8 *
 	
 	decr_len = buf_len;
 	decr_buf = g_new0(guint8, buf_len);
-	if (!qq_crypt(DECRYPT, buf, buf_len, qd->session_key, decr_buf, &decr_len)) {
+	if (!qq_decrypt(buf, buf_len, qd->session_key, decr_buf, &decr_len)) {
 		purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Couldn't decrypt get level packet\n");
 	}
 
============================================================
--- libpurple/protocols/qq/buddy_list.c	e75ee5822361713c3fc476da02c788fea6810e40
+++ libpurple/protocols/qq/buddy_list.c	5cf3df8a59aa6a2ae8386150d23d3c78a6e3bb56
@@ -166,7 +166,7 @@ void qq_process_get_buddies_online_reply
 
 	purple_debug(PURPLE_DEBUG_INFO, "QQ", "processing get_buddies_online_reply\n");
 	
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 
 		_qq_show_packet("Get buddies online reply packet", data, len);
 
@@ -262,7 +262,7 @@ void qq_process_get_buddies_list_reply(g
 	data = g_newa(guint8, len);
 	cursor = data;
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		read_packet_w(data, &cursor, len, &position);
 		/* the following data is buddy list in this packet */
 		i = 0;
@@ -356,7 +356,7 @@ void qq_process_get_all_list_with_group_
 	data = g_newa(guint8, len);
 	cursor = data;
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		read_packet_b(data, &cursor, len, &sub_cmd);
 		g_return_if_fail(sub_cmd == 0x01);
 		read_packet_b(data, &cursor, len, &reply_code);
============================================================
--- libpurple/protocols/qq/buddy_opt.c	b2c9154a9107d0c574dd7b226d296c6a5ba64eb4
+++ libpurple/protocols/qq/buddy_opt.c	b157c45af075db815c8bc2b2f94e89d342aed4f7
@@ -267,7 +267,7 @@ void qq_process_add_buddy_auth_reply(gui
 	data = g_newa(guint8, len);
 	cursor = data;
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		read_packet_b(data, &cursor, len, &reply);
 		if (reply != QQ_ADD_BUDDY_AUTH_REPLY_OK) {
 			purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Add buddy with auth request failed\n");
@@ -297,7 +297,7 @@ void qq_process_remove_buddy_reply(guint
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		cursor = data;
 		read_packet_b(data, &cursor, len, &reply);
 		if (reply != QQ_REMOVE_BUDDY_REPLY_OK) {
@@ -326,7 +326,7 @@ void qq_process_remove_self_reply(guint8
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		cursor = data;
 		read_packet_b(data, &cursor, len, &reply);
 		if (reply != QQ_REMOVE_SELF_REPLY_OK)
@@ -381,7 +381,7 @@ void qq_process_add_buddy_reply(guint8 *
 
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		if (NULL == (segments = split_data(data, len, "\x1f", 2)))
 			return;
 		uid = segments[0];
============================================================
--- libpurple/protocols/qq/buddy_status.c	887e959eba68a8276fbac096374ca1904dbe55a2
+++ libpurple/protocols/qq/buddy_status.c	c0cfe6b3cb7aade33aed915ca8477944e9465e91
@@ -195,7 +195,7 @@ void qq_process_change_status_reply(guin
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		cursor = data;
 		read_packet_b(data, &cursor, len, &reply);
 		if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) {
@@ -232,7 +232,7 @@ void qq_process_friend_change_status(gui
 	data = g_newa(guint8, len);
 	cursor = data;
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		s = g_new0(qq_buddy_status, 1);
 		bytes = 0;
 		/* 000-030: qq_buddy_status */
============================================================
--- libpurple/protocols/qq/crypt.c	312230eb692dbc4c10fc7cb7d63bfb489f8c55b2
+++ libpurple/protocols/qq/crypt.c	7fb56194d3a4c64f9e2998ff1927bd07fdf8a2a8
@@ -99,7 +99,7 @@ static void encrypt_block(guint8 *plain,
 	*is_header = 0;			/* and exit header */
 }					/* encrypt_block */
 
-static void qq_encrypt(const guint8 *const instr, gint instrlen, 
+void qq_encrypt(const guint8 *const instr, gint instrlen, 
 		const guint8 *const key, 
 		guint8 *outstr, gint *outstrlen_ptr)
 {
@@ -211,7 +211,7 @@ static gint decrypt_block(const guint8 *
 }
 
 /* return 0 if failed, 1 otherwise */
-static gint qq_decrypt(const guint8 *const instr, gint instrlen, 
+gint qq_decrypt(const guint8 *const instr, gint instrlen, 
 		const guint8 *const key,
 		guint8 *outstr, gint *outstrlen_ptr)
 {
@@ -296,19 +296,3 @@ static gint qq_decrypt(const guint8 *con
 	}
 	return 1;
 }
-
-/* return 1 is succeed, otherwise return 0 */
-gint qq_crypt(gint flag,
-		const guint8 *const instr, gint instrlen, 
-		const guint8 *const key, 
-		guint8 *outstr, gint *outstrlen_ptr)
-{
-	if (flag == DECRYPT)
-		return qq_decrypt(instr, instrlen, key, outstr, outstrlen_ptr);
-	else if (flag == ENCRYPT)
-		qq_encrypt(instr, instrlen, key, outstr, outstrlen_ptr);
-	else 
-		return 0;
-
-	return 1;
-}
============================================================
--- libpurple/protocols/qq/crypt.h	aa881a6941a265e987444d258068df0f9ccc618d
+++ libpurple/protocols/qq/crypt.h	6017061150dc8aa165d76035952436353257411c
@@ -27,12 +27,12 @@
 
 #include <glib.h>
 
-#define DECRYPT 0x00
-#define ENCRYPT 0x01
-
-gint qq_crypt(gint flag,
-	     const guint8 *const instr, gint instrlen, 
-	     const guint8 *const key, 
-	     guint8 *outstr, gint *outstrlen_ptr);
-
+void qq_encrypt(const guint8 *const instr, gint instrlen, 
+		const guint8 *const key, 
+		guint8 *outstr, gint *outstrlen_ptr);
+		
+gint qq_decrypt(const guint8 *const instr, gint instrlen, 
+		const guint8 *const key,
+		guint8 *outstr, gint *outstrlen_ptr);
+		
 #endif
============================================================
--- libpurple/protocols/qq/file_trans.c	c07f767a88ac2ed8eba476e440885c922c8226e8
+++ libpurple/protocols/qq/file_trans.c	95e21d081496e39521388523a594eea27ed45a02
@@ -357,7 +357,7 @@ void qq_send_file_ctl_packet(PurpleConne
 		g_free(hex_dump);
 		encrypted_len = bytes + 16;
 		encrypted_data = g_newa(guint8, encrypted_len);
-		qq_crypt(ENCRYPT, raw_data, bytes, info->file_session_key, encrypted_data, &encrypted_len);
+		qq_encrypt(raw_data, bytes, info->file_session_key, encrypted_data, &encrypted_len);
 		/*debug: try to decrypt it */
 		/*
 		if (QQ_DEBUG) {
@@ -368,7 +368,7 @@ void qq_send_file_ctl_packet(PurpleConne
 			g_free(hex_dump);
 			buf = g_newa(guint8, MAX_PACKET_SIZE);
 			buflen = encrypted_len;
-			if (qq_crypt(DECRYPT, encrypted_data, encrypted_len, info->file_session_key, buf, &buflen)) {
+			if (qq_decrypt(encrypted_data, encrypted_len, info->file_session_key, buf, &buflen)) {
 				purple_debug(PURPLE_DEBUG_INFO, "QQ", "decrypt success\n");
 				if (buflen == bytes && memcmp(raw_data, buf, buflen) == 0)
 					purple_debug(PURPLE_DEBUG_INFO, "QQ", "checksum ok\n");
@@ -534,7 +534,7 @@ static void _qq_process_recv_file_ctl_pa
 	decrypted_data = g_newa(guint8, len);
 	decrypted_len = len;
 
-	if (qq_crypt(DECRYPT, cursor, len - (cursor - data), qd->session_md5, decrypted_data, &decrypted_len)) {
+	if (qq_decrypt(cursor, len - (cursor - data), qd->session_md5, decrypted_data, &decrypted_len)) {
 		gchar *hex_dump;
 		cursor = decrypted_data + 16;	/* skip md5 section */
 		read_packet_w(decrypted_data, &cursor, decrypted_len, &packet_type);
============================================================
--- libpurple/protocols/qq/group_network.c	af931a8ff18a0d840c3acc7855f65327af678ab6
+++ libpurple/protocols/qq/group_network.c	c594a820896f954c8e86aced99ca5d8f19462405
@@ -149,7 +149,7 @@ void qq_process_group_cmd_reply(guint8 *
 		return;
 	}
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		if (len <= 2) {
 			purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Group cmd reply is too short, only %d bytes\n", len);
 			return;
============================================================
--- libpurple/protocols/qq/im.c	fe965a9243bb9c01da7d7e6fcff1f49f86337b24
+++ libpurple/protocols/qq/im.c	02c9a405d32010d5e49caa9f413aea2c41c14aa9
@@ -568,7 +568,7 @@ void qq_process_send_im_reply(guint8 *bu
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		cursor = data;
 		read_packet_b(data, &cursor, len, &reply);
 		if (reply != QQ_SEND_IM_REPLY_OK) {
@@ -597,7 +597,7 @@ void qq_process_recv_im(guint8 *buf, gin
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		if (len < 16) {	/* we need to ack with the first 16 bytes */
 			purple_debug(PURPLE_DEBUG_ERROR, "QQ", "IM is too short\n");
 			return;
============================================================
--- libpurple/protocols/qq/keep_alive.c	028329a307b727053d5dbdb45518c183d71dff4b
+++ libpurple/protocols/qq/keep_alive.c	0d4f3f8407056a7dfaa78f25ed1a585763d22342
@@ -77,7 +77,7 @@ void qq_process_keep_alive_reply(guint8 
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		/* the last one is 60, don't know what it is */
 		if (NULL == (segments = split_data(data, len, "\x1f", 6)))
 			return;
============================================================
--- libpurple/protocols/qq/login_logout.c	a7117c16ea36489378b3cc0a1248dc2b2ae308d5
+++ libpurple/protocols/qq/login_logout.c	9a050dd4a599acb3f83fbf2bbf02ccae2b326321
@@ -336,7 +336,7 @@ static void qq_send_packet_login(PurpleC
 
 	/* now generate the encrypted data
 	 * 000-015 use pwkey as key to encrypt empty string */
-	qq_crypt(ENCRYPT, (guint8 *) "", 0, qd->pwkey, raw_data, &encrypted_len);
+	qq_encrypt((guint8 *) "", 0, qd->pwkey, raw_data, &encrypted_len);
 	/* 016-016 */
 	raw_data[16] = 0x00;
 	/* 017-020, used to be IP, now zero */
@@ -362,7 +362,7 @@ static void qq_send_packet_login(PurpleC
 	/* all zero left */
 	memset(raw_data+pos, 0, QQ_LOGIN_DATA_LENGTH - pos);
 
-	qq_crypt(ENCRYPT, raw_data, QQ_LOGIN_DATA_LENGTH, qd->inikey, encrypted_data, &encrypted_len);
+	qq_encrypt(raw_data, QQ_LOGIN_DATA_LENGTH, qd->inikey, encrypted_data, &encrypted_len);
 
 	cursor = buf;
 	bytes = 0;
@@ -437,7 +437,7 @@ void qq_process_login_reply(guint8 *buf,
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->pwkey, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->pwkey, data, &len)) {
 		/* should be able to decrypt with pwkey */
 		purple_debug(PURPLE_DEBUG_INFO, "QQ", "Decrypt login reply packet with pwkey, %d bytes\n", len);
 		if (data[0] == QQ_LOGIN_REPLY_OK) {
@@ -448,7 +448,7 @@ void qq_process_login_reply(guint8 *buf,
 		}
 	} else {		/* decrypt with pwkey error */
 		len = buf_len;	/* reset len, decrypt will fail if len is too short */
-		if (qq_crypt(DECRYPT, buf, buf_len, qd->inikey, data, &len)) {
+		if (qq_decrypt(buf, buf_len, qd->inikey, data, &len)) {
 			/* decrypt ok with inipwd, it might be password error */
 			purple_debug(PURPLE_DEBUG_WARNING, "QQ", 
 					"Decrypt login reply packet with inikey, %d bytes\n", len);
============================================================
--- libpurple/protocols/qq/recv_core.c	c8890a830dc15d393d5a2d6c7c61fdd9baf6e4fe
+++ libpurple/protocols/qq/recv_core.c	b4dc341706cde432c36f1c2f0e1f3f49c013c68b
@@ -91,7 +91,7 @@ static void _qq_process_packet_default(g
 	msg_utf8 = NULL;
 
 	_qq_show_packet("Processing unknown packet", buf, len);
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		gchar *hex_dump = hex_dump_to_str(data, len);
 		purple_debug(PURPLE_DEBUG_WARNING, "QQ",
 			   ">>> [%d] %s, %d bytes -> [default] decrypt and dump\n%s",
============================================================
--- libpurple/protocols/qq/send_core.c	88d77dc6c841adedbbc1d42e27894c6f519a4675
+++ libpurple/protocols/qq/send_core.c	d21c0abb1cc7aa8644d479e0010f935edbd42517
@@ -132,7 +132,7 @@ gint qq_send_cmd(PurpleConnection *gc, g
 	cursor = buf;
 	bytes_written = 0;
 
-	qq_crypt(ENCRYPT, data, len, qd->session_key, encrypted_data, &encrypted_len);
+	qq_encrypt(data, len, qd->session_key, encrypted_data, &encrypted_len);
 
 	seq_ret = seq;
 	if (_create_packet_head_seq(buf, &cursor, gc, cmd, is_auto_seq, &seq_ret) >= 0) {
============================================================
--- libpurple/protocols/qq/sys_msg.c	ddb215c4828f1b0438eed0b3701cce631a3549b7
+++ libpurple/protocols/qq/sys_msg.c	4eae60cbe2b2893a746b0b1380ae93a241bfd3ae
@@ -288,7 +288,7 @@ void qq_process_msg_sys(guint8 *buf, gin
 	len = buf_len;
 	data = g_newa(guint8, len);
 
-	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
+	if (qq_decrypt(buf, buf_len, qd->session_key, data, &len)) {
 		if (NULL == (segments = split_data(data, len, "\x1f", 4)))
 			return;
 		code = segments[0];


More information about the Commits mailing list