Skip to content
Snippets Groups Projects
Commit 1a9f1a30 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #10039: sipvoiplink: use references to avoid unnecessary parameter validation

We should only have to test a pointer once to see if it's NULL, after that
it can be safely derefrenced and its pointed-to value can be passed around by
reference.
parent 8289eaa2
No related branches found
No related tags found
No related merge requests found
...@@ -1592,34 +1592,25 @@ void update_contact_header(pjsip_regc_cbparam *param, SIPAccount *account) ...@@ -1592,34 +1592,25 @@ void update_contact_header(pjsip_regc_cbparam *param, SIPAccount *account)
pj_pool_release(pool); pj_pool_release(pool);
} }
static void lookForReceivedParameter(pjsip_regc_cbparam *param, SIPAccount *account) void lookForReceivedParameter(pjsip_regc_cbparam &param, SIPAccount &account)
{ {
pj_str_t receivedValue = param->rdata->msg_info.via->recvd_param; pj_str_t receivedValue = param.rdata->msg_info.via->recvd_param;
if (receivedValue.slen) { if (receivedValue.slen) {
std::string publicIpFromReceived(receivedValue.ptr, receivedValue.slen); std::string publicIpFromReceived(receivedValue.ptr, receivedValue.slen);
account->setReceivedParameter(publicIpFromReceived); account.setReceivedParameter(publicIpFromReceived);
} }
account->setRPort(param->rdata->msg_info.via->rport_param); account.setRPort(param.rdata->msg_info.via->rport_param);
} }
static void processRegistrationError(pjsip_regc_cbparam *param, SIPAccount *account, const RegistrationState &state) void processRegistrationError(SIPAccount &account, RegistrationState /*state*/)
{ {
if(param == NULL) { account.stopKeepAliveTimer();
ERROR("UserAgent: param is NULL while processing registration error"); #warning FIXME: We should be using the state parameter here
return; account.setRegistrationState(ErrorAuth);
} account.setRegister(false);
SIPVoIPLink::instance()->sipTransport.shutdownSipTransport(account);
if(account == NULL) {
ERROR("UserAgent: Account is NULL while processing registration error");
return;
}
account->stopKeepAliveTimer();
account->setRegistrationState(ErrorAuth);
account->setRegister(false);
SIPVoIPLink::instance()->sipTransport.shutdownSipTransport(*account);
} }
void registration_cb(pjsip_regc_cbparam *param) void registration_cb(pjsip_regc_cbparam *param)
...@@ -1655,7 +1646,7 @@ void registration_cb(pjsip_regc_cbparam *param) ...@@ -1655,7 +1646,7 @@ void registration_cb(pjsip_regc_cbparam *param)
if (param->status != PJ_SUCCESS) { if (param->status != PJ_SUCCESS) {
FAILURE_MESSAGE(); FAILURE_MESSAGE();
processRegistrationError(param, account, ErrorAuth); processRegistrationError(*account, ErrorAuth);
return; return;
} }
...@@ -1667,11 +1658,11 @@ void registration_cb(pjsip_regc_cbparam *param) ...@@ -1667,11 +1658,11 @@ void registration_cb(pjsip_regc_cbparam *param)
case PJSIP_SC_USE_PROXY: // 305 case PJSIP_SC_USE_PROXY: // 305
case PJSIP_SC_ALTERNATIVE_SERVICE: // 380 case PJSIP_SC_ALTERNATIVE_SERVICE: // 380
FAILURE_MESSAGE(); FAILURE_MESSAGE();
processRegistrationError(param, account, Error); processRegistrationError(*account, Error);
break; break;
case PJSIP_SC_SERVICE_UNAVAILABLE: // 503 case PJSIP_SC_SERVICE_UNAVAILABLE: // 503
FAILURE_MESSAGE(); FAILURE_MESSAGE();
processRegistrationError(param, account, ErrorHost); processRegistrationError(*account, ErrorHost);
break; break;
case PJSIP_SC_UNAUTHORIZED: // 401 case PJSIP_SC_UNAUTHORIZED: // 401
// Automatically answered by PJSIP // Automatically answered by PJSIP
...@@ -1680,11 +1671,11 @@ void registration_cb(pjsip_regc_cbparam *param) ...@@ -1680,11 +1671,11 @@ void registration_cb(pjsip_regc_cbparam *param)
case PJSIP_SC_FORBIDDEN: // 403 case PJSIP_SC_FORBIDDEN: // 403
case PJSIP_SC_NOT_FOUND: // 404 case PJSIP_SC_NOT_FOUND: // 404
FAILURE_MESSAGE(); FAILURE_MESSAGE();
processRegistrationError(param, account, ErrorAuth); processRegistrationError(*account, ErrorAuth);
break; break;
case PJSIP_SC_REQUEST_TIMEOUT: // 408 case PJSIP_SC_REQUEST_TIMEOUT: // 408
FAILURE_MESSAGE(); FAILURE_MESSAGE();
processRegistrationError(param, account, ErrorHost); processRegistrationError(*account, ErrorHost);
break; break;
case PJSIP_SC_INTERVAL_TOO_BRIEF: // 423 case PJSIP_SC_INTERVAL_TOO_BRIEF: // 423
// Expiration Interval Too Brief // Expiration Interval Too Brief
...@@ -1693,18 +1684,18 @@ void registration_cb(pjsip_regc_cbparam *param) ...@@ -1693,18 +1684,18 @@ void registration_cb(pjsip_regc_cbparam *param)
account->setRegister(false); account->setRegister(false);
break; break;
case PJSIP_SC_NOT_ACCEPTABLE_ANYWHERE: // 606 case PJSIP_SC_NOT_ACCEPTABLE_ANYWHERE: // 606
lookForReceivedParameter(param, account); lookForReceivedParameter(*param, *account);
account->setRegistrationState(ErrorNotAcceptable); account->setRegistrationState(ErrorNotAcceptable);
account->registerVoIPLink(); account->registerVoIPLink();
break; break;
default: default:
FAILURE_MESSAGE(); FAILURE_MESSAGE();
processRegistrationError(param, account, Error); processRegistrationError(*account, Error);
break; break;
} }
} else { } else {
lookForReceivedParameter(param, account); lookForReceivedParameter(*param, *account);
if (account->isRegistered()) if (account->isRegistered())
account->setRegistrationState(Registered); account->setRegistrationState(Registered);
else { else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment