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