From dd05d0354aa1f254e7d16a86380264d4bcebe635 Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.com> Date: Mon, 23 Apr 2012 14:17:04 -0400 Subject: [PATCH] #9910: Update parse received parameter on 606 registration error --- daemon/src/managerimpl.cpp | 1 - daemon/src/sip/sipaccount.cpp | 1 + daemon/src/sip/sipaccount.h | 13 +++++++++++++ daemon/src/sip/sipvoiplink.cpp | 16 ++++++++++++++++ gnome/src/actions.c | 25 ++++++++++++++----------- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 4c3a128d93..8213c022f6 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -226,7 +226,6 @@ bool ManagerImpl::outgoingCall(const std::string& account_id, try { Call *call = getAccountLink(account_id)->newOutgoingCall(call_id, to_cleaned); - switchCall(call_id); call->setConfId(conf_id); } catch (const VoipLinkException &e) { diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 33a6a6301b..f89caf97e4 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -99,6 +99,7 @@ SIPAccount::SIPAccount(const std::string& accountID) , registrationStateDetailed_() , keepAliveTimer_() , link_(SIPVoIPLink::instance()) + , receivedParameter_() {} void SIPAccount::serialize(Conf::YamlEmitter &emitter) diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 2e406363ae..7014967084 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -495,6 +495,14 @@ class SIPAccount : public Account { return zrtpHelloHash_; } + void setReceivedParameter(std::string received) { + receivedParameter_ = received; + } + + std::string getReceivedParameter() { + return receivedParameter_; + } + /** * Timer used to periodically send re-register request based * on the "Expire" sip header (or the "expire" Contact parameter) @@ -718,6 +726,11 @@ class SIPAccount : public Account { * Voice over IP Link contains a listener thread and calls */ SIPVoIPLink* link_; + + /** + * Received via parameters + */ + std::string receivedParameter_; }; #endif diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 1638532c7a..b1ebcc9153 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -515,6 +515,9 @@ void SIPVoIPLink::sendRegister(Account *a) std::string contact(account->getContactHeader()); pj_str_t pjContact = pj_str((char*) contact.c_str()); + std::string received(account->getReceivedParameter()); + pj_str_t pjReceived = pj_str((char *) received.c_str()); + if (pjsip_regc_init(regc, &pjSrv, &pjFrom, &pjFrom, 1, &pjContact, account->getRegistrationExpire()) != PJ_SUCCESS) throw VoipLinkException("Unable to initialize account registration structure"); @@ -1560,6 +1563,18 @@ void update_contact_header(pjsip_regc_cbparam *param, SIPAccount *account) pj_pool_release(pool); } +static void looksForReceivedParameter(pjsip_regc_cbparam *param, SIPAccount *account) { + pj_str_t receivedValue = param->rdata->msg_info.via->recvd_param; + std::string publicIpFromReceived = ""; + + ERROR("looksForReceivedParameter"); + if(receivedValue.slen) { + publicIpFromReceived = std::string(receivedValue.ptr, receivedValue.slen); + DEBUG("Cool received received parameter... uhhh?, the value is %s", publicIpFromReceived.c_str()); + account->setReceivedParameter(publicIpFromReceived); + } +} + void registration_cb(pjsip_regc_cbparam *param) { if (param == NULL) { @@ -1599,6 +1614,7 @@ void registration_cb(pjsip_regc_cbparam *param) if (param->code < 0 || param->code >= 300) { switch (param->code) { case 606: + looksForReceivedParameter(param, account); account->setRegistrationState(ErrorNotAcceptable); break; diff --git a/gnome/src/actions.c b/gnome/src/actions.c index 936440d70c..78f96a4f9b 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -752,7 +752,7 @@ static void place_direct_call(const callable_obj_t * c) static int place_registered_call(callable_obj_t * c) { - account_t * current = NULL; + account_t * account = NULL; if (c->_state != CALL_STATE_DIALING) return -1; @@ -760,51 +760,54 @@ static int place_registered_call(callable_obj_t * c) if (!*c->_peer_number) return -1; +// No longer usefull +/* if (account_list_get_size() == 0) { notify_no_accounts(); sflphone_fail(c); return -1; } - +*/ +/* if (account_list_get_by_state(ACCOUNT_STATE_REGISTERED) == NULL) { DEBUG("Actions: No registered account, cannot make a call"); notify_no_registered_accounts(); sflphone_fail(c); return -1; } - +*/ DEBUG("Actions: Get account for this call"); if (strlen(c->_accountID) != 0) { DEBUG("Actions: Account %s already set for this call", c->_accountID); - current = account_list_get_by_id(c->_accountID); + account = account_list_get_by_id(c->_accountID); } else { DEBUG("Actions: No account set for this call, use first of the list"); - current = account_list_get_current(); + account = account_list_get_current(); } - if (current == NULL) { + if (account == NULL) { DEBUG("Actions: Unexpected condition: account_t is NULL in %s at %d for accountID %s", __FILE__, __LINE__, c->_accountID); return -1; } - gpointer status = g_hash_table_lookup(current->properties, "Status"); + gpointer status = g_hash_table_lookup(account->properties, "Status"); if (utf8_case_equal(status, "REGISTERED")) { /* The call is made with the current account */ // free memory for previous account id and get a new one g_free(c->_accountID); - c->_accountID = g_strdup(current->accountID); + c->_accountID = g_strdup(account->accountID); dbus_place_call(c); } else { /* Place the call with the first registered account * and switch the current account. * If we are here, we can be sure that there is at least one. */ - current = account_list_get_by_state(ACCOUNT_STATE_REGISTERED); + account = account_list_get_by_state(ACCOUNT_STATE_REGISTERED); g_free(c->_accountID); - c->_accountID = g_strdup(current->accountID); + c->_accountID = g_strdup(account->accountID); dbus_place_call(c); - notify_current_account(current); + notify_current_account(account); } c->_history_state = g_strdup(OUTGOING_STRING); -- GitLab