Mercurial > pidgin.yaz
annotate src/plugin.c @ 5468:809ef68273c8
[gaim-migrate @ 5860]
Perl plugin loader added
committer: Tailor Script <tailor@pidgin.im>
author | Herman Bloggs <hermanator12002@yahoo.com> |
---|---|
date | Wed, 21 May 2003 15:54:22 +0000 |
parents | bb1e160467b6 |
children | cce2d7868c78 |
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 | |
5449 | 143 #endif /* GAIM_PLUGINS */ |
144 | |
5205 | 145 static gint |
146 compare_prpl(GaimPlugin *a, GaimPlugin *b) | |
147 { | |
148 /* neg if a before b, 0 if equal, pos if a after b */ | |
149 return ((GAIM_IS_PROTOCOL_PLUGIN(a) | |
150 ? GAIM_PLUGIN_PROTOCOL_INFO(a)->protocol : -1) - | |
151 ((GAIM_IS_PROTOCOL_PLUGIN(b) | |
152 ? GAIM_PLUGIN_PROTOCOL_INFO(b)->protocol : -1))); | |
153 } | |
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) { | |
5450 | 186 const char *error; |
5205 | 187 plugin->handle = g_module_open(filename, 0); |
188 | |
189 if (plugin->handle == NULL) { | |
5443 | 190 error = g_module_error(); |
5269
cd7e4ba049f9
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
191 gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", |
5443 | 192 plugin->path, error ? error : "Unknown error."); |
5205 | 193 |
5269
cd7e4ba049f9
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
194 gaim_plugin_destroy(plugin); |
cd7e4ba049f9
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
195 |
cd7e4ba049f9
[gaim-migrate @ 5641]
Christian Hammond <chipx86@chipx86.com>
parents:
5268
diff
changeset
|
196 return NULL; |
5205 | 197 } |
198 | |
199 if (!g_module_symbol(plugin->handle, "gaim_init_plugin", | |
200 (gpointer *)&gaim_init_plugin)) { | |
201 g_module_close(plugin->handle); | |
202 plugin->handle = NULL; | |
203 | |
5443 | 204 error = g_module_error(); |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
205 gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", |
5443 | 206 plugin->path, error ? error : "Unknown error."); |
5205 | 207 |
208 gaim_plugin_destroy(plugin); | |
209 | |
210 return NULL; | |
211 } | |
212 } | |
213 else { | |
214 loader = __find_loader_for_plugin(plugin); | |
215 | |
216 if (loader == NULL) { | |
217 gaim_plugin_destroy(plugin); | |
218 | |
219 return NULL; | |
220 } | |
221 | |
222 gaim_init_plugin = GAIM_PLUGIN_LOADER_INFO(loader)->probe; | |
223 } | |
224 | |
225 plugin->error = NULL; | |
226 | |
227 if (!gaim_init_plugin(plugin) || plugin->info == NULL) { | |
228 char buf[BUFSIZ]; | |
229 | |
230 g_snprintf(buf, sizeof(buf), | |
231 _("The plugin %s did not return any valid plugin " | |
232 "information"), | |
233 plugin->path); | |
234 | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5357
diff
changeset
|
235 gaim_notify_error(NULL, NULL, |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5357
diff
changeset
|
236 _("Gaim was unable to load your plugin."), buf); |
5205 | 237 |
238 gaim_plugin_destroy(plugin); | |
239 | |
240 return NULL; | |
241 } | |
242 | |
243 return plugin; | |
244 #else | |
245 return NULL; | |
246 #endif /* !GAIM_PLUGINS */ | |
247 } | |
248 | |
249 gboolean | |
250 gaim_plugin_load(GaimPlugin *plugin) | |
251 { | |
252 #ifdef GAIM_PLUGINS | |
253 g_return_val_if_fail(plugin != NULL, FALSE); | |
5270
d1fe8e320dab
[gaim-migrate @ 5642]
Christian Hammond <chipx86@chipx86.com>
parents:
5269
diff
changeset
|
254 g_return_val_if_fail(plugin->error == NULL, FALSE); |
5205 | 255 |
256 if (gaim_plugin_is_loaded(plugin)) | |
257 return TRUE; | |
258 | |
259 if (plugin->native_plugin) { | |
5357
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
260 if (plugin->info != NULL) { |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
261 if (plugin->info->load != NULL) |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
262 plugin->info->load(plugin); |
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 if (plugin->info->type == GAIM_PLUGIN_LOADER) { |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
265 GaimPluginLoaderInfo *loader_info; |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
266 |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
267 loader_info = GAIM_PLUGIN_LOADER_INFO(plugin); |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
268 |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
269 if (loader_info->broadcast != NULL) |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
270 gaim_signals_register_broadcast_func(loader_info->broadcast, |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
271 NULL); |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
272 } |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
273 } |
5205 | 274 } |
275 else { | |
276 GaimPlugin *loader; | |
277 GaimPluginLoaderInfo *loader_info; | |
278 | |
279 loader = __find_loader_for_plugin(plugin); | |
280 | |
281 if (loader == NULL) | |
282 return FALSE; | |
283 | |
284 loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
285 | |
286 if (loader_info->load != NULL) | |
287 loader_info->load(plugin); | |
288 } | |
289 | |
290 loaded_plugins = g_list_append(loaded_plugins, plugin); | |
291 | |
292 plugin->loaded = TRUE; | |
293 | |
294 /* TODO */ | |
295 if (load_cb != NULL) | |
296 load_cb(plugin, load_cb_data); | |
297 | |
298 return TRUE; | |
299 | |
300 #else | |
5449 | 301 return TRUE; |
5205 | 302 #endif /* !GAIM_PLUGINS */ |
303 } | |
304 | |
305 gboolean | |
306 gaim_plugin_unload(GaimPlugin *plugin) | |
307 { | |
308 #ifdef GAIM_PLUGINS | |
309 g_return_val_if_fail(plugin != NULL, FALSE); | |
310 | |
311 loaded_plugins = g_list_remove(loaded_plugins, plugin); | |
312 | |
313 g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
314 | |
5211
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
315 gaim_debug(GAIM_DEBUG_INFO, "plugins", "Unloading plugin %s\n", |
0241d6b6702d
[gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
316 plugin->info->name); |
5205 | 317 |
318 /* cancel any pending dialogs the plugin has */ | |
319 do_ask_cancel_by_handle(plugin); | |
320 | |
321 plugin->loaded = FALSE; | |
322 | |
323 if (plugin->native_plugin) { | |
324 if (plugin->info->unload != NULL) | |
325 plugin->info->unload(plugin); | |
326 | |
327 if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
328 GaimPluginProtocolInfo *prpl_info; | |
329 GList *l; | |
330 struct proto_user_split *pus; | |
331 struct proto_user_opt *puo; | |
332 | |
333 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin); | |
334 | |
335 for (l = prpl_info->user_splits; l != NULL; l = l->next) { | |
336 pus = l->data; | |
337 | |
338 g_free(pus->label); | |
339 g_free(pus->def); | |
340 g_free(pus); | |
341 } | |
342 | |
343 g_list_free(prpl_info->user_splits); | |
344 | |
345 for (l = prpl_info->user_opts; l != NULL; l = l->next) { | |
346 puo = l->data; | |
347 | |
348 g_free(puo->label); | |
349 g_free(puo->def); | |
350 g_free(puo); | |
351 } | |
352 | |
353 g_list_free(prpl_info->user_opts); | |
354 } | |
5357
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
355 else if (plugin->info->type == GAIM_PLUGIN_LOADER) { |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
356 GaimPluginLoaderInfo *loader_info; |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
357 |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
358 loader_info = GAIM_PLUGIN_LOADER_INFO(plugin); |
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 if (loader_info->broadcast != NULL) |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
361 gaim_signals_unregister_broadcast_func(loader_info->broadcast); |
2a1c92df7024
[gaim-migrate @ 5733]
Christian Hammond <chipx86@chipx86.com>
parents:
5270
diff
changeset
|
362 } |
5205 | 363 } |
364 else { | |
365 GaimPlugin *loader; | |
366 GaimPluginLoaderInfo *loader_info; | |
367 | |
368 loader = __find_loader_for_plugin(plugin); | |
369 | |
370 if (loader == NULL) | |
371 return FALSE; | |
372 | |
373 loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
374 | |
375 if (loader_info->load != NULL) | |
376 loader_info->unload(plugin); | |
377 } | |
378 | |
379 gaim_signals_disconnect_by_handle(plugin); | |
380 | |
381 /* TODO */ | |
382 if (unload_cb != NULL) | |
383 unload_cb(plugin, unload_cb_data); | |
384 | |
385 return TRUE; | |
5449 | 386 #else |
387 return TRUE; | |
5205 | 388 #endif /* GAIM_PLUGINS */ |
389 } | |
390 | |
391 gboolean | |
392 gaim_plugin_reload(GaimPlugin *plugin) | |
393 { | |
394 #ifdef GAIM_PLUGINS | |
395 g_return_val_if_fail(plugin != NULL, FALSE); | |
396 g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); | |
397 | |
398 if (!gaim_plugin_unload(plugin)) | |
399 return FALSE; | |
400 | |
401 if (!gaim_plugin_load(plugin)) | |
402 return FALSE; | |
403 | |
404 return TRUE; | |
405 #else | |
5449 | 406 return TRUE; |
5205 | 407 #endif /* !GAIM_PLUGINS */ |
408 } | |
409 | |
410 void | |
411 gaim_plugin_destroy(GaimPlugin *plugin) | |
412 { | |
5449 | 413 #ifdef GAIM_PLUGINS |
5205 | 414 g_return_if_fail(plugin != NULL); |
415 | |
416 if (gaim_plugin_is_loaded(plugin)) | |
417 gaim_plugin_unload(plugin); | |
418 | |
419 plugins = g_list_remove(plugins, plugin); | |
420 | |
5243
f6e0c689a88b
[gaim-migrate @ 5614]
Christian Hammond <chipx86@chipx86.com>
parents:
5242
diff
changeset
|
421 if (plugin->info != NULL && plugin->info->dependencies != NULL) |
f6e0c689a88b
[gaim-migrate @ 5614]
Christian Hammond <chipx86@chipx86.com>
parents:
5242
diff
changeset
|
422 g_list_free(plugin->info->dependencies); |
5205 | 423 |
424 if (plugin->native_plugin) { | |
425 | |
426 if (plugin->info != NULL && plugin->info->type == GAIM_PLUGIN_LOADER) { | |
427 GList *exts, *l, *next_l; | |
428 GaimPlugin *p2; | |
429 | |
430 for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
431 exts != NULL; | |
432 exts = exts->next) { | |
433 | |
434 for (l = gaim_plugins_get_all(); l != NULL; l = next_l) { | |
435 next_l = l->next; | |
436 | |
437 p2 = l->data; | |
438 | |
439 if (p2->path != NULL && is_so_file(p2->path, exts->data)) | |
440 gaim_plugin_destroy(p2); | |
441 } | |
442 } | |
443 | |
444 g_list_free(GAIM_PLUGIN_LOADER_INFO(plugin)->exts); | |
445 | |
446 plugin_loaders = g_list_remove(plugin_loaders, plugin); | |
447 } | |
448 | |
449 if (plugin->info != NULL && plugin->info->destroy != NULL) | |
450 plugin->info->destroy(plugin); | |
451 | |
452 if (plugin->handle != NULL) | |
453 g_module_close(plugin->handle); | |
454 } | |
455 else { | |
456 GaimPlugin *loader; | |
457 GaimPluginLoaderInfo *loader_info; | |
458 | |
459 loader = __find_loader_for_plugin(plugin); | |
460 | |
461 if (loader == NULL) | |
462 return; | |
463 | |
464 loader_info = GAIM_PLUGIN_LOADER_INFO(loader); | |
465 | |
466 if (loader_info->destroy != NULL) | |
467 loader_info->destroy(plugin); | |
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 | 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
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
524 gaim_plugins_destroy_all(void) |
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 #ifdef GAIM_PLUGINS |
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 while (plugins != NULL) |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
529 gaim_plugin_destroy(plugins->data); |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
530 |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5211
diff
changeset
|
531 #endif /* GAIM_PLUGINS */ |
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 void |
5205 | 534 gaim_plugins_probe(const char *ext) |
535 { | |
536 #ifdef GAIM_PLUGINS | |
537 GDir *dir; | |
538 const gchar *file; | |
539 gchar *path; | |
540 GaimPlugin *plugin; | |
541 size_t i; | |
542 | |
543 if (!g_module_supported()) | |
544 return; | |
545 | |
546 for (i = 0; i < search_path_count; i++) { | |
547 if (search_paths[i] == NULL) | |
548 continue; | |
549 | |
550 dir = g_dir_open(search_paths[i], 0, NULL); | |
551 | |
552 if (dir != NULL) { | |
553 while ((file = g_dir_read_name(dir)) != NULL) { | |
554 path = g_build_filename(search_paths[i], file, NULL); | |
555 | |
556 if (ext == NULL || is_so_file(file, ext)) | |
557 plugin = gaim_plugin_probe(path); | |
558 | |
559 g_free(path); | |
560 } | |
561 | |
562 g_dir_close(dir); | |
563 } | |
564 } | |
565 | |
566 if (probe_cb != NULL) | |
567 probe_cb(probe_cb_data); | |
568 | |
569 #endif /* GAIM_PLUGINS */ | |
570 } | |
571 | |
572 gboolean | |
573 gaim_plugin_register(GaimPlugin *plugin) | |
574 { | |
575 g_return_val_if_fail(plugin != NULL, FALSE); | |
576 | |
577 if (g_list_find(plugins, plugin)) | |
578 return TRUE; | |
579 | |
580 /* Special exception for loader plugins. We want them loaded NOW! */ | |
581 if (plugin->info->type == GAIM_PLUGIN_LOADER) { | |
582 GList *exts; | |
583 | |
584 /* We'll just load this right now. */ | |
585 if (!gaim_plugin_load(plugin)) { | |
586 | |
587 gaim_plugin_destroy(plugin); | |
588 | |
589 return FALSE; | |
590 } | |
591 | |
592 plugin_loaders = g_list_append(plugin_loaders, plugin); | |
593 | |
594 for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; | |
595 exts != NULL; | |
596 exts = exts->next) { | |
597 | |
598 gaim_plugins_probe(exts->data); | |
599 } | |
600 } | |
601 else if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { | |
602 | |
603 /* We'll just load this right now. */ | |
604 if (!gaim_plugin_load(plugin)) { | |
605 | |
606 gaim_plugin_destroy(plugin); | |
607 | |
608 return FALSE; | |
609 } | |
610 | |
611 if (GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol == GAIM_PROTO_ICQ || | |
612 gaim_find_prpl(GAIM_PLUGIN_PROTOCOL_INFO(plugin)->protocol)) { | |
613 | |
614 /* Nothing to see here--move along, move along */ | |
615 gaim_plugin_destroy(plugin); | |
616 | |
617 return FALSE; | |
618 } | |
619 | |
620 protocols = g_slist_insert_sorted(protocols, plugin, | |
621 (GCompareFunc)compare_prpl); | |
622 } | |
623 | |
624 plugins = g_list_append(plugins, plugin); | |
625 | |
626 return TRUE; | |
627 } | |
628 | |
629 gboolean | |
630 gaim_plugins_enabled(void) | |
631 { | |
632 #ifdef GAIM_PLUGINS | |
633 return TRUE; | |
634 #else | |
635 return FALSE; | |
636 #endif | |
637 } | |
638 | |
639 void | |
640 gaim_plugins_register_probe_notify_cb(void (*func)(void *), void *data) | |
641 { | |
642 /* TODO */ | |
643 probe_cb = func; | |
644 probe_cb_data = data; | |
645 } | |
646 | |
647 void | |
648 gaim_plugins_unregister_probe_notify_cb(void (*func)(void *)) | |
649 { | |
650 /* TODO */ | |
651 probe_cb = NULL; | |
652 probe_cb_data = NULL; | |
653 } | |
654 | |
655 void | |
656 gaim_plugins_register_load_notify_cb(void (*func)(GaimPlugin *, void *), | |
657 void *data) | |
658 { | |
659 /* TODO */ | |
660 load_cb = func; | |
661 load_cb_data = data; | |
662 } | |
663 | |
664 void | |
665 gaim_plugins_unregister_load_notify_cb(void (*func)(GaimPlugin *, void *)) | |
666 { | |
667 /* TODO */ | |
668 load_cb = NULL; | |
669 load_cb_data = NULL; | |
670 } | |
671 | |
672 void | |
673 gaim_plugins_register_unload_notify_cb(void (*func)(GaimPlugin *, void *), | |
674 void *data) | |
675 { | |
676 /* TODO */ | |
677 unload_cb = func; | |
678 unload_cb_data = data; | |
679 } | |
680 | |
681 void | |
682 gaim_plugins_unregister_unload_notify_cb(void (*func)(GaimPlugin *, void *)) | |
683 { | |
684 /* TODO */ | |
685 unload_cb = NULL; | |
686 unload_cb_data = NULL; | |
687 } | |
688 | |
689 GaimPlugin * | |
690 gaim_plugins_find_with_name(const char *name) | |
691 { | |
692 GaimPlugin *plugin; | |
693 GList *l; | |
694 | |
695 for (l = plugins; l != NULL; l = l->next) { | |
696 plugin = l->data; | |
697 | |
698 if (!strcmp(plugin->info->name, name)) | |
699 return plugin; | |
700 } | |
701 | |
702 return NULL; | |
703 } | |
704 | |
705 GaimPlugin * | |
706 gaim_plugins_find_with_filename(const char *filename) | |
707 { | |
708 GaimPlugin *plugin; | |
709 GList *l; | |
710 | |
711 for (l = plugins; l != NULL; l = l->next) { | |
712 plugin = l->data; | |
713 | |
714 if (plugin->path != NULL && !strcmp(plugin->path, filename)) | |
715 return plugin; | |
716 } | |
717 | |
718 return NULL; | |
719 } | |
720 | |
721 GaimPlugin * | |
722 gaim_plugins_find_with_id(const char *id) | |
723 { | |
724 GaimPlugin *plugin; | |
725 GList *l; | |
726 | |
727 g_return_val_if_fail(id != NULL, NULL); | |
728 | |
729 for (l = plugins; l != NULL; l = l->next) { | |
730 plugin = l->data; | |
731 | |
732 if (!strcmp(plugin->info->id, id)) | |
733 return plugin; | |
734 } | |
735 | |
736 return NULL; | |
737 } | |
738 | |
739 GList * | |
740 gaim_plugins_get_loaded(void) | |
741 { | |
742 return loaded_plugins; | |
743 } | |
744 | |
745 GList * | |
746 gaim_plugins_get_all(void) | |
747 { | |
748 return plugins; | |
749 } | |
750 |