comparison src/perl.c @ 780:c714def9cebb

[gaim-migrate @ 790] You may be a geek if... You've ever used a computer on Friday, Saturday and Sunday of the same weekend. You find yourself interrupting computer store salesman to correct something he said. The first thing you notice when walking in a business is their computer system. ...and offer advice on how you would change it. You've ever mounted a magnetic tape reel. You own any shareware. You know more IP addresses than phone numbers. You've ever accidentally dialed an IP address. Your friends use you as tech support. You've ever named a computer. You have your local computer store on speed dial. You can't carry on a conversation without talking about computers. Co-workers have to E-mail you about the fire alarm to get you out of the building. You've ever found "stray" diskettes when doing laundry. Your computer has it's own phone line - but your teenager doesn't. You check the national weather service web page for current weather conditions (rather than look out the window). You know more URLs than street addresses. Your pet has a web page. You get really excited when Yahoo adds your link. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 29 Aug 2000 03:59:01 +0000
parents 94edd99b7302
children 95ebfdb31a9b
comparison
equal deleted inserted replaced
779:1823a4af82d3 780:c714def9cebb
55 char *name; 55 char *name;
56 char *version; 56 char *version;
57 char *shutdowncallback; /* bleh */ 57 char *shutdowncallback; /* bleh */
58 }; 58 };
59 59
60 struct _perl_event_handlers {
61 char *event_type;
62 char *handler_name;
63 }
64
60 struct _perl_timeout_handlers { 65 struct _perl_timeout_handlers {
61 char *handler_name; 66 char *handler_name;
62 gint iotag; 67 gint iotag;
63 }; 68 };
64 69
65 static GList *perl_list = NULL; /* should probably extern this at some point */ 70 static GList *perl_list = NULL; /* should probably extern this at some point */
66 static GList *perl_timeout_handlers = NULL; 71 static GList *perl_timeout_handlers = NULL;
72 static GList *perl_event_handlers = NULL;
67 static PerlInterpreter *my_perl = NULL; 73 static PerlInterpreter *my_perl = NULL;
68 74
69 /* dealing with gaim */ 75 /* dealing with gaim */
70 XS(XS_AIM_register); /* set up hooks for script */ 76 XS(XS_AIM_register); /* set up hooks for script */
71 XS(XS_AIM_get_info); /* version, last to attempt signon, protocol */ 77 XS(XS_AIM_get_info); /* version, last to attempt signon, protocol */
81 XS(XS_AIM_user_info); /* given name, return struct buddy members */ 87 XS(XS_AIM_user_info); /* given name, return struct buddy members */
82 XS(XS_AIM_print_to_conv); /* send message to someone */ 88 XS(XS_AIM_print_to_conv); /* send message to someone */
83 XS(XS_AIM_print_to_chat); /* send message to chat room */ 89 XS(XS_AIM_print_to_chat); /* send message to chat room */
84 90
85 /* handler commands */ 91 /* handler commands */
86 XS(XS_AIM_add_message_handler); /* when people talk */ 92 XS(XS_AIM_add_event_handler); /* when servers talk */
87 XS(XS_AIM_add_command_handler); /* when servers talk */
88 XS(XS_AIM_add_timeout_handler); /* figure it out */ 93 XS(XS_AIM_add_timeout_handler); /* figure it out */
89 94
90 void xs_init() 95 void xs_init()
91 { 96 {
92 char *file = __FILE__; 97 char *file = __FILE__;
170 newXS ("AIM::command", XS_AIM_command, "AIM"); 175 newXS ("AIM::command", XS_AIM_command, "AIM");
171 newXS ("AIM::user_info", XS_AIM_user_info, "AIM"); 176 newXS ("AIM::user_info", XS_AIM_user_info, "AIM");
172 newXS ("AIM::print_to_conv", XS_AIM_print_to_conv, "AIM"); 177 newXS ("AIM::print_to_conv", XS_AIM_print_to_conv, "AIM");
173 newXS ("AIM::print_to_chat", XS_AIM_print_to_chat, "AIM"); 178 newXS ("AIM::print_to_chat", XS_AIM_print_to_chat, "AIM");
174 179
175 newXS ("AIM::add_message_handler", XS_AIM_add_message_handler, "AIM"); 180 newXS ("AIM::add_event_handler", XS_AIM_add_event_handler, "AIM");
176 newXS ("AIM::add_command_handler", XS_AIM_add_command_handler, "AIM");
177 newXS ("AIM::add_timeout_handler", XS_AIM_add_timeout_handler, "AIM"); 181 newXS ("AIM::add_timeout_handler", XS_AIM_add_timeout_handler, "AIM");
178 } 182 }
179 183
180 void perl_end() 184 void perl_end()
181 { 185 {
182 struct perlscript *scp; 186 struct perlscript *scp;
183 struct _perl_timeout_handlers *thn; 187 struct _perl_timeout_handlers *thn;
188 struct _perl_event_handlers *ehn;
184 189
185 while (perl_list) { 190 while (perl_list) {
186 scp = perl_list->data; 191 scp = perl_list->data;
187 perl_list = g_list_remove(perl_list, scp); 192 perl_list = g_list_remove(perl_list, scp);
188 if (scp->shutdowncallback[0]) 193 if (scp->shutdowncallback[0])
197 thn = perl_timeout_handlers->data; 202 thn = perl_timeout_handlers->data;
198 perl_timeout_handlers = g_list_remove(perl_timeout_handlers, thn); 203 perl_timeout_handlers = g_list_remove(perl_timeout_handlers, thn);
199 gtk_timeout_remove(thn->iotag); 204 gtk_timeout_remove(thn->iotag);
200 g_free(thn->handler_name); 205 g_free(thn->handler_name);
201 g_free(thn); 206 g_free(thn);
207 }
208
209 while (perl_event_handlers) {
210 ehn = perl_event_handlers->data;
211 perl_event_handlers = g_list_remove(perl_event_handlers, ehn);
212 g_free(ehn->event_type);
213 g_free(ehn->handler_name);
214 g_free(ehn);
202 } 215 }
203 216
204 if (my_perl != NULL) { 217 if (my_perl != NULL) {
205 perl_destruct(my_perl); 218 perl_destruct(my_perl);
206 perl_free(my_perl); 219 perl_free(my_perl);
430 if (!c) 443 if (!c)
431 XSRETURN(0); 444 XSRETURN(0);
432 serv_chat_send(c->id, what); 445 serv_chat_send(c->id, what);
433 } 446 }
434 447
435 XS (XS_AIM_add_message_handler) 448 static char *event_name(enum gaim_event event)
436 { 449 {
437 /* FIXME */ 450 static char buf[128];
438 } 451 switch(event) {
439 452 case event_signon:
440 XS (XS_AIM_add_command_handler) 453 sprintf(buf, "event_signon");
441 { 454 break;
442 /* FIXME */ 455 case event_signoff:
456 sprintf(buf, "event_signoff");
457 break;
458 case event_away:
459 sprintf(buf, "event_away");
460 break;
461 case event_back:
462 sprintf(buf, "event_back");
463 break;
464 case event_im_recv:
465 sprintf(buf, "event_im_recv");
466 break;
467 case event_im_send:
468 sprintf(buf, "event_im_send");
469 break;
470 case event_buddy_signon:
471 sprintf(buf, "event_buddy_signon");
472 break;
473 case event_buddy_signoff:
474 sprintf(buf, "event_buddy_signoff");
475 break;
476 case event_buddy_away:
477 sprintf(buf, "event_buddy_away");
478 break;
479 case event_buddy_back:
480 sprintf(buf, "event_buddy_back");
481 break;
482 case event_blist_update:
483 sprintf(buf, "event_blist_update");
484 break;
485 case event_chat_invited:
486 sprintf(buf, "event_chat_invited");
487 break;
488 case event_chat_join:
489 sprintf(buf, "event_chat_join");
490 break;
491 case event_chat_leave:
492 sprintf(buf, "event_chat_leave");
493 break;
494 case event_chat_buddy_join:
495 sprintf(buf, "event_chat_buddy_join");
496 break;
497 case event_chat_buddy_leave:
498 sprintf(buf, "event_chat_buddy_leave");
499 break;
500 case event_chat_recv:
501 sprintf(buf, "event_chat_recv");
502 break;
503 case event_chat_send:
504 sprintf(buf, "event_chat_send");
505 break;
506 case event_warned:
507 sprintf(buf, "event_warned");
508 break;
509 case event_error:
510 sprintf(buf, "event_error");
511 break;
512 case event_quit:
513 sprintf(buf, "event_quit");
514 break;
515 default:
516 sprintf(buf, "event_unknown");
517 break;
518 }
519 }
520
521 int perl_event(enum gaim_event event, char *args)
522 {
523 GList *handler;
524 struct _perl_event_handlers *data;
525
526 for (handler = perl_event_handlers; handler != NULL; handler = handler->next) {
527 data = handler->data;
528 if (!strcmp(event_name(event), data->event_type))
529 execute_perl(args);
530 }
531
532 return 0;
533 }
534
535 XS (XS_AIM_add_event_handler)
536 {
537 int junk;
538 struct _perl_event_handlers *handler;
539 dXSARGS;
540 items = 0;
541
542 handler = g_new0(struct _perl_event_handlers, 1);
543 handler->event_type = g_strdup(SvPV(ST(0), junk));
544 handler->handler_name = g_strdup(SvPV(ST(1), junk));
545 perl_event_handlers = g_list_append(perl_event_handlers, handler);
546 XSRETURN_EMPTY;
443 } 547 }
444 548
445 static int perl_timeout(struct _perl_timeout_handlers *handler) 549 static int perl_timeout(struct _perl_timeout_handlers *handler)
446 { 550 {
447 execute_perl(handler->handler_name, ""); 551 execute_perl(handler->handler_name, "");