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