Sun, 27 Apr 2003 20:39:36 +0000
[gaim-migrate @ 5613]
Plugins are now destroyed when gaim quits. Less memory leaks will be shown
as a result of this.
| 5205 | 1 | /* |
| 2 | * gaim | |
| 3 | * | |
| 4 | * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | */ | |
| 20 | ||
| 21 | /* | |
| 22 | * ---------------- | |
| 23 | * The Plug-in plugin | |
| 24 | * | |
| 25 | * Plugin support is currently being maintained by Mike Saraf | |
| 26 | * msaraf@dwc.edu | |
| 27 | * | |
| 28 | * Well, I didn't see any work done on it for a while, so I'm going to try | |
| 29 | * my hand at it. - Eric warmenhoven@yahoo.com | |
| 30 | * | |
| 31 | * Mike is my roomate. I can assure you that he's lazy :-P | |
| 32 | * -- Rob rob@marko.net | |
| 33 | * | |
| 34 | * Yeah, well now I'm re-writing a good portion of it! The perl stuff was | |
| 35 | * a hack. Tsk tsk! -- Christian <chipx86@gnupdate.org> | |
| 36 | */ | |
| 37 | ||
| 38 | #ifdef HAVE_CONFIG_H | |
| 39 | #include <config.h> | |
| 40 | #endif | |
| 41 | ||
| 42 | #include "gaim.h" | |
| 43 | #include "prpl.h" | |
| 44 | #include "event.h" | |
| 45 | ||
| 46 | #include <string.h> | |
| 47 | ||
| 48 | #include <sys/types.h> | |
| 49 | #include <sys/stat.h> | |
| 50 | ||
| 51 | #include <unistd.h> | |
| 52 | #include <stdio.h> | |
| 53 | #include <stdlib.h> | |
| 54 | ||
| 55 | #ifdef _WIN32 | |
| 56 | #include "win32dep.h" | |
| 57 | #endif | |
| 58 | ||
| 59 | #ifdef _WIN32 | |
| 60 | # define PLUGIN_EXT ".dll" | |
| 61 | #else | |
| 62 | # define PLUGIN_EXT ".so" | |
| 63 | #endif | |
| 64 | ||
| 65 | static GList *loaded_plugins = NULL; | |
| 66 | static GList *plugins = NULL; | |
| 67 | static GList *plugin_loaders = NULL; | |
| 68 | ||
| 69 | static size_t search_path_count = 0; | |
| 70 | static char **search_paths = NULL; | |
| 71 | ||
| 72 | static void (*probe_cb)(void *) = NULL; | |
| 73 | static void *probe_cb_data = NULL; | |
| 74 | static void (*load_cb)(GaimPlugin *, void *) = NULL; | |
| 75 | static void *load_cb_data = NULL; | |
| 76 | static void (*unload_cb)(GaimPlugin *, void *) = NULL; | |
| 77 | static void *unload_cb_data = NULL; | |
| 78 | ||
| 79 | #ifdef GAIM_PLUGINS | |
| 80 | static int | |
| 81 | is_so_file(const char *filename, const char *ext) | |
| 82 | { | |
| 83 | int len, extlen; | |
| 84 | ||
| 85 | if (filename == NULL || *filename == '\0' || ext == NULL) | |
| 86 | return 0; | |
| 87 | ||
| 88 | extlen = strlen(ext); | |
| 89 | len = strlen(filename) - extlen; | |
| 90 | ||
| 91 | if (len < 0) | |
| 92 | return 0; | |
| 93 | ||
| 94 | return (!strncmp(filename + len, ext, extlen)); | |
| 95 | } | |
| 96 | ||
| 97 | static gboolean | |
| 98 | __loader_supports_file(GaimPlugin *loader, const char *filename) | |
| 99 | { | |
| 100 | GList *l, *exts; | |
| 101 | GaimPlugin *plugin; | |
| 102 | ||
| 103 | for (l = plugin_loaders; l != NULL; l = l->next) { | |
| 104 | plugin = l->data; | |
| 105 | ||
| 106 | for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
| 107 | exts != NULL; | |
| 108 | exts = exts->next) { | |
| 109 | ||
| 110 | if (is_so_file(filename, (char *)exts->data)) | |
| 111 | return TRUE; | |
| 112 | } | |
| 113 | } | |
| 114 | ||
| 115 | return FALSE; | |
| 116 | } | |
| 117 | ||
| 118 | static GaimPlugin * | |
| 119 | __find_loader_for_plugin(const GaimPlugin *plugin) | |
| 120 | { | |
| 121 | GaimPlugin *loader; | |
| 122 | GList *l; | |
| 123 | ||
| 124 | if (plugin->path == NULL) | |
| 125 | return NULL; | |
| 126 | ||
| 127 | for (l = gaim_plugins_get_loaded(); l != NULL; l = l->next) { | |
| 128 | loader = l->data; | |
| 129 | ||
| 130 | if (loader->info->type == GAIM_PLUGIN_LOADER && | |
| 131 | __loader_supports_file(loader, plugin->path)) { | |
| 132 | ||
| 133 | return loader; | |
| 134 | } | |
| 135 | ||
| 136 | loader = NULL; | |
| 137 | } | |
| 138 | ||
| 139 | return NULL; | |
| 140 | } | |
| 141 | ||
| 142 | static gint | |
| 143 | compare_prpl(GaimPlugin *a, GaimPlugin *b) | |
| 144 | { | |
| 145 | /* neg if a before b, 0 if equal, pos if a after b */ | |
| 146 | return ((GAIM_IS_PROTOCOL_PLUGIN(a) | |
| 147 | ? GAIM_PLUGIN_PROTOCOL_INFO(a)->protocol : -1) - | |
| 148 | ((GAIM_IS_PROTOCOL_PLUGIN(b) | |
| 149 | ? GAIM_PLUGIN_PROTOCOL_INFO(b)->protocol : -1))); | |
| 150 | } | |
| 151 | ||
| 152 | #endif /* GAIM_PLUGINS */ | |
| 153 | ||
| 154 | GaimPlugin * | |
| 155 | gaim_plugin_new(gboolean native, const char *path) | |
| 156 | { | |
| 157 | GaimPlugin *plugin; | |
| 158 | ||
| 159 | plugin = g_new0(GaimPlugin, 1); | |
| 160 | ||
| 161 | plugin->native_plugin = native; | |
| 162 | plugin->path = (path == NULL ? NULL : g_strdup(path)); | |
| 163 | ||
| 164 | return plugin; | |
| 165 | } | |
| 166 | ||
| 167 | GaimPlugin * | |
| 168 | gaim_plugin_probe(const char *filename) | |
| 169 | { | |
| 170 | #ifdef GAIM_PLUGINS | |
| 171 | GaimPlugin *plugin = NULL; | |
| 172 | GaimPlugin *loader; | |
| 173 | gboolean (*gaim_init_plugin)(GaimPlugin *); | |
| 174 | ||
| 175 | g_return_val_if_fail(filename != NULL, NULL); | |
| 176 | ||
| 177 | plugin = gaim_plugins_find_with_filename(filename); | |
| 178 | ||
| 179 | if (plugin != NULL) | |
| 180 | return plugin; | |
| 181 | ||
| 182 | plugin = gaim_plugin_new(is_so_file(filename, PLUGIN_EXT), filename); | |
| 183 | ||
| 184 | if (plugin->native_plugin) { | |
| 185 | plugin->handle = g_module_open(filename, 0); | |
| 186 | ||
| 187 | if (plugin->handle == NULL) { | |
| 188 | plugin->error = g_strdup(g_module_error()); | |
| 189 | ||
| 190 | return plugin; | |
| 191 | } | |
| 192 | ||
| 193 | if (!g_module_symbol(plugin->handle, "gaim_init_plugin", | |
| 194 | (gpointer *)&gaim_init_plugin)) { | |
| 195 | g_module_close(plugin->handle); | |
| 196 | plugin->handle = NULL; | |
| 197 | ||
|
5211
94d9756c381f
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
198 | gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", |
|
94d9756c381f
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
199 | plugin->path, g_module_error()); |
| 5205 | 200 | |
| 201 | gaim_plugin_destroy(plugin); | |
| 202 | ||
| 203 | return NULL; | |
| 204 | } | |
| 205 | } | |
| 206 | else { | |
| 207 | loader = __find_loader_for_plugin(plugin); | |
| 208 | ||
| 209 | if (loader == NULL) { | |
| 210 | gaim_plugin_destroy(plugin); | |
| 211 | ||
| 212 | return NULL; | |
| 213 | } | |
| 214 | ||
| 215 | gaim_init_plugin = GAIM_PLUGIN_LOADER_INFO(loader)->probe; | |
| 216 | } | |
| 217 | ||
| 218 | plugin->error = NULL; | |
| 219 | ||
| 220 | if (!gaim_init_plugin(plugin) || plugin->info == NULL) { | |
| 221 | char buf[BUFSIZ]; | |
| 222 | ||
| 223 | g_snprintf(buf, sizeof(buf), | |
| 224 | _("The plugin %s did not return any valid plugin " | |
| 225 | "information"), | |
| 226 | plugin->path); | |
| 227 | ||
| 228 | do_error_dialog(_("Gaim was unable to load your plugin."), buf, | |
| 229 | GAIM_ERROR); | |
| 230 | ||
| 231 | gaim_plugin_destroy(plugin); | |
| 232 | ||
| 233 | return NULL; | |
| 234 | } | |
| 235 | ||
| 236 | return plugin; | |
| 237 | #else | |
| 238 | return NULL; | |
| 239 | #endif /* !GAIM_PLUGINS */ | |
| 240 | } | |
| 241 | ||
| 242 | gboolean | |
| 243 | gaim_plugin_load(GaimPlugin *plugin) | |
| 244 | { | |
| 245 | #ifdef GAIM_PLUGINS | |
| 246 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 247 | ||
| 248 | if (gaim_plugin_is_loaded(plugin)) | |
| 249 | return TRUE; | |
| 250 | ||
| 251 | if (plugin->native_plugin) { | |
| 252 | if (plugin->info != NULL && plugin->info->load != NULL) | |
| 253 | plugin->info->load(plugin); | |
| 254 | } | |
| 255 | else { | |
| 256 | GaimPlugin *loader; | |
| 257 | GaimPluginLoaderInfo *loader_info; | |
| 258 | ||
| 259 | loader = __find_loader_for_plugin(plugin); | |
| 260 | ||
| 261 | if (loader == NULL) | |
| 262 | return FALSE; | |
| 263 | ||
| 264 | loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
| 265 | ||
| 266 | if (loader_info->load != NULL) | |
| 267 | loader_info->load(plugin); | |
| 268 | } | |
| 269 | ||
| 270 | loaded_plugins = g_list_append(loaded_plugins, plugin); | |
| 271 | ||
| 272 | plugin->loaded = TRUE; | |
| 273 | ||
| 274 | /* TODO */ | |
| 275 | if (load_cb != NULL) | |
| 276 | load_cb(plugin, load_cb_data); | |
| 277 | ||
| 278 | return TRUE; | |
| 279 | ||
| 280 | #else | |
| 281 | return FALSE; | |
| 282 | #endif /* !GAIM_PLUGINS */ | |
| 283 | } | |
| 284 | ||
| 285 | gboolean | |
| 286 | gaim_plugin_unload(GaimPlugin *plugin) | |
| 287 | { | |
| 288 | #ifdef GAIM_PLUGINS | |
| 289 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 290 | ||
| 291 | loaded_plugins = g_list_remove(loaded_plugins, plugin); | |
| 292 | ||
| 293 | g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
| 294 | ||
|
5211
94d9756c381f
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
295 | gaim_debug(GAIM_DEBUG_INFO, "plugins", "Unloading plugin %s\n", |
|
94d9756c381f
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
296 | plugin->info->name); |
| 5205 | 297 | |
| 298 | /* cancel any pending dialogs the plugin has */ | |
| 299 | do_ask_cancel_by_handle(plugin); | |
| 300 | ||
| 301 | plugin->loaded = FALSE; | |
| 302 | ||
| 303 | if (plugin->native_plugin) { | |
| 304 | if (plugin->info->unload != NULL) | |
| 305 | plugin->info->unload(plugin); | |
| 306 | ||
| 307 | if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
| 308 | GaimPluginProtocolInfo *prpl_info; | |
| 309 | GList *l; | |
| 310 | struct proto_user_split *pus; | |
| 311 | struct proto_user_opt *puo; | |
| 312 | ||
| 313 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
| 314 | ||
| 315 | for (l = prpl_info->user_splits; l != NULL; l = l->next) { | |
| 316 | pus = l->data; | |
| 317 | ||
| 318 | g_free(pus->label); | |
| 319 | g_free(pus->def); | |
| 320 | g_free(pus); | |
| 321 | } | |
| 322 | ||
| 323 | g_list_free(prpl_info->user_splits); | |
| 324 | ||
| 325 | for (l = prpl_info->user_opts; l != NULL; l = l->next) { | |
| 326 | puo = l->data; | |
| 327 | ||
| 328 | g_free(puo->label); | |
| 329 | g_free(puo->def); | |
| 330 | g_free(puo); | |
| 331 | } | |
| 332 | ||
| 333 | g_list_free(prpl_info->user_opts); | |
| 334 | } | |
| 335 | } | |
| 336 | else { | |
| 337 | GaimPlugin *loader; | |
| 338 | GaimPluginLoaderInfo *loader_info; | |
| 339 | ||
| 340 | loader = __find_loader_for_plugin(plugin); | |
| 341 | ||
| 342 | if (loader == NULL) | |
| 343 | return FALSE; | |
| 344 | ||
| 345 | loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
| 346 | ||
| 347 | if (loader_info->load != NULL) | |
| 348 | loader_info->unload(plugin); | |
| 349 | } | |
| 350 | ||
| 351 | gaim_signals_disconnect_by_handle(plugin); | |
| 352 | ||
| 353 | /* TODO */ | |
| 354 | if (unload_cb != NULL) | |
| 355 | unload_cb(plugin, unload_cb_data); | |
| 356 | ||
| 357 | return TRUE; | |
| 358 | #endif /* GAIM_PLUGINS */ | |
| 359 | } | |
| 360 | ||
| 361 | gboolean | |
| 362 | gaim_plugin_reload(GaimPlugin *plugin) | |
| 363 | { | |
| 364 | #ifdef GAIM_PLUGINS | |
| 365 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 366 | g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
| 367 | ||
| 368 | if (!gaim_plugin_unload(plugin)) | |
| 369 | return FALSE; | |
| 370 | ||
| 371 | if (!gaim_plugin_load(plugin)) | |
| 372 | return FALSE; | |
| 373 | ||
| 374 | return TRUE; | |
| 375 | #else | |
| 376 | return NULL; | |
| 377 | #endif /* !GAIM_PLUGINS */ | |
| 378 | } | |
| 379 | ||
| 380 | void | |
| 381 | gaim_plugin_destroy(GaimPlugin *plugin) | |
| 382 | { | |
| 383 | g_return_if_fail(plugin != NULL); | |
| 384 | ||
| 385 | if (gaim_plugin_is_loaded(plugin)) | |
| 386 | gaim_plugin_unload(plugin); | |
| 387 | ||
| 388 | plugins = g_list_remove(plugins, plugin); | |
| 389 | ||
| 390 | /* XXX */ | |
| 391 | if (plugin->info != NULL && plugin->info->type == GAIM_PLUGIN_PROTOCOL) | |
| 392 | return; | |
| 393 | ||
| 394 | if (plugin->native_plugin) { | |
| 395 | ||
| 396 | if (plugin->info != NULL && plugin->info->type == GAIM_PLUGIN_LOADER) { | |
| 397 | GList *exts, *l, *next_l; | |
| 398 | GaimPlugin *p2; | |
| 399 | ||
| 400 | for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
| 401 | exts != NULL; | |
| 402 | exts = exts->next) { | |
| 403 | ||
| 404 | for (l = gaim_plugins_get_all(); l != NULL; l = next_l) { | |
| 405 | next_l = l->next; | |
| 406 | ||
| 407 | p2 = l->data; | |
| 408 | ||
| 409 | if (p2->path != NULL && is_so_file(p2->path, exts->data)) | |
| 410 | gaim_plugin_destroy(p2); | |
| 411 | } | |
| 412 | } | |
| 413 | ||
| 414 | g_list_free(GAIM_PLUGIN_LOADER_INFO(plugin)->exts); | |
| 415 | ||
| 416 | plugin_loaders = g_list_remove(plugin_loaders, plugin); | |
| 417 | } | |
| 418 | ||
| 419 | if (plugin->info != NULL && plugin->info->destroy != NULL) | |
| 420 | plugin->info->destroy(plugin); | |
| 421 | ||
| 422 | if (plugin->handle != NULL) | |
| 423 | g_module_close(plugin->handle); | |
| 424 | } | |
| 425 | else { | |
| 426 | GaimPlugin *loader; | |
| 427 | GaimPluginLoaderInfo *loader_info; | |
| 428 | ||
| 429 | loader = __find_loader_for_plugin(plugin); | |
| 430 | ||
| 431 | if (loader == NULL) | |
| 432 | return; | |
| 433 | ||
| 434 | loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
| 435 | ||
| 436 | if (loader_info->destroy != NULL) | |
| 437 | loader_info->destroy(plugin); | |
| 438 | } | |
| 439 | ||
| 440 | if (plugin->info != NULL && plugin->info->dependencies != NULL) | |
| 441 | g_list_free(plugin->info->dependencies); | |
| 442 | ||
| 443 | if (plugin->path != NULL) g_free(plugin->path); | |
| 444 | if (plugin->error != NULL) g_free(plugin->error); | |
| 445 | ||
| 446 | g_free(plugin); | |
| 447 | } | |
| 448 | ||
| 449 | gboolean | |
| 450 | gaim_plugin_is_loaded(const GaimPlugin *plugin) | |
| 451 | { | |
| 452 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 453 | ||
| 454 | return plugin->loaded; | |
| 455 | } | |
| 456 | ||
| 457 | void | |
| 458 | gaim_plugins_set_search_paths(size_t count, char **paths) | |
| 459 | { | |
| 460 | size_t s; | |
| 461 | ||
| 462 | g_return_if_fail(count > 0); | |
| 463 | g_return_if_fail(paths != NULL); | |
| 464 | ||
| 465 | if (search_paths != NULL) { | |
| 466 | for (s = 0; s < search_path_count; s++) | |
| 467 | g_free(search_paths[s]); | |
| 468 | ||
| 469 | g_free(search_paths); | |
| 470 | } | |
| 471 | ||
| 472 | search_paths = g_new0(char *, count); | |
| 473 | ||
| 474 | for (s = 0; s < count; s++) { | |
| 475 | if (paths[s] == NULL) | |
| 476 | search_paths[s] = NULL; | |
| 477 | else | |
| 478 | search_paths[s] = g_strdup(paths[s]); | |
| 479 | } | |
| 480 | ||
| 481 | search_path_count = count; | |
| 482 | } | |
| 483 | ||
| 484 | void | |
| 485 | gaim_plugins_unload_all(void) | |
| 486 | { | |
| 487 | #ifdef GAIM_PLUGINS | |
| 488 | ||
| 489 | while (loaded_plugins != NULL) | |
| 490 | gaim_plugin_unload(loaded_plugins->data); | |
| 491 | ||
| 492 | #endif /* GAIM_PLUGINS */ | |
| 493 | } | |
| 494 | ||
| 495 | void | |
|
5242
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
496 | gaim_plugins_destroy_all(void) |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
497 | { |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
498 | #ifdef GAIM_PLUGINS |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
499 | |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
500 | gaim_plugins_unload_all(); |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
501 | |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
502 | while (plugins != NULL) |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
503 | gaim_plugin_destroy(plugins->data); |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
504 | |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
505 | #endif /* GAIM_PLUGINS */ |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
506 | } |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
507 | void |
| 5205 | 508 | gaim_plugins_probe(const char *ext) |
| 509 | { | |
| 510 | #ifdef GAIM_PLUGINS | |
| 511 | GDir *dir; | |
| 512 | const gchar *file; | |
| 513 | gchar *path; | |
| 514 | GaimPlugin *plugin; | |
| 515 | size_t i; | |
| 516 | ||
| 517 | if (!g_module_supported()) | |
| 518 | return; | |
| 519 | ||
| 520 | for (i = 0; i < search_path_count; i++) { | |
| 521 | if (search_paths[i] == NULL) | |
| 522 | continue; | |
| 523 | ||
| 524 | dir = g_dir_open(search_paths[i], 0, NULL); | |
| 525 | ||
| 526 | if (dir != NULL) { | |
| 527 | while ((file = g_dir_read_name(dir)) != NULL) { | |
| 528 | path = g_build_filename(search_paths[i], file, NULL); | |
| 529 | ||
| 530 | if (ext == NULL || is_so_file(file, ext)) | |
| 531 | plugin = gaim_plugin_probe(path); | |
| 532 | ||
| 533 | g_free(path); | |
| 534 | } | |
| 535 | ||
| 536 | g_dir_close(dir); | |
| 537 | } | |
| 538 | } | |
| 539 | ||
| 540 | if (probe_cb != NULL) | |
| 541 | probe_cb(probe_cb_data); | |
| 542 | ||
| 543 | #endif /* GAIM_PLUGINS */ | |
| 544 | } | |
| 545 | ||
| 546 | gboolean | |
| 547 | gaim_plugin_register(GaimPlugin *plugin) | |
| 548 | { | |
| 549 | #ifdef GAIM_PLUGINS | |
| 550 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 551 | ||
| 552 | if (g_list_find(plugins, plugin)) | |
| 553 | return TRUE; | |
| 554 | ||
| 555 | /* Special exception for loader plugins. We want them loaded NOW! */ | |
| 556 | if (plugin->info->type == GAIM_PLUGIN_LOADER) { | |
| 557 | GList *exts; | |
| 558 | ||
| 559 | /* We'll just load this right now. */ | |
| 560 | if (!gaim_plugin_load(plugin)) { | |
| 561 | ||
| 562 | gaim_plugin_destroy(plugin); | |
| 563 | ||
| 564 | return FALSE; | |
| 565 | } | |
| 566 | ||
| 567 | plugin_loaders = g_list_append(plugin_loaders, plugin); | |
| 568 | ||
| 569 | for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
| 570 | exts != NULL; | |
| 571 | exts = exts->next) { | |
| 572 | ||
| 573 | gaim_plugins_probe(exts->data); | |
| 574 | } | |
| 575 | } | |
| 576 | else if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
| 577 | ||
| 578 | /* We'll just load this right now. */ | |
| 579 | if (!gaim_plugin_load(plugin)) { | |
| 580 | ||
| 581 | gaim_plugin_destroy(plugin); | |
| 582 | ||
| 583 | return FALSE; | |
| 584 | } | |
| 585 | ||
| 586 | if (GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol == GAIM_PROTO_ICQ || | |
| 587 | gaim_find_prpl(GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol)) { | |
| 588 | ||
| 589 | /* Nothing to see here--move along, move along */ | |
| 590 | gaim_plugin_destroy(plugin); | |
| 591 | ||
| 592 | return FALSE; | |
| 593 | } | |
| 594 | ||
| 595 | protocols = g_slist_insert_sorted(protocols, plugin, | |
| 596 | (GCompareFunc)compare_prpl); | |
| 597 | } | |
| 598 | ||
| 599 | plugins = g_list_append(plugins, plugin); | |
| 600 | ||
| 601 | return TRUE; | |
| 602 | #else | |
| 603 | return FALSE; | |
| 604 | #endif /* !GAIM_PLUGINS */ | |
| 605 | } | |
| 606 | ||
| 607 | gboolean | |
| 608 | gaim_plugins_enabled(void) | |
| 609 | { | |
| 610 | #ifdef GAIM_PLUGINS | |
| 611 | return TRUE; | |
| 612 | #else | |
| 613 | return FALSE; | |
| 614 | #endif | |
| 615 | } | |
| 616 | ||
| 617 | void | |
| 618 | gaim_plugins_register_probe_notify_cb(void (*func)(void *), void *data) | |
| 619 | { | |
| 620 | /* TODO */ | |
| 621 | probe_cb = func; | |
| 622 | probe_cb_data = data; | |
| 623 | } | |
| 624 | ||
| 625 | void | |
| 626 | gaim_plugins_unregister_probe_notify_cb(void (*func)(void *)) | |
| 627 | { | |
| 628 | /* TODO */ | |
| 629 | probe_cb = NULL; | |
| 630 | probe_cb_data = NULL; | |
| 631 | } | |
| 632 | ||
| 633 | void | |
| 634 | gaim_plugins_register_load_notify_cb(void (*func)(GaimPlugin *, void *), | |
| 635 | void *data) | |
| 636 | { | |
| 637 | /* TODO */ | |
| 638 | load_cb = func; | |
| 639 | load_cb_data = data; | |
| 640 | } | |
| 641 | ||
| 642 | void | |
| 643 | gaim_plugins_unregister_load_notify_cb(void (*func)(GaimPlugin *, void *)) | |
| 644 | { | |
| 645 | /* TODO */ | |
| 646 | load_cb = NULL; | |
| 647 | load_cb_data = NULL; | |
| 648 | } | |
| 649 | ||
| 650 | void | |
| 651 | gaim_plugins_register_unload_notify_cb(void (*func)(GaimPlugin *, void *), | |
| 652 | void *data) | |
| 653 | { | |
| 654 | /* TODO */ | |
| 655 | unload_cb = func; | |
| 656 | unload_cb_data = data; | |
| 657 | } | |
| 658 | ||
| 659 | void | |
| 660 | gaim_plugins_unregister_unload_notify_cb(void (*func)(GaimPlugin *, void *)) | |
| 661 | { | |
| 662 | /* TODO */ | |
| 663 | unload_cb = NULL; | |
| 664 | unload_cb_data = NULL; | |
| 665 | } | |
| 666 | ||
| 667 | GaimPlugin * | |
| 668 | gaim_plugins_find_with_name(const char *name) | |
| 669 | { | |
| 670 | GaimPlugin *plugin; | |
| 671 | GList *l; | |
| 672 | ||
| 673 | for (l = plugins; l != NULL; l = l->next) { | |
| 674 | plugin = l->data; | |
| 675 | ||
| 676 | if (!strcmp(plugin->info->name, name)) | |
| 677 | return plugin; | |
| 678 | } | |
| 679 | ||
| 680 | return NULL; | |
| 681 | } | |
| 682 | ||
| 683 | GaimPlugin * | |
| 684 | gaim_plugins_find_with_filename(const char *filename) | |
| 685 | { | |
| 686 | GaimPlugin *plugin; | |
| 687 | GList *l; | |
| 688 | ||
| 689 | for (l = plugins; l != NULL; l = l->next) { | |
| 690 | plugin = l->data; | |
| 691 | ||
| 692 | if (plugin->path != NULL && !strcmp(plugin->path, filename)) | |
| 693 | return plugin; | |
| 694 | } | |
| 695 | ||
| 696 | return NULL; | |
| 697 | } | |
| 698 | ||
| 699 | GaimPlugin * | |
| 700 | gaim_plugins_find_with_id(const char *id) | |
| 701 | { | |
| 702 | GaimPlugin *plugin; | |
| 703 | GList *l; | |
| 704 | ||
| 705 | g_return_val_if_fail(id != NULL, NULL); | |
| 706 | ||
| 707 | for (l = plugins; l != NULL; l = l->next) { | |
| 708 | plugin = l->data; | |
| 709 | ||
| 710 | if (!strcmp(plugin->info->id, id)) | |
| 711 | return plugin; | |
| 712 | } | |
| 713 | ||
| 714 | return NULL; | |
| 715 | } | |
| 716 | ||
| 717 | GList * | |
| 718 | gaim_plugins_get_loaded(void) | |
| 719 | { | |
| 720 | return loaded_plugins; | |
| 721 | } | |
| 722 | ||
| 723 | GList * | |
| 724 | gaim_plugins_get_all(void) | |
| 725 | { | |
| 726 | return plugins; | |
| 727 | } | |
| 728 |