changeset 23492:72aa2ccad28d

fix sending offline message in p15 by sending the correct token. In msnp14, we send the main login token (I realize I may be making up some of the terms here), in p15, we send the one for messengersecure.live.com some refactoring also
author Ka-Hing Cheung <khc@hxbc.us>
date Wed, 26 Dec 2007 01:22:00 +0000
parents f1f5efd679a4
children bac263f5afe7
files libpurple/protocols/msn/contact.c libpurple/protocols/msn/nexus.c libpurple/protocols/msn/nexus.h libpurple/protocols/msn/oim.c libpurple/protocols/msn/oim.h
diffstat 5 files changed, 57 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Wed Dec 26 00:35:26 2007 +0000
+++ b/libpurple/protocols/msn/contact.c	Wed Dec 26 01:22:00 2007 +0000
@@ -207,26 +207,6 @@
 	return MSN_USER_TYPE_UNKNOWN;
 }
 
-/* Get a ticket token that's correctly formatted */
-static const char *
-msn_contact_get_token(MsnContact *contact)
-{
-	GHashTable *token;
-	char *msn_t;
-	char *msn_p;
-	static char token_str[BUF_LEN];
-
-	token = msn_nexus_get_token(contact->session->nexus, MSN_AUTH_CONTACTS);
-	msn_t = g_hash_table_lookup(token, "t");
-	msn_p = g_hash_table_lookup(token, "p");
-
-	g_sprintf(token_str, "t=%s&amp;p=%s", msn_t, msn_p);
-
-	g_hash_table_unref(token);
-
-	return token_str;
-}
-
 /* Create the AddressBook in the server, if we don't have one */
 static void
 msn_create_address_cb(MsnSoapMessage *req, MsnSoapMessage *resp, gpointer data)
@@ -252,8 +232,8 @@
 	purple_debug_info("msnab","Creating an Address Book.\n");
 
 	body = g_strdup_printf(MSN_ADD_ADDRESSBOOK_TEMPLATE,
-	                       msn_contact_get_token(contact),
-	                       contact->session->user->passport);
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		contact->session->user->passport);
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_ADD_ADDRESSBOOK_SOAP_ACTION,
@@ -440,8 +420,8 @@
 	}
 
 	body = g_strdup_printf(MSN_GET_CONTACT_TEMPLATE, partner_scenario_str,
-	                       msn_contact_get_token(contact),
-	                       update_str ? update_str : "");
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		update_str ? update_str : "");
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_GET_CONTACT_SOAP_ACTION,
@@ -755,9 +735,9 @@
 		update_str = g_strdup_printf(MSN_GET_ADDRESS_UPDATE_XML, LastChanged);
 
 	body = g_strdup_printf(MSN_GET_ADDRESS_TEMPLATE,
-	                       MsnSoapPartnerScenarioText[partner_scenario],
-	                       msn_contact_get_token(contact),
-	                       update_str ? update_str : "");
+		MsnSoapPartnerScenarioText[partner_scenario],
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		update_str ? update_str : "");
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_GET_ADDRESS_SOAP_ACTION,
@@ -823,8 +803,8 @@
 
 	contact_xml = g_strdup_printf(MSN_CONTACT_XML, passport);
 	body = g_strdup_printf(MSN_ADD_CONTACT_TEMPLATE,
-	                       msn_contact_get_token(contact),
-	                       contact_xml);
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		contact_xml);
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_CONTACT_ADD_SOAP_ACTION,
@@ -933,9 +913,8 @@
 	}
 
 	body = g_strdup_printf(MSN_ADD_CONTACT_GROUP_TEMPLATE,
-	                       msn_contact_get_token(contact),
-	                       groupId,
-	                       contact_xml);
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		groupId, contact_xml);
 
 	msn_soap_message_send(state->session,
 		msn_soap_message_new(MSN_ADD_CONTACT_GROUP_SOAP_ACTION,
@@ -984,8 +963,9 @@
 	/* build SOAP request */
 	purple_debug_info("MSNCL","Deleting contact with contactId: %s\n", contactId);
 	body = g_strdup_printf(MSN_DEL_CONTACT_TEMPLATE,
-	                       msn_contact_get_token(contact),
-	                       contact_id_xml);
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		contact_id_xml);
+
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_CONTACT_DEL_SOAP_ACTION,
 			xmlnode_from_str(body, -1)),
@@ -1058,9 +1038,8 @@
 
 	contact_id_xml = g_strdup_printf(MSN_CONTACT_ID_XML, user->uid);
 	body = g_strdup_printf(MSN_CONTACT_DEL_GROUP_TEMPLATE,
-	                       msn_contact_get_token(contact),
-	                       contact_id_xml,
-	                       groupId);
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		contact_id_xml, groupId);
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_CONTACT_DEL_GROUP_SOAP_ACTION,
@@ -1094,8 +1073,8 @@
 	escaped_nickname = g_markup_escape_text(nickname, -1);
 
 	body = g_strdup_printf(MSN_CONTACT_UPDATE_TEMPLATE,
-	                       msn_contact_get_token(contact),
-	                       escaped_nickname);
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		escaped_nickname);
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_CONTACT_UPDATE_SOAP_ACTION,
@@ -1173,10 +1152,9 @@
 	}
 
 	body = g_strdup_printf( MSN_CONTACT_DELECT_FROM_LIST_TEMPLATE,
-			        MsnSoapPartnerScenarioText[partner_scenario],
-			        msn_contact_get_token(contact),
-			        MsnMemberRole[list],
-			        member);
+		MsnSoapPartnerScenarioText[partner_scenario],
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		MsnMemberRole[list], member);
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_DELETE_MEMBER_FROM_LIST_SOAP_ACTION,
@@ -1246,10 +1224,9 @@
 	member = g_strdup_printf(MSN_MEMBER_PASSPORT_XML, state->who);
 
 	body = g_strdup_printf(MSN_CONTACT_ADD_TO_LIST_TEMPLATE, 
-			       MsnSoapPartnerScenarioText[partner_scenario],
-			       msn_contact_get_token(contact),
-			       MsnMemberRole[list], 
-			       member);
+		MsnSoapPartnerScenarioText[partner_scenario],
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS),
+		MsnMemberRole[list], member);
 
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_ADD_MEMBER_TO_LIST_SOAP_ACTION,
@@ -1281,7 +1258,8 @@
 	purple_debug_info("MSNP14","msn get gleams info...\n");
 	
 	body = g_strdup_printf(MSN_GLEAMS_TEMPLATE,
-	                       msn_contact_get_token(contact))
+		msn_nexus_get_token_str(contact->session->nexus, MSN_AUTH_CONTACTS));
+
 	msn_soap_message_send(contact->session,
 		msn_soap_message_new(MSN_GET_GLEAMS_SOAP_ACTION,
 			xmlnode_from_str(body, -1)),
@@ -1389,9 +1367,8 @@
 	*/
 	escaped_group_name = g_markup_escape_text(group_name, -1);
 	body = g_strdup_printf(MSN_GROUP_ADD_TEMPLATE,
-	                       msn_contact_get_token(session->contact),
-	                       escaped_group_name);
-	g_free(escaped_group_name);
+		msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
+		escaped_group_name);
 
 	msn_soap_message_send(session,
 		msn_soap_message_new(MSN_GROUP_ADD_SOAP_ACTION,
@@ -1399,6 +1376,7 @@
 		MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
 		msn_group_read_cb, state);
 
+	g_free(escaped_group_name);
 	g_free(body);
 }
 
@@ -1435,8 +1413,8 @@
 	msn_callback_state_set_guid(state, guid);
 	
 	body = g_strdup_printf(MSN_GROUP_DEL_TEMPLATE,
-	                       msn_contact_get_token(session->contact),
-	                       guid);
+		msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
+		guid);
 
 	msn_soap_message_send(session,
 		msn_soap_message_new(MSN_GROUP_DEL_SOAP_ACTION,
@@ -1480,9 +1458,8 @@
 	
 	escaped_group_name = g_markup_escape_text(new_group_name, -1);
 	body = g_strdup_printf(MSN_GROUP_RENAME_TEMPLATE,
-	                       msn_contact_get_token(session->contact),
-	                       guid, escaped_group_name);
-	g_free(escaped_group_name);
+		msn_nexus_get_token_str(session->nexus, MSN_AUTH_CONTACTS),
+		guid, escaped_group_name);
 	
 	msn_soap_message_send(session,
 		msn_soap_message_new(MSN_GROUP_RENAME_SOAP_ACTION,
@@ -1490,5 +1467,6 @@
 		MSN_CONTACT_SERVER, MSN_ADDRESS_BOOK_POST_URL,
 		msn_group_read_cb, state);
 
+	g_free(escaped_group_name);
 	g_free(body);
 }
--- a/libpurple/protocols/msn/nexus.c	Wed Dec 26 00:35:26 2007 +0000
+++ b/libpurple/protocols/msn/nexus.c	Wed Dec 26 01:22:00 2007 +0000
@@ -39,7 +39,7 @@
 	{"messengerclear.live.com", NULL},       /* Authentication for messenger. */
 	{"messenger.msn.com", "?id=507"},        /* Messenger website authentication. */
 	{"contacts.msn.com", "MBI"},             /* Authentication for the Contact server. */
-	{"messengersecure.live.com", "MBI_SSL"}, /* Unknown */
+	{"messengersecure.live.com", "MBI_SSL"}, /* Used for messenger.live.com */
 	{"spaces.live.com", "MBI"},              /* Authentication for the Windows Live Spaces */
 	{"livecontacts.live.com", "MBI"},        /* Live Contacts API, a simplified version of the Contacts SOAP service */
 	{"storage.live.com", "MBI"},             /* Storage REST API */
@@ -416,23 +416,28 @@
 	if (time(NULL) > nexus->tokens[id].expiry)
 		msn_nexus_update_token(nexus, id);
 
-	return g_hash_table_ref(nexus->tokens[id].token);
+	return nexus->tokens[id].token;
 }
 
-char *
-msn_nexus_get_token_str(MsnNexus *session, MsnAuthDomains id)
+const char *
+msn_nexus_get_token_str(MsnNexus *nexus, MsnAuthDomains id)
 {
-#if 0
+	static char buf[1024];
 	GHashTable *token = msn_nexus_get_token(nexus, id);
-	GString *token_str;
+	const char *msn_t;
+	const char *msn_p;
+	gint ret;
 
 	g_return_val_if_fail(token != NULL, NULL);
 
-	token_str = g_string_new(NULL);
-	g_hash_table_foreach(token, GHFunc func, token_str);
+	msn_t = g_hash_table_lookup(token, "t");
+	msn_p = g_hash_table_lookup(token, "p");
+
+	g_return_val_if_fail(msn_t != NULL, NULL);
+	g_return_val_if_fail(msn_p != NULL, NULL);
 
-	g_hash_table_unref (token);
-#endif
-	return NULL;
+	ret = g_snprintf(buf, sizeof(buf) - 1, "t=%s&amp;p=%s", msn_t, msn_p);
+	g_return_val_if_fail(ret != -1, NULL);
+
+	return buf;
 }
-
--- a/libpurple/protocols/msn/nexus.h	Wed Dec 26 00:35:26 2007 +0000
+++ b/libpurple/protocols/msn/nexus.h	Wed Dec 26 01:22:00 2007 +0000
@@ -32,7 +32,7 @@
 	MSN_AUTH_MESSENGER     = 0,
 	MSN_AUTH_MESSENGER_WEB = 1,
 	MSN_AUTH_CONTACTS      = 2,
-	MSN_AUTH_LIVE_UNKNOWN  = 3,
+	MSN_AUTH_LIVE_SECURE   = 3,
 	MSN_AUTH_SPACES        = 4,
 	MSN_AUTH_LIVE_CONTACTS = 5,
 	MSN_AUTH_STORAGE       = 6
@@ -134,7 +134,7 @@
 MsnNexus *msn_nexus_new(MsnSession *session);
 void msn_nexus_destroy(MsnNexus *nexus);
 GHashTable *msn_nexus_get_token(MsnNexus *session, MsnAuthDomains id);
-char *msn_nexus_get_token_str(MsnNexus *session, MsnAuthDomains id);
+const char *msn_nexus_get_token_str(MsnNexus *session, MsnAuthDomains id);
 
 #endif /* _MSN_NEXUS_H_ */
 
--- a/libpurple/protocols/msn/oim.c	Wed Dec 26 00:35:26 2007 +0000
+++ b/libpurple/protocols/msn/oim.c	Wed Dec 26 01:22:00 2007 +0000
@@ -217,7 +217,7 @@
 msn_oim_send_msg(MsnOim *oim)
 {
 	MsnOimSendReq *oim_request;
-	char *soap_body,*mspauth;
+	char *soap_body;
 	char *msg_body;
 
 	g_return_if_fail(oim != NULL);
@@ -225,16 +225,12 @@
 	g_return_if_fail(oim_request != NULL);
 
 	purple_debug_info("MSNP14","sending OIM: %s\n", oim_request->oim_msg);
-	mspauth = g_strdup_printf("t=%s&amp;p=%s",
-		oim->session->passport_info.t,
-		oim->session->passport_info.p
-		);
 
 	/* if we got the challenge lock key, we compute it
 	 * else we go for the SOAP fault and resend it.
 	 */
 	if(oim->challenge == NULL){
-		purple_debug_info("MSNP14","no lock key challenge,wait for SOAP Fault and Resend\n");
+		purple_debug_info("MSNP14","no lock key challenge, wait for SOAP Fault and Resend\n");
 	}
 
 	msg_body = msn_oim_msg_to_str(oim, oim_request->oim_msg);
@@ -242,7 +238,7 @@
 					oim_request->from_member,
 					oim_request->friendname,
 					oim_request->to_member,
-					mspauth,
+		msn_nexus_get_token_str(oim->session->nexus, MSN_AUTH_LIVE_SECURE),
 					MSNP15_WLM_PRODUCT_ID,
 					oim->challenge ? oim->challenge : "",
 					oim->send_seq,
@@ -258,7 +254,6 @@
 		oim->send_seq++;
 	}
 
-	g_free(mspauth);
 	g_free(msg_body);
 	g_free(soap_body);
 }
--- a/libpurple/protocols/msn/oim.h	Wed Dec 26 00:35:26 2007 +0000
+++ b/libpurple/protocols/msn/oim.h	Wed Dec 26 01:22:00 2007 +0000
@@ -81,7 +81,7 @@
 #define MSN_OIM_SEND_TEMPLATE "<?xml version=\"1.0\" encoding=\"utf-8\"?>"\
 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\
 	"<soap:Header>"\
-		"<From memberName=\"%s\" friendlyName=\"%s\" xml:lang=\"en-US\" proxy=\"MSNMSGR\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\" msnpVer=\"MSNP14\" buildVer=\"8.0.0792\"/>"\
+		"<From memberName=\"%s\" friendlyName=\"%s\" xml:lang=\"en-US\" proxy=\"MSNMSGR\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\" msnpVer=\"MSNP15\" buildVer=\"8.1.0178\"/>"\
 		"<To memberName=\"%s\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\"/>"\
 		"<Ticket passport=\"%s\" appid=\"%s\" lockkey=\"%s\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\"/>"\
 		"<Sequence xmlns=\"http://schemas.xmlsoap.org/ws/2003/03/rm\">"\