changeset 22519:575c4bda3b23

another patch from Maiku, this time handling IPG so we can receive paging. I am not sure why anyone would ever want to use this, but apparently some people find it helpful. Blame me if it doesn't work Fixes #5232
author Ka-Hing Cheung <khc@hxbc.us>
date Fri, 21 Mar 2008 05:24:21 +0000
parents 6aa076a2ea6f
children 32ff15843259
files libpurple/protocols/msn/notification.c libpurple/protocols/msn/userlist.c libpurple/protocols/msn/userlist.h
diffstat 3 files changed, 77 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/notification.c	Fri Mar 21 04:45:03 2008 +0000
+++ b/libpurple/protocols/msn/notification.c	Fri Mar 21 05:24:21 2008 +0000
@@ -1071,9 +1071,61 @@
 static void
 ipg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len)
 {
-#if 0
+	PurpleConnection *gc;
+	MsnUserList *userlist;
+	char *who = NULL, *text = NULL;
+	xmlnode *payloadNode, *from, *textNode;
+
 	purple_debug_misc("msn", "Incoming Page: {%s}\n", payload);
-#endif
+
+	userlist = cmdproc->session->userlist;
+	gc = purple_account_get_connection(cmdproc->session->account);
+
+	/* payload looks like this:
+	   <?xml version="1.0"?>
+	   <NOTIFICATION id="0" siteid="111100400" siteurl="http://mobile.msn.com/">
+	     <TO name="passport@example.com">
+	       <VIA agent="mobile"/>
+	     </TO>
+	     <FROM name="tel:+XXXXXXXXXXX"/>
+		 <MSG pri="1" id="1">
+		   <CAT Id="110110001"/>
+		   <ACTION url="2wayIM.asp"/>
+		   <SUBSCR url="2wayIM.asp"/>
+		   <BODY lcid="1033">
+		     <TEXT>Message was here</TEXT>
+		   </BODY>
+		 </MSG>
+	   </NOTIFICATION>
+	*/
+
+	if (!(payloadNode = xmlnode_from_str(payload, len)) ||
+		!(from = xmlnode_get_child(payloadNode, "FROM")) ||
+		!(textNode = xmlnode_get_child(payloadNode, "MSG/BODY/TEXT")))
+		return;
+
+	who = g_strdup(xmlnode_get_attrib(from, "name"));
+	if (!who) return;
+
+	text = xmlnode_get_data(textNode);
+
+	/* Match number to user's mobile number, FROM is a phone number if the
+	   other side page you using your phone number */
+	if(!strncmp(who, "tel:+", 5)) {
+		MsnUser *user =
+			msn_userlist_find_user_with_mobile_phone(userlist, who + 4);
+
+		if(user && user->passport) {
+			g_free(who);
+			who = g_strdup(user->passport);
+		}
+	}
+
+	serv_got_im(gc, who, text, 0, time(NULL));
+
+	g_free(text);
+	g_free(who);
+	xmlnode_free(payloadNode);
 }
 
 static void
--- a/libpurple/protocols/msn/userlist.c	Fri Mar 21 04:45:03 2008 +0000
+++ b/libpurple/protocols/msn/userlist.c	Fri Mar 21 05:24:21 2008 +0000
@@ -518,6 +518,28 @@
 	return NULL;
 }
 
+MsnUser *
+msn_userlist_find_user_with_mobile_phone(MsnUserList *userlist, const char *number)
+{
+	GList *l;
+
+	g_return_val_if_fail(number != NULL, NULL);
+
+	for (l = userlist->users; l != NULL; l = l->next) {
+		MsnUser *user = (MsnUser *)l->data;
+
+		if (user->phone.mobile == NULL) {
+			continue;
+		}
+
+		if (!g_strcasecmp(number, user->phone.mobile)) {
+			return user;
+		}
+	}
+
+	return NULL;
+}
+
 void
 msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group)
 {
--- a/libpurple/protocols/msn/userlist.h	Fri Mar 21 04:45:03 2008 +0000
+++ b/libpurple/protocols/msn/userlist.h	Fri Mar 21 05:24:21 2008 +0000
@@ -80,6 +80,7 @@
 MsnUser * msn_userlist_find_add_user(MsnUserList *userlist,
 				const char *passport, const char *userName);
 MsnUser * msn_userlist_find_user_with_id(MsnUserList *userlist, const char *uid);
+MsnUser * msn_userlist_find_user_with_mobile_phone(MsnUserList *userlist, const char *number);
 
 void msn_userlist_add_group(MsnUserList *userlist, MsnGroup *group);
 void msn_userlist_remove_group(MsnUserList *userlist, MsnGroup *group);