gchar *sipmsg_apply_x_mms_im_format(const char *x_mms_im_format, gchar *body) { char *pre, *post; gchar *res; if (!x_mms_im_format) { return body ? g_strdup(body) : NULL; } msn_parse_format(x_mms_im_format, &pre, &post); res = g_strdup_printf("%s%s%s", pre ? pre : "", body ? body : "", post ? post : ""); g_free(pre); g_free(post); return res; }
static void msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, MsnMsgErrorType error) { MsnSwitchBoard *swboard; g_return_if_fail(cmdproc != NULL); g_return_if_fail(msg != NULL); if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL)) msg->nak_cb(msg, msg->ack_data); swboard = cmdproc->data; /* This is not good, and should be fixed somewhere else. */ g_return_if_fail(swboard != NULL); if (msg->type == MSN_MSG_TEXT) { const char *format, *str_reason; char *body_str, *body_enc, *pre, *post; #if 0 if (swboard->conv == NULL) { if (msg->ack_ref) msn_message_unref(msg); return; } #endif if (error == MSN_MSG_ERROR_TIMEOUT) { str_reason = _("Message may have not been sent " "because a timeout occurred:"); } 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\n", 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: str_reason = _("Message could not be sent, " "not allowed while invisible:"); break; case MSN_SB_ERROR_USER_OFFLINE: str_reason = _("Message could not be sent " "because the user is offline:"); break; case MSN_SB_ERROR_CONNECTION: str_reason = _("Message could not be sent " "because a connection error occurred:"); break; case MSN_SB_ERROR_TOO_FAST: str_reason = _("Message could not be sent " "because we are sending too quickly:"); break; case MSN_SB_ERROR_AUTHFAILED: str_reason = _("Message could not be sent " "because we were unable to establish a " "session with the server. This is " "likely a server problem, try again in " "a few minutes:"); break; default: str_reason = _("Message could not be sent " "because an error with " "the switchboard occurred:"); break; } } else { str_reason = _("Message may have not been sent " "because an unknown error occurred:"); } body_str = msn_message_to_string(msg); body_enc = g_markup_escape_text(body_str, -1); g_free(body_str); format = msn_message_get_attr(msg, "X-MMS-IM-Format"); msn_parse_format(format, &pre, &post); body_str = g_strdup_printf("%s%s%s", pre ? pre : "", body_enc ? body_enc : "", post ? post : ""); g_free(body_enc); g_free(pre); g_free(post); msn_switchboard_report_user(swboard, PURPLE_MESSAGE_ERROR, str_reason); msn_switchboard_report_user(swboard, PURPLE_MESSAGE_RAW, body_str); g_free(body_str); } /* If a timeout occures we will want the msg around just in case we * receive the ACK after the timeout. */ if (msg->ack_ref && error != MSN_MSG_ERROR_TIMEOUT) { swboard->ack_list = g_list_remove(swboard->ack_list, msg); msn_message_unref(msg); } }
/************************************************************************** * Message Handlers **************************************************************************/ void msn_plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { PurpleConnection *gc; const char *body; char *body_enc; char *body_final; size_t body_len; const char *passport; const char *value; gc = purple_account_get_connection(cmdproc->session->account); body = msn_message_get_bin_data(msg, &body_len); body_enc = g_markup_escape_text(body, body_len); passport = msg->remote_user; if (!strcmp(passport, "*****@*****.**") && strstr(body, "immediate security update")) { return; } #if 0 if ((value = msn_message_get_header_value(msg, "User-Agent")) != NULL) { purple_debug_misc("msn", "User-Agent = '%s'\n", value); } #endif if ((value = msn_message_get_header_value(msg, "X-MMS-IM-Format")) != NULL) { char *pre, *post; msn_parse_format(value, &pre, &post); body_final = g_strdup_printf("%s%s%s", pre ? pre : "", body_enc ? body_enc : "", post ? post : ""); g_free(pre); g_free(post); g_free(body_enc); } else { body_final = body_enc; } if (cmdproc->servconn->type == MSN_SERVCONN_SB) { MsnSwitchBoard *swboard = cmdproc->data; swboard->flag |= MSN_SB_FLAG_IM; if (swboard->current_users > 1 || ((swboard->conv != NULL) && PURPLE_IS_CHAT_CONVERSATION(swboard->conv))) { /* If current_users is always ok as it should then there is no need to * check if this is a chat. */ if (swboard->current_users <= 1) purple_debug_misc("msn", "plain_msg: current_users(%d)\n", swboard->current_users); purple_serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, time(NULL)); if (swboard->conv == NULL) { swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat(gc, swboard->chat_id)); swboard->flag |= MSN_SB_FLAG_IM; } } else if (!g_str_equal(passport, purple_account_get_username(purple_connection_get_account(gc)))) { /* Don't im ourselves ... */ purple_serv_got_im(gc, passport, body_final, 0, time(NULL)); if (swboard->conv == NULL) { swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account( passport, purple_connection_get_account(gc))); swboard->flag |= MSN_SB_FLAG_IM; } } } else { purple_serv_got_im(gc, passport, body_final, 0, time(NULL)); } g_free(body_final); }
/************************************************************************** * Message Handlers **************************************************************************/ static void plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { GaimConnection *gc; MsnSwitchBoard *swboard; const char *body; char *body_str; char *body_enc; char *body_final; size_t body_len; const char *passport; const char *value; gc = cmdproc->session->account->gc; swboard = cmdproc->data; body = msn_message_get_bin_data(msg, &body_len); body_str = g_strndup(body, body_len); body_enc = g_markup_escape_text(body_str, -1); g_free(body_str); passport = msg->remote_user; if (!strcmp(passport, "*****@*****.**") && strstr(body, "immediate security update")) { return; } #if 0 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { gaim_debug_misc("msn", "User-Agent = '%s'\n", value); } #endif if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) { char *pre, *post; msn_parse_format(value, &pre, &post); body_final = g_strdup_printf("%s%s%s", pre ? pre : "", body_enc ? body_enc : "", post ? post : ""); g_free(pre); g_free(post); g_free(body_enc); } else { body_final = body_enc; } swboard->flag |= MSN_SB_FLAG_IM; if (swboard->current_users > 1 || ((swboard->conv != NULL) && gaim_conversation_get_type(swboard->conv) == GAIM_CONV_TYPE_CHAT)) { /* If current_users is always ok as it should then there is no need to * check if this is a chat. */ if (swboard->current_users <= 1) gaim_debug_misc("msn", "plain_msg: current_users(%d)\n", swboard->current_users); serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_chat(gc, swboard->chat_id); swboard->flag |= MSN_SB_FLAG_IM; } } else { serv_got_im(gc, passport, body_final, 0, time(NULL)); if (swboard->conv == NULL) { swboard->conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, passport, gaim_connection_get_account(gc)); swboard->flag |= MSN_SB_FLAG_IM; } } g_free(body_final); }
static void msg_error_helper(MsnCmdProc *cmdproc, MsnMessage *msg, MsnMsgErrorType error) { MsnSwitchBoard *swboard; g_return_if_fail(cmdproc != NULL); g_return_if_fail(msg != NULL); if ((error != MSN_MSG_ERROR_SB) && (msg->nak_cb != NULL)) msg->nak_cb(msg, msg->ack_data); swboard = cmdproc->data; /* This is not good, and should be fixed somewhere else. */ g_return_if_fail(swboard != NULL); if (msg->type == MSN_MSG_TEXT) { const char *format, *str_reason; char *body_str, *body_enc, *pre, *post; #if 0 if (swboard->conv == NULL) { if (msg->ack_ref) msn_message_unref(msg); return; } #endif if (error == MSN_MSG_ERROR_TIMEOUT) { str_reason = _("Message may have not been sent " "because a timeout occurred:"); } else if (error == MSN_MSG_ERROR_SB) { switch (swboard->error) { case MSN_SB_ERROR_OFFLINE: str_reason = _("Message could not be sent, " "not allowed while invisible:"); break; case MSN_SB_ERROR_USER_OFFLINE: str_reason = _("Message could not be sent " "because the user is offline:"); break; case MSN_SB_ERROR_CONNECTION: str_reason = _("Message could not be sent " "because a connection error occurred:"); break; case MSN_SB_ERROR_TOO_FAST: str_reason = _("Message could not be sent " "because we are sending too quickly:"); break; default: str_reason = _("Message could not be sent " "because an error with " "the switchboard occurred:"); break; } } else { str_reason = _("Message may have not been sent " "because an unknown error occurred:"); } body_str = msn_message_to_string(msg); body_enc = g_markup_escape_text(body_str, -1); g_free(body_str); format = msn_message_get_attr(msg, "X-MMS-IM-Format"); msn_parse_format(format, &pre, &post); body_str = g_strdup_printf("%s%s%s", pre ? pre : "", body_enc ? body_enc : "", post ? post : ""); g_free(body_enc); g_free(pre); g_free(post); msn_switchboard_report_user(swboard, GAIM_MESSAGE_ERROR, str_reason); msn_switchboard_report_user(swboard, GAIM_MESSAGE_RAW, body_str); g_free(body_str); } /* If a timeout occures we will want the msg around just in case we * receive the ACK after the timeout. */ if (msg->ack_ref && error != MSN_MSG_ERROR_TIMEOUT) { swboard->ack_list = g_list_remove(swboard->ack_list, msg); msn_message_unref(msg); } }