Mercurial > pidgin
annotate src/module.c @ 3630:9682c0e022c6
[gaim-migrate @ 3753]
Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk.
committer: Tailor Script <tailor@pidgin.im>
| author | Rob Flynn <gaim@robflynn.com> |
|---|---|
| date | Fri, 11 Oct 2002 03:14:01 +0000 |
| parents | bdd0bebd2d04 |
| children | 988485669631 |
| 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 struct gaim_plugin *reload_plugin(struct gaim_plugin *p); | |
| 68 void gaim_signal_connect(GModule *, enum gaim_event, void *, void *); | |
| 69 void gaim_signal_disconnect(GModule *, enum gaim_event, void *); | |
| 70 void gaim_plugin_unload(GModule *); | |
| 71 | |
| 72 /* --------------- Static Function Declarations ------------- */ | |
| 73 | |
| 74 static void plugin_remove_callbacks(GModule *); | |
| 3551 | 75 #endif |
| 2393 | 76 /* ------------------ Code Below ---------------------------- */ |
| 77 | |
| 3551 | 78 static int is_so_file(char *filename, char *ext) |
| 79 { | |
| 80 int len; | |
| 81 if (!filename) return 0; | |
| 82 if (!filename[0]) return 0; | |
| 83 len = strlen(filename); | |
| 84 len -= strlen(ext); | |
| 85 if (len < 0) return 0; | |
| 86 return (!strncmp(filename + len, ext, strlen(ext))); | |
| 87 } | |
| 88 | |
| 89 void gaim_probe_plugins() { | |
| 90 GDir *dir; | |
| 91 const gchar *file; | |
| 92 gchar *path; | |
| 93 struct gaim_plugin_description *plugdes; | |
| 94 struct gaim_plugin *plug; | |
| 3630 | 95 char *probedirs[3]; |
| 3565 | 96 int l; |
| 3551 | 97 #if GAIM_PLUGINS |
| 98 char *(*gaim_plugin_init)(GModule *); | |
| 3572 | 99 char *(*gaim_prpl_init)(struct prpl *); |
| 3551 | 100 char *(*cfunc)(); |
| 3572 | 101 struct prpl * new_prpl; |
| 3551 | 102 struct gaim_plugin_description *(*desc)(); |
| 103 GModule *handle; | |
| 104 #endif | |
| 105 | |
| 3630 | 106 probedirs[0] = LIBDIR; |
| 107 probedirs[1] = gaim_user_dir(); | |
| 108 probedirs[2] = 0; | |
| 3551 | 109 |
| 110 for (l=0; probedirs[l]; l++) { | |
| 111 dir = g_dir_open(probedirs[l], 0, NULL); | |
| 112 if (dir) { | |
| 113 while ((file = g_dir_read_name(dir))) { | |
| 114 #ifdef GAIM_PLUGINS | |
| 3630 | 115 if (is_so_file(file, |
| 116 #ifndef _WIN32 | |
| 117 ".so" | |
| 118 #else | |
| 119 ".dll" | |
| 120 #endif | |
| 121 ) && g_module_supported()) { | |
| 3551 | 122 path = g_build_filename(probedirs[l], file, NULL); |
| 123 handle = g_module_open(path, 0); | |
| 124 if (!handle) { | |
| 125 debug_printf("%s is unloadable: %s\n", file, g_module_error()); | |
| 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); | |
| 140 continue; | |
| 141 } | |
| 142 protocols = g_slist_insert_sorted(protocols, new_prpl, (GCompareFunc)proto_compare); | |
| 143 g_module_close(handle); | |
| 144 continue; | |
| 145 } | |
| 146 | |
| 3551 | 147 if (!g_module_symbol(handle, "gaim_plugin_init", (gpointer *)&gaim_plugin_init)) { |
| 148 debug_printf("%s is unloadable %s\n", file, g_module_error()); | |
| 149 g_module_close(handle); | |
| 150 continue; | |
| 151 } | |
| 152 plug = g_new0(struct gaim_plugin, 1); | |
| 153 g_snprintf(plug->path, sizeof(plug->path), path); | |
| 154 plug->type = plugin; | |
| 155 g_free(path); | |
| 156 if (g_module_symbol(handle, "gaim_plugin_desc", (gpointer *)&desc)) { | |
| 157 memcpy(&(plug->desc), desc(), sizeof(plug->desc)); | |
| 158 } else { | |
| 159 if (g_module_symbol(handle, "name", (gpointer *)&cfunc)) { | |
| 160 plug->desc.name = g_strdup(cfunc()); | |
| 161 } | |
| 162 if (g_module_symbol(handle, "description", (gpointer *)&cfunc)) { | |
| 163 plug->desc.description = g_strdup(cfunc()); | |
| 164 } | |
| 165 } | |
| 166 probed_plugins = g_list_append(probed_plugins, plug); | |
| 167 g_module_close(handle); | |
| 168 } | |
| 169 #endif | |
| 170 #ifdef USE_PERL | |
| 171 if (is_so_file(file, ".pl")) { | |
| 3563 | 172 path = g_build_filename(probedirs[l], file, NULL); |
| 3551 | 173 plug = probe_perl(path); |
| 174 if (plug) | |
| 175 probed_plugins = g_list_append(probed_plugins, plug); | |
| 176 g_free(path); | |
| 177 } | |
| 178 #endif | |
| 179 } | |
| 180 g_dir_close(dir); | |
| 181 } | |
| 182 } | |
| 183 } | |
| 184 | |
| 185 #ifdef GAIM_PLUGINS | |
| 3466 | 186 struct gaim_plugin *load_plugin(const char *filename) |
| 2393 | 187 { |
| 188 struct gaim_plugin *plug; | |
| 3551 | 189 struct gaim_plugin_description *desc; |
| 190 struct gaim_plugin_description *(*gaim_plugin_desc)(); | |
| 2393 | 191 char *(*cfunc)(); |
| 3551 | 192 GList *c = plugins; |
| 193 GList *p = probed_plugins; | |
| 194 char *(*gaim_plugin_init)(GModule *); | |
| 3563 | 195 char *error, *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 |
| 3563 | 204 if (is_so_file(filename, ".pl")) { |
| 205 return perl_load_file(filename); | |
| 206 } | |
| 3565 | 207 #endif |
| 3563 | 208 |
| 3551 | 209 while (filename && p) { |
| 210 plug = (struct gaim_plugin *)p->data; | |
| 211 if (!strcmp(filename, plug->path)) | |
| 212 break; | |
| 213 p = p->next; | |
| 2393 | 214 } |
| 3551 | 215 |
| 216 if (plug && plug->handle) { | |
| 217 reload_plugin(plug); | |
| 218 return NULL; | |
| 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 /* Do unload/load cycle of plugin. */ | |
| 336 struct gaim_plugin *reload_plugin(struct gaim_plugin *p) | |
| 337 { | |
| 338 char file[1024]; | |
| 339 GModule *handle = p->handle; | |
| 340 | |
| 341 strncpy(file, g_module_name(handle), sizeof(file)); | |
| 342 file[sizeof(file) - 1] = '\0'; | |
| 343 | |
| 344 debug_printf("Reloading %s\n", file); | |
| 345 | |
| 346 /* Unload */ | |
| 347 unload_plugin(p); | |
| 348 | |
| 349 /* Load */ | |
| 350 return load_plugin(file); | |
| 351 } | |
| 352 | |
| 353 /* Remove all callbacks associated with plugin handle */ | |
| 354 static void plugin_remove_callbacks(GModule *handle) | |
| 355 { | |
| 356 GList *c = callbacks; | |
| 357 struct gaim_callback *g; | |
| 358 | |
| 359 debug_printf("%d callbacks to search\n", g_list_length(callbacks)); | |
| 360 | |
| 361 while (c) { | |
| 362 g = (struct gaim_callback *)c->data; | |
| 363 if (g->handle == handle) { | |
| 364 c = g_list_next(c); | |
| 365 callbacks = g_list_remove(callbacks, (gpointer)g); | |
| 366 debug_printf("Removing callback, %d remain\n", g_list_length(callbacks)); | |
| 367 } else | |
| 368 c = g_list_next(c); | |
| 369 } | |
| 370 } | |
| 371 | |
| 372 void gaim_signal_connect(GModule *handle, enum gaim_event which, void *func, void *data) | |
| 373 { | |
| 374 struct gaim_callback *call = g_new0(struct gaim_callback, 1); | |
| 375 call->handle = handle; | |
| 376 call->event = which; | |
| 377 call->function = func; | |
| 378 call->data = data; | |
| 379 | |
| 380 callbacks = g_list_append(callbacks, call); | |
| 381 debug_printf("Adding callback %d\n", g_list_length(callbacks)); | |
| 382 } | |
| 383 | |
| 384 void gaim_signal_disconnect(GModule *handle, enum gaim_event which, void *func) | |
| 385 { | |
| 386 GList *c = callbacks; | |
| 387 struct gaim_callback *g = NULL; | |
| 388 | |
| 389 while (c) { | |
| 390 g = (struct gaim_callback *)c->data; | |
| 391 if (handle == g->handle && func == g->function) { | |
| 392 callbacks = g_list_remove(callbacks, c->data); | |
| 393 g_free(g); | |
| 394 c = callbacks; | |
| 395 if (c == NULL) | |
| 396 break; | |
| 397 } | |
| 398 c = g_list_next(c); | |
| 399 } | |
| 400 } | |
| 401 | |
| 402 #endif /* GAIM_PLUGINS */ | |
| 403 | |
|
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
404 char *event_name(enum gaim_event event) |
| 2393 | 405 { |
| 406 static char buf[128]; | |
| 407 switch (event) { | |
| 408 case event_signon: | |
| 409 sprintf(buf, "event_signon"); | |
| 410 break; | |
| 411 case event_signoff: | |
| 412 sprintf(buf, "event_signoff"); | |
| 413 break; | |
| 414 case event_away: | |
| 415 sprintf(buf, "event_away"); | |
| 416 break; | |
| 417 case event_back: | |
| 418 sprintf(buf, "event_back"); | |
| 419 break; | |
| 420 case event_im_recv: | |
| 421 sprintf(buf, "event_im_recv"); | |
| 422 break; | |
| 423 case event_im_send: | |
| 424 sprintf(buf, "event_im_send"); | |
| 425 break; | |
| 426 case event_buddy_signon: | |
| 427 sprintf(buf, "event_buddy_signon"); | |
| 428 break; | |
| 429 case event_buddy_signoff: | |
| 430 sprintf(buf, "event_buddy_signoff"); | |
| 431 break; | |
| 432 case event_buddy_away: | |
| 433 sprintf(buf, "event_buddy_away"); | |
| 434 break; | |
| 435 case event_buddy_back: | |
| 436 sprintf(buf, "event_buddy_back"); | |
| 437 break; | |
| 438 case event_buddy_idle: | |
| 439 sprintf(buf, "event_buddy_idle"); | |
| 440 break; | |
| 441 case event_buddy_unidle: | |
| 442 sprintf(buf, "event_buddy_unidle"); | |
| 443 break; | |
| 444 case event_blist_update: | |
| 445 sprintf(buf, "event_blist_update"); | |
| 446 break; | |
| 447 case event_chat_invited: | |
| 448 sprintf(buf, "event_chat_invited"); | |
| 449 break; | |
| 450 case event_chat_join: | |
| 451 sprintf(buf, "event_chat_join"); | |
| 452 break; | |
| 453 case event_chat_leave: | |
| 454 sprintf(buf, "event_chat_leave"); | |
| 455 break; | |
| 456 case event_chat_buddy_join: | |
| 457 sprintf(buf, "event_chat_buddy_join"); | |
| 458 break; | |
| 459 case event_chat_buddy_leave: | |
| 460 sprintf(buf, "event_chat_buddy_leave"); | |
| 461 break; | |
| 462 case event_chat_recv: | |
| 463 sprintf(buf, "event_chat_recv"); | |
| 464 break; | |
| 465 case event_chat_send: | |
| 466 sprintf(buf, "event_chat_send"); | |
| 467 break; | |
| 468 case event_warned: | |
| 469 sprintf(buf, "event_warned"); | |
| 470 break; | |
| 471 case event_error: | |
| 472 sprintf(buf, "event_error"); | |
| 473 break; | |
| 474 case event_quit: | |
| 475 sprintf(buf, "event_quit"); | |
| 476 break; | |
| 477 case event_new_conversation: | |
| 478 sprintf(buf, "event_new_conversation"); | |
| 479 break; | |
| 480 case event_set_info: | |
| 481 sprintf(buf, "event_set_info"); | |
| 482 break; | |
| 483 case event_draw_menu: | |
| 484 sprintf(buf, "event_draw_menu"); | |
| 485 break; | |
| 486 case event_im_displayed_sent: | |
| 487 sprintf(buf, "event_im_displayed_sent"); | |
| 488 break; | |
| 489 case event_im_displayed_rcvd: | |
| 490 sprintf(buf, "event_im_displayed_rcvd"); | |
| 491 break; | |
| 492 case event_chat_send_invite: | |
| 493 sprintf(buf, "event_chat_send_invite"); | |
| 494 break; | |
| 2993 | 495 case event_got_typing: |
| 496 sprintf(buf, "event_got_typing"); | |
| 497 break; | |
| 3510 | 498 case event_del_conversation: |
| 499 sprintf(buf, "event_del_conversation"); | |
| 500 break; | |
| 501 case event_connecting: | |
| 502 sprintf(buf, "event_connecting"); | |
| 503 break; | |
| 2393 | 504 default: |
| 505 sprintf(buf, "event_unknown"); | |
| 506 break; | |
| 507 } | |
| 508 return buf; | |
| 509 } | |
| 510 | |
| 3517 | 511 int plugin_event(enum gaim_event event, ...) |
| 2393 | 512 { |
| 513 #ifdef GAIM_PLUGINS | |
| 514 GList *c = callbacks; | |
| 515 struct gaim_callback *g; | |
| 3551 | 516 #endif |
| 3517 | 517 va_list arrg; |
| 518 void *arg1 = NULL, | |
| 519 *arg2 = NULL, | |
| 520 *arg3 = NULL, | |
| 521 *arg4 = NULL, | |
| 522 *arg5 = NULL; | |
| 3551 | 523 |
| 2393 | 524 |
| 3517 | 525 debug_printf("%s\n", event_name(event)); |
|
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
526 |
|
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
527 #ifdef GAIM_PLUGINS |
| 2393 | 528 while (c) { |
| 3517 | 529 void (*cbfunc)(void *, ...); |
| 530 | |
| 2393 | 531 g = (struct gaim_callback *)c->data; |
|
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
532 if (g->event == event && g->function != NULL) { |
| 3517 | 533 cbfunc=g->function; |
| 534 va_start(arrg, event); | |
| 2393 | 535 switch (event) { |
| 536 | |
| 537 /* no args */ | |
| 538 case event_blist_update: | |
| 539 case event_quit: | |
| 3517 | 540 cbfunc(g->data); |
| 2393 | 541 break; |
| 542 | |
| 543 /* one arg */ | |
| 544 case event_signon: | |
| 545 case event_signoff: | |
| 546 case event_new_conversation: | |
| 3461 | 547 case event_del_conversation: |
| 2393 | 548 case event_error: |
| 3510 | 549 case event_connecting: |
| 3517 | 550 arg1 = va_arg(arrg, void *); |
| 551 cbfunc(arg1, g->data); | |
| 2393 | 552 break; |
| 553 | |
| 554 /* two args */ | |
| 555 case event_buddy_signon: | |
| 556 case event_buddy_signoff: | |
| 557 case event_buddy_away: | |
| 558 case event_buddy_back: | |
| 559 case event_buddy_idle: | |
| 560 case event_buddy_unidle: | |
| 561 case event_set_info: | |
| 562 case event_draw_menu: | |
| 2993 | 563 case event_got_typing: |
| 3517 | 564 arg1 = va_arg(arrg, void *); |
| 565 arg2 = va_arg(arrg, void *); | |
| 566 cbfunc(arg1, arg2, g->data); | |
| 2393 | 567 break; |
| 3517 | 568 case event_chat_leave: |
| 569 { | |
| 570 int id; | |
| 571 arg1 = va_arg(arrg, void*); | |
| 572 id = va_arg(arrg, int); | |
| 573 cbfunc(arg1, id, g->data); | |
| 574 } | |
| 575 break; | |
| 2393 | 576 /* three args */ |
| 577 case event_im_send: | |
| 578 case event_im_displayed_sent: | |
| 3517 | 579 case event_away: |
| 580 arg1 = va_arg(arrg, void *); | |
| 581 arg2 = va_arg(arrg, void *); | |
| 582 arg3 = va_arg(arrg, void *); | |
| 583 cbfunc(arg1, arg2, arg3, g->data); | |
| 584 break; | |
| 2393 | 585 case event_chat_buddy_join: |
| 586 case event_chat_buddy_leave: | |
| 587 case event_chat_send: | |
| 3517 | 588 case event_chat_join: |
| 589 { | |
| 590 int id; | |
| 591 arg1 = va_arg(arrg, void*); | |
| 592 id = va_arg(arrg, int); | |
| 593 arg3 = va_arg(arrg, void*); | |
| 594 cbfunc(arg1, id, arg3, g->data); | |
| 595 } | |
| 596 break; | |
| 2393 | 597 case event_warned: |
| 3517 | 598 { |
| 599 int id; | |
| 600 arg1 = va_arg(arrg, void*); | |
| 601 arg2 = va_arg(arrg, void*); | |
| 602 id = va_arg(arrg, int); | |
| 603 cbfunc(arg1, arg2, id, g->data); | |
| 604 } | |
| 2393 | 605 break; |
| 606 /* four args */ | |
| 607 case event_im_recv: | |
| 3517 | 608 case event_chat_invited: |
| 609 arg1 = va_arg(arrg, void *); | |
| 610 arg2 = va_arg(arrg, void *); | |
| 611 arg3 = va_arg(arrg, void *); | |
| 612 arg4 = va_arg(arrg, void *); | |
| 613 cbfunc(arg1, arg2, arg3, arg4, g->data); | |
| 614 break; | |
| 2393 | 615 case event_chat_recv: |
| 616 case event_chat_send_invite: | |
| 3517 | 617 { |
| 618 int id; | |
| 619 arg1 = va_arg(arrg, void *); | |
| 620 id = va_arg(arrg, int); | |
| 621 | |
| 622 arg3 = va_arg(arrg, void *); | |
| 623 arg4 = va_arg(arrg, void *); | |
| 624 cbfunc(arg1, id, arg3, arg4, g->data); | |
| 625 } | |
| 2393 | 626 break; |
| 3517 | 627 /* five args */ |
| 628 case event_im_displayed_rcvd: | |
| 629 { | |
| 630 time_t time; | |
| 631 arg1 = va_arg(arrg, void *); | |
| 632 arg2 = va_arg(arrg, void *); | |
| 633 arg3 = va_arg(arrg, void *); | |
| 634 arg4 = va_arg(arrg, void *); | |
| 635 time = va_arg(arrg, time_t); | |
| 636 cbfunc(arg1, arg2, arg3, arg4, time, g->data); | |
| 637 } | |
| 638 break; | |
| 639 default: | |
| 2393 | 640 debug_printf("unknown event %d\n", event); |
| 641 break; | |
| 642 } | |
| 3517 | 643 va_end(arrg); |
| 2393 | 644 } |
| 645 c = c->next; | |
| 646 } | |
| 647 #endif /* GAIM_PLUGINS */ | |
| 648 #ifdef USE_PERL | |
| 3517 | 649 va_start(arrg, event); |
| 650 arg1 = va_arg(arrg, void *); | |
| 651 arg2 = va_arg(arrg, void *); | |
| 652 arg3 = va_arg(arrg, void *); | |
| 653 arg4 = va_arg(arrg, void *); | |
| 654 arg5 = va_arg(arrg, void *); | |
| 655 return perl_event(event, arg1, arg2, arg3, arg4, arg5); | |
| 2393 | 656 #else |
| 657 return 0; | |
| 658 #endif | |
| 659 } | |
| 660 | |
| 661 /* Calls the gaim_plugin_remove function in any loaded plugin that has one */ | |
| 662 #ifdef GAIM_PLUGINS | |
| 663 void remove_all_plugins() | |
| 664 { | |
| 665 GList *c = plugins; | |
| 666 struct gaim_plugin *p; | |
| 667 void (*gaim_plugin_remove)(); | |
| 668 | |
| 669 while (c) { | |
| 670 p = (struct gaim_plugin *)c->data; | |
| 3563 | 671 if (p->type == plugin) { |
| 672 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) | |
| 673 gaim_plugin_remove(); | |
| 674 } | |
| 2393 | 675 g_free(p); |
| 676 c = c->next; | |
| 677 } | |
| 678 } | |
| 679 #endif |
