comparison libpurple/protocols/msn/msg.c @ 25947:4b8c4870b13a

propagate from branch 'im.pidgin.pidgin.next.minor' (head 7305b29db7bd00d3261f348c71674c93aa31b327) to branch 'im.pidgin.pidgin' (head d8c03c68d591d9392607d954942ee58b8618d946)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Mon, 02 Mar 2009 04:18:40 +0000
parents 15fc25014ce2
children 79e043347bbe e0e0cecdcd16
comparison
equal deleted inserted replaced
25946:8998ca47e6d0 25947:4b8c4870b13a
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;
77 g_return_val_if_fail(msg != NULL, NULL); 78 g_return_val_if_fail(msg != NULL, NULL);
78 79
79 msg->ref_count++; 80 msg->ref_count++;
80 81
81 #ifdef MSN_DEBUG_MSG 82 #ifdef MSN_DEBUG_MSG
82 purple_debug_info("msn", "message ref (%p)[%d]\n", msg, msg->ref_count); 83 purple_debug_info("msn", "message ref (%p)[%" G_GSIZE_FORMAT "]\n", msg, msg->ref_count);
83 #endif 84 #endif
84 85
85 return msg; 86 return msg;
86 } 87 }
87 88
92 g_return_val_if_fail(msg->ref_count > 0, NULL); 93 g_return_val_if_fail(msg->ref_count > 0, NULL);
93 94
94 msg->ref_count--; 95 msg->ref_count--;
95 96
96 #ifdef MSN_DEBUG_MSG 97 #ifdef MSN_DEBUG_MSG
97 purple_debug_info("msn", "message unref (%p)[%d]\n", msg, msg->ref_count); 98 purple_debug_info("msn", "message unref (%p)[%" G_GSIZE_FORMAT "]\n", msg, msg->ref_count);
98 #endif 99 #endif
99 100
100 if (msg->ref_count == 0) 101 if (msg->ref_count == 0)
101 { 102 {
102 msn_message_destroy(msg); 103 msn_message_destroy(msg);
348 msg->body_len = payload_len - (tmp - tmp_base); 349 msg->body_len = payload_len - (tmp - tmp_base);
349 g_free(msg->body); 350 g_free(msg->body);
350 msg->body = g_malloc(msg->body_len + 1); 351 msg->body = g_malloc(msg->body_len + 1);
351 memcpy(msg->body, tmp, msg->body_len); 352 memcpy(msg->body, tmp, msg->body_len);
352 msg->body[msg->body_len] = '\0'; 353 msg->body[msg->body_len] = '\0';
354 }
355
356 if (msg->charset == NULL) {
357 char *body = g_convert(msg->body, msg->body_len, "UTF-8",
358 "ISO-8859-1", NULL, &msg->body_len, NULL);
359 g_free(msg->body);
360 msg->body = body;
361 msg->charset = g_strdup("UTF-8");
353 } 362 }
354 } 363 }
355 364
356 g_free(tmp_base); 365 g_free(tmp_base);
357 } 366 }
802 811
803 purple_debug_info("msn", "Message %s:\n{%s}\n", info, str->str); 812 purple_debug_info("msn", "Message %s:\n{%s}\n", info, str->str);
804 813
805 g_string_free(str, TRUE); 814 g_string_free(str, TRUE);
806 } 815 }
816
817 /**************************************************************************
818 * Message Handlers
819 **************************************************************************/
820 void
821 msn_plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
822 {
823 PurpleConnection *gc;
824 const char *body;
825 char *body_str;
826 char *body_enc;
827 char *body_final;
828 size_t body_len;
829 const char *passport;
830 const char *value;
831
832 gc = cmdproc->session->account->gc;
833
834 body = msn_message_get_bin_data(msg, &body_len);
835 body_str = g_strndup(body, body_len);
836 body_enc = g_markup_escape_text(body_str, -1);
837 g_free(body_str);
838
839 passport = msg->remote_user;
840
841 if (!strcmp(passport, "messenger@microsoft.com") &&
842 strstr(body, "immediate security update"))
843 {
844 return;
845 }
846
847 #if 0
848 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL)
849 {
850 purple_debug_misc("msn", "User-Agent = '%s'\n", value);
851 }
852 #endif
853
854 if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL)
855 {
856 char *pre, *post;
857
858 msn_parse_format(value, &pre, &post);
859
860 body_final = g_strdup_printf("%s%s%s", pre ? pre : "",
861 body_enc ? body_enc : "", post ? post : "");
862
863 g_free(pre);
864 g_free(post);
865 g_free(body_enc);
866 }
867 else
868 {
869 body_final = body_enc;
870 }
871
872 if (cmdproc->servconn->type == MSN_SERVCONN_SB) {
873 MsnSwitchBoard *swboard = cmdproc->data;
874
875 swboard->flag |= MSN_SB_FLAG_IM;
876
877 if (swboard->current_users > 1 ||
878 ((swboard->conv != NULL) &&
879 purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
880 {
881 /* If current_users is always ok as it should then there is no need to
882 * check if this is a chat. */
883 if (swboard->current_users <= 1)
884 purple_debug_misc("msn", "plain_msg: current_users(%d)\n",
885 swboard->current_users);
886
887 serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final,
888 time(NULL));
889 if (swboard->conv == NULL)
890 {
891 swboard->conv = purple_find_chat(gc, swboard->chat_id);
892 swboard->flag |= MSN_SB_FLAG_IM;
893 }
894 }
895 else
896 {
897 serv_got_im(gc, passport, body_final, 0, time(NULL));
898 if (swboard->conv == NULL)
899 {
900 swboard->conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
901 passport, purple_connection_get_account(gc));
902 swboard->flag |= MSN_SB_FLAG_IM;
903 }
904 }
905
906 } else {
907 serv_got_im(gc, passport, body_final, 0, time(NULL));
908 }
909
910 g_free(body_final);
911 }
912
913 void
914 msn_control_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
915 {
916 PurpleConnection *gc;
917 char *passport;
918
919 gc = cmdproc->session->account->gc;
920 passport = msg->remote_user;
921
922 if (msn_message_get_attr(msg, "TypingUser") == NULL)
923 return;
924
925 if (cmdproc->servconn->type == MSN_SERVCONN_SB) {
926 MsnSwitchBoard *swboard = cmdproc->data;
927
928 if (swboard->current_users == 1)
929 {
930 serv_got_typing(gc, passport, MSN_TYPING_RECV_TIMEOUT,
931 PURPLE_TYPING);
932 }
933
934 } else {
935 serv_got_typing(gc, passport, MSN_TYPING_RECV_TIMEOUT,
936 PURPLE_TYPING);
937 }
938 }
939
940 void
941 msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
942 {
943 GHashTable *body;
944 const char *id;
945 body = msn_message_get_hashtable_from_body(msg);
946
947 id = g_hash_table_lookup(body, "ID");
948
949 if (!strcmp(id, "1")) {
950 /* Nudge */
951 PurpleAccount *account;
952 const char *user;
953
954 account = cmdproc->session->account;
955 user = msg->remote_user;
956
957 if (cmdproc->servconn->type == MSN_SERVCONN_SB) {
958 MsnSwitchBoard *swboard = cmdproc->data;
959 if (swboard->current_users > 1 ||
960 ((swboard->conv != NULL) &&
961 purple_conversation_get_type(swboard->conv) == PURPLE_CONV_TYPE_CHAT))
962 purple_prpl_got_attention_in_chat(account->gc, swboard->chat_id, user, MSN_NUDGE);
963
964 else
965 purple_prpl_got_attention(account->gc, user, MSN_NUDGE);
966
967 } else {
968 purple_prpl_got_attention(account->gc, user, MSN_NUDGE);
969 }
970
971 } else if (!strcmp(id, "2")) {
972 /* Wink */
973
974 } else if (!strcmp(id, "3")) {
975 /* Voiceclip */
976
977 } else if (!strcmp(id, "4")) {
978 /* Action */
979
980 } else {
981 purple_debug_warning("msn", "Got unknown datacast with ID %s.\n", id);
982 }
983
984 g_hash_table_destroy(body);
985 }
986