aboutsummaryrefslogtreecommitdiff
path: root/src/util/plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/plugin.c')
-rw-r--r--src/util/plugin.c143
1 files changed, 67 insertions, 76 deletions
diff --git a/src/util/plugin.c b/src/util/plugin.c
index dffc8ecd6..fe5fb87f9 100644
--- a/src/util/plugin.c
+++ b/src/util/plugin.c
@@ -85,30 +85,30 @@ plugin_init ()
85 85
86 err = lt_dlinit (); 86 err = lt_dlinit ();
87 if (err > 0) 87 if (err > 0)
88 { 88 {
89 fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"), 89 fprintf (stderr, _("Initialization of plugin mechanism failed: %s!\n"),
90 lt_dlerror ()); 90 lt_dlerror ());
91 return; 91 return;
92 } 92 }
93 opath = lt_dlgetsearchpath (); 93 opath = lt_dlgetsearchpath ();
94 if (opath != NULL) 94 if (opath != NULL)
95 old_dlsearchpath = GNUNET_strdup (opath); 95 old_dlsearchpath = GNUNET_strdup (opath);
96 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR); 96 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
97 if (path != NULL) 97 if (path != NULL)
98 {
99 if (opath != NULL)
98 { 100 {
99 if (opath != NULL) 101 GNUNET_asprintf (&cpath, "%s:%s", opath, path);
100 { 102 lt_dlsetsearchpath (cpath);
101 GNUNET_asprintf (&cpath, "%s:%s", opath, path); 103 GNUNET_free (path);
102 lt_dlsetsearchpath (cpath); 104 GNUNET_free (cpath);
103 GNUNET_free (path);
104 GNUNET_free (cpath);
105 }
106 else
107 {
108 lt_dlsetsearchpath (path);
109 GNUNET_free (path);
110 }
111 } 105 }
106 else
107 {
108 lt_dlsetsearchpath (path);
109 GNUNET_free (path);
110 }
111 }
112} 112}
113 113
114 114
@@ -120,10 +120,10 @@ plugin_fini ()
120{ 120{
121 lt_dlsetsearchpath (old_dlsearchpath); 121 lt_dlsetsearchpath (old_dlsearchpath);
122 if (old_dlsearchpath != NULL) 122 if (old_dlsearchpath != NULL)
123 { 123 {
124 GNUNET_free (old_dlsearchpath); 124 GNUNET_free (old_dlsearchpath);
125 old_dlsearchpath = NULL; 125 old_dlsearchpath = NULL;
126 } 126 }
127 lt_dlexit (); 127 lt_dlexit ();
128} 128}
129 129
@@ -143,8 +143,8 @@ resolve_function (struct PluginList *plug, const char *name)
143 mptr = lt_dlsym (plug->handle, initName); 143 mptr = lt_dlsym (plug->handle, initName);
144 if (mptr == NULL) 144 if (mptr == NULL)
145 LOG (GNUNET_ERROR_TYPE_ERROR, 145 LOG (GNUNET_ERROR_TYPE_ERROR,
146 _("`%s' failed to resolve method '%s' with error: %s\n"), 146 _("`%s' failed to resolve method '%s' with error: %s\n"), "lt_dlsym",
147 "lt_dlsym", &initName[1], lt_dlerror ()); 147 &initName[1], lt_dlerror ());
148 GNUNET_free (initName); 148 GNUNET_free (initName);
149 return mptr; 149 return mptr;
150} 150}
@@ -166,10 +166,10 @@ GNUNET_PLUGIN_test (const char *library_name)
166 struct PluginList plug; 166 struct PluginList plug;
167 167
168 if (!initialized) 168 if (!initialized)
169 { 169 {
170 initialized = GNUNET_YES; 170 initialized = GNUNET_YES;
171 plugin_init (); 171 plugin_init ();
172 } 172 }
173 libhandle = lt_dlopenext (library_name); 173 libhandle = lt_dlopenext (library_name);
174 if (libhandle == NULL) 174 if (libhandle == NULL)
175 return GNUNET_NO; 175 return GNUNET_NO;
@@ -177,11 +177,11 @@ GNUNET_PLUGIN_test (const char *library_name)
177 plug.name = (char *) library_name; 177 plug.name = (char *) library_name;
178 init = resolve_function (&plug, "init"); 178 init = resolve_function (&plug, "init");
179 if (init == NULL) 179 if (init == NULL)
180 { 180 {
181 GNUNET_break (0); 181 GNUNET_break (0);
182 lt_dlclose (libhandle); 182 lt_dlclose (libhandle);
183 return GNUNET_NO; 183 return GNUNET_NO;
184 } 184 }
185 lt_dlclose (libhandle); 185 lt_dlclose (libhandle);
186 return GNUNET_YES; 186 return GNUNET_YES;
187} 187}
@@ -208,18 +208,18 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
208 void *ret; 208 void *ret;
209 209
210 if (!initialized) 210 if (!initialized)
211 { 211 {
212 initialized = GNUNET_YES; 212 initialized = GNUNET_YES;
213 plugin_init (); 213 plugin_init ();
214 } 214 }
215 libhandle = lt_dlopenext (library_name); 215 libhandle = lt_dlopenext (library_name);
216 if (libhandle == NULL) 216 if (libhandle == NULL)
217 { 217 {
218 LOG (GNUNET_ERROR_TYPE_ERROR, 218 LOG (GNUNET_ERROR_TYPE_ERROR,
219 _("`%s' failed for library `%s' with error: %s\n"), 219 _("`%s' failed for library `%s' with error: %s\n"), "lt_dlopenext",
220 "lt_dlopenext", library_name, lt_dlerror ()); 220 library_name, lt_dlerror ());
221 return NULL; 221 return NULL;
222 } 222 }
223 plug = GNUNET_malloc (sizeof (struct PluginList)); 223 plug = GNUNET_malloc (sizeof (struct PluginList));
224 plug->handle = libhandle; 224 plug->handle = libhandle;
225 plug->name = GNUNET_strdup (library_name); 225 plug->name = GNUNET_strdup (library_name);
@@ -227,13 +227,13 @@ GNUNET_PLUGIN_load (const char *library_name, void *arg)
227 plugins = plug; 227 plugins = plug;
228 init = resolve_function (plug, "init"); 228 init = resolve_function (plug, "init");
229 if ((init == NULL) || (NULL == (ret = init (arg)))) 229 if ((init == NULL) || (NULL == (ret = init (arg))))
230 { 230 {
231 lt_dlclose (libhandle); 231 lt_dlclose (libhandle);
232 GNUNET_free (plug->name); 232 GNUNET_free (plug->name);
233 plugins = plug->next; 233 plugins = plug->next;
234 GNUNET_free (plug); 234 GNUNET_free (plug);
235 return NULL; 235 return NULL;
236 } 236 }
237 return ret; 237 return ret;
238} 238}
239 239
@@ -257,10 +257,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
257 prev = NULL; 257 prev = NULL;
258 pos = plugins; 258 pos = plugins;
259 while ((pos != NULL) && (0 != strcmp (pos->name, library_name))) 259 while ((pos != NULL) && (0 != strcmp (pos->name, library_name)))
260 { 260 {
261 prev = pos; 261 prev = pos;
262 pos = pos->next; 262 pos = pos->next;
263 } 263 }
264 if (pos == NULL) 264 if (pos == NULL)
265 return NULL; 265 return NULL;
266 266
@@ -276,10 +276,10 @@ GNUNET_PLUGIN_unload (const char *library_name, void *arg)
276 GNUNET_free (pos->name); 276 GNUNET_free (pos->name);
277 GNUNET_free (pos); 277 GNUNET_free (pos);
278 if (plugins == NULL) 278 if (plugins == NULL)
279 { 279 {
280 plugin_fini (); 280 plugin_fini ();
281 initialized = GNUNET_NO; 281 initialized = GNUNET_NO;
282 } 282 }
283 return ret; 283 return ret;
284} 284}
285 285
@@ -294,8 +294,7 @@ struct LoadAllContext
294 294
295 295
296static int 296static int
297find_libraries (void *cls, 297find_libraries (void *cls, const char *filename)
298 const char *filename)
299{ 298{
300 struct LoadAllContext *lac = cls; 299 struct LoadAllContext *lac = cls;
301 const char *slashpos; 300 const char *slashpos;
@@ -309,14 +308,10 @@ find_libraries (void *cls,
309 while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR))) 308 while (NULL != (slashpos = strstr (libname, DIR_SEPARATOR_STR)))
310 libname = slashpos + 1; 309 libname = slashpos + 1;
311 n = strlen (libname); 310 n = strlen (libname);
312 if (0 != strncmp (lac->basename, 311 if (0 != strncmp (lac->basename, libname, strlen (lac->basename)))
313 libname, 312 return GNUNET_OK; /* wrong name */
314 strlen (lac->basename))) 313 if ((n > 3) && (0 == strcmp (&libname[n - 3], ".la")))
315 return GNUNET_OK; /* wrong name */ 314 return GNUNET_OK; /* .la file */
316 if ( (n > 3) &&
317 (0 == strcmp (&libname[n-3],
318 ".la")) )
319 return GNUNET_OK; /* .la file */
320 basename = GNUNET_strdup (libname); 315 basename = GNUNET_strdup (libname);
321 if (NULL != (dot = strstr (basename, "."))) 316 if (NULL != (dot = strstr (basename, ".")))
322 *dot = '\0'; 317 *dot = '\0';
@@ -340,11 +335,9 @@ find_libraries (void *cls,
340 * @param cb function to call for each plugin found 335 * @param cb function to call for each plugin found
341 * @param cb_cls closure for 'cb' 336 * @param cb_cls closure for 'cb'
342 */ 337 */
343void 338void
344GNUNET_PLUGIN_load_all (const char *basename, 339GNUNET_PLUGIN_load_all (const char *basename, void *arg,
345 void *arg, 340 GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls)
346 GNUNET_PLUGIN_LoaderCallback cb,
347 void *cb_cls)
348{ 341{
349 struct LoadAllContext lac; 342 struct LoadAllContext lac;
350 char *path; 343 char *path;
@@ -353,16 +346,14 @@ GNUNET_PLUGIN_load_all (const char *basename,
353 if (path == NULL) 346 if (path == NULL)
354 { 347 {
355 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
356 _("Could not determine plugin installation path.\n")); 349 _("Could not determine plugin installation path.\n"));
357 return; 350 return;
358 } 351 }
359 lac.basename = basename; 352 lac.basename = basename;
360 lac.arg = arg; 353 lac.arg = arg;
361 lac.cb = cb; 354 lac.cb = cb;
362 lac.cb_cls = cb_cls; 355 lac.cb_cls = cb_cls;
363 GNUNET_DISK_directory_scan (path, 356 GNUNET_DISK_directory_scan (path, &find_libraries, &lac);
364 &find_libraries,
365 &lac);
366 GNUNET_free (path); 357 GNUNET_free (path);
367} 358}
368 359