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