changeset 15876:80ee585fb53c

SF Patch #1686400 from Eoin Coffey ("ecoffey") ecoffey described the changes: 1) Small tweaks to the loader to bring it up to speed with new mono versions and API wrapper changes that grim had made. (was in original patch, just forgot about it :-P) 2) .NET Plugins are now required to define an Id as part of their info. 3) Modified gaim_probe_plugin to check for existence of info->id and to make sure it's not empty; Prints an error, stores an error in the plugin and sets plugin->unloadable = TRUE.
author Richard Laager <rlaager@wiktel.com>
date Sat, 24 Mar 2007 06:24:59 +0000
parents 23367ba62f59
children fde34f782314
files libpurple/plugin.c libpurple/plugins/mono/BooPlugin.boo libpurple/plugins/mono/GetBuddyBack.cs libpurple/plugins/mono/MPlugin.cs libpurple/plugins/mono/api/GaimPlugin.cs libpurple/plugins/mono/api/PurplePlugin.cs libpurple/plugins/mono/loader/mono-helper.c libpurple/plugins/mono/loader/mono-helper.h libpurple/plugins/mono/loader/mono.c
diffstat 9 files changed, 114 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/plugin.c	Fri Mar 23 01:47:09 2007 +0000
+++ b/libpurple/plugin.c	Sat Mar 24 06:24:59 2007 +0000
@@ -369,6 +369,20 @@
 		return plugin;
 	}
 
+	/* 
+ 	 * Check to make sure a plugin has defined an id.
+ 	 * Not having this check caused purple_plugin_unload to
+ 	 * enter an infinite loop in certain situations by passing
+ 	 * purple_find_plugin_by_id a NULL value. -- ecoffey
+ 	 */
+	if (!plugin->info->id || !strcmp(plugin->info->id, ""))
+	{
+		plugin->error = g_strdup_printf(_("This plugin has not defined an ID."));
+		purple_debug_error("plugins", "%s is not loadable: info->id is not defined.\n", plugin->path);
+		plugin->unloadable = TRUE;
+		return plugin;
+	}
+
 	/* Really old plugins. */
 	if (plugin->info->magic != PURPLE_PLUGIN_MAGIC)
 	{
--- a/libpurple/plugins/mono/BooPlugin.boo	Fri Mar 23 01:47:09 2007 +0000
+++ b/libpurple/plugins/mono/BooPlugin.boo	Sat Mar 24 06:24:59 2007 +0000
@@ -1,6 +1,6 @@
-import Gaim
+import Purple
 
-class BooPlugin(GaimPlugin):
+class BooPlugin(PurplePlugin):
 
 	def handle(*args as (object)):
 		b as Buddy
@@ -18,5 +18,5 @@
 		Debug.debug(Debug.INFO, "booplugin", "destroying...\n")
 		
 	override def Info():
-		return GaimPluginInfo("Boo Plugin", "0.1", "Test Boo Plugin", "Longer Description", "Eoin Coffey", "urled")
+		return PurplePluginInfo("mono-boo", "Boo Plugin", "0.1", "Test Boo Plugin", "Longer Description", "Eoin Coffey", "urled")
 		
--- a/libpurple/plugins/mono/GetBuddyBack.cs	Fri Mar 23 01:47:09 2007 +0000
+++ b/libpurple/plugins/mono/GetBuddyBack.cs	Sat Mar 24 06:24:59 2007 +0000
@@ -1,8 +1,8 @@
-using Gaim;
+using Purple;
 
 public class GetBuddyBack : Plugin
 {
-	private static PluginInfo info = new PluginInfo("C# Get Buddy Back", "0.1", "Prints when a Buddy returns", "Longer Description", "Eoin Coffey", "urled");
+	private static PluginInfo info = new PluginInfo("mono-buddyback", "C# Get Buddy Back", "0.1", "Prints when a Buddy returns", "Longer Description", "Eoin Coffey", "urled");
 
 	public GetBuddyBack()
 		: base (info)
@@ -21,7 +21,7 @@
 		Debug.debug(Debug.INFO, "buddyback", "loading...\n");
 		
 		/*Signal.connect(BuddyList.GetHandle(), this, "buddy-back", new Signal.Handler(HandleSig));*/
-		/*BuddyList.OnBuddyBack.connect(this, new Signal.Handler(HandleSig));*/
+		BuddyList.OnBuddyStatusChanged.connect(this, new Signal.Handler(HandleSig));
 	}
 	
 	public override void Unload()
--- a/libpurple/plugins/mono/MPlugin.cs	Fri Mar 23 01:47:09 2007 +0000
+++ b/libpurple/plugins/mono/MPlugin.cs	Sat Mar 24 06:24:59 2007 +0000
@@ -1,8 +1,8 @@
-using Gaim;
+using Purple;
 
 public class MPlugin : Plugin
 {
-	private static PluginInfo info = new PluginInfo("C# Plugin", "0.1", "Test C# Plugin", "Longer Description", "Eoin Coffey", "urled");
+	private static PluginInfo info = new PluginInfo("mono-mplugin", "C# Plugin", "0.1", "Test C# Plugin", "Longer Description", "Eoin Coffey", "urled");
 
 	public MPlugin()
 		: base(info)
--- a/libpurple/plugins/mono/api/GaimPlugin.cs	Fri Mar 23 01:47:09 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-namespace Gaim {
-	public class PluginInfo {
-		private string name;
-		private string version;
-		private string summary;
-		private string description;
-		private string author;
-		private string homepage;
-		
-		public PluginInfo(string name, string version, string summary,
-						  string description, string author, string homepage)
-		{
-			this.name = name;
-			this.version = version;
-			this.summary = summary;
-			this.description = description;
-			this.author = author;
-			this.homepage = homepage;	
-		}
-
-		public string Name {
-			get { return name; }
-		}
-
-		public string Version {
-			get { return version; }
-		}
-
-		public string Summary {
-			get { return summary; }
-		}
-
-		public string Description {
-			get { return description; }
-		}
-
-		public string Author {
-			get { return author; }
-		}
-
-		public string Homepage {
-			get { return homepage; }
-		}
-	}
-	
-	abstract public class Plugin {
-		private PluginInfo info;
-
-		public Plugin(PluginInfo info) {
-			this.info = info;
-		}
-
-		public abstract void Load();
-		public abstract void Unload();
-		public abstract void Destroy();
-
-		public PluginInfo Info {
-			get { return info; }
-		}
-	}
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/plugins/mono/api/PurplePlugin.cs	Sat Mar 24 06:24:59 2007 +0000
@@ -0,0 +1,67 @@
+namespace Purple {
+	public class PluginInfo {
+		private string id;
+		private string name;
+		private string version;
+		private string summary;
+		private string description;
+		private string author;
+		private string homepage;
+		
+		public PluginInfo(string id, string name, string version, string summary,
+						  string description, string author, string homepage)
+		{
+			this.id = id;
+			this.name = name;
+			this.version = version;
+			this.summary = summary;
+			this.description = description;
+			this.author = author;
+			this.homepage = homepage;	
+		}
+
+		public string Id {
+			get { return id; }
+		}
+
+		public string Name {
+			get { return name; }
+		}
+
+		public string Version {
+			get { return version; }
+		}
+
+		public string Summary {
+			get { return summary; }
+		}
+
+		public string Description {
+			get { return description; }
+		}
+
+		public string Author {
+			get { return author; }
+		}
+
+		public string Homepage {
+			get { return homepage; }
+		}
+	}
+	
+	abstract public class Plugin {
+		private PluginInfo info;
+
+		public Plugin(PluginInfo info) {
+			this.info = info;
+		}
+
+		public abstract void Load();
+		public abstract void Unload();
+		public abstract void Destroy();
+
+		public PluginInfo Info {
+			get { return info; }
+		}
+	}
+}
--- a/libpurple/plugins/mono/loader/mono-helper.c	Fri Mar 23 01:47:09 2007 +0000
+++ b/libpurple/plugins/mono/loader/mono-helper.c	Sat Mar 24 06:24:59 2007 +0000
@@ -84,10 +84,13 @@
 	total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF);
 	for (i = 1; i <= total; ++i) {
 		klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i);
+		
 		pklass = mono_class_get_parent(klass);
-		if (pklass) 
-			if (strcmp("PurplePlugin", mono_class_get_name(pklass)) == 0)
+		if (pklass) {
+		
+			if (strcmp("Plugin", mono_class_get_name(pklass)) == 0)
 				return klass;
+		}
 	}
 	
 	return NULL;
@@ -126,6 +129,18 @@
 	return mono_string_to_utf8(str);
 }
 
+MonoObject* ml_get_info_prop(MonoObject *obj)
+{
+	MonoClass *klass;
+	MonoProperty *prop;
+	
+	klass = mono_class_get_parent(mono_object_get_class(obj));
+	
+	prop = mono_class_get_property_from_name(klass, "Info");
+	
+	return mono_property_get_value(prop, obj, NULL, NULL);
+}
+
 gboolean ml_is_api_dll(MonoImage *image)
 {	
 	MonoClass *klass;
--- a/libpurple/plugins/mono/loader/mono-helper.h	Fri Mar 23 01:47:09 2007 +0000
+++ b/libpurple/plugins/mono/loader/mono-helper.h	Sat Mar 24 06:24:59 2007 +0000
@@ -40,6 +40,8 @@
 
 void ml_set_prop_string(MonoObject *obj, char *field, char *data);
 
+MonoObject* ml_get_info_prop(MonoObject *obj);
+
 gboolean ml_is_api_dll(MonoImage *image);
 
 MonoDomain* ml_get_domain(void);
--- a/libpurple/plugins/mono/loader/mono.c	Fri Mar 23 01:47:09 2007 +0000
+++ b/libpurple/plugins/mono/loader/mono.c	Sat Mar 24 06:24:59 2007 +0000
@@ -26,9 +26,8 @@
 {
 	MonoAssembly *assm;
 	MonoMethod *m = NULL;
-	MonoMethod *info_method = NULL;
 	MonoObject *plugin_info;
-	gboolean found_load = FALSE, found_unload = FALSE, found_destroy = FALSE, found_info = FALSE;
+	gboolean found_load = FALSE, found_unload = FALSE, found_destroy = FALSE;
 	gpointer iter = NULL;
 
 	PurplePluginInfo *info;
@@ -71,6 +70,7 @@
 	mono_runtime_object_init(mplug->obj);
 
 	while ((m = mono_class_get_methods(mplug->klass, &iter))) {
+		purple_debug_info("mono", "plugin method: %s\n", mono_method_get_name(m));
 		if (strcmp(mono_method_get_name(m), "Load") == 0) {
 			mplug->load = m;
 			found_load = TRUE;
@@ -80,22 +80,20 @@
 		} else if (strcmp(mono_method_get_name(m), "Destroy") == 0) {
 			mplug->destroy = m;
 			found_destroy = TRUE;
-		} else if (strcmp(mono_method_get_name(m), "Info") == 0) {
-			info_method = m;
-			found_info = TRUE;
 		}
 	}
 
-	if (!(found_load && found_unload && found_destroy && found_info)) {
+	if (!(found_load && found_unload && found_destroy)) {
 		purple_debug(PURPLE_DEBUG_ERROR, "mono", "did not find the required methods\n");
 		return FALSE;
 	}
-
-	plugin_info = ml_invoke(info_method, mplug->obj, NULL);
+	
+	plugin_info = ml_get_info_prop(mplug->obj);
 
 	/* now that the methods are filled out we can populate
 	   the info struct with all the needed info */
 
+	info->id = ml_get_prop_string(plugin_info, "Id");
 	info->name = ml_get_prop_string(plugin_info, "Name");
 	info->version = ml_get_prop_string(plugin_info, "Version");
 	info->summary = ml_get_prop_string(plugin_info, "Summary");