Mercurial > pidgin.yaz
changeset 31250: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 | fcfe022982e4 |
children | fd4b918a9b2f |
files | libpurple/protocols/msn/msg.c libpurple/protocols/msn/msg.h libpurple/protocols/msn/switchboard.c |
diffstat | 3 files changed, 143 insertions(+), 139 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/msg.c Sat Jun 19 22:28:59 2010 +0000 +++ b/libpurple/protocols/msn/msg.c Sat Jun 19 22:29:55 2010 +0000 @@ -900,6 +900,145 @@ } void +msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg) +{ + MsnSession *session; + MsnSlpLink *slplink; + const char *data; + gsize len; + + session = cmdproc->servconn->session; + slplink = msn_session_get_slplink(session, msg->remote_user); + + if (slplink->swboard == NULL) + { + /* + * We will need swboard in order to change its flags. If its + * NULL, something has probably gone wrong earlier on. I + * didn't want to do this, but MSN 7 is somehow causing us + * to crash here, I couldn't reproduce it to debug more, + * and people are reporting bugs. Hopefully this doesn't + * cause more crashes. Stu. + */ + if (cmdproc->data == NULL) + g_warning("msn_p2p_msg cmdproc->data was NULL\n"); + else { + slplink->swboard = (MsnSwitchBoard *)cmdproc->data; + slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink); + } + } + + data = msn_message_get_bin_data(msg, &len); + + msn_slplink_process_msg(slplink, msg->part->header, data, len); +} + +static void +got_emoticon(MsnSlpCall *slpcall, + const guchar *data, gsize size) +{ + PurpleConversation *conv; + MsnSwitchBoard *swboard; + + swboard = slpcall->slplink->swboard; + conv = swboard->conv; + + if (conv) { + /* FIXME: it would be better if we wrote the data as we received it + instead of all at once, calling write multiple times and + close once at the very end + */ + purple_conv_custom_smiley_write(conv, slpcall->data_info, data, size); + purple_conv_custom_smiley_close(conv, slpcall->data_info ); + } + if (purple_debug_is_verbose()) + purple_debug_info("msn", "Got smiley: %s\n", slpcall->data_info); +} + +void msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg) +{ + MsnSession *session; + MsnSlpLink *slplink; + MsnSwitchBoard *swboard; + MsnObject *obj; + char **tokens; + char *smile, *body_str; + const char *body, *who, *sha1; + guint tok; + size_t body_len; + + PurpleConversation *conv; + + session = cmdproc->servconn->session; + + if (!purple_account_get_bool(session->account, "custom_smileys", TRUE)) + return; + + swboard = cmdproc->data; + conv = swboard->conv; + + body = msn_message_get_bin_data(msg, &body_len); + if (!body || !body_len) + return; + body_str = g_strndup(body, body_len); + + /* MSN Messenger 7 may send more than one MSNObject in a single message... + * Maybe 10 tokens is a reasonable max value. */ + tokens = g_strsplit(body_str, "\t", 10); + + g_free(body_str); + + for (tok = 0; tok < 9; tok += 2) { + if (tokens[tok] == NULL || tokens[tok + 1] == NULL) { + break; + } + + smile = tokens[tok]; + obj = msn_object_new_from_string(purple_url_decode(tokens[tok + 1])); + + if (obj == NULL) + break; + + who = msn_object_get_creator(obj); + sha1 = msn_object_get_sha1(obj); + + slplink = msn_session_get_slplink(session, who); + if (slplink->swboard != swboard) { + if (slplink->swboard != NULL) + /* + * Apparently we're using a different switchboard now or + * something? I don't know if this is normal, but it + * definitely happens. So make sure the old switchboard + * doesn't still have a reference to us. + */ + slplink->swboard->slplinks = g_list_remove(slplink->swboard->slplinks, slplink); + slplink->swboard = swboard; + slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink); + } + + /* If the conversation doesn't exist then this is a custom smiley + * used in the first message in a MSN conversation: we need to create + * the conversation now, otherwise the custom smiley won't be shown. + * This happens because every GtkIMHtml has its own smiley tree: if + * the conversation doesn't exist then we cannot associate the new + * smiley with its GtkIMHtml widget. */ + if (!conv) { + conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, session->account, who); + } + + if (purple_conv_custom_smiley_add(conv, smile, "sha1", sha1, TRUE)) { + msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj); + } + + msn_object_destroy(obj); + obj = NULL; + who = NULL; + sha1 = NULL; + } + g_strfreev(tokens); +} + +void msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { GHashTable *body;
--- a/libpurple/protocols/msn/msg.h Sat Jun 19 22:28:59 2010 +0000 +++ b/libpurple/protocols/msn/msg.h Sat Jun 19 22:29:55 2010 +0000 @@ -317,6 +317,10 @@ void msn_control_msg(MsnCmdProc *cmdproc, MsnMessage *msg); +void msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg); + +void msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg); + void msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg); void msn_handwritten_msg(MsnCmdProc *cmdproc, MsnMessage *msg);
--- a/libpurple/protocols/msn/switchboard.c Sat Jun 19 22:28:59 2010 +0000 +++ b/libpurple/protocols/msn/switchboard.c Sat Jun 19 22:29:55 2010 +0000 @@ -575,145 +575,6 @@ * Message Stuff **************************************************************************/ -void -msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg) -{ - MsnSession *session; - MsnSlpLink *slplink; - const char *data; - gsize len; - - session = cmdproc->servconn->session; - slplink = msn_session_get_slplink(session, msg->remote_user); - - if (slplink->swboard == NULL) - { - /* - * We will need swboard in order to change its flags. If its - * NULL, something has probably gone wrong earlier on. I - * didn't want to do this, but MSN 7 is somehow causing us - * to crash here, I couldn't reproduce it to debug more, - * and people are reporting bugs. Hopefully this doesn't - * cause more crashes. Stu. - */ - if (cmdproc->data == NULL) - g_warning("msn_p2p_msg cmdproc->data was NULL\n"); - else { - slplink->swboard = (MsnSwitchBoard *)cmdproc->data; - slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink); - } - } - - data = msn_message_get_bin_data(msg, &len); - - msn_slplink_process_msg(slplink, msg->part->header, data, len); -} - -static void -got_emoticon(MsnSlpCall *slpcall, - const guchar *data, gsize size) -{ - PurpleConversation *conv; - MsnSwitchBoard *swboard; - - swboard = slpcall->slplink->swboard; - conv = swboard->conv; - - if (conv) { - /* FIXME: it would be better if we wrote the data as we received it - instead of all at once, calling write multiple times and - close once at the very end - */ - purple_conv_custom_smiley_write(conv, slpcall->data_info, data, size); - purple_conv_custom_smiley_close(conv, slpcall->data_info ); - } - if (purple_debug_is_verbose()) - purple_debug_info("msn", "Got smiley: %s\n", slpcall->data_info); -} - -void msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg) -{ - MsnSession *session; - MsnSlpLink *slplink; - MsnSwitchBoard *swboard; - MsnObject *obj; - char **tokens; - char *smile, *body_str; - const char *body, *who, *sha1; - guint tok; - size_t body_len; - - PurpleConversation *conv; - - session = cmdproc->servconn->session; - - if (!purple_account_get_bool(session->account, "custom_smileys", TRUE)) - return; - - swboard = cmdproc->data; - conv = swboard->conv; - - body = msn_message_get_bin_data(msg, &body_len); - if (!body || !body_len) - return; - body_str = g_strndup(body, body_len); - - /* MSN Messenger 7 may send more than one MSNObject in a single message... - * Maybe 10 tokens is a reasonable max value. */ - tokens = g_strsplit(body_str, "\t", 10); - - g_free(body_str); - - for (tok = 0; tok < 9; tok += 2) { - if (tokens[tok] == NULL || tokens[tok + 1] == NULL) { - break; - } - - smile = tokens[tok]; - obj = msn_object_new_from_string(purple_url_decode(tokens[tok + 1])); - - if (obj == NULL) - break; - - who = msn_object_get_creator(obj); - sha1 = msn_object_get_sha1(obj); - - slplink = msn_session_get_slplink(session, who); - if (slplink->swboard != swboard) { - if (slplink->swboard != NULL) - /* - * Apparently we're using a different switchboard now or - * something? I don't know if this is normal, but it - * definitely happens. So make sure the old switchboard - * doesn't still have a reference to us. - */ - slplink->swboard->slplinks = g_list_remove(slplink->swboard->slplinks, slplink); - slplink->swboard = swboard; - slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink); - } - - /* If the conversation doesn't exist then this is a custom smiley - * used in the first message in a MSN conversation: we need to create - * the conversation now, otherwise the custom smiley won't be shown. - * This happens because every GtkIMHtml has its own smiley tree: if - * the conversation doesn't exist then we cannot associate the new - * smiley with its GtkIMHtml widget. */ - if (!conv) { - conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, session->account, who); - } - - if (purple_conv_custom_smiley_add(conv, smile, "sha1", sha1, TRUE)) { - msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj); - } - - msn_object_destroy(obj); - obj = NULL; - who = NULL; - sha1 = NULL; - } - g_strfreev(tokens); -} - /** Called when a message times out. */ static void msg_timeout(MsnCmdProc *cmdproc, MsnTransaction *trans)