diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-11-05 22:16:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-11-05 22:16:16 +0000 |
commit | 2386d0b653cfabc856a8639504d6dcc82022cc1b (patch) | |
tree | 8baceca2d1d1c8c4f96edd63890d0ddb73c841ba /src/util/plugin.c | |
parent | 755a13bfb425dc9d91aeb691e65e281fed89eb1d (diff) | |
download | gnunet-2386d0b653cfabc856a8639504d6dcc82022cc1b.tar.gz gnunet-2386d0b653cfabc856a8639504d6dcc82022cc1b.zip |
add API to test for plugin's existence
Diffstat (limited to 'src/util/plugin.c')
-rw-r--r-- | src/util/plugin.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util/plugin.c b/src/util/plugin.c index 567b401c4..4e960b4fe 100644 --- a/src/util/plugin.c +++ b/src/util/plugin.c | |||
@@ -151,6 +151,43 @@ resolve_function (struct PluginList *plug, const char *name) | |||
151 | return mptr; | 151 | return mptr; |
152 | } | 152 | } |
153 | 153 | ||
154 | /** | ||
155 | * Test if a plugin exists. | ||
156 | * | ||
157 | * Note that the library must export a symbol called | ||
158 | * "library_name_init" for the test to succeed. | ||
159 | * | ||
160 | * @param library_name name of the plugin to test if it is installed | ||
161 | * @return GNUNET_YES if the plugin exists, GNUNET_NO if not | ||
162 | */ | ||
163 | int | ||
164 | GNUNET_PLUGIN_test (const char *library_name) | ||
165 | { | ||
166 | void *libhandle; | ||
167 | GNUNET_PLUGIN_Callback init; | ||
168 | struct PluginList plug; | ||
169 | |||
170 | if (! initialized) | ||
171 | { | ||
172 | initialized = GNUNET_YES; | ||
173 | plugin_init (); | ||
174 | } | ||
175 | libhandle = lt_dlopenext (library_name); | ||
176 | if (libhandle == NULL) | ||
177 | return GNUNET_NO; | ||
178 | plug.handle = libhandle; | ||
179 | plug.name = (char*) library_name; | ||
180 | init = resolve_function (&plug, "init"); | ||
181 | if (init == NULL) | ||
182 | { | ||
183 | GNUNET_break (0); | ||
184 | lt_dlclose (libhandle); | ||
185 | return GNUNET_NO; | ||
186 | } | ||
187 | lt_dlclose (libhandle); | ||
188 | return GNUNET_YES; | ||
189 | } | ||
190 | |||
154 | 191 | ||
155 | /** | 192 | /** |
156 | * Setup plugin (runs the "init" callback and returns whatever "init" | 193 | * Setup plugin (runs the "init" callback and returns whatever "init" |
@@ -193,6 +230,7 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg) | |||
193 | init = resolve_function (plug, "init"); | 230 | init = resolve_function (plug, "init"); |
194 | if ((init == NULL) || (NULL == (ret = init (arg)))) | 231 | if ((init == NULL) || (NULL == (ret = init (arg)))) |
195 | { | 232 | { |
233 | lt_dlclose (libhandle); | ||
196 | GNUNET_free (plug->name); | 234 | GNUNET_free (plug->name); |
197 | plugins = plug->next; | 235 | plugins = plug->next; |
198 | GNUNET_free (plug); | 236 | GNUNET_free (plug); |