gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13577 - in gnunet/src: include util


From: gnunet
Subject: [GNUnet-SVN] r13577 - in gnunet/src: include util
Date: Fri, 5 Nov 2010 23:16:16 +0100

Author: grothoff
Date: 2010-11-05 23:16:16 +0100 (Fri, 05 Nov 2010)
New Revision: 13577

Modified:
   gnunet/src/include/gnunet_plugin_lib.h
   gnunet/src/util/plugin.c
Log:
add API to test for plugin's existence

Modified: gnunet/src/include/gnunet_plugin_lib.h
===================================================================
--- gnunet/src/include/gnunet_plugin_lib.h      2010-11-05 22:04:46 UTC (rev 
13576)
+++ gnunet/src/include/gnunet_plugin_lib.h      2010-11-05 22:16:16 UTC (rev 
13577)
@@ -51,6 +51,17 @@
 
 
 /**
+ * Test if a plugin exists.
+ *
+ * Note that the library must export a symbol called
+ * "library_name_init" for the test to succeed. 
+ *
+ * @param library_name name of the plugin to test if it is installed
+ * @return GNUNET_YES if the plugin exists, GNUNET_NO if not
+ */
+int GNUNET_PLUGIN_test (const char *library_name);
+
+/**
  * Setup plugin (runs the "init" callback and returns whatever "init"
  * returned).  If "init" returns NULL, the plugin is unloaded.
  *

Modified: gnunet/src/util/plugin.c
===================================================================
--- gnunet/src/util/plugin.c    2010-11-05 22:04:46 UTC (rev 13576)
+++ gnunet/src/util/plugin.c    2010-11-05 22:16:16 UTC (rev 13577)
@@ -151,7 +151,44 @@
   return mptr;
 }
 
+/**
+ * Test if a plugin exists.
+ *
+ * Note that the library must export a symbol called
+ * "library_name_init" for the test to succeed. 
+ *
+ * @param library_name name of the plugin to test if it is installed
+ * @return GNUNET_YES if the plugin exists, GNUNET_NO if not
+ */
+int
+GNUNET_PLUGIN_test (const char *library_name)
+{
+  void *libhandle;
+  GNUNET_PLUGIN_Callback init;
+  struct PluginList plug;
 
+  if (! initialized)
+    {
+      initialized = GNUNET_YES;
+      plugin_init ();
+    }
+  libhandle = lt_dlopenext (library_name);
+  if (libhandle == NULL)
+    return GNUNET_NO;
+  plug.handle = libhandle;
+  plug.name = (char*) library_name;
+  init = resolve_function (&plug, "init");
+  if (init == NULL)
+    {
+      GNUNET_break (0);
+      lt_dlclose (libhandle);
+      return GNUNET_NO;
+    }
+  lt_dlclose (libhandle);
+  return GNUNET_YES;
+}
+
+
 /**
  * Setup plugin (runs the "init" callback and returns whatever "init"
  * returned).  If "init" returns NULL, the plugin is unloaded.
@@ -193,6 +230,7 @@
   init = resolve_function (plug, "init");
   if ((init == NULL) || (NULL == (ret = init (arg))))
     {
+      lt_dlclose (libhandle);
       GNUNET_free (plug->name);
       plugins = plug->next;
       GNUNET_free (plug);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]