/soc/2013/ankitkv/gobjectification: 15719256474a: Add/remove XMP...

Ankit Vani a at nevitus.org
Tue Sep 3 17:14:45 EDT 2013


Changeset: 15719256474ae931a5331a2a631493af96332bc1
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-09-04 02:04 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/15719256474a

Description:

Add/remove XMPPProtocol, GTalkProtocol, FacebookProtocol via the single jabber plugin

diffstat:

 libpurple/protocols/jabber/facebook.c |  129 +-----------------------------
 libpurple/protocols/jabber/gtalk.c    |  127 +-----------------------------
 libpurple/protocols/jabber/jabber.c   |  144 +++++++++++++++++++++++++++++++++-
 libpurple/protocols/jabber/xmpp.c     |  117 ---------------------------
 4 files changed, 147 insertions(+), 370 deletions(-)

diffs (truncated from 617 to 300 lines):

diff --git a/libpurple/protocols/jabber/facebook.c b/libpurple/protocols/jabber/facebook.c
--- a/libpurple/protocols/jabber/facebook.c
+++ b/libpurple/protocols/jabber/facebook.c
@@ -20,11 +20,6 @@
  *
  */
 
-/* libfacebook is the Facebook XMPP protocol plugin. It is linked against
- * libjabbercommon, which may be used to support other protocols (Bonjour)
- * which may need to share code.
- */
-
 #include "internal.h"
 #include "chat.h"
 #include "core.h"
@@ -32,72 +27,6 @@
 
 #include "facebook.h"
 
-static PurpleProtocol *my_protocol = NULL;
-
-static PurpleAccount *find_acct(const char *protocol, const char *acct_id)
-{
-	PurpleAccount *acct = NULL;
-
-	/* If we have a specific acct, use it */
-	if (acct_id) {
-		acct = purple_accounts_find(acct_id, protocol);
-		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(protocol, 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 = params ? g_hash_table_lookup(params, "account") : NULL;
-	PurpleAccount *acct;
-
-	if (g_ascii_strcasecmp(proto, "xmpp"))
-		return FALSE;
-
-	acct = find_acct(purple_protocol_get_id(my_protocol), acct_id);
-
-	if (!acct)
-		return FALSE;
-
-	/* xmpp:romeo at montague.net?message;subject=Test%20Message;body=Here%27s%20a%20test%20message */
-	/* params is NULL if the URI has no '?' (or anything after it) */
-	if (!params || g_hash_table_lookup_extended(params, "message", NULL, NULL)) {
-		char *body = g_hash_table_lookup(params, "body");
-		if (user && *user) {
-			PurpleIMConversation *im =
-					purple_im_conversation_new(acct, user);
-			purple_conversation_present(PURPLE_CONVERSATION(im));
-			if (body && *body)
-				purple_conversation_send_confirm(PURPLE_CONVERSATION(im), 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 const char *
 facebook_list_icon(PurpleAccount *a, PurpleBuddy *b)
 {
@@ -200,58 +129,6 @@ facebook_protocol_interface_init(PurpleP
 
 static void facebook_protocol_base_finalize(FacebookProtocolClass *klass) { }
 
-static PurplePluginInfo *
-plugin_query(GError **error)
-{
-	const gchar * const dependencies[] = {
-		"protocol-xmpp",
-		NULL
-	};
-
-	return purple_plugin_info_new(
-		"id",            "protocol-facebook",
-		"name",          "Facebook XMPP Protocol",
-		"version",       DISPLAY_VERSION,
-		"category",      N_("Protocol"),
-		"summary",       N_("Facebook XMPP Protocol Plugin"),
-		"description",   N_("Facebook XMPP Protocol Plugin"),
-		"website",       PURPLE_WEBSITE,
-		"abi-version",   PURPLE_ABI_VERSION,
-		"dependencies",  dependencies,
-		"flags",         PURPLE_PLUGIN_INFO_FLAGS_INTERNAL |
-		                 PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD,
-		NULL
-	);
-}
-
-static gboolean
-plugin_load(PurplePlugin *plugin, GError **error)
-{
-	my_protocol = purple_protocols_add(FACEBOOK_TYPE_PROTOCOL, error);
-	if (!my_protocol)
-		return FALSE;
-
-	purple_signal_connect(purple_get_core(), "uri-handler", my_protocol,
-		PURPLE_CALLBACK(xmpp_uri_handler), NULL);
-
-	jabber_protocol_init(my_protocol);
-	return TRUE;
-}
-
-static gboolean
-plugin_unload(PurplePlugin *plugin, GError **error)
-{
-	jabber_protocol_uninit(my_protocol);
-	if (!purple_protocols_remove(my_protocol, error))
-		return FALSE;
-
-	return TRUE;
-}
-
-static PurplePlugin *my_plugin;
-
-PURPLE_PROTOCOL_DEFINE_EXTENDED(my_plugin, FacebookProtocol, facebook_protocol,
-                                JABBER_TYPE_PROTOCOL, 0);
-
-PURPLE_PLUGIN_INIT_VAL(my_plugin, facebookxmpp, plugin_query, plugin_load,
-                       plugin_unload);
+extern PurplePlugin *_jabber_plugin;
+PURPLE_PROTOCOL_DEFINE_EXTENDED(_jabber_plugin, FacebookProtocol,
+                                facebook_protocol, JABBER_TYPE_PROTOCOL, 0);
diff --git a/libpurple/protocols/jabber/gtalk.c b/libpurple/protocols/jabber/gtalk.c
--- a/libpurple/protocols/jabber/gtalk.c
+++ b/libpurple/protocols/jabber/gtalk.c
@@ -20,11 +20,6 @@
  *
  */
 
-/* libgtalk is the Google Talk XMPP protocol plugin. It is linked against
- * libjabbercommon, which may be used to support other protocols (Bonjour) which
- * may need to share code.
- */
-
 #include "internal.h"
 #include "chat.h"
 #include "core.h"
@@ -32,72 +27,6 @@
 
 #include "gtalk.h"
 
-static PurpleProtocol *my_protocol = NULL;
-
-static PurpleAccount *find_acct(const char *protocol, const char *acct_id)
-{
-	PurpleAccount *acct = NULL;
-
-	/* If we have a specific acct, use it */
-	if (acct_id) {
-		acct = purple_accounts_find(acct_id, protocol);
-		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(protocol, 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 = params ? g_hash_table_lookup(params, "account") : NULL;
-	PurpleAccount *acct;
-
-	if (g_ascii_strcasecmp(proto, "xmpp"))
-		return FALSE;
-
-	acct = find_acct(purple_protocol_get_id(my_protocol), acct_id);
-
-	if (!acct)
-		return FALSE;
-
-	/* xmpp:romeo at montague.net?message;subject=Test%20Message;body=Here%27s%20a%20test%20message */
-	/* params is NULL if the URI has no '?' (or anything after it) */
-	if (!params || g_hash_table_lookup_extended(params, "message", NULL, NULL)) {
-		char *body = g_hash_table_lookup(params, "body");
-		if (user && *user) {
-			PurpleIMConversation *im =
-					purple_im_conversation_new(acct, user);
-			purple_conversation_present(PURPLE_CONVERSATION(im));
-			if (body && *body)
-				purple_conversation_send_confirm(PURPLE_CONVERSATION(im), 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 const char *
 gtalk_list_icon(PurpleAccount *a, PurpleBuddy *b)
 {
@@ -193,58 +122,6 @@ gtalk_protocol_interface_init(PurpleProt
 
 static void gtalk_protocol_base_finalize(GTalkProtocolClass *klass) { }
 
-static PurplePluginInfo *
-plugin_query(GError **error)
-{
-	const gchar * const dependencies[] = {
-		"protocol-xmpp",
-		NULL
-	};
-
-	return purple_plugin_info_new(
-		"id",            "protocol-gtalk",
-		"name",          "Google Talk Protocol",
-		"version",       DISPLAY_VERSION,
-		"category",      N_("Protocol"),
-		"summary",       N_("Google Talk Protocol Plugin"),
-		"description",   N_("Google Talk Protocol Plugin"),
-		"website",       PURPLE_WEBSITE,
-		"abi-version",   PURPLE_ABI_VERSION,
-		"dependencies",  dependencies,
-		"flags",         PURPLE_PLUGIN_INFO_FLAGS_INTERNAL |
-		                 PURPLE_PLUGIN_INFO_FLAGS_AUTO_LOAD,
-		NULL
-	);
-}
-
-static gboolean
-plugin_load(PurplePlugin *plugin, GError **error)
-{
-	my_protocol = purple_protocols_add(GTALK_TYPE_PROTOCOL, error);
-	if (!my_protocol)
-		return FALSE;
-
-	purple_signal_connect(purple_get_core(), "uri-handler", my_protocol,
-		PURPLE_CALLBACK(xmpp_uri_handler), NULL);
-
-	jabber_protocol_init(my_protocol);
-	return TRUE;
-}
-
-static gboolean
-plugin_unload(PurplePlugin *plugin, GError **error)
-{
-	jabber_protocol_uninit(my_protocol);
-	if (!purple_protocols_remove(my_protocol, error))
-		return FALSE;
-
-	return TRUE;
-}
-
-static PurplePlugin *my_plugin;
-
-PURPLE_PROTOCOL_DEFINE_EXTENDED(my_plugin, GTalkProtocol, gtalk_protocol,
+extern PurplePlugin *_jabber_plugin;
+PURPLE_PROTOCOL_DEFINE_EXTENDED(_jabber_plugin, GTalkProtocol, gtalk_protocol,
                                 JABBER_TYPE_PROTOCOL, 0);
-
-PURPLE_PLUGIN_INIT_VAL(my_plugin, gtalk, plugin_query, plugin_load,
-                       plugin_unload);
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c



More information about the Commits mailing list