/soc/2013/ankitkv/gobjectification: 1a49a1a9ce18: Started the ne...
Ankit Vani
a at nevitus.org
Sun Jul 28 08:58:07 EDT 2013
Changeset: 1a49a1a9ce1838d2091e9c1b0ce2dac0f3d83624
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-28 18:27 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/1a49a1a9ce18
Description:
Started the new GObject plugin API
diffstat:
libpurple/plugin.c | 1655 ++-------------------------------------------------
libpurple/plugin.h | 638 +-------------------
2 files changed, 116 insertions(+), 2177 deletions(-)
diffs (truncated from 2388 to 300 lines):
diff --git a/libpurple/plugin.c b/libpurple/plugin.c
--- a/libpurple/plugin.c
+++ b/libpurple/plugin.c
@@ -19,1596 +19,118 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
-#define _PURPLE_PLUGIN_C_
+#include "plugin.h"
-#include "internal.h"
+#define PURPLE_PLUGIN_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_PLUGIN, PurplePluginPrivate))
-#include "accountopt.h"
-#include "core.h"
-#include "dbus-maybe.h"
-#include "debug.h"
-#include "notify.h"
-#include "prefs.h"
-#include "prpl.h"
-#include "request.h"
-#include "signals.h"
-#include "util.h"
-#include "valgrind.h"
-#include "version.h"
+/** @copydoc _PurplePluginPrivate */
+typedef struct _PurplePluginPrivate PurplePluginPrivate;
-typedef struct
+/**************************************************************************
+ * Private data
+ **************************************************************************/
+struct _PurplePluginPrivate {
+ gboolean unloadable;
+};
+
+/* Plugin property enums */
+enum
{
- GHashTable *commands;
- size_t command_count;
+ PROP_0,
+ PROP_UNLOADABLE,
+ PROP_LAST
+};
-} PurplePluginIpcInfo;
+static GPluginPluginImplementationClass *parent_class;
-typedef struct
+/**************************************************************************
+ * Plugin API
+ **************************************************************************/
+
+
+/**************************************************************************
+ * GObject code
+ **************************************************************************/
+/* GObject Property names */
+#define PROP_UNLOADABLE_S "unloadable"
+
+/* Set method for GObject properties */
+static void
+purple_plugin_set_property(GObject *obj, guint param_id, const GValue *value,
+ GParamSpec *pspec)
{
- PurpleCallback func;
- PurpleSignalMarshalFunc marshal;
+ PurplePlugin *plugin = PURPLE_PLUGIN(obj);
- int num_params;
- GType *param_types;
- GType ret_type;
-
-} PurplePluginIpcCommand;
-
-static GList *search_paths = NULL;
-static GList *plugins = NULL;
-static GList *loaded_plugins = NULL;
-static GList *protocol_plugins = NULL;
-#ifdef PURPLE_PLUGINS
-static GList *load_queue = NULL;
-static GList *plugin_loaders = NULL;
-static GList *plugins_to_disable = NULL;
-#endif
-
-#ifdef PURPLE_PLUGINS
-
-static gboolean
-has_file_extension(const char *filename, const char *ext)
-{
- int len, extlen;
-
- if (filename == NULL || *filename == '\0' || ext == NULL)
- return 0;
-
- extlen = strlen(ext);
- len = strlen(filename) - extlen;
-
- if (len < 0)
- return 0;
-
- return (strncmp(filename + len, ext, extlen) == 0);
-}
-
-static gboolean
-is_native(const char *filename)
-{
- const char *last_period;
-
- last_period = strrchr(filename, '.');
- if (last_period == NULL)
- return FALSE;
-
- return !(strcmp(last_period, ".dll") &
- strcmp(last_period, ".sl") &
- strcmp(last_period, ".so"));
-}
-
-static char *
-purple_plugin_get_basename(const char *filename)
-{
- const char *basename;
- const char *last_period;
-
- basename = strrchr(filename, G_DIR_SEPARATOR);
- if (basename != NULL)
- basename++;
- else
- basename = filename;
-
- if (is_native(basename) &&
- ((last_period = strrchr(basename, '.')) != NULL))
- return g_strndup(basename, (last_period - basename));
-
- return g_strdup(basename);
-}
-
-static gboolean
-loader_supports_file(PurplePlugin *loader, const char *filename)
-{
- GList *exts;
-
- for (exts = PURPLE_PLUGIN_LOADER_INFO(loader)->exts; exts != NULL; exts = exts->next) {
- if (has_file_extension(filename, (char *)exts->data)) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-static PurplePlugin *
-find_loader_for_plugin(const PurplePlugin *plugin)
-{
- PurplePlugin *loader;
- GList *l;
-
- if (plugin->path == NULL)
- return NULL;
-
- for (l = purple_plugins_get_loaded(); l != NULL; l = l->next) {
- loader = l->data;
-
- if (loader->info->type == PURPLE_PLUGIN_LOADER &&
- loader_supports_file(loader, plugin->path)) {
-
- return loader;
- }
-
- loader = NULL;
- }
-
- return NULL;
-}
-
-#endif /* PURPLE_PLUGINS */
-
-/**
- * Negative if a before b, 0 if equal, positive if a after b.
- */
-static gint
-compare_prpl(PurplePlugin *a, PurplePlugin *b)
-{
- if(PURPLE_IS_PROTOCOL_PLUGIN(a)) {
- if(PURPLE_IS_PROTOCOL_PLUGIN(b))
- return strcmp(a->info->name, b->info->name);
- else
- return -1;
- } else {
- if(PURPLE_IS_PROTOCOL_PLUGIN(b))
- return 1;
- else
- return 0;
+ switch (param_id) {
+ case PROP_UNLOADABLE:
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
}
}
-PurplePlugin *
-purple_plugin_new(gboolean native, const char *path)
+/* Get method for GObject properties */
+static void
+purple_plugin_get_property(GObject *obj, guint param_id, GValue *value,
+ GParamSpec *pspec)
{
- PurplePlugin *plugin;
+ PurplePlugin *plugin = PURPLE_PLUGIN(obj);
- plugin = g_new0(PurplePlugin, 1);
-
- plugin->native_plugin = native;
- plugin->path = g_strdup(path);
-
- PURPLE_DBUS_REGISTER_POINTER(plugin, PurplePlugin);
-
- return plugin;
-}
-
-PurplePlugin *
-purple_plugin_probe(const char *filename)
-{
-#ifdef PURPLE_PLUGINS
- PurplePlugin *plugin = NULL;
- PurplePlugin *loader;
- gpointer unpunned;
- gchar *basename = NULL;
- gboolean (*purple_init_plugin)(PurplePlugin *);
-
- purple_debug_misc("plugins", "probing %s\n", filename);
- g_return_val_if_fail(filename != NULL, NULL);
-
- if (!g_file_test(filename, G_FILE_TEST_EXISTS))
- return NULL;
-
- /* If this plugin has already been probed then exit */
- basename = purple_plugin_get_basename(filename);
- plugin = purple_plugins_find_with_basename(basename);
- g_free(basename);
- if (plugin != NULL)
- {
- if (purple_strequal(filename, plugin->path))
- return plugin;
- else if (!purple_plugin_is_unloadable(plugin))
- {
- purple_debug_warning("plugins", "Not loading %s. "
- "Another plugin with the same name (%s) has already been loaded.\n",
- filename, plugin->path);
- return plugin;
- }
- else
- {
- /* The old plugin was a different file and it was unloadable.
- * There's no guarantee that this new file with the same name
- * will be loadable, but unless it fails in one of the silent
- * ways and the first one didn't, it's not any worse. The user
- * will still see a greyed-out plugin, which is what we want. */
- purple_plugin_destroy(plugin);
- }
- }
-
- plugin = purple_plugin_new(has_file_extension(filename, G_MODULE_SUFFIX), filename);
-
- if (plugin->native_plugin) {
- const char *error;
-#ifdef _WIN32
- /* Suppress error popups for failing to load plugins */
- UINT old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
-#endif
-
- /*
- * We pass G_MODULE_BIND_LOCAL here to prevent symbols from
- * plugins being added to the global name space.
- *
- * G_MODULE_BIND_LOCAL was added in glib 2.3.3.
- */
- plugin->handle = g_module_open(filename, G_MODULE_BIND_LOCAL);
-
- if (plugin->handle == NULL)
- {
- const char *error = g_module_error();
- if (error != NULL && purple_str_has_prefix(error, filename))
- {
- error = error + strlen(filename);
-
- /* These are just so we don't crash. If we
- * got this far, they should always be true. */
- if (*error == ':')
- error++;
- if (*error == ' ')
- error++;
- }
-
- if (error == NULL || !*error)
- {
More information about the Commits
mailing list