changeset 27063:4c651771840d

Add a data parameter for FQY callbacks and remove the pending users list that was previously used instead.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 07 Jun 2009 06:12:18 +0000
parents e2b6b376125c
children 175dd2627727
files libpurple/protocols/msn/msn.c libpurple/protocols/msn/notification.c libpurple/protocols/msn/notification.h libpurple/protocols/msn/userlist.c libpurple/protocols/msn/userlist.h
diffstat 5 files changed, 62 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Sun Jun 07 04:56:15 2009 +0000
+++ b/libpurple/protocols/msn/msn.c	Sun Jun 07 06:12:18 2009 +0000
@@ -1380,6 +1380,37 @@
 	msn_change_status(session);
 }
 
+/*
+ * Actually adds a buddy once we have the response from FQY
+ */
+static void
+add_pending_buddy(MsnSession *session,
+                  const char *who,
+                  MsnNetwork network,
+                  MsnUser *user)
+{
+	MsnUserList *userlist = session->userlist;
+	MsnUser *user2;
+	char *group;
+
+	g_return_if_fail(user != NULL);
+
+	group = msn_user_remove_pending_group(user);
+
+	user2 = msn_userlist_find_user(userlist, who);
+	if (user2 != NULL) {
+		/* User already in userlist, so just update it. */
+		msn_user_destroy(user);
+		user = user2;
+	} else {
+		msn_userlist_add_user(userlist, user);
+	}
+
+	msn_user_set_network(user, network);
+	msn_userlist_add_buddy(userlist, who, group);
+	g_free(group);
+}
+
 static void
 msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
 {
@@ -1413,13 +1444,15 @@
 		char **tokens;
 		char *fqy;
 		/* We need to check the network for this buddy first */
-		msn_userlist_save_pending_buddy(userlist, who, gname);
+		user = msn_user_new(userlist, who, NULL);
+		msn_user_set_pending_group(user, gname);
+		msn_user_set_network(user, MSN_NETWORK_UNKNOWN);
 		tokens = g_strsplit(who, "@", 2);
 		fqy = g_strdup_printf("<ml><d n=\"%s\"><c n=\"%s\"/></d></ml>",
 		                      tokens[1],
 		                      tokens[0]);
 		msn_notification_send_fqy(session, fqy, strlen(fqy),
-		                          (MsnFqyCb)msn_userlist_add_pending_buddy);
+		                          (MsnFqyCb)add_pending_buddy, user);
 		g_free(fqy);
 		g_strfreev(tokens);
 	}
--- a/libpurple/protocols/msn/notification.c	Sun Jun 07 04:56:15 2009 +0000
+++ b/libpurple/protocols/msn/notification.c	Sun Jun 07 06:12:18 2009 +0000
@@ -479,6 +479,12 @@
 /**************************************************************************
  * Buddy Lists
  **************************************************************************/
+
+typedef struct MsnFqyCbData {
+	MsnFqyCb cb;
+	gpointer data;
+} MsnFqyCbData;
+
 /* add contact to xmlnode */
 static void
 msn_add_contact_xml(MsnSession *session, xmlnode *mlNode,const char *passport, MsnListOp list_op, MsnNetwork networkId)
@@ -554,21 +560,27 @@
 void
 msn_notification_send_fqy(MsnSession *session,
                           const char *payload, int payload_len,
-                          MsnFqyCb cb)
+                          MsnFqyCb cb,
+                          gpointer cb_data)
 {
 	MsnTransaction *trans;
 	MsnCmdProc *cmdproc;
+	MsnFqyCbData *data;
 
 	cmdproc = session->notification->cmdproc;
 
+	data = g_new(MsnFqyCbData, 1);
+	data->cb = cb;
+	data->data = cb_data;
+
 	trans = msn_transaction_new(cmdproc, "FQY", "%d", payload_len);
 	msn_transaction_set_payload(trans, payload, payload_len);
-	msn_transaction_set_data(trans, cb);
+	msn_transaction_set_data(trans, data);
 	msn_cmdproc_send_trans(cmdproc, trans);
 }
 
 static void
-update_contact_network(MsnSession *session, const char *passport, MsnNetwork network)
+update_contact_network(MsnSession *session, const char *passport, MsnNetwork network, gpointer unused)
 {
 	MsnUser *user;
 
@@ -684,7 +696,7 @@
 				payload = xmlnode_to_str(fqy_node, &payload_len);
 
 				msn_notification_send_fqy(session, payload, payload_len,
-				                          update_contact_network);
+				                          update_contact_network, NULL);
 
 				g_free(payload);
 				xmlnode_free(fqy_node);
@@ -709,7 +721,7 @@
 		payload = xmlnode_to_str(fqy_node, &payload_len);
 
 		msn_notification_send_fqy(session, payload, payload_len,
-		                          update_contact_network);
+		                          update_contact_network, NULL);
 
 		g_free(payload);
 	}
@@ -926,8 +938,13 @@
 
 			purple_debug_info("msn", "FQY response says %s is from network %d\n",
 			                  passport, network);
-			if (cmd->trans->data)
-				((MsnFqyCb)cmd->trans->data)(session, passport, network);
+			if (cmd->trans->data) {
+				MsnFqyCbData *fqy_data = cmd->trans->data;
+				fqy_data->cb(session, passport, network, fqy_data->data);
+				/* TODO: This leaks, but the server responds to FQY multiple times, so we
+				         can't free it yet. We need to figure out somewhere else to do so.
+				g_free(fqy_data); */
+			}
 
 			g_free(passport);
 		}
@@ -952,7 +969,7 @@
 	   FQY error, it's probably going to disconnect us. So it isn't necessary
 	   to tell the handler about it. */
 	else if (trans->data)
-		((MsnFqyCb)trans->data)(session, NULL, MSN_NETWORK_UNKNOWN); */
+		((MsnFqyCb)trans->data)(session, NULL, MSN_NETWORK_UNKNOWN, NULL);
 #endif
 }
 
--- a/libpurple/protocols/msn/notification.h	Sun Jun 07 04:56:15 2009 +0000
+++ b/libpurple/protocols/msn/notification.h	Sun Jun 07 06:12:18 2009 +0000
@@ -58,7 +58,7 @@
 	gboolean in_use;
 };
 
-typedef void (*MsnFqyCb)(MsnSession *session, const char *passport, MsnNetwork network);
+typedef void (*MsnFqyCb)(MsnSession *session, const char *passport, MsnNetwork network, gpointer data);
 
 #include "state.h"
 void uum_send_msg(MsnSession *session,MsnMessage *msg);
@@ -73,7 +73,7 @@
 
 void msn_notification_send_fqy(MsnSession *session,
                                const char *payload, int payload_len,
-                               MsnFqyCb cb);
+                               MsnFqyCb cb, gpointer cb_data);
 
 MsnNotification *msn_notification_new(MsnSession *session);
 void msn_notification_destroy(MsnNotification *notification);
--- a/libpurple/protocols/msn/userlist.c	Sun Jun 07 04:56:15 2009 +0000
+++ b/libpurple/protocols/msn/userlist.c	Sun Jun 07 06:12:18 2009 +0000
@@ -601,69 +601,6 @@
 	msn_add_contact_to_group(userlist->session, state, who, group_id);
 }
 
-/*
- * Save a buddy address/group until we get back response from FQY
- */
-void
-msn_userlist_save_pending_buddy(MsnUserList *userlist,
-                               const char *who,
-                               const char *group_name)
-{
-	MsnUser *user;
-
-	g_return_if_fail(userlist != NULL);
-
-	user = msn_user_new(userlist, who, NULL);
-	msn_user_set_pending_group(user, group_name);
-	msn_user_set_network(user, MSN_NETWORK_UNKNOWN);
-	userlist->pending = g_list_prepend(userlist->pending, user);
-}
-
-/*
- * Actually adds a buddy once we have the response from FQY
- */
-void
-msn_userlist_add_pending_buddy(MsnSession *session,
-                               const char *who,
-                               /*MsnNetwork*/ int network)
-{
-	MsnUserList *userlist = session->userlist;
-	MsnUser *user = NULL;
-	MsnUser *user2;
-	GList *l;
-	char *group;
-
-	for (l = userlist->pending; l != NULL; l = l->next)
-	{
-		user = (MsnUser *)l->data;
-
-		if (!g_ascii_strcasecmp(who, user->passport)) {
-			userlist->pending = g_list_delete_link(userlist->pending, l);
-			break;
-		}
-	}
-
-	if (user == NULL) {
-		purple_debug_error("msn", "Attempting to add a pending user that does not exist.\n");
-		return;
-	}
-
-	group = msn_user_remove_pending_group(user);
-
-	user2 = msn_userlist_find_user(userlist, who);
-	if (user2 != NULL) {
-		/* User already in userlist, so just update it. */
-		msn_user_destroy(user);
-		user = user2;
-	} else {
-		msn_userlist_add_user(userlist, user);
-	}
-
-	msn_user_set_network(user, network);
-	msn_userlist_add_buddy(userlist, who, group);
-	g_free(group);
-}
-
 void
 msn_userlist_add_buddy_to_list(MsnUserList *userlist, const char *who,
 							MsnListId list_id)
--- a/libpurple/protocols/msn/userlist.h	Sun Jun 07 04:56:15 2009 +0000
+++ b/libpurple/protocols/msn/userlist.h	Sun Jun 07 06:12:18 2009 +0000
@@ -47,7 +47,6 @@
 
 	GList *users; /* Contains MsnUsers */
 	GList *groups; /* Contains MsnGroups */
-	GList *pending; /* MsnUsers pending addition (waiting for FQY response) */
 
 	GQueue *buddy_icon_requests;
 	int buddy_icon_window;
@@ -87,12 +86,6 @@
 void msn_userlist_rem_buddy(MsnUserList *userlist, const char *who);
 void msn_userlist_add_buddy(MsnUserList *userlist,
 			    const char *who, const char *group_name);
-void msn_userlist_save_pending_buddy(MsnUserList *userlist,
-                                     const char *who,
-                                     const char *group_name);
-void msn_userlist_add_pending_buddy(MsnSession *session,
-                                    const char *who,
-                                    /*MsnNetwork*/ int network);
 void msn_userlist_move_buddy(MsnUserList *userlist, const char *who,
 						    const char *old_group_name,
 						    const char *new_group_name);