comparison src/perl.c @ 1101:0ef4386edc29

[gaim-migrate @ 1111] wow, perl got updated. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Thu, 16 Nov 2000 10:06:12 +0000
parents f168625b63fe
children 5bc8fdacd2cb
comparison
equal deleted inserted replaced
1100:f168625b63fe 1101:0ef4386edc29
76 static GList *perl_timeout_handlers = NULL; 76 static GList *perl_timeout_handlers = NULL;
77 static GList *perl_event_handlers = NULL; 77 static GList *perl_event_handlers = NULL;
78 static PerlInterpreter *my_perl = NULL; 78 static PerlInterpreter *my_perl = NULL;
79 79
80 /* dealing with gaim */ 80 /* dealing with gaim */
81 XS(XS_AIM_register); /* set up hooks for script */ 81 XS(XS_GAIM_register); /* set up hooks for script */
82 XS(XS_AIM_get_info); /* version, last to attempt signon, protocol */ 82 XS(XS_GAIM_get_info); /* version, last to attempt signon, protocol */
83 XS(XS_AIM_print); /* lemme figure this one out... */ 83 XS(XS_GAIM_print); /* lemme figure this one out... */
84 84
85 /* list stuff */ 85 /* list stuff */
86 XS(XS_AIM_buddy_list); /* all buddies */ 86 XS(XS_GAIM_buddy_list); /* all buddies */
87 XS(XS_AIM_online_list); /* online buddies */ 87 XS(XS_GAIM_online_list); /* online buddies */
88 XS(XS_AIM_deny_list); /* also returns permit list */
89 88
90 /* server stuff */ 89 /* server stuff */
91 XS(XS_AIM_command); /* send command to server */ 90 XS(XS_GAIM_command); /* send command to server */
92 XS(XS_AIM_user_info); /* given name, return struct buddy members */ 91 XS(XS_GAIM_user_info); /* given name, return struct buddy members */
93 XS(XS_AIM_print_to_conv); /* send message to someone */ 92 XS(XS_GAIM_print_to_conv); /* send message to someone */
94 XS(XS_AIM_print_to_chat); /* send message to chat room */ 93 XS(XS_GAIM_print_to_chat); /* send message to chat room */
95 94
96 /* handler commands */ 95 /* handler commands */
97 XS(XS_AIM_add_event_handler); /* when servers talk */ 96 XS(XS_GAIM_add_event_handler); /* when servers talk */
98 XS(XS_AIM_add_timeout_handler); /* figure it out */ 97 XS(XS_GAIM_add_timeout_handler); /* figure it out */
99 98
100 void xs_init() 99 void xs_init()
101 { 100 {
102 char *file = __FILE__; 101 char *file = __FILE__;
103 newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); 102 newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
205 perl_eval_pv(load_file, TRUE); 204 perl_eval_pv(load_file, TRUE);
206 #else 205 #else
207 Perl_eval_pv(load_file, TRUE); 206 Perl_eval_pv(load_file, TRUE);
208 #endif 207 #endif
209 208
210 newXS ("AIM::register", XS_AIM_register, "AIM"); 209 newXS ("GAIM::register", XS_GAIM_register, "GAIM");
211 newXS ("AIM::get_info", XS_AIM_get_info, "AIM"); 210 newXS ("GAIM::get_info", XS_GAIM_get_info, "GAIM");
212 newXS ("AIM::print", XS_AIM_print, "AIM"); 211 newXS ("GAIM::print", XS_GAIM_print, "GAIM");
213 212
214 newXS ("AIM::buddy_list", XS_AIM_buddy_list, "AIM"); 213 newXS ("GAIM::buddy_list", XS_GAIM_buddy_list, "GAIM");
215 newXS ("AIM::online_list", XS_AIM_online_list, "AIM"); 214 newXS ("GAIM::online_list", XS_GAIM_online_list, "GAIM");
216 newXS ("AIM::deny_list", XS_AIM_deny_list, "AIM"); 215
217 216 newXS ("GAIM::command", XS_GAIM_command, "GAIM");
218 newXS ("AIM::command", XS_AIM_command, "AIM"); 217 newXS ("GAIM::user_info", XS_GAIM_user_info, "GAIM");
219 newXS ("AIM::user_info", XS_AIM_user_info, "AIM"); 218 newXS ("GAIM::print_to_conv", XS_GAIM_print_to_conv, "GAIM");
220 newXS ("AIM::print_to_conv", XS_AIM_print_to_conv, "AIM"); 219 newXS ("GAIM::print_to_chat", XS_GAIM_print_to_chat, "GAIM");
221 newXS ("AIM::print_to_chat", XS_AIM_print_to_chat, "AIM"); 220
222 221 newXS ("GAIM::add_event_handler", XS_GAIM_add_event_handler, "GAIM");
223 newXS ("AIM::add_event_handler", XS_AIM_add_event_handler, "AIM"); 222 newXS ("GAIM::add_timeout_handler", XS_GAIM_add_timeout_handler, "GAIM");
224 newXS ("AIM::add_timeout_handler", XS_AIM_add_timeout_handler, "AIM");
225 } 223 }
226 224
227 void perl_end() 225 void perl_end()
228 { 226 {
229 struct perlscript *scp; 227 struct perlscript *scp;
262 perl_free(my_perl); 260 perl_free(my_perl);
263 my_perl = NULL; 261 my_perl = NULL;
264 } 262 }
265 } 263 }
266 264
267 XS (XS_AIM_register) 265 XS (XS_GAIM_register)
268 { 266 {
269 char *name, *ver, *callback, *unused; /* exactly like X-Chat, eh? :) */ 267 char *name, *ver, *callback, *unused; /* exactly like X-Chat, eh? :) */
270 int junk; 268 int junk;
271 struct perlscript *scp; 269 struct perlscript *scp;
272 dXSARGS; 270 dXSARGS;
285 283
286 XST_mPV (0, VERSION); 284 XST_mPV (0, VERSION);
287 XSRETURN (1); 285 XSRETURN (1);
288 } 286 }
289 287
290 XS (XS_AIM_get_info) 288 XS (XS_GAIM_get_info)
291 { 289 {
290 int i = 0;
292 int junk; 291 int junk;
293 dXSARGS; 292 dXSARGS;
294 items = 0; 293 items = 0;
295 294
296 switch(atoi(SvPV(ST(0), junk))) { 295 switch(atoi(SvPV(ST(0), junk))) {
297 case 0: 296 case 0:
298 XST_mPV(0, VERSION); 297 XST_mPV(0, VERSION);
298 i = 1;
299 break; 299 break;
300 case 1: 300 case 1:
301 /* FIXME: no more current_user 301 {
302 XST_mPV(0, current_user->username); 302 GSList *c = connections;
303 */ 303 struct gaim_connection *gc;
304
305 while (c) {
306 gc = (struct gaim_connection *)c->data;
307 XST_mPV(i++, gc->username);
308 c = c->next;
309 }
310 }
304 break; 311 break;
305 case 2: 312 case 2:
306 /* FIXME: more per-connection issues 313 {
307 if (!blist) 314 GList *u = aim_users;
308 XST_mPV(0, "Offline"); 315 struct aim_user *a;
309 else if (!USE_OSCAR) 316 char *name = g_strdup(normalize(SvPV(ST(1), junk)));
310 XST_mPV(0, "TOC"); 317
311 else 318 while (u) {
312 XST_mPV(0, "Oscar"); 319 a = (struct aim_user *)u->data;
313 */ 320 if (!strcasecmp(normalize(a->username), name))
321 XST_mIV(i++, a->protocol);
322 u = u->next;
323 }
324 g_free(name);
325 }
314 break; 326 break;
315 default: 327 default:
316 XST_mPV(0, "Error2"); 328 XST_mPV(0, "Error2");
317 } 329 i = 1;
318 330 }
319 XSRETURN(1); 331
320 } 332 XSRETURN(i);
321 333 }
322 XS (XS_AIM_print) 334
335 XS (XS_GAIM_print)
323 { 336 {
324 char *title; 337 char *title;
325 char *message; 338 char *message;
326 int junk; 339 int junk;
327 dXSARGS; 340 dXSARGS;
331 message = SvPV(ST(1), junk); 344 message = SvPV(ST(1), junk);
332 do_error_dialog(message, title); 345 do_error_dialog(message, title);
333 XSRETURN(0); 346 XSRETURN(0);
334 } 347 }
335 348
336 XS (XS_AIM_buddy_list) 349 XS (XS_GAIM_buddy_list)
337 { 350 {
338 /* FIXME 351 char *acct;
352 struct gaim_connection *gc;
339 struct buddy *buddy; 353 struct buddy *buddy;
340 struct group *g; 354 struct group *g;
341 GSList *list = groups; 355 GSList *list = NULL;
342 GList *mem; 356 GSList *mem;
343 int i = 0; 357 int i = 0;
344 dXSARGS; 358 int junk;
345 items = 0; 359 dXSARGS;
360 items = 0;
361
362 acct = SvPV(ST(0), junk);
363 gc = find_gaim_conn_by_name(acct);
364 if (gc) list = gc->groups;
346 365
347 while (list) { 366 while (list) {
348 g = (struct group *)list->data; 367 g = (struct group *)list->data;
349 mem = g->members; 368 mem = g->members;
350 while (mem) { 369 while (mem) {
353 mem = mem->next; 372 mem = mem->next;
354 } 373 }
355 list = g_slist_next(list); 374 list = g_slist_next(list);
356 } 375 }
357 XSRETURN(i); 376 XSRETURN(i);
358 */ 377 }
359 } 378
360 379 XS (XS_GAIM_online_list)
361 XS (XS_AIM_online_list) 380 {
362 { 381 char *acct;
363 /* FIXME 382 struct gaim_connection *gc;
364 struct buddy *b; 383 struct buddy *b;
365 struct group *g; 384 struct group *g;
366 GSList *list = groups; 385 GSList *list = NULL;
367 GList *mem; 386 GSList *mem;
368 int i = 0; 387 int i = 0;
369 dXSARGS; 388 int junk;
370 items = 0; 389 dXSARGS;
390 items = 0;
391
392 acct = SvPV(ST(0), junk);
393 gc = find_gaim_conn_by_name(acct);
394 if (gc) list = gc->groups;
371 395
372 while (list) { 396 while (list) {
373 g = (struct group *)list->data; 397 g = (struct group *)list->data;
374 mem = g->members; 398 mem = g->members;
375 while (mem) { 399 while (mem) {
378 mem = mem->next; 402 mem = mem->next;
379 } 403 }
380 list = g_slist_next(list); 404 list = g_slist_next(list);
381 } 405 }
382 XSRETURN(i); 406 XSRETURN(i);
383 */ 407 }
384 } 408
385 409 XS (XS_GAIM_command)
386 XS (XS_AIM_deny_list)
387 {
388 /* FIXME, yet again. perl is so fucked
389 char *name;
390 GList *list = deny;
391 int i = 0;
392 dXSARGS;
393 items = 0;
394
395 while (list) {
396 name = (char *)list->data;
397 XST_mPV(i++, name);
398 list = list->next;
399 }
400 XSRETURN(i);
401 */
402 }
403
404 XS (XS_AIM_command)
405 { 410 {
406 int junk; 411 int junk;
407 char *command = NULL; 412 char *command = NULL;
408 dXSARGS; 413 dXSARGS;
409 items = 0; 414 items = 0;
410 415
411 command = SvPV(ST(0), junk); 416 command = SvPV(ST(0), junk);
412 if (!command) XSRETURN(0); 417 if (!command) XSRETURN(0);
413 if (!strncasecmp(command, "signon", 6)) { 418 if (!strncasecmp(command, "signon", 6)) {
414 /* FIXME 419 char *who = SvPV(ST(1), junk);
415 if (!blist) { 420 struct aim_user *u = find_user(who, -1);
416 show_login(); 421 if (u) serv_login(u);
417 dologin(0, 0);
418 }
419 */
420 } else if (!strncasecmp(command, "signoff", 7)) { 422 } else if (!strncasecmp(command, "signoff", 7)) {
421 /* FIXME: we need to figure out how this works for multiple connections 423 char *who = SvPV(ST(1), junk);
422 * signoff(); */ 424 struct gaim_connection *gc = find_gaim_conn_by_name(who);
425 if (gc) signoff(gc);
426 else signoff_all(NULL, NULL);
423 } else if (!strncasecmp(command, "away", 4)) { 427 } else if (!strncasecmp(command, "away", 4)) {
424 char *message = SvPV(ST(1), junk); 428 char *message = SvPV(ST(1), junk);
425 struct away_message a; 429 struct away_message a;
426 g_snprintf(a.message, sizeof(a.message), "%s", message); 430 g_snprintf(a.message, sizeof(a.message), "%s", message);
427 do_away_message(NULL, &a); 431 do_away_message(NULL, &a);
428 } else if (!strncasecmp(command, "back", 4)) { 432 } else if (!strncasecmp(command, "back", 4)) {
429 do_im_back(); 433 do_im_back();
430 } else if (!strncasecmp(command, "idle", 4)) { 434 } else if (!strncasecmp(command, "idle", 4)) {
431 /* FIXME 435 GSList *c = connections;
432 serv_set_idle(atoi(SvPV(ST(1), junk))); 436 struct gaim_connection *gc;
433 */ 437
438 while (c) {
439 gc = (struct gaim_connection *)c->data;
440 serv_set_idle(gc, atoi(SvPV(ST(1), junk)));
441 gc->is_idle = 1;
442 c = c->next;
443 }
434 } else if (!strncasecmp(command, "warn", 4)) { 444 } else if (!strncasecmp(command, "warn", 4)) {
435 /* yet another perl FIXME 445 GSList *c = connections;
436 char *name = SvPV(ST(1), junk); 446 struct gaim_connection *gc;
437 serv_warn(name, 0); 447
438 */ 448 while (c) {
449 gc = (struct gaim_connection *)c->data;
450 serv_warn(gc, SvPV(ST(1), junk), 0);
451 c = c->next;
452 }
439 } 453 }
440 454
441 XSRETURN(0); 455 XSRETURN(0);
442 } 456 }
443 457
444 XS (XS_AIM_user_info) 458 XS (XS_GAIM_user_info)
445 { 459 {
446 /* FIXME 460 GSList *c = connections;
461 struct gaim_connection *gc;
447 int junk; 462 int junk;
448 struct buddy *buddy; 463 struct buddy *buddy;
449 char *nick; 464 char *nick;
450 dXSARGS; 465 dXSARGS;
451 items = 0; 466 items = 0;
452 467
453 nick = SvPV(ST(0), junk); 468 nick = SvPV(ST(0), junk);
454 if (!nick[0]) 469 if (!nick[0])
455 XSRETURN(0); 470 XSRETURN(0);
456 buddy = find_buddy(nick); 471 while (c) {
472 gc = (struct gaim_connection *)c->data;
473 buddy = find_buddy(gc, nick);
474 if (buddy) c = NULL;
475 else c = c->next;
476 }
457 if (!buddy) 477 if (!buddy)
458 XSRETURN(0); 478 XSRETURN(0);
459 XST_mPV(0, buddy->name); 479 XST_mPV(0, buddy->name);
460 XST_mPV(1, buddy->present ? "Online" : "Offline"); 480 XST_mPV(1, buddy->show);
461 XST_mIV(2, buddy->evil); 481 XST_mPV(2, buddy->present ? "Online" : "Offline");
462 XST_mIV(3, buddy->signon); 482 XST_mIV(3, buddy->evil);
463 XST_mIV(4, buddy->idle); 483 XST_mIV(4, buddy->signon);
464 XST_mIV(5, buddy->uc); 484 XST_mIV(5, buddy->idle);
465 XST_mIV(6, buddy->caps); 485 XST_mIV(6, buddy->uc);
466 XSRETURN(7); 486 XST_mIV(7, buddy->caps);
467 */ 487 XSRETURN(8);
468 } 488 }
469 489
470 XS (XS_AIM_print_to_conv) 490 XS (XS_GAIM_print_to_conv)
471 { 491 {
472 /* FIXME
473 char *nick, *what; 492 char *nick, *what;
474 struct conversation *c; 493 struct conversation *c;
475 int junk; 494 int junk;
476 dXSARGS; 495 dXSARGS;
477 items = 0; 496 items = 0;
480 what = SvPV(ST(1), junk); 499 what = SvPV(ST(1), junk);
481 c = find_conversation(nick); 500 c = find_conversation(nick);
482 if (!c) 501 if (!c)
483 c = new_conversation(nick); 502 c = new_conversation(nick);
484 write_to_conv(c, what, WFLAG_SEND, NULL); 503 write_to_conv(c, what, WFLAG_SEND, NULL);
485 serv_send_im(nick, what, 0); 504 serv_send_im(c->gc, nick, what, 0);
486 */ 505 }
487 } 506
488 507 XS (XS_GAIM_print_to_chat)
489 XS (XS_AIM_print_to_chat) 508 {
490 { 509 char *nick, *what, *tmp;
491 /* FIXME: need to make this multi-connection based 510 GSList *c = connections;
492 char *nick, *what; 511 struct gaim_connection *gc;
493 struct conversation *c = NULL; 512 struct conversation *b = NULL;
494 GList *bcs = buddy_chats; 513 GSList *bcs;
495 int junk; 514 int junk;
496 dXSARGS; 515 dXSARGS;
497 items = 0; 516 items = 0;
498 517
499 nick = SvPV(ST(0), junk); 518 nick = SvPV(ST(0), junk);
500 what = SvPV(ST(1), junk); 519 what = SvPV(ST(1), junk);
501 while (bcs) { 520 tmp = g_strdup(normalize(nick));
502 c = (struct conversation *)bcs->data; 521 while (c) {
503 if (!strcmp(c->name, nick)) 522 gc = (struct gaim_connection *)c->data;
504 break; 523 bcs = gc->buddy_chats;
505 bcs = bcs->next; 524 while (bcs) {
506 c = NULL; 525 b = (struct conversation *)bcs->data;
507 } 526 if (!strcmp(normalize(b->name), tmp))
508 if (!c) 527 break;
509 XSRETURN(0); 528 bcs = bcs->next;
510 serv_chat_send(c->id, what); 529 b = NULL;
511 */ 530 }
531 serv_chat_send(b->gc, b->id, what);
532 c = c->next;
533 }
534 XSRETURN(0);
512 } 535 }
513 536
514 int perl_event(char *event, char *args) 537 int perl_event(char *event, char *args)
515 { 538 {
516 GList *handler; 539 GList *handler;
527 } 550 }
528 551
529 return 0; 552 return 0;
530 } 553 }
531 554
532 XS (XS_AIM_add_event_handler) 555 XS (XS_GAIM_add_event_handler)
533 { 556 {
534 int junk; 557 int junk;
535 struct _perl_event_handlers *handler; 558 struct _perl_event_handlers *handler;
536 dXSARGS; 559 dXSARGS;
537 items = 0; 560 items = 0;
553 g_free(handler); 576 g_free(handler);
554 577
555 return 0; /* returning zero removes the timeout handler */ 578 return 0; /* returning zero removes the timeout handler */
556 } 579 }
557 580
558 XS (XS_AIM_add_timeout_handler) 581 XS (XS_GAIM_add_timeout_handler)
559 { 582 {
560 int junk; 583 int junk;
561 long timeout; 584 long timeout;
562 struct _perl_timeout_handlers *handler; 585 struct _perl_timeout_handlers *handler;
563 dXSARGS; 586 dXSARGS;