/soc/2013/ankitkv/gobjectification: a7a71bf77f83: Refactored ssl...

Ankit Vani a at nevitus.org
Sat Aug 10 18:17:03 EDT 2013


Changeset: a7a71bf77f834f38f4a84b5011aaf86aa75dd5bf
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-11 03:46 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/a7a71bf77f83

Description:

Refactored ssl plugins to use the new API

diffstat:

 libpurple/plugins/ssl/ssl-gnutls.c |  66 ++++++++------------------
 libpurple/plugins/ssl/ssl-nss.c    |  65 ++++++++------------------
 libpurple/plugins/ssl/ssl.c        |  95 ++++++++++++++++---------------------
 3 files changed, 82 insertions(+), 144 deletions(-)

diffs (truncated from 313 to 300 lines):

diff --git a/libpurple/plugins/ssl/ssl-gnutls.c b/libpurple/plugins/ssl/ssl-gnutls.c
--- a/libpurple/plugins/ssl/ssl-gnutls.c
+++ b/libpurple/plugins/ssl/ssl-gnutls.c
@@ -1275,8 +1275,26 @@ static PurpleSslOps ssl_ops =
 	NULL
 };
 
+static PurplePluginInfo *
+plugin_query(GError **error)
+{
+	return purple_plugin_info_new(
+		"id",           SSL_GNUTLS_PLUGIN_ID,
+		"name",         N_("GNUTLS"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("SSL"),
+		"summary",      N_("Provides SSL support through GNUTLS."),
+		"description",  N_("Provides SSL support through GNUTLS."),
+		"author",       "Christian Hammond <chipx86 at gnupdate.org>",
+		"website",      PURPLE_WEBSITE,
+		"purple-abi",   PURPLE_ABI_VERSION,
+		"flags",        GPLUGIN_PLUGIN_INFO_FLAGS_INTERNAL,
+		NULL
+	);
+}
+
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	if(!purple_ssl_get_ops()) {
 		purple_ssl_set_ops(&ssl_ops);
@@ -1292,7 +1310,7 @@ plugin_load(PurplePlugin *plugin)
 }
 
 static gboolean
-plugin_unload(PurplePlugin *plugin)
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
 	if(purple_ssl_get_ops() == &ssl_ops) {
 		purple_ssl_set_ops(NULL);
@@ -1303,46 +1321,4 @@ plugin_unload(PurplePlugin *plugin)
 	return TRUE;
 }
 
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,                             /**< type           */
-	NULL,                                             /**< ui_requirement */
-	PURPLE_PLUGIN_FLAG_INVISIBLE,                       /**< flags          */
-	NULL,                                             /**< dependencies   */
-	PURPLE_PRIORITY_DEFAULT,                            /**< priority       */
-
-	SSL_GNUTLS_PLUGIN_ID,                             /**< id             */
-	N_("GNUTLS"),                                     /**< name           */
-	DISPLAY_VERSION,                                  /**< version        */
-	                                                  /**  summary        */
-	N_("Provides SSL support through GNUTLS."),
-	                                                  /**  description    */
-	N_("Provides SSL support through GNUTLS."),
-	"Christian Hammond <chipx86 at gnupdate.org>",
-	PURPLE_WEBSITE,                                     /**< homepage       */
-
-	plugin_load,                                      /**< load           */
-	plugin_unload,                                    /**< unload         */
-	NULL,                                             /**< destroy        */
-
-	NULL,                                             /**< ui_info        */
-	NULL,                                             /**< extra_info     */
-	NULL,                                             /**< prefs_info     */
-	NULL,                                             /**< actions        */
-
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
-}
-
-PURPLE_INIT_PLUGIN(ssl_gnutls, init_plugin, info)
+PURPLE_PLUGIN_INIT(ssl_gnutls, plugin_query, plugin_load, plugin_unload);
diff --git a/libpurple/plugins/ssl/ssl-nss.c b/libpurple/plugins/ssl/ssl-nss.c
--- a/libpurple/plugins/ssl/ssl-nss.c
+++ b/libpurple/plugins/ssl/ssl-nss.c
@@ -1053,9 +1053,26 @@ static PurpleSslOps ssl_ops =
 	NULL
 };
 
+static PurplePluginInfo *
+plugin_query(GError **error)
+{
+	return purple_plugin_info_new(
+		"id",           SSL_NSS_PLUGIN_ID,
+		"name",         N_("NSS"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("SSL"),
+		"summary",      N_("Provides SSL support through Mozilla NSS."),
+		"description",  N_("Provides SSL support through Mozilla NSS."),
+		"author",       "Christian Hammond <chipx86 at gnupdate.org>",
+		"website",      PURPLE_WEBSITE,
+		"purple-abi",   PURPLE_ABI_VERSION,
+		"flags",        GPLUGIN_PLUGIN_INFO_FLAGS_INTERNAL,
+		NULL
+	);
+}
 
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
 	if (!purple_ssl_get_ops()) {
 		purple_ssl_set_ops(&ssl_ops);
@@ -1071,7 +1088,7 @@ plugin_load(PurplePlugin *plugin)
 }
 
 static gboolean
-plugin_unload(PurplePlugin *plugin)
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
 	if (purple_ssl_get_ops() == &ssl_ops) {
 		purple_ssl_set_ops(NULL);
@@ -1083,46 +1100,4 @@ plugin_unload(PurplePlugin *plugin)
 	return TRUE;
 }
 
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,                             /**< type           */
-	NULL,                                             /**< ui_requirement */
-	PURPLE_PLUGIN_FLAG_INVISIBLE,                       /**< flags          */
-	NULL,                                             /**< dependencies   */
-	PURPLE_PRIORITY_DEFAULT,                            /**< priority       */
-
-	SSL_NSS_PLUGIN_ID,                             /**< id             */
-	N_("NSS"),                                        /**< name           */
-	DISPLAY_VERSION,                                  /**< version        */
-	                                                  /**  summary        */
-	N_("Provides SSL support through Mozilla NSS."),
-	                                                  /**  description    */
-	N_("Provides SSL support through Mozilla NSS."),
-	"Christian Hammond <chipx86 at gnupdate.org>",
-	PURPLE_WEBSITE,                                     /**< homepage       */
-
-	plugin_load,                                      /**< load           */
-	plugin_unload,                                    /**< unload         */
-	NULL,                                             /**< destroy        */
-
-	NULL,                                             /**< ui_info        */
-	NULL,                                             /**< extra_info     */
-	NULL,                                             /**< prefs_info     */
-	NULL,                                             /**< actions        */
-
-	/* padding */
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-static void
-init_plugin(PurplePlugin *plugin)
-{
-}
-
-PURPLE_INIT_PLUGIN(ssl_nss, init_plugin, info)
+PURPLE_PLUGIN_INIT(ssl_nss, plugin_query, plugin_load, plugin_unload);
diff --git a/libpurple/plugins/ssl/ssl.c b/libpurple/plugins/ssl/ssl.c
--- a/libpurple/plugins/ssl/ssl.c
+++ b/libpurple/plugins/ssl/ssl.c
@@ -25,27 +25,30 @@
 #include "sslconn.h"
 #include "version.h"
 
-#define SSL_PLUGIN_ID "core-ssl"
+#define SSL_PLUGIN_ID      "core-ssl"
+#define SSL_PLUGIN_DOMAIN  (g_quark_from_static_string(SSL_PLUGIN_ID))
 
 static PurplePlugin *ssl_plugin = NULL;
 
 static gboolean
-probe_ssl_plugins(PurplePlugin *my_plugin)
+probe_ssl_plugins(PurplePlugin *my_plugin, GError **error)
 {
 	PurplePlugin *plugin;
-	GList *l;
+	GList *plugins, *l;
 
 	ssl_plugin = NULL;
 
-	for (l = purple_plugins_get_all(); l != NULL; l = l->next)
+	plugins = purple_plugins_find_all();
+
+	for (l = plugins; l != NULL; l = l->next)
 	{
-		plugin = (PurplePlugin *)l->data;
+		plugin = PURPLE_PLUGIN(l->data);
 
 		if (plugin == my_plugin)
 			continue;
 
-		if (plugin->info != NULL && plugin->info->id != NULL &&
-			strncmp(plugin->info->id, "ssl-", 4) == 0)
+		if (strncmp(purple_plugin_info_get_id(purple_plugin_get_info(plugin)),
+				"ssl-", 4) == 0)
 		{
 			if (purple_plugin_is_loaded(plugin) || purple_plugin_load(plugin))
 			{
@@ -56,17 +59,43 @@ probe_ssl_plugins(PurplePlugin *my_plugi
 		}
 	}
 
-	return (ssl_plugin != NULL);
+	g_list_free(plugins);
+
+	if (ssl_plugin == NULL) {
+		g_set_error(error, SSL_PLUGIN_DOMAIN, 0,
+				"Could not find a plugin that implements SSL.");
+		return FALSE;
+	} else {
+		return TRUE;
+	}
+}
+
+static PurplePluginInfo *
+plugin_query(GError **error)
+{
+	return purple_plugin_info_new(
+		"id",           SSL_PLUGIN_ID,
+		"name",         N_("SSL"),
+		"version",      DISPLAY_VERSION,
+		"category",     N_("SSL"),
+		"summary",      N_("Provides a wrapper around SSL support libraries."),
+		"description",  N_("Provides a wrapper around SSL support libraries."),
+		"author",       "Christian Hammond <chipx86 at gnupdate.org>",
+		"website",      PURPLE_WEBSITE,
+		"purple-abi",   PURPLE_ABI_VERSION,
+		"flags",        GPLUGIN_PLUGIN_INFO_FLAGS_INTERNAL,
+		NULL
+	);
 }
 
 static gboolean
-plugin_load(PurplePlugin *plugin)
+plugin_load(PurplePlugin *plugin, GError **error)
 {
-	return probe_ssl_plugins(plugin);
+	return probe_ssl_plugins(plugin, error);
 }
 
 static gboolean
-plugin_unload(PurplePlugin *plugin)
+plugin_unload(PurplePlugin *plugin, GError **error)
 {
 	if (ssl_plugin != NULL &&
 		g_list_find(purple_plugins_get_loaded(), ssl_plugin) != NULL)
@@ -79,46 +108,4 @@ plugin_unload(PurplePlugin *plugin)
 	return TRUE;
 }
 
-static PurplePluginInfo info =
-{
-	PURPLE_PLUGIN_MAGIC,
-	PURPLE_MAJOR_VERSION,
-	PURPLE_MINOR_VERSION,
-	PURPLE_PLUGIN_STANDARD,                             /**< type           */
-    NULL,                                             /**< ui_requirement */
-	PURPLE_PLUGIN_FLAG_INVISIBLE,                       /**< flags          */
-	NULL,                                             /**< dependencies   */
-	PURPLE_PRIORITY_DEFAULT,                            /**< priority       */
-
-	SSL_PLUGIN_ID,                                    /**< id             */
-	N_("SSL"),                                        /**< name           */
-	DISPLAY_VERSION,                                  /**< version        */
-	                                                  /**  summary        */
-	N_("Provides a wrapper around SSL support libraries."),
-	                                                  /**  description    */
-	N_("Provides a wrapper around SSL support libraries."),
-	"Christian Hammond <chipx86 at gnupdate.org>",
-	PURPLE_WEBSITE,                                     /**< homepage       */
-
-	plugin_load,                                      /**< load           */
-	plugin_unload,                                    /**< unload         */
-	NULL,                                             /**< destroy        */
-
-	NULL,                                             /**< ui_info        */
-	NULL,                                             /**< extra_info     */
-	NULL,
-	NULL,
-
-	/* padding */



More information about the Commits mailing list