/soc/2013/ankitkv/gobjectification: e7fe371c60a6: Refactored jab...

Ankit Vani a at nevitus.org
Sat Aug 10 17:13:29 EDT 2013


Changeset: e7fe371c60a61cd78c79f3c3a7a24871bfc774d4
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-11 02:43 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/e7fe371c60a6

Description:

Refactored jabber to use the new API

diffstat:

 libpurple/protocols/jabber/adhoccommands.c |   8 +-
 libpurple/protocols/jabber/buddy.c         |   8 +-
 libpurple/protocols/jabber/buddy.h         |   4 +-
 libpurple/protocols/jabber/jabber.c        |  26 ++++---
 libpurple/protocols/jabber/jabber.h        |   2 +-
 libpurple/protocols/jabber/libfacebook.c   |  95 ++++++++++++------------------
 libpurple/protocols/jabber/libgtalk.c      |  95 ++++++++++++------------------
 libpurple/protocols/jabber/libxmpp.c       |  95 ++++++++++++------------------
 libpurple/protocols/jabber/usernick.c      |   6 +-
 libpurple/prpl.h                           |   2 +-
 10 files changed, 144 insertions(+), 197 deletions(-)

diffs (truncated from 662 to 300 lines):

diff --git a/libpurple/protocols/jabber/adhoccommands.c b/libpurple/protocols/jabber/adhoccommands.c
--- a/libpurple/protocols/jabber/adhoccommands.c
+++ b/libpurple/protocols/jabber/adhoccommands.c
@@ -318,10 +318,10 @@ void jabber_adhoc_execute(JabberStream *
 	jabber_iq_send(iq);
 }
 
-static void jabber_adhoc_server_execute(PurplePluginAction *action) {
+static void jabber_adhoc_server_execute(PurpleProtocolAction *action) {
 	JabberAdHocCommands *cmd = action->user_data;
 	if(cmd) {
-		PurpleConnection *gc = (PurpleConnection *) action->context;
+		PurpleConnection *gc = (PurpleConnection *) action->connection;
 		JabberStream *js = purple_connection_get_protocol_data(gc);
 
 		jabber_adhoc_execute(js, cmd);
@@ -342,7 +342,7 @@ void jabber_adhoc_init_server_commands(J
 			for(riter = jbr->commands; riter; riter = g_list_next(riter)) {
 				JabberAdHocCommands *cmd = riter->data;
 				char *cmdname = g_strdup_printf("%s (%s)",cmd->name,jbr->name);
-				PurplePluginAction *act = purple_plugin_action_new(cmdname, jabber_adhoc_server_execute);
+				PurpleProtocolAction *act = purple_protocol_action_new(cmdname, jabber_adhoc_server_execute);
 				act->user_data = cmd;
 				*m = g_list_append(*m, act);
 				g_free(cmdname);
@@ -354,7 +354,7 @@ void jabber_adhoc_init_server_commands(J
 	/* now add server commands */
 	for(cmdlst = js->commands; cmdlst; cmdlst = g_list_next(cmdlst)) {
 		JabberAdHocCommands *cmd = cmdlst->data;
-		PurplePluginAction *act = purple_plugin_action_new(cmd->name, jabber_adhoc_server_execute);
+		PurpleProtocolAction *act = purple_protocol_action_new(cmd->name, jabber_adhoc_server_execute);
 		act->user_data = cmd;
 		*m = g_list_append(*m, act);
 	}
diff --git a/libpurple/protocols/jabber/buddy.c b/libpurple/protocols/jabber/buddy.c
--- a/libpurple/protocols/jabber/buddy.c
+++ b/libpurple/protocols/jabber/buddy.c
@@ -624,9 +624,9 @@ jabber_format_info(PurpleConnection *gc,
  * string (if any) into GSLists for the (multi-entry) edit dialog and
  * calls the set_vcard dialog.
  */
-void jabber_setup_set_info(PurplePluginAction *action)
+void jabber_setup_set_info(PurpleProtocolAction *action)
 {
-	PurpleConnection *gc = (PurpleConnection *) action->context;
+	PurpleConnection *gc = (PurpleConnection *) action->connection;
 	PurpleRequestFields *fields;
 	PurpleRequestFieldGroup *group;
 	PurpleRequestField *field;
@@ -2270,9 +2270,9 @@ void jabber_user_search(JabberStream *js
 	jabber_iq_send(iq);
 }
 
-void jabber_user_search_begin(PurplePluginAction *action)
+void jabber_user_search_begin(PurpleProtocolAction *action)
 {
-	PurpleConnection *gc = (PurpleConnection *) action->context;
+	PurpleConnection *gc = (PurpleConnection *) action->connection;
 	JabberStream *js = purple_connection_get_protocol_data(gc);
 	const char *def_val = purple_account_get_string(purple_connection_get_account(js->gc), "user_directory", "");
 	if(!*def_val && js->user_directories)
diff --git a/libpurple/protocols/jabber/buddy.h b/libpurple/protocols/jabber/buddy.h
--- a/libpurple/protocols/jabber/buddy.h
+++ b/libpurple/protocols/jabber/buddy.h
@@ -103,11 +103,11 @@ void jabber_buddy_get_info(PurpleConnect
 GList *jabber_blist_node_menu(PurpleBlistNode *node);
 
 void jabber_set_info(PurpleConnection *gc, const char *info);
-void jabber_setup_set_info(PurplePluginAction *action);
+void jabber_setup_set_info(PurpleProtocolAction *action);
 void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img);
 
 void jabber_user_search(JabberStream *js, const char *directory);
-void jabber_user_search_begin(PurplePluginAction *);
+void jabber_user_search_begin(PurpleProtocolAction *);
 
 void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js);
 
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -2513,10 +2513,10 @@ static void jabber_password_change_cb(Ja
 	jabber_iq_send(iq);
 }
 
-static void jabber_password_change(PurplePluginAction *action)
+static void jabber_password_change(PurpleProtocolAction *action)
 {
 
-	PurpleConnection *gc = (PurpleConnection *) action->context;
+	PurpleConnection *gc = (PurpleConnection *) action->connection;
 	JabberStream *js = purple_connection_get_protocol_data(gc);
 	PurpleRequestFields *fields;
 	PurpleRequestFieldGroup *group;
@@ -2546,28 +2546,27 @@ static void jabber_password_change(Purpl
 			js);
 }
 
-GList *jabber_actions(PurplePlugin *plugin, gpointer context)
+GList *jabber_get_actions(PurpleConnection *gc)
 {
-	PurpleConnection *gc = (PurpleConnection *) context;
 	JabberStream *js = purple_connection_get_protocol_data(gc);
 	GList *m = NULL;
-	PurplePluginAction *act;
-
-	act = purple_plugin_action_new(_("Set User Info..."),
+	PurpleProtocolAction *act;
+
+	act = purple_protocol_action_new(_("Set User Info..."),
 	                             jabber_setup_set_info);
 	m = g_list_append(m, act);
 
 	/* if (js->protocol_options & CHANGE_PASSWORD) { */
-		act = purple_plugin_action_new(_("Change Password..."),
+		act = purple_protocol_action_new(_("Change Password..."),
 		                             jabber_password_change);
 		m = g_list_append(m, act);
 	/* } */
 
-	act = purple_plugin_action_new(_("Search for Users..."),
+	act = purple_protocol_action_new(_("Search for Users..."),
 	                             jabber_user_search_begin);
 	m = g_list_append(m, act);
 
-	purple_debug_info("jabber", "jabber_actions: have pep: %s\n", js->pep?"YES":"NO");
+	purple_debug_info("jabber", "jabber_get_actions: have pep: %s\n", js->pep?"YES":"NO");
 
 	if(js->pep)
 		jabber_pep_init_actions(&m);
@@ -3736,6 +3735,7 @@ static void jabber_unregister_commands(P
 	g_hash_table_remove(jabber_cmds, plugin);
 }
 
+#if 0
 /* IPC functions */
 
 /**
@@ -3783,6 +3783,7 @@ jabber_ipc_add_feature(const gchar *feat
 	/* send presence with new caps info for all connected accounts */
 	jabber_caps_broadcast_change();
 }
+#endif
 
 static void
 jabber_do_init(void)
@@ -3940,6 +3941,7 @@ void jabber_plugin_init(PurplePlugin *pl
 
 	jabber_register_commands(plugin);
 
+#if 0
 	/* IPC functions */
 	purple_plugin_ipc_register(plugin, "contact_has_feature", PURPLE_CALLBACK(jabber_ipc_contact_has_feature),
 							 purple_marshal_BOOLEAN__POINTER_POINTER_POINTER,
@@ -3963,6 +3965,7 @@ void jabber_plugin_init(PurplePlugin *pl
 	                           G_TYPE_NONE, 2,
 	                           G_TYPE_STRING,  /* node */
 	                           G_TYPE_STRING); /* namespace */
+#endif
 
 	purple_signal_register(plugin, "jabber-register-namespace-watcher",
 			purple_marshal_VOID__POINTER_POINTER,
@@ -4047,8 +4050,9 @@ void jabber_plugin_uninit(PurplePlugin *
 	g_return_if_fail(plugin_ref > 0);
 
 	purple_signals_unregister_by_instance(plugin);
+#if 0
 	purple_plugin_ipc_unregister_all(plugin);
-
+#endif
 	jabber_unregister_commands(plugin);
 
 	--plugin_ref;
diff --git a/libpurple/protocols/jabber/jabber.h b/libpurple/protocols/jabber/jabber.h
--- a/libpurple/protocols/jabber/jabber.h
+++ b/libpurple/protocols/jabber/jabber.h
@@ -403,7 +403,7 @@ void jabber_convo_closed(PurpleConnectio
 PurpleChat *jabber_find_blist_chat(PurpleAccount *account, const char *name);
 gboolean jabber_offline_message(const PurpleBuddy *buddy);
 int jabber_prpl_send_raw(PurpleConnection *gc, const char *buf, int len);
-GList *jabber_actions(PurplePlugin *plugin, gpointer context);
+GList *jabber_get_actions(PurpleConnection *gc);
 
 gboolean jabber_audio_enabled(JabberStream *js, const char *unused);
 gboolean jabber_video_enabled(JabberStream *js, const char *unused);
diff --git a/libpurple/protocols/jabber/libfacebook.c b/libpurple/protocols/jabber/libfacebook.c
--- a/libpurple/protocols/jabber/libfacebook.c
+++ b/libpurple/protocols/jabber/libfacebook.c
@@ -55,10 +55,12 @@ facebook_list_icon(PurpleAccount *a, Pur
 	return "facebook";
 }
 
-static PurplePlugin *my_protocol = NULL;
+static PurplePluginProtocolInfo *my_protocol = NULL;
 
 static PurplePluginProtocolInfo prpl_info =
 {
+	"prpl-facebook-xmpp",                   /* id */
+	"Facebook (XMPP)",                      /* name */
 	sizeof(PurplePluginProtocolInfo),       /* struct_size */
 	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_MAIL_CHECK |
 #ifdef HAVE_CYRUS_SASL
@@ -68,6 +70,7 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL,							/* user_splits */
 	NULL,							/* protocol_options */
 	{"png", 32, 32, 96, 96, 0, PURPLE_ICON_SCALE_SEND | PURPLE_ICON_SCALE_DISPLAY}, /* icon_spec */
+	jabber_get_actions,				/* get_actions */
 	facebook_list_icon,				/* list_icon */
 	jabber_list_emblem,			/* list_emblems */
 	jabber_status_text,				/* status_text */
@@ -136,57 +139,6 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL  /* get_public_alias */
 };
 
-static gboolean load_plugin(PurplePlugin *plugin)
-{
-	jabber_plugin_init(plugin);
-
-	return TRUE;
-}
-
-static gboolean unload_plugin(PurplePlugin *plugin)
-{
-	jabber_plugin_uninit(plugin);
-
-	return TRUE;
-}
-
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_PROTOCOL,                         /**< type           */
-	NULL,                                           /**< ui_requirement */
-	0,                                              /**< flags          */
-	NULL,                                           /**< dependencies   */
-	PURPLE_PRIORITY_DEFAULT,                        /**< priority       */
-
-	"prpl-facebook-xmpp",                           /**< id             */
-	"Facebook (XMPP)",                              /**< name           */
-	DISPLAY_VERSION,                                /**< version        */
-	                                                /**  summary        */
-	N_("Facebook XMPP Protocol Plugin"),
-	                                                /**  description    */
-	N_("Facebook XMPP Protocol Plugin"),
-	NULL,                                           /**< author         */
-	PURPLE_WEBSITE,                                 /**< homepage       */
-
-	load_plugin,                                    /**< load           */
-	unload_plugin,                                  /**< unload         */
-	NULL,                                           /**< destroy        */
-
-	NULL,                                           /**< ui_info        */
-	&prpl_info,                                     /**< extra_info     */
-	NULL,                                           /**< prefs_info     */
-	jabber_actions,
-
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
 static PurpleAccount *find_acct(const char *prpl, const char *acct_id)
 {
 	PurpleAccount *acct = NULL;
@@ -219,7 +171,7 @@ static gboolean xmpp_uri_handler(const c
 	if (g_ascii_strcasecmp(proto, "xmpp"))
 		return FALSE;
 
-	acct = find_acct(purple_plugin_get_id(my_protocol), acct_id);
+	acct = find_acct(my_protocol->id, acct_id);
 
 	if (!acct)
 		return FALSE;
@@ -251,9 +203,24 @@ static gboolean xmpp_uri_handler(const c
 	return FALSE;
 }
 
+static PurplePluginInfo *
+plugin_query(GError **error)
+{
+	return purple_plugin_info_new(
+		"id",           "prpl-facebook-xmpp",
+		"name",         "Facebook (XMPP)",
+		"version",      DISPLAY_VERSION,
+		"category",     _("Protocol"),
+		"summary",      N_("Facebook XMPP Protocol Plugin"),
+		"description",  N_("Facebook XMPP Protocol Plugin"),
+		"website",      PURPLE_WEBSITE,
+		"purple-abi",   PURPLE_ABI_VERSION,
+		NULL
+	);
+}
 
-static void
-init_plugin(PurplePlugin *plugin)
+static gboolean



More information about the Commits mailing list