comparison libpurple/protocols/irc/irc.c @ 32692:0f94ec89f0bc

merged from im.pidgin.pidgin
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 26 Sep 2011 14:57:21 +0900
parents ac6353ffa129 c6943fd38d44
children 4a34689eeb33
comparison
equal deleted inserted replaced
32438:55e678325bda 32692:0f94ec89f0bc
68 { 68 {
69 PurpleConnection *gc = (PurpleConnection *) action->context; 69 PurpleConnection *gc = (PurpleConnection *) action->context;
70 struct irc_conn *irc; 70 struct irc_conn *irc;
71 char *title; 71 char *title;
72 72
73 if (gc == NULL || gc->proto_data == NULL) { 73 if (gc == NULL || purple_connection_get_protocol_data(gc) == NULL) {
74 purple_debug(PURPLE_DEBUG_ERROR, "irc", "got MOTD request for NULL gc\n"); 74 purple_debug(PURPLE_DEBUG_ERROR, "irc", "got MOTD request for NULL gc\n");
75 return; 75 return;
76 } 76 }
77 irc = gc->proto_data; 77 irc = purple_connection_get_protocol_data(gc);
78 if (irc->motd == NULL) { 78 if (irc->motd == NULL) {
79 purple_notify_error(gc, _("Error displaying MOTD"), _("No MOTD available"), 79 purple_notify_error(gc, _("Error displaying MOTD"), _("No MOTD available"),
80 _("There is no MOTD associated with this connection.")); 80 _("There is no MOTD associated with this connection."));
81 return; 81 return;
82 } 82 }
98 return ret; 98 return ret;
99 } 99 }
100 100
101 static int irc_send_raw(PurpleConnection *gc, const char *buf, int len) 101 static int irc_send_raw(PurpleConnection *gc, const char *buf, int len)
102 { 102 {
103 struct irc_conn *irc = (struct irc_conn*)gc->proto_data; 103 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
104 if (len == -1) { 104 if (len == -1) {
105 len = strlen(buf); 105 len = strlen(buf);
106 } 106 }
107 irc_send_len(irc, buf, len); 107 irc_send_len(irc, buf, len);
108 return len; 108 return len;
363 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS, 363 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
364 _("IRC nick and server may not contain whitespace")); 364 _("IRC nick and server may not contain whitespace"));
365 return; 365 return;
366 } 366 }
367 367
368 gc->proto_data = irc = g_new0(struct irc_conn, 1); 368 irc = g_new0(struct irc_conn, 1);
369 purple_connection_set_protocol_data(gc, irc);
369 irc->fd = -1; 370 irc->fd = -1;
370 irc->account = account; 371 irc->account = account;
371 irc->outbuf = purple_circ_buffer_new(512); 372 irc->outbuf = purple_circ_buffer_new(512);
372 373
373 userparts = g_strsplit(username, "@", 2); 374 userparts = g_strsplit(username, "@", 2);
413 414
414 static gboolean do_login(PurpleConnection *gc) { 415 static gboolean do_login(PurpleConnection *gc) {
415 char *buf, *tmp = NULL; 416 char *buf, *tmp = NULL;
416 char *server; 417 char *server;
417 const char *username, *realname; 418 const char *username, *realname;
418 struct irc_conn *irc = gc->proto_data; 419 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
419 const char *pass = purple_connection_get_password(gc); 420 const char *pass = purple_connection_get_password(gc);
420 421
421 if (pass && *pass) { 422 if (pass && *pass) {
422 buf = irc_format(irc, "v:", "PASS", pass); 423 buf = irc_format(irc, "v:", "PASS", pass);
423 if (irc_send(irc, buf) < 0) { 424 if (irc_send(irc, buf) < 0) {
483 } 484 }
484 485
485 static void irc_login_cb(gpointer data, gint source, const gchar *error_message) 486 static void irc_login_cb(gpointer data, gint source, const gchar *error_message)
486 { 487 {
487 PurpleConnection *gc = data; 488 PurpleConnection *gc = data;
488 struct irc_conn *irc = gc->proto_data; 489 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
489 490
490 if (source < 0) { 491 if (source < 0) {
491 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"), 492 gchar *tmp = g_strdup_printf(_("Unable to connect: %s"),
492 error_message); 493 error_message);
493 purple_connection_error (gc, 494 purple_connection_error (gc,
506 static void 507 static void
507 irc_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error, 508 irc_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error,
508 gpointer data) 509 gpointer data)
509 { 510 {
510 PurpleConnection *gc = data; 511 PurpleConnection *gc = data;
511 struct irc_conn *irc = gc->proto_data; 512 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
512 513
513 irc->gsc = NULL; 514 irc->gsc = NULL;
514 515
515 purple_connection_ssl_error (gc, error); 516 purple_connection_ssl_error (gc, error);
516 } 517 }
517 518
518 static void irc_close(PurpleConnection *gc) 519 static void irc_close(PurpleConnection *gc)
519 { 520 {
520 struct irc_conn *irc = gc->proto_data; 521 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
521 522
522 if (irc == NULL) 523 if (irc == NULL)
523 return; 524 return;
524 525
525 if (irc->gsc || (irc->fd >= 0)) 526 if (irc->gsc || (irc->fd >= 0))
556 g_free(irc); 557 g_free(irc);
557 } 558 }
558 559
559 static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags) 560 static int irc_im_send(PurpleConnection *gc, const char *who, const char *what, PurpleMessageFlags flags)
560 { 561 {
561 struct irc_conn *irc = gc->proto_data; 562 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
562 char *plain; 563 char *plain;
563 const char *args[2]; 564 const char *args[2];
564 565
565 args[0] = irc_nick_skip_mode(irc, who); 566 args[0] = irc_nick_skip_mode(irc, who);
566 567
572 return 1; 573 return 1;
573 } 574 }
574 575
575 static void irc_get_info(PurpleConnection *gc, const char *who) 576 static void irc_get_info(PurpleConnection *gc, const char *who)
576 { 577 {
577 struct irc_conn *irc = gc->proto_data; 578 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
578 const char *args[2]; 579 const char *args[2];
579 args[0] = who; 580 args[0] = who;
580 args[1] = NULL; 581 args[1] = NULL;
581 irc_cmd_whois(irc, "whois", NULL, args); 582 irc_cmd_whois(irc, "whois", NULL, args);
582 } 583 }
587 struct irc_conn *irc; 588 struct irc_conn *irc;
588 const char *args[1]; 589 const char *args[1];
589 const char *status_id = purple_status_get_id(status); 590 const char *status_id = purple_status_get_id(status);
590 591
591 g_return_if_fail(gc != NULL); 592 g_return_if_fail(gc != NULL);
592 irc = gc->proto_data; 593 irc = purple_connection_get_protocol_data(gc);
593 594
594 if (!purple_status_is_active(status)) 595 if (!purple_status_is_active(status))
595 return; 596 return;
596 597
597 args[0] = NULL; 598 args[0] = NULL;
604 } else if (!strcmp(status_id, "available")) { 605 } else if (!strcmp(status_id, "available")) {
605 irc_cmd_away(irc, "back", NULL, args); 606 irc_cmd_away(irc, "back", NULL, args);
606 } 607 }
607 } 608 }
608 609
609 static void irc_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 610 static void irc_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group, const char *message)
610 { 611 {
611 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; 612 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
612 struct irc_buddy *ib; 613 struct irc_buddy *ib;
613 const char *bname = purple_buddy_get_name(buddy); 614 const char *bname = purple_buddy_get_name(buddy);
614 615
615 ib = g_hash_table_lookup(irc->buddies, bname); 616 ib = g_hash_table_lookup(irc->buddies, bname);
616 if (ib != NULL) { 617 if (ib != NULL) {
631 irc_ison_one(irc, ib); 632 irc_ison_one(irc, ib);
632 } 633 }
633 634
634 static void irc_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 635 static void irc_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
635 { 636 {
636 struct irc_conn *irc = (struct irc_conn *)gc->proto_data; 637 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
637 struct irc_buddy *ib; 638 struct irc_buddy *ib;
638 639
639 ib = g_hash_table_lookup(irc->buddies, purple_buddy_get_name(buddy)); 640 ib = g_hash_table_lookup(irc->buddies, purple_buddy_get_name(buddy));
640 if (ib && --ib->ref == 0) { 641 if (ib && --ib->ref == 0) {
641 g_hash_table_remove(irc->buddies, purple_buddy_get_name(buddy)); 642 g_hash_table_remove(irc->buddies, purple_buddy_get_name(buddy));
676 static void irc_input_cb_ssl(gpointer data, PurpleSslConnection *gsc, 677 static void irc_input_cb_ssl(gpointer data, PurpleSslConnection *gsc,
677 PurpleInputCondition cond) 678 PurpleInputCondition cond)
678 { 679 {
679 680
680 PurpleConnection *gc = data; 681 PurpleConnection *gc = data;
681 struct irc_conn *irc = gc->proto_data; 682 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
682 int len; 683 int len;
683 684
684 if(!g_list_find(purple_connections_get_all(), gc)) { 685 if(!g_list_find(purple_connections_get_all(), gc)) {
685 purple_ssl_close(gsc); 686 purple_ssl_close(gsc);
686 return; 687 return;
714 } 715 }
715 716
716 static void irc_input_cb(gpointer data, gint source, PurpleInputCondition cond) 717 static void irc_input_cb(gpointer data, gint source, PurpleInputCondition cond)
717 { 718 {
718 PurpleConnection *gc = data; 719 PurpleConnection *gc = data;
719 struct irc_conn *irc = gc->proto_data; 720 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
720 int len; 721 int len;
721 722
722 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { 723 if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) {
723 irc->inbuflen += IRC_INITIAL_BUFSIZE; 724 irc->inbuflen += IRC_INITIAL_BUFSIZE;
724 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); 725 irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen);
744 read_input(irc, len); 745 read_input(irc, len);
745 } 746 }
746 747
747 static void irc_chat_join (PurpleConnection *gc, GHashTable *data) 748 static void irc_chat_join (PurpleConnection *gc, GHashTable *data)
748 { 749 {
749 struct irc_conn *irc = gc->proto_data; 750 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
750 const char *args[2]; 751 const char *args[2];
751 752
752 args[0] = g_hash_table_lookup(data, "channel"); 753 args[0] = g_hash_table_lookup(data, "channel");
753 args[1] = g_hash_table_lookup(data, "password"); 754 args[1] = g_hash_table_lookup(data, "password");
754 irc_cmd_join(irc, "join", NULL, args); 755 irc_cmd_join(irc, "join", NULL, args);
758 return g_strdup(g_hash_table_lookup(data, "channel")); 759 return g_strdup(g_hash_table_lookup(data, "channel"));
759 } 760 }
760 761
761 static void irc_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name) 762 static void irc_chat_invite(PurpleConnection *gc, int id, const char *message, const char *name)
762 { 763 {
763 struct irc_conn *irc = gc->proto_data; 764 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
764 PurpleConversation *convo = purple_find_chat(gc, id); 765 PurpleConversation *convo = purple_find_chat(gc, id);
765 const char *args[2]; 766 const char *args[2];
766 767
767 if (!convo) { 768 if (!convo) {
768 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n"); 769 purple_debug(PURPLE_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n");
774 } 775 }
775 776
776 777
777 static void irc_chat_leave (PurpleConnection *gc, int id) 778 static void irc_chat_leave (PurpleConnection *gc, int id)
778 { 779 {
779 struct irc_conn *irc = gc->proto_data; 780 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
780 PurpleConversation *convo = purple_find_chat(gc, id); 781 PurpleConversation *convo = purple_find_chat(gc, id);
781 const char *args[2]; 782 const char *args[2];
782 783
783 if (!convo) 784 if (!convo)
784 return; 785 return;
789 serv_got_chat_left(gc, id); 790 serv_got_chat_left(gc, id);
790 } 791 }
791 792
792 static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags) 793 static int irc_chat_send(PurpleConnection *gc, int id, const char *what, PurpleMessageFlags flags)
793 { 794 {
794 struct irc_conn *irc = gc->proto_data; 795 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
795 PurpleConversation *convo = purple_find_chat(gc, id); 796 PurpleConversation *convo = purple_find_chat(gc, id);
796 const char *args[2]; 797 const char *args[2];
797 char *tmp; 798 char *tmp;
798 799
799 if (!convo) { 800 if (!convo) {
843 { 844 {
844 char *buf; 845 char *buf;
845 const char *name = NULL; 846 const char *name = NULL;
846 struct irc_conn *irc; 847 struct irc_conn *irc;
847 848
848 irc = gc->proto_data; 849 irc = purple_connection_get_protocol_data(gc);
849 name = purple_conversation_get_name(purple_find_chat(gc, id)); 850 name = purple_conversation_get_name(purple_find_chat(gc, id));
850 851
851 if (name == NULL) 852 if (name == NULL)
852 return; 853 return;
853 854
861 struct irc_conn *irc; 862 struct irc_conn *irc;
862 GList *fields = NULL; 863 GList *fields = NULL;
863 PurpleRoomlistField *f; 864 PurpleRoomlistField *f;
864 char *buf; 865 char *buf;
865 866
866 irc = gc->proto_data; 867 irc = purple_connection_get_protocol_data(gc);
867 868
868 if (irc->roomlist) 869 if (irc->roomlist)
869 purple_roomlist_unref(irc->roomlist); 870 purple_roomlist_unref(irc->roomlist);
870 871
871 irc->roomlist = purple_roomlist_new(purple_connection_get_account(gc)); 872 irc->roomlist = purple_roomlist_new(purple_connection_get_account(gc));
895 struct irc_conn *irc; 896 struct irc_conn *irc;
896 897
897 if (gc == NULL) 898 if (gc == NULL)
898 return; 899 return;
899 900
900 irc = gc->proto_data; 901 irc = purple_connection_get_protocol_data(gc);
901 902
902 purple_roomlist_set_in_progress(list, FALSE); 903 purple_roomlist_set_in_progress(list, FALSE);
903 904
904 if (irc->roomlist == list) { 905 if (irc->roomlist == list) {
905 irc->roomlist = NULL; 906 irc->roomlist = NULL;
907 } 908 }
908 } 909 }
909 910
910 static void irc_keepalive(PurpleConnection *gc) 911 static void irc_keepalive(PurpleConnection *gc)
911 { 912 {
912 struct irc_conn *irc = gc->proto_data; 913 struct irc_conn *irc = purple_connection_get_protocol_data(gc);
913 if ((time(NULL) - irc->recv_time) > PING_TIMEOUT) 914 if ((time(NULL) - irc->recv_time) > PING_TIMEOUT)
914 irc_cmd_ping(irc, NULL, NULL, NULL); 915 irc_cmd_ping(irc, NULL, NULL, NULL);
915 } 916 }
916 917
917 static PurplePluginProtocolInfo prpl_info = 918 static PurplePluginProtocolInfo prpl_info =
918 { 919 {
920 sizeof(PurplePluginProtocolInfo), /* struct_size */
919 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL | 921 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL |
920 OPT_PROTO_SLASH_COMMANDS_NATIVE, 922 OPT_PROTO_SLASH_COMMANDS_NATIVE,
921 NULL, /* user_splits */ 923 NULL, /* user_splits */
922 NULL, /* protocol_options */ 924 NULL, /* protocol_options */
923 NO_BUDDY_ICONS, /* icon_spec */ 925 NO_BUDDY_ICONS, /* icon_spec */
955 NULL, /* chat_whisper */ 957 NULL, /* chat_whisper */
956 irc_chat_send, /* chat_send */ 958 irc_chat_send, /* chat_send */
957 irc_keepalive, /* keepalive */ 959 irc_keepalive, /* keepalive */
958 NULL, /* register_user */ 960 NULL, /* register_user */
959 NULL, /* get_cb_info */ 961 NULL, /* get_cb_info */
960 NULL, /* get_cb_away */
961 NULL, /* alias_buddy */ 962 NULL, /* alias_buddy */
962 NULL, /* group_buddy */ 963 NULL, /* group_buddy */
963 NULL, /* rename_group */ 964 NULL, /* rename_group */
964 NULL, /* buddy_free */ 965 NULL, /* buddy_free */
965 NULL, /* convo_closed */ 966 NULL, /* convo_closed */
980 irc_send_raw, /* send_raw */ 981 irc_send_raw, /* send_raw */
981 NULL, /* roomlist_room_serialize */ 982 NULL, /* roomlist_room_serialize */
982 NULL, /* unregister_user */ 983 NULL, /* unregister_user */
983 NULL, /* send_attention */ 984 NULL, /* send_attention */
984 NULL, /* get_attention_types */ 985 NULL, /* get_attention_types */
985 sizeof(PurplePluginProtocolInfo), /* struct_size */
986 NULL, /* get_account_text_table */ 986 NULL, /* get_account_text_table */
987 NULL, /* initiate_media */ 987 NULL, /* initiate_media */
988 NULL, /* get_media_caps */ 988 NULL, /* get_media_caps */
989 NULL, /* get_moods */ 989 NULL, /* get_moods */
990 NULL, /* set_public_alias */ 990 NULL, /* set_public_alias */
991 NULL, /* get_public_alias */ 991 NULL /* get_public_alias */
992 NULL, /* add_buddy_with_invite */
993 NULL /* add_buddies_with_invite */
994 }; 992 };
995 993
996 static gboolean load_plugin (PurplePlugin *plugin) { 994 static gboolean load_plugin (PurplePlugin *plugin) {
997 995
998 purple_signal_register(plugin, "irc-sending-text", 996 purple_signal_register(plugin, "irc-sending-text",