From 3ca9b414219504aa4a39caefeadf28bf1b99ad39 Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Tue, 4 Dec 2012 18:09:15 -0500 Subject: [PATCH] * #18237: sip: respond with 415 error code if dealing with unsupported media This is not ideal because it means changing the API of voiplink et al. We could alternately store the reason in the call but this gets messy as far as state is concerned. --- daemon/src/iax/iaxvoiplink.cpp | 2 +- daemon/src/iax/iaxvoiplink.h | 2 +- daemon/src/managerimpl.cpp | 6 +++--- daemon/src/sip/sipvoiplink.cpp | 11 +++++++---- daemon/src/sip/sipvoiplink.h | 2 +- daemon/src/voiplink.h | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index aaf1333cf2..12e4a95d01 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -288,7 +288,7 @@ IAXVoIPLink::answer(Call *call) } void -IAXVoIPLink::hangup(const std::string& id) +IAXVoIPLink::hangup(const std::string& id, int reason UNUSED) { IAXCall* call = getIAXCall(id); diff --git a/daemon/src/iax/iaxvoiplink.h b/daemon/src/iax/iaxvoiplink.h index d7b53d9f9c..0d37b89b1f 100644 --- a/daemon/src/iax/iaxvoiplink.h +++ b/daemon/src/iax/iaxvoiplink.h @@ -121,7 +121,7 @@ class IAXVoIPLink : public VoIPLink { * Hangup a call * @param id The ID of the call */ - virtual void hangup(const std::string& id); + virtual void hangup(const std::string& id, int reason); /** * Peer Hungup a call diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index ca8cc995a1..ebf59ebfb1 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -395,7 +395,7 @@ void ManagerImpl::hangupCall(const std::string& callId) Call * call = SIPVoIPLink::instance()->getSipCall(callId); if (call) { history_.addCall(call, preferences.getHistoryLimit()); - SIPVoIPLink::instance()->hangup(callId); + SIPVoIPLink::instance()->hangup(callId, 0); saveHistory(); } } catch (const VoipLinkException &e) { @@ -407,7 +407,7 @@ void ManagerImpl::hangupCall(const std::string& callId) if (call) { history_.addCall(call, preferences.getHistoryLimit()); VoIPLink *link = getAccountLink(accountId); - link->hangup(callId); + link->hangup(callId, 0); removeCallAccount(callId); saveHistory(); } @@ -1588,7 +1588,7 @@ void ManagerImpl::peerHungupCall(const std::string& call_id) if (isIPToIP(call_id)) { Call * call = SIPVoIPLink::instance()->getSipCall(call_id); history_.addCall(call, preferences.getHistoryLimit()); - SIPVoIPLink::instance()->hangup(call_id); + SIPVoIPLink::instance()->hangup(call_id, 0); saveHistory(); } else { const std::string account_id(getAccountFromCall(call_id)); diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 3f37a8d1c5..6569ecf54e 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -941,7 +941,7 @@ void stopRtpIfCurrent(const std::string &id, SIPCall &call) } void -SIPVoIPLink::hangup(const std::string& id) +SIPVoIPLink::hangup(const std::string& id, int reason) { SIPCall* call = getSIPCall(id); @@ -969,13 +969,12 @@ SIPVoIPLink::hangup(const std::string& id) pjsip_tx_data *tdata = NULL; - const int status = + const int status = reason ? reason : inv->state <= PJSIP_INV_STATE_EARLY and inv->role != PJSIP_ROLE_UAC ? PJSIP_SC_CALL_TSX_DOES_NOT_EXIST : inv->state >= PJSIP_INV_STATE_DISCONNECTED ? PJSIP_SC_DECLINE : 0; - // User hangup current call. Notify peer if (pjsip_inv_end_session(inv, status, NULL, &tdata) != PJ_SUCCESS || !tdata) return; @@ -1671,9 +1670,13 @@ void sdp_media_update_cb(pjsip_inv_session *inv, pj_status_t status) } if (status != PJ_SUCCESS) { + const int reason = inv->state != PJSIP_INV_STATE_NULL and + inv->state != PJSIP_INV_STATE_CONFIRMED ? + PJSIP_SC_UNSUPPORTED_MEDIA_TYPE : 0; + WARN("Could not negotiate offer"); const std::string callID(call->getCallId()); - SIPVoIPLink::instance()->hangup(callID); + SIPVoIPLink::instance()->hangup(callID, reason); // call is now a dangling pointer after calling hangup call = 0; Manager::instance().callFailure(callID); diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index d525a1c04c..83107eaeac 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -153,7 +153,7 @@ class SIPVoIPLink : public VoIPLink { * Hang up the call * @param id The call identifier */ - virtual void hangup(const std::string& id); + virtual void hangup(const std::string& id, int reason); /** * Hang up the call diff --git a/daemon/src/voiplink.h b/daemon/src/voiplink.h index 841eb7679b..8f53edaec7 100644 --- a/daemon/src/voiplink.h +++ b/daemon/src/voiplink.h @@ -92,7 +92,7 @@ class VoIPLink { * Hang up a call * @param id The call identifier */ - virtual void hangup(const std::string &id) = 0; + virtual void hangup(const std::string &id, int reason) = 0; /** * Peer Hung up a call -- GitLab