changeset 10044:86a6d78b070b

[gaim-migrate @ 11003] this is the msn buddy list sync code from the 1.0.0 tree, also from shx. in this patch, i changed one instance of "b" to "buddy" to make it compile. this introduces code to ask the user about discrepances between the local and server lists on msn. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sun, 19 Sep 2004 03:02:28 +0000
parents 700f8fb9e581
children ac98ece02b1f
files src/protocols/msn/Makefile.am src/protocols/msn/Makefile.mingw src/protocols/msn/dialog.c src/protocols/msn/dialog.h src/protocols/msn/msn.c src/protocols/msn/notification.c src/protocols/msn/session.c src/protocols/msn/session.h src/protocols/msn/switchboard.c src/protocols/msn/sync.c src/protocols/msn/user.c src/protocols/msn/userlist.c
diffstat 12 files changed, 450 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/Makefile.am	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/Makefile.am	Sun Sep 19 03:02:28 2004 +0000
@@ -8,6 +8,8 @@
 	cmdproc.h \
 	command.c \
 	command.h \
+	dialog.c \
+	dialog.h \
 	directconn.c \
 	directconn.h \
 	error.c \
--- a/src/protocols/msn/Makefile.mingw	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/Makefile.mingw	Sun Sep 19 03:02:28 2004 +0000
@@ -70,6 +70,7 @@
 
 C_SRC =			cmdproc.c \
 			command.c \
+			dialog.c \
 			directconn.c \
 			error.c \
 			group.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/dialog.c	Sun Sep 19 03:02:28 2004 +0000
@@ -0,0 +1,128 @@
+/**
+ * @file dialog.c Dialog functions
+ *
+ * gaim
+ *
+ * Gaim is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "msn.h"
+
+typedef struct
+{
+	GaimConnection *gc;
+	char *who;
+	char *group;
+	gboolean add;
+
+} MsnAddRemData;
+
+static void
+msn_add_cb(MsnAddRemData *data)
+{
+	if (g_list_find(gaim_connections_get_all(), data->gc) != NULL)
+	{
+		MsnSession *session = data->gc->proto_data;
+		MsnUserList *userlist = session->userlist;
+
+		msn_userlist_add_buddy(userlist, data->who, MSN_LIST_FL, data->group);
+	}
+
+	if (data->group != NULL)
+		g_free(data->group);
+
+	g_free(data->who);
+	g_free(data);
+}
+
+static void
+msn_rem_cb(MsnAddRemData *data)
+{
+	if (g_list_find(gaim_connections_get_all(), data->gc) != NULL)
+	{
+		MsnSession *session = data->gc->proto_data;
+		MsnUserList *userlist = session->userlist;
+
+		msn_userlist_rem_buddy(userlist, data->who, MSN_LIST_FL, data->group);
+	}
+
+	if (data->group != NULL)
+		g_free(data->group);
+
+	g_free(data->who);
+	g_free(data);
+}
+
+void
+msn_show_sync_issue(MsnSession *session, const char *passport,
+					const char *group_name)
+{
+	GaimConnection *gc;
+	GaimAccount *account;
+	MsnAddRemData *data;
+	char *msg, *reason;
+	GaimBuddy *buddy;
+	GaimGroup *group = NULL;
+
+	account = session->account;
+	gc = gaim_account_get_connection(account);
+
+	data        = g_new0(MsnAddRemData, 1);
+	data->who   = g_strdup(passport);
+	data->group = g_strdup(group_name);
+	data->gc    = gc;
+
+	msg = g_strdup_printf(_("Buddy list syncronization issue in %s (%s)"),
+						  gaim_account_get_username(account),
+						  gaim_account_get_protocol_name(account));
+
+	if (group_name != NULL)
+	{
+		reason = g_strdup_printf(_("%s on the local list is "
+								   "inside the group \"%s\" but not on "
+								   "the server list. "
+								   "Do you want this buddy to be added?"),
+								 passport, group_name);
+	}
+	else
+	{
+		reason = g_strdup_printf(_("%s is on the local list but "
+								   "not on the server list. "
+								   "Do you want this buddy to be added?"),
+								 passport);
+	}
+
+	gaim_request_action(gc, NULL, msg, reason, 0, data, 2,
+						_("Yes"), G_CALLBACK(msn_add_cb),
+						_("No"), G_CALLBACK(msn_rem_cb));
+
+	if (group_name != NULL)
+		group = gaim_find_group(group_name);
+
+	if (group != NULL)
+		buddy = gaim_find_buddy_in_group(account, passport, group);
+	else
+		buddy = gaim_find_buddy(account, passport);
+
+	if (buddy != NULL)
+		gaim_blist_remove_buddy(buddy);
+
+	g_free(reason);
+	g_free(msg);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/protocols/msn/dialog.h	Sun Sep 19 03:02:28 2004 +0000
@@ -0,0 +1,30 @@
+/**
+ * @file dialog.h Dialog functions
+ *
+ * gaim
+ *
+ * Gaim is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#ifndef _MSN_DIALOG_H_
+#define _MSN_DIALOG_H_
+
+void msn_show_sync_issue(MsnSession *session, const char *passport,
+						 const char *group_name);
+
+#endif /* _MSN_DIALOG_H_ */
--- a/src/protocols/msn/msn.c	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/msn.c	Sun Sep 19 03:02:28 2004 +0000
@@ -423,13 +423,27 @@
 static char *
 msn_status_text(GaimBuddy *buddy)
 {
-	GaimPresence *presence = gaim_buddy_get_presence(buddy);
-	GaimStatus *status = gaim_presence_get_active_status(presence);
+	GString *s;
+	GaimPresence *presence;
+	GaimStatus *status;
+	MsnUser *user;
+
+	s = g_string_new("");
+	user = buddy->proto_data;
+	presence = gaim_buddy_get_presence(buddy);
+	status = gaim_presence_get_active_status(presence);
 
 	if (!gaim_status_is_available(status))
-		return g_strdup(gaim_status_get_name(status));
+	{
+		g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Status"),
+							   gaim_status_get_name(status));
+	}
 
-	return NULL;
+	g_string_append_printf(s, _("\n<b>%s:</b> %s"), _("Has you"),
+						   (user->list_op & (1 << MSN_LIST_RL)) ?
+						   _("Yes") : _("No"));
+
+	return g_string_free(s, FALSE);
 }
 
 static char *
@@ -611,7 +625,7 @@
 		gaim_debug_info("msn", "using http method\n");
 
 		host = "gateway.messenger.hotmail.com";
-		port   = 80;
+		port = 80;
 	}
 	else
 	{
@@ -801,6 +815,54 @@
 }
 
 static void
+fake_userlist_add_buddy(MsnUserList *userlist,
+					   const char *who, int list_id,
+					   const char *group_name)
+{
+	MsnUser *user;
+	static int group_id_c = 1;
+	int group_id;
+
+	group_id = -1;
+
+	if (group_name != NULL)
+	{
+		MsnGroup *group;
+		group = msn_group_new(userlist, group_id_c, group_name);
+		group_id = group_id_c++;
+	}
+
+	user = msn_userlist_find_user(userlist, who);
+
+	if (user == NULL)
+	{
+		user = msn_user_new(userlist, who, NULL);
+		msn_userlist_add_user(userlist, user);
+	}
+	else
+		if (user->list_op & (1 << list_id))
+		{
+			if (list_id == MSN_LIST_FL)
+			{
+				if (group_id >= 0)
+					if (g_list_find(user->group_ids,
+									GINT_TO_POINTER(group_id)))
+						return;
+			}
+			else
+				return;
+		}
+
+	if (group_id >= 0)
+	{
+		user->group_ids = g_list_append(user->group_ids,
+										GINT_TO_POINTER(group_id));
+	}
+
+	user->list_op |= (1 << list_id);
+}
+
+static void
 msn_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group)
 {
 	MsnSession *session;
@@ -812,12 +874,19 @@
 	who = msn_normalize(gc->account, buddy->name);
 
 	if (!session->logged_in)
+	{
+		fake_userlist_add_buddy(session->sync_userlist, who, MSN_LIST_FL,
+								group ? group->name : NULL);
+
 		return;
+	}
 
+#if 0
 	if (group != NULL && group->name != NULL)
 		gaim_debug_info("msn", "msn_add_buddy: %s, %s\n", who, group->name);
 	else
 		gaim_debug_info("msn", "msn_add_buddy: %s\n", who);
+#endif
 
 #if 0
 	/* Which is the max? */
@@ -830,7 +899,9 @@
 	}
 #endif
 
-	/* XXX - Would group ever be NULL here?  I don't think so... */
+	/* XXX - Would group ever be NULL here?  I don't think so...
+	 * shx: Yes it should; MSN handles non-grouped buddies, and this is only
+	 * internal. */
 	msn_userlist_add_buddy(userlist, who, MSN_LIST_FL,
 						   group ? group->name : NULL);
 }
@@ -1147,53 +1218,78 @@
 }
 
 static char *
-msn_tooltip_info_text(MsnGetInfoData *info_data) {
-	GString *s = g_string_sized_new(80); /* wild guess */
+msn_tooltip_info_text(MsnGetInfoData *info_data)
+{
+	GString *s;
 	GString *name;
 	GaimBuddy *b;
 	const char *p;
 
+	s = g_string_sized_new(80); /* wild guess */
+
 	/* Try to not display the MSN screen name as an email address */
 	p = strrchr(info_data->name, '@');
-	if (p) {
+	if (p)
+	{
 		name = g_string_new_len(info_data->name, p - info_data->name);
 		g_string_append_printf(name, "&#64;%s", p + 1);
-	} else { /* This should never happen */
+	}
+	else
+	{
+		/* This should never happen */
 		name = g_string_new(info_data->name);
 	}
+
 	g_string_printf(s, "<span style=\"font-size: larger\"><b>%s</b></span><br>",
-			name->str);
+					name->str);
 	g_string_free(name, TRUE);
 	b = gaim_find_buddy(gaim_connection_get_account(info_data->gc),
-			info_data->name);
+						info_data->name);
 
-	if (b) {
+	if (b)
+	{
+		MsnUser *user;
 		GaimPresence *presence;
 		char *statustext = msn_tooltip_text(b);
+
 		presence = gaim_buddy_get_presence(b);
-		if(b->alias && b->alias[0]) {
+
+		if (b->alias && b->alias[0])
+		{
 			char *aliastext = g_markup_escape_text(b->alias, -1);
 			g_string_append_printf(s, _("<b>Alias:</b> %s<br>"), aliastext);
 			g_free(aliastext);
 		}
-		if(b->server_alias) {
+
+		if (b->server_alias)
+		{
 			char *nicktext = g_markup_escape_text(b->server_alias, -1);
 			g_string_append_printf(s, _("<b>%s:</b> "), _("Nickname"));
 			g_string_append_printf(s, "<font sml=\"msn\">%s</font><br>",
 					nicktext);
 			g_free(nicktext);
 		}
-		if (gaim_presence_is_idle(presence)) {
+
+		if (gaim_presence_is_idle(presence))
+		{
 			char *idletime = gaim_str_seconds_to_string(time(NULL) -
 										gaim_presence_get_idle_time(presence));
 			g_string_append_printf(s, _("<b>%s:</b> %s<br>"), _("Idle"),
 					idletime);
 			g_free(idletime);
 		}
-		if (statustext) {
+
+		if (statustext)
+		{
 			g_string_append_printf(s, "%s<br>", statustext);
 			g_free(statustext);
 		}
+
+		user = b->proto_data;
+
+		g_string_append_printf(s, _("<b>%s:</b> %s<br>"), _("Has you"),
+							   (user->list_op & (1 << MSN_LIST_RL)) ? 
+							   _("yes") : _("no"));
 	}
 
 	return g_string_free(s, FALSE);
@@ -1201,25 +1297,32 @@
 
 #if PHOTO_SUPPORT
 
-static char *msn_get_photo_url(const char *url_text) {
+static char *
+msn_get_photo_url(const char *url_text)
+{
 	char *p;
 	char *it = NULL;
 
 	p = strstr(url_text, " title=\"Click to see the full-size photo.\">");
 
-	if (p) {
+	if (p)
+	{
 		/* Search backwards for "http://". This is stupid, but it works. */
-		for (; !it && p > url_text; p -= 1) {
-			if (strncmp(p, "\"http://", 8) == 0) {
+		for (; !it && p > url_text; p -= 1)
+		{
+			if (strncmp(p, "\"http://", 8) == 0)
+			{
 				char *q;
 				p += 1; /* skip only the " */
 				q = strchr(p, '"');
-				if (q) {
+				if (q)
+				{
 					it = g_strndup(p, q - p);
 				}
 			}
 		}
 	}
+
 	return it;
 }
 
@@ -1541,16 +1644,20 @@
 	info2_data->title = title;
 
 	/* Try to put the photo in there too, if there's one */
-	if (photo_url_text) {
+	if (photo_url_text)
+	{
 		gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, msn_got_photo,
-				info2_data);
-	} else {
+					   info2_data);
+	}
+	else
+	{
 		/* Emulate a callback */
 		msn_got_photo(info2_data, NULL, 0);
 	}
 }
 
-static void msn_got_photo(void *data, const char *url_text, size_t len)
+static void
+msn_got_photo(void *data, const char *url_text, size_t len)
 {
 	MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)data;
 	int id = -1;
@@ -1565,14 +1672,18 @@
 	const char *title = info2_data->title;
 
 	/* Try to put the photo in there too, if there's one and is readable */
-	if (data && url_text && len != 0) {
+	if (data && url_text && len != 0)
+	{
 		if (strstr(url_text, "400 Bad Request")
-				|| strstr(url_text, "403 Forbidden")
-				|| strstr(url_text, "404 Not Found")) {
+			|| strstr(url_text, "403 Forbidden")
+			|| strstr(url_text, "404 Not Found"))
+		{
 
 			gaim_debug_info("msn", "Error getting %s: %s\n",
 					photo_url_text, url_text);
-		} else {
+		}
+		else
+		{
 			char buf[1024];
 			gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len);
 			id = gaim_imgstore_add(url_text, len, NULL);
@@ -1640,7 +1751,8 @@
 }
 
 static GaimPluginPrefFrame *
-get_plugin_pref_frame(GaimPlugin *plugin) {
+get_plugin_pref_frame(GaimPlugin *plugin)
+{
 	GaimPluginPrefFrame *frame;
 	GaimPluginPref *ppref;
 
--- a/src/protocols/msn/notification.c	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/notification.c	Sun Sep 19 03:02:28 2004 +0000
@@ -317,8 +317,6 @@
 
 	if (user == NULL)
 	{
-		gaim_debug_info("msn", "Creating new user. '%s' was not found.\n",
-						passport);
 		user = msn_user_new(session->userlist, passport, friendly);
 		msn_userlist_add_user(session->userlist, user);
 	}
@@ -410,7 +408,6 @@
 	g_strfreev(params);
 }
 
-
 static void
 adg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
@@ -711,19 +708,14 @@
 syn_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnSession *session;
-	GaimConnection *gc;
 	int total_users;
 
 	session = cmdproc->session;
-	gc = gaim_account_get_connection(session->account);
 	total_users  = atoi(cmd->params[2]);
 
 	if (total_users == 0)
 	{
-		gaim_connection_set_state(gc, GAIM_CONNECTED);
-		session->logged_in = TRUE;
-		
-		serv_finish_login(gc);
+		msn_session_finish_login(session);
 	}
 	else
 	{
--- a/src/protocols/msn/session.c	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/session.c	Sun Sep 19 03:02:28 2004 +0000
@@ -27,6 +27,8 @@
 
 #include "slplink.h"
 
+#include "dialog.h"
+
 MsnSession *
 msn_session_new(GaimAccount *account, const char *host, int port,
 				gboolean http_method)
@@ -44,6 +46,7 @@
 
 	session->notification = msn_notification_new(session);
 	session->userlist = msn_userlist_new(session);
+	session->sync_userlist = msn_userlist_new(session);
 
 	session->protocol_ver = 9;
 
@@ -72,6 +75,9 @@
 
 	msn_userlist_destroy(session->userlist);
 
+	if (session->sync_userlist != NULL)
+		msn_userlist_destroy(session->sync_userlist);
+
 	if (session->passport_info.kv != NULL)
 		g_free(session->passport_info.kv);
 
@@ -186,3 +192,97 @@
 
 	return swboard;
 }
+
+static void
+msn_session_sync_users(MsnSession *session)
+{
+	GList *l;
+
+	l = session->sync_userlist->users;
+
+	while (l != NULL)
+	{
+		MsnUser *local_user;
+
+		local_user = (MsnUser *)l->data;
+
+		if (local_user->passport != NULL)
+		{
+			MsnUser *remote_user;
+
+			remote_user = msn_userlist_find_user(session->userlist,
+												 local_user->passport);
+
+			if (remote_user == NULL ||
+				((local_user->list_op & ( 1 << MSN_LIST_FL)) &&
+				 !(remote_user->list_op & ( 1 << MSN_LIST_FL))))
+			{
+				/* The user was not on the server list */
+				msn_show_sync_issue(session, local_user->passport, NULL);
+			}
+			else
+			{
+				GList *l;
+
+				for (l = local_user->group_ids; l != NULL; l = l->next)
+				{
+					const char *group_name;
+					int gid;
+					gboolean found = FALSE;
+					GList *l2;
+
+					group_name =
+						msn_userlist_find_group_name(local_user->userlist,
+													 (int)l->data);
+
+					gid = msn_userlist_find_group_id(remote_user->userlist,
+													 group_name);
+
+					for (l2 = remote_user->group_ids; l2 != NULL; l2 = l2->next)
+					{
+						if ((int)l2->data == gid)
+						{
+							found = TRUE;
+							break;
+						}
+					}
+
+					if (!found)
+					{
+						/* The user was not on that group on the server list */
+						msn_show_sync_issue(session, local_user->passport,
+											group_name);
+					}
+				}
+			}
+		}
+
+		l = l->next;
+	}
+
+	msn_userlist_destroy(session->sync_userlist);
+	session->sync_userlist = NULL;
+}
+
+void
+msn_session_finish_login(MsnSession *session)
+{
+	GaimAccount *account;
+	GaimConnection *gc;
+
+	account = session->account;
+	gc = gaim_account_get_connection(account);
+
+	msn_user_set_buddy_icon(session->user,
+							gaim_account_get_buddy_icon(session->account));
+
+	msn_change_status(session, MSN_ONLINE);
+
+	gaim_connection_set_state(gc, GAIM_CONNECTED);
+	session->logged_in = TRUE;
+
+	/* Sync users */
+	msn_session_sync_users(session);
+
+	serv_finish_login(gc);
+}
--- a/src/protocols/msn/session.h	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/session.h	Sun Sep 19 03:02:28 2004 +0000
@@ -60,6 +60,7 @@
 	gint http_poll_timer;
 
 	MsnUserList *userlist;
+	MsnUserList *sync_userlist;
 
 	int servconns_count;
 	GList *switches;
@@ -141,4 +142,6 @@
 MsnSwitchBoard *msn_session_get_swboard(MsnSession *session,
 										const char *username);
 
+void msn_session_finish_login(MsnSession *session);
+
 #endif /* _MSN_SESSION_H_ */
--- a/src/protocols/msn/switchboard.c	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/switchboard.c	Sun Sep 19 03:02:28 2004 +0000
@@ -605,13 +605,14 @@
 	swboard->servconn = servconn = msn_servconn_new(session, MSN_SERVER_SB);
 	cmdproc = servconn->cmdproc;
 
-	msn_servconn_set_connect_cb(servconn, connect_cb);
-	msn_servconn_set_disconnect_cb(servconn, disconnect_cb);
-
 	swboard->im_queue = g_queue_new();
 
 	if (session->http_method)
 		servconn->http_data->server_type = "SB";
+	else
+		msn_servconn_set_connect_cb(servconn, connect_cb);
+
+	msn_servconn_set_disconnect_cb(servconn, disconnect_cb);
 
 	servconn->data = swboard;
 
@@ -799,8 +800,40 @@
 	msn_parse_socket(cmd->params[2], &host, &port);
 
 	if (swboard->session->http_method)
+	{
+		GaimAccount *account;
+		MsnSession *session;
+		MsnServConn *servconn;
+
 		port = 80;
 
+		session = swboard->session;
+		servconn = swboard->servconn;
+		account = session->account;
+
+		swboard->user_joined = TRUE;
+
+		servconn->http_data->gateway_host = g_strdup(host);
+
+#if 0
+		servconn->connected = TRUE;
+		servconn->cmdproc->ready = TRUE;
+#endif
+
+		if (msn_switchboard_is_invited(swboard))
+		{
+			msn_cmdproc_send(servconn->cmdproc, "ANS", "%s %s %s",
+							 gaim_account_get_username(account),
+							 swboard->auth_key, swboard->session_id);
+		}
+		else
+		{
+			msn_cmdproc_send(servconn->cmdproc, "USR", "%s %s",
+							 gaim_account_get_username(account),
+							 swboard->auth_key);
+		}
+	}
+
 	msn_switchboard_connect(swboard, host, port);
 }
 
--- a/src/protocols/msn/sync.c	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/sync.c	Sun Sep 19 03:02:28 2004 +0000
@@ -110,24 +110,14 @@
 lst_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnSession *session = cmdproc->session;
-	GaimAccount *account = session->account;
-	GaimConnection *gc = gaim_account_get_connection(account);
 	char *passport = NULL;
 	const char *friend = NULL;
 	int list_op;
 	MsnUser *user;
 
-	passport   = cmd->params[0];
-	friend     = gaim_url_decode(cmd->params[1]);
-	list_op    = atoi(cmd->params[2]);
-
-#if 0
-	gaim_debug_misc("msn", "Got list op = %d\n", list_op);
-	gaim_debug_misc("msn", "FL = %d\n", (list_op & MSN_LIST_FL_OP));
-	gaim_debug_misc("msn", "AL = %d\n", (list_op & MSN_LIST_AL_OP));
-	gaim_debug_misc("msn", "BL = %d\n", (list_op & MSN_LIST_BL_OP));
-	gaim_debug_misc("msn", "RL = %d\n", (list_op & MSN_LIST_RL_OP));
-#endif
+	passport = cmd->params[0];
+	friend   = gaim_url_decode(cmd->params[1]);
+	list_op  = atoi(cmd->params[2]);
 
 	user = msn_user_new(session->userlist, passport, friend);
 
@@ -175,15 +165,7 @@
 	{
 		cmdproc->cbs_table = session->sync->old_cbs_table;
 
-		msn_user_set_buddy_icon(session->user,
-								gaim_account_get_buddy_icon(session->account));
-
-		msn_change_status(session, MSN_ONLINE);
-
-		gaim_connection_set_state(gc, GAIM_CONNECTED);
-		session->logged_in = TRUE;
-
-		serv_finish_login(gc);
+		msn_session_finish_login(session);
 
 		msn_sync_destroy(session->sync);
 		session->sync = NULL;
--- a/src/protocols/msn/user.c	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/user.c	Sun Sep 19 03:02:28 2004 +0000
@@ -210,7 +210,7 @@
 	const char *group_name;
 
 	g_return_if_fail(user != NULL);
-	g_return_if_fail(id > -1);
+	g_return_if_fail(id >= 0);
 
 	user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(id));
 
@@ -238,7 +238,7 @@
 msn_user_remove_group_id(MsnUser *user, int id)
 {
 	g_return_if_fail(user != NULL);
-	g_return_if_fail(id > -1);
+	g_return_if_fail(id >= 0);
 
 	user->group_ids = g_list_remove(user->group_ids, GINT_TO_POINTER(id));
 }
--- a/src/protocols/msn/userlist.c	Sun Sep 19 02:53:00 2004 +0000
+++ b/src/protocols/msn/userlist.c	Sun Sep 19 03:02:28 2004 +0000
@@ -250,14 +250,6 @@
 						"%s has added you to his or her contact list.\n",
 						passport);
 
-#if 0
-		gaim_debug_misc("msn", "User's list op = %d\n", user->list_op);
-		gaim_debug_misc("msn", "FL = %d\n", (user->list_op & MSN_LIST_FL_OP));
-		gaim_debug_misc("msn", "AL = %d\n", (user->list_op & MSN_LIST_AL_OP));
-		gaim_debug_misc("msn", "BL = %d\n", (user->list_op & MSN_LIST_BL_OP));
-		gaim_debug_misc("msn", "RL = %d\n", (user->list_op & MSN_LIST_RL_OP));
-#endif
-
 		if (!(user->list_op & (MSN_LIST_AL_OP | MSN_LIST_BL_OP |
 							   MSN_LIST_FL_OP)))
 		{
@@ -433,8 +425,6 @@
 void
 msn_userlist_add_user(MsnUserList *userlist, MsnUser *user)
 {
-	gaim_debug_misc("msn", "[%p] Adding %s (%p)\n",
-					userlist, user->passport, user);
 	userlist->users = g_list_append(userlist->users, user);
 }
 
@@ -457,11 +447,6 @@
 
 		g_return_val_if_fail(user->passport != NULL, NULL);
 
-#if 0
-		gaim_debug_misc("msn", "[%p] Comparing '%s' and '%s' (%p)\n",
-						userlist, passport, user->passport, user);
-#endif
-
 		if (!strcmp(passport, user->passport))
 			return user;
 	}
@@ -636,9 +621,7 @@
 	if (user_is_there(user, list_id, group_id))
 	{
 		list = lists[list_id];
-#if 0
 		gaim_debug_error("msn", "User '%s' is already there: %s\n", who, list);
-#endif
 		return;
 	}