changeset 23522:fd124c21ebb7

Properly parse (most of) the MSN GCF command. Provides a <Account>->"View Blocked Text" dialog showing the regular expressions that the MSN servers are currently blocking. For the people who were wondering why their messages were never received.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 15 Jun 2008 06:55:21 +0000
parents 9fdf0accd4aa
children 31b5a1334e7e
files libpurple/protocols/msn/msn.c libpurple/protocols/msn/notification.c libpurple/protocols/msn/session.c libpurple/protocols/msn/session.h
diffstat 4 files changed, 59 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/msn.c	Sun Jun 15 06:22:25 2008 +0000
+++ b/libpurple/protocols/msn/msn.c	Sun Jun 15 06:55:21 2008 +0000
@@ -394,6 +394,29 @@
 }
 
 static void
+msn_show_blocked_text(PurplePluginAction *action)
+{
+	PurpleConnection *pc = (PurpleConnection *) action->context;
+	MsnSession *session;
+	char *title;
+
+	session = pc->proto_data;
+
+	title = g_strdup_printf(_("Blocked Text for %s"), session->account->username);
+	if (session->blocked_text == NULL) {
+		purple_notify_formatted(pc, title, title, NULL, _("No text is blocked for this account."), NULL, NULL);
+	} else {
+		char *blocked_text;
+		blocked_text = g_strdup_printf(_("MSN servers are currently blocking the following regular expressions:<br/>%s"),
+		                               session->blocked_text);
+		
+		purple_notify_formatted(pc, title, title, NULL, blocked_text, NULL, NULL);
+		g_free(blocked_text);
+	}
+	g_free(title);
+}
+
+static void
 msn_show_hotmail_inbox(PurplePluginAction *action)
 {
 	PurpleConnection *gc;
@@ -809,6 +832,11 @@
 			msn_show_set_mobile_pages);
 	m = g_list_append(m, act);
 
+	m = g_list_append(m, NULL);
+	act = purple_plugin_action_new(_("View Blocked Text..."),
+			msn_show_blocked_text);
+	m = g_list_append(m, act);
+
 	account = purple_connection_get_account(gc);
 	user = msn_normalize(account, purple_account_get_username(account));
 
--- a/libpurple/protocols/msn/notification.c	Sun Jun 15 06:22:25 2008 +0000
+++ b/libpurple/protocols/msn/notification.c	Sun Jun 15 06:55:21 2008 +0000
@@ -1612,9 +1612,8 @@
 gcf_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload,
 			 size_t len)
 {
-	xmlnode * root;
-	gchar * buf;
-	int xmllen;
+	xmlnode *root;
+	xmlnode *policy;
 
 	g_return_if_fail(cmd->payload != NULL);
 
@@ -1624,12 +1623,32 @@
 		return;
 	}
 
-	buf = xmlnode_to_formatted_str(root, &xmllen);
+
+	g_free(cmdproc->session->blocked_text);
+	cmdproc->session->blocked_text = NULL;
+
+	/* We need a get_child with attrib... */
+	policy = xmlnode_get_child(root, "Policy");
+	while (policy) {
+		if (g_str_equal(xmlnode_get_attrib(policy, "type"), "SHIELDS"))
+			break;
+		policy = xmlnode_get_next_twin(policy);
+	}
 
-	/* get the payload content */
-	purple_debug_info("MSNP14","GCF command payload:\n%.*s\n", xmllen, buf);
+	if (policy) {
+		GString *blocked = g_string_new(NULL);
+		xmlnode *imtext = xmlnode_get_child(policy,
+		                                    "config/block/regexp/imtext");
+		while (imtext) {
+			const char *value = xmlnode_get_attrib(imtext, "value");
+			g_string_append_printf(blocked, "%s<br/>\n",
+			                       purple_base64_decode(value, NULL));
+			imtext = xmlnode_get_next_twin(imtext);
+		}
 
-	g_free(buf);
+		cmdproc->session->blocked_text = g_string_free(blocked, FALSE);
+	}
+
 	xmlnode_free(root);
 }
 
--- a/libpurple/protocols/msn/session.c	Sun Jun 15 06:22:25 2008 +0000
+++ b/libpurple/protocols/msn/session.c	Sun Jun 15 06:55:21 2008 +0000
@@ -72,6 +72,9 @@
 	msn_userlist_destroy(session->userlist);
 
 	g_free(session->psm);
+
+	g_free(session->blocked_text);
+
 	g_free(session->passport_info.kv);
 	g_free(session->passport_info.sid);
 	g_free(session->passport_info.mspauth);
--- a/libpurple/protocols/msn/session.h	Sun Jun 15 06:22:25 2008 +0000
+++ b/libpurple/protocols/msn/session.h	Sun Jun 15 06:55:21 2008 +0000
@@ -107,6 +107,8 @@
 	/*psm info*/
 	char *psm;
 
+	char *blocked_text;
+
 	struct
 	{
 		char *kv;