Mercurial > pidgin
annotate src/plugin.c @ 5268:503cc9b0a8ef
[gaim-migrate @ 5640]
Plugins with errors should no longer be able to load.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Thu, 01 May 2003 08:34:52 +0000 |
| parents | f6e0c689a88b |
| children | cd7e4ba049f9 |
| rev | line source |
|---|---|
| 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
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
198 gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", |
|
0241d6b6702d
[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); | |
|
5268
503cc9b0a8ef
[gaim-migrate @ 5640]
Christian Hammond <chipx86@chipx86.com>
parents:
5243
diff
changeset
|
247 g_return_val_if_fail(plugin->error != NULL, FALSE); |
| 5205 | 248 |
| 249 if (gaim_plugin_is_loaded(plugin)) | |
| 250 return TRUE; | |
| 251 | |
| 252 if (plugin->native_plugin) { | |
| 253 if (plugin->info != NULL && plugin->info->load != NULL) | |
| 254 plugin->info->load(plugin); | |
| 255 } | |
| 256 else { | |
| 257 GaimPlugin *loader; | |
| 258 GaimPluginLoaderInfo *loader_info; | |
| 259 | |
| 260 loader = __find_loader_for_plugin(plugin); | |
| 261 | |
| 262 if (loader == NULL) | |
| 263 return FALSE; | |
| 264 | |
| 265 loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
| 266 | |
| 267 if (loader_info->load != NULL) | |
| 268 loader_info->load(plugin); | |
| 269 } | |
| 270 | |
| 271 loaded_plugins = g_list_append(loaded_plugins, plugin); | |
| 272 | |
| 273 plugin->loaded = TRUE; | |
| 274 | |
| 275 /* TODO */ | |
| 276 if (load_cb != NULL) | |
| 277 load_cb(plugin, load_cb_data); | |
| 278 | |
| 279 return TRUE; | |
| 280 | |
| 281 #else | |
| 282 return FALSE; | |
| 283 #endif /* !GAIM_PLUGINS */ | |
| 284 } | |
| 285 | |
| 286 gboolean | |
| 287 gaim_plugin_unload(GaimPlugin *plugin) | |
| 288 { | |
| 289 #ifdef GAIM_PLUGINS | |
| 290 g_return_val_if_fail(plugin != NULL, FALSE); | |
| 291 | |
| 292 loaded_plugins = g_list_remove(loaded_plugins, plugin); | |
| 293 | |
| 294 g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
| 295 | |
|
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
296 gaim_debug(GAIM_DEBUG_INFO, "plugins", "Unloading plugin %s\n", |
|
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
297 plugin->info->name); |
| 5205 | 298 |
| 299 /* cancel any pending dialogs the plugin has */ | |
| 300 do_ask_cancel_by_handle(plugin); | |
| 301 | |
| 302 plugin->loaded = FALSE; | |
| 303 | |
| 304 if (plugin->native_plugin) { | |
| 305 if (plugin->info->unload != NULL) | |
| 306 plugin->info->unload(plugin); | |
| 307 | |
| 308 if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
| 309 GaimPluginProtocolInfo *prpl_info; | |
| 310 GList *l; | |
| 311 struct proto_user_split *pus; | |
| 312 struct proto_user_opt *puo; | |
| 313 | |
| 314 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
| 315 | |
| 316 for (l = prpl_info->user_splits; l != NULL; l = l->next) { | |
| 317 pus = l->data; | |
| 318 | |
| 319 g_free(pus->label); | |
| 320 g_free(pus->def); | |
| 321 g_free(pus); | |
| 322 } | |
| 323 | |
| 324 g_list_free(prpl_info->user_splits); | |
| 325 | |
| 326 for (l = prpl_info->user_opts; l != NULL; l = l->next) { | |
| 327 puo = l->data; | |
| 328 | |
| 329 g_free(puo->label); | |
| 330 g_free(puo->def); | |
| 331 g_free(puo); | |
| 332 } | |
| 333 | |
| 334 g_list_free(prpl_info->user_opts); | |
| 335 } | |
| 336 } | |
| 337 else { | |
| 338 GaimPlugin *loader; | |
| 339 GaimPluginLoaderInfo *loader_info; | |
| 340 | |
| 341 loader = __find_loader_for_plugin(plugin); | |
| 342 | |
| 343 if (loader == NULL) | |
| 344 return FALSE; | |
| 345 | |
| 346 loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
| 347 | |
| 348 if (loader_info->load != NULL) | |
| 349 loader_info->unload(plugin); | |
| 350 } | |
| 351 | |
| 352 gaim_signals_disconnect_by_handle(plugin); | |
| 353 | |
| 354 /* TODO */ | |
| 355 if (unload_cb != NULL) | |
| 356 unload_cb(plugin, unload_cb_data); | |
| 357 | |
| 358 return TRUE; | |
| 359 #endif /* GAIM_PLUGINS */ | |
| 360 } | |
| 361 | |
| 362 gboolean | |
| 363 gaim_plugin_reload(GaimPlugin *plugin) | |
| 364 { | |
| 365 #ifdef GAIM_PLUGINS | |
| 366 g_return_val_if_fail(plugin != NULL, FALSE); | |
| 367 g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
| 368 | |
| 369 if (!gaim_plugin_unload(plugin)) | |
| 370 return FALSE; | |
| 371 | |
| 372 if (!gaim_plugin_load(plugin)) | |
| 373 return FALSE; | |
| 374 | |
| 375 return TRUE; | |
| 376 #else | |
| 377 return NULL; | |
| 378 #endif /* !GAIM_PLUGINS */ | |
| 379 } | |
| 380 | |
| 381 void | |
| 382 gaim_plugin_destroy(GaimPlugin *plugin) | |
| 383 { | |
| 384 g_return_if_fail(plugin != NULL); | |
| 385 | |
| 386 if (gaim_plugin_is_loaded(plugin)) | |
| 387 gaim_plugin_unload(plugin); | |
| 388 | |
| 389 plugins = g_list_remove(plugins, plugin); | |
| 390 | |
|
5243
f6e0c689a88b
[gaim-migrate @ 5614]
Christian Hammond <chipx86@chipx86.com>
parents:
5242
diff
changeset
|
391 if (plugin->info != NULL && plugin->info->dependencies != NULL) |
|
f6e0c689a88b
[gaim-migrate @ 5614]
Christian Hammond <chipx86@chipx86.com>
parents:
5242
diff
changeset
|
392 g_list_free(plugin->info->dependencies); |
| 5205 | 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->path != NULL) g_free(plugin->path); | |
| 441 if (plugin->error != NULL) g_free(plugin->error); | |
| 442 | |
| 443 g_free(plugin); | |
| 444 } | |
| 445 | |
| 446 gboolean | |
| 447 gaim_plugin_is_loaded(const GaimPlugin *plugin) | |
| 448 { | |
| 449 g_return_val_if_fail(plugin != NULL, FALSE); | |
| 450 | |
| 451 return plugin->loaded; | |
| 452 } | |
| 453 | |
| 454 void | |
| 455 gaim_plugins_set_search_paths(size_t count, char **paths) | |
| 456 { | |
| 457 size_t s; | |
| 458 | |
| 459 g_return_if_fail(count > 0); | |
| 460 g_return_if_fail(paths != NULL); | |
| 461 | |
| 462 if (search_paths != NULL) { | |
| 463 for (s = 0; s < search_path_count; s++) | |
| 464 g_free(search_paths[s]); | |
| 465 | |
| 466 g_free(search_paths); | |
| 467 } | |
| 468 | |
| 469 search_paths = g_new0(char *, count); | |
| 470 | |
| 471 for (s = 0; s < count; s++) { | |
| 472 if (paths[s] == NULL) | |
| 473 search_paths[s] = NULL; | |
| 474 else | |
| 475 search_paths[s] = g_strdup(paths[s]); | |
| 476 } | |
| 477 | |
| 478 search_path_count = count; | |
| 479 } | |
| 480 | |
| 481 void | |
| 482 gaim_plugins_unload_all(void) | |
| 483 { | |
| 484 #ifdef GAIM_PLUGINS | |
| 485 | |
| 486 while (loaded_plugins != NULL) | |
| 487 gaim_plugin_unload(loaded_plugins->data); | |
| 488 | |
| 489 #endif /* GAIM_PLUGINS */ | |
| 490 } | |
| 491 | |
| 492 void | |
|
5242
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
493 gaim_plugins_destroy_all(void) |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
494 { |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
495 #ifdef GAIM_PLUGINS |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
496 |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
497 while (plugins != NULL) |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
498 gaim_plugin_destroy(plugins->data); |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
499 |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
500 #endif /* GAIM_PLUGINS */ |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
501 } |
|
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
502 void |
| 5205 | 503 gaim_plugins_probe(const char *ext) |
| 504 { | |
| 505 #ifdef GAIM_PLUGINS | |
| 506 GDir *dir; | |
| 507 const gchar *file; | |
| 508 gchar *path; | |
| 509 GaimPlugin *plugin; | |
| 510 size_t i; | |
| 511 | |
| 512 if (!g_module_supported()) | |
| 513 return; | |
| 514 | |
| 515 for (i = 0; i < search_path_count; i++) { | |
| 516 if (search_paths[i] == NULL) | |
| 517 continue; | |
| 518 | |
| 519 dir = g_dir_open(search_paths[i], 0, NULL); | |
| 520 | |
| 521 if (dir != NULL) { | |
| 522 while ((file = g_dir_read_name(dir)) != NULL) { | |
| 523 path = g_build_filename(search_paths[i], file, NULL); | |
| 524 | |
| 525 if (ext == NULL || is_so_file(file, ext)) | |
| 526 plugin = gaim_plugin_probe(path); | |
| 527 | |
| 528 g_free(path); | |
| 529 } | |
| 530 | |
| 531 g_dir_close(dir); | |
| 532 } | |
| 533 } | |
| 534 | |
| 535 if (probe_cb != NULL) | |
| 536 probe_cb(probe_cb_data); | |
| 537 | |
| 538 #endif /* GAIM_PLUGINS */ | |
| 539 } | |
| 540 | |
| 541 gboolean | |
| 542 gaim_plugin_register(GaimPlugin *plugin) | |
| 543 { | |
| 544 #ifdef GAIM_PLUGINS | |
| 545 g_return_val_if_fail(plugin != NULL, FALSE); | |
| 546 | |
| 547 if (g_list_find(plugins, plugin)) | |
| 548 return TRUE; | |
| 549 | |
| 550 /* Special exception for loader plugins. We want them loaded NOW! */ | |
| 551 if (plugin->info->type == GAIM_PLUGIN_LOADER) { | |
| 552 GList *exts; | |
| 553 | |
| 554 /* We'll just load this right now. */ | |
| 555 if (!gaim_plugin_load(plugin)) { | |
| 556 | |
| 557 gaim_plugin_destroy(plugin); | |
| 558 | |
| 559 return FALSE; | |
| 560 } | |
| 561 | |
| 562 plugin_loaders = g_list_append(plugin_loaders, plugin); | |
| 563 | |
| 564 for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
| 565 exts != NULL; | |
| 566 exts = exts->next) { | |
| 567 | |
| 568 gaim_plugins_probe(exts->data); | |
| 569 } | |
| 570 } | |
| 571 else if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
| 572 | |
| 573 /* We'll just load this right now. */ | |
| 574 if (!gaim_plugin_load(plugin)) { | |
| 575 | |
| 576 gaim_plugin_destroy(plugin); | |
| 577 | |
| 578 return FALSE; | |
| 579 } | |
| 580 | |
| 581 if (GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol == GAIM_PROTO_ICQ || | |
| 582 gaim_find_prpl(GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol)) { | |
| 583 | |
| 584 /* Nothing to see here--move along, move along */ | |
| 585 gaim_plugin_destroy(plugin); | |
| 586 | |
| 587 return FALSE; | |
| 588 } | |
| 589 | |
| 590 protocols = g_slist_insert_sorted(protocols, plugin, | |
| 591 (GCompareFunc)compare_prpl); | |
| 592 } | |
| 593 | |
| 594 plugins = g_list_append(plugins, plugin); | |
| 595 | |
| 596 return TRUE; | |
| 597 #else | |
| 598 return FALSE; | |
| 599 #endif /* !GAIM_PLUGINS */ | |
| 600 } | |
| 601 | |
| 602 gboolean | |
| 603 gaim_plugins_enabled(void) | |
| 604 { | |
| 605 #ifdef GAIM_PLUGINS | |
| 606 return TRUE; | |
| 607 #else | |
| 608 return FALSE; | |
| 609 #endif | |
| 610 } | |
| 611 | |
| 612 void | |
| 613 gaim_plugins_register_probe_notify_cb(void (*func)(void *), void *data) | |
| 614 { | |
| 615 /* TODO */ | |
| 616 probe_cb = func; | |
| 617 probe_cb_data = data; | |
| 618 } | |
| 619 | |
| 620 void | |
| 621 gaim_plugins_unregister_probe_notify_cb(void (*func)(void *)) | |
| 622 { | |
| 623 /* TODO */ | |
| 624 probe_cb = NULL; | |
| 625 probe_cb_data = NULL; | |
| 626 } | |
| 627 | |
| 628 void | |
| 629 gaim_plugins_register_load_notify_cb(void (*func)(GaimPlugin *, void *), | |
| 630 void *data) | |
| 631 { | |
| 632 /* TODO */ | |
| 633 load_cb = func; | |
| 634 load_cb_data = data; | |
| 635 } | |
| 636 | |
| 637 void | |
| 638 gaim_plugins_unregister_load_notify_cb(void (*func)(GaimPlugin *, void *)) | |
| 639 { | |
| 640 /* TODO */ | |
| 641 load_cb = NULL; | |
| 642 load_cb_data = NULL; | |
| 643 } | |
| 644 | |
| 645 void | |
| 646 gaim_plugins_register_unload_notify_cb(void (*func)(GaimPlugin *, void *), | |
| 647 void *data) | |
| 648 { | |
| 649 /* TODO */ | |
| 650 unload_cb = func; | |
| 651 unload_cb_data = data; | |
| 652 } | |
| 653 | |
| 654 void | |
| 655 gaim_plugins_unregister_unload_notify_cb(void (*func)(GaimPlugin *, void *)) | |
| 656 { | |
| 657 /* TODO */ | |
| 658 unload_cb = NULL; | |
| 659 unload_cb_data = NULL; | |
| 660 } | |
| 661 | |
| 662 GaimPlugin * | |
| 663 gaim_plugins_find_with_name(const char *name) | |
| 664 { | |
| 665 GaimPlugin *plugin; | |
| 666 GList *l; | |
| 667 | |
| 668 for (l = plugins; l != NULL; l = l->next) { | |
| 669 plugin = l->data; | |
| 670 | |
| 671 if (!strcmp(plugin->info->name, name)) | |
| 672 return plugin; | |
| 673 } | |
| 674 | |
| 675 return NULL; | |
| 676 } | |
| 677 | |
| 678 GaimPlugin * | |
| 679 gaim_plugins_find_with_filename(const char *filename) | |
| 680 { | |
| 681 GaimPlugin *plugin; | |
| 682 GList *l; | |
| 683 | |
| 684 for (l = plugins; l != NULL; l = l->next) { | |
| 685 plugin = l->data; | |
| 686 | |
| 687 if (plugin->path != NULL && !strcmp(plugin->path, filename)) | |
| 688 return plugin; | |
| 689 } | |
| 690 | |
| 691 return NULL; | |
| 692 } | |
| 693 | |
| 694 GaimPlugin * | |
| 695 gaim_plugins_find_with_id(const char *id) | |
| 696 { | |
| 697 GaimPlugin *plugin; | |
| 698 GList *l; | |
| 699 | |
| 700 g_return_val_if_fail(id != NULL, NULL); | |
| 701 | |
| 702 for (l = plugins; l != NULL; l = l->next) { | |
| 703 plugin = l->data; | |
| 704 | |
| 705 if (!strcmp(plugin->info->id, id)) | |
| 706 return plugin; | |
| 707 } | |
| 708 | |
| 709 return NULL; | |
| 710 } | |
| 711 | |
| 712 GList * | |
| 713 gaim_plugins_get_loaded(void) | |
| 714 { | |
| 715 return loaded_plugins; | |
| 716 } | |
| 717 | |
| 718 GList * | |
| 719 gaim_plugins_get_all(void) | |
| 720 { | |
| 721 return plugins; | |
| 722 } | |
| 723 |
