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