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