fix bad free
[oweals/gnunet.git] / src / include / gnunet_plugin_lib.h
index e4f603c4eb83b2b251dfbd18c28eef2eb2d8c7e0..52e0dee5197bc7b3f267d99ea6c852d68f80d3fa 100644 (file)
@@ -1,27 +1,30 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**
- * @file include/gnunet_plugin_lib.h
- * @brief plugin loading and unloading
  * @author Christian Grothoff
+ *
+ * @file
+ * Plugin loading and unloading
+ *
+ * @defgroup plugin  Plugin library
+ * Plugin loading and unloading
+ * @{
  */
 
 #ifndef GNUNET_PLUGIN_LIB_H
@@ -41,8 +44,27 @@ extern "C"
 
 /**
  * Signature of any function exported by a plugin.
+ *
+ * @param arg argument to the function (context)
+ * @return some pointer, NULL if the plugin was
+ *         shutdown or if there was an error, otherwise
+ *         the plugin's API on success
  */
-typedef void *(*GNUNET_PLUGIN_Callback) (void *arg);
+typedef void *
+(*GNUNET_PLUGIN_Callback) (void *arg);
+
+
+/**
+ * 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);
 
 
 /**
@@ -55,9 +77,46 @@ typedef void *(*GNUNET_PLUGIN_Callback) (void *arg);
  *
  * @param library_name name of the plugin to load
  * @param arg argument to the plugin initialization function
- * @return whatever the initialization function returned
+ * @return whatever the initialization function returned, NULL on error
+ */
+void *
+GNUNET_PLUGIN_load (const char *library_name,
+                    void *arg);
+
+
+/**
+ * Signature of a function called by #GNUNET_PLUGIN_load_all().
+ *
+ * @param cls closure
+ * @param library_name full name of the library (to be used with
+ *        #GNUNET_PLUGIN_unload)
+ * @param lib_ret return value from the initialization function
+ *        of the library (same as what #GNUNET_PLUGIN_load would
+ *        have returned for the given library name)
+ */
+typedef void
+(*GNUNET_PLUGIN_LoaderCallback) (void *cls,
+                                 const char *library_name,
+                                 void *lib_ret);
+
+
+/**
+ * Load all compatible plugins with the given base name.
+ *
+ * Note that the library must export symbols called
+ * "basename_ANYTHING_init" and "basename_ANYTHING__done".  These will
+ * be called when the library is loaded and unloaded respectively.
+ *
+ * @param basename basename of the plugins to load
+ * @param arg argument to the plugin initialization function
+ * @param cb function to call for each plugin found
+ * @param cb_cls closure for @a cb
  */
-void *GNUNET_PLUGIN_load (const char *library_name, void *arg);
+void
+GNUNET_PLUGIN_load_all (const char *basename,
+                        void *arg,
+                        GNUNET_PLUGIN_LoaderCallback cb,
+                        void *cb_cls);
 
 
 /**
@@ -66,9 +125,12 @@ void *GNUNET_PLUGIN_load (const char *library_name, void *arg);
  *
  * @param library_name name of the plugin to unload
  * @param arg argument to the plugin shutdown function
- * @return whatever the shutdown function returned
+ * @return whatever the shutdown function returned, typically NULL
+ *         or a "char *" representing the error message
  */
-void *GNUNET_PLUGIN_unload (const char *library_name, void *arg);
+void *
+GNUNET_PLUGIN_unload (const char *library_name,
+                      void *arg);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */
@@ -78,7 +140,9 @@ void *GNUNET_PLUGIN_unload (const char *library_name, void *arg);
 }
 #endif
 
-
 /* ifndef GNUNET_PLUGIN_LIB_H */
 #endif
+
+/** @} */  /* end of group */
+
 /* end of gnunet_plugin_lib.h */