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