Commit 135f50c5 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6841: fix some error handling

parent 99633f98
......@@ -402,7 +402,7 @@ IAXVoIPLink::peerHungup (const std::string& id)
bool
void
IAXVoIPLink::onhold (const std::string& id)
{
IAXCall* call = getIAXCall (id);
......@@ -411,21 +411,19 @@ IAXVoIPLink::onhold (const std::string& id)
Manager::instance().getMainBuffer()->unBindAll (call->getCallId());
//if (call->getState() == Call::Hold) { _debug("Call is already on hold"); return false; }
mutexIAX_.enterMutex();
iax_quelch_moh (call->getSession() , MUSIC_ONHOLD);
iax_quelch_moh (call->getSession(), MUSIC_ONHOLD);
mutexIAX_.leaveMutex();
call->setState (Call::Hold);
return true;
}
bool
void
IAXVoIPLink::offhold (const std::string& id)
{
IAXCall* call = getIAXCall (id);
CHK_VALID_CALL;
if (call == NULL)
throw VoipLinkException("Call does not exist");
Manager::instance().addStream (call->getCallId());
......@@ -434,7 +432,6 @@ IAXVoIPLink::offhold (const std::string& id)
mutexIAX_.leaveMutex();
audiolayer_->startStream();
call->setState (Call::Active);
return true;
}
bool
......
......@@ -136,7 +136,7 @@ class IAXVoIPLink : public VoIPLink
* @return bool true on success
* false otherwise
*/
virtual bool onhold (const std::string& id);
virtual void onhold (const std::string& id);
/**
* Put a call off hold
......@@ -144,7 +144,7 @@ class IAXVoIPLink : public VoIPLink
* @return bool true on success
* false otherwise
*/
virtual bool offhold (const std::string& id);
virtual void offhold (const std::string& id);
/**
* Transfer a call
......
......@@ -431,34 +431,31 @@ bool ManagerImpl::hangupConference (const std::string& id)
//THREAD=Main
bool ManagerImpl::onHoldCall (const std::string& callId)
void ManagerImpl::onHoldCall (const std::string& callId)
{
bool returnValue = false;
_debug ("Manager: Put call %s on hold", callId.c_str());
stopTone();
std::string current_call_id = getCurrentCallId();
std::string current_call_id(getCurrentCallId());
try {
if (getConfigFromCall (callId) == Call::IPtoIP) {
/* Direct IP to IP call */
returnValue = SIPVoIPLink::instance ()-> onhold (callId);
SIPVoIPLink::instance ()-> onhold (callId);
}
else {
/* Classic call, attached to an account */
std::string account_id(getAccountFromCall (callId));
if (account_id == "") {
_debug ("Manager: Account ID %s or callid %s doesn't exists in call onHold", account_id.c_str(), callId.c_str());
return false;
}
returnValue = getAccountLink (account_id)->onhold (callId);
if (account_id.empty()) {
_debug ("Manager: Account ID %s or callid %s doesn't exists in call onHold", account_id.c_str(), callId.c_str());
return;
}
getAccountLink(account_id)->onhold(callId);
}
}
catch (const VoipLinkException &e){
catch (const VoipLinkException &e) {
_error("Manager: Error: %s", e.what());
}
......@@ -476,22 +473,19 @@ bool ManagerImpl::onHoldCall (const std::string& callId)
_dbus.getCallManager()->callStateChanged (callId, "HOLD");
getMainBuffer()->stateInfo();
return returnValue;
}
//THREAD=Main
bool ManagerImpl::offHoldCall (const std::string& callId)
void ManagerImpl::offHoldCall (const std::string& callId)
{
std::string accountId;
bool returnValue = true;
std::string codecName;
_debug ("Manager: Put call %s off hold", callId.c_str());
stopTone();
std::string currentCallId = getCurrentCallId();
std::string currentCallId(getCurrentCallId());
//Place current call on hold if it isn't
......@@ -509,7 +503,7 @@ bool ManagerImpl::offHoldCall (const std::string& callId)
/* Direct IP to IP call */
if (getConfigFromCall (callId) == Call::IPtoIP)
returnValue = SIPVoIPLink::instance ()-> offhold (callId);
SIPVoIPLink::instance ()-> offhold (callId);
else {
/* Classic call, attached to an account */
accountId = getAccountFromCall (callId);
......@@ -520,16 +514,14 @@ bool ManagerImpl::offHoldCall (const std::string& callId)
if (call)
{
isRec = call->isRecording();
returnValue = getAccountLink (accountId)->offhold (callId);
getAccountLink(accountId)->offhold(callId);
}
}
_dbus.getCallManager()->callStateChanged (callId, isRec ? "UNHOLD_RECORD" : "UNHOLD_CURRENT");
if (participToConference (callId)) {
std::string currentAccountId;
currentAccountId = getAccountFromCall (callId);
std::string currentAccountId(getAccountFromCall(callId));
Call *call = getAccountLink (currentAccountId)->getCall (callId);
if (call)
......@@ -541,8 +533,6 @@ bool ManagerImpl::offHoldCall (const std::string& callId)
addStream(callId);
getMainBuffer()->stateInfo();
return returnValue;
}
//THREAD=Main
......
......@@ -200,14 +200,14 @@ class ManagerImpl
* Put the call on hold
* @param id The call identifier
*/
bool onHoldCall (const std::string& id);
void onHoldCall (const std::string& id);
/**
* Functions which occur with a user's action
* Put the call off hold
* @param id The call identifier
*/
bool offHoldCall (const std::string& id);
void offHoldCall (const std::string& id);
/**
* Functions which occur with a user's action
......
......@@ -515,14 +515,14 @@ void SIPVoIPLink::sendUnregister (Account *a)
pjsip_regc *regc = account->getRegistrationInfo();
if (!regc)
throw VoipLinkException("Registration structure is NULL");
throw VoipLinkException("Registration structure is NULL");
pjsip_tx_data *tdata = NULL;
if (pjsip_regc_unregister (regc, &tdata) != PJ_SUCCESS)
throw VoipLinkException("Unable to unregister sip account");
throw VoipLinkException("Unable to unregister sip account");
if (pjsip_regc_send (regc, tdata) != PJ_SUCCESS)
throw VoipLinkException("Unable to send request to unregister sip account");
throw VoipLinkException("Unable to send request to unregister sip account");
account->setRegister (false);
}
......@@ -546,9 +546,8 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to
// If toUri is not a well formated sip URI, use account information to process it
std::string toUri;
if((toUrl.find("sip:") != std::string::npos) or
toUrl.find("sips:") != std::string::npos) {
toUrl.find("sips:") != std::string::npos)
toUri = toUrl;
}
else
toUri = account->getToUri (toUrl);
......@@ -590,7 +589,7 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to
call->getAudioRtp()->start (static_cast<sfl::AudioCodec *>(audiocodec));
} catch (...) {
delete call;
throw VoipLinkException ("Could not start rtp session for early media");
throw VoipLinkException ("Could not start rtp session for early media");
}
// init file name according to peer phone number
......@@ -600,7 +599,7 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to
call->getLocalSDP()->setLocalIP (addrSdp);
if (call->getLocalSDP()->createOffer(account->getActiveCodecs()) != PJ_SUCCESS) {
delete call;
throw VoipLinkException ("Could not create local sdp offer for new call");
throw VoipLinkException ("Could not create local sdp offer for new call");
}
if (SIPStartCall(call)) {
......@@ -629,10 +628,10 @@ SIPVoIPLink::answer (Call *c)
_debug ("UserAgent: SDP negotiation success! : call %s ", call->getCallId().c_str());
// Create and send a 200(OK) response
if (pjsip_inv_answer (inv_session, PJSIP_SC_OK, NULL, NULL, &tdata) != PJ_SUCCESS)
throw VoipLinkException("Could not init invite request answer (200 OK)");
throw VoipLinkException("Could not init invite request answer (200 OK)");
if (pjsip_inv_send_msg (inv_session, tdata) != PJ_SUCCESS)
throw VoipLinkException("Could not send invite request answer (200 OK)");
throw VoipLinkException("Could not send invite request answer (200 OK)");
call->setConnectionState (Call::Connected);
call->setState (Call::Active);
......@@ -650,7 +649,7 @@ SIPVoIPLink::hangup (const std::string& id)
pjsip_inv_session *inv = call->inv;
if (inv == NULL)
throw VoipLinkException("No invite session for this call");
throw VoipLinkException("No invite session for this call");
// Looks for sip routes
if (not (account->getServiceRoute().empty())) {
......@@ -675,7 +674,7 @@ SIPVoIPLink::hangup (const std::string& id)
call->getAudioRtp()->stop();
}
catch (...) {
throw VoipLinkException("Could not stop audio rtp session");
throw VoipLinkException("Could not stop audio rtp session");
}
removeCall (id);
......@@ -707,7 +706,7 @@ SIPVoIPLink::peerHungup (const std::string& id)
}
}
catch (...) {
throw VoipLinkException("Could not stop audio rtp session");
throw VoipLinkException("Could not stop audio rtp session");
}
removeCall (id);
......@@ -717,12 +716,11 @@ void
SIPVoIPLink::cancel (const std::string& id)
{
_info ("UserAgent: Cancel call %s", id.c_str());
removeCall (id);
}
bool
void
SIPVoIPLink::onhold (const std::string& id)
{
SIPCall *call = getSIPCall(id);
......@@ -749,10 +747,10 @@ SIPVoIPLink::onhold (const std::string& id)
sdpSession->addAttributeToLocalAudioMedia("sendonly");
// Create re-INVITE with new offer
return SIPSessionReinvite (call) == PJ_SUCCESS;
SIPSessionReinvite (call);
}
bool
void
SIPVoIPLink::offhold (const std::string& id)
{
_debug ("UserAgent: retrive call from hold status");
......@@ -801,10 +799,9 @@ SIPVoIPLink::offhold (const std::string& id)
/* Create re-INVITE with new offer */
if (SIPSessionReinvite (call) != PJ_SUCCESS)
return false;
return;
call->setState (Call::Active);
return true;
}
bool
......@@ -1060,10 +1057,8 @@ SIPVoIPLink::dtmfSipInfo (SIPCall *call, char code)
// Create a temporary memory pool
pj_pool_t *tmp_pool = pj_pool_create (&_cp->factory, "tmpdtmf10", 1000, 1000, NULL);
if (tmp_pool == NULL) {
_debug ("UserAgent: Could not initialize memory pool while sending DTMF");
return;
}
if (tmp_pool == NULL)
throw VoipLinkException("UserAgent: Could not initialize memory pool while sending DTMF");
pj_str_t methodName;
pj_strdup2 (tmp_pool, &methodName, "INFO");
......@@ -1439,23 +1434,22 @@ bool SIPVoIPLink::SIPNewIpToIpCall (const std::string& id, const std::string& to
// Private functions
///////////////////////////////////////////////////////////////////////////////
bool SIPVoIPLink::pjsipInit()
void SIPVoIPLink::pjsipInit()
{
// Init PJLIB: must be called before any call to the pjsip library
pj_status_t status = pj_init();
// Use pjsip macros for sanity check
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pj_init() != PJ_SUCCESS)
return;
// Init PJLIB-UTIL library
status = pjlib_util_init();
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjlib_util_init() != PJ_SUCCESS)
return;
// Set the pjsip log level
pj_log_set_level (PJ_LOG_LEVEL);
// Init PJNATH
status = pjnath_init();
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjnath_init() != PJ_SUCCESS)
return;
// Create a pool factory to allocate memory
pj_caching_pool_init (_cp, &pj_pool_factory_default_policy, 0);
......@@ -1463,36 +1457,32 @@ bool SIPVoIPLink::pjsipInit()
// Create memory pool for application.
_pool = pj_pool_create (&_cp->factory, "sflphone", 4000, 4000, NULL);
if (!_pool) {
_debug ("UserAgent: Could not initialize memory pool");
return PJ_ENOMEM;
}
if (!_pool)
throw VoipLinkException("UserAgent: Could not initialize memory pool");
// Create the SIP endpoint
status = pjsip_endpt_create (&_cp->factory, pj_gethostname()->ptr, &_endpt);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_endpt_create (&_cp->factory, pj_gethostname()->ptr, &_endpt) !=
PJ_SUCCESS)
return;
if (loadSIPLocalIP().empty()) {
_debug ("UserAgent: Unable to determine network capabilities");
return false;
}
if (loadSIPLocalIP().empty())
throw VoipLinkException("UserAgent: Unable to determine network capabilities");
// Initialize transaction layer
status = pjsip_tsx_layer_init_module (_endpt);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_tsx_layer_init_module (_endpt) != PJ_SUCCESS)
return;
// Initialize UA layer module
status = pjsip_ua_init_module (_endpt, NULL);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_ua_init_module (_endpt, NULL) != PJ_SUCCESS)
return;
// Initialize Replaces support. See the Replaces specification in RFC 3891
status = pjsip_replaces_init_module (_endpt);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_replaces_init_module (_endpt) != PJ_SUCCESS)
return;
// Initialize 100rel support
status = pjsip_100rel_init_module (_endpt);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_100rel_init_module (_endpt) != PJ_SUCCESS)
return;
// Initialize and register sflphone module
std::string name_mod(PACKAGE);
......@@ -1501,18 +1491,17 @@ bool SIPVoIPLink::pjsipInit()
_mod_ua.priority = PJSIP_MOD_PRIORITY_APPLICATION;
_mod_ua.on_rx_request = &transaction_request_cb;
_mod_ua.on_rx_response = &transaction_response_cb;
status = pjsip_endpt_register_module (_endpt, &_mod_ua);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_endpt_register_module (_endpt, &_mod_ua) != PJ_SUCCESS)
return;
// Init the event subscription module.
// It extends PJSIP by supporting SUBSCRIBE and NOTIFY methods
status = pjsip_evsub_init_module (_endpt);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_evsub_init_module (_endpt) != PJ_SUCCESS)
return;
// Init xfer/REFER module
status = pjsip_xfer_init_module (_endpt);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_xfer_init_module (_endpt) != PJ_SUCCESS)
return;
// Init the callback for INVITE session:
pjsip_inv_callback inv_cb;
......@@ -1525,8 +1514,8 @@ bool SIPVoIPLink::pjsipInit()
inv_cb.on_create_offer = &sdp_create_offer_cb;
// Initialize session invite module
status = pjsip_inv_usage_init (_endpt, &inv_cb);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_inv_usage_init (_endpt, &inv_cb) != PJ_SUCCESS)
return;
_debug ("UserAgent: VOIP callbacks initialized");
......@@ -1545,14 +1534,11 @@ bool SIPVoIPLink::pjsipInit()
_debug ("UserAgent: pjsip version %s for %s initialized", pj_get_version(), PJ_OS_NAME);
status = pjsip_replaces_init_module (_endpt);
PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1);
if (pjsip_replaces_init_module(_endpt) != PJ_SUCCESS)
return;
// Create the secondary thread to poll sip events
evThread_->start();
/* Done! */
return PJ_SUCCESS;
}
......@@ -1602,13 +1588,12 @@ pj_status_t SIPVoIPLink::stunServerResolve (SIPAccount *account)
return status;
}
bool SIPVoIPLink::acquireTransport (SIPAccount *account)
void SIPVoIPLink::acquireTransport (SIPAccount *account)
{
// If an account is already bound to this account, decrease its reference
// as it is going to change. If the same transport is selected, reference
// counter will be increased
if (account->getAccountTransport()) {
_debug ("pjsip_transport_dec_ref in acquireTransport");
pjsip_transport_dec_ref (account->getAccountTransport());
}
......@@ -1617,39 +1602,34 @@ bool SIPVoIPLink::acquireTransport (SIPAccount *account)
// are different than one defined for already created ones
// If TLS is enabled, TLS connection is automatically handled when sending account registration
// However, for any other sip transaction, we must create TLS connection
if (createSipTransport (account))
return true;
// A transport is already created on this port, use it
_debug ("Could not create a new transport (%d)", account->getLocalPort());
// Could not create new transport, this transport may already exists
pjsip_transport* tr = transportMap_[account->getLocalPort()];
if (tr) {
account->setAccountTransport (tr);
// Increment newly associated transport reference counter
// If the account is shutdowning, time is automatically canceled
pjsip_transport_add_ref (tr);
return true;
}
// Transport could not either be created, socket not available
_debug ("Did not find transport (%d) in transport map", account->getLocalPort());
account->setAccountTransport(_localUDPTransport);
std::string localHostName(_localUDPTransport->local_name.host.ptr,
_localUDPTransport->local_name.host.slen);
if (not createSipTransport(account)) {
// A transport is already created on this port, use it
_debug ("Could not create a new transport (%d)", account->getLocalPort());
// Could not create new transport, this transport may already exists
pjsip_transport* tr = transportMap_[account->getLocalPort()];
if (tr) {
account->setAccountTransport (tr);
// Increment newly associated transport reference counter
// If the account is shutdowning, time is automatically canceled
pjsip_transport_add_ref (tr);
}
else {
// Transport could not either be created, socket not available
_debug ("Did not find transport (%d) in transport map", account->getLocalPort());
_debug ("Use default one instead (%s:%i)", localHostName.c_str(),
_localUDPTransport->local_name.port);
account->setAccountTransport(_localUDPTransport);
std::string localHostName(_localUDPTransport->local_name.host.ptr,
_localUDPTransport->local_name.host.slen);
// account->setLocalAddress(localHostName);
account->setLocalPort(_localUDPTransport->local_name.port);
_debug ("Use default one instead (%s:%i)", localHostName.c_str(),
_localUDPTransport->local_name.port);
// Transport could not either be created or found in the map, socket not available
return false;
// account->setLocalAddress(localHostName);
account->setLocalPort(_localUDPTransport->local_name.port);
_error("Transport could not either be created or found in the map, socket not available");
}
}
}
......@@ -1831,7 +1811,7 @@ std::string SIPVoIPLink::findLocalAddressFromUri (const std::string& uri, pjsip_
// Create a temporary memory pool
pj_pool_t *tmp_pool = pj_pool_create (&_cp->factory, "tmpdtmf10", 1000, 1000, NULL);
if (tmp_pool == NULL)
_error ("UserAgent: Could not initialize memory pool");
throw VoipLinkException("UserAgent: Could not initialize memory pool");
// Find the transport that must be used with the given uri
pj_str_t tmp;
......@@ -1931,10 +1911,8 @@ int SIPVoIPLink::findLocalPortFromUri (const std::string& uri, pjsip_transport *
{
// Create a temporary memory pool
pj_pool_t *tmp_pool = pj_pool_create (&_cp->factory, "tmpdtmf10", 1000, 1000, NULL);
if (tmp_pool == NULL) {
_debug ("UserAgent: Could not initialize memory pool");
return false;
}
if (tmp_pool == NULL)
throw VoipLinkException("UserAgent: Could not initialize memory pool");
// Find the transport that must be used with the given uri
pj_str_t tmp;
......
......@@ -143,14 +143,14 @@ class SIPVoIPLink : public VoIPLink
* @param id The call identifier
* @return bool True on success
*/
virtual bool onhold (const std::string& id);
virtual void onhold (const std::string& id);
/**
* Put the call off hold
* @param id The call identifier
* @return bool True on success
*/
virtual bool offhold (const std::string& id);
virtual void offhold (const std::string& id);
/**
* Transfer the call
......@@ -332,7 +332,7 @@ class SIPVoIPLink : public VoIPLink
*
* @return bool True on success
*/
bool pjsipInit();
void pjsipInit();
/**
* Delete link-related stuff like calls
......@@ -351,10 +351,8 @@ class SIPVoIPLink : public VoIPLink
* This function should be called before registering an account
* @param account An account for which transport is to be set
*
* @return bool True if the account is successfully created or successfully obtained
* from the transport map
*/
bool acquireTransport (SIPAccount *account);
void acquireTransport (SIPAccount *account);
/**
* Create the default TLS litener according to account settings.
......
......@@ -127,14 +127,14 @@ class VoIPLink
* @param id The call identifier
* @return bool True on success
*/
virtual bool onhold (const std::string& id) = 0;
virtual void onhold (const std::string& id) = 0;
/**
* Resume a call from hold state
* @param id The call identifier
* @return bool True on success
*/
virtual bool offhold (const std::string& id) = 0;
virtual void offhold (const std::string& id) = 0;
/**
* Transfer a call to specified URI
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment