Mercurial > pidgin
changeset 24207:fb722b8b4c74
attempts to resend message on switchboard error once, tested by maually
disabling switchboard connection on the receiving side
I have a feeling that there is a real bug somewhere, but this would at
least allow the message to make through (after some delay)
References #3330
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Tue, 30 Sep 2008 05:52:57 +0000 |
parents | 9340e1db0f46 |
children | c5b225367947 |
files | libpurple/protocols/msn/msg.c libpurple/protocols/msn/msg.h libpurple/protocols/msn/msn.c libpurple/protocols/msn/msn.h libpurple/protocols/msn/switchboard.c libpurple/protocols/msn/switchboard.h |
diffstat | 6 files changed, 75 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/msn/msg.c Tue Sep 30 00:49:53 2008 +0000 +++ b/libpurple/protocols/msn/msg.c Tue Sep 30 05:52:57 2008 +0000 @@ -114,6 +114,7 @@ char *message_cr; msg = msn_message_new(MSN_MSG_TEXT); + msg->retries = 1; msn_message_set_attr(msg, "User-Agent", PACKAGE_NAME "/" VERSION); msn_message_set_content_type(msg, "text/plain"); msn_message_set_charset(msg, "UTF-8");
--- a/libpurple/protocols/msn/msg.h Tue Sep 30 00:49:53 2008 +0000 +++ b/libpurple/protocols/msn/msg.h Tue Sep 30 05:52:57 2008 +0000 @@ -129,6 +129,8 @@ void *ack_data; /**< The data used by callbacks. */ MsnMsgErrorType error; /**< The error of the message. */ + + guint32 retries; }; /** @@ -243,24 +245,6 @@ */ char msn_message_get_flag(const MsnMessage *msg); -#if 0 -/** - * Sets the body of a message. - * - * @param msg The message. - * @param body The body of the message. - */ -void msn_message_set_body(MsnMessage *msg, const char *body); - -/** - * Returns the body of the message. - * - * @param msg The message. - * - * @return The body of the message. - */ -const char *msn_message_get_body(const MsnMessage *msg); -#endif /** * Sets the binary content of the message. *
--- a/libpurple/protocols/msn/msn.c Tue Sep 30 00:49:53 2008 +0000 +++ b/libpurple/protocols/msn/msn.c Tue Sep 30 05:52:57 2008 +0000 @@ -42,6 +42,7 @@ #include "msnutils.h" #include "version.h" +#include "msg.h" #include "switchboard.h" #include "notification.h" #include "sync.h" @@ -1115,6 +1116,31 @@ return list; } +void +msn_send_im_message(MsnSession *session, MsnMessage *msg) +{ + MsnEmoticon *smile; + GSList *smileys; + GString *emoticons = NULL; + const char *username = purple_account_get_username(session->account); + MsnSwitchBoard *swboard = msn_session_get_swboard(session, msg->remote_user, MSN_SB_FLAG_IM); + + smileys = msn_msg_grab_emoticons(msg->body, username); + while (smileys) { + smile = (MsnEmoticon*)smileys->data; + emoticons = msn_msg_emoticon_add(emoticons, smile); + msn_emoticon_destroy(smile); + smileys = g_slist_delete_link(smileys, smileys); + } + + if (emoticons) { + msn_send_emoticons(swboard, emoticons); + g_string_free(emoticons, TRUE); + } + + msn_switchboard_send_msg(swboard, msg, TRUE); +} + static int msn_send_im(PurpleConnection *gc, const char *who, const char *message, PurpleMessageFlags flags) @@ -1177,31 +1203,13 @@ purple_debug_info("msn", "prepare to send online Message\n"); if (g_ascii_strcasecmp(who, username)) { - MsnEmoticon *smile; - GSList *smileys; - GString *emoticons = NULL; - if (msn_user_is_yahoo(account, who)) { /*we send the online and offline Message to Yahoo User via UBM*/ purple_debug_info("msn", "send to Yahoo User\n"); uum_send_msg(session, msg); } else { purple_debug_info("msn", "send via switchboard\n"); - swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); - smileys = msn_msg_grab_emoticons(message, username); - while (smileys) { - smile = (MsnEmoticon*)smileys->data; - emoticons = msn_msg_emoticon_add(emoticons, smile); - msn_emoticon_destroy(smile); - smileys = g_slist_delete_link(smileys, smileys); - } - - if (emoticons) { - msn_send_emoticons(swboard, emoticons); - g_string_free(emoticons, TRUE); - } - - msn_switchboard_send_msg(swboard, msg, TRUE); + msn_send_im_message(session, msg); } } else
--- a/libpurple/protocols/msn/msn.h Tue Sep 30 00:49:53 2008 +0000 +++ b/libpurple/protocols/msn/msn.h Tue Sep 30 05:52:57 2008 +0000 @@ -55,6 +55,8 @@ #include "ft.h" +#include "msg.h" + #define MSN_BUF_LEN 8192 /* Windows Live Messenger Server*/ @@ -142,5 +144,6 @@ void msn_act_id(PurpleConnection *gc, const char *entry); void msn_send_privacy(PurpleConnection *gc); +void msn_send_im_message(MsnSession *session, MsnMessage *msg); #endif /* _MSN_H_ */
--- a/libpurple/protocols/msn/switchboard.c Tue Sep 30 00:49:53 2008 +0000 +++ b/libpurple/protocols/msn/switchboard.c Tue Sep 30 05:52:57 2008 +0000 @@ -375,6 +375,19 @@ g_strfreev(params); } +static gboolean +msg_resend_cb(gpointer data) +{ + MsnSwitchBoard *swboard = data; + + purple_debug_info("msn", "unqueuing unsent message to %s", swboard->im_user); + + msn_switchboard_request(swboard); + msn_switchboard_request_add_user(swboard, swboard->im_user); + swboard->reconn_timeout_h = 0; + return FALSE; +} + static void msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, MsnMsgErrorType error) { @@ -413,6 +426,34 @@ } else if (error == MSN_MSG_ERROR_SB) { + MsnSession *session = swboard->session; + + if (!session->destroying && msg->retries && swboard->im_user && + (swboard->error == MSN_SB_ERROR_CONNECTION || + swboard->error == MSN_SB_ERROR_UNKNOWN)) { + MsnSwitchBoard *new_sw = msn_session_find_swboard(session, + swboard->im_user); + + if (new_sw == NULL || new_sw->reconn_timeout_h == 0) { + new_sw = msn_switchboard_new(session); + new_sw->im_user = g_strdup(swboard->im_user); + new_sw->reconn_timeout_h = purple_timeout_add_seconds(3, msg_resend_cb, new_sw); + new_sw->flag |= MSN_SB_FLAG_IM; + } + + body_str = msn_message_to_string(msg); + body_enc = g_markup_escape_text(body_str, -1); + g_free(body_str); + + purple_debug_info("msn", "queuing unsent message to %s: %s", + swboard->im_user, body_enc); + g_free(body_enc); + msn_send_im_message(session, msg); + msg->retries--; + + return; + } + switch (swboard->error) { case MSN_SB_ERROR_OFFLINE:
--- a/libpurple/protocols/msn/switchboard.h Tue Sep 30 00:49:53 2008 +0000 +++ b/libpurple/protocols/msn/switchboard.h Tue Sep 30 05:52:57 2008 +0000 @@ -104,6 +104,7 @@ MsnSBErrorType error; /**< The error that occurred in this switchboard (if applicable). */ GList *slplinks; /**< The list of slplinks that are using this switchboard. */ + guint reconn_timeout_h; }; /**