Mercurial > pidgin.yaz
comparison libpurple/protocols/null/nullprpl.c @ 32701:35c1739709df
nullprpl also updated to use accessor methods.
author | andrew.victor@mxit.com |
---|---|
date | Sat, 01 Oct 2011 15:48:36 +0000 |
parents | c6943fd38d44 |
children | f75041cb3fec |
comparison
equal
deleted
inserted
replaced
32700:1f68af4afe67 | 32701:35c1739709df |
---|---|
136 | 136 |
137 static void call_chat_func(gpointer data, gpointer userdata) { | 137 static void call_chat_func(gpointer data, gpointer userdata) { |
138 PurpleConnection *to = (PurpleConnection *)data; | 138 PurpleConnection *to = (PurpleConnection *)data; |
139 ChatFuncData *cfdata = (ChatFuncData *)userdata; | 139 ChatFuncData *cfdata = (ChatFuncData *)userdata; |
140 | 140 |
141 int id = cfdata->from_chat->id; | 141 int id = purple_conv_chat_get_id(cfdata->from_chat); |
142 PurpleConversation *conv = purple_find_chat(to, id); | 142 PurpleConversation *conv = purple_find_chat(to, id); |
143 if (conv) { | 143 if (conv) { |
144 PurpleConvChat *chat = purple_conversation_get_chat_data(conv); | 144 PurpleConvChat *chat = purple_conversation_get_chat_data(conv); |
145 cfdata->fn(cfdata->from_chat, chat, id, conv->name, cfdata->userdata); | 145 cfdata->fn(cfdata->from_chat, chat, id, purple_conversation_get_name(conv), cfdata->userdata); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 static void foreach_gc_in_chat(ChatFunc fn, PurpleConnection *from, | 149 static void foreach_gc_in_chat(ChatFunc fn, PurpleConnection *from, |
150 int id, gpointer userdata) { | 150 int id, gpointer userdata) { |
646 | 646 |
647 static void joined_chat(PurpleConvChat *from, PurpleConvChat *to, | 647 static void joined_chat(PurpleConvChat *from, PurpleConvChat *to, |
648 int id, const char *room, gpointer userdata) { | 648 int id, const char *room, gpointer userdata) { |
649 /* tell their chat window that we joined */ | 649 /* tell their chat window that we joined */ |
650 purple_debug_info("nullprpl", "%s sees that %s joined chat room %s\n", | 650 purple_debug_info("nullprpl", "%s sees that %s joined chat room %s\n", |
651 to->nick, from->nick, room); | 651 purple_conv_chat_get_nick(to), purple_conv_chat_get_nick(from), room); |
652 purple_conv_chat_add_user(to, | 652 purple_conv_chat_add_user(to, |
653 from->nick, | 653 purple_conv_chat_get_nick(from), |
654 NULL, /* user-provided join message, IRC style */ | 654 NULL, /* user-provided join message, IRC style */ |
655 PURPLE_CBFLAGS_NONE, | 655 PURPLE_CBFLAGS_NONE, |
656 TRUE); /* show a join message */ | 656 TRUE); /* show a join message */ |
657 | 657 |
658 if (from != to) { | 658 if (from != to) { |
659 /* add them to our chat window */ | 659 /* add them to our chat window */ |
660 purple_debug_info("nullprpl", "%s sees that %s is in chat room %s\n", | 660 purple_debug_info("nullprpl", "%s sees that %s is in chat room %s\n", |
661 from->nick, to->nick, room); | 661 purple_conv_chat_get_nick(from), purple_conv_chat_get_nick(to), room); |
662 purple_conv_chat_add_user(from, | 662 purple_conv_chat_add_user(from, |
663 to->nick, | 663 purple_conv_chat_get_nick(to), |
664 NULL, /* user-provided join message, IRC style */ | 664 NULL, /* user-provided join message, IRC style */ |
665 PURPLE_CBFLAGS_NONE, | 665 PURPLE_CBFLAGS_NONE, |
666 FALSE); /* show a join message */ | 666 FALSE); /* show a join message */ |
667 } | 667 } |
668 } | 668 } |
719 | 719 |
720 static void nullprpl_chat_invite(PurpleConnection *gc, int id, | 720 static void nullprpl_chat_invite(PurpleConnection *gc, int id, |
721 const char *message, const char *who) { | 721 const char *message, const char *who) { |
722 const char *username = gc->account->username; | 722 const char *username = gc->account->username; |
723 PurpleConversation *conv = purple_find_chat(gc, id); | 723 PurpleConversation *conv = purple_find_chat(gc, id); |
724 const char *room = conv->name; | 724 const char *room = purple_conversation_get_name(conv); |
725 PurpleAccount *to_acct = purple_accounts_find(who, NULLPRPL_ID); | 725 PurpleAccount *to_acct = purple_accounts_find(who, NULLPRPL_ID); |
726 | 726 |
727 purple_debug_info("nullprpl", "%s is inviting %s to join chat room %s\n", | 727 purple_debug_info("nullprpl", "%s is inviting %s to join chat room %s\n", |
728 username, who, room); | 728 username, who, room); |
729 | 729 |
750 static void left_chat_room(PurpleConvChat *from, PurpleConvChat *to, | 750 static void left_chat_room(PurpleConvChat *from, PurpleConvChat *to, |
751 int id, const char *room, gpointer userdata) { | 751 int id, const char *room, gpointer userdata) { |
752 if (from != to) { | 752 if (from != to) { |
753 /* tell their chat window that we left */ | 753 /* tell their chat window that we left */ |
754 purple_debug_info("nullprpl", "%s sees that %s left chat room %s\n", | 754 purple_debug_info("nullprpl", "%s sees that %s left chat room %s\n", |
755 to->nick, from->nick, room); | 755 purple_conv_chat_get_nick(to), purple_conv_chat_get_nick(from), room); |
756 purple_conv_chat_remove_user(to, | 756 purple_conv_chat_remove_user(to, |
757 from->nick, | 757 purple_conv_chat_get_nick(from), |
758 NULL); /* user-provided message, IRC style */ | 758 NULL); /* user-provided message, IRC style */ |
759 } | 759 } |
760 } | 760 } |
761 | 761 |
762 static void nullprpl_chat_leave(PurpleConnection *gc, int id) { | 762 static void nullprpl_chat_leave(PurpleConnection *gc, int id) { |
763 PurpleConversation *conv = purple_find_chat(gc, id); | 763 PurpleConversation *conv = purple_find_chat(gc, id); |
764 purple_debug_info("nullprpl", "%s is leaving chat room %s\n", | 764 purple_debug_info("nullprpl", "%s is leaving chat room %s\n", |
765 gc->account->username, conv->name); | 765 gc->account->username, purple_conversation_get_name(conv)); |
766 | 766 |
767 /* tell everyone that we left */ | 767 /* tell everyone that we left */ |
768 foreach_gc_in_chat(left_chat_room, gc, id, NULL); | 768 foreach_gc_in_chat(left_chat_room, gc, id, NULL); |
769 } | 769 } |
770 | 770 |
787 } else if (!message || !*message) { | 787 } else if (!message || !*message) { |
788 *error = g_strdup(_("Whisper is missing message.")); | 788 *error = g_strdup(_("Whisper is missing message.")); |
789 return PURPLE_CMD_RET_FAILED; | 789 return PURPLE_CMD_RET_FAILED; |
790 } | 790 } |
791 | 791 |
792 from_username = conv->account->username; | 792 from_username = purple_conversation_get_account(conv)->username; |
793 purple_debug_info("nullprpl", "%s whispers to %s in chat room %s: %s\n", | 793 purple_debug_info("nullprpl", "%s whispers to %s in chat room %s: %s\n", |
794 from_username, to_username, conv->name, message); | 794 from_username, to_username, purple_conversation_get_name(conv), message); |
795 | 795 |
796 chat = purple_conversation_get_chat_data(conv); | 796 chat = purple_conversation_get_chat_data(conv); |
797 chat_buddy = purple_conv_chat_cb_find(chat, to_username); | 797 chat_buddy = purple_conv_chat_cb_find(chat, to_username); |
798 to = get_nullprpl_gc(to_username); | 798 to = get_nullprpl_gc(to_username); |
799 | 799 |
811 PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_WHISPER, | 811 PURPLE_MESSAGE_SEND | PURPLE_MESSAGE_WHISPER, |
812 time(NULL)); | 812 time(NULL)); |
813 g_free(message_to); | 813 g_free(message_to); |
814 | 814 |
815 /* send the whisper */ | 815 /* send the whisper */ |
816 serv_chat_whisper(to, chat->id, from_username, message); | 816 serv_chat_whisper(to, purple_conv_chat_get_id(chat), from_username, message); |
817 | 817 |
818 return PURPLE_CMD_RET_OK; | 818 return PURPLE_CMD_RET_OK; |
819 } | 819 } |
820 } | 820 } |
821 | 821 |
823 const char *message) { | 823 const char *message) { |
824 const char *username = gc->account->username; | 824 const char *username = gc->account->username; |
825 PurpleConversation *conv = purple_find_chat(gc, id); | 825 PurpleConversation *conv = purple_find_chat(gc, id); |
826 purple_debug_info("nullprpl", | 826 purple_debug_info("nullprpl", |
827 "%s receives whisper from %s in chat room %s: %s\n", | 827 "%s receives whisper from %s in chat room %s: %s\n", |
828 username, who, conv->name, message); | 828 username, who, purple_conversation_get_name(conv), message); |
829 | 829 |
830 /* receive whisper on recipient's account */ | 830 /* receive whisper on recipient's account */ |
831 serv_got_chat_in(gc, id, who, PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_WHISPER, | 831 serv_got_chat_in(gc, id, who, PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_WHISPER, |
832 message, time(NULL)); | 832 message, time(NULL)); |
833 } | 833 } |
834 | 834 |
835 static void receive_chat_message(PurpleConvChat *from, PurpleConvChat *to, | 835 static void receive_chat_message(PurpleConvChat *from, PurpleConvChat *to, |
836 int id, const char *room, gpointer userdata) { | 836 int id, const char *room, gpointer userdata) { |
837 const char *message = (const char *)userdata; | 837 const char *message = (const char *)userdata; |
838 PurpleConnection *to_gc = get_nullprpl_gc(to->nick); | 838 PurpleConnection *to_gc = get_nullprpl_gc(purple_conv_chat_get_nick(to)); |
839 | 839 |
840 purple_debug_info("nullprpl", | 840 purple_debug_info("nullprpl", |
841 "%s receives message from %s in chat room %s: %s\n", | 841 "%s receives message from %s in chat room %s: %s\n", |
842 to->nick, from->nick, room, message); | 842 purple_conv_chat_get_nick(to), purple_conv_chat_get_nick(from), room, message); |
843 serv_got_chat_in(to_gc, id, from->nick, PURPLE_MESSAGE_RECV, message, | 843 serv_got_chat_in(to_gc, id, purple_conv_chat_get_nick(from), PURPLE_MESSAGE_RECV, message, |
844 time(NULL)); | 844 time(NULL)); |
845 } | 845 } |
846 | 846 |
847 static int nullprpl_chat_send(PurpleConnection *gc, int id, const char *message, | 847 static int nullprpl_chat_send(PurpleConnection *gc, int id, const char *message, |
848 PurpleMessageFlags flags) { | 848 PurpleMessageFlags flags) { |
850 PurpleConversation *conv = purple_find_chat(gc, id); | 850 PurpleConversation *conv = purple_find_chat(gc, id); |
851 | 851 |
852 if (conv) { | 852 if (conv) { |
853 purple_debug_info("nullprpl", | 853 purple_debug_info("nullprpl", |
854 "%s is sending message to chat room %s: %s\n", username, | 854 "%s is sending message to chat room %s: %s\n", username, |
855 conv->name, message); | 855 purple_conversation_get_name(conv), message); |
856 | 856 |
857 /* send message to everyone in the chat room */ | 857 /* send message to everyone in the chat room */ |
858 foreach_gc_in_chat(receive_chat_message, gc, id, (gpointer)message); | 858 foreach_gc_in_chat(receive_chat_message, gc, id, (gpointer)message); |
859 return 0; | 859 return 0; |
860 } else { | 860 } else { |
873 | 873 |
874 static void nullprpl_get_cb_info(PurpleConnection *gc, int id, const char *who) { | 874 static void nullprpl_get_cb_info(PurpleConnection *gc, int id, const char *who) { |
875 PurpleConversation *conv = purple_find_chat(gc, id); | 875 PurpleConversation *conv = purple_find_chat(gc, id); |
876 purple_debug_info("nullprpl", | 876 purple_debug_info("nullprpl", |
877 "retrieving %s's info for %s in chat room %s\n", who, | 877 "retrieving %s's info for %s in chat room %s\n", who, |
878 gc->account->username, conv->name); | 878 gc->account->username, purple_conversation_get_name(conv)); |
879 | 879 |
880 nullprpl_get_info(gc, who); | 880 nullprpl_get_info(gc, who); |
881 } | 881 } |
882 | 882 |
883 static void nullprpl_alias_buddy(PurpleConnection *gc, const char *who, | 883 static void nullprpl_alias_buddy(PurpleConnection *gc, const char *who, |
926 | 926 |
927 | 927 |
928 static void set_chat_topic_fn(PurpleConvChat *from, PurpleConvChat *to, | 928 static void set_chat_topic_fn(PurpleConvChat *from, PurpleConvChat *to, |
929 int id, const char *room, gpointer userdata) { | 929 int id, const char *room, gpointer userdata) { |
930 const char *topic = (const char *)userdata; | 930 const char *topic = (const char *)userdata; |
931 const char *username = from->conv->account->username; | 931 const char *username = purple_conversation_get_account(purple_conv_chat_get_conversation(from))->username; |
932 char *msg; | 932 char *msg; |
933 | 933 |
934 purple_conv_chat_set_topic(to, username, topic); | 934 purple_conv_chat_set_topic(to, username, topic); |
935 | 935 |
936 if (topic && *topic) | 936 if (topic && *topic) |
952 | 952 |
953 if (!chat) | 953 if (!chat) |
954 return; | 954 return; |
955 | 955 |
956 purple_debug_info("nullprpl", "%s sets topic of chat room '%s' to '%s'\n", | 956 purple_debug_info("nullprpl", "%s sets topic of chat room '%s' to '%s'\n", |
957 gc->account->username, conv->name, topic); | 957 gc->account->username, purple_conversation_get_name(conv), topic); |
958 | 958 |
959 last_topic = purple_conv_chat_get_topic(chat); | 959 last_topic = purple_conv_chat_get_topic(chat); |
960 if ((!topic && !last_topic) || | 960 if ((!topic && !last_topic) || |
961 (topic && last_topic && !strcmp(topic, last_topic))) | 961 (topic && last_topic && !strcmp(topic, last_topic))) |
962 return; /* topic is unchanged, this is a noop */ | 962 return; /* topic is unchanged, this is a noop */ |
992 /* add each chat room. the chat ids are cached in seen_ids so that each room | 992 /* add each chat room. the chat ids are cached in seen_ids so that each room |
993 * is only returned once, even if multiple users are in it. */ | 993 * is only returned once, even if multiple users are in it. */ |
994 for (chats = purple_get_chats(); chats; chats = g_list_next(chats)) { | 994 for (chats = purple_get_chats(); chats; chats = g_list_next(chats)) { |
995 PurpleConversation *conv = (PurpleConversation *)chats->data; | 995 PurpleConversation *conv = (PurpleConversation *)chats->data; |
996 PurpleRoomlistRoom *room; | 996 PurpleRoomlistRoom *room; |
997 const char *name = conv->name; | 997 const char *name = purple_conversation_get_name(conv); |
998 int id = purple_conversation_get_chat_data(conv)->id; | 998 int id = purple_conv_chat_get_id(purple_conversation_get_chat_data(conv)); |
999 | 999 |
1000 /* have we already added this room? */ | 1000 /* have we already added this room? */ |
1001 if (g_list_find_custom(seen_ids, name, (GCompareFunc)strcmp)) | 1001 if (g_list_find_custom(seen_ids, name, (GCompareFunc)strcmp)) |
1002 continue; /* yes! try the next one. */ | 1002 continue; /* yes! try the next one. */ |
1003 | 1003 |