Mercurial > pidgin
annotate src/module.c @ 4024:c97789bb4bbc
[gaim-migrate @ 4226]
spelling fixes from John B. Silvestri. quoth he: While looking through the
.todo (the web version, actually) for something, my cable modem chose to drop
my connection. In a fit of boredom, I've gone ahead and proofread the todo for
typos. I could have gone crazy and capitalized the first letter of every
sentence, but I was not that bored :-). These are just a few little typos. For
some reason, I have a knack at spotting these things, and somehow it just seems
better to have it right, even for developers :). [Added note: It later
occurred to me to run the .todo through a spellchecker, which caught about
twice as many new typos as my eyes caught - hint: "I before E, except after C,
and a few odd cases (their, weigh, etc.).]
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 30 Nov 2002 19:09:22 +0000 |
parents | b359aab1c576 |
children | 4927f8dd046f |
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()); | |
125 continue; | |
126 } | |
3572 | 127 if (g_module_symbol(handle, "gaim_prpl_init", (gpointer *)&gaim_prpl_init)) { |
128 plug = g_new0(struct gaim_plugin, 1); | |
129 g_snprintf(plug->path, sizeof(plug->path), path); | |
130 plug->type = plugin; | |
131 | |
132 new_prpl = g_new0(struct prpl, 1); | |
133 new_prpl->plug = plug; | |
134 gaim_prpl_init(new_prpl); | |
135 if (new_prpl->protocol == PROTO_ICQ || | |
136 find_prpl(new_prpl->protocol)) { | |
137 /* Nothing to see here--move along, move along */ | |
138 unload_protocol(new_prpl); | |
139 continue; | |
140 } | |
141 protocols = g_slist_insert_sorted(protocols, new_prpl, (GCompareFunc)proto_compare); | |
142 g_module_close(handle); | |
143 continue; | |
144 } | |
145 | |
3551 | 146 if (!g_module_symbol(handle, "gaim_plugin_init", (gpointer *)&gaim_plugin_init)) { |
147 debug_printf("%s is unloadable %s\n", file, g_module_error()); | |
148 g_module_close(handle); | |
149 continue; | |
150 } | |
151 plug = g_new0(struct gaim_plugin, 1); | |
152 g_snprintf(plug->path, sizeof(plug->path), path); | |
153 plug->type = plugin; | |
154 g_free(path); | |
155 if (g_module_symbol(handle, "gaim_plugin_desc", (gpointer *)&desc)) { | |
156 memcpy(&(plug->desc), desc(), sizeof(plug->desc)); | |
157 } else { | |
158 if (g_module_symbol(handle, "name", (gpointer *)&cfunc)) { | |
159 plug->desc.name = g_strdup(cfunc()); | |
160 } | |
161 if (g_module_symbol(handle, "description", (gpointer *)&cfunc)) { | |
162 plug->desc.description = g_strdup(cfunc()); | |
163 } | |
164 } | |
165 probed_plugins = g_list_append(probed_plugins, plug); | |
166 g_module_close(handle); | |
167 } | |
168 #endif | |
169 #ifdef USE_PERL | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
170 if (is_so_file((char*)file, ".pl")) { |
3563 | 171 path = g_build_filename(probedirs[l], file, NULL); |
3551 | 172 plug = probe_perl(path); |
173 if (plug) | |
174 probed_plugins = g_list_append(probed_plugins, plug); | |
175 g_free(path); | |
176 } | |
177 #endif | |
178 } | |
179 g_dir_close(dir); | |
180 } | |
181 } | |
182 } | |
183 | |
184 #ifdef GAIM_PLUGINS | |
3466 | 185 struct gaim_plugin *load_plugin(const char *filename) |
2393 | 186 { |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
187 struct gaim_plugin *plug=NULL; |
3551 | 188 struct gaim_plugin_description *desc; |
189 struct gaim_plugin_description *(*gaim_plugin_desc)(); | |
2393 | 190 char *(*cfunc)(); |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
191 /*GList *c = plugins;*/ |
3551 | 192 GList *p = probed_plugins; |
193 char *(*gaim_plugin_init)(GModule *); | |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
194 char *error=NULL; |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
195 char *retval; |
3551 | 196 gboolean newplug = FALSE; |
2393 | 197 |
198 if (!g_module_supported()) | |
199 return NULL; | |
3551 | 200 if (!filename || !strlen(filename)) |
2393 | 201 return NULL; |
202 | |
3565 | 203 #ifdef USE_PERL |
3717
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
204 if (is_so_file((char*)filename, ".pl")) { |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
205 /* perl_load_file is returning an int.. this should be fixed */ |
988485669631
[gaim-migrate @ 3850]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3630
diff
changeset
|
206 return (struct gaim_plugin *)perl_load_file((char*)filename); |
3563 | 207 } |
3565 | 208 #endif |
3563 | 209 |
3551 | 210 while (filename && p) { |
211 plug = (struct gaim_plugin *)p->data; | |
212 if (!strcmp(filename, plug->path)) | |
213 break; | |
214 p = p->next; | |
2393 | 215 } |
3551 | 216 |
217 if (plug && plug->handle) { | |
3835 | 218 return plug; |
3551 | 219 } |
220 | |
221 if (!plug) { | |
222 plug = g_new0(struct gaim_plugin, 1); | |
223 g_snprintf(plug->path, sizeof(plug->path), filename); | |
224 newplug = TRUE; | |
225 } | |
226 | |
2393 | 227 debug_printf("Loading %s\n", filename); |
228 plug->handle = g_module_open(filename, 0); | |
229 if (!plug->handle) { | |
230 error = (char *)g_module_error(); | |
3551 | 231 plug->handle = NULL; |
3563 | 232 g_snprintf(plug->error, sizeof(plug->error), error); |
2393 | 233 return NULL; |
234 } | |
3551 | 235 |
2393 | 236 if (!g_module_symbol(plug->handle, "gaim_plugin_init", (gpointer *)&gaim_plugin_init)) { |
237 g_module_close(plug->handle); | |
3551 | 238 plug->handle = NULL; |
3563 | 239 g_snprintf(plug->error, sizeof(plug->error), error); |
2393 | 240 return NULL; |
241 } | |
242 | |
3563 | 243 plug->error[0] = '\0'; |
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2511
diff
changeset
|
244 retval = gaim_plugin_init(plug->handle); |
2393 | 245 debug_printf("loaded plugin returned %s\n", retval ? retval : "NULL"); |
246 if (retval) { | |
247 plugin_remove_callbacks(plug->handle); | |
3427 | 248 do_error_dialog("Gaim was unable to load your plugin.", retval, GAIM_ERROR); |
2393 | 249 g_module_close(plug->handle); |
3551 | 250 plug->handle = NULL; |
2393 | 251 return NULL; |
252 } | |
253 | |
254 plugins = g_list_append(plugins, plug); | |
255 | |
3551 | 256 if (newplug) { |
257 g_snprintf(plug->path, sizeof(plug->path), filename); | |
258 if (g_module_symbol(plug->handle, "gaim_plugin_desc", (gpointer *)&gaim_plugin_desc)) { | |
259 desc = gaim_plugin_desc(); | |
260 plug->desc.name = desc->name; | |
261 } else { | |
262 if (g_module_symbol(plug->handle, "name", (gpointer *)&cfunc)) { | |
263 plug->desc.name = g_strdup(cfunc()); | |
264 } | |
265 if (g_module_symbol(plug->handle, "description", (gpointer *)&cfunc)) { | |
266 plug->desc.description = g_strdup(cfunc()); | |
267 } | |
268 } | |
269 probed_plugins = g_list_append(probed_plugins, plug); | |
2393 | 270 } |
3551 | 271 |
2393 | 272 save_prefs(); |
273 return plug; | |
3551 | 274 |
2393 | 275 } |
276 | |
277 static void unload_gaim_plugin(struct gaim_plugin *p) | |
278 { | |
279 void (*gaim_plugin_remove)(); | |
280 | |
281 debug_printf("Unloading %s\n", g_module_name(p->handle)); | |
282 | |
283 /* Attempt to call the plugin's remove function (if there) */ | |
284 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
|
285 gaim_plugin_remove(); |
2393 | 286 |
287 plugin_remove_callbacks(p->handle); | |
288 | |
289 plugins = g_list_remove(plugins, p); | |
3551 | 290 p->handle = NULL; |
2393 | 291 save_prefs(); |
292 } | |
293 | |
294 void unload_plugin(struct gaim_plugin *p) | |
295 { | |
296 GModule *handle = p->handle; | |
297 unload_gaim_plugin(p); | |
298 g_module_close(handle); | |
299 } | |
300 | |
301 static gboolean unload_timeout(gpointer handle) | |
302 { | |
303 g_module_close(handle); | |
304 return FALSE; | |
305 } | |
306 | |
307 void gaim_plugin_unload(GModule *handle) | |
308 { | |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
309 GList *pl = plugins; |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
310 struct gaim_plugin *p = NULL; |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
311 void (*gaim_plugin_remove)(); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
312 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
313 while (pl) { |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
314 p = pl->data; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
315 if (p->handle == handle) |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
316 break; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
317 pl = pl->next; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
318 } |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
319 if (!pl) |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
320 return; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
321 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
322 debug_printf("Unloading %s\n", g_module_name(p->handle)); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
323 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
324 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
|
325 gaim_plugin_remove(); |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
326 plugin_remove_callbacks(p->handle); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
327 plugins = g_list_remove(plugins, p); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
328 g_free(p); |
3551 | 329 /* XXX CUI need to tell UI what happened, but not like this |
330 update_show_plugins(); */ | |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
331 |
2393 | 332 g_timeout_add(5000, unload_timeout, handle); |
333 } | |
334 | |
335 /* Remove all callbacks associated with plugin handle */ | |
336 static void plugin_remove_callbacks(GModule *handle) | |
337 { | |
338 GList *c = callbacks; | |
339 struct gaim_callback *g; | |
340 | |
341 debug_printf("%d callbacks to search\n", g_list_length(callbacks)); | |
342 | |
343 while (c) { | |
344 g = (struct gaim_callback *)c->data; | |
345 if (g->handle == handle) { | |
346 c = g_list_next(c); | |
347 callbacks = g_list_remove(callbacks, (gpointer)g); | |
348 debug_printf("Removing callback, %d remain\n", g_list_length(callbacks)); | |
349 } else | |
350 c = g_list_next(c); | |
351 } | |
352 } | |
353 | |
354 void gaim_signal_connect(GModule *handle, enum gaim_event which, void *func, void *data) | |
355 { | |
356 struct gaim_callback *call = g_new0(struct gaim_callback, 1); | |
357 call->handle = handle; | |
358 call->event = which; | |
359 call->function = func; | |
360 call->data = data; | |
361 | |
362 callbacks = g_list_append(callbacks, call); | |
363 debug_printf("Adding callback %d\n", g_list_length(callbacks)); | |
364 } | |
365 | |
366 void gaim_signal_disconnect(GModule *handle, enum gaim_event which, void *func) | |
367 { | |
368 GList *c = callbacks; | |
369 struct gaim_callback *g = NULL; | |
370 | |
371 while (c) { | |
372 g = (struct gaim_callback *)c->data; | |
373 if (handle == g->handle && func == g->function) { | |
374 callbacks = g_list_remove(callbacks, c->data); | |
375 g_free(g); | |
376 c = callbacks; | |
377 if (c == NULL) | |
378 break; | |
379 } | |
380 c = g_list_next(c); | |
381 } | |
382 } | |
383 | |
384 #endif /* GAIM_PLUGINS */ | |
385 | |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
386 char *event_name(enum gaim_event event) |
2393 | 387 { |
388 static char buf[128]; | |
389 switch (event) { | |
390 case event_signon: | |
391 sprintf(buf, "event_signon"); | |
392 break; | |
393 case event_signoff: | |
394 sprintf(buf, "event_signoff"); | |
395 break; | |
396 case event_away: | |
397 sprintf(buf, "event_away"); | |
398 break; | |
399 case event_back: | |
400 sprintf(buf, "event_back"); | |
401 break; | |
402 case event_im_recv: | |
403 sprintf(buf, "event_im_recv"); | |
404 break; | |
405 case event_im_send: | |
406 sprintf(buf, "event_im_send"); | |
407 break; | |
408 case event_buddy_signon: | |
409 sprintf(buf, "event_buddy_signon"); | |
410 break; | |
411 case event_buddy_signoff: | |
412 sprintf(buf, "event_buddy_signoff"); | |
413 break; | |
414 case event_buddy_away: | |
415 sprintf(buf, "event_buddy_away"); | |
416 break; | |
417 case event_buddy_back: | |
418 sprintf(buf, "event_buddy_back"); | |
419 break; | |
420 case event_buddy_idle: | |
421 sprintf(buf, "event_buddy_idle"); | |
422 break; | |
423 case event_buddy_unidle: | |
424 sprintf(buf, "event_buddy_unidle"); | |
425 break; | |
426 case event_blist_update: | |
427 sprintf(buf, "event_blist_update"); | |
428 break; | |
429 case event_chat_invited: | |
430 sprintf(buf, "event_chat_invited"); | |
431 break; | |
432 case event_chat_join: | |
433 sprintf(buf, "event_chat_join"); | |
434 break; | |
435 case event_chat_leave: | |
436 sprintf(buf, "event_chat_leave"); | |
437 break; | |
438 case event_chat_buddy_join: | |
439 sprintf(buf, "event_chat_buddy_join"); | |
440 break; | |
441 case event_chat_buddy_leave: | |
442 sprintf(buf, "event_chat_buddy_leave"); | |
443 break; | |
444 case event_chat_recv: | |
445 sprintf(buf, "event_chat_recv"); | |
446 break; | |
447 case event_chat_send: | |
448 sprintf(buf, "event_chat_send"); | |
449 break; | |
450 case event_warned: | |
451 sprintf(buf, "event_warned"); | |
452 break; | |
453 case event_error: | |
454 sprintf(buf, "event_error"); | |
455 break; | |
456 case event_quit: | |
457 sprintf(buf, "event_quit"); | |
458 break; | |
459 case event_new_conversation: | |
460 sprintf(buf, "event_new_conversation"); | |
461 break; | |
462 case event_set_info: | |
463 sprintf(buf, "event_set_info"); | |
464 break; | |
465 case event_draw_menu: | |
466 sprintf(buf, "event_draw_menu"); | |
467 break; | |
468 case event_im_displayed_sent: | |
469 sprintf(buf, "event_im_displayed_sent"); | |
470 break; | |
471 case event_im_displayed_rcvd: | |
472 sprintf(buf, "event_im_displayed_rcvd"); | |
473 break; | |
474 case event_chat_send_invite: | |
475 sprintf(buf, "event_chat_send_invite"); | |
476 break; | |
2993 | 477 case event_got_typing: |
478 sprintf(buf, "event_got_typing"); | |
479 break; | |
3510 | 480 case event_del_conversation: |
481 sprintf(buf, "event_del_conversation"); | |
482 break; | |
483 case event_connecting: | |
484 sprintf(buf, "event_connecting"); | |
485 break; | |
2393 | 486 default: |
487 sprintf(buf, "event_unknown"); | |
488 break; | |
489 } | |
490 return buf; | |
491 } | |
492 | |
3517 | 493 int plugin_event(enum gaim_event event, ...) |
2393 | 494 { |
495 #ifdef GAIM_PLUGINS | |
496 GList *c = callbacks; | |
497 struct gaim_callback *g; | |
3551 | 498 #endif |
3517 | 499 va_list arrg; |
500 void *arg1 = NULL, | |
501 *arg2 = NULL, | |
502 *arg3 = NULL, | |
503 *arg4 = NULL, | |
504 *arg5 = NULL; | |
3551 | 505 |
2393 | 506 |
3517 | 507 debug_printf("%s\n", event_name(event)); |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
508 |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
509 #ifdef GAIM_PLUGINS |
2393 | 510 while (c) { |
3517 | 511 void (*cbfunc)(void *, ...); |
512 | |
2393 | 513 g = (struct gaim_callback *)c->data; |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
514 if (g->event == event && g->function != NULL) { |
3517 | 515 cbfunc=g->function; |
516 va_start(arrg, event); | |
2393 | 517 switch (event) { |
518 | |
519 /* no args */ | |
520 case event_blist_update: | |
521 case event_quit: | |
3517 | 522 cbfunc(g->data); |
2393 | 523 break; |
524 | |
525 /* one arg */ | |
526 case event_signon: | |
527 case event_signoff: | |
528 case event_new_conversation: | |
3461 | 529 case event_del_conversation: |
2393 | 530 case event_error: |
3510 | 531 case event_connecting: |
3517 | 532 arg1 = va_arg(arrg, void *); |
533 cbfunc(arg1, g->data); | |
2393 | 534 break; |
535 | |
536 /* two args */ | |
537 case event_buddy_signon: | |
538 case event_buddy_signoff: | |
539 case event_buddy_away: | |
540 case event_buddy_back: | |
541 case event_buddy_idle: | |
542 case event_buddy_unidle: | |
543 case event_set_info: | |
544 case event_draw_menu: | |
2993 | 545 case event_got_typing: |
3517 | 546 arg1 = va_arg(arrg, void *); |
547 arg2 = va_arg(arrg, void *); | |
548 cbfunc(arg1, arg2, g->data); | |
2393 | 549 break; |
3517 | 550 case event_chat_leave: |
551 { | |
552 int id; | |
553 arg1 = va_arg(arrg, void*); | |
554 id = va_arg(arrg, int); | |
555 cbfunc(arg1, id, g->data); | |
556 } | |
557 break; | |
2393 | 558 /* three args */ |
559 case event_im_send: | |
560 case event_im_displayed_sent: | |
3517 | 561 case event_away: |
562 arg1 = va_arg(arrg, void *); | |
563 arg2 = va_arg(arrg, void *); | |
564 arg3 = va_arg(arrg, void *); | |
565 cbfunc(arg1, arg2, arg3, g->data); | |
566 break; | |
2393 | 567 case event_chat_buddy_join: |
568 case event_chat_buddy_leave: | |
569 case event_chat_send: | |
3517 | 570 case event_chat_join: |
571 { | |
572 int id; | |
573 arg1 = va_arg(arrg, void*); | |
574 id = va_arg(arrg, int); | |
575 arg3 = va_arg(arrg, void*); | |
576 cbfunc(arg1, id, arg3, g->data); | |
577 } | |
578 break; | |
2393 | 579 case event_warned: |
3517 | 580 { |
581 int id; | |
582 arg1 = va_arg(arrg, void*); | |
583 arg2 = va_arg(arrg, void*); | |
584 id = va_arg(arrg, int); | |
585 cbfunc(arg1, arg2, id, g->data); | |
586 } | |
2393 | 587 break; |
588 /* four args */ | |
589 case event_im_recv: | |
3517 | 590 case event_chat_invited: |
591 arg1 = va_arg(arrg, void *); | |
592 arg2 = va_arg(arrg, void *); | |
593 arg3 = va_arg(arrg, void *); | |
594 arg4 = va_arg(arrg, void *); | |
595 cbfunc(arg1, arg2, arg3, arg4, g->data); | |
596 break; | |
2393 | 597 case event_chat_recv: |
598 case event_chat_send_invite: | |
3517 | 599 { |
600 int id; | |
601 arg1 = va_arg(arrg, void *); | |
602 id = va_arg(arrg, int); | |
603 | |
604 arg3 = va_arg(arrg, void *); | |
605 arg4 = va_arg(arrg, void *); | |
606 cbfunc(arg1, id, arg3, arg4, g->data); | |
607 } | |
2393 | 608 break; |
3517 | 609 /* five args */ |
610 case event_im_displayed_rcvd: | |
611 { | |
612 time_t time; | |
613 arg1 = va_arg(arrg, void *); | |
614 arg2 = va_arg(arrg, void *); | |
615 arg3 = va_arg(arrg, void *); | |
616 arg4 = va_arg(arrg, void *); | |
617 time = va_arg(arrg, time_t); | |
618 cbfunc(arg1, arg2, arg3, arg4, time, g->data); | |
619 } | |
620 break; | |
621 default: | |
2393 | 622 debug_printf("unknown event %d\n", event); |
623 break; | |
624 } | |
3517 | 625 va_end(arrg); |
2393 | 626 } |
627 c = c->next; | |
628 } | |
629 #endif /* GAIM_PLUGINS */ | |
630 #ifdef USE_PERL | |
3517 | 631 va_start(arrg, event); |
632 arg1 = va_arg(arrg, void *); | |
633 arg2 = va_arg(arrg, void *); | |
634 arg3 = va_arg(arrg, void *); | |
635 arg4 = va_arg(arrg, void *); | |
636 arg5 = va_arg(arrg, void *); | |
637 return perl_event(event, arg1, arg2, arg3, arg4, arg5); | |
2393 | 638 #else |
639 return 0; | |
640 #endif | |
641 } | |
642 | |
643 /* Calls the gaim_plugin_remove function in any loaded plugin that has one */ | |
644 #ifdef GAIM_PLUGINS | |
645 void remove_all_plugins() | |
646 { | |
647 GList *c = plugins; | |
648 struct gaim_plugin *p; | |
649 void (*gaim_plugin_remove)(); | |
650 | |
651 while (c) { | |
652 p = (struct gaim_plugin *)c->data; | |
3563 | 653 if (p->type == plugin) { |
654 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) | |
655 gaim_plugin_remove(); | |
656 } | |
2393 | 657 g_free(p); |
658 c = c->next; | |
659 } | |
660 } | |
661 #endif |