From 30a1b49d597988ed02158f315d1dfab0da64eccb Mon Sep 17 00:00:00 2001 From: Tristan Matthews <tristan.matthews@savoirfairelinux.com> Date: Tue, 24 Apr 2012 17:56:29 -0400 Subject: [PATCH] * #9910: SIP: use rport from VIA header if present This fixes the issue where we weren't receiving BYE requests from the ekiga.net callback account (520@ekiga.net). --- daemon/src/sip/sipaccount.cpp | 1 + daemon/src/sip/sipaccount.h | 16 +++++++++++++++- daemon/src/sip/sipvoiplink.cpp | 7 +++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/daemon/src/sip/sipaccount.cpp b/daemon/src/sip/sipaccount.cpp index 031bda7cbf..fd5b198a41 100644 --- a/daemon/src/sip/sipaccount.cpp +++ b/daemon/src/sip/sipaccount.cpp @@ -99,6 +99,7 @@ SIPAccount::SIPAccount(const std::string& accountID) , keepAliveTimer_() , link_(SIPVoIPLink::instance()) , receivedParameter_() + , rPort_(-1) {} void SIPAccount::serialize(Conf::YamlEmitter &emitter) diff --git a/daemon/src/sip/sipaccount.h b/daemon/src/sip/sipaccount.h index 007c4cab15..6b97d5b1cc 100644 --- a/daemon/src/sip/sipaccount.h +++ b/daemon/src/sip/sipaccount.h @@ -505,6 +505,15 @@ class SIPAccount : public Account { return receivedParameter_; } + int getRPort() const { + if (rPort_ == -1) + return localPort_; + else + return rPort_; + } + + void setRPort(int rPort) { rPort_ = rPort; } + /** * Timer used to periodically send re-register request based * on the "Expire" sip header (or the "expire" Contact parameter) @@ -734,9 +743,14 @@ class SIPAccount : public Account { SIPVoIPLink* link_; /** - * Received via parameters + * Optional: "received" parameter from VIA header */ std::string receivedParameter_; + + /** + * Optional: "rport" parameter from VIA header + */ + int rPort_; }; #endif diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index c8773ca594..a1a0c0469c 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -519,11 +519,12 @@ void SIPVoIPLink::sendRegister(Account *a) std::string contact = account->getContactHeader(); pj_str_t pjContact = pj_str((char*) contact.c_str()); - if(!received.empty()) { + if (!received.empty()) { // Set received parameter string to empty in order to avoid creating new transport for each register account->setReceivedParameter(""); // Explicitely set the bound address port to 0 so that pjsip determine a random port by itself - account->transport_= sipTransport.createUdpTransport(account->getLocalInterface(), 0, received, account->getLocalPort()); + account->transport_= sipTransport.createUdpTransport(account->getLocalInterface(), 0, received, account->getRPort()); + account->setRPort(-1); if(account->transport_ == NULL) { ERROR("UserAgent: Could not create new udp transport with public address: %s:%d", received.c_str(), account->getLocalPort()); } @@ -1582,6 +1583,8 @@ void lookForReceivedParameter(pjsip_regc_cbparam *param, SIPAccount *account) DEBUG("Cool received received parameter... uhhh?, the value is %s", publicIpFromReceived.c_str()); account->setReceivedParameter(publicIpFromReceived); } + + account->setRPort(param->rdata->msg_info.via->rport_param); } void registration_cb(pjsip_regc_cbparam *param) -- GitLab