diff --git a/sflphone-common/src/iax/iaxvoiplink.cpp b/sflphone-common/src/iax/iaxvoiplink.cpp index 51cbd95f639dc199390fd3f53553ea055259adbb..079a968f2b23c7c47adf9020d2fb8e42ce0e2dea 100644 --- a/sflphone-common/src/iax/iaxvoiplink.cpp +++ b/sflphone-common/src/iax/iaxvoiplink.cpp @@ -513,7 +513,7 @@ IAXVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) throw( bool -IAXVoIPLink::answer (const CallID& id) +IAXVoIPLink::answer (const CallID& id) throw (VoipLinkException) { IAXCall* call = getIAXCall (id); call->setCodecMap (Manager::instance().getCodecDescriptorMap()); diff --git a/sflphone-common/src/iax/iaxvoiplink.h b/sflphone-common/src/iax/iaxvoiplink.h index e516f457a7e6e9cf3ddcd8f53a31209588baf079..7efba3be4088112229be528a00d96cc175dd4224 100644 --- a/sflphone-common/src/iax/iaxvoiplink.h +++ b/sflphone-common/src/iax/iaxvoiplink.h @@ -120,7 +120,7 @@ class IAXVoIPLink : public VoIPLink * @return bool true on success * false otherwise */ - virtual bool answer (const CallID& id); + virtual bool answer (const CallID& id) throw (VoipLinkException); /** * Hangup a call diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 5253480a3def2ec014b5f7871e4cf95dbbc9d3a1..fedd05199306aac5ac637953480425a776a97863 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -363,11 +363,14 @@ bool ManagerImpl::answerCall (const CallID& call_id) } } - - if (!getAccountLink (account_id)->answer (call_id)) { - // error when receiving... - removeCallAccount (call_id); - return false; + try { + if (!getAccountLink (account_id)->answer (call_id)) { + removeCallAccount (call_id); + return false; + } + } + catch(VoipLinkException &e) { + _error("Manager: Error: %s", e.what()); } // if it was waiting, it's waiting no more diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index a3f5bf8ee60f9c495dc851fe754349843abfd07d..01c2082ab6caa60aac62175f286a3ba9ea6eee33 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -636,7 +636,7 @@ void SIPVoIPLink::sendUnregister (AccountID id) throw(VoipLinkException) account->setRegister (false); } -Call *SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) throw (VoipLinkException) // throw (SIPVoipLinkException) +Call *SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) throw (VoipLinkException) { SIPAccount * account = NULL; pj_status_t status; @@ -727,7 +727,7 @@ Call *SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) } bool -SIPVoIPLink::answer (const CallID& id) +SIPVoIPLink::answer (const CallID& id) throw (VoipLinkException) { pj_status_t status = PJ_SUCCESS; pjsip_tx_data *tdata; @@ -737,49 +737,41 @@ SIPVoIPLink::answer (const CallID& id) SIPCall *call = getSIPCall (id); -// AccountID account_id = Manager::instance().getAccountFromCall (id); -// SIPAccount *account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (account_id)); - - if (call==0) { - _debug ("UserAgent: SIPCall %s doesn't exists while answering", id.c_str()); - return false; + if (call==NULL) { + throw VoipLinkException("Call is NULL while answering"); } inv_session = call->getInvSession(); -// if (! (account->getServiceRoute().empty())) { -// -// pjsip_route_hdr *route_set = createRouteSet(account); -// pjsip_dlg_set_route_set (inv_session->dlg, route_set); -// } - if (status == PJ_SUCCESS) { - _debug ("SIPVoIPLink: UserAgent: SDP Negociation success! : call %s ", call->getCallId().c_str()); + _debug ("UserAgent: SDP Negociation success! : call %s ", call->getCallId().c_str()); // Create and send a 200(OK) response - status = pjsip_inv_answer (inv_session, PJSIP_SC_OK, NULL, NULL, &tdata); - PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1); - status = pjsip_inv_send_msg (inv_session, tdata); - PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1); + if((status = pjsip_inv_answer (inv_session, PJSIP_SC_OK, NULL, NULL, &tdata)) != PJ_SUCCESS) { + throw VoipLinkException("Could not init invite request answer (200 OK)"); + } + if((status = pjsip_inv_send_msg (inv_session, tdata)) != PJ_SUCCESS) { + throw VoipLinkException("Could not send invite request answer (200 OK)"); + } call->setConnectionState (Call::Connected); call->setState (Call::Active); return true; } else { - // Create and send a 488/Not acceptable here - // because the SDP negociation failed - status = pjsip_inv_answer (inv_session, PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL, NULL, - &tdata); - PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1); - status = pjsip_inv_send_msg (inv_session, tdata); - PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1); - + // Create and send a 488/Not acceptable because the SDP negociation failed + if((status = pjsip_inv_answer (inv_session, PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL, NULL, &tdata)) != PJ_SUCCESS) { + throw VoipLinkException("Could not init invite answer (488 not acceptable here)"); + } + if((status = pjsip_inv_send_msg (inv_session, tdata)) != PJ_SUCCESS) { + throw VoipLinkException("Could not init invite request answer (488 NOT ACCEPTABLE HERE)"); + } // Terminate the call - _debug ("SIPVoIPLink: UserAgent: SDP Negociation failed, terminate call %s ", call->getCallId().c_str()); + _debug ("UserAgent: SDP Negociation failed, terminate call %s ", call->getCallId().c_str()); - if (call->getAudioRtp()) + if (call->getAudioRtp()) { call->getAudioRtp()->stop (); + } removeCall (call->getCallId()); diff --git a/sflphone-common/src/sip/sipvoiplink.h b/sflphone-common/src/sip/sipvoiplink.h index f418463cf01880b66c16026d3ffe95490b023c78..76fc82553814c246361dc6c393c3d69b2de75cf1 100644 --- a/sflphone-common/src/sip/sipvoiplink.h +++ b/sflphone-common/src/sip/sipvoiplink.h @@ -35,9 +35,9 @@ #ifndef SIPVOIPLINK_H #define SIPVOIPLINK_H -#include "voiplink.h" -#include "hooks/urlhook.h" -#include "../im/InstantMessaging.h" +#include <map> +#include <sstream> +#include <exception> ////////////////////////////// /* PJSIP imports */ @@ -48,9 +48,9 @@ #include <pjnath/stun_config.h> /////////////////////////////// -#include <map> -#include <sstream> -#include <exception> +#include "voiplink.h" +#include "hooks/urlhook.h" +#include "../im/InstantMessaging.h" class EventThread; class SIPCall; @@ -162,7 +162,7 @@ class SIPVoIPLink : public VoIPLink * @param id The call identifier * @return int True on success */ - virtual bool answer (const CallID& id); + virtual bool answer (const CallID& id) throw (VoipLinkException); /** * Hang up the call diff --git a/sflphone-common/src/voiplink.h b/sflphone-common/src/voiplink.h index abe68c5bbf3d68a5f4e4597f3ac5e6b0d39f84dc..2b1cefd6b9909f7f293452b797c25cffa38faa4e 100644 --- a/sflphone-common/src/voiplink.h +++ b/sflphone-common/src/voiplink.h @@ -134,7 +134,7 @@ class VoIPLink * @param id The call identifier * @return bool True on success */ - virtual bool answer (const CallID& id) = 0; + virtual bool answer (const CallID& id) throw (VoipLinkException) = 0; /** * Hang up a call