changeset 23514:5f9e6f8b2aea

Correctly update MSN OIM tokens when an invalid token error is returned.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 07 Jun 2008 06:12:44 +0000
parents 1b98e2090a71
children eb8bd060b987
files libpurple/protocols/msn/oim.c libpurple/protocols/msn/oim.h
diffstat 2 files changed, 133 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/oim.c	Sat Jun 07 06:08:01 2008 +0000
+++ b/libpurple/protocols/msn/oim.c	Sat Jun 07 06:12:44 2008 +0000
@@ -115,6 +115,120 @@
 }
 
 /****************************************
+ * Manage OIM Tokens
+ ****************************************/
+typedef struct _MsnOimRequestData {
+	MsnOim *oim;
+	gboolean send;
+	const char *action;
+	const char *host;
+	const char *url;
+	xmlnode *body;
+	MsnSoapCallback cb;
+	gpointer cb_data;
+} MsnOimRequestData;
+
+static void msn_oim_request_helper(MsnOimRequestData *data);
+
+static void
+msn_oim_request_cb(MsnSoapMessage *request, MsnSoapMessage *response,
+	gpointer req_data)
+{
+	MsnOimRequestData *data = (MsnOimRequestData *)req_data;
+	xmlnode *xml;
+	xmlnode *faultcode;
+	gchar *faultcode_str;
+
+	xml = response->xml;
+	faultcode = xmlnode_get_child(xml, "Body/Fault/faultcode");
+
+	if (faultcode != NULL) {
+		faultcode_str = xmlnode_get_data(faultcode);
+
+		if (faultcode_str && g_str_equal(faultcode_str, "q0:BadContextToken")) {
+			purple_debug_error("msnp15", "OIM Request Error, Updating token now.");
+			msn_nexus_update_token(data->oim->session->nexus,
+				data->send ? MSN_AUTH_LIVE_SECURE : MSN_AUTH_MESSENGER_WEB,
+				(GSourceFunc)msn_oim_request_helper, data);
+			g_free(faultcode_str);
+			return;
+		}
+		g_free(faultcode_str);
+	}
+
+	if (data->cb)
+		data->cb(request, response, data->cb_data);
+	xmlnode_free(data->body);
+	g_free(data);
+}
+
+static void
+msn_oim_request_helper(MsnOimRequestData *data)
+{
+	MsnSession *session = data->oim->session;
+
+	if (data->send) {
+		/* The Sending of OIM's uses a different token for some reason. */
+		xmlnode *ticket;
+		ticket = xmlnode_get_child(data->body, "Header/Ticket");
+		xmlnode_set_attrib(ticket, "passport",
+			msn_nexus_get_token_str(session->nexus, MSN_AUTH_LIVE_SECURE));
+	}
+	else
+	{
+		xmlnode *passport;
+		xmlnode *xml_t;
+		xmlnode *xml_p;
+		GHashTable *token;
+		const char *msn_t;
+		const char *msn_p;
+
+		token = msn_nexus_get_token(session->nexus, MSN_AUTH_MESSENGER_WEB);
+		g_return_if_fail(token != NULL);
+
+		msn_t = g_hash_table_lookup(token, "t");
+		msn_p = g_hash_table_lookup(token, "p");
+
+		g_return_if_fail(msn_t != NULL);
+		g_return_if_fail(msn_p != NULL);
+
+		passport = xmlnode_get_child(data->body, "Header/PassportCookie");
+		xml_t = xmlnode_get_child(passport, "t");
+		xml_p = xmlnode_get_child(passport, "p");
+
+		/* frees old token text, or the 'EMPTY' text if first time */
+		xmlnode_free(xml_t->child);
+		xmlnode_free(xml_p->child);
+
+		xmlnode_insert_data(xml_t, msn_t, -1);
+		xmlnode_insert_data(xml_p, msn_p, -1);
+	}
+
+	msn_soap_message_send(session,
+		msn_soap_message_new(data->action, xmlnode_copy(data->body)),
+		data->host, data->url, msn_oim_request_cb, data);
+}
+
+
+static void
+msn_oim_make_request(MsnOim *oim, gboolean send, const char *action,
+	const char *host, const char *url, xmlnode *body, MsnSoapCallback cb,
+	gpointer cb_data)
+{
+	MsnOimRequestData *data = g_new0(MsnOimRequestData, 1);
+	data->oim = oim;
+	data->send = send;
+	data->action = action;
+	data->host = host;
+	data->url = url;
+	data->body = body;
+	data->cb = cb;
+	data->cb_data = cb_data;
+
+	msn_oim_request_helper(data);
+}
+
+/****************************************
  * OIM GetMetadata request
  * **************************************/
 static void
@@ -133,29 +247,10 @@
 static void
 msn_oim_get_metadata(MsnOim *oim)
 {
-	char *soap_body;
-	GHashTable *token;
-	const char *msn_t;
-	const char *msn_p;
-
-	token = msn_nexus_get_token(oim->session->nexus, MSN_AUTH_MESSENGER_WEB);
-	g_return_if_fail(token != NULL);
-
-	msn_t = g_hash_table_lookup(token, "t");
-	msn_p = g_hash_table_lookup(token, "p");
-
-	g_return_if_fail(msn_t != NULL);
-	g_return_if_fail(msn_p != NULL);
-
-	soap_body = g_strdup_printf(MSN_OIM_GET_METADATA_TEMPLATE, msn_t, msn_p);
-
-	msn_soap_message_send(oim->session,
-		msn_soap_message_new(MSN_OIM_GET_METADATA_ACTION,
-			xmlnode_from_str(soap_body, -1)),
+	msn_oim_make_request(oim, FALSE, MSN_OIM_GET_METADATA_ACTION,
 		MSN_OIM_RETRIEVE_HOST, MSN_OIM_RETRIEVE_URL,
+		xmlnode_from_str(MSN_OIM_GET_METADATA_TEMPLATE, -1),
 		msn_oim_get_metadata_cb, oim);
-
-	g_free(soap_body);
 }
 
 /****************************************
@@ -208,8 +303,6 @@
 					xmlnode *challengeNode = xmlnode_get_child(faultNode,
 						"detail/LockKeyChallenge");
 
-					g_free(faultcode_str);
-
 					if (challengeNode == NULL) {
 						if (oim->challenge) {
 							g_free(oim->challenge);
@@ -285,16 +378,14 @@
 					oim_request->from_member,
 					oim_request->friendname,
 					oim_request->to_member,
-		msn_nexus_get_token_str(oim->session->nexus, MSN_AUTH_LIVE_SECURE),
 					MSNP15_WLM_PRODUCT_ID,
 					oim->challenge ? oim->challenge : "",
 					oim->send_seq,
 					msg_body);
 
-	msn_soap_message_send(oim->session,
-		msn_soap_message_new(MSN_OIM_SEND_SOAP_ACTION,
-			xmlnode_from_str(soap_body, -1)),
-		MSN_OIM_SEND_HOST, MSN_OIM_SEND_URL, msn_oim_send_read_cb, oim);
+	msn_oim_make_request(oim, TRUE, MSN_OIM_SEND_SOAP_ACTION, MSN_OIM_SEND_HOST,
+		MSN_OIM_SEND_URL, xmlnode_from_str(soap_body, -1), msn_oim_send_read_cb,
+		oim);
 
 	/*increase the offline Sequence control*/
 	if (oim->challenge != NULL) {
@@ -333,28 +424,13 @@
 	MsnOim *oim = rdata->oim;
 	char *msgid = rdata->msg_id;
 	char *soap_body;
-	GHashTable *token;
-	const char *msn_t;
-	const char *msn_p;
 
 	purple_debug_info("MSNP14","Delete single OIM Message {%s}\n",msgid);
 
-	token = msn_nexus_get_token(oim->session->nexus, MSN_AUTH_MESSENGER_WEB);
-	g_return_if_fail(token != NULL);
-
-	msn_t = g_hash_table_lookup(token, "t");
-	msn_p = g_hash_table_lookup(token, "p");
+	soap_body = g_strdup_printf(MSN_OIM_DEL_TEMPLATE, msgid);
 
-	g_return_if_fail(msn_t != NULL);
-	g_return_if_fail(msn_p != NULL);
-
-	soap_body = g_strdup_printf(MSN_OIM_DEL_TEMPLATE, msn_t, msn_p, msgid);
-
-	msn_soap_message_send(oim->session,
-		msn_soap_message_new(MSN_OIM_DEL_SOAP_ACTION,
-			xmlnode_from_str(soap_body, -1)),
-		MSN_OIM_RETRIEVE_HOST, MSN_OIM_RETRIEVE_URL,
-		msn_oim_delete_read_cb, rdata);
+	msn_oim_make_request(oim, FALSE, MSN_OIM_DEL_SOAP_ACTION, MSN_OIM_RETRIEVE_HOST,
+		MSN_OIM_RETRIEVE_URL, xmlnode_from_str(soap_body, -1), msn_oim_delete_read_cb, rdata);
 
 	g_free(soap_body);
 }
@@ -606,30 +682,17 @@
 {
 	char *soap_body;
 	MsnOimRecvData *data = g_new0(MsnOimRecvData, 1);
-	GHashTable *token;
-	const char *msn_t;
-	const char *msn_p;
 
 	purple_debug_info("MSNP14","Get single OIM Message\n");
 
-	token = msn_nexus_get_token(oim->session->nexus, MSN_AUTH_MESSENGER_WEB);
-	g_return_if_fail(token != NULL);
-
-	msn_t = g_hash_table_lookup(token, "t");
-	msn_p = g_hash_table_lookup(token, "p");
-	g_return_if_fail(msn_t != NULL);
-	g_return_if_fail(msn_p != NULL);
-
 	data->oim = oim;
 	data->msg_id = msgid;
 
-	soap_body = g_strdup_printf(MSN_OIM_GET_TEMPLATE, msn_t, msn_p, msgid);
+	soap_body = g_strdup_printf(MSN_OIM_GET_TEMPLATE, msgid);
 
-	msn_soap_message_send(oim->session,
-		msn_soap_message_new(MSN_OIM_GET_SOAP_ACTION,
-			xmlnode_from_str(soap_body, -1)),
-		MSN_OIM_RETRIEVE_HOST, MSN_OIM_RETRIEVE_URL,
-		msn_oim_get_read_cb, data);
+	msn_oim_make_request(oim, FALSE, MSN_OIM_GET_SOAP_ACTION, MSN_OIM_RETRIEVE_HOST,
+		MSN_OIM_RETRIEVE_URL, xmlnode_from_str(soap_body, -1), msn_oim_get_read_cb,
+		data);
 
 	g_free(soap_body);
 }
--- a/libpurple/protocols/msn/oim.h	Sat Jun 07 06:08:01 2008 +0000
+++ b/libpurple/protocols/msn/oim.h	Sat Jun 07 06:12:44 2008 +0000
@@ -39,8 +39,8 @@
 	" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\
 	"<soap:Header>"\
 		"<PassportCookie xmlns=\"http://www.hotmail.msn.com/ws/2004/09/oim/rsi\">"\
-			"<t>%s</t>"\
-			"<p>%s</p>"\
+			"<t>EMPTY</t>"\
+			"<p>EMPTY</p>"\
 		"</PassportCookie>"\
 	"</soap:Header>"\
 	"<soap:Body>"\
@@ -58,8 +58,8 @@
 	" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\
 	"<soap:Header>"\
 		"<PassportCookie xmlns=\"http://www.hotmail.msn.com/ws/2004/09/oim/rsi\">"\
-			"<t>%s</t>"\
-			"<p>%s</p>"\
+			"<t>EMPTY</t>"\
+			"<p>EMPTY</p>"\
 		"</PassportCookie>"\
 	"</soap:Header>"\
 	"<soap:Body>"\
@@ -80,8 +80,8 @@
 	" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"\
 	"<soap:Header>"\
 		"<PassportCookie xmlns=\"http://www.hotmail.msn.com/ws/2004/09/oim/rsi\">"\
-			"<t>%s</t>"\
-			"<p>%s</p>"\
+			"<t>EMPTY</t>"\
+			"<p>EMPTY</p>"\
 		"</PassportCookie>"\
 	"</soap:Header>"\
 	"<soap:Body>"\
@@ -120,7 +120,7 @@
 			" msnpVer=\"MSNP15\""\
 			" buildVer=\"8.5.1288\"/>"\
 		"<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/\"/>"\
+		"<Ticket passport=\"EMPTY\" appid=\"%s\" lockkey=\"%s\" xmlns=\"http://messenger.msn.com/ws/2004/09/oim/\"/>"\
 		"<Sequence xmlns=\"http://schemas.xmlsoap.org/ws/2003/03/rm\">"\
 			"<Identifier xmlns=\"http://schemas.xmlsoap.org/ws/2002/07/utility\">http://messenger.msn.com</Identifier>"\
 			"<MessageNumber>%d</MessageNumber>"\