Mercurial > pidgin
comparison libpurple/protocols/msn/msg.c @ 30812:623e38669111
Move MsnMessage callbacks to msn.c instead of polluting everywhere.
author | masca@cpw.pidgin.im |
---|---|
date | Sat, 19 Jun 2010 22:29:55 +0000 |
parents | fd8abea40a0d |
children | 4b0cb9435414 |
comparison
equal
deleted
inserted
replaced
30811:fcfe022982e4 | 30812:623e38669111 |
---|---|
898 fclose(f); | 898 fclose(f); |
899 g_free(path); | 899 g_free(path); |
900 } | 900 } |
901 | 901 |
902 void | 902 void |
903 msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
904 { | |
905 MsnSession *session; | |
906 MsnSlpLink *slplink; | |
907 const char *data; | |
908 gsize len; | |
909 | |
910 session = cmdproc->servconn->session; | |
911 slplink = msn_session_get_slplink(session, msg->remote_user); | |
912 | |
913 if (slplink->swboard == NULL) | |
914 { | |
915 /* | |
916 * We will need swboard in order to change its flags. If its | |
917 * NULL, something has probably gone wrong earlier on. I | |
918 * didn't want to do this, but MSN 7 is somehow causing us | |
919 * to crash here, I couldn't reproduce it to debug more, | |
920 * and people are reporting bugs. Hopefully this doesn't | |
921 * cause more crashes. Stu. | |
922 */ | |
923 if (cmdproc->data == NULL) | |
924 g_warning("msn_p2p_msg cmdproc->data was NULL\n"); | |
925 else { | |
926 slplink->swboard = (MsnSwitchBoard *)cmdproc->data; | |
927 slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink); | |
928 } | |
929 } | |
930 | |
931 data = msn_message_get_bin_data(msg, &len); | |
932 | |
933 msn_slplink_process_msg(slplink, msg->part->header, data, len); | |
934 } | |
935 | |
936 static void | |
937 got_emoticon(MsnSlpCall *slpcall, | |
938 const guchar *data, gsize size) | |
939 { | |
940 PurpleConversation *conv; | |
941 MsnSwitchBoard *swboard; | |
942 | |
943 swboard = slpcall->slplink->swboard; | |
944 conv = swboard->conv; | |
945 | |
946 if (conv) { | |
947 /* FIXME: it would be better if we wrote the data as we received it | |
948 instead of all at once, calling write multiple times and | |
949 close once at the very end | |
950 */ | |
951 purple_conv_custom_smiley_write(conv, slpcall->data_info, data, size); | |
952 purple_conv_custom_smiley_close(conv, slpcall->data_info ); | |
953 } | |
954 if (purple_debug_is_verbose()) | |
955 purple_debug_info("msn", "Got smiley: %s\n", slpcall->data_info); | |
956 } | |
957 | |
958 void msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
959 { | |
960 MsnSession *session; | |
961 MsnSlpLink *slplink; | |
962 MsnSwitchBoard *swboard; | |
963 MsnObject *obj; | |
964 char **tokens; | |
965 char *smile, *body_str; | |
966 const char *body, *who, *sha1; | |
967 guint tok; | |
968 size_t body_len; | |
969 | |
970 PurpleConversation *conv; | |
971 | |
972 session = cmdproc->servconn->session; | |
973 | |
974 if (!purple_account_get_bool(session->account, "custom_smileys", TRUE)) | |
975 return; | |
976 | |
977 swboard = cmdproc->data; | |
978 conv = swboard->conv; | |
979 | |
980 body = msn_message_get_bin_data(msg, &body_len); | |
981 if (!body || !body_len) | |
982 return; | |
983 body_str = g_strndup(body, body_len); | |
984 | |
985 /* MSN Messenger 7 may send more than one MSNObject in a single message... | |
986 * Maybe 10 tokens is a reasonable max value. */ | |
987 tokens = g_strsplit(body_str, "\t", 10); | |
988 | |
989 g_free(body_str); | |
990 | |
991 for (tok = 0; tok < 9; tok += 2) { | |
992 if (tokens[tok] == NULL || tokens[tok + 1] == NULL) { | |
993 break; | |
994 } | |
995 | |
996 smile = tokens[tok]; | |
997 obj = msn_object_new_from_string(purple_url_decode(tokens[tok + 1])); | |
998 | |
999 if (obj == NULL) | |
1000 break; | |
1001 | |
1002 who = msn_object_get_creator(obj); | |
1003 sha1 = msn_object_get_sha1(obj); | |
1004 | |
1005 slplink = msn_session_get_slplink(session, who); | |
1006 if (slplink->swboard != swboard) { | |
1007 if (slplink->swboard != NULL) | |
1008 /* | |
1009 * Apparently we're using a different switchboard now or | |
1010 * something? I don't know if this is normal, but it | |
1011 * definitely happens. So make sure the old switchboard | |
1012 * doesn't still have a reference to us. | |
1013 */ | |
1014 slplink->swboard->slplinks = g_list_remove(slplink->swboard->slplinks, slplink); | |
1015 slplink->swboard = swboard; | |
1016 slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink); | |
1017 } | |
1018 | |
1019 /* If the conversation doesn't exist then this is a custom smiley | |
1020 * used in the first message in a MSN conversation: we need to create | |
1021 * the conversation now, otherwise the custom smiley won't be shown. | |
1022 * This happens because every GtkIMHtml has its own smiley tree: if | |
1023 * the conversation doesn't exist then we cannot associate the new | |
1024 * smiley with its GtkIMHtml widget. */ | |
1025 if (!conv) { | |
1026 conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, session->account, who); | |
1027 } | |
1028 | |
1029 if (purple_conv_custom_smiley_add(conv, smile, "sha1", sha1, TRUE)) { | |
1030 msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj); | |
1031 } | |
1032 | |
1033 msn_object_destroy(obj); | |
1034 obj = NULL; | |
1035 who = NULL; | |
1036 sha1 = NULL; | |
1037 } | |
1038 g_strfreev(tokens); | |
1039 } | |
1040 | |
1041 void | |
903 msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | 1042 msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
904 { | 1043 { |
905 GHashTable *body; | 1044 GHashTable *body; |
906 const char *id; | 1045 const char *id; |
907 body = msn_message_get_hashtable_from_body(msg); | 1046 body = msn_message_get_hashtable_from_body(msg); |