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