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