Mercurial > pidgin
comparison libpurple/protocols/msn/msg.c @ 25398:ea98810d89c5
Move some MSN message handlers from switchboard to general msg.c.
References #7676.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Sun, 01 Feb 2009 08:25:57 +0000 |
parents | b0e069922896 |
children | 8ee34225cfd9 |
comparison
equal
deleted
inserted
replaced
25397:3e89d2c6bf93 | 25398:ea98810d89c5 |
---|---|
21 * along with this program; if not, write to the Free Software | 21 * along with this program; if not, write to the Free Software |
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA | 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
23 */ | 23 */ |
24 #include "msn.h" | 24 #include "msn.h" |
25 #include "msg.h" | 25 #include "msg.h" |
26 #include "msnutils.h" | |
26 | 27 |
27 MsnMessage * | 28 MsnMessage * |
28 msn_message_new(MsnMsgType type) | 29 msn_message_new(MsnMsgType type) |
29 { | 30 { |
30 MsnMessage *msg; | 31 MsnMessage *msg; |
802 | 803 |
803 purple_debug_info("msn", "Message %s:\n{%s}\n", info, str->str); | 804 purple_debug_info("msn", "Message %s:\n{%s}\n", info, str->str); |
804 | 805 |
805 g_string_free(str, TRUE); | 806 g_string_free(str, TRUE); |
806 } | 807 } |
808 | |
809 /************************************************************************** | |
810 * Message Handlers | |
811 **************************************************************************/ | |
812 void | |
813 msn_plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
814 { | |
815 PurpleConnection *gc; | |
816 MsnSwitchBoard *swboard; | |
817 const char *body; | |
818 char *body_str; | |
819 char *body_enc; | |
820 char *body_final; | |
821 size_t body_len; | |
822 const char *passport; | |
823 const char *value; | |
824 | |
825 gc = cmdproc->session->account->gc; | |
826 swboard = cmdproc->data; | |
827 | |
828 body = msn_message_get_bin_data(msg, &body_len); | |
829 body_str = g_strndup(body, body_len); | |
830 body_enc = g_markup_escape_text(body_str, -1); | |
831 g_free(body_str); | |
832 | |
833 passport = msg->remote_user; | |
834 | |
835 if (!strcmp(passport, "messenger@microsoft.com") && | |
836 strstr(body, "immediate security update")) | |
837 { | |
838 return; | |
839 } | |
840 | |
841 #if 0 | |
842 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) | |
843 { | |
844 purple_debug_misc("msn", "User-Agent = '%s'\n", value); | |
845 } | |
846 #endif | |
847 | |
848 if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) | |
849 { | |
850 char *pre, *post; | |
851 | |
852 msn_parse_format(value, &pre, &post); | |
853 | |
854 body_final = g_strdup_printf("%s%s%s", pre ? pre : "", | |
855 body_enc ? body_enc : "", post ? post : ""); | |
856 | |
857 g_free(pre); | |
858 g_free(post); | |
859 g_free(body_enc); | |
860 } | |
861 else | |
862 { | |
863 body_final = body_enc; | |
864 } | |
865 | |
866 swboard->flag |= MSN_SB_FLAG_IM; | |
867 | |
868 if (swboard->current_users > 1 || | |
869 ((swboard->conv != NULL) && | |
870 purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT)) | |
871 { | |
872 /* If current_users is always ok as it should then there is no need to | |
873 * check if this is a chat. */ | |
874 if (swboard->current_users <= 1) | |
875 purple_debug_misc("msn", "plain_msg: current_users(%d)\n", | |
876 swboard->current_users); | |
877 | |
878 serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, | |
879 time(NULL)); | |
880 if (swboard->conv == NULL) | |
881 { | |
882 swboard->conv = purple_find_chat(gc, swboard->chat_id); | |
883 swboard->flag |= MSN_SB_FLAG_IM; | |
884 } | |
885 } | |
886 else | |
887 { | |
888 serv_got_im(gc, passport, body_final, 0, time(NULL)); | |
889 if (swboard->conv == NULL) | |
890 { | |
891 swboard->conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, | |
892 passport, purple_connection_get_account(gc)); | |
893 swboard->flag |= MSN_SB_FLAG_IM; | |
894 } | |
895 } | |
896 | |
897 g_free(body_final); | |
898 } | |
899 | |
900 void | |
901 msn_control_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
902 { | |
903 PurpleConnection *gc; | |
904 MsnSwitchBoard *swboard; | |
905 char *passport; | |
906 | |
907 gc = cmdproc->session->account->gc; | |
908 swboard = cmdproc->data; | |
909 passport = msg->remote_user; | |
910 | |
911 if (swboard->current_users == 1 && | |
912 msn_message_get_attr(msg, "TypingUser") != NULL) | |
913 { | |
914 serv_got_typing(gc, passport, MSN_TYPING_RECV_TIMEOUT, | |
915 PURPLE_TYPING); | |
916 } | |
917 } | |
918 | |
919 void | |
920 msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
921 { | |
922 GHashTable *body; | |
923 const char *id; | |
924 body = msn_message_get_hashtable_from_body(msg); | |
925 | |
926 id = g_hash_table_lookup(body, "ID"); | |
927 | |
928 if (!strcmp(id, "1")) { | |
929 /* Nudge */ | |
930 MsnSwitchBoard *swboard; | |
931 PurpleAccount *account; | |
932 const char *user; | |
933 | |
934 swboard = cmdproc->data; | |
935 account = cmdproc->session->account; | |
936 user = msg->remote_user; | |
937 | |
938 if (swboard->current_users > 1 || | |
939 ((swboard->conv != NULL) && | |
940 purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT)) | |
941 purple_prpl_got_attention_in_chat(account->gc, swboard->chat_id, user, MSN_NUDGE); | |
942 | |
943 else | |
944 purple_prpl_got_attention(account->gc, user, MSN_NUDGE); | |
945 | |
946 } else if (!strcmp(id, "2")) { | |
947 /* Wink */ | |
948 | |
949 } else if (!strcmp(id, "3")) { | |
950 /* Voiceclip */ | |
951 | |
952 } else if (!strcmp(id, "4")) { | |
953 /* Action */ | |
954 | |
955 } else { | |
956 purple_debug_warning("msn", "Got unknown datacast with ID %s.\n", id); | |
957 } | |
958 | |
959 g_hash_table_destroy(body); | |
960 } | |
961 |