changeset 10682:c604c88a7530

[gaim-migrate @ 12228] This is the changes I made to plugin loading to oldstatus a few days ago. Luckily plugin.c is compiled before gtkstatusbox.c, so I can at least test that this compiles. It's basically the same code as oldstatus, so hopefully it'll work. Here's the commit message from that commit: sf patch #1118347, from Richard Laager, with changes by me This changes how plugins are loaded. Here's the run-down: 1. If a plugin is loaded, the plugin's full file name + path is stored in prefs.xml 2. When we attempt to load any saved plugins, we first try to load the plugin using the full path name. 3. If that fails, we strip the plugin's path and just use the base name. When doing this, if the plugin is a .so or .dll we also strip the plugin's extension. This change will hopefully allow people to use the same prefs.xml on Windows and "lunix" and have their list of loaded plugins not get cleared. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 11 Mar 2005 03:54:23 +0000
parents d29fae081061
children e11f3e1599d4
files src/plugin.c src/plugin.h
diffstat 2 files changed, 84 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugin.c	Thu Mar 10 23:47:30 2005 +0000
+++ b/src/plugin.c	Fri Mar 11 03:54:23 2005 +0000
@@ -81,6 +81,39 @@
 }
 
 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, GAIM_PLUGIN_EXT_WIN32) &
+	         strcmp(last_period, GAIM_PLUGIN_EXT_HPUX) &
+	         strcmp(last_period, GAIM_PLUGIN_EXT_UNIX));
+}
+
+static char *
+gaim_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(GaimPlugin *loader, const char *filename)
 {
 	GList *exts;
@@ -843,24 +876,42 @@
 
 	for (f = files; f; f = f->next)
 	{
-		char *filename = g_path_get_basename(f->data);
-		GaimPlugin *plugin = NULL;
+		char *filename;
+		char *basename;
+		GaimPlugin *plugin;
+
+		if (f->data == NULL)
+			continue;
 
-		if (filename != NULL)
+		filename = f->data;
+		/*
+		 * We don't know if the filename uses Windows or Unix path
+		 * separators (because people might be sharing a prefs.xml
+		 * file across systems), so we find the last occurrence
+		 * of either.
+		 */
+		basename = strrchr(filename, '/');
+		if ((basename == NULL) || (basename < strrchr(filename, '\\')))
+			basename = strrchr(filename, '\\');
+		if (basename != NULL)
+			basename++;
+
+		if ((plugin = gaim_plugins_find_with_filename(filename)) != NULL)
 		{
-			if ((plugin = gaim_plugins_find_with_basename(filename)) != NULL)
-			{
-				gaim_debug_info("plugins", "Loading saved plugin %s\n",
-								filename);
-				gaim_plugin_load(plugin);
-			}
-			else
-			{
-				gaim_debug_error("plugins", "Unable to find saved plugin %s\n",
-								 filename);
-			}
-
-			g_free(filename);
+			gaim_debug_info("plugins", "Loading saved plugin %s\n",
+							plugin->path);
+			gaim_plugin_load(plugin);
+		}
+		else if ((plugin = gaim_plugins_find_with_basename(basename)) != NULL)
+		{
+			gaim_debug_info("plugins", "Loading saved plugin %s\n",
+							plugin->path);
+			gaim_plugin_load(plugin);
+		}
+		else
+		{
+			gaim_debug_error("plugins", "Unable to find saved plugin %s\n",
+							 filename);
 		}
 
 		g_free(f->data);
@@ -1121,25 +1172,31 @@
 {
 	GaimPlugin *plugin;
 	GList *l;
+	char *basename_no_ext;
+	char *tmp;
 
 	g_return_val_if_fail(basename != NULL, NULL);
 
+	basename_no_ext = gaim_plugin_get_basename(basename);
+
 	for (l = plugins; l != NULL; l = l->next)
 	{
-		char *tmp;
-
 		plugin = (GaimPlugin *)l->data;
 
 		if (plugin->path != NULL) {
-			tmp = g_path_get_basename(plugin->path);
-			if (!strcmp(tmp, basename)) {
+			tmp = gaim_plugin_get_basename(plugin->path);
+			if (!strcmp(tmp, basename_no_ext))
+			{
 				g_free(tmp);
+				g_free(basename_no_ext);
 				return plugin;
 			}
 			g_free(tmp);
 		}
 	}
 
+	g_free(basename_no_ext);
+
 	return NULL;
 }
 
--- a/src/plugin.h	Thu Mar 10 23:47:30 2005 +0000
+++ b/src/plugin.h	Fri Mar 11 03:54:23 2005 +0000
@@ -30,13 +30,17 @@
 #include "signals.h"
 #include "value.h"
 
+#define GAIM_PLUGIN_EXT_WIN32 ".dll"
+#define GAIM_PLUGIN_EXT_HPUX ".sl"
+#define GAIM_PLUGIN_EXT_UNIX ".so"
+
 #ifdef _WIN32
-# define GAIM_PLUGIN_EXT ".dll"
+# define GAIM_PLUGIN_EXT GAIM_PLUGIN_EXT_WIN32
 #else
 # ifdef __hpux
-#  define GAIM_PLUGIN_EXT ".sl"
+#  define GAIM_PLUGIN_EXT GAIM_PLUGIN_EXT_HPUX
 # else
-#  define GAIM_PLUGIN_EXT ".so"
+#  define GAIM_PLUGIN_EXT GAIM_PLUGIN_EXT_UNIX
 # endif
 #endif