diff src/protocols/qq/buddy_opt.c @ 14021:ef8490f9e823

[gaim-migrate @ 16618] Replaced all C++-style comments with C-style ones. Cleaned up some comments and implemented a more consistent formatting scheme. committer: Tailor Script <tailor@pidgin.im>
author Mark Huetsch <markhuetsch>
date Wed, 02 Aug 2006 15:35:36 +0000
parents 983fd420e86b
children 32a71e64ceae
line wrap: on
line diff
--- a/src/protocols/qq/buddy_opt.c	Wed Aug 02 13:37:13 2006 +0000
+++ b/src/protocols/qq/buddy_opt.c	Wed Aug 02 15:35:36 2006 +0000
@@ -20,24 +20,22 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-// START OF FILE
-/*****************************************************************************/
-#include "debug.h"		// gaim_debug
-#include "internal.h"		// strlen, _("get_text")
-#include "notify.h"		// gaim_notify
-#include "request.h"		// gaim_request_input
+#include "debug.h"
+#include "internal.h"
+#include "notify.h"
+#include "request.h"
 
-#include "utils.h"		// uid_to_gaim_name, gaim_name_to_uid
-#include "packet_parse.h"	// create_packet, read_packet
-#include "buddy_info.h"		// qq_send_packet_get_info
-#include "buddy_list.h"		// qq_send_packet_get_buddies_online
+#include "buddy_info.h"
+#include "buddy_list.h"
 #include "buddy_opt.h"
-#include "char_conv.h"		// qq_to_utf8
-#include "crypt.h"		// qq_crypt
-#include "header_info.h"	// cmd alias
-#include "keep_alive.h"		// qq_update_buddy_contact
-#include "im.h"			// QQ_MSG_IM_MAX
-#include "send_core.h"		// qq_send_cmd
+#include "char_conv.h"
+#include "crypt.h"
+#include "header_info.h"
+#include "im.h"
+#include "keep_alive.h"
+#include "packet_parse.h"
+#include "send_core.h"
+#include "utils.h"
 
 #define GAIM_GROUP_QQ_FORMAT          "QQ (%s)"
 #define GAIM_GROUP_QQ_UNKNOWN         "QQ Unknown"
@@ -45,12 +43,12 @@
 
 #define QQ_REMOVE_BUDDY_REPLY_OK      0x00
 #define QQ_REMOVE_SELF_REPLY_OK       0x00
-#define QQ_ADD_BUDDY_AUTH_REPLY_OK    0x30	// ASCii value of "0"
+#define QQ_ADD_BUDDY_AUTH_REPLY_OK    0x30	/* ASCII value of "0" */
 
 enum {
-	QQ_MY_AUTH_APPROVE = 0x30,	// ASCii value of "0"
-	QQ_MY_AUTH_REJECT = 0x31,	// ASCii value of "1"
-	QQ_MY_AUTH_REQUEST = 0x32,	// ASCii value of "2"
+	QQ_MY_AUTH_APPROVE = 0x30,	/* ASCII value of "0" */
+	QQ_MY_AUTH_REJECT = 0x31,	/* ASCII value of "1" */
+	QQ_MY_AUTH_REQUEST = 0x32,	/* ASCII value of "2" */
 };
 
 typedef struct _qq_add_buddy_request {
@@ -58,9 +56,8 @@
 	guint16 seq;
 } qq_add_buddy_request;
 
-/*****************************************************************************/
-// send packet to remove a buddy from my buddy list
-static void _qq_send_packet_remove_buddy(GaimConnection * gc, guint32 uid)
+/* send packet to remove a buddy from my buddy list */
+static void _qq_send_packet_remove_buddy(GaimConnection *gc, guint32 uid)
 {
 	gchar *uid_str;
 
@@ -70,11 +67,10 @@
 	qq_send_cmd(gc, QQ_CMD_DEL_FRIEND, TRUE, 0, TRUE, uid_str, strlen(uid_str));
 
 	g_free(uid_str);
-}				// _qq_send_packet_remove_buddy
+}
 
-/*****************************************************************************/
-// try to remove myself from someone's buddy list
-static void _qq_send_packet_remove_self_from(GaimConnection * gc, guint32 uid)
+/* try to remove myself from someone's buddy list */
+static void _qq_send_packet_remove_self_from(GaimConnection *gc, guint32 uid)
 {
 	guint8 *raw_data, *cursor;
 
@@ -85,12 +81,10 @@
 	create_packet_dw(raw_data, &cursor, uid);
 
 	qq_send_cmd(gc, QQ_CMD_REMOVE_SELF, TRUE, 0, TRUE, raw_data, 4);
-
-}				// _qq_send_packet_add_buddy
+}
 
-/*****************************************************************************/
-// try to add a buddy without authentication
-static void _qq_send_packet_add_buddy(GaimConnection * gc, guint32 uid)
+/* try to add a buddy without authentication */
+static void _qq_send_packet_add_buddy(GaimConnection *gc, guint32 uid)
 {
 	qq_data *qd;
 	qq_add_buddy_request *req;
@@ -98,22 +92,21 @@
 
 	g_return_if_fail(gc != NULL && gc->proto_data != NULL && uid > 0);
 
-	// we need to send the ascii code of this uid to qq server
+	/* we need to send the ascii code of this uid to qq server */
 	uid_str = g_strdup_printf("%d", uid);
 	qq_send_cmd(gc, QQ_CMD_ADD_FRIEND_WO_AUTH, TRUE, 0, TRUE, uid_str, strlen(uid_str));
 	g_free(uid_str);
 
-	// must be set after sending packet to get the correct send_seq
+	/* must be set after sending packet to get the correct send_seq */
 	qd = (qq_data *) gc->proto_data;
 	req = g_new0(qq_add_buddy_request, 1);
 	req->seq = qd->send_seq;
 	req->uid = uid;
 	qd->add_buddy_request = g_list_append(qd->add_buddy_request, req);
-}				// _qq_send_packet_add_buddy
+}
 
-/*****************************************************************************/
-// this buddy needs authentication, text conversion is done at lowest level
-static void _qq_send_packet_buddy_auth(GaimConnection * gc, guint32 uid, const gchar response, const gchar * text)
+/* this buddy needs authentication, text conversion is done at lowest level */
+static void _qq_send_packet_buddy_auth(GaimConnection *gc, guint32 uid, const gchar response, const gchar *text)
 {
 	gchar *text_qq, *uid_str;
 	guint8 bar, *cursor, *raw_data;
@@ -138,11 +131,10 @@
 
 	qq_send_cmd(gc, QQ_CMD_BUDDY_AUTH, TRUE, 0, TRUE, raw_data, cursor - raw_data);
 	g_free(uid_str);
-}				// _qq_send_packet_buddy_auth
-
+}
 
-/*****************************************************************************/
-static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid * g, const gchar * text) {
+static void _qq_send_packet_add_buddy_auth_with_gc_and_uid(gc_and_uid *g, const gchar *text)
+{
 	GaimConnection *gc;
 	guint32 uid;
 	g_return_if_fail(g != NULL);
@@ -153,11 +145,10 @@
 
 	_qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_REQUEST, text);
 	g_free(g);
-}				// qq_send_packet_add_buddy_auth
+}
 
-/*****************************************************************************/
-// the real packet to reject and request is sent from here
-static void _qq_reject_add_request_real(gc_and_uid * g, const gchar * reason)
+/* the real packet to reject and request is sent from here */
+static void _qq_reject_add_request_real(gc_and_uid *g, const gchar *reason)
 {
 	gint uid;
 	GaimConnection *gc;
@@ -170,11 +161,10 @@
 
 	_qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_REJECT, reason);
 	g_free(g);
-}				// _qq_reject_add_request_real
+}
 
-/*****************************************************************************/
-// we approve other's request of adding me as friend
-void qq_approve_add_request_with_gc_and_uid(gc_and_uid * g)
+/* we approve other's request of adding me as friend */
+void qq_approve_add_request_with_gc_and_uid(gc_and_uid *g)
 {
 	gint uid;
 	GaimConnection *gc;
@@ -187,17 +177,15 @@
 
 	_qq_send_packet_buddy_auth(gc, uid, QQ_MY_AUTH_APPROVE, NULL);
 	g_free(g);
-}				// qq_approve_add_request_with_gc_and_uid
+}
 
-/*****************************************************************************/
-void qq_do_nothing_with_gc_and_uid(gc_and_uid * g, const gchar * msg)
+void qq_do_nothing_with_gc_and_uid(gc_and_uid *g, const gchar *msg)
 {
 	g_free(g);
-}				// qq_do_nothing_with_gc_and_uid
+}
 
-/*****************************************************************************/
-// we reject other's request of adding me as friend
-void qq_reject_add_request_with_gc_and_uid(gc_and_uid * g)
+/* we reject other's request of adding me as friend */
+void qq_reject_add_request_with_gc_and_uid(gc_and_uid *g)
 {
 	gint uid;
 	gchar *msg1, *msg2;
@@ -222,11 +210,9 @@
 	gaim_request_input(gc, _("Reject request"), msg1, msg2,
 			   _("Sorry, you are not my type..."), TRUE, FALSE,
 			   NULL, _("Reject"), G_CALLBACK(_qq_reject_add_request_real), _("Cancel"), NULL, g2);
-
-}				// qq_reject_add_request_with_gc_and_uid
+}
 
-/*****************************************************************************/
-void qq_add_buddy_with_gc_and_uid(gc_and_uid * g)
+void qq_add_buddy_with_gc_and_uid(gc_and_uid *g)
 {
 	gint uid;
 	GaimConnection *gc;
@@ -239,10 +225,9 @@
 
 	_qq_send_packet_add_buddy(gc, uid);
 	g_free(g);
-}				// qq_add_buddy_with_gc_and_uid
+}
 
-/*****************************************************************************/
-void qq_block_buddy_with_gc_and_uid(gc_and_uid * g)
+void qq_block_buddy_with_gc_and_uid(gc_and_uid *g)
 {
 	guint32 uid;
 	GaimConnection *gc;
@@ -260,12 +245,11 @@
 
 	qq_remove_buddy(gc, &buddy, &group);
 	_qq_send_packet_remove_self_from(gc, uid);
-
-}				// qq_block_buddy_with_gc_and_uid
+}
 
-/*****************************************************************************/
-//  process reply to add_buddy_auth request
-void qq_process_add_buddy_auth_reply(guint8 * buf, gint buf_len, GaimConnection * gc) {
+/*  process reply to add_buddy_auth request */
+void qq_process_add_buddy_auth_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
+{
 	qq_data *qd;
 	gint len;
 	guint8 *data, *cursor, reply;
@@ -288,16 +272,17 @@
 			msg_utf8 = qq_to_utf8(segments[1], QQ_CHARSET_DEFAULT);
 			gaim_notify_error(gc, NULL, _("Add buddy with auth request fails"), msg_utf8);
 			g_free(msg_utf8);
-		} else
+		} else {
 			gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy with auth request OK\n");
-	} else
+		}
+	} else {
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy with auth reply\n");
+	}
+}
 
-}				// qq_process_add_buddy_auth_reply
-
-/*****************************************************************************/
-// process the server reply for my request to remove a buddy
-void qq_process_remove_buddy_reply(guint8 * buf, gint buf_len, GaimConnection * gc) {
+/* process the server reply for my request to remove a buddy */
+void qq_process_remove_buddy_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
+{
 	qq_data *qd;
 	gint len;
 	guint8 *data, *cursor, reply;
@@ -312,22 +297,21 @@
 	if (qq_crypt(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)
-			// there is no reason return from server
+		if (reply != QQ_REMOVE_BUDDY_REPLY_OK) {
+			/* there is no reason return from server */
 			gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove buddy fails\n");
-		else {		// if reply
+		} else {		/* if reply */
 			gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove buddy OK\n");
 			gaim_notify_info(gc, NULL, _("You have successfully removed a buddy"), NULL);
 		}
-	} else
+	} else {
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove buddy reply\n");
-
-}				// qq_process_remove_buddy_reply
+	}
+}
 
-
-/*****************************************************************************/
-// process the server reply for my request to remove myself from a buddy
-void qq_process_remove_self_reply(guint8 * buf, gint buf_len, GaimConnection * gc) {
+/* process the server reply for my request to remove myself from a buddy */
+void qq_process_remove_self_reply(guint8 *buf, gint buf_len, GaimConnection *gc) 
+{
 	qq_data *qd;
 	gint len;
 	guint8 *data, *cursor, reply;
@@ -343,19 +327,19 @@
 		cursor = data;
 		read_packet_b(data, &cursor, len, &reply);
 		if (reply != QQ_REMOVE_SELF_REPLY_OK)
-			// there is no reason return from server
+			/* there is no reason return from server */
 			gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Remove self fails\n");
-		else {		// if reply
+		else {		/* if reply */
 			gaim_debug(GAIM_DEBUG_INFO, "QQ", "Remove self from a buddy OK\n");
 			gaim_notify_info(gc, NULL, _("You have successfully removed yourself from a buddy"), NULL);
 		}
-	} else
+	} else {
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt remove self reply\n");
+	}
+}
 
-}				// qq_process_remove_buddy_reply
-
-/*****************************************************************************/
-void qq_process_add_buddy_reply(guint8 * buf, gint buf_len, guint16 seq, GaimConnection * gc) {
+void qq_process_add_buddy_reply(guint8 *buf, gint buf_len, guint16 seq, GaimConnection *gc)
+{
 	qq_data *qd;
 	gint len, for_uid;
 	gchar *msg, *data, **segments, *uid, *reply;
@@ -374,20 +358,21 @@
 	list = qd->add_buddy_request;
 	while (list != NULL) {
 		req = (qq_add_buddy_request *) list->data;
-		if (req->seq == seq) {	// reply to this
+		if (req->seq == seq) {	/* reply to this */
 			for_uid = req->uid;
 			qd->add_buddy_request = g_list_remove(qd->add_buddy_request, qd->add_buddy_request->data);
 			g_free(req);
 			break;
 		}
 		list = list->next;
-	}			// while list
+	}
 
-	if (for_uid == 0) {	// we have no record for this
+	if (for_uid == 0) {	/* we have no record for this */
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "We have no record for add buddy reply [%d], discard\n", seq);
 		return;
-	} else
+	} else {
 		gaim_debug(GAIM_DEBUG_INFO, "QQ", "Add buddy reply [%d] is for id [%d]\n", seq, for_uid);
+	}
 
 	data = g_newa(guint8, len);
 
@@ -396,13 +381,13 @@
 			return;
 		uid = segments[0];
 		reply = segments[1];
-		if (strtol(uid, NULL, 10) != qd->uid) {	// should not happen
+		if (strtol(uid, NULL, 10) != qd->uid) {	/* should not happen */
 			gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Add buddy reply is to [%s], not me!", uid);
 			g_strfreev(segments);
 			return;
-		}		// if uid
+		}
 
-		if (strtol(reply, NULL, 10) > 0) {	// need auth
+		if (strtol(reply, NULL, 10) > 0) {	/* need auth */
 			gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add buddy attempt fails, need authentication\n");
 			b = gaim_find_buddy(gc->account, uid_to_gaim_name(for_uid));
 			if (b != NULL)
@@ -419,20 +404,19 @@
 					   (_qq_send_packet_add_buddy_auth_with_gc_and_uid),
 					   _("Cancel"), G_CALLBACK(qq_do_nothing_with_gc_and_uid), g);
 			g_free(msg);
-		} else {	// add OK
+		} else {	/* add OK */
 			qq_add_buddy_by_recv_packet(gc, for_uid, TRUE, TRUE);
 			msg = g_strdup_printf(_("You have added %d in buddy list"), for_uid);
 			gaim_notify_info(gc, NULL, msg, NULL);
 			g_free(msg);
-		}		// if reply
+		}
 		g_strfreev(segments);
-	} else
+	} else {
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt add buddy reply\n");
+	}
+}
 
-}				// qq_process_add_buddy_reply
-
-/*****************************************************************************/
-GaimGroup *qq_get_gaim_group(const gchar * group_name)
+GaimGroup *qq_get_gaim_group(const gchar *group_name)
 {
 	GaimGroup *g;
 
@@ -443,15 +427,15 @@
 		g = gaim_group_new(group_name);
 		gaim_blist_add_group(g, NULL);
 		gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new group: %s\n", group_name);
-	}			// if (g == NULL) 
+	}
 
 	return g;
-}				// qq_get_gaim_group
+}
 
-/*****************************************************************************/
-// we add new buddy, if the received packet is from someone not in my list
-// return the GaimBuddy that is just created
-GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection * gc, guint32 uid, gboolean is_known, gboolean create) {
+/* we add new buddy, if the received packet is from someone not in my list
+ * return the GaimBuddy that is just created */
+GaimBuddy *qq_add_buddy_by_recv_packet(GaimConnection *gc, guint32 uid, gboolean is_known, gboolean create)
+{
 	GaimAccount *a;
 	GaimBuddy *b;
 	GaimGroup *g;
@@ -472,8 +456,8 @@
 
 	name = uid_to_gaim_name(uid);
 	b = gaim_find_buddy(gc->account, name);
-	// remove old, we can not simply return here
-	// because there might be old local copy of this buddy
+	/* remove old, we can not simply return here
+	 * because there might be old local copy of this buddy */
 	if (b != NULL)
 		gaim_blist_remove_buddy(b);
 
@@ -488,7 +472,7 @@
 		qd->buddies = g_list_append(qd->buddies, q_bud);
 		qq_send_packet_get_info(gc, q_bud->uid, FALSE);
 		qq_send_packet_get_buddies_online(gc, QQ_FRIENDS_ONLINE_POSITION_START);
-	}			// if !create
+	}
 
 	gaim_blist_add_buddy(b, NULL, g, NULL);
 	gaim_debug(GAIM_DEBUG_WARNING, "QQ", "Add new buddy: [%s]\n", name);
@@ -497,14 +481,14 @@
 	g_free(group_name);
 
 	return b;
-}				// qq_add_buddy_by_recv_packet
+}
 
-/*****************************************************************************/
-// add a buddy and send packet to QQ server
-// note that when gaim load local cached buddy list into its blist
-// it also calls this funtion, so we have to 
-// define qd->logged_in=TRUE AFTER serv_finish_login(gc)
-void qq_add_buddy(GaimConnection * gc, GaimBuddy * buddy, GaimGroup * group) {
+/* add a buddy and send packet to QQ server
+ * note that when gaim load local cached buddy list into its blist
+ * it also calls this funtion, so we have to 
+ * define qd->logged_in=TRUE AFTER serv_finish_login(gc) */
+void qq_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
+{
 	qq_data *qd;
 	guint32 uid;
 	GaimBuddy *b;
@@ -513,7 +497,7 @@
 
 	qd = (qq_data *) gc->proto_data;
 	if (!qd->logged_in)
-		return;		// IMPORTANT !
+		return;		/* IMPORTANT ! */
 
 	uid = gaim_name_to_uid(buddy->name);
 	if (uid > 0)
@@ -526,11 +510,11 @@
 				  _("QQid Error"),
 				  _("Invalid QQid, to add buddy 1234567, \nyou should input qq-1234567"));
 	}
-}				// _qq_add_buddy
+}
 
-/*****************************************************************************/
-// remove a buddy and send packet to QQ server accordingly
-void qq_remove_buddy(GaimConnection * gc, GaimBuddy * buddy, GaimGroup * group) {
+/* remove a buddy and send packet to QQ server accordingly */
+void qq_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
+{
 	qq_data *qd;
 	GaimBuddy *b;
 	qq_buddy *q_bud;
@@ -554,18 +538,16 @@
 			qd->buddies = g_list_remove(qd->buddies, q_bud);
 		else
 			gaim_debug(GAIM_DEBUG_WARNING, "QQ", "We have no qq_buddy record for %s\n", buddy->name);
-		// remove buddy on blist, this does not trigger qq_remove_buddy again
-		// do this only if the request comes from block request,
-		// otherwise gaim segmentation fault
-		if (g_ascii_strcasecmp(group->name, GAIM_GROUP_QQ_BLOCKED)
-		    == 0)
+		/* remove buddy on blist, this does not trigger qq_remove_buddy again
+		 * do this only if the request comes from block request,
+		 * otherwise gaim segmentation fault */
+		if (g_ascii_strcasecmp(group->name, GAIM_GROUP_QQ_BLOCKED) == 0)
 			gaim_blist_remove_buddy(b);
-	}			// if b != NULL
-}				// _qq_remove_buddy
+	}
+}
 
-/*****************************************************************************/
-// free add buddy request queue
-void qq_add_buddy_request_free(qq_data * qd)
+/* free add buddy request queue */
+void qq_add_buddy_request_free(qq_data *qd)
 {
 	gint i;
 	qq_add_buddy_request *p;
@@ -580,11 +562,10 @@
 		i++;
 	}
 	gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d add buddy requests are freed!\n", i);
-}				// qq_add_buddy_request_free
+}
 
-/*****************************************************************************/
-// free up all qq_buddy
-void qq_buddies_list_free(GaimAccount *account, qq_data * qd)
+/* free up all qq_buddy */
+void qq_buddies_list_free(GaimAccount *account, qq_data *qd)
 {
 	gint i;
 	qq_buddy *p;
@@ -597,21 +578,16 @@
 	while (qd->buddies) {
 		p = (qq_buddy *) (qd->buddies->data);
 		qd->buddies = g_list_remove(qd->buddies, p);
-		// added by gfhuang, for relogin crash bug
 		name = uid_to_gaim_name(p->uid);
 		b = gaim_find_buddy(account, name);   	
-		if(b != NULL) b->proto_data = NULL;
-		else {
+		if(b != NULL) 
+			b->proto_data = NULL;
+		else
 			gaim_debug(GAIM_DEBUG_INFO, "QQ", "qq_buddy %s not found in gaim proto_data\n", name);
-		}
 		g_free(name);
 
 		g_free(p);
 		i++;
 	}
 	gaim_debug(GAIM_DEBUG_INFO, "QQ", "%d qq_buddy structures are freed!\n", i);
-
-}				// qq_buddies_list_free
-
-/*****************************************************************************/
-// END OF FILE
+}