pidgin: a7bd74cb: Add a data parameter for FQY callbacks a...

qulogic at pidgin.im qulogic at pidgin.im
Sun Jun 7 04:10:51 EDT 2009


-----------------------------------------------------------------
Revision: a7bd74cbe46498f1390a4d33cce115bdd123a68d
Ancestor: 0e2af7d2799397628273f534fac31e6dd7c6fe14
Author: qulogic at pidgin.im
Date: 2009-06-07T06:12:18
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/a7bd74cbe46498f1390a4d33cce115bdd123a68d

Modified 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

ChangeLog: 

Add a data parameter for FQY callbacks and remove the pending users list
that was previously used instead.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msn.c	a04fa331e9ccdd0a218aa6283f727d88067cf2c6
+++ libpurple/protocols/msn/msn.c	b64a12dc36b8d425c61805866b9f0a8126b02b3e
@@ -1380,7 +1380,38 @@ msn_set_idle(PurpleConnection *gc, int i
 	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)
 {
 	MsnSession *session;
@@ -1413,13 +1444,15 @@ msn_add_buddy(PurpleConnection *gc, Purp
 		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);
 	}
============================================================
--- libpurple/protocols/msn/notification.c	34318439bd78e3289fd5c34ed85ed7018dfe4503
+++ libpurple/protocols/msn/notification.c	1d788aff6b47615484fadfa4fb5d3955077e6999
@@ -479,6 +479,12 @@ chl_cmd(MsnCmdProc *cmdproc, MsnCommand 
 /**************************************************************************
  * 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 @@ msn_notification_send_fqy(MsnSession *se
 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 @@ msn_notification_dump_contact(MsnSession
 				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 @@ msn_notification_dump_contact(MsnSession
 		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 @@ fqy_cmd_post(MsnCmdProc *cmdproc, MsnCom
 
 			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(MsnCmdProc *cmdproc, MsnTransa
 	   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
 }
 
============================================================
--- libpurple/protocols/msn/notification.h	c5fda71615516de493ca7e188a4573602e0e67fc
+++ libpurple/protocols/msn/notification.h	efe0cdabd251a4338c91706bf251c3129e0bba70
@@ -58,7 +58,7 @@ struct _MsnNotification
 	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(MsnSessio
 
 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);
============================================================
--- libpurple/protocols/msn/userlist.c	60a7d766efeae5979b308b530be6c13bddd3f813
+++ libpurple/protocols/msn/userlist.c	63770d720fd02e8faca4ac3386b747ac9d3aa528
@@ -601,70 +601,7 @@ msn_userlist_add_buddy(MsnUserList *user
 	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)
 {
============================================================
--- libpurple/protocols/msn/userlist.h	17b5ee141bf1dec65d2d36dda5a8d689b4a80b5d
+++ libpurple/protocols/msn/userlist.h	96d4707a3b584eb1f39fdd33fe0d3fa2281133df
@@ -47,7 +47,6 @@ struct _MsnUserList
 
 	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_add_buddy(MsnUserList 
 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);


More information about the Commits mailing list