Tue, 24 Jun 2003 03:50:31 +0000
[gaim-migrate @ 6393]
Saved plugins are now stored in UI-specific keys, which are passed to
gaim_plugins_load_saved(). If you're using CVS (shame on you!) you'll need
to reload your plugins, and if you're careful enough, remove the old
plugins tree from prefs.xml (/core/plugins/loaded/...). I assume no
responsibility if you destroy prefs.xml, delete your harddrive, or sell
your soul to a goat.
| 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 | */ | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
37 | #include "internal.h" |
| 5205 | 38 | |
|
5638
53e752c88ea1
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
39 | #include "accountopt.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
40 | #include "debug.h" |
| 5205 | 41 | #include "event.h" |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5357
diff
changeset
|
42 | #include "notify.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
43 | #include "prefs.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
44 | #include "prpl.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
45 | #include "request.h" |
| 5205 | 46 | |
| 47 | #ifdef _WIN32 | |
| 48 | # define PLUGIN_EXT ".dll" | |
| 49 | #else | |
| 50 | # define PLUGIN_EXT ".so" | |
| 51 | #endif | |
| 52 | ||
| 53 | static GList *loaded_plugins = NULL; | |
| 54 | static GList *plugins = NULL; | |
| 55 | static GList *plugin_loaders = NULL; | |
|
5573
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
56 | static GList *protocol_plugins = NULL; |
| 5205 | 57 | |
| 58 | static size_t search_path_count = 0; | |
| 59 | static char **search_paths = NULL; | |
| 60 | ||
| 61 | static void (*probe_cb)(void *) = NULL; | |
| 62 | static void *probe_cb_data = NULL; | |
| 63 | static void (*load_cb)(GaimPlugin *, void *) = NULL; | |
| 64 | static void *load_cb_data = NULL; | |
| 65 | static void (*unload_cb)(GaimPlugin *, void *) = NULL; | |
| 66 | static void *unload_cb_data = NULL; | |
| 67 | ||
| 68 | #ifdef GAIM_PLUGINS | |
| 69 | static int | |
| 70 | is_so_file(const char *filename, const char *ext) | |
| 71 | { | |
| 72 | int len, extlen; | |
| 73 | ||
| 74 | if (filename == NULL || *filename == '\0' || ext == NULL) | |
| 75 | return 0; | |
| 76 | ||
| 77 | extlen = strlen(ext); | |
| 78 | len = strlen(filename) - extlen; | |
| 79 | ||
| 80 | if (len < 0) | |
| 81 | return 0; | |
| 82 | ||
| 83 | return (!strncmp(filename + len, ext, extlen)); | |
| 84 | } | |
| 85 | ||
| 86 | static gboolean | |
|
5794
ebdbb7dc6658
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5646
diff
changeset
|
87 | loader_supports_file(GaimPlugin *loader, const char *filename) |
| 5205 | 88 | { |
| 89 | GList *l, *exts; | |
| 90 | GaimPlugin *plugin; | |
| 91 | ||
| 92 | for (l = plugin_loaders; l != NULL; l = l->next) { | |
| 93 | plugin = l->data; | |
| 94 | ||
| 95 | for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
| 96 | exts != NULL; | |
| 97 | exts = exts->next) { | |
| 98 | ||
| 99 | if (is_so_file(filename, (char *)exts->data)) | |
| 100 | return TRUE; | |
| 101 | } | |
| 102 | } | |
| 103 | ||
| 104 | return FALSE; | |
| 105 | } | |
| 106 | ||
| 107 | static GaimPlugin * | |
|
5794
ebdbb7dc6658
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5646
diff
changeset
|
108 | find_loader_for_plugin(const GaimPlugin *plugin) |
| 5205 | 109 | { |
| 110 | GaimPlugin *loader; | |
| 111 | GList *l; | |
| 112 | ||
| 113 | if (plugin->path == NULL) | |
| 114 | return NULL; | |
| 115 | ||
| 116 | for (l = gaim_plugins_get_loaded(); l != NULL; l = l->next) { | |
| 117 | loader = l->data; | |
| 118 | ||
| 119 | if (loader->info->type == GAIM_PLUGIN_LOADER && | |
|
5794
ebdbb7dc6658
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5646
diff
changeset
|
120 | loader_supports_file(loader, plugin->path)) { |
| 5205 | 121 | |
| 122 | return loader; | |
| 123 | } | |
| 124 | ||
| 125 | loader = NULL; | |
| 126 | } | |
| 127 | ||
| 128 | return NULL; | |
| 129 | } | |
| 130 | ||
|
5449
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
131 | #endif /* GAIM_PLUGINS */ |
|
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
132 | |
| 5838 | 133 | static void |
| 134 | update_plugin_prefs(void) | |
| 135 | { | |
| 136 | GList *pl; | |
| 137 | GList *files = NULL; | |
| 138 | GaimPlugin *p; | |
| 139 | ||
| 140 | for (pl = gaim_plugins_get_loaded(); pl != NULL; pl = pl->next) { | |
| 141 | p = pl->data; | |
| 142 | ||
| 143 | if(p->info->type != GAIM_PLUGIN_PROTOCOL && | |
| 144 | p->info->type != GAIM_PLUGIN_LOADER) { | |
| 145 | files = g_list_append(files, p->path); | |
| 146 | } | |
| 147 | } | |
| 148 | ||
| 149 | gaim_prefs_set_string_list("/plugins/loaded", files); | |
| 150 | g_list_free(files); | |
| 151 | } | |
| 152 | ||
| 5205 | 153 | static gint |
| 154 | compare_prpl(GaimPlugin *a, GaimPlugin *b) | |
| 155 | { | |
| 156 | /* neg if a before b, 0 if equal, pos if a after b */ | |
| 157 | return ((GAIM_IS_PROTOCOL_PLUGIN(a) | |
| 158 | ? GAIM_PLUGIN_PROTOCOL_INFO(a)->protocol : -1) - | |
| 159 | ((GAIM_IS_PROTOCOL_PLUGIN(b) | |
| 160 | ? GAIM_PLUGIN_PROTOCOL_INFO(b)->protocol : -1))); | |
| 161 | } | |
| 162 | ||
| 163 | GaimPlugin * | |
| 164 | gaim_plugin_new(gboolean native, const char *path) | |
| 165 | { | |
| 166 | GaimPlugin *plugin; | |
| 167 | ||
| 168 | plugin = g_new0(GaimPlugin, 1); | |
| 169 | ||
| 170 | plugin->native_plugin = native; | |
| 171 | plugin->path = (path == NULL ? NULL : g_strdup(path)); | |
| 172 | ||
| 173 | return plugin; | |
| 174 | } | |
| 175 | ||
| 176 | GaimPlugin * | |
| 177 | gaim_plugin_probe(const char *filename) | |
| 178 | { | |
| 179 | #ifdef GAIM_PLUGINS | |
| 180 | GaimPlugin *plugin = NULL; | |
| 181 | GaimPlugin *loader; | |
| 182 | gboolean (*gaim_init_plugin)(GaimPlugin *); | |
| 183 | ||
| 184 | g_return_val_if_fail(filename != NULL, NULL); | |
| 185 | ||
| 186 | plugin = gaim_plugins_find_with_filename(filename); | |
| 187 | ||
| 188 | if (plugin != NULL) | |
| 189 | return plugin; | |
| 190 | ||
| 191 | plugin = gaim_plugin_new(is_so_file(filename, PLUGIN_EXT), filename); | |
| 192 | ||
| 193 | if (plugin->native_plugin) { | |
| 5450 | 194 | const char *error; |
| 5205 | 195 | plugin->handle = g_module_open(filename, 0); |
| 196 | ||
| 197 | if (plugin->handle == NULL) { | |
| 5443 | 198 | error = g_module_error(); |
|
5269
a318feccd844
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
199 | gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", |
| 5443 | 200 | plugin->path, error ? error : "Unknown error."); |
| 5205 | 201 | |
|
5269
a318feccd844
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
202 | gaim_plugin_destroy(plugin); |
|
a318feccd844
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
203 | |
|
a318feccd844
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
204 | return NULL; |
| 5205 | 205 | } |
| 206 | ||
| 207 | if (!g_module_symbol(plugin->handle, "gaim_init_plugin", | |
| 208 | (gpointer *)&gaim_init_plugin)) { | |
| 209 | g_module_close(plugin->handle); | |
| 210 | plugin->handle = NULL; | |
| 211 | ||
| 5443 | 212 | error = g_module_error(); |
|
5211
94d9756c381f
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
213 | gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", |
| 5443 | 214 | plugin->path, error ? error : "Unknown error."); |
| 5205 | 215 | |
| 216 | gaim_plugin_destroy(plugin); | |
| 217 | ||
| 218 | return NULL; | |
| 219 | } | |
| 220 | } | |
| 221 | else { | |
|
5794
ebdbb7dc6658
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5646
diff
changeset
|
222 | loader = find_loader_for_plugin(plugin); |
| 5205 | 223 | |
| 224 | if (loader == NULL) { | |
| 225 | gaim_plugin_destroy(plugin); | |
| 226 | ||
| 227 | return NULL; | |
| 228 | } | |
| 229 | ||
| 230 | gaim_init_plugin = GAIM_PLUGIN_LOADER_INFO(loader)->probe; | |
| 231 | } | |
| 232 | ||
| 233 | plugin->error = NULL; | |
| 234 | ||
| 235 | if (!gaim_init_plugin(plugin) || plugin->info == NULL) { | |
| 236 | char buf[BUFSIZ]; | |
| 237 | ||
| 238 | g_snprintf(buf, sizeof(buf), | |
| 239 | _("The plugin %s did not return any valid plugin " | |
| 240 | "information"), | |
| 241 | plugin->path); | |
| 242 | ||
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5357
diff
changeset
|
243 | gaim_notify_error(NULL, NULL, |
|
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5357
diff
changeset
|
244 | _("Gaim was unable to load your plugin."), buf); |
| 5205 | 245 | |
| 246 | gaim_plugin_destroy(plugin); | |
| 247 | ||
| 248 | return NULL; | |
| 249 | } | |
| 250 | ||
| 251 | return plugin; | |
| 252 | #else | |
| 253 | return NULL; | |
| 254 | #endif /* !GAIM_PLUGINS */ | |
| 255 | } | |
| 256 | ||
| 257 | gboolean | |
| 258 | gaim_plugin_load(GaimPlugin *plugin) | |
| 259 | { | |
| 260 | #ifdef GAIM_PLUGINS | |
| 261 | g_return_val_if_fail(plugin != NULL, FALSE); | |
|
5270
74286f7fb991
[gaim-migrate @ 5642]
Christian Hammond <chipx86@chipx86.com>
parents:
5269
diff
changeset
|
262 | g_return_val_if_fail(plugin->error == NULL, FALSE); |
| 5205 | 263 | |
| 264 | if (gaim_plugin_is_loaded(plugin)) | |
| 265 | return TRUE; | |
| 266 | ||
| 267 | if (plugin->native_plugin) { | |
|
5357
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
268 | if (plugin->info != NULL) { |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
269 | if (plugin->info->load != NULL) |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
270 | plugin->info->load(plugin); |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
271 | |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
272 | if (plugin->info->type == GAIM_PLUGIN_LOADER) { |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
273 | GaimPluginLoaderInfo *loader_info; |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
274 | |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
275 | loader_info = GAIM_PLUGIN_LOADER_INFO(plugin); |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
276 | |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
277 | if (loader_info->broadcast != NULL) |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
278 | gaim_signals_register_broadcast_func(loader_info->broadcast, |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
279 | NULL); |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
280 | } |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
281 | } |
| 5205 | 282 | } |
| 283 | else { | |
| 284 | GaimPlugin *loader; | |
| 285 | GaimPluginLoaderInfo *loader_info; | |
| 286 | ||
|
5794
ebdbb7dc6658
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5646
diff
changeset
|
287 | loader = find_loader_for_plugin(plugin); |
| 5205 | 288 | |
| 289 | if (loader == NULL) | |
| 290 | return FALSE; | |
| 291 | ||
| 292 | loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
| 293 | ||
| 294 | if (loader_info->load != NULL) | |
| 295 | loader_info->load(plugin); | |
| 296 | } | |
| 297 | ||
| 298 | loaded_plugins = g_list_append(loaded_plugins, plugin); | |
| 5838 | 299 | update_plugin_prefs(); |
| 5205 | 300 | |
| 301 | plugin->loaded = TRUE; | |
| 302 | ||
| 303 | /* TODO */ | |
| 304 | if (load_cb != NULL) | |
| 305 | load_cb(plugin, load_cb_data); | |
| 306 | ||
| 307 | return TRUE; | |
| 308 | ||
| 309 | #else | |
|
5449
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
310 | return TRUE; |
| 5205 | 311 | #endif /* !GAIM_PLUGINS */ |
| 312 | } | |
| 313 | ||
| 314 | gboolean | |
| 315 | gaim_plugin_unload(GaimPlugin *plugin) | |
| 316 | { | |
| 317 | #ifdef GAIM_PLUGINS | |
| 318 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 319 | ||
| 320 | loaded_plugins = g_list_remove(loaded_plugins, plugin); | |
| 5838 | 321 | update_plugin_prefs(); |
| 5205 | 322 | |
| 323 | g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
| 324 | ||
|
5211
94d9756c381f
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
325 | gaim_debug(GAIM_DEBUG_INFO, "plugins", "Unloading plugin %s\n", |
|
94d9756c381f
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
326 | plugin->info->name); |
| 5205 | 327 | |
| 328 | /* cancel any pending dialogs the plugin has */ | |
|
5498
01eec144d71b
[gaim-migrate @ 5894]
Christian Hammond <chipx86@chipx86.com>
parents:
5450
diff
changeset
|
329 | gaim_request_close_with_handle(plugin); |
|
01eec144d71b
[gaim-migrate @ 5894]
Christian Hammond <chipx86@chipx86.com>
parents:
5450
diff
changeset
|
330 | gaim_notify_close_with_handle(plugin); |
| 5205 | 331 | |
| 332 | plugin->loaded = FALSE; | |
| 333 | ||
| 334 | if (plugin->native_plugin) { | |
| 335 | if (plugin->info->unload != NULL) | |
| 336 | plugin->info->unload(plugin); | |
| 337 | ||
| 338 | if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
| 339 | GaimPluginProtocolInfo *prpl_info; | |
| 340 | GList *l; | |
| 341 | ||
| 342 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
| 343 | ||
|
5638
53e752c88ea1
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
344 | for (l = prpl_info->user_splits; l != NULL; l = l->next) |
|
53e752c88ea1
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
345 | gaim_account_user_split_destroy(l->data); |
| 5205 | 346 | |
|
5638
53e752c88ea1
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
347 | for (l = prpl_info->protocol_options; l != NULL; l = l->next) |
|
53e752c88ea1
[gaim-migrate @ 6047]
Christian Hammond <chipx86@chipx86.com>
parents:
5573
diff
changeset
|
348 | gaim_account_option_destroy(l->data); |
| 5205 | 349 | |
|
5646
0aa637549d87
[gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents:
5638
diff
changeset
|
350 | if (prpl_info->user_splits != NULL) |
|
0aa637549d87
[gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents:
5638
diff
changeset
|
351 | g_list_free(prpl_info->user_splits); |
|
0aa637549d87
[gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents:
5638
diff
changeset
|
352 | |
|
0aa637549d87
[gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents:
5638
diff
changeset
|
353 | if (prpl_info->protocol_options != NULL) |
|
0aa637549d87
[gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents:
5638
diff
changeset
|
354 | g_list_free(prpl_info->protocol_options); |
| 5205 | 355 | } |
|
5357
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
356 | else if (plugin->info->type == GAIM_PLUGIN_LOADER) { |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
357 | GaimPluginLoaderInfo *loader_info; |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
358 | |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
359 | loader_info = GAIM_PLUGIN_LOADER_INFO(plugin); |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
360 | |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
361 | if (loader_info->broadcast != NULL) |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
362 | gaim_signals_unregister_broadcast_func(loader_info->broadcast); |
|
1fa9e57df50c
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
363 | } |
| 5205 | 364 | } |
| 365 | else { | |
| 366 | GaimPlugin *loader; | |
| 367 | GaimPluginLoaderInfo *loader_info; | |
| 368 | ||
|
5794
ebdbb7dc6658
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5646
diff
changeset
|
369 | loader = find_loader_for_plugin(plugin); |
| 5205 | 370 | |
| 371 | if (loader == NULL) | |
| 372 | return FALSE; | |
| 373 | ||
| 374 | loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
| 375 | ||
| 376 | if (loader_info->load != NULL) | |
| 377 | loader_info->unload(plugin); | |
| 378 | } | |
| 379 | ||
| 380 | gaim_signals_disconnect_by_handle(plugin); | |
| 381 | ||
| 382 | /* TODO */ | |
| 383 | if (unload_cb != NULL) | |
| 384 | unload_cb(plugin, unload_cb_data); | |
| 385 | ||
| 386 | return TRUE; | |
|
5449
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
387 | #else |
|
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
388 | return TRUE; |
| 5205 | 389 | #endif /* GAIM_PLUGINS */ |
| 390 | } | |
| 391 | ||
| 392 | gboolean | |
| 393 | gaim_plugin_reload(GaimPlugin *plugin) | |
| 394 | { | |
| 395 | #ifdef GAIM_PLUGINS | |
| 396 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 397 | g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
| 398 | ||
| 399 | if (!gaim_plugin_unload(plugin)) | |
| 400 | return FALSE; | |
| 401 | ||
| 402 | if (!gaim_plugin_load(plugin)) | |
| 403 | return FALSE; | |
| 404 | ||
| 405 | return TRUE; | |
| 406 | #else | |
|
5449
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
407 | return TRUE; |
| 5205 | 408 | #endif /* !GAIM_PLUGINS */ |
| 409 | } | |
| 410 | ||
| 411 | void | |
| 412 | gaim_plugin_destroy(GaimPlugin *plugin) | |
| 413 | { | |
|
5449
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
414 | #ifdef GAIM_PLUGINS |
| 5205 | 415 | g_return_if_fail(plugin != NULL); |
| 416 | ||
| 417 | if (gaim_plugin_is_loaded(plugin)) | |
| 418 | gaim_plugin_unload(plugin); | |
| 419 | ||
| 420 | plugins = g_list_remove(plugins, plugin); | |
| 421 | ||
|
5243
e8d35a430c6d
[gaim-migrate @ 5614]
Christian Hammond <chipx86@chipx86.com>
parents:
5242
diff
changeset
|
422 | if (plugin->info != NULL && plugin->info->dependencies != NULL) |
|
e8d35a430c6d
[gaim-migrate @ 5614]
Christian Hammond <chipx86@chipx86.com>
parents:
5242
diff
changeset
|
423 | g_list_free(plugin->info->dependencies); |
| 5205 | 424 | |
| 425 | if (plugin->native_plugin) { | |
| 426 | ||
| 427 | if (plugin->info != NULL && plugin->info->type == GAIM_PLUGIN_LOADER) { | |
| 428 | GList *exts, *l, *next_l; | |
| 429 | GaimPlugin *p2; | |
| 430 | ||
| 431 | for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
| 432 | exts != NULL; | |
| 433 | exts = exts->next) { | |
| 434 | ||
| 435 | for (l = gaim_plugins_get_all(); l != NULL; l = next_l) { | |
| 436 | next_l = l->next; | |
| 437 | ||
| 438 | p2 = l->data; | |
| 439 | ||
| 440 | if (p2->path != NULL && is_so_file(p2->path, exts->data)) | |
| 441 | gaim_plugin_destroy(p2); | |
| 442 | } | |
| 443 | } | |
| 444 | ||
| 445 | g_list_free(GAIM_PLUGIN_LOADER_INFO(plugin)->exts); | |
| 446 | ||
| 447 | plugin_loaders = g_list_remove(plugin_loaders, plugin); | |
| 448 | } | |
| 449 | ||
| 450 | if (plugin->info != NULL && plugin->info->destroy != NULL) | |
| 451 | plugin->info->destroy(plugin); | |
| 452 | ||
| 453 | if (plugin->handle != NULL) | |
| 454 | g_module_close(plugin->handle); | |
| 455 | } | |
| 456 | else { | |
| 457 | GaimPlugin *loader; | |
| 458 | GaimPluginLoaderInfo *loader_info; | |
| 459 | ||
|
5794
ebdbb7dc6658
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5646
diff
changeset
|
460 | loader = find_loader_for_plugin(plugin); |
| 5205 | 461 | |
|
5941
46e136a842b8
[gaim-migrate @ 6381]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
462 | if (loader != NULL) { |
|
46e136a842b8
[gaim-migrate @ 6381]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
463 | loader_info = GAIM_PLUGIN_LOADER_INFO(loader); |
| 5205 | 464 | |
|
5941
46e136a842b8
[gaim-migrate @ 6381]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
465 | if (loader_info->destroy != NULL) |
|
46e136a842b8
[gaim-migrate @ 6381]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
466 | loader_info->destroy(plugin); |
|
46e136a842b8
[gaim-migrate @ 6381]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
467 | } |
| 5205 | 468 | } |
| 469 | ||
| 470 | if (plugin->path != NULL) g_free(plugin->path); | |
| 471 | if (plugin->error != NULL) g_free(plugin->error); | |
| 472 | ||
| 473 | g_free(plugin); | |
|
5449
4c350eb7d4a0
[gaim-migrate @ 5836]
Decklin Foster <decklin@red-bean.com>
parents:
5443
diff
changeset
|
474 | #endif /* !GAIM_PLUGINS */ |
| 5205 | 475 | } |
| 476 | ||
| 477 | gboolean | |
| 478 | gaim_plugin_is_loaded(const GaimPlugin *plugin) | |
| 479 | { | |
| 480 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 481 | ||
| 482 | return plugin->loaded; | |
| 483 | } | |
| 484 | ||
| 485 | void | |
| 486 | gaim_plugins_set_search_paths(size_t count, char **paths) | |
| 487 | { | |
| 488 | size_t s; | |
| 489 | ||
| 490 | g_return_if_fail(count > 0); | |
| 491 | g_return_if_fail(paths != NULL); | |
| 492 | ||
| 493 | if (search_paths != NULL) { | |
| 494 | for (s = 0; s < search_path_count; s++) | |
| 495 | g_free(search_paths[s]); | |
| 496 | ||
| 497 | g_free(search_paths); | |
| 498 | } | |
| 499 | ||
| 500 | search_paths = g_new0(char *, count); | |
| 501 | ||
| 502 | for (s = 0; s < count; s++) { | |
| 503 | if (paths[s] == NULL) | |
| 504 | search_paths[s] = NULL; | |
| 505 | else | |
| 506 | search_paths[s] = g_strdup(paths[s]); | |
| 507 | } | |
| 508 | ||
| 509 | search_path_count = count; | |
| 510 | } | |
| 511 | ||
| 512 | void | |
| 513 | gaim_plugins_unload_all(void) | |
| 514 | { | |
| 515 | #ifdef GAIM_PLUGINS | |
| 516 | ||
| 517 | while (loaded_plugins != NULL) | |
| 518 | gaim_plugin_unload(loaded_plugins->data); | |
| 519 | ||
| 520 | #endif /* GAIM_PLUGINS */ | |
| 521 | } | |
| 522 | ||
| 523 | void | |
|
5242
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
524 | gaim_plugins_destroy_all(void) |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
525 | { |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
526 | #ifdef GAIM_PLUGINS |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
527 | |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
528 | while (plugins != NULL) |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
529 | gaim_plugin_destroy(plugins->data); |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
530 | |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
531 | #endif /* GAIM_PLUGINS */ |
|
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
532 | } |
| 5838 | 533 | |
| 534 | void | |
|
5949
bb7cbf02dda9
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5941
diff
changeset
|
535 | gaim_plugins_load_saved(const char *key) |
| 5838 | 536 | { |
| 537 | #ifdef GAIM_PLUGINS | |
|
5949
bb7cbf02dda9
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5941
diff
changeset
|
538 | GList *f, *files; |
|
bb7cbf02dda9
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5941
diff
changeset
|
539 | |
|
bb7cbf02dda9
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5941
diff
changeset
|
540 | g_return_if_fail(key != NULL); |
| 5838 | 541 | |
|
5949
bb7cbf02dda9
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5941
diff
changeset
|
542 | files = gaim_prefs_get_string_list(key); |
|
bb7cbf02dda9
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5941
diff
changeset
|
543 | |
|
bb7cbf02dda9
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5941
diff
changeset
|
544 | for (f = files; f; f = f->next) { |
| 5838 | 545 | gaim_plugin_load(gaim_plugin_probe(f->data)); |
| 546 | g_free(f->data); | |
| 547 | } | |
| 548 | ||
| 549 | g_list_free(files); | |
| 550 | #endif /* GAIM_PLUGINS */ | |
| 551 | } | |
| 552 | ||
| 553 | ||
|
5242
155da5e9bbf0
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
554 | void |
| 5205 | 555 | gaim_plugins_probe(const char *ext) |
| 556 | { | |
| 557 | #ifdef GAIM_PLUGINS | |
| 558 | GDir *dir; | |
| 559 | const gchar *file; | |
| 560 | gchar *path; | |
| 561 | GaimPlugin *plugin; | |
| 562 | size_t i; | |
| 563 | ||
| 564 | if (!g_module_supported()) | |
| 565 | return; | |
| 566 | ||
| 567 | for (i = 0; i < search_path_count; i++) { | |
| 568 | if (search_paths[i] == NULL) | |
| 569 | continue; | |
| 570 | ||
| 571 | dir = g_dir_open(search_paths[i], 0, NULL); | |
| 572 | ||
| 573 | if (dir != NULL) { | |
| 574 | while ((file = g_dir_read_name(dir)) != NULL) { | |
| 575 | path = g_build_filename(search_paths[i], file, NULL); | |
| 576 | ||
| 577 | if (ext == NULL || is_so_file(file, ext)) | |
| 578 | plugin = gaim_plugin_probe(path); | |
| 579 | ||
| 580 | g_free(path); | |
| 581 | } | |
| 582 | ||
| 583 | g_dir_close(dir); | |
| 584 | } | |
| 585 | } | |
| 586 | ||
| 587 | if (probe_cb != NULL) | |
| 588 | probe_cb(probe_cb_data); | |
| 589 | ||
| 590 | #endif /* GAIM_PLUGINS */ | |
| 591 | } | |
| 592 | ||
| 593 | gboolean | |
| 594 | gaim_plugin_register(GaimPlugin *plugin) | |
| 595 | { | |
| 596 | g_return_val_if_fail(plugin != NULL, FALSE); | |
| 597 | ||
| 598 | if (g_list_find(plugins, plugin)) | |
| 599 | return TRUE; | |
| 600 | ||
| 601 | /* Special exception for loader plugins. We want them loaded NOW! */ | |
| 602 | if (plugin->info->type == GAIM_PLUGIN_LOADER) { | |
| 603 | GList *exts; | |
| 604 | ||
| 605 | /* We'll just load this right now. */ | |
| 606 | if (!gaim_plugin_load(plugin)) { | |
| 607 | ||
| 608 | gaim_plugin_destroy(plugin); | |
| 609 | ||
| 610 | return FALSE; | |
| 611 | } | |
| 612 | ||
| 613 | plugin_loaders = g_list_append(plugin_loaders, plugin); | |
| 614 | ||
| 615 | for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
| 616 | exts != NULL; | |
| 617 | exts = exts->next) { | |
| 618 | ||
| 619 | gaim_plugins_probe(exts->data); | |
| 620 | } | |
| 621 | } | |
| 622 | else if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
| 623 | ||
| 624 | /* We'll just load this right now. */ | |
| 625 | if (!gaim_plugin_load(plugin)) { | |
| 626 | ||
| 627 | gaim_plugin_destroy(plugin); | |
| 628 | ||
| 629 | return FALSE; | |
| 630 | } | |
| 631 | ||
| 632 | if (GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol == GAIM_PROTO_ICQ || | |
| 633 | gaim_find_prpl(GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol)) { | |
| 634 | ||
| 635 | /* Nothing to see here--move along, move along */ | |
| 636 | gaim_plugin_destroy(plugin); | |
| 637 | ||
| 638 | return FALSE; | |
| 639 | } | |
| 640 | ||
|
5573
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
641 | protocol_plugins = g_list_insert_sorted(protocol_plugins, plugin, |
|
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
642 | (GCompareFunc)compare_prpl); |
| 5205 | 643 | } |
| 644 | ||
| 645 | plugins = g_list_append(plugins, plugin); | |
| 646 | ||
| 647 | return TRUE; | |
| 648 | } | |
| 649 | ||
| 650 | gboolean | |
| 651 | gaim_plugins_enabled(void) | |
| 652 | { | |
| 653 | #ifdef GAIM_PLUGINS | |
| 654 | return TRUE; | |
| 655 | #else | |
| 656 | return FALSE; | |
| 657 | #endif | |
| 658 | } | |
| 659 | ||
| 660 | void | |
| 661 | gaim_plugins_register_probe_notify_cb(void (*func)(void *), void *data) | |
| 662 | { | |
| 663 | /* TODO */ | |
| 664 | probe_cb = func; | |
| 665 | probe_cb_data = data; | |
| 666 | } | |
| 667 | ||
| 668 | void | |
| 669 | gaim_plugins_unregister_probe_notify_cb(void (*func)(void *)) | |
| 670 | { | |
| 671 | /* TODO */ | |
| 672 | probe_cb = NULL; | |
| 673 | probe_cb_data = NULL; | |
| 674 | } | |
| 675 | ||
| 676 | void | |
| 677 | gaim_plugins_register_load_notify_cb(void (*func)(GaimPlugin *, void *), | |
| 678 | void *data) | |
| 679 | { | |
| 680 | /* TODO */ | |
| 681 | load_cb = func; | |
| 682 | load_cb_data = data; | |
| 683 | } | |
| 684 | ||
| 685 | void | |
| 686 | gaim_plugins_unregister_load_notify_cb(void (*func)(GaimPlugin *, void *)) | |
| 687 | { | |
| 688 | /* TODO */ | |
| 689 | load_cb = NULL; | |
| 690 | load_cb_data = NULL; | |
| 691 | } | |
| 692 | ||
| 693 | void | |
| 694 | gaim_plugins_register_unload_notify_cb(void (*func)(GaimPlugin *, void *), | |
| 695 | void *data) | |
| 696 | { | |
| 697 | /* TODO */ | |
| 698 | unload_cb = func; | |
| 699 | unload_cb_data = data; | |
| 700 | } | |
| 701 | ||
| 702 | void | |
| 703 | gaim_plugins_unregister_unload_notify_cb(void (*func)(GaimPlugin *, void *)) | |
| 704 | { | |
| 705 | /* TODO */ | |
| 706 | unload_cb = NULL; | |
| 707 | unload_cb_data = NULL; | |
| 708 | } | |
| 709 | ||
| 710 | GaimPlugin * | |
| 711 | gaim_plugins_find_with_name(const char *name) | |
| 712 | { | |
| 713 | GaimPlugin *plugin; | |
| 714 | GList *l; | |
| 715 | ||
| 716 | for (l = plugins; l != NULL; l = l->next) { | |
| 717 | plugin = l->data; | |
| 718 | ||
| 719 | if (!strcmp(plugin->info->name, name)) | |
| 720 | return plugin; | |
| 721 | } | |
| 722 | ||
| 723 | return NULL; | |
| 724 | } | |
| 725 | ||
| 726 | GaimPlugin * | |
| 727 | gaim_plugins_find_with_filename(const char *filename) | |
| 728 | { | |
| 729 | GaimPlugin *plugin; | |
| 730 | GList *l; | |
| 731 | ||
| 732 | for (l = plugins; l != NULL; l = l->next) { | |
| 733 | plugin = l->data; | |
| 734 | ||
| 735 | if (plugin->path != NULL && !strcmp(plugin->path, filename)) | |
| 736 | return plugin; | |
| 737 | } | |
| 738 | ||
| 739 | return NULL; | |
| 740 | } | |
| 741 | ||
| 742 | GaimPlugin * | |
| 743 | gaim_plugins_find_with_id(const char *id) | |
| 744 | { | |
| 745 | GaimPlugin *plugin; | |
| 746 | GList *l; | |
| 747 | ||
| 748 | g_return_val_if_fail(id != NULL, NULL); | |
| 749 | ||
| 750 | for (l = plugins; l != NULL; l = l->next) { | |
| 751 | plugin = l->data; | |
| 752 | ||
| 753 | if (!strcmp(plugin->info->id, id)) | |
| 754 | return plugin; | |
| 755 | } | |
| 756 | ||
| 757 | return NULL; | |
| 758 | } | |
| 759 | ||
| 760 | GList * | |
| 761 | gaim_plugins_get_loaded(void) | |
| 762 | { | |
| 763 | return loaded_plugins; | |
| 764 | } | |
| 765 | ||
| 766 | GList * | |
|
5573
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
767 | gaim_plugins_get_protocols(void) |
|
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
768 | { |
|
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
769 | return protocol_plugins; |
|
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
770 | } |
|
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
771 | |
|
633880e3f137
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5498
diff
changeset
|
772 | GList * |
| 5205 | 773 | gaim_plugins_get_all(void) |
| 774 | { | |
| 775 | return plugins; | |
| 776 | } | |
| 777 |