changeset 25150:d673ccc44a6e

2009.02.24 - flos <lonicerae(at)gmail.com> * Changed update_class type from gint to guint32 * Fixed a bug of displaying of memo when memo is nothing
author SHiNE CsyFeK <csyfek@gmail.com>
date Tue, 24 Feb 2009 14:33:49 +0000
parents 7da3cf2530b7
children 7c21fb8132f7
files libpurple/protocols/qq/ChangeLog libpurple/protocols/qq/buddy_list.c libpurple/protocols/qq/buddy_memo.c libpurple/protocols/qq/buddy_memo.h libpurple/protocols/qq/qq.c libpurple/protocols/qq/qq_process.c
diffstat 6 files changed, 68 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/qq/ChangeLog	Tue Feb 24 13:15:34 2009 +0000
+++ b/libpurple/protocols/qq/ChangeLog	Tue Feb 24 14:33:49 2009 +0000
@@ -1,3 +1,7 @@
+2009.02.24 - flos <lonicerae(at)gmail.com>
+	* Changed update_class type from gint to guint32
+	* Fixed a bug of displaying of memo when memo is nothing
+
 2009.02.21 - flos <lonicerae(at)gmail.com>
 	* Added 'qq_strlen' and 'qq_strcmp' funtions in qq.h
 	* Fixed compiling problems with lower version of GTK+
--- a/libpurple/protocols/qq/buddy_list.c	Tue Feb 24 13:15:34 2009 +0000
+++ b/libpurple/protocols/qq/buddy_list.c	Tue Feb 24 14:33:49 2009 +0000
@@ -347,7 +347,8 @@
 		/* nickname has been copy to buddy_data do not free
 		   g_free(bd.nickname);
 		*/
-		qq_request_buddy_memo(gc, ((qq_buddy_data*)buddy->proto_data)->uid, 0, QQ_BUDDY_MEMO_GET);
+		/*qq_request_buddy_memo(gc, ((qq_buddy_data*)buddy->proto_data)->uid, 0, QQ_BUDDY_MEMO_GET);*/
+		qq_request_buddy_memo(gc, bd.uid, bd.uid, QQ_BUDDY_MEMO_GET);
 	}
 
 	if(bytes > data_len) {
--- a/libpurple/protocols/qq/buddy_memo.c	Tue Feb 24 13:15:34 2009 +0000
+++ b/libpurple/protocols/qq/buddy_memo.c	Tue Feb 24 14:33:49 2009 +0000
@@ -37,13 +37,13 @@
 
 /* memo id */
 static const gchar *memo_id[] = {
-	N_("mm_alias"),
-	N_("mm_mobile"),
-	N_("mm_telephone"),
-	N_("mm_address"),
-	N_("mm_email"),
-	N_("mm_zipcode"),
-	N_("mm_note")
+	"mm_alias",
+	"mm_mobile",
+	"mm_telephone",
+	"mm_address",
+	"mm_email",
+	"mm_zipcode",
+	"mm_note"
 };
 
 /* memo text */
@@ -97,7 +97,7 @@
 	buddy = purple_find_buddy(account, who);
 	if (buddy == NULL || buddy->proto_data == NULL) {
 		g_free(who);
-		purple_debug_info("QQ", "Error Can not find %d!\n", bd_uid);
+		purple_debug_info("QQ", "Error...Can NOT find %d!\n", bd_uid);
 		return;
 	}
 	purple_blist_alias_buddy(buddy, (const char*)alias);
@@ -108,7 +108,7 @@
 	gint bytes;
 	/* Attention, length of each segment must be guint8(0~255),
 	 * so length of memo string is limited.
-	 * convert it to guint8 first before put data */
+	 * convert it to guint8 first before putting data */
 	guint seg_len;
 	gint index;
 	guint8 raw_data[MAX_PACKET_SIZE - 16] = {0};
@@ -189,7 +189,7 @@
 }
 
 /* memo modify dialogue */
-static void memo_modify_dialogue(PurpleConnection *gc, guint32 bd_uid, gchar **segments, gint iclass)
+static void memo_modify_dialogue(PurpleConnection *gc, guint32 bd_uid, gchar **segments, guint32 action)
 {
 	modify_memo_request *memo_request;
 	PurpleRequestField *field;
@@ -201,11 +201,12 @@
 
 	g_return_if_fail(NULL != gc && NULL != segments);
 
-	switch (iclass) {
+	switch (action) {
 		case QQ_BUDDY_MEMO_GET:
+			memo_free(segments);
 			break;
 		case QQ_BUDDY_MEMO_MODIFY:
-			/* Keep one dialog once a time */
+			/* keep one dialog once a time */
 			purple_request_close_with_handle(gc);
 			/* show dialog */
 			fields = purple_request_fields_new();
@@ -217,7 +218,6 @@
 				   purple_debug_info("QQ", "id:%s txt:%s segment:%s\n",
 				   memo_id[index], memo_txt[index], segments[index]);
 				   */
-
 				field = purple_request_field_string_new(memo_id[index], memo_txt[index],
 						segments[index], FALSE);
 				purple_request_field_group_add_field(group, field);
@@ -243,13 +243,27 @@
 			g_free(utf8_primary);
 			break;
 		default:
-			purple_debug_info("QQ", "unknown memo action\n");
+			purple_debug_info("QQ", "Error...unknown memo action, please tell us\n");
 			break;
 	}
 }
 
+static void qq_create_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 action)
+{
+	gchar **segments;
+	gint index;
+	g_return_if_fail(NULL != gc);
+
+	segments = g_new0(gchar*, QQ_MEMO_SIZE);
+	for (index = 0; index < QQ_MEMO_SIZE; index++) {
+		segments[index] = g_strdup("");;
+	}
+	memo_modify_dialogue(gc, bd_uid, segments, action);
+}
+
 /* process reply to get_memo packet */
-void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len, guint32 action)
+void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len,
+		guint32 update_class, guint32 action)
 {
 	gchar **segments;
 	gint bytes;
@@ -259,20 +273,26 @@
 	guint8 unk1_8;
 	guint8 is_success;
 
-	g_return_if_fail(data != NULL && data_len != 0);
+	g_return_if_fail(NULL != gc && NULL != data && 0 != data_len);
 	/*
 	   qq_show_packet("MEMO REACH", data, data_len);
 	   */
-	purple_debug_info("QQ", "action:0x%x\n", action);
+	purple_debug_info("QQ", "action=0x%02X\n", action);
 
 	bytes = 0;
 
 	/* TX looks a bit clever than before... :) */
 	bytes += qq_get8(&rcv_cmd, data+bytes);
-	purple_debug_info("QQ", "rcv_cmd:0x%x\n", rcv_cmd);
-	/* it's possible that no buddy uid and no memo!!! */
-	if (1 == data_len) {
+	purple_debug_info("QQ", "rcv_cmd=0x%02X\n", rcv_cmd);
+
+	/* it's possible that packet contains no buddy uid and no memo!!!
+	 * go to next step according to previous action sent */
+	if (1 == data_len) { /* only one byte */
 		purple_debug_info("QQ", "memo packet contains no buddy uid and memo...\n");
+		if (QQ_BUDDY_MEMO_MODIFY == action) {
+			qq_create_buddy_memo(gc, (guint32)update_class, QQ_BUDDY_MEMO_MODIFY);
+			return;
+		}
 		return;
 	}
 
@@ -282,22 +302,24 @@
 			bytes += qq_get8(&is_success, data+bytes);
 			if (QQ_BUDDY_MEMO_REQUEST_SUCCESS == is_success) {
 				purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO,
-						_("Memo Modify"), _("Your request was accepted."), NULL,
+						_("Memo Modify"), _("Server says:"),
+						_("Your request was accepted."),
 						NULL, NULL);
-				purple_debug_info("QQ", "memo change succeessfully!");
+				purple_debug_info("QQ", "memo change succeessfully!\n");
 			}
 			else {
 				purple_notify_message(gc, PURPLE_NOTIFY_MSG_INFO,
-						_("Memo Modify"), _("Your request was rejected."), NULL,
+						_("Memo Modify"), _("Server says:"),
+						_("Your request was rejected."),
 						NULL, NULL);
-				purple_debug_info("QQ", "memo change failed");
+				purple_debug_info("QQ", "memo change failed\n");
 			}
 			break;
 		case QQ_BUDDY_MEMO_GET:
 			bytes += qq_get32(&rcv_uid, data+bytes);
-			purple_debug_info("QQ", "rcv_uid:%u\n", rcv_uid);
+			purple_debug_info("QQ", "rcv_uid=%u\n", rcv_uid);
 			bytes += qq_get8(&unk1_8, data+bytes);
-			purple_debug_info("QQ", "unk1_8:0x%x\n", unk1_8);
+			purple_debug_info("QQ", "unk1_8=0x%02X\n", unk1_8);
 			segments = g_new0(gchar*, QQ_MEMO_SIZE);
 			for (index = 0; index < QQ_MEMO_SIZE; index++) {
 				/* get utf8 string */
@@ -312,21 +334,21 @@
 
 			/* memo is thing that we regard our buddy as, so we need one more buddy_uid */
 			memo_modify_dialogue(gc, rcv_uid, segments, action);
-
 			break;
 		default:
-			purple_debug_info("QQ", "received an UNKNOWN memo cmd!!!");
+			purple_debug_info("QQ", "received an UNKNOWN memo cmd!!!\n");
 			break;
 	}
 }
 
 /* request buddy memo */
-void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 update_class, int action)
+void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 update_class, guint32 action)
 {
 	guint8 raw_data[16] = {0};
 	gint bytes;
 
-	purple_debug_info("QQ", "qq_request_buddy_memo, buddy uid=%u\n", bd_uid);
+	purple_debug_info("QQ", "qq_request_buddy_memo, buddy uid=%u, update_class=%u\n",
+			bd_uid, update_class);
 	g_return_if_fail(NULL != gc);
 	/* '0' is ok
 	   g_return_if_fail(uid != 0);
@@ -341,16 +363,4 @@
 	qq_send_cmd_mess(gc, QQ_CMD_BUDDY_MEMO, (guint8*)raw_data, bytes, update_class, action);
 }
 
-void qq_create_buddy_memo(PurpleConnection *gc, guint32 bd_uid, int action)
-{
-	gchar **segments;
-	gint index;
-	g_return_if_fail(NULL != gc);
 
-	segments = g_new0(gchar*, QQ_MEMO_SIZE);
-	for (index = 0; index < QQ_MEMO_SIZE; index++) {
-		segments[index] = g_strdup("");;
-	}
-	memo_modify_dialogue(gc, bd_uid, segments, action);
-}
-
--- a/libpurple/protocols/qq/buddy_memo.h	Tue Feb 24 13:15:34 2009 +0000
+++ b/libpurple/protocols/qq/buddy_memo.h	Tue Feb 24 14:33:49 2009 +0000
@@ -16,11 +16,9 @@
 };
 
 
-void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len, guint32 action);
+void qq_process_get_buddy_memo(PurpleConnection *gc, guint8* data, gint data_len, guint32 update_class, guint32 action);
 
-void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 update_class, int action);
-
-void qq_create_buddy_memo(PurpleConnection *gc, guint32 bd_uid, int action);
+void qq_request_buddy_memo(PurpleConnection *gc, guint32 bd_uid, guint32 update_class, guint32 action);
 
 #endif
 
--- a/libpurple/protocols/qq/qq.c	Tue Feb 24 13:15:34 2009 +0000
+++ b/libpurple/protocols/qq/qq.c	Tue Feb 24 14:33:49 2009 +0000
@@ -57,7 +57,7 @@
 #include "utils.h"
 #include "version.h"
 
-#define OPENQ_VERSION 		"0.3.2-p19" 
+#define OPENQ_VERSION 		"0.3.2-p20" 
 
 static GList *server_list_build(gchar select)
 {
@@ -826,8 +826,6 @@
 	qq_buddy_data *bd;
 	PurpleConnection *gc;
 	guint32 bd_uid;
-	const gchar *alias;
-	const gchar *server_alias;
 
 	g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));
 
@@ -841,19 +839,10 @@
 	g_return_if_fail(NULL != bd);
 	bd_uid = bd->uid;
 
-	/* gc, uid, update_class, action */
-	qq_request_buddy_memo(gc, bd_uid, 0, QQ_BUDDY_MEMO_MODIFY);
-
-	/* if buddy does NOT have a memo, open the memo dialogue directly */
-	alias = purple_buddy_get_alias_only(buddy);
-	server_alias = purple_buddy_get_server_alias(buddy);
-
-	purple_debug_info("QQ", "alias=%s\n", alias);
-	purple_debug_info("QQ", "server_alias=%s\n", server_alias);
-
-	if (!qq_strcmp(alias, server_alias)) {
-		qq_create_buddy_memo(gc, bd_uid, QQ_BUDDY_MEMO_MODIFY);
-	}
+	/* param: gc, uid, update_class, action
+	 * here, update_class is set to bd_uid. because some memo packages returned
+	 * without uid, which will make us confused */
+	qq_request_buddy_memo(gc, bd_uid, bd_uid, QQ_BUDDY_MEMO_MODIFY);
 }
 
 static GList *qq_buddy_menu(PurpleBuddy *buddy)
--- a/libpurple/protocols/qq/qq_process.c	Tue Feb 24 13:15:34 2009 +0000
+++ b/libpurple/protocols/qq/qq_process.c	Tue Feb 24 14:33:49 2009 +0000
@@ -1145,7 +1145,9 @@
 			break;
 		case QQ_CMD_BUDDY_MEMO:
 			purple_debug_info("QQ", "Receive memo from server!\n");
-			qq_process_get_buddy_memo(gc, data, data_len, ship32);
+			qq_process_get_buddy_memo(gc, data, data_len, update_class, ship32);
+			return;
+			purple_debug_info("QQ", "Should NOT be here...\n");
 			break;
 		default:
 			process_unknow_cmd(gc, _("Unknown CLIENT CMD"), data, data_len, cmd, seq);