changeset 5318:bd98232872a3

[gaim-migrate @ 5690] Renaming a group on the buddy list now renames the group on the server-stored buddy list. Also, we updated to MSNP7 on the notification server as well! Yay! committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 06 May 2003 23:07:12 +0000
parents 2b437c18719e
children 3adb20b869b4
files src/protocols/msn/msn.c src/protocols/msn/notification.c src/protocols/msn/session.c src/protocols/msn/session.h
diffstat 4 files changed, 97 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/msn.c	Tue May 06 22:42:00 2003 +0000
+++ b/src/protocols/msn/msn.c	Tue May 06 23:07:12 2003 +0000
@@ -748,6 +748,44 @@
 }
 
 static void
+msn_group_buddy(struct gaim_connection *gc, const char *who,
+				const char *old_group, const char *new_group)
+{
+	
+}
+
+static void
+msn_rename_group(struct gaim_connection *gc, const char *old_group,
+				 const char *new_group, GList *members)
+{
+	MsnSession *session = gc->proto_data;
+	char outparams[MSN_BUF_LEN];
+	int *group_id;
+
+	if (g_hash_table_lookup_extended(session->group_ids, old_group,
+									 NULL, (gpointer)&group_id)) {
+		g_snprintf(outparams, sizeof(outparams), "%d %s 0",
+				   *group_id, msn_url_encode(new_group));
+
+		if (!msn_servconn_send_command(session->notification_conn,
+									   "REG", outparams)) {
+			hide_login_progress(gc, _("Write error"));
+			signoff(gc);
+		}
+	}
+	else {
+		g_snprintf(outparams, sizeof(outparams), "%s 0",
+				   msn_url_encode(new_group));
+
+		if (!msn_servconn_send_command(session->notification_conn,
+									   "ADG", outparams)) {
+			hide_login_progress(gc, _("Write error"));
+			signoff(gc);
+		}
+	}
+}
+
+static void
 msn_buddy_free(struct buddy *b)
 {
 	if (b->proto_data != NULL)
@@ -833,8 +871,8 @@
 	NULL,
 	NULL,
 	NULL,
-	NULL,
-	NULL,
+	msn_group_buddy,
+	msn_rename_group,
 	msn_buddy_free,
 	msn_convo_closed,
 	msn_normalize
--- a/src/protocols/msn/notification.c	Tue May 06 22:42:00 2003 +0000
+++ b/src/protocols/msn/notification.c	Tue May 06 23:07:12 2003 +0000
@@ -110,17 +110,16 @@
 __unknown_cmd(MsnServConn *servconn, const char *command, const char **params,
 			  size_t param_count)
 {
-	struct gaim_connection *gc = servconn->session->account->gc;
+	char buf[MSN_BUF_LEN];
 
-	if (isdigit(*command)) {
-		hide_login_progress(gc, (char *)msn_error_get_text(atoi(command)));
-	}
-	else
-		hide_login_progress(gc, _("Unable to parse message."));
+	g_snprintf(buf, sizeof(buf), "MSN Error: %s\n",
+			   (isdigit(*command)
+				? msn_error_get_text(atoi(command))
+				: "Unable to parse message."));
 
-	signoff(gc);
+	do_error_dialog(buf, NULL, GAIM_ERROR);
 
-	return FALSE;
+	return TRUE;
 }
 
 
@@ -440,19 +439,31 @@
 	struct group *g;
 	const char *name;
 	int group_num, num_groups, group_id;
+	gint *group_id_1, *group_id_2;
 
 	group_num  = atoi(params[2]);
 	num_groups = atoi(params[3]);
 	group_id   = atoi(params[4]);
 	name       = msn_url_decode(params[5]);
 
+	if (num_groups == 0)
+		return TRUE;
+
 	if (group_num == 1) {
-		session->groups = g_hash_table_new_full(g_int_hash, g_int_equal,
-												NULL, g_free);
+		session->group_names = g_hash_table_new_full(g_int_hash, g_int_equal,
+													 g_free, g_free);
+		session->group_ids = g_hash_table_new_full(g_str_hash, g_str_equal,
+												   g_free, g_free);
 	}
 
-	g_hash_table_insert(session->groups, GINT_TO_POINTER(group_id),
-						g_strdup(name));
+	group_id_1 = g_new(gint, 1);
+	group_id_2 = g_new(gint, 1);
+
+	*group_id_1 = group_id;
+	*group_id_2 = group_id;
+
+	g_hash_table_insert(session->group_names, group_id_1, g_strdup(name));
+	g_hash_table_insert(session->group_ids, g_strdup(name), group_id_2);
 
 	if ((g = gaim_find_group(name)) == NULL) {
 		g = gaim_group_new(name);
@@ -585,8 +596,8 @@
 				group_id = msn_user_get_group_id(user);
 
 				if (group_id > -1) {
-					group_name = g_hash_table_lookup(session->groups,
-							GINT_TO_POINTER(group_id));
+					group_name = g_hash_table_lookup(session->group_names,
+													 &group_id);
 				}
 
 				if (group_name == NULL) {
@@ -674,6 +685,31 @@
 	return TRUE;
 }
 
+static gboolean
+__reg_cmd(MsnServConn *servconn, const char *command, const char **params,
+		  size_t param_count)
+{
+	MsnSession *session = servconn->session;
+	gint *group_id;
+	char *group_name;
+
+	group_id = g_new(gint, 1);
+	*group_id = atoi(params[2]);
+
+	group_name = msn_url_decode(params[3]);
+
+	gaim_debug(GAIM_DEBUG_INFO, "msn", "Renamed group %s to %s\n",
+			   g_hash_table_lookup(session->group_names, group_id),
+			   group_name);
+
+	g_hash_table_replace(session->group_names, group_id, g_strdup(group_name));
+
+	g_hash_table_remove(session->group_ids, group_name);
+	g_hash_table_insert(session->group_ids, group_name, group_id);
+
+	return TRUE;
+}
+
 /**************************************************************************
  * Misc commands
  **************************************************************************/
@@ -973,7 +1009,7 @@
 		notification->fd = source;
 
 	if (!msn_servconn_send_command(notification, "VER",
-								   "MSNP6 MSNP5 MSNP4 CVR0")) {
+								   "MSNP7 MSNP6 MSNP5 MSNP4 CVR0")) {
 		hide_login_progress(gc, _("Unable to write to server"));
 		signoff(gc);
 		return FALSE;
@@ -1027,6 +1063,7 @@
 		msn_servconn_register_command(notification, "QNG",       __blank_cmd);
 		msn_servconn_register_command(notification, "QRY",       __blank_cmd);
 		msn_servconn_register_command(notification, "REA",       __rea_cmd);
+		msn_servconn_register_command(notification, "REG",       __reg_cmd);
 		msn_servconn_register_command(notification, "REM",       __blank_cmd);
 		msn_servconn_register_command(notification, "RNG",       __rng_cmd);
 		msn_servconn_register_command(notification, "SYN",       __blank_cmd);
--- a/src/protocols/msn/session.c	Tue May 06 22:42:00 2003 +0000
+++ b/src/protocols/msn/session.c	Tue May 06 23:07:12 2003 +0000
@@ -58,6 +58,9 @@
 	while (session->lists.forward)
 		msn_user_destroy(session->lists.forward->data);
 
+	if (session->group_ids)   g_hash_table_destroy(session->group_ids);
+	if (session->group_names) g_hash_table_destroy(session->group_names);
+
 	g_slist_free(session->lists.allow);
 	g_slist_free(session->lists.block);
 
--- a/src/protocols/msn/session.h	Tue May 06 22:42:00 2003 +0000
+++ b/src/protocols/msn/session.h	Tue May 06 23:07:12 2003 +0000
@@ -45,7 +45,8 @@
 	MsnUsers *users;
 
 	GList *switches;
-	GHashTable *groups;
+	GHashTable *group_names; /* ID -> name */
+	GHashTable *group_ids;   /* Name -> ID */
 
 	struct
 	{