Mercurial > pidgin
annotate plugins/perl/perl.c @ 6485:70d5122bc3ff
[gaim-migrate @ 6999]
Removed the old event system and replaced it with a much better signal
system. There will most likely be some bugs in this, but it seems to be
working for now. Plugins can now generate their own signals, and other
plugins can find those plugins and connect to them. This could give
plugins a form of IPC. It's also useful for other things. It's rather
flexible, except for the damn marshalling, but there's no way around that
that I or the glib people can see.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 18 Aug 2003 01:03:43 +0000 |
parents | 8f94cce8faa5 |
children | cbd24b37350d |
rev | line source |
---|---|
5205 | 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 * This was taken almost exactly from X-Chat. The power of the GPL. | |
21 * Translated from X-Chat to Gaim by Eric Warmenhoven. | |
22 * Originally by Erik Scrafford <eriks@chilisoft.com>. | |
23 * X-Chat Copyright (C) 1998 Peter Zelezny. | |
24 * | |
25 */ | |
6235 | 26 |
27 #ifdef HAVE_CONFIG_H | |
28 #include <config.h> | |
29 #endif | |
30 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
31 #ifdef DEBUG |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
32 # undef DEBUG |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
33 #endif |
5205 | 34 |
35 #undef PACKAGE | |
36 | |
37 #define group perl_group | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
38 |
5205 | 39 #ifdef _WIN32 |
40 /* This took me an age to figure out.. without this __declspec(dllimport) | |
41 * will be ignored. | |
42 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
43 # define HASATTRIBUTE |
5205 | 44 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
45 |
5205 | 46 #include <EXTERN.h> |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
47 |
5205 | 48 #ifndef _SEM_SEMUN_UNDEFINED |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
49 # define HAS_UNION_SEMUN |
5205 | 50 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
51 |
5205 | 52 #include <perl.h> |
53 #include <XSUB.h> | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
54 |
5205 | 55 #ifndef _WIN32 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
56 # include <sys/mman.h> |
5205 | 57 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
58 |
5205 | 59 #undef PACKAGE |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
60 |
5205 | 61 #ifndef _WIN32 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
62 # include <dirent.h> |
5205 | 63 #else |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
64 /* We're using perl's win32 port of this */ |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
65 # define dirent direct |
5205 | 66 #endif |
67 | |
68 #undef group | |
69 | |
70 /* perl module support */ | |
71 #ifdef OLD_PERL | |
72 extern void boot_DynaLoader _((CV * cv)); | |
73 #else | |
74 extern void boot_DynaLoader _((pTHX_ CV * cv)); /* perl is so wacky */ | |
75 #endif | |
76 | |
77 #undef _ | |
78 #ifdef DEBUG | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
79 # undef DEBUG |
5205 | 80 #endif |
81 #ifdef _WIN32 | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
82 # undef pipe |
5205 | 83 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
84 |
5912
b3c412884a22
[gaim-migrate @ 6344]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5873
diff
changeset
|
85 #ifdef _WIN32 |
b3c412884a22
[gaim-migrate @ 6344]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5873
diff
changeset
|
86 #define _WIN32DEP_H_ |
b3c412884a22
[gaim-migrate @ 6344]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5873
diff
changeset
|
87 #endif |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
88 #include "internal.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
89 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
90 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
91 #include "prpl.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
92 #include "notify.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
93 #include "server.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
94 #include "sound.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
95 |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6235
diff
changeset
|
96 /* XXX CORE/UI */ |
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6235
diff
changeset
|
97 #include "gtkinternal.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
98 #include "ui.h" |
5205 | 99 |
100 #ifndef call_pv | |
101 # define call_pv(i,j) perl_call_pv((i), (j)) | |
102 #endif | |
103 | |
104 #define PERL_PLUGIN_ID "core-perl" | |
105 | |
106 struct perlscript { | |
107 char *name; | |
108 char *version; | |
109 char *shutdowncallback; /* bleh */ | |
110 GaimPlugin *plug; | |
111 }; | |
112 | |
113 struct _perl_event_handlers { | |
114 char *event_type; | |
115 char *handler_name; | |
116 GaimPlugin *plug; | |
117 }; | |
118 | |
119 struct _perl_timeout_handlers { | |
120 char *handler_name; | |
121 char *handler_args; | |
122 gint iotag; | |
123 GaimPlugin *plug; | |
124 }; | |
125 | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5408
diff
changeset
|
126 static GaimPlugin *my_plugin = NULL; |
5205 | 127 static GList *perl_list = NULL; |
128 static GList *perl_timeout_handlers = NULL; | |
129 static GList *perl_event_handlers = NULL; | |
130 static PerlInterpreter *my_perl = NULL; | |
131 static void perl_init(); | |
132 | |
133 /* dealing with gaim */ | |
134 XS(XS_GAIM_register); /* set up hooks for script */ | |
135 XS(XS_GAIM_get_info); /* version, last to attempt signon, protocol */ | |
136 XS(XS_GAIM_print); /* lemme figure this one out... */ | |
137 XS(XS_GAIM_write_to_conv); /* write into conversation window */ | |
138 | |
139 /* list stuff */ | |
140 XS(XS_GAIM_buddy_list); /* all buddies */ | |
141 XS(XS_GAIM_online_list); /* online buddies */ | |
142 | |
143 /* server stuff */ | |
144 XS(XS_GAIM_command); /* send command to server */ | |
145 XS(XS_GAIM_user_info); /* given name, return struct buddy members */ | |
146 XS(XS_GAIM_print_to_conv); /* send message to someone */ | |
147 XS(XS_GAIM_print_to_chat); /* send message to chat room */ | |
148 XS(XS_GAIM_serv_send_im); /* send message to someone (but do not display) */ | |
149 | |
150 /* handler commands */ | |
151 XS(XS_GAIM_add_event_handler); /* when servers talk */ | |
152 XS(XS_GAIM_remove_event_handler); /* remove a handler */ | |
153 XS(XS_GAIM_add_timeout_handler); /* figure it out */ | |
154 | |
155 /* play sound */ | |
156 XS(XS_GAIM_play_sound); /*play a sound */ | |
157 | |
158 static void | |
159 #ifdef OLD_PERL | |
160 xs_init() | |
161 #else | |
162 xs_init(pTHX) | |
163 #endif | |
164 { | |
165 char *file = __FILE__; | |
166 | |
167 /* This one allows dynamic loading of perl modules in perl | |
168 scripts by the 'use perlmod;' construction*/ | |
169 newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); | |
170 | |
171 /* load up all the custom Gaim perl functions */ | |
172 newXS ("GAIM::register", XS_GAIM_register, "GAIM"); | |
173 newXS ("GAIM::get_info", XS_GAIM_get_info, "GAIM"); | |
174 newXS ("GAIM::print", XS_GAIM_print, "GAIM"); | |
175 newXS ("GAIM::write_to_conv", XS_GAIM_write_to_conv, "GAIM"); | |
176 | |
177 newXS ("GAIM::buddy_list", XS_GAIM_buddy_list, "GAIM"); | |
178 newXS ("GAIM::online_list", XS_GAIM_online_list, "GAIM"); | |
179 | |
180 newXS ("GAIM::command", XS_GAIM_command, "GAIM"); | |
181 newXS ("GAIM::user_info", XS_GAIM_user_info, "GAIM"); | |
182 newXS ("GAIM::print_to_conv", XS_GAIM_print_to_conv, "GAIM"); | |
183 newXS ("GAIM::print_to_chat", XS_GAIM_print_to_chat, "GAIM"); | |
184 newXS ("GAIM::serv_send_im", XS_GAIM_serv_send_im, "GAIM"); | |
185 | |
186 newXS ("GAIM::add_event_handler", XS_GAIM_add_event_handler, "GAIM"); | |
187 newXS ("GAIM::remove_event_handler", XS_GAIM_remove_event_handler, "GAIM"); | |
188 newXS ("GAIM::add_timeout_handler", XS_GAIM_add_timeout_handler, "GAIM"); | |
189 | |
190 newXS ("GAIM::play_sound", XS_GAIM_play_sound, "GAIM"); | |
191 } | |
192 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
193 #if 0 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
194 #define COMPARE_EVENT(evt, sig, h) \ |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
195 if (!strcmp(event_name, (evt))) \ |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
196 { \ |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
197 *signal_name = (sig); \ |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
198 *handle = (h); \ |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
199 return TRUE; \ |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
200 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
201 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
202 static gboolean |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
203 convert_event_to_signal(const char *event_name, const char **signal_name, |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
204 void **handle) |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
205 { |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
206 void *conn_handle = gaim_connections_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
207 void *account_handle = gaim_accounts_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
208 void *conv_handle = gaim_conversations_get_handle(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
209 void *blist_handle = gaim_get_blist(); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
210 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
211 COMPARE_EVENT("event_signon", "signed-on", conn_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
212 COMPARE_EVENT("event_signoff", "signed-off", conn_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
213 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
214 COMPARE_EVENT("event_away", "account-away", account_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
215 COMPARE_EVENT("event_back", "account-back", account_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
216 COMPARE_EVENT("event_warned", "account-warned", account_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
217 COMPARE_EVENT("event_set_info", "account-set-info", account_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
218 COMPARE_EVENT("event_connecting", "account-connecting", account_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
219 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
220 COMPARE_EVENT("event_im_recv", "received-im-msg", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
221 COMPARE_EVENT("event_im_send", "sent-im-msg", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
222 COMPARE_EVENT("event_chat_invited", "chat-invited", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
223 COMPARE_EVENT("event_chat_join", "chat-joined", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
224 COMPARE_EVENT("event_chat_leave", "chat-left", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
225 COMPARE_EVENT("event_chat_buddy_join", "chat-buddy-joined", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
226 COMPARE_EVENT("event_chat_buddy_leave", "chat-buddy-left", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
227 COMPARE_EVENT("event_chat_recv", "received-chat-msg", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
228 COMPARE_EVENT("event_chat_send", "sent-chat-msg", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
229 COMPARE_EVENT("event_new_conversation", "conversation-created", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
230 conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
231 COMPARE_EVENT("event_im_displayed_sent", "sending-im-msg", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
232 COMPARE_EVENT("event_im_displayed_rcvd", NULL, NULL); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
233 COMPARE_EVENT("event_chat_send_invite", "chat-inviting-user", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
234 COMPARE_EVENT("event_got_typing", "buddy-typing", conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
235 COMPARE_EVENT("event_del_conversation", "deleting-conversation", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
236 conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
237 COMPARE_EVENT("event_conversation_switch", "conversation-switched", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
238 conv_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
239 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
240 COMPARE_EVENT("event_buddy_signon", "buddy-signed-on", blist_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
241 COMPARE_EVENT("event_buddy_signoff", "buddy-signed-off", blist_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
242 COMPARE_EVENT("event_buddy_away", "buddy-away", blist_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
243 COMPARE_EVENT("event_buddy_back", "buddy-back", blist_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
244 COMPARE_EVENT("event_buddy_idle", "buddy-idle", blist_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
245 COMPARE_EVENT("event_buddy_unidle", "buddy-unidle", blist_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
246 COMPARE_EVENT("event_blist_update", "update-idle", blist_handle); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
247 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
248 COMPARE_EVENT("event_quit", "quitting", gaim_get_core()); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
249 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
250 *signal_name = NULL; |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
251 *handle = NULL; |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
252 |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
253 return FALSE; |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
254 } |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
255 #endif |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
256 |
5205 | 257 static char * |
258 escape_quotes(const char *buf) | |
259 { | |
260 static char *tmp_buf = NULL; | |
261 const char *i; | |
262 char *j; | |
263 | |
264 if (tmp_buf) | |
265 g_free(tmp_buf); | |
266 | |
267 tmp_buf = g_malloc(strlen(buf) * 2 + 1); | |
268 | |
269 for (i = buf, j = tmp_buf; *i; i++, j++) { | |
270 if (*i == '\'' || *i == '\\') | |
271 *j++ = '\\'; | |
272 | |
273 *j = *i; | |
274 } | |
275 | |
276 *j = '\0'; | |
277 | |
278 return tmp_buf; | |
279 } | |
280 | |
281 /* | |
282 2003/02/06: execute_perl modified by Mark Doliner <mark@kingant.net> | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
283 Pass parameters by pushing them onto the stack rather than |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
284 passing an array of strings. This way, perl scripts can |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
285 modify the parameters and we can get the changed values |
5205 | 286 and then shoot ourselves. I mean, uh, use them. |
287 | |
288 2001/06/14: execute_perl replaced by Martin Persson <mep@passagen.se> | |
289 previous use of perl_eval leaked memory, replaced with | |
290 a version that uses perl_call instead | |
291 | |
292 30/11/2002: execute_perl modified by Eric Timme <timothy@voidnet.com> | |
293 args changed to char** so that we can have preparsed | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
294 arguments again, and many headaches ensued! This essentially |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
295 means we replaced one hacked method with a messier hacked |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
296 method out of perceived necessity. Formerly execute_perl |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
297 required a single char_ptr, and it would insert it into an |
5205 | 298 array of character pointers and NULL terminate the new array. |
299 Now we have to pass in pre-terminated character pointer arrays | |
300 to accomodate functions that want to pass in multiple arguments. | |
301 | |
302 Previously arguments were preparsed because an argument list | |
303 was constructed in the form 'arg one','arg two' and was | |
304 executed via a call like &funcname(arglist) (see .59.x), so | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
305 the arglist was magically pre-parsed because of the method. |
5205 | 306 With Martin Persson's change to perl_call we now need to |
307 use a null terminated list of character pointers for arguments | |
308 if we wish them to be parsed. Lacking a better way to allow | |
309 for both single arguments and many I created a NULL terminated | |
310 array in every function that called execute_perl and passed | |
311 that list into the function. In the former version a single | |
312 character pointer was passed in, and was placed into an array | |
313 of character pointers with two elements, with a NULL element | |
314 tacked onto the back, but this method no longer seemed prudent. | |
315 | |
316 Enhancements in the future might be to get rid of pre-declaring | |
317 the array sizes? I am not comfortable enough with this | |
318 subject to attempt it myself and hope it to stand the test | |
319 of time. | |
320 */ | |
321 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
322 static int |
5205 | 323 execute_perl(const char *function, int argc, char **args) |
324 { | |
325 int count = 0, i, ret_value = 1; | |
326 SV *sv_args[argc]; | |
327 STRLEN na; | |
328 | |
329 /* | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
330 * Set up the perl environment, push arguments onto the |
5205 | 331 * perl stack, then call the given function |
332 */ | |
333 dSP; | |
334 ENTER; | |
335 SAVETMPS; | |
336 PUSHMARK(sp); | |
337 | |
338 for (i = 0; i < argc; i++) { | |
339 if (args[i]) { | |
340 sv_args[i] = sv_2mortal(newSVpv(args[i], 0)); | |
341 XPUSHs(sv_args[i]); | |
342 } | |
343 } | |
344 | |
345 PUTBACK; | |
346 count = call_pv(function, G_EVAL | G_SCALAR); | |
347 SPAGAIN; | |
348 | |
349 /* | |
350 * Check for "die," make sure we have 1 argument, and set our | |
351 * return value. | |
352 */ | |
353 if (SvTRUE(ERRSV)) { | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
354 gaim_debug(GAIM_DEBUG_ERROR, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
355 "Perl function %s exited abnormally: %s\n", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
356 function, SvPV(ERRSV, na)); |
5205 | 357 POPs; |
358 } | |
359 else if (count != 1) { | |
360 /* | |
361 * This should NEVER happen. G_SCALAR ensures that we WILL | |
362 * have 1 parameter. | |
363 */ | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
364 gaim_debug(GAIM_DEBUG_ERROR, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
365 "Perl error from %s: expected 1 return value, " |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
366 "but got %d\n", function, count); |
5205 | 367 } |
368 else | |
369 ret_value = POPi; | |
370 | |
371 /* Check for changed arguments */ | |
372 for (i = 0; i < argc; i++) { | |
373 if (args[i] && strcmp(args[i], SvPVX(sv_args[i]))) { | |
374 /* | |
375 * Shizzel. So the perl script changed one of the parameters, | |
376 * and we want this change to affect the original parameters. | |
377 * args[i] is just a tempory little list of pointers. We don't | |
378 * want to free args[i] here because the new parameter doesn't | |
379 * overwrite the data that args[i] points to. That is done by | |
380 * the function that called execute_perl. I'm not explaining this | |
381 * very well. See, it's aggregate... Oh, but if 2 perl scripts | |
382 * both modify the data, _that's_ a memleak. This is really kind | |
383 * of hackish. I should fix it. Look how long this comment is. | |
384 * Holy crap. | |
385 */ | |
386 args[i] = g_strdup(SvPV(sv_args[i], na)); | |
387 } | |
388 } | |
389 | |
390 PUTBACK; | |
391 FREETMPS; | |
392 LEAVE; | |
393 | |
394 return ret_value; | |
395 } | |
396 | |
397 static void | |
398 perl_unload_file(GaimPlugin *plug) | |
399 { | |
400 char *atmp[2] = { "", NULL }; | |
401 struct perlscript *scp = NULL; | |
402 struct _perl_timeout_handlers *thn; | |
403 struct _perl_event_handlers *ehn; | |
404 GList *pl; | |
405 | |
406 for (pl = perl_list; pl != NULL; pl = pl->next) { | |
407 scp = pl->data; | |
408 | |
409 if (scp->plug == plug) { | |
410 perl_list = g_list_remove(perl_list, scp); | |
411 | |
412 if (scp->shutdowncallback[0]) | |
413 execute_perl(scp->shutdowncallback, 1, atmp); | |
414 | |
415 g_free(scp->name); | |
416 g_free(scp->version); | |
417 g_free(scp->shutdowncallback); | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
418 g_free(scp); |
5205 | 419 |
420 break; | |
421 } | |
422 } | |
423 | |
424 for (pl = perl_timeout_handlers; pl != NULL; pl = pl->next) { | |
425 thn = pl->data; | |
426 | |
427 if (thn && thn->plug == plug) { | |
428 perl_timeout_handlers = g_list_remove(perl_timeout_handlers, thn); | |
429 | |
430 g_source_remove(thn->iotag); | |
431 g_free(thn->handler_args); | |
432 g_free(thn->handler_name); | |
433 g_free(thn); | |
434 } | |
435 } | |
436 | |
437 for (pl = perl_event_handlers; pl != NULL; pl = pl->next) { | |
438 ehn = pl->data; | |
439 | |
440 if (ehn && ehn->plug == plug) { | |
441 perl_event_handlers = g_list_remove(perl_event_handlers, ehn); | |
442 | |
443 g_free(ehn->event_type); | |
444 g_free(ehn->handler_name); | |
445 g_free(ehn); | |
446 } | |
447 } | |
448 } | |
449 | |
450 static int | |
451 perl_load_file(char *script_name, GaimPlugin *plugin) | |
452 { | |
453 char *atmp[2] = { script_name, NULL }; | |
454 GList *s; | |
455 struct perlscript *scp; | |
456 int ret; | |
457 | |
458 if (my_perl == NULL) | |
459 perl_init(); | |
460 | |
461 plugin->handle = plugin->path; | |
462 | |
463 ret = execute_perl("load_n_eval", 1, atmp); | |
464 | |
465 for (s = perl_list; s != NULL; s = s->next) { | |
466 scp = s->data; | |
467 | |
468 if (!strcmp(scp->name, plugin->info->name) && | |
469 !strcmp(scp->version, plugin->info->version)) { | |
470 | |
471 break; | |
472 } | |
473 } | |
474 | |
475 if (!s) { | |
476 plugin->error = g_strdup(_("GAIM::register not called with " | |
477 "proper arguments. Consult PERL-HOWTO.")); | |
478 | |
479 return 0; | |
480 } | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
481 |
5205 | 482 return ret; |
483 } | |
484 | |
485 static void | |
486 perl_init(void) | |
487 { | |
488 /* changed the name of the variable from load_file to | |
489 perl_definitions since now it does much more than defining | |
490 the load_file sub. Moreover, deplaced the initialisation to | |
491 the xs_init function. (TheHobbit)*/ | |
492 char *perl_args[] = { "", "-e", "0", "-w" }; | |
493 char perl_definitions[] = | |
494 { | |
495 /* We use to function one to load a file the other to | |
496 execute the string obtained from the first and holding | |
497 the file conents. This allows to have a realy local $/ | |
498 without introducing temp variables to hold the old | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
499 value. Just a question of style:) */ |
5205 | 500 "sub load_file{" |
501 "my $f_name=shift;" | |
502 "local $/=undef;" | |
503 "open FH,$f_name or return \"__FAILED__\";" | |
504 "$_=<FH>;" | |
505 "close FH;" | |
506 "return $_;" | |
507 "}" | |
508 "sub load_n_eval{" | |
509 "my $f_name=shift;" | |
510 "my $strin=load_file($f_name);" | |
511 "return 2 if($strin eq \"__FAILED__\");" | |
512 "eval $strin;" | |
513 "if($@){" | |
514 /*" #something went wrong\n"*/ | |
515 "GAIM::print(\"Errors loading file $f_name:\\n\",\"$@\");" | |
516 "return 1;" | |
517 "}" | |
518 "return 0;" | |
519 "}" | |
520 }; | |
521 | |
522 my_perl = perl_alloc(); | |
523 perl_construct(my_perl); | |
524 #ifdef DEBUG | |
525 perl_parse(my_perl, xs_init, 4, perl_args, NULL); | |
526 #else | |
527 perl_parse(my_perl, xs_init, 3, perl_args, NULL); | |
528 #endif | |
529 #ifdef HAVE_PERL_EVAL_PV | |
530 eval_pv(perl_definitions, TRUE); | |
531 #else | |
532 perl_eval_pv(perl_definitions, TRUE); /* deprecated */ | |
533 #endif | |
534 } | |
535 | |
536 static void | |
537 perl_end(void) | |
538 { | |
539 char *atmp[2] = { "", NULL }; | |
540 struct perlscript *scp; | |
541 struct _perl_timeout_handlers *thn; | |
542 struct _perl_event_handlers *ehn; | |
543 | |
544 while (perl_list) { | |
545 scp = perl_list->data; | |
546 perl_list = g_list_remove(perl_list, scp); | |
547 | |
548 if (scp->shutdowncallback[0]) | |
549 execute_perl(scp->shutdowncallback, 1, atmp); | |
550 | |
551 g_free(scp->name); | |
552 g_free(scp->version); | |
553 g_free(scp->shutdowncallback); | |
554 g_free(scp); | |
555 } | |
556 | |
557 while (perl_timeout_handlers) { | |
558 thn = perl_timeout_handlers->data; | |
559 perl_timeout_handlers = g_list_remove(perl_timeout_handlers, thn); | |
560 g_source_remove(thn->iotag); | |
561 g_free(thn->handler_args); | |
562 g_free(thn->handler_name); | |
563 g_free(thn); | |
564 } | |
565 | |
566 while (perl_event_handlers) { | |
567 ehn = perl_event_handlers->data; | |
568 perl_event_handlers = g_list_remove(perl_event_handlers, ehn); | |
569 g_free(ehn->event_type); | |
570 g_free(ehn->handler_name); | |
571 g_free(ehn); | |
572 } | |
573 | |
574 if (my_perl != NULL) { | |
575 perl_destruct(my_perl); | |
576 perl_free(my_perl); | |
577 my_perl = NULL; | |
578 } | |
579 } | |
580 | |
581 XS (XS_GAIM_register) | |
582 { | |
583 char *name, *ver, *callback, *unused; /* exactly like X-Chat, eh? :) */ | |
584 unsigned int junk; | |
585 struct perlscript *scp; | |
586 GaimPlugin *plug = NULL; | |
587 GList *pl; | |
588 | |
589 dXSARGS; | |
590 items = 0; | |
591 | |
592 name = SvPV(ST(0), junk); | |
593 ver = SvPV(ST(1), junk); | |
594 callback = SvPV(ST(2), junk); | |
595 unused = SvPV(ST(3), junk); | |
596 | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
597 gaim_debug(GAIM_DEBUG_INFO, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
598 "GAIM::register(%s, %s)\n", name, ver); |
5205 | 599 |
600 for (pl = gaim_plugins_get_all(); pl != NULL; pl = pl->next) { | |
601 plug = pl->data; | |
602 | |
603 if (!strcmp(name, plug->info->name) && | |
604 !strcmp(ver, plug->info->version)) { | |
605 | |
606 break; | |
607 } | |
608 | |
609 plug = NULL; | |
610 } | |
611 | |
612 if (plug) { | |
613 scp = g_new0(struct perlscript, 1); | |
614 scp->name = g_strdup(name); | |
615 scp->version = g_strdup(ver); | |
616 scp->shutdowncallback = g_strdup(callback); | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
617 scp->plug = plug; |
5205 | 618 perl_list = g_list_append(perl_list, scp); |
619 XST_mPV(0, plug->path); | |
620 } | |
621 else | |
622 XST_mPV(0, NULL); | |
623 | |
624 XSRETURN (1); | |
625 } | |
626 | |
627 XS (XS_GAIM_get_info) | |
628 { | |
629 int i = 0; | |
630 dXSARGS; | |
631 items = 0; | |
632 | |
633 switch(SvIV(ST(0))) { | |
634 case 0: | |
635 XST_mPV(0, VERSION); | |
636 i = 1; | |
637 break; | |
638 | |
639 case 1: | |
640 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
641 GList *c = gaim_connections_get_all(); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
642 GaimConnection *gc; |
5205 | 643 |
644 while (c) { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
645 gc = (GaimConnection *)c->data; |
5205 | 646 XST_mIV(i++, (guint)gc); |
647 c = c->next; | |
648 } | |
649 } | |
650 break; | |
651 | |
652 case 2: | |
653 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
654 GaimConnection *gc = |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
655 (GaimConnection *)SvIV(ST(1)); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
656 GaimAccount *account = gaim_connection_get_account(gc); |
5205 | 657 |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
658 if (g_list_find(gaim_connections_get_all(), gc)) |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
659 XST_mIV(i++, gaim_account_get_protocol(account)); |
5205 | 660 else |
661 XST_mIV(i++, -1); | |
662 } | |
663 break; | |
664 | |
665 case 3: | |
666 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
667 GaimConnection *gc = |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
668 (GaimConnection *)SvIV(ST(1)); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
669 GaimAccount *account = gaim_connection_get_account(gc); |
5205 | 670 |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
671 if (g_list_find(gaim_connections_get_all(), gc)) |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
672 XST_mPV(i++, gaim_account_get_username(account)); |
5205 | 673 else |
674 XST_mPV(i++, ""); | |
675 } | |
676 break; | |
677 | |
678 case 4: | |
679 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
680 GaimConnection *gc = |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
681 (GaimConnection *)SvIV(ST(1)); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
682 GaimAccount *account = gaim_connection_get_account(gc); |
5205 | 683 |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
684 if (g_list_find(gaim_connections_get_all(), gc)) |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
685 XST_mIV(i++, g_list_index(gaim_accounts_get_all(), |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
686 account)); |
5205 | 687 else |
688 XST_mIV(i++, -1); | |
689 } | |
690 break; | |
691 | |
692 case 5: | |
693 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
694 GList *a = gaim_accounts_get_all(); |
5205 | 695 while (a) { |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
696 GaimAccount *account = a->data; |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
697 XST_mPV(i++, gaim_account_get_username(account)); |
5205 | 698 a = a->next; |
699 } | |
700 } | |
701 break; | |
702 | |
703 case 6: | |
704 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
705 GList *a = gaim_accounts_get_all(); |
5205 | 706 while (a) { |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
707 GaimAccount *account = a->data; |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
708 XST_mIV(i++, gaim_account_get_protocol(account)); |
5205 | 709 a = a->next; |
710 } | |
711 } | |
712 break; | |
713 | |
714 case 7: | |
715 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
716 GaimConnection *gc = |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
717 (GaimConnection *)SvIV(ST(1)); |
5205 | 718 |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
719 if (g_list_find(gaim_connections_get_all(), gc)) |
5205 | 720 XST_mPV(i++, gc->prpl->info->name); |
721 else | |
722 XST_mPV(i++, "Unknown"); | |
723 } | |
724 break; | |
725 | |
726 default: | |
727 XST_mPV(0, "Error2"); | |
728 i = 1; | |
729 } | |
730 | |
731 XSRETURN(i); | |
732 } | |
733 | |
734 XS (XS_GAIM_print) | |
735 { | |
736 char *title; | |
737 char *message; | |
738 unsigned int junk; | |
739 dXSARGS; | |
740 items = 0; | |
741 | |
742 title = SvPV(ST(0), junk); | |
743 message = SvPV(ST(1), junk); | |
5445
ad9b6e65713b
[gaim-migrate @ 5827]
Christian Hammond <chipx86@chipx86.com>
parents:
5436
diff
changeset
|
744 gaim_notify_info(my_plugin, NULL, title, message); |
5205 | 745 XSRETURN(0); |
746 } | |
747 | |
748 XS (XS_GAIM_buddy_list) | |
749 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
750 GaimConnection *gc; |
5205 | 751 struct buddy *buddy; |
752 struct group *g; | |
753 GaimBlistNode *gnode,*bnode; | |
754 int i = 0; | |
755 dXSARGS; | |
756 items = 0; | |
757 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
758 gc = (GaimConnection *)SvIV(ST(0)); |
5205 | 759 |
760 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
761 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
762 continue; | |
763 g = (struct group *)gnode; | |
764 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
765 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
766 continue; | |
767 buddy = (struct buddy *)bnode; | |
768 if(buddy->account == gc->account) | |
769 XST_mPV(i++, buddy->name); | |
770 } | |
771 } | |
772 XSRETURN(i); | |
773 } | |
774 | |
775 XS (XS_GAIM_online_list) | |
776 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
777 GaimConnection *gc; |
5205 | 778 struct buddy *b; |
779 struct group *g; | |
780 GaimBlistNode *gnode,*bnode; | |
781 int i = 0; | |
782 dXSARGS; | |
783 items = 0; | |
784 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
785 gc = (GaimConnection *)SvIV(ST(0)); |
5205 | 786 |
787 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
788 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
789 continue; | |
790 g = (struct group *)gnode; | |
791 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
792 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
793 continue; | |
794 b = (struct buddy *)bnode; | |
795 if (b->account == gc->account && GAIM_BUDDY_IS_ONLINE(b)) XST_mPV(i++, b->name); | |
796 } | |
797 } | |
798 XSRETURN(i); | |
799 } | |
800 | |
801 XS (XS_GAIM_command) | |
802 { | |
803 unsigned int junk; | |
804 char *command = NULL; | |
805 dXSARGS; | |
806 items = 0; | |
807 | |
808 command = SvPV(ST(0), junk); | |
809 if (!command) XSRETURN(0); | |
810 if (!strncasecmp(command, "signon", 6)) { | |
811 int index = SvIV(ST(1)); | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
812 if (g_list_nth_data(gaim_accounts_get_all(), index)) |
6036 | 813 gaim_account_connect(g_list_nth_data(gaim_accounts_get_all(), index)); |
5205 | 814 } else if (!strncasecmp(command, "signoff", 7)) { |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
815 GaimConnection *gc = (GaimConnection *)SvIV(ST(1)); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
816 if (g_list_find(gaim_connections_get_all(), gc)) |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
817 gaim_connection_disconnect(gc); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
818 else |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
819 gaim_connections_disconnect_all(); |
5205 | 820 } else if (!strncasecmp(command, "info", 4)) { |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
821 GaimConnection *gc = (GaimConnection *)SvIV(ST(1)); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
822 if (g_list_find(gaim_connections_get_all(), gc)) |
5205 | 823 serv_set_info(gc, SvPV(ST(2), junk)); |
824 } else if (!strncasecmp(command, "away", 4)) { | |
825 char *message = SvPV(ST(1), junk); | |
826 static struct away_message a; | |
827 g_snprintf(a.message, sizeof(a.message), "%s", message); | |
828 do_away_message(NULL, &a); | |
829 } else if (!strncasecmp(command, "back", 4)) { | |
5775 | 830 do_im_back(NULL, NULL); |
5205 | 831 } else if (!strncasecmp(command, "idle", 4)) { |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
832 GList *c = gaim_connections_get_all(); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
833 GaimConnection *gc; |
5205 | 834 |
835 while (c) { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
836 gc = (GaimConnection *)c->data; |
5205 | 837 serv_set_idle(gc, SvIV(ST(1))); |
838 c = c->next; | |
839 } | |
840 } else if (!strncasecmp(command, "warn", 4)) { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
841 GList *c = gaim_connections_get_all(); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
842 GaimConnection *gc; |
5205 | 843 |
844 while (c) { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
845 gc = (GaimConnection *)c->data; |
5205 | 846 serv_warn(gc, SvPV(ST(1), junk), SvIV(ST(2))); |
847 c = c->next; | |
848 } | |
849 } | |
850 | |
851 XSRETURN(0); | |
852 } | |
853 | |
854 XS (XS_GAIM_user_info) | |
855 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
856 GaimConnection *gc; |
5205 | 857 unsigned int junk; |
858 struct buddy *buddy = NULL; | |
859 dXSARGS; | |
860 items = 0; | |
861 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
862 gc = (GaimConnection *)SvIV(ST(0)); |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
863 if (g_list_find(gaim_connections_get_all(), gc)) |
5205 | 864 buddy = gaim_find_buddy(gc->account, SvPV(ST(1), junk)); |
865 | |
866 if (!buddy) | |
867 XSRETURN(0); | |
868 XST_mPV(0, buddy->name); | |
869 XST_mPV(1, gaim_get_buddy_alias(buddy)); | |
870 XST_mPV(2, GAIM_BUDDY_IS_ONLINE(buddy) ? "Online" : "Offline"); | |
871 XST_mIV(3, buddy->evil); | |
872 XST_mIV(4, buddy->signon); | |
873 XST_mIV(5, buddy->idle); | |
874 XSRETURN(6); | |
875 } | |
876 | |
877 XS (XS_GAIM_write_to_conv) | |
878 { | |
879 char *nick, *who, *what; | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5586
diff
changeset
|
880 GaimConversation *c; |
5205 | 881 int junk; |
882 int send, wflags; | |
883 dXSARGS; | |
884 items = 0; | |
885 | |
886 nick = SvPV(ST(0), junk); | |
887 send = SvIV(ST(1)); | |
888 what = SvPV(ST(2), junk); | |
889 who = SvPV(ST(3), junk); | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
890 |
5205 | 891 if (!*who) who=NULL; |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
892 |
5205 | 893 switch (send) { |
894 case 0: wflags=WFLAG_SEND; break; | |
895 case 1: wflags=WFLAG_RECV; break; | |
896 case 2: wflags=WFLAG_SYSTEM; break; | |
897 default: wflags=WFLAG_RECV; | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
898 } |
5205 | 899 |
900 c = gaim_find_conversation(nick); | |
901 | |
902 if (!c) | |
903 c = gaim_conversation_new(GAIM_CONV_IM, NULL, nick); | |
904 | |
905 gaim_conversation_write(c, who, what, -1, wflags, time(NULL)); | |
906 XSRETURN(0); | |
907 } | |
908 | |
909 XS (XS_GAIM_serv_send_im) | |
910 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
911 GaimConnection *gc; |
5205 | 912 char *nick, *what; |
913 int isauto; | |
914 int junk; | |
915 dXSARGS; | |
916 items = 0; | |
917 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
918 gc = (GaimConnection *)SvIV(ST(0)); |
5205 | 919 nick = SvPV(ST(1), junk); |
920 what = SvPV(ST(2), junk); | |
921 isauto = SvIV(ST(3)); | |
922 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
923 if (!g_list_find(gaim_connections_get_all(), gc)) { |
5205 | 924 XSRETURN(0); |
925 return; | |
926 } | |
927 serv_send_im(gc, nick, what, -1, isauto); | |
928 XSRETURN(0); | |
929 } | |
930 | |
931 XS (XS_GAIM_print_to_conv) | |
932 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
933 GaimConnection *gc; |
5205 | 934 char *nick, *what; |
935 int isauto; | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5586
diff
changeset
|
936 GaimConversation *c; |
5205 | 937 unsigned int junk; |
938 dXSARGS; | |
939 items = 0; | |
940 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
941 gc = (GaimConnection *)SvIV(ST(0)); |
5205 | 942 nick = SvPV(ST(1), junk); |
943 what = SvPV(ST(2), junk); | |
944 isauto = SvIV(ST(3)); | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
945 if (!g_list_find(gaim_connections_get_all(), gc)) { |
5205 | 946 XSRETURN(0); |
947 return; | |
948 } | |
949 | |
950 c = gaim_find_conversation(nick); | |
951 | |
952 if (!c) | |
953 c = gaim_conversation_new(GAIM_CONV_IM, gc->account, nick); | |
954 else | |
955 gaim_conversation_set_account(c, gc->account); | |
956 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
957 gaim_conversation_write(c, NULL, what, -1, |
5205 | 958 (WFLAG_SEND | (isauto ? WFLAG_AUTO : 0)), time(NULL)); |
959 serv_send_im(gc, nick, what, -1, isauto ? IM_FLAG_AWAY : 0); | |
960 XSRETURN(0); | |
961 } | |
962 | |
963 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
964 |
5205 | 965 XS (XS_GAIM_print_to_chat) |
966 { | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
967 GaimConnection *gc; |
5205 | 968 int id; |
969 char *what; | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5586
diff
changeset
|
970 GaimConversation *b = NULL; |
5205 | 971 GSList *bcs; |
972 unsigned int junk; | |
973 dXSARGS; | |
974 items = 0; | |
975 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
976 gc = (GaimConnection *)SvIV(ST(0)); |
5205 | 977 id = SvIV(ST(1)); |
978 what = SvPV(ST(2), junk); | |
979 | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
980 if (!g_list_find(gaim_connections_get_all(), gc)) { |
5205 | 981 XSRETURN(0); |
982 return; | |
983 } | |
984 bcs = gc->buddy_chats; | |
985 while (bcs) { | |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5586
diff
changeset
|
986 b = (GaimConversation *)bcs->data; |
5205 | 987 |
988 if (gaim_chat_get_id(gaim_conversation_get_chat_data(b)) == id) | |
989 break; | |
990 bcs = bcs->next; | |
991 b = NULL; | |
992 } | |
993 if (b) | |
994 serv_chat_send(gc, id, what); | |
995 XSRETURN(0); | |
996 } | |
997 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
998 #if 0 |
5205 | 999 static int |
1000 perl_event(GaimEvent event, void *unused, va_list args) | |
1001 { | |
1002 char *buf[5] = { NULL, NULL, NULL, NULL, NULL }; /* Maximum of 5 args */ | |
1003 void *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL, *arg5 = NULL; | |
1004 char tmpbuf1[16], tmpbuf2[16], tmpbuf3[1]; | |
1005 GList *handler; | |
1006 struct _perl_event_handlers *data; | |
1007 int handler_return; | |
1008 | |
1009 arg1 = va_arg(args, void *); | |
1010 arg2 = va_arg(args, void *); | |
1011 arg3 = va_arg(args, void *); | |
1012 arg4 = va_arg(args, void *); | |
1013 arg5 = va_arg(args, void *); | |
1014 | |
1015 tmpbuf1[0] = '\0'; | |
1016 tmpbuf2[0] = '\0'; | |
1017 tmpbuf3[0] = '\0'; | |
1018 | |
1019 /* Make a pretty array of char*'s with which to call perl functions */ | |
1020 switch (event) { | |
5408
2af3224b329a
[gaim-migrate @ 5784]
Christian Hammond <chipx86@chipx86.com>
parents:
5227
diff
changeset
|
1021 case event_connecting: |
5205 | 1022 case event_signon: |
1023 case event_signoff: | |
1024 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1025 buf[0] = tmpbuf1; | |
1026 break; | |
1027 case event_away: | |
1028 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1029 buf[0] = tmpbuf1; | |
5586
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
1030 buf[1] = ((GaimConnection *)arg1)->away ? |
cde28f5c47d4
[gaim-migrate @ 5990]
Christian Hammond <chipx86@chipx86.com>
parents:
5470
diff
changeset
|
1031 ((GaimConnection *)arg1)->away : tmpbuf2; |
5205 | 1032 break; |
1033 case event_im_recv: | |
1034 if (!*(char**)arg2 || !*(char**)arg3) return 1; | |
1035 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1036 buf[0] = tmpbuf1; | |
1037 buf[1] = *(char **)arg2; | |
1038 buf[2] = *(char **)arg3; | |
1039 break; | |
1040 case event_im_send: | |
1041 if (!*(char**)arg3) return 1; | |
1042 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1043 buf[0] = tmpbuf1; | |
1044 buf[1] = arg2 ? arg2 : tmpbuf3; | |
1045 buf[2] = *(char **)arg3; | |
1046 break; | |
1047 case event_buddy_signon: | |
1048 case event_buddy_signoff: | |
1049 case event_set_info: | |
1050 case event_buddy_away: | |
1051 case event_buddy_back: | |
1052 case event_buddy_idle: | |
1053 case event_buddy_unidle: | |
1054 case event_got_typing: | |
1055 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1056 buf[0] = tmpbuf1; | |
1057 buf[1] = arg2; | |
1058 break; | |
1059 case event_chat_invited: | |
1060 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1061 buf[0] = tmpbuf1; | |
1062 buf[1] = arg2; | |
1063 buf[2] = arg3; | |
1064 buf[3] = arg4; | |
1065 break; | |
1066 case event_chat_join: | |
1067 case event_chat_buddy_join: | |
1068 case event_chat_buddy_leave: | |
1069 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1070 buf[0] = tmpbuf1; | |
1071 g_snprintf(tmpbuf2, 16, "%d", (int)arg2); | |
1072 buf[1] = tmpbuf2; | |
1073 buf[2] = arg3; | |
1074 break; | |
1075 case event_chat_leave: | |
1076 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1077 buf[0] = tmpbuf1; | |
1078 g_snprintf(tmpbuf2, 16, "%d", (int)arg2); | |
1079 buf[1] = tmpbuf2; | |
1080 break; | |
1081 case event_chat_recv: | |
1082 if (!*(char**)arg3 || !*(char**)arg4) return 1; | |
1083 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1084 buf[0] = tmpbuf1; | |
1085 g_snprintf(tmpbuf2, 16, "%d", (int)arg2); | |
1086 buf[1] = tmpbuf2; | |
1087 buf[2] = *(char **)arg3; | |
1088 buf[3] = *(char **)arg4; | |
1089 break; | |
1090 case event_chat_send_invite: | |
1091 if (!*(char**)arg4) return 1; | |
1092 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1093 buf[0] = tmpbuf1; | |
1094 g_snprintf(tmpbuf2, 16, "%d", (int)arg2); | |
1095 buf[1] = tmpbuf2; | |
1096 buf[2] = arg3; | |
1097 buf[3] = *(char **)arg4; | |
1098 break; | |
1099 case event_chat_send: | |
1100 if (!*(char**)arg3) return 1; | |
1101 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1102 buf[0] = tmpbuf1; | |
1103 g_snprintf(tmpbuf2, 16, "%d", (int)arg2); | |
1104 buf[1] = tmpbuf2; | |
1105 buf[2] = *(char **)arg3; | |
1106 break; | |
1107 case event_warned: | |
1108 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1109 buf[0] = tmpbuf1; | |
1110 buf[1] = arg2 ? arg2 : tmpbuf3; | |
1111 g_snprintf(tmpbuf2, 16, "%d", (int)arg3); | |
1112 buf[2] = tmpbuf2; | |
1113 break; | |
1114 case event_quit: | |
1115 case event_blist_update: | |
1116 buf[0] = tmpbuf3; | |
1117 break; | |
1118 case event_new_conversation: | |
1119 case event_del_conversation: | |
6100 | 1120 case event_conversation_switch: |
5205 | 1121 buf[0] = arg1; |
1122 break; | |
1123 case event_im_displayed_sent: | |
1124 if (!*(char**)arg3) return 1; | |
1125 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1126 buf[0] = tmpbuf1; | |
1127 buf[1] = arg2; | |
1128 buf[2] = *(char **)arg3; | |
1129 break; | |
1130 case event_im_displayed_rcvd: | |
1131 g_snprintf(tmpbuf1, 16, "%lu", (unsigned long)arg1); | |
1132 buf[0] = tmpbuf1; | |
1133 buf[1] = arg2; | |
1134 buf[2] = arg3 ? arg3 : tmpbuf3; | |
1135 break; | |
1136 case event_draw_menu: | |
1137 /* we can't handle this usefully without gtk/perl bindings */ | |
1138 return 0; | |
1139 default: | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1140 gaim_debug(GAIM_DEBUG_WARNING, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1141 "Someone forgot to handle %s in the perl binding\n", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1142 gaim_event_get_name(event)); |
5205 | 1143 return 0; |
1144 } | |
1145 | |
1146 /* Call any applicable functions */ | |
1147 for (handler = perl_event_handlers; | |
1148 handler != NULL; | |
1149 handler = handler->next) { | |
1150 | |
1151 data = handler->data; | |
1152 | |
1153 if (!strcmp(gaim_event_get_name(event), data->event_type)) { | |
1154 | |
1155 handler_return = execute_perl(data->handler_name, 5, buf); | |
1156 | |
1157 if (handler_return) | |
1158 return handler_return; | |
1159 } | |
1160 } | |
1161 | |
1162 /* Now make changes from perl scripts affect the real data */ | |
1163 switch (event) { | |
1164 case event_im_recv: | |
1165 if (buf[1] != *(char **)arg2) { | |
1166 free(*(char **)arg2); | |
1167 *(char **)arg2 = buf[1]; | |
1168 } | |
1169 if (buf[2] != *(char **)arg3) { | |
1170 free(*(char **)arg3); | |
1171 *(char **)arg3 = buf[2]; | |
1172 } | |
1173 break; | |
1174 case event_im_send: | |
1175 if (buf[2] != *(char **)arg3) { | |
1176 free(*(char **)arg3); | |
1177 *(char **)arg3 = buf[2]; | |
1178 } | |
1179 break; | |
1180 case event_chat_recv: | |
1181 if (buf[2] != *(char **)arg3) { | |
1182 free(*(char **)arg3); | |
1183 *(char **)arg3 = buf[2]; | |
1184 } | |
1185 if (buf[3] != *(char **)arg4) { | |
1186 free(*(char **)arg4); | |
1187 *(char **)arg4 = buf[3]; | |
1188 } | |
1189 break; | |
1190 case event_chat_send_invite: | |
1191 if (buf[3] != *(char **)arg4) { | |
1192 free(*(char **)arg4); | |
1193 *(char **)arg4 = buf[3]; | |
1194 } | |
1195 break; | |
1196 case event_chat_send: | |
1197 if (buf[2] != *(char **)arg3) { | |
1198 free(*(char **)arg3); | |
1199 *(char **)arg3 = buf[2]; | |
1200 } | |
1201 break; | |
1202 case event_im_displayed_sent: | |
1203 if (buf[2] != *(char **)arg3) { | |
1204 free(*(char **)arg3); | |
1205 *(char **)arg3 = buf[2]; | |
1206 } | |
1207 break; | |
1208 default: | |
1209 break; | |
1210 } | |
1211 | |
1212 return 0; | |
1213 } | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1214 #endif |
5205 | 1215 |
1216 XS (XS_GAIM_add_event_handler) | |
1217 { | |
1218 unsigned int junk; | |
1219 struct _perl_event_handlers *handler; | |
1220 char *handle; | |
1221 GaimPlugin *plug; | |
1222 GList *p; | |
1223 dXSARGS; | |
1224 items = 0; | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1225 |
5205 | 1226 handle = SvPV(ST(0), junk); |
1227 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1228 gaim_debug(GAIM_DEBUG_ERROR, "perl", |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1229 "Ay, sorry matey. Ye perl scripts are getting " |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1230 "events no more. Argh.\n"); |
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1231 |
5205 | 1232 for (p = gaim_plugins_get_all(); p != NULL; p = p->next) { |
1233 plug = p->data; | |
1234 | |
1235 if (!strcmp(handle, plug->path)) | |
1236 break; | |
1237 } | |
1238 | |
1239 if (p) { | |
1240 handler = g_new0(struct _perl_event_handlers, 1); | |
1241 handler->event_type = g_strdup(SvPV(ST(1), junk)); | |
1242 handler->handler_name = g_strdup(SvPV(ST(2), junk)); | |
1243 handler->plug = plug; | |
1244 perl_event_handlers = g_list_append(perl_event_handlers, handler); | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1245 gaim_debug(GAIM_DEBUG_INFO, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1246 "Registered perl event handler for %s\n", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1247 handler->event_type); |
5205 | 1248 } else { |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1249 gaim_debug(GAIM_DEBUG_ERROR, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1250 "Invalid handle (%s) registering perl event handler\n", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1251 handle); |
5205 | 1252 } |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1253 |
5205 | 1254 XSRETURN_EMPTY; |
1255 } | |
1256 | |
1257 XS (XS_GAIM_remove_event_handler) | |
1258 { | |
1259 unsigned int junk; | |
1260 struct _perl_event_handlers *ehn; | |
1261 GList *cur = perl_event_handlers; | |
1262 dXSARGS; | |
1263 items = 0; | |
1264 | |
1265 while (cur) { | |
1266 GList *next = cur->next; | |
1267 ehn = cur->data; | |
1268 | |
1269 if (!strcmp(ehn->event_type, SvPV(ST(0), junk)) && | |
1270 !strcmp(ehn->handler_name, SvPV(ST(1), junk))) | |
1271 { | |
1272 perl_event_handlers = g_list_remove(perl_event_handlers, ehn); | |
1273 g_free(ehn->event_type); | |
1274 g_free(ehn->handler_name); | |
1275 g_free(ehn); | |
1276 } | |
1277 | |
1278 cur = next; | |
1279 } | |
1280 } | |
1281 | |
1282 static int | |
1283 perl_timeout(gpointer data) | |
1284 { | |
1285 char *atmp[2] = { NULL, NULL }; | |
1286 struct _perl_timeout_handlers *handler = data; | |
1287 | |
1288 atmp[0] = escape_quotes(handler->handler_args); | |
1289 execute_perl(handler->handler_name, 1, atmp); | |
1290 | |
1291 perl_timeout_handlers = g_list_remove(perl_timeout_handlers, handler); | |
1292 g_free(handler->handler_args); | |
1293 g_free(handler->handler_name); | |
1294 g_free(handler); | |
1295 | |
1296 return 0; /* returning zero removes the timeout handler */ | |
1297 } | |
1298 | |
1299 XS (XS_GAIM_add_timeout_handler) | |
1300 { | |
1301 unsigned int junk; | |
1302 long timeout; | |
1303 struct _perl_timeout_handlers *handler; | |
1304 char *handle; | |
1305 GaimPlugin *plug; | |
1306 GList *p; | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1307 |
5205 | 1308 dXSARGS; |
1309 items = 0; | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1310 |
5205 | 1311 handle = SvPV(ST(0), junk); |
1312 | |
1313 for (p = gaim_plugins_get_all(); p != NULL; p = p->next) { | |
1314 plug = p->data; | |
1315 | |
1316 if (!strcmp(handle, plug->path)) | |
1317 break; | |
1318 } | |
1319 | |
1320 if (p) { | |
1321 handler = g_new0(struct _perl_timeout_handlers, 1); | |
1322 timeout = 1000 * SvIV(ST(1)); | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1323 gaim_debug(GAIM_DEBUG_INFO, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1324 "Adding timeout for %ld seconds.\n", timeout/1000); |
5205 | 1325 handler->plug = plug; |
1326 handler->handler_name = g_strdup(SvPV(ST(2), junk)); | |
1327 handler->handler_args = g_strdup(SvPV(ST(3), junk)); | |
1328 perl_timeout_handlers = g_list_append(perl_timeout_handlers, handler); | |
1329 handler->iotag = g_timeout_add(timeout, perl_timeout, handler); | |
1330 } else { | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1331 gaim_debug(GAIM_DEBUG_ERROR, "perl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1332 "Invalid handle (%s) in adding perl timeout handler.", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
1333 handle); |
5205 | 1334 } |
1335 XSRETURN_EMPTY; | |
1336 } | |
1337 | |
1338 XS (XS_GAIM_play_sound) | |
1339 { | |
1340 int id; | |
1341 dXSARGS; | |
1342 | |
1343 items = 0; | |
1344 | |
1345 id = SvIV(ST(0)); | |
1346 | |
1347 gaim_sound_play_event(id); | |
1348 | |
1349 XSRETURN_EMPTY; | |
1350 } | |
1351 | |
1352 static gboolean | |
1353 probe_perl_plugin(GaimPlugin *plugin) | |
1354 { | |
1355 /* XXX This would be much faster if I didn't create a new | |
1356 * PerlInterpreter every time I probed a plugin */ | |
1357 | |
1358 GaimPluginInfo *info; | |
1359 PerlInterpreter *prober = perl_alloc(); | |
1360 char *argv[] = {"", plugin->path }; | |
1361 int count; | |
1362 gboolean status = TRUE; | |
1363 | |
1364 perl_construct(prober); | |
5922 | 1365 perl_parse(prober, xs_init, 2, argv, NULL); |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1366 |
5205 | 1367 { |
1368 dSP; | |
1369 ENTER; | |
1370 SAVETMPS; | |
1371 PUSHMARK(SP); | |
1372 | |
1373 count = perl_call_pv("description", G_NOARGS | G_ARRAY | G_EVAL); | |
1374 SPAGAIN; | |
1375 | |
1376 if (count == 6) { | |
1377 info = g_new0(GaimPluginInfo, 1); | |
1378 | |
1379 info->api_version = 2; | |
1380 info->type = GAIM_PLUGIN_STANDARD; | |
1381 | |
1382 info->dependencies = g_list_append(info->dependencies, | |
1383 PERL_PLUGIN_ID); | |
1384 | |
1385 POPp; /* iconfile */ | |
1386 | |
1387 info->homepage = g_strdup(POPp); | |
1388 info->author = g_strdup(POPp); | |
1389 info->description = g_strdup(POPp); | |
1390 info->version = g_strdup(POPp); | |
1391 info->name = g_strdup(POPp); | |
1392 | |
1393 plugin->info = info; | |
1394 | |
1395 if (!gaim_plugin_register(plugin)) | |
1396 status = FALSE; | |
1397 } | |
1398 else | |
1399 status = FALSE; | |
1400 | |
1401 PUTBACK; | |
1402 FREETMPS; | |
1403 LEAVE; | |
1404 } | |
1405 | |
1406 perl_destruct(prober); | |
1407 perl_free(prober); | |
1408 | |
1409 return status; | |
1410 } | |
1411 | |
1412 static gboolean | |
1413 load_perl_plugin(GaimPlugin *plugin) | |
1414 { | |
1415 perl_load_file(plugin->path, plugin); | |
1416 | |
1417 return TRUE; | |
1418 } | |
1419 | |
1420 static gboolean | |
1421 unload_perl_plugin(GaimPlugin *plugin) | |
1422 { | |
1423 perl_unload_file(plugin); | |
1424 | |
1425 return TRUE; | |
1426 } | |
1427 | |
1428 static void | |
1429 destroy_perl_plugin(GaimPlugin *plugin) | |
1430 { | |
1431 if (plugin->info != NULL) { | |
1432 g_free(plugin->info->name); | |
1433 g_free(plugin->info->version); | |
1434 g_free(plugin->info->description); | |
1435 g_free(plugin->info->author); | |
1436 g_free(plugin->info->homepage); | |
1437 } | |
1438 } | |
1439 | |
1440 static gboolean | |
1441 plugin_unload(GaimPlugin *plugin) | |
1442 { | |
1443 perl_end(); | |
1444 | |
1445 return TRUE; | |
1446 } | |
1447 | |
1448 static GaimPluginLoaderInfo loader_info = | |
1449 { | |
1450 NULL, /**< exts */ | |
1451 | |
1452 probe_perl_plugin, /**< probe */ | |
1453 load_perl_plugin, /**< load */ | |
1454 unload_perl_plugin, /**< unload */ | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
1455 destroy_perl_plugin /**< destroy */ |
5205 | 1456 }; |
1457 | |
1458 static GaimPluginInfo info = | |
1459 { | |
1460 2, /**< api_version */ | |
1461 GAIM_PLUGIN_LOADER, /**< type */ | |
1462 NULL, /**< ui_requirement */ | |
1463 0, /**< flags */ | |
1464 NULL, /**< dependencies */ | |
1465 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
1466 | |
1467 PERL_PLUGIN_ID, /**< id */ | |
1468 N_("Perl Plugin Loader"), /**< name */ | |
1469 VERSION, /**< version */ | |
1470 N_("Provides support for loading perl plugins."), /**< summary */ | |
1471 N_("Provides support for loading perl plugins."), /**< description */ | |
1472 "Christian Hammond <chipx86@gnupdate.org>", /**< author */ | |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6235
diff
changeset
|
1473 GAIM_WEBSITE, /**< homepage */ |
5205 | 1474 |
1475 NULL, /**< load */ | |
1476 plugin_unload, /**< unload */ | |
1477 NULL, /**< destroy */ | |
1478 | |
1479 NULL, /**< ui_info */ | |
1480 &loader_info /**< extra_info */ | |
1481 }; | |
1482 | |
1483 static void | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5775
diff
changeset
|
1484 init_plugin(GaimPlugin *plugin) |
5205 | 1485 { |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5408
diff
changeset
|
1486 my_plugin = plugin; |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5408
diff
changeset
|
1487 |
5205 | 1488 loader_info.exts = g_list_append(loader_info.exts, "pl"); |
1489 } | |
1490 | |
6063 | 1491 GAIM_INIT_PLUGIN(perl, init_plugin, info) |