Mercurial > pidgin
annotate src/module.c @ 2534:2bc6ee172103
[gaim-migrate @ 2547]
I got an itty bitty diff for you ;-)
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Thu, 18 Oct 2001 07:26:56 +0000 |
parents | a83b4a5ffcd6 |
children | b0c5770156e1 |
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 #ifdef GAIM_PLUGINS |
40 | |
41 #include <string.h> | |
42 #include <sys/time.h> | |
43 | |
44 #include <sys/types.h> | |
45 #include <sys/stat.h> | |
46 | |
47 #include <unistd.h> | |
48 #include <stdio.h> | |
49 #include <stdlib.h> | |
50 | |
51 /* ------------------ Global Variables ----------------------- */ | |
52 | |
53 GList *plugins = NULL; | |
54 GList *callbacks = NULL; | |
55 | |
2405
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
56 char *last_dir = NULL; |
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
57 |
2393 | 58 /* --------------- Function Declarations --------------------- */ |
59 | |
60 struct gaim_plugin * load_plugin(char *); | |
61 void unload_plugin(struct gaim_plugin *p); | |
62 struct gaim_plugin *reload_plugin(struct gaim_plugin *p); | |
63 | |
64 void gaim_signal_connect(GModule *, enum gaim_event, void *, void *); | |
65 void gaim_signal_disconnect(GModule *, enum gaim_event, void *); | |
66 void gaim_plugin_unload(GModule *); | |
67 | |
68 /* --------------- Static Function Declarations ------------- */ | |
69 | |
70 static void plugin_remove_callbacks(GModule *); | |
71 | |
72 /* ------------------ Code Below ---------------------------- */ | |
73 | |
74 struct gaim_plugin *load_plugin(char *filename) | |
75 { | |
76 struct gaim_plugin *plug; | |
77 GList *c = plugins; | |
78 char *(*gaim_plugin_init)(GModule *); | |
79 char *(*cfunc)(); | |
80 char *error; | |
81 char *retval; | |
82 | |
83 if (!g_module_supported()) | |
84 return NULL; | |
85 if (filename && !strlen(filename)) | |
86 return NULL; | |
87 | |
88 while (filename && c) { | |
89 plug = (struct gaim_plugin *)c->data; | |
90 if (!strcmp(filename, g_module_name(plug->handle))) { | |
91 /* just need to reload plugin */ | |
92 return reload_plugin(plug); | |
93 } else | |
94 c = g_list_next(c); | |
95 } | |
96 plug = g_malloc(sizeof *plug); | |
97 | |
2405
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
98 if (last_dir) |
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
99 g_free(last_dir); |
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
100 last_dir = g_dirname(filename); |
6e637ad18494
[gaim-migrate @ 2418]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2393
diff
changeset
|
101 |
2393 | 102 debug_printf("Loading %s\n", filename); |
103 plug->handle = g_module_open(filename, 0); | |
104 if (!plug->handle) { | |
105 error = (char *)g_module_error(); | |
106 do_error_dialog(error, _("Plugin Error")); | |
107 g_free(plug); | |
108 return NULL; | |
109 } | |
110 | |
111 if (!g_module_symbol(plug->handle, "gaim_plugin_init", (gpointer *)&gaim_plugin_init)) { | |
112 do_error_dialog(g_module_error(), _("Plugin Error")); | |
113 g_module_close(plug->handle); | |
114 g_free(plug); | |
115 return NULL; | |
116 } | |
117 | |
118 retval = (*gaim_plugin_init)(plug->handle); | |
119 debug_printf("loaded plugin returned %s\n", retval ? retval : "NULL"); | |
120 if (retval) { | |
121 plugin_remove_callbacks(plug->handle); | |
122 do_error_dialog(retval, _("Plugin Error")); | |
123 g_module_close(plug->handle); | |
124 g_free(plug); | |
125 return NULL; | |
126 } | |
127 | |
128 plugins = g_list_append(plugins, plug); | |
129 | |
130 if (g_module_symbol(plug->handle, "name", (gpointer *)&cfunc)) { | |
131 plug->name = (*cfunc)(); | |
132 } else { | |
133 plug->name = NULL; | |
134 } | |
135 | |
136 if (g_module_symbol(plug->handle, "description", (gpointer *)&cfunc)) | |
137 plug->description = (*cfunc)(); | |
138 else | |
139 plug->description = NULL; | |
140 | |
141 save_prefs(); | |
142 return plug; | |
143 } | |
144 | |
145 static void unload_gaim_plugin(struct gaim_plugin *p) | |
146 { | |
147 void (*gaim_plugin_remove)(); | |
148 | |
149 debug_printf("Unloading %s\n", g_module_name(p->handle)); | |
150 | |
151 /* Attempt to call the plugin's remove function (if there) */ | |
152 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) | |
153 (*gaim_plugin_remove)(); | |
154 | |
155 plugin_remove_callbacks(p->handle); | |
156 | |
157 plugins = g_list_remove(plugins, p); | |
158 g_free(p); | |
159 save_prefs(); | |
160 } | |
161 | |
162 void unload_plugin(struct gaim_plugin *p) | |
163 { | |
164 GModule *handle = p->handle; | |
165 unload_gaim_plugin(p); | |
166 g_module_close(handle); | |
167 } | |
168 | |
169 static gboolean unload_timeout(gpointer handle) | |
170 { | |
171 g_module_close(handle); | |
172 return FALSE; | |
173 } | |
174 | |
175 void gaim_plugin_unload(GModule *handle) | |
176 { | |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
177 GList *pl = plugins; |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
178 struct gaim_plugin *p = NULL; |
2494
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
179 void (*gaim_plugin_remove)(); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
180 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
181 while (pl) { |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
182 p = pl->data; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
183 if (p->handle == handle) |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
184 break; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
185 pl = pl->next; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
186 } |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
187 if (!pl) |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
188 return; |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
189 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
190 debug_printf("Unloading %s\n", g_module_name(p->handle)); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
191 |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
192 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
193 (*gaim_plugin_remove)(); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
194 plugin_remove_callbacks(p->handle); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
195 plugins = g_list_remove(plugins, p); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
196 g_free(p); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
197 /* XXX CUI need to tell UI what happened, but not like this */ |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
198 update_show_plugins(); |
2c1950c5544a
[gaim-migrate @ 2507]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2465
diff
changeset
|
199 |
2393 | 200 g_timeout_add(5000, unload_timeout, handle); |
201 } | |
202 | |
203 /* Do unload/load cycle of plugin. */ | |
204 struct gaim_plugin *reload_plugin(struct gaim_plugin *p) | |
205 { | |
206 char file[1024]; | |
207 GModule *handle = p->handle; | |
208 | |
209 strncpy(file, g_module_name(handle), sizeof(file)); | |
210 file[sizeof(file) - 1] = '\0'; | |
211 | |
212 debug_printf("Reloading %s\n", file); | |
213 | |
214 /* Unload */ | |
215 unload_plugin(p); | |
216 | |
217 /* Load */ | |
218 return load_plugin(file); | |
219 } | |
220 | |
221 /* Remove all callbacks associated with plugin handle */ | |
222 static void plugin_remove_callbacks(GModule *handle) | |
223 { | |
224 GList *c = callbacks; | |
225 struct gaim_callback *g; | |
226 | |
227 debug_printf("%d callbacks to search\n", g_list_length(callbacks)); | |
228 | |
229 while (c) { | |
230 g = (struct gaim_callback *)c->data; | |
231 if (g->handle == handle) { | |
232 c = g_list_next(c); | |
233 callbacks = g_list_remove(callbacks, (gpointer)g); | |
234 debug_printf("Removing callback, %d remain\n", g_list_length(callbacks)); | |
235 } else | |
236 c = g_list_next(c); | |
237 } | |
238 } | |
239 | |
240 void gaim_signal_connect(GModule *handle, enum gaim_event which, void *func, void *data) | |
241 { | |
242 struct gaim_callback *call = g_new0(struct gaim_callback, 1); | |
243 call->handle = handle; | |
244 call->event = which; | |
245 call->function = func; | |
246 call->data = data; | |
247 | |
248 callbacks = g_list_append(callbacks, call); | |
249 debug_printf("Adding callback %d\n", g_list_length(callbacks)); | |
250 } | |
251 | |
252 void gaim_signal_disconnect(GModule *handle, enum gaim_event which, void *func) | |
253 { | |
254 GList *c = callbacks; | |
255 struct gaim_callback *g = NULL; | |
256 | |
257 while (c) { | |
258 g = (struct gaim_callback *)c->data; | |
259 if (handle == g->handle && func == g->function) { | |
260 callbacks = g_list_remove(callbacks, c->data); | |
261 g_free(g); | |
262 c = callbacks; | |
263 if (c == NULL) | |
264 break; | |
265 } | |
266 c = g_list_next(c); | |
267 } | |
268 } | |
269 | |
270 #endif /* GAIM_PLUGINS */ | |
271 | |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
272 char *event_name(enum gaim_event event) |
2393 | 273 { |
274 static char buf[128]; | |
275 switch (event) { | |
276 case event_signon: | |
277 sprintf(buf, "event_signon"); | |
278 break; | |
279 case event_signoff: | |
280 sprintf(buf, "event_signoff"); | |
281 break; | |
282 case event_away: | |
283 sprintf(buf, "event_away"); | |
284 break; | |
285 case event_back: | |
286 sprintf(buf, "event_back"); | |
287 break; | |
288 case event_im_recv: | |
289 sprintf(buf, "event_im_recv"); | |
290 break; | |
291 case event_im_send: | |
292 sprintf(buf, "event_im_send"); | |
293 break; | |
294 case event_buddy_signon: | |
295 sprintf(buf, "event_buddy_signon"); | |
296 break; | |
297 case event_buddy_signoff: | |
298 sprintf(buf, "event_buddy_signoff"); | |
299 break; | |
300 case event_buddy_away: | |
301 sprintf(buf, "event_buddy_away"); | |
302 break; | |
303 case event_buddy_back: | |
304 sprintf(buf, "event_buddy_back"); | |
305 break; | |
306 case event_buddy_idle: | |
307 sprintf(buf, "event_buddy_idle"); | |
308 break; | |
309 case event_buddy_unidle: | |
310 sprintf(buf, "event_buddy_unidle"); | |
311 break; | |
312 case event_blist_update: | |
313 sprintf(buf, "event_blist_update"); | |
314 break; | |
315 case event_chat_invited: | |
316 sprintf(buf, "event_chat_invited"); | |
317 break; | |
318 case event_chat_join: | |
319 sprintf(buf, "event_chat_join"); | |
320 break; | |
321 case event_chat_leave: | |
322 sprintf(buf, "event_chat_leave"); | |
323 break; | |
324 case event_chat_buddy_join: | |
325 sprintf(buf, "event_chat_buddy_join"); | |
326 break; | |
327 case event_chat_buddy_leave: | |
328 sprintf(buf, "event_chat_buddy_leave"); | |
329 break; | |
330 case event_chat_recv: | |
331 sprintf(buf, "event_chat_recv"); | |
332 break; | |
333 case event_chat_send: | |
334 sprintf(buf, "event_chat_send"); | |
335 break; | |
336 case event_warned: | |
337 sprintf(buf, "event_warned"); | |
338 break; | |
339 case event_error: | |
340 sprintf(buf, "event_error"); | |
341 break; | |
342 case event_quit: | |
343 sprintf(buf, "event_quit"); | |
344 break; | |
345 case event_new_conversation: | |
346 sprintf(buf, "event_new_conversation"); | |
347 break; | |
348 case event_set_info: | |
349 sprintf(buf, "event_set_info"); | |
350 break; | |
351 case event_draw_menu: | |
352 sprintf(buf, "event_draw_menu"); | |
353 break; | |
354 case event_im_displayed_sent: | |
355 sprintf(buf, "event_im_displayed_sent"); | |
356 break; | |
357 case event_im_displayed_rcvd: | |
358 sprintf(buf, "event_im_displayed_rcvd"); | |
359 break; | |
360 case event_chat_send_invite: | |
361 sprintf(buf, "event_chat_send_invite"); | |
362 break; | |
363 default: | |
364 sprintf(buf, "event_unknown"); | |
365 break; | |
366 } | |
367 return buf; | |
368 } | |
369 | |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
370 static void debug_event(enum gaim_event event, void *arg1, void *arg2, void *arg3, void *arg4) |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
371 { |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
372 #ifndef DEBUG |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
373 if (!(misc_options & OPT_MISC_DEBUG)) |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
374 return; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
375 #endif |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
376 switch (event) { |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
377 case event_quit: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
378 debug_printf("%s\n", event_name(event)); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
379 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
380 case event_signon: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
381 case event_signoff: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
382 debug_printf("%s: %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
383 ((struct gaim_connection *)arg1)->username); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
384 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
385 case event_new_conversation: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
386 debug_printf("event_new_conversation: %s\n", (char *)arg1); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
387 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
388 case event_error: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
389 debug_printf("event_error: %d\n", (int)arg1); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
390 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
391 case event_buddy_signon: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
392 case event_buddy_signoff: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
393 case event_buddy_away: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
394 case event_buddy_back: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
395 case event_buddy_idle: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
396 case event_buddy_unidle: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
397 case event_set_info: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
398 debug_printf("%s: %s %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
399 ((struct gaim_connection *)arg1)->username, (char *)arg2); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
400 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
401 case event_chat_leave: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
402 debug_printf("event_chat_leave: %s %d\n", |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
403 ((struct gaim_connection *)arg1)->username, (int)arg2); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
404 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
405 case event_im_send: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
406 case event_im_displayed_sent: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
407 debug_printf("%s: %s %s %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
408 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
409 (char *)arg2, *(char **)arg3 ? *(char **)arg3 : ""); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
410 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
411 case event_chat_join: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
412 case event_chat_buddy_join: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
413 case event_chat_buddy_leave: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
414 debug_printf("%s: %s %d %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
415 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
416 (int)arg2, (char *)arg3); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
417 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
418 case event_chat_send: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
419 debug_printf("%s: %s %d %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
420 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
421 (int)arg2, *(char **)arg3 ? *(char **)arg3 : ""); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
422 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
423 case event_away: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
424 debug_printf("%s: %s %s %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
425 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
426 (char *)arg2, (char *)arg3 ? (char *)arg3 : ""); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
427 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
428 case event_warned: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
429 debug_printf("%s: %s %s %d\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
430 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
431 (char *)arg2 ? (char *)arg2 : "", (int)arg3); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
432 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
433 case event_im_recv: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
434 debug_printf("%s: %s %s %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
435 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
436 *(char **)arg2 ? *(char **)arg2 : "", |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
437 *(char **)arg3 ? *(char **)arg3 : ""); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
438 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
439 case event_im_displayed_rcvd: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
440 debug_printf("%s: %s %s %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
441 ((struct gaim_connection *)arg1)->username, |
2464
59f61bfef2b3
[gaim-migrate @ 2477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2463
diff
changeset
|
442 (char *)arg2 ? (char *)arg2 : "", |
59f61bfef2b3
[gaim-migrate @ 2477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2463
diff
changeset
|
443 (char *)arg3 ? (char *)arg3 : ""); |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
444 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
445 case event_chat_recv: |
2465
7f36b34f8676
[gaim-migrate @ 2478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2464
diff
changeset
|
446 debug_printf("%s: %s %d %s\n", event_name(event), |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
447 ((struct gaim_connection *)arg1)->username, |
2465
7f36b34f8676
[gaim-migrate @ 2478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2464
diff
changeset
|
448 (int)arg2, |
7f36b34f8676
[gaim-migrate @ 2478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2464
diff
changeset
|
449 (char *)arg3 ? (char *)arg3 : "", |
7f36b34f8676
[gaim-migrate @ 2478]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2464
diff
changeset
|
450 (char *)arg4 ? (char *)arg4 : ""); |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
451 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
452 case event_chat_send_invite: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
453 debug_printf("%s: %s %d %s %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
454 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
455 (int)arg2, (char *)arg3, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
456 *(char **)arg4 ? *(char **)arg4 : ""); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
457 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
458 case event_chat_invited: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
459 debug_printf("%s: %s %s %s %s\n", event_name(event), |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
460 ((struct gaim_connection *)arg1)->username, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
461 (char *)arg2, (char *)arg3, |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
462 (char *)arg4 ? (char *)arg4 : ""); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
463 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
464 default: |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
465 break; |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
466 } |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
467 } |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
468 |
2393 | 469 int plugin_event(enum gaim_event event, void *arg1, void *arg2, void *arg3, void *arg4) |
470 { | |
471 #ifdef GAIM_PLUGINS | |
472 GList *c = callbacks; | |
473 struct gaim_callback *g; | |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
474 #endif |
2393 | 475 |
2463
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
476 debug_event(event, arg1, arg2, arg3, arg4); |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
477 |
0be6fadaa64f
[gaim-migrate @ 2476]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2443
diff
changeset
|
478 #ifdef GAIM_PLUGINS |
2393 | 479 while (c) { |
480 void (*zero)(void *); | |
481 void (*one)(void *, void *); | |
482 void (*two)(void *, void *, void *); | |
483 void (*three)(void *, void *, void *, void *); | |
484 void (*four)(void *, void *, void *, void *, void *); | |
485 | |
486 g = (struct gaim_callback *)c->data; | |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
487 if (g->event == event && g->function != NULL) { |
2393 | 488 switch (event) { |
489 | |
490 /* no args */ | |
491 case event_blist_update: | |
492 case event_quit: | |
493 zero = g->function; | |
494 (*zero)(g->data); | |
495 break; | |
496 | |
497 /* one arg */ | |
498 case event_signon: | |
499 case event_signoff: | |
500 case event_new_conversation: | |
501 case event_error: | |
502 one = g->function; | |
503 (*one)(arg1, g->data); | |
504 break; | |
505 | |
506 /* two args */ | |
507 case event_buddy_signon: | |
508 case event_buddy_signoff: | |
509 case event_buddy_away: | |
510 case event_buddy_back: | |
511 case event_buddy_idle: | |
512 case event_buddy_unidle: | |
513 case event_chat_leave: | |
514 case event_set_info: | |
515 case event_draw_menu: | |
516 two = g->function; | |
517 (*two)(arg1, arg2, g->data); | |
518 break; | |
519 | |
520 /* three args */ | |
521 case event_im_send: | |
522 case event_im_displayed_sent: | |
523 case event_chat_join: | |
524 case event_chat_buddy_join: | |
525 case event_chat_buddy_leave: | |
526 case event_chat_send: | |
527 case event_away: | |
528 case event_back: | |
529 case event_warned: | |
530 three = g->function; | |
531 (*three)(arg1, arg2, arg3, g->data); | |
532 break; | |
533 | |
534 /* four args */ | |
535 case event_im_recv: | |
536 case event_chat_recv: | |
537 case event_im_displayed_rcvd: | |
538 case event_chat_send_invite: | |
539 case event_chat_invited: | |
540 four = g->function; | |
541 (*four)(arg1, arg2, arg3, arg4, g->data); | |
542 break; | |
543 | |
544 default: | |
545 debug_printf("unknown event %d\n", event); | |
546 break; | |
547 } | |
548 } | |
549 c = c->next; | |
550 } | |
551 #endif /* GAIM_PLUGINS */ | |
552 #ifdef USE_PERL | |
2511
a83b4a5ffcd6
[gaim-migrate @ 2524]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2494
diff
changeset
|
553 return perl_event(event, arg1, arg2, arg3, arg4); |
2393 | 554 #else |
555 return 0; | |
556 #endif | |
557 } | |
558 | |
559 /* Calls the gaim_plugin_remove function in any loaded plugin that has one */ | |
560 #ifdef GAIM_PLUGINS | |
561 void remove_all_plugins() | |
562 { | |
563 GList *c = plugins; | |
564 struct gaim_plugin *p; | |
565 void (*gaim_plugin_remove)(); | |
566 | |
567 while (c) { | |
568 p = (struct gaim_plugin *)c->data; | |
569 if (g_module_symbol(p->handle, "gaim_plugin_remove", (gpointer *)&gaim_plugin_remove)) | |
570 (*gaim_plugin_remove)(); | |
571 g_free(p); | |
572 c = c->next; | |
573 } | |
574 } | |
575 #endif |