/*destroy the oim object*/ void msn_oim_destroy(MsnOim *oim) { MsnOimSendReq *request; purple_debug_info("msn", "destroy the OIM %p\n", oim); g_free(oim->run_id); g_free(oim->challenge); while ((request = g_queue_pop_head(oim->send_queue)) != NULL) msn_oim_free_send_req(request); g_queue_free(oim->send_queue); while (oim->oim_list != NULL) msn_oim_recv_data_free((MsnOimRecvData *)oim->oim_list->data); g_free(oim); }
/* * Process the send return SOAP string * If got SOAP Fault,get the lock key,and resend it. */ static void msn_oim_send_read_cb(MsnSoapMessage *request, MsnSoapMessage *response, gpointer data) { MsnOim *oim = data; MsnOimSendReq *msg = g_queue_pop_head(oim->send_queue); g_return_if_fail(msg != NULL); if (response == NULL) { purple_debug_info("msn", "cannot send OIM: %s\n", msg->oim_msg); } else { PurpleXmlNode *faultNode = purple_xmlnode_get_child(msn_soap_message_get_xml(response), "Body/Fault"); if (faultNode == NULL) { /*Send OK! return*/ purple_debug_info("msn", "sent OIM: %s\n", msg->oim_msg); } else { PurpleXmlNode *faultcode = purple_xmlnode_get_child(faultNode, "faultcode"); if (faultcode) { char *faultcode_str = purple_xmlnode_get_data(faultcode); if (faultcode_str && g_str_equal(faultcode_str, "q0:AuthenticationFailed")) { PurpleXmlNode *challengeNode = purple_xmlnode_get_child(faultNode, "detail/LockKeyChallenge"); char *challenge = NULL; if (challengeNode == NULL || (challenge = purple_xmlnode_get_data(challengeNode)) == NULL) { if (oim->challenge) { g_free(oim->challenge); oim->challenge = NULL; purple_debug_info("msn", "Resending OIM: %s\n", msg->oim_msg); g_queue_push_head(oim->send_queue, msg); msn_oim_send_msg(oim); msg = NULL; } else { purple_debug_info("msn", "Can't find lock key for OIM: %s\n", msg->oim_msg); } } else { char buf[33]; msn_handle_chl(challenge, buf); g_free(oim->challenge); oim->challenge = g_strndup(buf, sizeof(buf)); g_free(challenge); purple_debug_info("msn", "Found lockkey:{%s}\n", oim->challenge); /*repost the send*/ purple_debug_info("msn", "Resending OIM: %s\n", msg->oim_msg); g_queue_push_head(oim->send_queue, msg); msn_oim_send_msg(oim); msg = NULL; } } else { /* Report the error */ const char *str_reason = NULL; if (faultcode_str) { if (g_str_equal(faultcode_str, "q0:SystemUnavailable")) { str_reason = _("Message was not sent because the system is " "unavailable. This normally happens when the " "user is blocked or does not exist."); } else if (g_str_equal(faultcode_str, "q0:SenderThrottleLimitExceeded")) { str_reason = _("Message was not sent because messages " "are being sent too quickly."); } else if (g_str_equal(faultcode_str, "q0:InvalidContent")) { str_reason = _("Message was not sent because an unknown " "encoding error occurred."); } } if (str_reason == NULL) { str_reason = _("Message was not sent because an unknown " "error occurred."); } msn_session_report_user(oim->session, msg->to_member, str_reason, PURPLE_MESSAGE_ERROR); msn_session_report_user(oim->session, msg->to_member, msg->oim_msg, PURPLE_MESSAGE_RAW); } g_free(faultcode_str); } } } if (msg) msn_oim_free_send_req(msg); }