Commit a8f5fbc4 authored by Tristan Matthews's avatar Tristan Matthews

* #19032: sip: don't decrement transport reference on error

This was causing PJSIP to abort since in the SIP thread, it will
automatically decrement the reference count in case of error.
parent 59ebd231
......@@ -214,7 +214,7 @@ void Account::setActiveAudioCodecs(const vector<string> &list)
string Account::mapStateNumberToString(RegistrationState state)
{
static const char * mapStateToChar[] = {
static const char * mapStateToChar[NUMBER_OF_STATES] = {
"UNREGISTERED",
"TRYING",
"REGISTERED",
......@@ -222,8 +222,9 @@ string Account::mapStateNumberToString(RegistrationState state)
"ERRORAUTH",
"ERRORNETWORK",
"ERRORHOST",
"ERRORSERVICEUNAVAILABLE",
"ERROREXISTSTUN",
"ERRORCONFSTUN"
"ERRORNOTACCEPTABLE",
};
if (state > NUMBER_OF_STATES)
......
......@@ -38,9 +38,10 @@ typedef enum {
TRYING,
REGISTERED,
ERROR_GENERIC,
ERROR_AUTH ,
ERROR_NETWORK ,
ERROR_AUTH,
ERROR_NETWORK,
ERROR_HOST,
ERROR_SERVICE_UNAVAILABLE,
ERROR_EXIST_STUN,
ERROR_NOT_ACCEPTABLE,
NUMBER_OF_STATES
......
......@@ -313,9 +313,10 @@ SipTransport::createTlsTransport(SIPAccount &account)
DEBUG("Get new tls transport from transport manager");
pjsip_transport *transport = NULL;
pjsip_endpt_acquire_transport(endpt_, PJSIP_TRANSPORT_TLS, &rem_addr,
pj_status_t status = pjsip_endpt_acquire_transport(endpt_, PJSIP_TRANSPORT_TLS, &rem_addr,
sizeof rem_addr, NULL, &transport);
RETURN_IF_FAIL(transport != NULL, NULL, "Could not create new TLS transport");
RETURN_IF_FAIL(transport != NULL and status == PJ_SUCCESS, NULL,
"Could not create new TLS transport");
return transport;
}
#endif
......@@ -506,14 +507,18 @@ pjsip_transport *SipTransport::createStunTransport(SIPAccount &account)
#undef RETURN_IF_STUN_FAIL
}
void SipTransport::shutdownSipTransport(SIPAccount &account)
void SipTransport::shutdownSTUNResolver(SIPAccount &account)
{
if (account.isStunEnabled()) {
pj_str_t stunServerName = account.getStunServerName();
std::string server(stunServerName.ptr, stunServerName.slen);
destroyStunResolver(server);
}
}
void SipTransport::shutdownSipTransport(SIPAccount &account)
{
shutdownSTUNResolver(account);
if (account.transport_) {
pjsip_transport_dec_ref(account.transport_);
account.transport_ = NULL;
......
......@@ -107,6 +107,11 @@ class SipTransport {
pjsip_tpselector *
createTransportSelector(pjsip_transport *transport, pj_pool_t *tp_pool) const;
/**
* This function unset the STUN resolver for a given account.
*/
void shutdownSTUNResolver(SIPAccount &account);
/**
* This function unset the transport for a given account.
*/
......
......@@ -1982,7 +1982,10 @@ void processRegistrationError(SIPAccount &account, RegistrationState state)
account.stopKeepAliveTimer();
account.setRegistrationState(state);
account.setRegister(false);
SIPVoIPLink::instance()->sipTransport.shutdownSipTransport(account);
SIPVoIPLink::instance()->sipTransport.shutdownSTUNResolver(account);
// DON'T decrement reference count since we're in an error state, PJSIP
// will destroy it automatically
account.transport_ = NULL;
}
void registration_cb(pjsip_regc_cbparam *param)
......@@ -2031,7 +2034,7 @@ void registration_cb(pjsip_regc_cbparam *param)
break;
case PJSIP_SC_SERVICE_UNAVAILABLE: // 503
FAILURE_MESSAGE();
processRegistrationError(*account, ERROR_HOST);
processRegistrationError(*account, ERROR_SERVICE_UNAVAILABLE);
break;
case PJSIP_SC_UNAUTHORIZED: // 401
// Automatically answered by PJSIP
......
......@@ -167,6 +167,8 @@ const gchar * account_state_name(account_state_t s)
return _("Network unreachable");
case ACCOUNT_STATE_ERROR_HOST:
return _("Host unreachable");
case ACCOUNT_STATE_ERROR_SERVICE_UNAVAILABLE:
return _("Service unavailable");
case ACCOUNT_STATE_ERROR_NOT_ACCEPTABLE:
return _("Not acceptable");
case ACCOUNT_STATE_ERROR_EXIST_STUN:
......
......@@ -55,6 +55,8 @@ typedef enum {
ACCOUNT_STATE_ERROR_NETWORK,
/** Host is unreachable. The account is not registered */
ACCOUNT_STATE_ERROR_HOST,
/** Host does not support requested service (e.g. TLS). The account is not registered */
ACCOUNT_STATE_ERROR_SERVICE_UNAVAILABLE,
/** Stun server is not existing. The account is not registered */
ACCOUNT_STATE_ERROR_EXIST_STUN,
/** Stun server configuration error. The account is not registered */
......
Markdown is supported
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