diff libpurple/protocols/qq/buddy_list.c @ 24019:147ada94a1d8

2008.08.16 - ccpaging <ecc_hy(at)hotmail.com> * Rename group to room. If you used pidginqq before, this may create a new room with same title, you may delete old one * Replace purple_debug with purple_debug_info, purple_debug_warning, purple_debug_error * Add server notice and server new, and two options to turn on/off * Minor modify for reducing transaction's debug infor * Minor modifies for system notice and QQ news. * Add 4 new strings need translate compare with p10.
author SHiNE CsyFeK <csyfek@gmail.com>
date Thu, 11 Sep 2008 13:25:07 +0000
parents 5f454b975a99
children 23cec4360d4a 25f62d21b3f8
line wrap: on
line diff
--- a/libpurple/protocols/qq/buddy_list.c	Thu Sep 11 04:19:37 2008 +0000
+++ b/libpurple/protocols/qq/buddy_list.c	Thu Sep 11 13:25:07 2008 +0000
@@ -56,7 +56,7 @@
 } qq_buddy_online;
 
 /* get a list of online_buddies */
-void qq_send_packet_get_buddies_online(PurpleConnection *gc, guint8 position)
+void qq_request_get_buddies_online(PurpleConnection *gc, guint8 position, gint update_class)
 {
 	qq_data *qd;
 	guint8 *raw_data;
@@ -77,15 +77,14 @@
 	/* 003-004 */
 	bytes += qq_put16(raw_data + bytes, 0x0000);
 
-	qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_ONLINE, raw_data, 5);
+	qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_ONLINE, raw_data, 5, update_class, 0);
 	qd->last_get_online = time(NULL);
 }
 
-/* position starts with 0x0000, 
+/* position starts with 0x0000,
  * server may return a position tag if list is too long for one packet */
-void qq_send_packet_get_buddies_list(PurpleConnection *gc, guint16 position)
+void qq_request_get_buddies_list(PurpleConnection *gc, guint16 position, gint update_class)
 {
-	qq_data *qd = (qq_data *) gc->proto_data;
 	guint8 raw_data[16] = {0};
 	gint bytes = 0;
 
@@ -98,13 +97,12 @@
 	 * March 22, found the 00,00,00 starts to work as well */
 	bytes += qq_put8(raw_data + bytes, 0x00);
 
-	qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes);
+	qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_LIST, raw_data, bytes, update_class, 0);
 }
 
 /* get all list, buddies & Quns with groupsid support */
-void qq_send_packet_get_buddies_and_rooms(PurpleConnection *gc, guint32 position)
+void qq_request_get_buddies_and_rooms(PurpleConnection *gc, guint32 position, gint update_class)
 {
-	qq_data *qd = (qq_data *) gc->proto_data;
 	guint8 raw_data[16] = {0};
 	gint bytes = 0;
 
@@ -116,7 +114,7 @@
 	bytes += qq_put32(raw_data + bytes, 0x00000000);
 	bytes += qq_put32(raw_data + bytes, position);
 
-	qq_send_cmd(qd, QQ_CMD_GET_BUDDIES_AND_ROOMS, raw_data, bytes);
+	qq_send_cmd_mess(gc, QQ_CMD_GET_BUDDIES_AND_ROOMS, raw_data, bytes, update_class, 0);
 }
 
 /* parse the data into qq_buddy_status */
@@ -146,8 +144,8 @@
 	/* 015-030: unknown key */
 	bytes += qq_getdata(&(bs->unknown_key[0]), QQ_KEY_LENGTH, data + bytes);
 
-	purple_debug(PURPLE_DEBUG_INFO, "QQ_STATUS", 
-			"uid: %d, U1: %d, ip: %s:%d, U2:%d, status:%d, U3:%04X\n", 
+	purple_debug_info("QQ_STATUS",
+			"uid: %d, U1: %d, ip: %s:%d, U2:%d, status:%d, U3:%04X\n",
 			bs->uid, bs->unknown1, inet_ntoa(bs->ip), bs->port,
 			bs->unknown2, bs->status, bs->unknown3);
 
@@ -180,13 +178,12 @@
 	count = 0;
 	while (bytes < data_len) {
 		if (data_len - bytes < QQ_ONLINE_BUDDY_ENTRY_LEN) {
-			purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
-					"[buddies online] only %d, need %d", 
+			purple_debug_error("QQ", "[buddies online] only %d, need %d",
 					(data_len - bytes), QQ_ONLINE_BUDDY_ENTRY_LEN);
 			break;
 		}
 		memset(&bo, 0 ,sizeof(bo));
-		
+
 		/* set flag */
 		bytes_buddy = bytes;
 		/* based on one online buddy entry */
@@ -204,31 +201,29 @@
 		bytes += qq_get8(&bo.ending, data + bytes);	/* 0x00 */
 
 		if (bo.bs.uid == 0 || (bytes - bytes_buddy) != QQ_ONLINE_BUDDY_ENTRY_LEN) {
-			purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
-					"uid=0 or entry complete len(%d) != %d", 
+			purple_debug_error("QQ", "uid=0 or entry complete len(%d) != %d",
 					(bytes - bytes_buddy), QQ_ONLINE_BUDDY_ENTRY_LEN);
 			continue;
 		}	/* check if it is a valid entry */
 
 		if (bo.bs.uid == qd->uid) {
-			purple_debug(PURPLE_DEBUG_WARNING, "QQ", 
-					"I am in online list %d\n", bo.bs.uid);
+			purple_debug_warning("QQ", "I am in online list %d\n", bo.bs.uid);
 			continue;
 		}
 
 		/* update buddy information */
 		purple_name = uid_to_purple_name(bo.bs.uid);
 		if (purple_name == NULL) {
-			purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
+			purple_debug_error("QQ",
 					"Got an online buddy %d, but not find purple name\n", bo.bs.uid);
 			continue;
 		}
 		b = purple_find_buddy(purple_connection_get_account(gc), purple_name);
 		g_free(purple_name);
-		
+
 		q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
 		if (q_bud == NULL) {
-			purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
+			purple_debug_error("QQ",
 					"Got an online buddy %d, but not in my buddy list\n", bo.bs.uid);
 			continue;
 		}
@@ -247,11 +242,11 @@
 	}
 
 	if(bytes > data_len) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
+		purple_debug_error("QQ",
 				"qq_process_get_buddies_online_reply: Dangerous error! maybe protocol changed, notify developers!\n");
 	}
 
-	purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d online buddies, nextposition=%u\n",
+	purple_debug_info("QQ", "Received %d online buddies, nextposition=%u\n",
 							count, (guint) position);
 	return position;
 }
@@ -274,7 +269,7 @@
 	qd = (qq_data *) gc->proto_data;
 
 	if (data_len <= 2) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", "empty buddies list");
+		purple_debug_error("QQ", "empty buddies list");
 		return -1;
 	}
 	/* qq_show_packet("QQ get buddies list", data, data_len); */
@@ -305,7 +300,7 @@
 		bytes_expected = 12 + pascal_len;
 
 		if (q_bud->uid == 0 || (bytes - buddy_bytes) != bytes_expected) {
-			purple_debug(PURPLE_DEBUG_INFO, "QQ",
+			purple_debug_info("QQ",
 					"Buddy entry, expect %d bytes, read %d bytes\n", bytes_expected, bytes - buddy_bytes);
 			g_free(q_bud->nickname);
 			g_free(q_bud);
@@ -315,7 +310,7 @@
 		}
 
 #if 1
-		purple_debug(PURPLE_DEBUG_INFO, "QQ",
+		purple_debug_info("QQ",
 				"buddy [%09d]: ext_flag=0x%02x, comm_flag=0x%02x, nick=%s\n",
 				q_bud->uid, q_bud->ext_flag, q_bud->comm_flag, q_bud->nickname);
 #endif
@@ -334,11 +329,11 @@
 	}
 
 	if(bytes > data_len) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
+		purple_debug_error("QQ",
 				"qq_process_get_buddies_list_reply: Dangerous error! maybe protocol changed, notify developers!");
 	}
 
-	purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d buddies, nextposition=%u\n",
+	purple_debug_info("QQ", "Received %d buddies, nextposition=%u\n",
 		count, (guint) position);
 	return position;
 }
@@ -364,8 +359,7 @@
 
 	bytes += qq_get8(&reply_code, data + bytes);
 	if(0 != reply_code) {
-		purple_debug(PURPLE_DEBUG_WARNING, "QQ", 
-				"qq_process_get_buddies_and_rooms, %d", reply_code);
+		purple_debug_warning("QQ", "qq_process_get_buddies_and_rooms, %d", reply_code);
 	}
 
 	bytes += qq_get32(&unknown, data + bytes);
@@ -381,48 +375,45 @@
 		/* 05: groupid*4 */ /* seems to always be 0 */
 		bytes += qq_get8(&groupid, data + bytes);
 		/*
-		   purple_debug(PURPLE_DEBUG_INFO, "QQ", "groupid: %i\n", groupid);
+		   purple_debug_info("QQ", "groupid: %i\n", groupid);
 		   groupid >>= 2;
 		   */
 		if (uid == 0 || (type != 0x1 && type != 0x4)) {
-			purple_debug(PURPLE_DEBUG_INFO, "QQ",
-					"Buddy entry, uid=%d, type=%d", uid, type);
+			purple_debug_info("QQ", "Buddy entry, uid=%d, type=%d", uid, type);
 			continue;
-		} 
+		}
 		if(0x1 == type) { /* a buddy */
-			/* don't do anything but count - buddies are handled by 
-			 * qq_send_packet_get_buddies_list */
+			/* don't do anything but count - buddies are handled by
+			 * qq_request_get_buddies_list */
 			++i;
 		} else { /* a group */
 			group = qq_room_search_id(gc, uid);
 			if(group == NULL) {
-				purple_debug(PURPLE_DEBUG_INFO, "QQ",
+				purple_debug_info("QQ",
 					"Not find room id %d in qq_process_get_buddies_and_rooms\n", uid);
 				qq_set_pending_id(&qd->adding_groups_from_server, uid, TRUE);
-				qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, uid);
 			} else {
-				group->my_status = QQ_GROUP_MEMBER_STATUS_IS_MEMBER;
+				group->my_role = QQ_ROOM_ROLE_YES;
 				qq_group_refresh(gc, group);
-				qq_send_room_cmd_only(gc, QQ_ROOM_CMD_GET_INFO, group->id);
 			}
 			++j;
 		}
 	}
 
 	if(bytes > data_len) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
+		purple_debug_error("QQ",
 				"qq_process_get_buddies_and_rooms: Dangerous error! maybe protocol changed, notify developers!");
 	}
 
-	purple_debug(PURPLE_DEBUG_INFO, "QQ", "Received %d buddies and %d groups, nextposition=%u\n", i, j, (guint) position);
+	purple_debug_info("QQ", "Received %d buddies and %d groups, nextposition=%u\n", i, j, (guint) position);
 	return position;
 }
 
 #define QQ_MISC_STATUS_HAVING_VIIDEO      0x00000001
 #define QQ_CHANGE_ONLINE_STATUS_REPLY_OK 	0x30	/* ASCII value of "0" */
 
-/* TODO: figure out what's going on with the IP region. Sometimes I get valid IP addresses, 
- * but the port number's weird, other times I get 0s. I get these simultaneously on the same buddy, 
+/* TODO: figure out what's going on with the IP region. Sometimes I get valid IP addresses,
+ * but the port number's weird, other times I get 0s. I get these simultaneously on the same buddy,
  * using different accounts to get info. */
 
 /* check if status means online or offline */
@@ -441,9 +432,9 @@
 
 /* Help calculate the correct icon index to tell the server. */
 gint get_icon_offset(PurpleConnection *gc)
-{ 
+{
 	PurpleAccount *account;
-	PurplePresence *presence; 
+	PurplePresence *presence;
 
 	account = purple_connection_get_account(gc);
 	presence = purple_account_get_presence(account);
@@ -460,7 +451,7 @@
 }
 
 /* send a packet to change my online status */
-void qq_send_packet_change_status(PurpleConnection *gc)
+void qq_request_change_status(PurpleConnection *gc, gint update_class)
 {
 	qq_data *qd;
 	guint8 raw_data[16] = {0};
@@ -469,13 +460,13 @@
 	guint32 misc_status;
 	gboolean fake_video;
 	PurpleAccount *account;
-	PurplePresence *presence; 
+	PurplePresence *presence;
 
 	account = purple_connection_get_account(gc);
 	presence = purple_account_get_presence(account);
 
 	qd = (qq_data *) gc->proto_data;
-	if (!qd->logged_in)
+	if (!qd->is_login)
 		return;
 
 	if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_INVISIBLE)) {
@@ -497,7 +488,7 @@
 	bytes += qq_put8(raw_data + bytes, away_cmd);
 	bytes += qq_put32(raw_data + bytes, misc_status);
 
-	qq_send_cmd(qd, QQ_CMD_CHANGE_ONLINE_STATUS, raw_data, bytes);
+	qq_send_cmd_mess(gc, QQ_CMD_CHANGE_STATUS, raw_data, bytes, update_class, 0);
 }
 
 /* parse the reply packet for change_status */
@@ -513,15 +504,15 @@
 	g_return_if_fail(data != NULL && data_len != 0);
 
 	qd = (qq_data *) gc->proto_data;
-	
+
 	bytes = 0;
 	bytes = qq_get8(&reply, data + bytes);
 	if (reply != QQ_CHANGE_ONLINE_STATUS_REPLY_OK) {
-		purple_debug(PURPLE_DEBUG_WARNING, "QQ", "Change status fail 0x%02X\n", reply);
+		purple_debug_warning("QQ", "Change status fail 0x%02X\n", reply);
 		return;
 	}
 
-	/* purple_debug(PURPLE_DEBUG_INFO, "QQ", "Change status OK\n"); */
+	/* purple_debug_info("QQ", "Change status OK\n"); */
 	name = uid_to_purple_name(qd->uid);
 	b = purple_find_buddy(gc->account, name);
 	g_free(name);
@@ -532,7 +523,7 @@
 }
 
 /* it is a server message indicating that one of my buddies has changed its status */
-void qq_process_buddy_change_status(guint8 *data, gint data_len, PurpleConnection *gc) 
+void qq_process_buddy_change_status(guint8 *data, gint data_len, PurpleConnection *gc)
 {
 	qq_data *qd;
 	gint bytes;
@@ -547,16 +538,16 @@
 	qd = (qq_data *) gc->proto_data;
 
 	if (data_len < 35) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", "[buddy status change] only %d, need 35 bytes\n", data_len);
+		purple_debug_error("QQ", "[buddy status change] only %d, need 35 bytes\n", data_len);
 		return;
 	}
-	
+
 	memset(&bs, 0, sizeof(bs));
 	bytes = 0;
 	/* 000-030: qq_buddy_status */
 	bytes += get_buddy_status(&bs, data + bytes);
-	/* 031-034:  Unknow, maybe my uid */ 
-	/* This has a value of 0 when we've changed our status to 
+	/* 031-034:  Unknow, maybe my uid */
+	/* This has a value of 0 when we've changed our status to
 	 * QQ_BUDDY_ONLINE_INVISIBLE */
 	bytes += qq_get32(&my_uid, data + bytes);
 
@@ -565,13 +556,13 @@
 	g_free(name);
 	q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
 	if (q_bud == NULL) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", 
+		purple_debug_error("QQ",
 				"got information of unknown buddy %d\n", bs.uid);
 		return;
 	}
 
-	purple_debug(PURPLE_DEBUG_INFO, "QQ", "status:.uid = %d, q_bud->uid = %d\n", bs.uid , q_bud->uid);
-	if(bs.ip.s_addr != 0) { 
+	purple_debug_info("QQ", "status:.uid = %d, q_bud->uid = %d\n", bs.uid , q_bud->uid);
+	if(bs.ip.s_addr != 0) {
 		q_bud->ip.s_addr = bs.ip.s_addr;
 		q_bud->port = bs.port;
 	}
@@ -589,24 +580,24 @@
 	gchar *purple_name;
 	PurpleBuddy *bud;
 	gchar *status_id;
-	
+
 	g_return_if_fail(q_bud != NULL);
 
 	purple_name = uid_to_purple_name(q_bud->uid);
 	if (purple_name == NULL) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Not find purple name: %d\n", q_bud->uid);
+		purple_debug_error("QQ", "Not find purple name: %d\n", q_bud->uid);
 		return;
 	}
 
 	bud = purple_find_buddy(gc->account, purple_name);
 	if (bud == NULL) {
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Not find buddy: %d\n", q_bud->uid);
+		purple_debug_error("QQ", "Not find buddy: %d\n", q_bud->uid);
 		g_free(purple_name);
 		return;
 	}
-	
+
 	purple_blist_server_alias_buddy(bud, q_bud->nickname); /* server */
-	q_bud->last_refresh = time(NULL);
+	q_bud->last_update = time(NULL);
 
 	/* purple supports signon and idle time
 	 * but it is not much use for QQ, I do not use them */
@@ -630,10 +621,10 @@
 		break;
 	default:
 		status_id = "invisible";
-		purple_debug(PURPLE_DEBUG_ERROR, "QQ", "unknown status: %x\n", q_bud->status);
+		purple_debug_error("QQ", "unknown status: %x\n", q_bud->status);
 		break;
 	}
-	purple_debug(PURPLE_DEBUG_INFO, "QQ", "buddy %d %s\n", q_bud->uid, status_id);
+	purple_debug_info("QQ", "buddy %d %s\n", q_bud->uid, status_id);
 	purple_prpl_got_user_status(gc->account, purple_name, status_id, NULL);
 
 	if (q_bud->comm_flag & QQ_COMM_FLAG_MOBILE && q_bud->status != QQ_BUDDY_OFFLINE)
@@ -664,7 +655,7 @@
 
 	while (list != NULL) {
 		q_bud = (qq_buddy *) list->data;
-		if (q_bud != NULL && now > q_bud->last_refresh + QQ_UPDATE_ONLINE_INTERVAL
+		if (q_bud != NULL && now > q_bud->last_update + QQ_UPDATE_ONLINE_INTERVAL
 				&& q_bud->status != QQ_BUDDY_ONLINE_INVISIBLE) {
 			q_bud->status = QQ_BUDDY_ONLINE_OFFLINE;
 			qq_update_buddy_contact(gc, q_bud);