Mercurial > pidgin.yaz
annotate src/module.c @ 3565:154c4a9d9b6d
[gaim-migrate @ 3660]
Now you can configure your plugins.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 28 Sep 2002 21:39:45 +0000 |
parents | e120097bbd72 |
children | bdd0bebd2d04 |
rev | line source |
---|---|
2393 | 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 * The Plug-in plug | |
22 * | |
23 * Plugin support is currently being maintained by Mike Saraf | |
24 * msaraf@dwc.edu | |
25 * | |
26 * Well, I didn't see any work done on it for a while, so I'm going to try | |
27 * my hand at it. - Eric warmenhoven@yahoo.com | |
28 * | |
29 * Mike is my roomate. I can assure you that he's lazy :-P -- Rob rob@marko.net | |
30 * | |
31 */ | |
32 | |
33 #ifdef HAVE_CONFIG_H | |
34 #include <config.h> | |
35 #endif | |
36 | |
2414
70cb0ce6991a
[gaim-migrate @ 2427]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2405
diff
changeset
|
37 #include "gaim.h" |
70cb0ce6991a
[gaim-migrate @ 2427]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2405
diff
changeset
|
38 |
2393 | 39 #include <string.h> |
40 #include <sys/time.h> | |
41 | |
42 #include <sys/types.h> | |
43 #include <sys/stat.h> | |
44 | |
45 #include <unistd.h> | |
46 #include <stdio.h> | |
47 #include <stdlib.h> | |
48 | |
49 /* ------------------ Global Variables ----------------------- */ | |
50 | |
51 GList *plugins = NULL; | |
3551 | 52 GList *probed_plugins = NULL; |
2393 | 53 GList *callbacks = NULL; |
54 | |
2405
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
55 char *last_dir = NULL; |
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
56 |
2393 | 57 /* --------------- Function Declarations --------------------- */ |
58 | |
3466 | 59 struct gaim_plugin * load_plugin(const char *); |
3551 | 60 #ifdef GAIM_PLUGINS |
2393 | 61 void unload_plugin(struct gaim_plugin *p); |
62 struct gaim_plugin *reload_plugin(struct gaim_plugin *p); | |
63 void gaim_signal_connect(GModule *, enum gaim_event, void *, void *); | |
64 void gaim_signal_disconnect(GModule *, enum gaim_event, void *); | |
65 void gaim_plugin_unload(GModule *); | |
66 | |
67 /* --------------- Static Function Declarations ------------- */ | |
68 | |
69 static void plugin_remove_callbacks(GModule *); | |
3551 | 70 #endif |
2393 | 71 /* ------------------ Code Below ---------------------------- */ |
72 | |
3551 | 73 static int is_so_file(char *filename, char *ext) |
74 { | |
75 int len; | |
76 if (!filename) return 0; | |
77 if (!filename[0]) return 0; | |
78 len = strlen(filename); | |
79 len -= strlen(ext); | |
80 if (len < 0) return 0; | |
81 return (!strncmp(filename + len, ext, strlen(ext))); | |
82 } | |
83 | |
84 void gaim_probe_plugins() { | |
85 GDir *dir; | |
86 const gchar *file; | |
87 gchar *path; | |
88 struct gaim_plugin_description *plugdes; | |
89 struct gaim_plugin *plug; | |
90 char userspace[128]; | |
91 char *probedirs[] = {LIBDIR, &userspace, 0}; | |
3565 | 92 int l; |
3551 | 93 #if GAIM_PLUGINS |
94 char *(*gaim_plugin_init)(GModule *); | |
95 char *(*cfunc)(); | |
96 struct gaim_plugin_description *(*desc)(); | |
97 GModule *handle; | |
98 #endif | |
99 | |
100 g_snprintf(userspace, sizeof(userspace), "%s" G_DIR_SEPARATOR_S ".gaim", g_get_home_dir()); | |
101 | |
102 for (l=0; probedirs[l]; l++) { | |
103 dir = g_dir_open(probedirs[l], 0, NULL); | |
104 if (dir) { | |
105 while ((file = g_dir_read_name(dir))) { | |
106 #ifdef GAIM_PLUGINS | |
107 if (is_so_file(file, ".so") && g_module_supported()) { | |
108 path = g_build_filename(probedirs[l], file, NULL); | |
109 handle = g_module_open(path, 0); | |
110 if (!handle) { | |
111 debug_printf("%s is unloadable: %s\n", file, g_module_error()); | |
112 continue; | |
113 } | |
114 if (!g_module_symbol(handle, "gaim_plugin_init", (gpointer *)&gaim_plugin_init)) { | |
115 debug_printf("%s is unloadable %s\n", file, g_module_error()); | |
116 g_module_close(handle); | |
117 continue; | |
118 } | |
119 plug = g_new0(struct gaim_plugin, 1); | |
120 g_snprintf(plug->path, sizeof(plug->path), path); | |
121 plug->type = plugin; | |
122 g_free(path); | |
123 if (g_module_symbol(handle, "gaim_plugin_desc", (gpointer *)&desc)) { | |
124 memcpy(&(plug->desc), desc(), sizeof(plug->desc)); | |
125 } else { | |
126 if (g_module_symbol(handle, "name", (gpointer *)&cfunc)) { | |
127 plug->desc.name = g_strdup(cfunc()); | |
128 } | |
129 if (g_module_symbol(handle, "description", (gpointer *)&cfunc)) { | |
130 plug->desc.description = g_strdup(cfunc()); | |
131 } | |
132 } | |
133 probed_plugins = g_list_append(probed_plugins, plug); | |
134 g_module_close(handle); | |
135 } | |
136 #endif | |
137 #ifdef USE_PERL | |
138 if (is_so_file(file, ".pl")) { | |
3563 | 139 path = g_build_filename(probedirs[l], file, NULL); |
3551 | 140 plug = probe_perl(path); |
141 if (plug) | |
142 probed_plugins = g_list_append(probed_plugins, plug); | |
143 g_free(path); | |
144 } | |
145 #endif | |
146 } | |
147 g_dir_close(dir); | |
148 } | |
149 } | |
150 } | |
151 | |
152 #ifdef GAIM_PLUGINS | |
3466 | 153 struct gaim_plugin *load_plugin(const char *filename) |
2393 | 154 { |
155 struct gaim_plugin *plug; | |
3551 | 156 struct gaim_plugin_description *desc; |
157 struct gaim_plugin_description *(*gaim_plugin_desc)(); | |
2393 | 158 char *(*cfunc)(); |
3551 | 159 GList *c = plugins; |
160 GList *p = probed_plugins; | |
161 char *(*gaim_plugin_init)(GModule *); | |
3563 | 162 char *error, *retval; |
3551 | 163 gboolean newplug = FALSE; |
2393 | 164 |
165 if (!g_module_supported()) | |
166 return NULL; | |
3551 | 167 if (!filename || !strlen(filename)) |
2393 | 168 return NULL; |
169 | |
3565 | 170 #ifdef USE_PERL |
3563 | 171 if (is_so_file(filename, ".pl")) { |
172 return perl_load_file(filename); | |
173 } | |
3565 | 174 #endif |
3563 | 175 |
3551 | 176 while (filename && p) { |
177 plug = (struct gaim_plugin *)p->data; | |
178 if (!strcmp(filename, plug->path)) | |
179 break; | |
180 p = p->next; | |
2393 | 181 } |
3551 | 182 |
183 if (plug && plug->handle) { | |
184 reload_plugin(plug); | |
185 return NULL; | |
186 } | |
187 | |
188 if (!plug) { | |
189 plug = g_new0(struct gaim_plugin, 1); | |
190 g_snprintf(plug->path, sizeof(plug->path), filename); | |
191 newplug = TRUE; | |
192 } | |
193 | |
2393 | 194 debug_printf("Loading %s\n", filename); |
195 plug->handle = g_module_open(filename, 0); | |
196 if (!plug->handle) { | |
197 error = (char *)g_module_error(); | |
3551 | 198 plug->handle = NULL; |
3563 | 199 g_snprintf(plug->error, sizeof(plug->error), error); |
2393 | 200 return NULL; |
201 } | |
3551 | 202 |
2393 | 203 if (!g_module_symbol(plug->handle, "gaim_plugin_init", (gpointer *)&gaim_plugin_init)) { |
204 g_module_close(plug->handle); | |
3551 | 205 plug->handle = NULL; |
3563 | 206 g_snprintf(plug->error, sizeof(plug->error), error); |
2393 | 207 return NULL; |
208 } | |
209 | |
3563 | 210 plug->error[0] = '\0'; |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2511
diff
changeset
|
211 retval = gaim_plugin_init(plug->handle); |
2393 | 212 debug_printf("loaded plugin returned %s\n", retval ? retval : "NULL"); |
213 if (retval) { | |
214 plugin_remove_callbacks(plug->handle); | |
3427 | 215 do_error_dialog("Gaim was unable to load your plugin.", retval, GAIM_ERROR); |
2393 | 216 g_module_close(plug->handle); |
3551 | 217 plug->handle = NULL; |
2393 | 218 return NULL; |
219 } | |
220 | |
221 plugins = g_list_append(plugins, plug); | |
222 | |
3551 | 223 if (newplug) { |
224 g_snprintf(plug->path, sizeof(plug->path), filename); | |
225 if (g_module_symbol(plug->handle, "gaim_plugin_desc", (gpointer *)&gaim_plugin_desc)) { | |
226 desc = gaim_plugin_desc(); | |
227 plug->desc.name = desc->name; | |
228 } else { | |
229 if (g_module_symbol(plug->handle, "name", (gpointer *)&cfunc)) { | |
230 plug->desc.name = g_strdup(cfunc()); | |
231 } | |
232 if (g_module_symbol(plug->handle, "description", (gpointer *)&cfunc)) { | |
233 plug->desc.description = g_strdup(cfunc()); | |
234 } | |
235 } | |
236 probed_plugins = g_list_append(probed_plugins, plug); | |
2393 | 237 } |
3551 | 238 |
2393 | 239 save_prefs(); |
240 return plug; | |
3551 | 241 |
2393 | 242 } |
243 | |
244 static void unload_gaim_plugin(struct gaim_plugin *p) | |
245 { | |
246 void (*gaim_plugin_remove)(); | |
247 | |
248 debug_printf("Unloading %s\n", g_module_name(p->handle)); | |
249 | |
250 /* Attempt to call the plugin's remove function (if there) */ | |
251 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) | |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2511
diff
changeset
|
252 gaim_plugin_remove(); |
2393 | 253 |
254 plugin_remove_callbacks(p->handle); | |
255 | |
256 plugins = g_list_remove(plugins, p); | |
3551 | 257 p->handle = NULL; |
2393 | 258 save_prefs(); |
259 } | |
260 | |
261 void unload_plugin(struct gaim_plugin *p) | |
262 { | |
263 GModule *handle = p->handle; | |
264 unload_gaim_plugin(p); | |
265 g_module_close(handle); | |
266 } | |
267 | |
268 static gboolean unload_timeout(gpointer handle) | |
269 { | |
270 g_module_close(handle); | |
271 return FALSE; | |
272 } | |
273 | |
274 void gaim_plugin_unload(GModule *handle) | |
275 { | |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
276 GList *pl = plugins; |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
277 struct gaim_plugin *p = NULL; |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
278 void (*gaim_plugin_remove)(); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
279 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
280 while (pl) { |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
281 p = pl->data; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
282 if (p->handle == handle) |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
283 break; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
284 pl = pl->next; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
285 } |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
286 if (!pl) |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
287 return; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
288 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
289 debug_printf("Unloading %s\n", g_module_name(p->handle)); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
290 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
291 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2511
diff
changeset
|
292 gaim_plugin_remove(); |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
293 plugin_remove_callbacks(p->handle); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
294 plugins = g_list_remove(plugins, p); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
295 g_free(p); |
3551 | 296 /* XXX CUI need to tell UI what happened, but not like this |
297 update_show_plugins(); */ | |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
298 |
2393 | 299 g_timeout_add(5000, unload_timeout, handle); |
300 } | |
301 | |
302 /* Do unload/load cycle of plugin. */ | |
303 struct gaim_plugin *reload_plugin(struct gaim_plugin *p) | |
304 { | |
305 char file[1024]; | |
306 GModule *handle = p->handle; | |
307 | |
308 strncpy(file, g_module_name(handle), sizeof(file)); | |
309 file[sizeof(file) - 1] = '\0'; | |
310 | |
311 debug_printf("Reloading %s\n", file); | |
312 | |
313 /* Unload */ | |
314 unload_plugin(p); | |
315 | |
316 /* Load */ | |
317 return load_plugin(file); | |
318 } | |
319 | |
320 /* Remove all callbacks associated with plugin handle */ | |
321 static void plugin_remove_callbacks(GModule *handle) | |
322 { | |
323 GList *c = callbacks; | |
324 struct gaim_callback *g; | |
325 | |
326 debug_printf("%d callbacks to search\n", g_list_length(callbacks)); | |
327 | |
328 while (c) { | |
329 g = (struct gaim_callback *)c->data; | |
330 if (g->handle == handle) { | |
331 c = g_list_next(c); | |
332 callbacks = g_list_remove(callbacks, (gpointer)g); | |
333 debug_printf("Removing callback, %d remain\n", g_list_length(callbacks)); | |
334 } else | |
335 c = g_list_next(c); | |
336 } | |
337 } | |
338 | |
339 void gaim_signal_connect(GModule *handle, enum gaim_event which, void *func, void *data) | |
340 { | |
341 struct gaim_callback *call = g_new0(struct gaim_callback, 1); | |
342 call->handle = handle; | |
343 call->event = which; | |
344 call->function = func; | |
345 call->data = data; | |
346 | |
347 callbacks = g_list_append(callbacks, call); | |
348 debug_printf("Adding callback %d\n", g_list_length(callbacks)); | |
349 } | |
350 | |
351 void gaim_signal_disconnect(GModule *handle, enum gaim_event which, void *func) | |
352 { | |
353 GList *c = callbacks; | |
354 struct gaim_callback *g = NULL; | |
355 | |
356 while (c) { | |
357 g = (struct gaim_callback *)c->data; | |
358 if (handle == g->handle && func == g->function) { | |
359 callbacks = g_list_remove(callbacks, c->data); | |
360 g_free(g); | |
361 c = callbacks; | |
362 if (c == NULL) | |
363 break; | |
364 } | |
365 c = g_list_next(c); | |
366 } | |
367 } | |
368 | |
369 #endif /* GAIM_PLUGINS */ | |
370 | |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
371 char *event_name(enum gaim_event event) |
2393 | 372 { |
373 static char buf[128]; | |
374 switch (event) { | |
375 case event_signon: | |
376 sprintf(buf, "event_signon"); | |
377 break; | |
378 case event_signoff: | |
379 sprintf(buf, "event_signoff"); | |
380 break; | |
381 case event_away: | |
382 sprintf(buf, "event_away"); | |
383 break; | |
384 case event_back: | |
385 sprintf(buf, "event_back"); | |
386 break; | |
387 case event_im_recv: | |
388 sprintf(buf, "event_im_recv"); | |
389 break; | |
390 case event_im_send: | |
391 sprintf(buf, "event_im_send"); | |
392 break; | |
393 case event_buddy_signon: | |
394 sprintf(buf, "event_buddy_signon"); | |
395 break; | |
396 case event_buddy_signoff: | |
397 sprintf(buf, "event_buddy_signoff"); | |
398 break; | |
399 case event_buddy_away: | |
400 sprintf(buf, "event_buddy_away"); | |
401 break; | |
402 case event_buddy_back: | |
403 sprintf(buf, "event_buddy_back"); | |
404 break; | |
405 case event_buddy_idle: | |
406 sprintf(buf, "event_buddy_idle"); | |
407 break; | |
408 case event_buddy_unidle: | |
409 sprintf(buf, "event_buddy_unidle"); | |
410 break; | |
411 case event_blist_update: | |
412 sprintf(buf, "event_blist_update"); | |
413 break; | |
414 case event_chat_invited: | |
415 sprintf(buf, "event_chat_invited"); | |
416 break; | |
417 case event_chat_join: | |
418 sprintf(buf, "event_chat_join"); | |
419 break; | |
420 case event_chat_leave: | |
421 sprintf(buf, "event_chat_leave"); | |
422 break; | |
423 case event_chat_buddy_join: | |
424 sprintf(buf, "event_chat_buddy_join"); | |
425 break; | |
426 case event_chat_buddy_leave: | |
427 sprintf(buf, "event_chat_buddy_leave"); | |
428 break; | |
429 case event_chat_recv: | |
430 sprintf(buf, "event_chat_recv"); | |
431 break; | |
432 case event_chat_send: | |
433 sprintf(buf, "event_chat_send"); | |
434 break; | |
435 case event_warned: | |
436 sprintf(buf, "event_warned"); | |
437 break; | |
438 case event_error: | |
439 sprintf(buf, "event_error"); | |
440 break; | |
441 case event_quit: | |
442 sprintf(buf, "event_quit"); | |
443 break; | |
444 case event_new_conversation: | |
445 sprintf(buf, "event_new_conversation"); | |
446 break; | |
447 case event_set_info: | |
448 sprintf(buf, "event_set_info"); | |
449 break; | |
450 case event_draw_menu: | |
451 sprintf(buf, "event_draw_menu"); | |
452 break; | |
453 case event_im_displayed_sent: | |
454 sprintf(buf, "event_im_displayed_sent"); | |
455 break; | |
456 case event_im_displayed_rcvd: | |
457 sprintf(buf, "event_im_displayed_rcvd"); | |
458 break; | |
459 case event_chat_send_invite: | |
460 sprintf(buf, "event_chat_send_invite"); | |
461 break; | |
2993 | 462 case event_got_typing: |
463 sprintf(buf, "event_got_typing"); | |
464 break; | |
3510 | 465 case event_del_conversation: |
466 sprintf(buf, "event_del_conversation"); | |
467 break; | |
468 case event_connecting: | |
469 sprintf(buf, "event_connecting"); | |
470 break; | |
2393 | 471 default: |
472 sprintf(buf, "event_unknown"); | |
473 break; | |
474 } | |
475 return buf; | |
476 } | |
477 | |
3517 | 478 int plugin_event(enum gaim_event event, ...) |
2393 | 479 { |
480 #ifdef GAIM_PLUGINS | |
481 GList *c = callbacks; | |
482 struct gaim_callback *g; | |
3551 | 483 #endif |
3517 | 484 va_list arrg; |
485 void *arg1 = NULL, | |
486 *arg2 = NULL, | |
487 *arg3 = NULL, | |
488 *arg4 = NULL, | |
489 *arg5 = NULL; | |
3551 | 490 |
2393 | 491 |
3517 | 492 debug_printf("%s\n", event_name(event)); |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
493 |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
494 #ifdef GAIM_PLUGINS |
2393 | 495 while (c) { |
3517 | 496 void (*cbfunc)(void *, ...); |
497 | |
2393 | 498 g = (struct gaim_callback *)c->data; |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
499 if (g->event == event && g->function != NULL) { |
3517 | 500 cbfunc=g->function; |
501 va_start(arrg, event); | |
2393 | 502 switch (event) { |
503 | |
504 /* no args */ | |
505 case event_blist_update: | |
506 case event_quit: | |
3517 | 507 cbfunc(g->data); |
2393 | 508 break; |
509 | |
510 /* one arg */ | |
511 case event_signon: | |
512 case event_signoff: | |
513 case event_new_conversation: | |
3461 | 514 case event_del_conversation: |
2393 | 515 case event_error: |
3510 | 516 case event_connecting: |
3517 | 517 arg1 = va_arg(arrg, void *); |
518 cbfunc(arg1, g->data); | |
2393 | 519 break; |
520 | |
521 /* two args */ | |
522 case event_buddy_signon: | |
523 case event_buddy_signoff: | |
524 case event_buddy_away: | |
525 case event_buddy_back: | |
526 case event_buddy_idle: | |
527 case event_buddy_unidle: | |
528 case event_set_info: | |
529 case event_draw_menu: | |
2993 | 530 case event_got_typing: |
3517 | 531 arg1 = va_arg(arrg, void *); |
532 arg2 = va_arg(arrg, void *); | |
533 cbfunc(arg1, arg2, g->data); | |
2393 | 534 break; |
3517 | 535 case event_chat_leave: |
536 { | |
537 int id; | |
538 arg1 = va_arg(arrg, void*); | |
539 id = va_arg(arrg, int); | |
540 cbfunc(arg1, id, g->data); | |
541 } | |
542 break; | |
2393 | 543 /* three args */ |
544 case event_im_send: | |
545 case event_im_displayed_sent: | |
3517 | 546 case event_away: |
547 arg1 = va_arg(arrg, void *); | |
548 arg2 = va_arg(arrg, void *); | |
549 arg3 = va_arg(arrg, void *); | |
550 cbfunc(arg1, arg2, arg3, g->data); | |
551 break; | |
2393 | 552 case event_chat_buddy_join: |
553 case event_chat_buddy_leave: | |
554 case event_chat_send: | |
3517 | 555 case event_chat_join: |
556 { | |
557 int id; | |
558 arg1 = va_arg(arrg, void*); | |
559 id = va_arg(arrg, int); | |
560 arg3 = va_arg(arrg, void*); | |
561 cbfunc(arg1, id, arg3, g->data); | |
562 } | |
563 break; | |
2393 | 564 case event_warned: |
3517 | 565 { |
566 int id; | |
567 arg1 = va_arg(arrg, void*); | |
568 arg2 = va_arg(arrg, void*); | |
569 id = va_arg(arrg, int); | |
570 cbfunc(arg1, arg2, id, g->data); | |
571 } | |
2393 | 572 break; |
573 /* four args */ | |
574 case event_im_recv: | |
3517 | 575 case event_chat_invited: |
576 arg1 = va_arg(arrg, void *); | |
577 arg2 = va_arg(arrg, void *); | |
578 arg3 = va_arg(arrg, void *); | |
579 arg4 = va_arg(arrg, void *); | |
580 cbfunc(arg1, arg2, arg3, arg4, g->data); | |
581 break; | |
2393 | 582 case event_chat_recv: |
583 case event_chat_send_invite: | |
3517 | 584 { |
585 int id; | |
586 arg1 = va_arg(arrg, void *); | |
587 id = va_arg(arrg, int); | |
588 | |
589 arg3 = va_arg(arrg, void *); | |
590 arg4 = va_arg(arrg, void *); | |
591 cbfunc(arg1, id, arg3, arg4, g->data); | |
592 } | |
2393 | 593 break; |
3517 | 594 /* five args */ |
595 case event_im_displayed_rcvd: | |
596 { | |
597 time_t time; | |
598 arg1 = va_arg(arrg, void *); | |
599 arg2 = va_arg(arrg, void *); | |
600 arg3 = va_arg(arrg, void *); | |
601 arg4 = va_arg(arrg, void *); | |
602 time = va_arg(arrg, time_t); | |
603 cbfunc(arg1, arg2, arg3, arg4, time, g->data); | |
604 } | |
605 break; | |
606 default: | |
2393 | 607 debug_printf("unknown event %d\n", event); |
608 break; | |
609 } | |
3517 | 610 va_end(arrg); |
2393 | 611 } |
612 c = c->next; | |
613 } | |
614 #endif /* GAIM_PLUGINS */ | |
615 #ifdef USE_PERL | |
3517 | 616 va_start(arrg, event); |
617 arg1 = va_arg(arrg, void *); | |
618 arg2 = va_arg(arrg, void *); | |
619 arg3 = va_arg(arrg, void *); | |
620 arg4 = va_arg(arrg, void *); | |
621 arg5 = va_arg(arrg, void *); | |
622 return perl_event(event, arg1, arg2, arg3, arg4, arg5); | |
2393 | 623 #else |
624 return 0; | |
625 #endif | |
626 } | |
627 | |
628 /* Calls the gaim_plugin_remove function in any loaded plugin that has one */ | |
629 #ifdef GAIM_PLUGINS | |
630 void remove_all_plugins() | |
631 { | |
632 GList *c = plugins; | |
633 struct gaim_plugin *p; | |
634 void (*gaim_plugin_remove)(); | |
635 | |
636 while (c) { | |
637 p = (struct gaim_plugin *)c->data; | |
3563 | 638 if (p->type == plugin) { |
639 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) | |
640 gaim_plugin_remove(); | |
641 } | |
2393 | 642 g_free(p); |
643 c = c->next; | |
644 } | |
645 } | |
646 #endif |