Mercurial > pidgin
annotate src/module.c @ 3563:e120097bbd72
[gaim-migrate @ 3658]
I made my perl script unloading not suck (as much). Now you may port your
perl scripts--use gaim.pl and PERL-HOWTO as references.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Sat, 28 Sep 2002 08:08:14 +0000 |
| parents | cd938f18f3f8 |
| children | 154c4a9d9b6d |
| 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}; | |
| 92 #if GAIM_PLUGINS | |
| 93 char *(*gaim_plugin_init)(GModule *); | |
| 94 char *(*cfunc)(); | |
| 95 int l; | |
| 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 | |
| 3563 | 170 if (is_so_file(filename, ".pl")) { |
| 171 return perl_load_file(filename); | |
| 172 } | |
| 173 | |
| 3551 | 174 while (filename && p) { |
| 175 plug = (struct gaim_plugin *)p->data; | |
| 176 if (!strcmp(filename, plug->path)) | |
| 177 break; | |
| 178 p = p->next; | |
| 2393 | 179 } |
| 3551 | 180 |
| 181 if (plug && plug->handle) { | |
| 182 reload_plugin(plug); | |
| 183 return NULL; | |
| 184 } | |
| 185 | |
| 186 if (!plug) { | |
| 187 plug = g_new0(struct gaim_plugin, 1); | |
| 188 g_snprintf(plug->path, sizeof(plug->path), filename); | |
| 189 newplug = TRUE; | |
| 190 } | |
| 191 | |
| 2393 | 192 debug_printf("Loading %s\n", filename); |
| 193 plug->handle = g_module_open(filename, 0); | |
| 194 if (!plug->handle) { | |
| 195 error = (char *)g_module_error(); | |
| 3551 | 196 plug->handle = NULL; |
| 3563 | 197 g_snprintf(plug->error, sizeof(plug->error), error); |
| 2393 | 198 return NULL; |
| 199 } | |
| 3551 | 200 |
| 2393 | 201 if (!g_module_symbol(plug->handle, "gaim_plugin_init", (gpointer *)&gaim_plugin_init)) { |
| 202 g_module_close(plug->handle); | |
| 3551 | 203 plug->handle = NULL; |
| 3563 | 204 g_snprintf(plug->error, sizeof(plug->error), error); |
| 2393 | 205 return NULL; |
| 206 } | |
| 207 | |
| 3563 | 208 plug->error[0] = '\0'; |
|
2662
b0c5770156e1
[gaim-migrate @ 2675]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2511
diff
changeset
|
209 retval = gaim_plugin_init(plug->handle); |
| 2393 | 210 debug_printf("loaded plugin returned %s\n", retval ? retval : "NULL"); |
| 211 if (retval) { | |
| 212 plugin_remove_callbacks(plug->handle); | |
| 3427 | 213 do_error_dialog("Gaim was unable to load your plugin.", retval, GAIM_ERROR); |
| 2393 | 214 g_module_close(plug->handle); |
| 3551 | 215 plug->handle = NULL; |
| 2393 | 216 return NULL; |
| 217 } | |
| 218 | |
| 219 plugins = g_list_append(plugins, plug); | |
| 220 | |
| 3551 | 221 if (newplug) { |
| 222 g_snprintf(plug->path, sizeof(plug->path), filename); | |
| 223 if (g_module_symbol(plug->handle, "gaim_plugin_desc", (gpointer *)&gaim_plugin_desc)) { | |
| 224 desc = gaim_plugin_desc(); | |
| 225 plug->desc.name = desc->name; | |
| 226 } else { | |
| 227 if (g_module_symbol(plug->handle, "name", (gpointer *)&cfunc)) { | |
| 228 plug->desc.name = g_strdup(cfunc()); | |
| 229 } | |
| 230 if (g_module_symbol(plug->handle, "description", (gpointer *)&cfunc)) { | |
| 231 plug->desc.description = g_strdup(cfunc()); | |
| 232 } | |
| 233 } | |
| 234 probed_plugins = g_list_append(probed_plugins, plug); | |
| 2393 | 235 } |
| 3551 | 236 |
| 2393 | 237 save_prefs(); |
| 238 return plug; | |
| 3551 | 239 |
| 2393 | 240 } |
| 241 | |
| 242 static void unload_gaim_plugin(struct gaim_plugin *p) | |
| 243 { | |
| 244 void (*gaim_plugin_remove)(); | |
| 245 | |
| 246 debug_printf("Unloading %s\n", g_module_name(p->handle)); | |
| 247 | |
| 248 /* Attempt to call the plugin's remove function (if there) */ | |
| 249 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
|
250 gaim_plugin_remove(); |
| 2393 | 251 |
| 252 plugin_remove_callbacks(p->handle); | |
| 253 | |
| 254 plugins = g_list_remove(plugins, p); | |
| 3551 | 255 p->handle = NULL; |
| 2393 | 256 save_prefs(); |
| 257 } | |
| 258 | |
| 259 void unload_plugin(struct gaim_plugin *p) | |
| 260 { | |
| 261 GModule *handle = p->handle; | |
| 262 unload_gaim_plugin(p); | |
| 263 g_module_close(handle); | |
| 264 } | |
| 265 | |
| 266 static gboolean unload_timeout(gpointer handle) | |
| 267 { | |
| 268 g_module_close(handle); | |
| 269 return FALSE; | |
| 270 } | |
| 271 | |
| 272 void gaim_plugin_unload(GModule *handle) | |
| 273 { | |
|
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
274 GList *pl = plugins; |
|
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
275 struct gaim_plugin *p = NULL; |
|
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
276 void (*gaim_plugin_remove)(); |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
277 |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
278 while (pl) { |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
279 p = pl->data; |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
280 if (p->handle == handle) |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
281 break; |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
282 pl = pl->next; |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
283 } |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
284 if (!pl) |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
285 return; |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
286 |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
287 debug_printf("Unloading %s\n", g_module_name(p->handle)); |
|
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 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
|
290 gaim_plugin_remove(); |
|
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
291 plugin_remove_callbacks(p->handle); |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
292 plugins = g_list_remove(plugins, p); |
|
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
293 g_free(p); |
| 3551 | 294 /* XXX CUI need to tell UI what happened, but not like this |
| 295 update_show_plugins(); */ | |
|
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
296 |
| 2393 | 297 g_timeout_add(5000, unload_timeout, handle); |
| 298 } | |
| 299 | |
| 300 /* Do unload/load cycle of plugin. */ | |
| 301 struct gaim_plugin *reload_plugin(struct gaim_plugin *p) | |
| 302 { | |
| 303 char file[1024]; | |
| 304 GModule *handle = p->handle; | |
| 305 | |
| 306 strncpy(file, g_module_name(handle), sizeof(file)); | |
| 307 file[sizeof(file) - 1] = '\0'; | |
| 308 | |
| 309 debug_printf("Reloading %s\n", file); | |
| 310 | |
| 311 /* Unload */ | |
| 312 unload_plugin(p); | |
| 313 | |
| 314 /* Load */ | |
| 315 return load_plugin(file); | |
| 316 } | |
| 317 | |
| 318 /* Remove all callbacks associated with plugin handle */ | |
| 319 static void plugin_remove_callbacks(GModule *handle) | |
| 320 { | |
| 321 GList *c = callbacks; | |
| 322 struct gaim_callback *g; | |
| 323 | |
| 324 debug_printf("%d callbacks to search\n", g_list_length(callbacks)); | |
| 325 | |
| 326 while (c) { | |
| 327 g = (struct gaim_callback *)c->data; | |
| 328 if (g->handle == handle) { | |
| 329 c = g_list_next(c); | |
| 330 callbacks = g_list_remove(callbacks, (gpointer)g); | |
| 331 debug_printf("Removing callback, %d remain\n", g_list_length(callbacks)); | |
| 332 } else | |
| 333 c = g_list_next(c); | |
| 334 } | |
| 335 } | |
| 336 | |
| 337 void gaim_signal_connect(GModule *handle, enum gaim_event which, void *func, void *data) | |
| 338 { | |
| 339 struct gaim_callback *call = g_new0(struct gaim_callback, 1); | |
| 340 call->handle = handle; | |
| 341 call->event = which; | |
| 342 call->function = func; | |
| 343 call->data = data; | |
| 344 | |
| 345 callbacks = g_list_append(callbacks, call); | |
| 346 debug_printf("Adding callback %d\n", g_list_length(callbacks)); | |
| 347 } | |
| 348 | |
| 349 void gaim_signal_disconnect(GModule *handle, enum gaim_event which, void *func) | |
| 350 { | |
| 351 GList *c = callbacks; | |
| 352 struct gaim_callback *g = NULL; | |
| 353 | |
| 354 while (c) { | |
| 355 g = (struct gaim_callback *)c->data; | |
| 356 if (handle == g->handle && func == g->function) { | |
| 357 callbacks = g_list_remove(callbacks, c->data); | |
| 358 g_free(g); | |
| 359 c = callbacks; | |
| 360 if (c == NULL) | |
| 361 break; | |
| 362 } | |
| 363 c = g_list_next(c); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 #endif /* GAIM_PLUGINS */ | |
| 368 | |
|
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
369 char *event_name(enum gaim_event event) |
| 2393 | 370 { |
| 371 static char buf[128]; | |
| 372 switch (event) { | |
| 373 case event_signon: | |
| 374 sprintf(buf, "event_signon"); | |
| 375 break; | |
| 376 case event_signoff: | |
| 377 sprintf(buf, "event_signoff"); | |
| 378 break; | |
| 379 case event_away: | |
| 380 sprintf(buf, "event_away"); | |
| 381 break; | |
| 382 case event_back: | |
| 383 sprintf(buf, "event_back"); | |
| 384 break; | |
| 385 case event_im_recv: | |
| 386 sprintf(buf, "event_im_recv"); | |
| 387 break; | |
| 388 case event_im_send: | |
| 389 sprintf(buf, "event_im_send"); | |
| 390 break; | |
| 391 case event_buddy_signon: | |
| 392 sprintf(buf, "event_buddy_signon"); | |
| 393 break; | |
| 394 case event_buddy_signoff: | |
| 395 sprintf(buf, "event_buddy_signoff"); | |
| 396 break; | |
| 397 case event_buddy_away: | |
| 398 sprintf(buf, "event_buddy_away"); | |
| 399 break; | |
| 400 case event_buddy_back: | |
| 401 sprintf(buf, "event_buddy_back"); | |
| 402 break; | |
| 403 case event_buddy_idle: | |
| 404 sprintf(buf, "event_buddy_idle"); | |
| 405 break; | |
| 406 case event_buddy_unidle: | |
| 407 sprintf(buf, "event_buddy_unidle"); | |
| 408 break; | |
| 409 case event_blist_update: | |
| 410 sprintf(buf, "event_blist_update"); | |
| 411 break; | |
| 412 case event_chat_invited: | |
| 413 sprintf(buf, "event_chat_invited"); | |
| 414 break; | |
| 415 case event_chat_join: | |
| 416 sprintf(buf, "event_chat_join"); | |
| 417 break; | |
| 418 case event_chat_leave: | |
| 419 sprintf(buf, "event_chat_leave"); | |
| 420 break; | |
| 421 case event_chat_buddy_join: | |
| 422 sprintf(buf, "event_chat_buddy_join"); | |
| 423 break; | |
| 424 case event_chat_buddy_leave: | |
| 425 sprintf(buf, "event_chat_buddy_leave"); | |
| 426 break; | |
| 427 case event_chat_recv: | |
| 428 sprintf(buf, "event_chat_recv"); | |
| 429 break; | |
| 430 case event_chat_send: | |
| 431 sprintf(buf, "event_chat_send"); | |
| 432 break; | |
| 433 case event_warned: | |
| 434 sprintf(buf, "event_warned"); | |
| 435 break; | |
| 436 case event_error: | |
| 437 sprintf(buf, "event_error"); | |
| 438 break; | |
| 439 case event_quit: | |
| 440 sprintf(buf, "event_quit"); | |
| 441 break; | |
| 442 case event_new_conversation: | |
| 443 sprintf(buf, "event_new_conversation"); | |
| 444 break; | |
| 445 case event_set_info: | |
| 446 sprintf(buf, "event_set_info"); | |
| 447 break; | |
| 448 case event_draw_menu: | |
| 449 sprintf(buf, "event_draw_menu"); | |
| 450 break; | |
| 451 case event_im_displayed_sent: | |
| 452 sprintf(buf, "event_im_displayed_sent"); | |
| 453 break; | |
| 454 case event_im_displayed_rcvd: | |
| 455 sprintf(buf, "event_im_displayed_rcvd"); | |
| 456 break; | |
| 457 case event_chat_send_invite: | |
| 458 sprintf(buf, "event_chat_send_invite"); | |
| 459 break; | |
| 2993 | 460 case event_got_typing: |
| 461 sprintf(buf, "event_got_typing"); | |
| 462 break; | |
| 3510 | 463 case event_del_conversation: |
| 464 sprintf(buf, "event_del_conversation"); | |
| 465 break; | |
| 466 case event_connecting: | |
| 467 sprintf(buf, "event_connecting"); | |
| 468 break; | |
| 2393 | 469 default: |
| 470 sprintf(buf, "event_unknown"); | |
| 471 break; | |
| 472 } | |
| 473 return buf; | |
| 474 } | |
| 475 | |
| 3517 | 476 int plugin_event(enum gaim_event event, ...) |
| 2393 | 477 { |
| 478 #ifdef GAIM_PLUGINS | |
| 479 GList *c = callbacks; | |
| 480 struct gaim_callback *g; | |
| 3551 | 481 #endif |
| 3517 | 482 va_list arrg; |
| 483 void *arg1 = NULL, | |
| 484 *arg2 = NULL, | |
| 485 *arg3 = NULL, | |
| 486 *arg4 = NULL, | |
| 487 *arg5 = NULL; | |
| 3551 | 488 |
| 2393 | 489 |
| 3517 | 490 debug_printf("%s\n", event_name(event)); |
|
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
491 |
|
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
492 #ifdef GAIM_PLUGINS |
| 2393 | 493 while (c) { |
| 3517 | 494 void (*cbfunc)(void *, ...); |
| 495 | |
| 2393 | 496 g = (struct gaim_callback *)c->data; |
|
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
497 if (g->event == event && g->function != NULL) { |
| 3517 | 498 cbfunc=g->function; |
| 499 va_start(arrg, event); | |
| 2393 | 500 switch (event) { |
| 501 | |
| 502 /* no args */ | |
| 503 case event_blist_update: | |
| 504 case event_quit: | |
| 3517 | 505 cbfunc(g->data); |
| 2393 | 506 break; |
| 507 | |
| 508 /* one arg */ | |
| 509 case event_signon: | |
| 510 case event_signoff: | |
| 511 case event_new_conversation: | |
| 3461 | 512 case event_del_conversation: |
| 2393 | 513 case event_error: |
| 3510 | 514 case event_connecting: |
| 3517 | 515 arg1 = va_arg(arrg, void *); |
| 516 cbfunc(arg1, g->data); | |
| 2393 | 517 break; |
| 518 | |
| 519 /* two args */ | |
| 520 case event_buddy_signon: | |
| 521 case event_buddy_signoff: | |
| 522 case event_buddy_away: | |
| 523 case event_buddy_back: | |
| 524 case event_buddy_idle: | |
| 525 case event_buddy_unidle: | |
| 526 case event_set_info: | |
| 527 case event_draw_menu: | |
| 2993 | 528 case event_got_typing: |
| 3517 | 529 arg1 = va_arg(arrg, void *); |
| 530 arg2 = va_arg(arrg, void *); | |
| 531 cbfunc(arg1, arg2, g->data); | |
| 2393 | 532 break; |
| 3517 | 533 case event_chat_leave: |
| 534 { | |
| 535 int id; | |
| 536 arg1 = va_arg(arrg, void*); | |
| 537 id = va_arg(arrg, int); | |
| 538 cbfunc(arg1, id, g->data); | |
| 539 } | |
| 540 break; | |
| 2393 | 541 /* three args */ |
| 542 case event_im_send: | |
| 543 case event_im_displayed_sent: | |
| 3517 | 544 case event_away: |
| 545 arg1 = va_arg(arrg, void *); | |
| 546 arg2 = va_arg(arrg, void *); | |
| 547 arg3 = va_arg(arrg, void *); | |
| 548 cbfunc(arg1, arg2, arg3, g->data); | |
| 549 break; | |
| 2393 | 550 case event_chat_buddy_join: |
| 551 case event_chat_buddy_leave: | |
| 552 case event_chat_send: | |
| 3517 | 553 case event_chat_join: |
| 554 { | |
| 555 int id; | |
| 556 arg1 = va_arg(arrg, void*); | |
| 557 id = va_arg(arrg, int); | |
| 558 arg3 = va_arg(arrg, void*); | |
| 559 cbfunc(arg1, id, arg3, g->data); | |
| 560 } | |
| 561 break; | |
| 2393 | 562 case event_warned: |
| 3517 | 563 { |
| 564 int id; | |
| 565 arg1 = va_arg(arrg, void*); | |
| 566 arg2 = va_arg(arrg, void*); | |
| 567 id = va_arg(arrg, int); | |
| 568 cbfunc(arg1, arg2, id, g->data); | |
| 569 } | |
| 2393 | 570 break; |
| 571 /* four args */ | |
| 572 case event_im_recv: | |
| 3517 | 573 case event_chat_invited: |
| 574 arg1 = va_arg(arrg, void *); | |
| 575 arg2 = va_arg(arrg, void *); | |
| 576 arg3 = va_arg(arrg, void *); | |
| 577 arg4 = va_arg(arrg, void *); | |
| 578 cbfunc(arg1, arg2, arg3, arg4, g->data); | |
| 579 break; | |
| 2393 | 580 case event_chat_recv: |
| 581 case event_chat_send_invite: | |
| 3517 | 582 { |
| 583 int id; | |
| 584 arg1 = va_arg(arrg, void *); | |
| 585 id = va_arg(arrg, int); | |
| 586 | |
| 587 arg3 = va_arg(arrg, void *); | |
| 588 arg4 = va_arg(arrg, void *); | |
| 589 cbfunc(arg1, id, arg3, arg4, g->data); | |
| 590 } | |
| 2393 | 591 break; |
| 3517 | 592 /* five args */ |
| 593 case event_im_displayed_rcvd: | |
| 594 { | |
| 595 time_t time; | |
| 596 arg1 = va_arg(arrg, void *); | |
| 597 arg2 = va_arg(arrg, void *); | |
| 598 arg3 = va_arg(arrg, void *); | |
| 599 arg4 = va_arg(arrg, void *); | |
| 600 time = va_arg(arrg, time_t); | |
| 601 cbfunc(arg1, arg2, arg3, arg4, time, g->data); | |
| 602 } | |
| 603 break; | |
| 604 default: | |
| 2393 | 605 debug_printf("unknown event %d\n", event); |
| 606 break; | |
| 607 } | |
| 3517 | 608 va_end(arrg); |
| 2393 | 609 } |
| 610 c = c->next; | |
| 611 } | |
| 612 #endif /* GAIM_PLUGINS */ | |
| 613 #ifdef USE_PERL | |
| 3517 | 614 va_start(arrg, event); |
| 615 arg1 = va_arg(arrg, void *); | |
| 616 arg2 = va_arg(arrg, void *); | |
| 617 arg3 = va_arg(arrg, void *); | |
| 618 arg4 = va_arg(arrg, void *); | |
| 619 arg5 = va_arg(arrg, void *); | |
| 620 return perl_event(event, arg1, arg2, arg3, arg4, arg5); | |
| 2393 | 621 #else |
| 622 return 0; | |
| 623 #endif | |
| 624 } | |
| 625 | |
| 626 /* Calls the gaim_plugin_remove function in any loaded plugin that has one */ | |
| 627 #ifdef GAIM_PLUGINS | |
| 628 void remove_all_plugins() | |
| 629 { | |
| 630 GList *c = plugins; | |
| 631 struct gaim_plugin *p; | |
| 632 void (*gaim_plugin_remove)(); | |
| 633 | |
| 634 while (c) { | |
| 635 p = (struct gaim_plugin *)c->data; | |
| 3563 | 636 if (p->type == plugin) { |
| 637 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) | |
| 638 gaim_plugin_remove(); | |
| 639 } | |
| 2393 | 640 g_free(p); |
| 641 c = c->next; | |
| 642 } | |
| 643 } | |
| 644 #endif |
