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