src/protocols/qq/buddy_info.c

changeset 14083
2b68bb18a66c
parent 14076
ac77316596dc
--- a/src/protocols/qq/buddy_info.c	Wed Aug 02 13:37:13 2006 +0000
+++ b/src/protocols/qq/buddy_info.c	Wed Aug 02 15:35:36 2006 +0000
@@ -20,34 +20,33 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "internal.h"		// strlen, _("get_text)
-#include "debug.h"		// gaim_debug
-#include "notify.h"		// gaim_notify
-#include "request.h"		// gaim_request_fields_new
+#include "internal.h"
+#include "debug.h"
+#include "notify.h"
+#include "request.h"
 
-#include "utils.h"		// uid_to_gaim_name
-#include "packet_parse.h"	// MAX_PACKET_SIZE
-#include "buddy_info.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 "send_core.h"		// qq_send_cmd
+#include "utils.h"
+#include "packet_parse.h"
+#include "buddy_info.h"		
+#include "char_conv.h"
+#include "crypt.h"
+#include "header_info.h"
+#include "keep_alive.h"
+#include "send_core.h"
 
-// Below is all of the information necessary to reconstruct the various
-// information fields that one can set in the official client. When we need
-// to know about a specific field (e.g., should "city" be a choice
-// or text field?), we can simply look it up from the template. Note that
-// there are a number of unidentified fields.
-
+/* Below is all of the information necessary to reconstruct the various
+ * information fields that one can set in the official client. When we need
+ * to know about a specific field (e.g., should "city" be a choice
+ * or text field?), we can simply look it up from the template. Note that
+ * there are a number of unidentified fields. */
 typedef struct _info_field {
 	gchar *title;
-	gchar *id;		// used by gaim_request fields
+	gchar *id;		/* used by gaim_request fields */
 	gint pos;
 	gchar *group;
-	gint group_pos;		// for display order in the UI
-	gint choice;		// indicates which character array contains the choices 
-	gboolean customizable;	// whether a user can enter any text as a value, regardless of choice arrays
+	gint group_pos;		/* for display order in the UI */
+	gint choice;		/* indicates which character array contains the choices */
+	gboolean customizable;	/* whether a user can enter any text as a value, regardless of choice arrays */
 	gchar *value;
 } info_field;
 
@@ -89,11 +88,11 @@
 	{ N_("Blood Type"), "blood",		34, QQ_EXTRA_INFO, 3, QQ_BLOOD, FALSE, NULL },
 	{ "qq_show", "qq_show",			35, QQ_MISC, 15, QQ_NO_CHOICE, TRUE, NULL },
 	{ "unknown6", "unknown6",		36, QQ_MISC, 16, QQ_NO_CHOICE, TRUE, NULL },
-	{ NULL,	NULL, 0, NULL, 0, 0, 0, NULL	}	//NULL termination
+	{ NULL,	NULL, 0, NULL, 0, 0, 0, NULL	}
 };
 
-//TODO: translate these arrays to their English equivalents
-// and move these characters to the zh_CN po file
+/* TODO: translate these arrays to their English equivalents
+ * and move these characters to the zh_CN po file */
 static const gchar *horoscope_names[] = {
 	"-", "水瓶座", "双鱼座", "牡羊座", "金牛座",
 	"双子座", "巨蟹座", "狮子座", "处女座", "天秤座",
@@ -159,10 +158,10 @@
         occupation_names
 };
 
-/*************** info and info_field methods *****************/
+/************************ info and info_field methods ************************/
 
-// Given an id, return the template for that field.
-// Returns NULL if the id is not found.
+/* Given an id, return the template for that field.
+ * Returns NULL if the id is not found. */
 static const info_field *info_field_get_template(const gchar *id)
 {
 	const info_field *cur_field;
@@ -171,7 +170,8 @@
 	cur_field = info_template_data;
 	cur_id = cur_field->id;
 	while(cur_id != NULL) {
-		if (g_ascii_strcasecmp(cur_id, id) == 0) return cur_field;
+		if (g_ascii_strcasecmp(cur_id, id) == 0) 
+			return cur_field;
 		cur_field++;
 		cur_id = cur_field->id;
 	}
@@ -179,7 +179,7 @@
 	return NULL;
 }
 
-// info_fields are compared by their group positions
+/* info_fields are compared by their group positions */
 static gint info_field_compare(gconstpointer a, gconstpointer b)
 {
 	return ((info_field *) a)->group_pos - ((info_field *) b)->group_pos;
@@ -191,9 +191,9 @@
 	g_free(i);
 }
 
-// Parses the info_template_data above and returns a newly-allocated list
-// containing the desired fields from segments. This list is ordered by
-// group_pos.
+/* Parses the info_template_data above and returns a newly-allocated list
+ * containing the desired fields from segments. This list is ordered by
+ * group_pos. */
 static GList *info_get_group(const gchar **info, const gchar *group_name)
 {
 	const info_field *cur;
@@ -213,25 +213,27 @@
 	return group;
 }
 
-// determines if the given text value and choice group require
-// a lookup from the choice arrays
+/* Determines if the given text value and choice group require
+ * a lookup from the choice arrays. */
 static gboolean is_valid_index(gchar *value, gint choice)
 {
 	gint len, i;
 
 	if (choice == 0) return FALSE;
 	len = strlen(value);
-	// the server sends us an ascii index and none of the arrays has more than 99
-	// elements
+	/* the server sends us an ascii index and none of the arrays has more than 99
+	 * elements */
 	if (len > 3 || len == 0) return FALSE;
 	for (i = 0; i < len; i++)
-		if (!g_ascii_isdigit(value[i])) return FALSE;
+		if (!g_ascii_isdigit(value[i])) 
+			return FALSE;
 	i = atoi(value);
-	if (i < 0 || i >= choice_sizes[choice]) return FALSE; 
+	if (i < 0 || i >= choice_sizes[choice]) 
+		return FALSE; 
 	return TRUE;
 }
 
-// formats a field for printing
+/* formats a field for printing */
 static void append_field_to_str(gpointer field, gpointer str)
 {
 	info_field *f;
@@ -250,7 +252,7 @@
 	info_field_free(f);
 }
 
-// formats a group of information for printing
+/* formats a group of information for printing */
 static void append_group_to_str(GString *str, const gchar *group_name, const gchar **info)
 {
 	GList *group;
@@ -262,8 +264,8 @@
 	g_string_append_printf(str, "<br />");
 }
 
-// takes a contact_info struct and outputs the appropriate fields in
-// a printable format for our upcoming call to gaim_notify_userinfo
+/* Takes a contact_info struct and outputs the appropriate fields in
+ * a printable format for our upcoming call to gaim_notify_userinfo. */
 static GString *info_to_str(const gchar **info)
 {
 	GString *info_text;
@@ -272,14 +274,14 @@
 	append_group_to_str(info_text, QQ_MAIN_INFO, info);
 	append_group_to_str(info_text, QQ_EXTRA_INFO, info);
 	append_group_to_str(info_text, QQ_PERSONAL_INTRO, info);
-	//if (QQ_DEBUG) append_group_to_str(info_text, QQ_MISC, info);
+	/* append_group_to_str(info_text, QQ_MISC, info); */
 
 	return info_text;
 }
 
-/*************** packets and UI management *****************/
+/************************ packets and UI management **************************/
 
-// send a packet to get detailed information of uid
+/* send a packet to get detailed information of uid */
 void qq_send_packet_get_info(GaimConnection * gc, guint32 uid, gboolean show_window)
 {
 	qq_data *qd;
@@ -301,8 +303,8 @@
 	g_free(uid_str);
 }
 
-// set up the fields requesting personal information and send a get_info packet
-// for myself
+/* set up the fields requesting personal information and send a get_info packet
+ * for myself */
 void qq_prepare_modify_info(GaimConnection *gc)
 {
 	qq_data *qd;
@@ -311,14 +313,15 @@
 
 	qd = (qq_data *) gc->proto_data;
 	qq_send_packet_get_info(gc, qd->uid, FALSE);
-	// traverse backwards so we get the most recent info_query
+	/* traverse backwards so we get the most recent info_query */
 	for (ql = g_list_last(qd->info_query); ql != NULL; ql = g_list_previous(ql)) {
 		query = ql->data;
-		if (query->uid == qd->uid) query->modify_info = TRUE;
+		if (query->uid == qd->uid) 
+			query->modify_info = TRUE;
 	}
 }
 
-// send packet to modify personal information
+/* send packet to modify personal information */
 void qq_send_packet_modify_info(GaimConnection *gc, contact_info *info)
 {
 	gchar *info_field[QQ_CONTACT_FIELDS];
@@ -335,7 +338,7 @@
 
 	create_packet_b(raw_data, &cursor, bar);
 
-	// important!, skip the first uid entry
+	/* important!, skip the first uid entry */
 	for (i = 1; i < QQ_CONTACT_FIELDS; i++) {
 		create_packet_b(raw_data, &cursor, bar);
 		create_packet_data(raw_data, &cursor, (guint8 *) info_field[i], strlen(info_field[i]));
@@ -357,8 +360,8 @@
 	g_free(mid);
 }
 
-// runs through all of the fields in the modify info UI and put
-// their values into the outgoing packet
+/* Runs through all of the fields in the modify info UI and puts
+ * their values into the outgoing packet. */
 static void parse_field(gpointer field, gpointer outgoing_info)
 {
 	GaimRequestField *f;
@@ -370,17 +373,19 @@
 	segments = (gchar **) outgoing_info;
 	id = gaim_request_field_get_id(f);
 	ft = info_field_get_template(id);
-	if (ft->choice && !ft->customizable) 
+	if (ft->choice && !ft->customizable) {
 		value = g_strdup_printf("%d", gaim_request_field_choice_get_value(f));
-	else {
+	} else {
 		value = (gchar *) gaim_request_field_string_get_value(f);
-		if (value == NULL) value = g_strdup("-");
-		else value = utf8_to_qq(value, QQ_CHARSET_DEFAULT);
+		if (value == NULL) 
+			value = g_strdup("-");
+		else 
+			value = utf8_to_qq(value, QQ_CHARSET_DEFAULT);
 	}
 	segments[ft->pos] = value;
 }
 
-// dumps the uneditable information straight into the outgoing packet 
+/* dumps the uneditable information straight into the outgoing packet */
 static void parse_misc_field(gpointer field, gpointer outgoing_info)
 {
 	info_field *f;
@@ -392,8 +397,8 @@
 	info_field_free(f);
 }
 
-// runs through all of the information fields and copies them into an
-// outgoing packet, then sends that packet
+/* Runs through all of the information fields and copies them into an
+ * outgoing packet, then sends that packet. */
 static void modify_info_ok_cb(modify_info_data *mid, GaimRequestFields *fields)
 {
 	GaimConnection *gc;
@@ -424,9 +429,9 @@
 		g_free(info_field[i]);
 }
 
-// Sets up the display for one group of information. This includes
-// managing which fields in the UI should be textfields and
-// which choices, and also mapping ints to choice values when appropriate.
+/* Sets up the display for one group of information. This includes
+ * managing which fields in the UI should be textfields and
+ * which choices, and also mapping ints to choice values when appropriate. */
 static void setup_group(gpointer field, gpointer group)
 {
 	info_field *f;
@@ -449,7 +454,9 @@
 		if (valid_index) {
 			index = atoi(f->value);
 			value = (gchar *) choices[choice][index];
-		} else value = qq_to_utf8(f->value, QQ_CHARSET_DEFAULT);
+		} else {
+			value = qq_to_utf8(f->value, QQ_CHARSET_DEFAULT);
+		}
 		rf = gaim_request_field_string_new(id, f->title, value, multiline);
 	} else {
 		index = atoi(f->value);
@@ -460,12 +467,13 @@
 			gaim_request_field_choice_add(rf, choices[choice][j++]);
 	}
 	gaim_request_field_group_add_field(g, rf);
-	if (!valid_index) g_free(value);
+	if (!valid_index) 
+		g_free(value);
 	info_field_free(f);
 }
 
-// Takes the info returned by a get_info packet for the user and sets up
-// a form using those values and the info_template.
+/* Takes the info returned by a get_info packet for the user and sets up
+ * a form using those values and the info_template. */
 static void create_modify_info_dialogue(GaimConnection *gc, const gchar **info)
 {
 	qq_data *qd;
@@ -476,14 +484,14 @@
 	modify_info_data *mid;
 	gint i;
 
-	// so we only have one dialog open at a time
+	/* so we only have one dialog open at a time */
 	qd = (qq_data *) gc->proto_data;
 	if (!qd->modifying_info) {
 		qd->modifying_info = TRUE;
 
 		fields = gaim_request_fields_new();
 	
-		// we only care about the first 3 groups, not the miscellaneous stuff
+		/* we only care about the first 3 groups, not the miscellaneous stuff */
 		for (i = 0; i < 3; i++) {
 			group = gaim_request_field_group_new(info_group_headers[i]);
 			gaim_request_fields_add_group(fields, group);
@@ -492,12 +500,9 @@
 			g_list_free(group_list);
 		}
 
-		//set this manually here instead of generating a new template column
 		field = gaim_request_fields_get_field(fields, "uid");
 		gaim_request_field_string_set_editable(field, FALSE);
 
-		//we need to pass the info that doesn't get modified as aux data
-		//because we'll still need it when we send the modify_info packet
 		mid = g_new0(modify_info_data, 1);
 		mid->gc = gc;
 		mid->misc = info_get_group(info, info_group_headers[3]);
@@ -510,7 +515,7 @@
 	}
 }
 
-// process the reply of modify_info packet
+/* process the reply of modify_info packet */
 void qq_process_modify_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
 {
 	qq_data *qd;
@@ -526,16 +531,16 @@
 
 	if (qq_crypt(DECRYPT, buf, buf_len, qd->session_key, data, &len)) {
 		data[len] = '\0';
-		if (qd->uid == atoi((gchar *) data)) {	// return should be my uid
+		if (qd->uid == atoi((gchar *) data)) {	/* return should be my uid */
 			gaim_debug(GAIM_DEBUG_INFO, "QQ", "Update info ACK OK\n");
 			gaim_notify_info(gc, NULL, _("Your information has been updated"), NULL);
 		}
-	} else
+	} else {
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt modify info reply\n");
-
+	}
 }
 
-// after getting info or modify myself, refresh the buddy list accordingly
+/* after getting info or modify myself, refresh the buddy list accordingly */
 void qq_refresh_buddy_and_myself(contact_info *info, GaimConnection *gc)
 {
 	GaimBuddy *b;
@@ -547,15 +552,15 @@
 	qd = (qq_data *) gc->proto_data;
 
 	alias_utf8 = qq_to_utf8(info->nick, QQ_CHARSET_DEFAULT);
-	if (qd->uid == strtol(info->uid, NULL, 10)) {	// it is me
+	if (qd->uid == strtol(info->uid, NULL, 10)) {	/* it is me */
 		qd->my_icon = strtol(info->face, NULL, 10);
 		if (alias_utf8 != NULL)
 			gaim_account_set_alias(gc->account, alias_utf8);
 	}
-	// update buddy list (including myself, if myself is the buddy)
+	/* update buddy list (including myself, if myself is the buddy) */
 	b = gaim_find_buddy(gc->account, uid_to_gaim_name(strtol(info->uid, NULL, 10)));
 	q_bud = (b == NULL) ? NULL : (qq_buddy *) b->proto_data;
-	if (q_bud != NULL) {	// I have this buddy
+	if (q_bud != NULL) {	/* I have this buddy */
 		q_bud->age = strtol(info->age, NULL, 10);
 		q_bud->gender = strtol(info->gender, NULL, 10);
 		q_bud->icon = strtol(info->face, NULL, 10);
@@ -566,7 +571,7 @@
 	g_free(alias_utf8);
 }
 
-// process reply to get_info packet
+/* process reply to get_info packet */
 void qq_process_get_info_reply(guint8 *buf, gint buf_len, GaimConnection *gc)
 {
 	gint len;
@@ -595,7 +600,7 @@
 		qq_refresh_buddy_and_myself(info, gc);
 
 		query_list = qd->info_query;
-		// ensure we're processing the right query
+		/* ensure we're processing the right query */
 		while (query_list) {
 			query = (qq_info_query *) query_list->data;
 			if (query->uid == atoi(info->uid)) {
@@ -614,12 +619,12 @@
 		}
 
 		g_strfreev(segments);
-	} else
+	} else {
 		gaim_debug(GAIM_DEBUG_ERROR, "QQ", "Error decrypt get info reply\n");
-
+	}
 }
 
-void qq_info_query_free(qq_data * qd)
+void qq_info_query_free(qq_data *qd)
 {
 	gint i;
 	qq_info_query *p;

mercurial