changeset 28203:da22b6d0151e

Add support for XMPP URIs on Windows. Closes #2326.
author Paul Aurich <paul@darkrain42.org>
date Sun, 09 Aug 2009 00:15:14 +0000
parents 30bde00f1909
children 58c8d6fc3aaf
files ChangeLog.win32 libpurple/protocols/jabber/libxmpp.c libpurple/util.c pidgin/win32/nsis/pidgin-installer.nsi
diffstat 4 files changed, 84 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.win32	Fri Aug 07 17:12:11 2009 +0000
+++ b/ChangeLog.win32	Sun Aug 09 00:15:14 2009 +0000
@@ -1,4 +1,5 @@
 version 2.6.0 (??/??/2009):
+	* Added XMPP URI support.
 
 version 2.5.8 (06/27/2009):
 	* No changes
--- a/libpurple/protocols/jabber/libxmpp.c	Fri Aug 07 17:12:11 2009 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Sun Aug 09 00:15:14 2009 +0000
@@ -28,6 +28,7 @@
 #include "internal.h"
 
 #include "accountopt.h"
+#include "core.h"
 #include "debug.h"
 #include "version.h"
 
@@ -47,6 +48,8 @@
 #include "data.h"
 #include "ibb.h"
 
+static PurplePlugin *my_protocol = NULL;
+
 static PurplePluginProtocolInfo prpl_info =
 {
 	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_MAIL_CHECK |
@@ -266,6 +269,70 @@
 	NULL
 };
 
+static PurpleAccount *find_acct(const char *prpl, const char *acct_id)
+{
+	PurpleAccount *acct = NULL;
+
+	/* If we have a specific acct, use it */
+	if (acct_id) {
+		acct = purple_accounts_find(acct_id, prpl);
+		if (acct && !purple_account_is_connected(acct))
+			acct = NULL;
+	} else { /* Otherwise find an active account for the protocol */
+		GList *l = purple_accounts_get_all();
+		while (l) {
+			if (!strcmp(prpl, purple_account_get_protocol_id(l->data))
+					&& purple_account_is_connected(l->data)) {
+				acct = l->data;
+				break;
+			}
+			l = l->next;
+		}
+	}
+
+	return acct;
+}
+
+static gboolean xmpp_uri_handler(const char *proto, const char *user, GHashTable *params)
+{
+	char *acct_id = g_hash_table_lookup(params, "account");
+	PurpleAccount *acct;
+
+	if (g_ascii_strcasecmp(proto, "xmpp"))
+		return FALSE;
+
+	acct = find_acct(purple_plugin_get_id(my_protocol), acct_id);
+
+	if (!acct)
+		return FALSE;
+
+	/* xmpp:romeo@montague.net?message;subject=Test%20Message;body=Here%27s%20a%20test%20message */
+	if (g_hash_table_lookup_extended(params, "message", NULL, NULL)) {
+		char *body = g_hash_table_lookup(params, "body");
+		if (user && *user) {
+			PurpleConversation *conv =
+					purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, user);
+			purple_conversation_present(conv);
+			if (body && *body)
+				purple_conv_send_confirm(conv, body);
+		}
+	} else if (g_hash_table_lookup_extended(params, "roster", NULL, NULL)) {
+		char *name = g_hash_table_lookup(params, "name");
+		if (user && *user)
+			purple_blist_request_add_buddy(acct, user, NULL, name);
+	} else if (g_hash_table_lookup_extended(params, "join", NULL, NULL)) {
+		PurpleConnection *gc = purple_account_get_connection(acct);
+		if (user && *user) {
+			GHashTable *params = jabber_chat_info_defaults(gc, user);
+			jabber_chat_join(gc, params);
+		}
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+
 static void
 init_plugin(PurplePlugin *plugin)
 {
@@ -331,6 +398,7 @@
 	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,
 		option);
 
+	my_protocol = plugin;
 	jabber_init_plugin(plugin);
 
 	purple_prefs_remove("/plugins/prpl/jabber");
@@ -366,6 +434,9 @@
 
 	jabber_ibb_init();
 	jabber_si_init();
+
+	purple_signal_connect(purple_get_core(), "uri-handler", plugin,
+		PURPLE_CALLBACK(xmpp_uri_handler), NULL);
 }
 
 
--- a/libpurple/util.c	Fri Aug 07 17:12:11 2009 +0000
+++ b/libpurple/util.c	Sun Aug 09 00:15:14 2009 +0000
@@ -3519,6 +3519,7 @@
 void purple_got_protocol_handler_uri(const char *uri)
 {
 	char proto[11];
+	char delimiter;
 	const char *tmp, *param_string;
 	char *cmd;
 	GHashTable *params = NULL;
@@ -3534,7 +3535,13 @@
 	proto[len] = '\0';
 
 	tmp++;
-	purple_debug_info("util", "Processing message '%s' for protocol '%s'.\n", tmp, proto);
+
+	if (g_str_equal(proto, "xmpp"))
+		delimiter = ';';
+	else
+		delimiter = '&';
+
+	purple_debug_info("util", "Processing message '%s' for protocol '%s' using delimiter '%c'.\n", tmp, proto, delimiter);
 
 	if ((param_string = strchr(tmp, '?'))) {
 		const char *keyend = NULL, *pairstart;
@@ -3547,7 +3554,7 @@
 		pairstart = tmp = param_string;
 
 		while (*tmp || *pairstart) {
-			if (*tmp == '&' || !(*tmp)) {
+			if (*tmp == delimiter || !(*tmp)) {
 				/* If there is no explicit value */
 				if (keyend == NULL)
 					keyend = tmp;
--- a/pidgin/win32/nsis/pidgin-installer.nsi	Fri Aug 07 17:12:11 2009 +0000
+++ b/pidgin/win32/nsis/pidgin-installer.nsi	Sun Aug 09 00:15:14 2009 +0000
@@ -567,6 +567,7 @@
   !insertmacro URI_SECTION "msnim"
   !insertmacro URI_SECTION "myim"
   !insertmacro URI_SECTION "ymsgr"
+  !insertmacro URI_SECTION "xmpp"
 SectionGroupEnd
 
 ;--------------------------------
@@ -708,6 +709,8 @@
     Call un.UnregisterURIHandler
     Push "ymsgr"
     Call un.UnregisterURIHandler
+    Push "xmpp"
+    Call un.UnregisterURIHandler
 
     Delete "$INSTDIR\ca-certs\America_Online_Root_Certification_Authority_1.pem"
     Delete "$INSTDIR\ca-certs\AOL_Member_CA.pem"