diff --git a/sflphone-common/src/sip/sipaccount.cpp b/sflphone-common/src/sip/sipaccount.cpp index 3d62708a7c2d323f4a40d28a85bd923b09bf4d38..d557c05a6fc79056f138601195dc7306a101c1f8 100644 --- a/sflphone-common/src/sip/sipaccount.cpp +++ b/sflphone-common/src/sip/sipaccount.cpp @@ -93,6 +93,7 @@ SIPAccount::SIPAccount (const AccountID& accountID) : Account (accountID, "SIP") , _routeSet ("") , _pool (NULL) + , _regc (NULL) , _bRegister (false) , _registrationExpire ("") , _interface ("default") @@ -146,6 +147,7 @@ SIPAccount::~SIPAccount() dynamic_cast<SIPVoIPLink*> (_link)->decrementClients(); /* Delete accounts-related information */ + _regc = NULL; free_cred(_cred); delete _tlsSetting; } @@ -659,6 +661,7 @@ int SIPAccount::unregisterVoIPLink() try { _link->sendUnregister (_accountID); + setRegistrationInfo (NULL); } catch(VoipLinkException &e) { _error("SIPAccount: %s", e.what()); diff --git a/sflphone-common/src/sip/sipaccount.h b/sflphone-common/src/sip/sipaccount.h index de1ddfb4afadc2c1e465fb35c0524d1e1afe7c5d..66db10dac9c25a88e7b3e64a52f3e09ad586c38c 100644 --- a/sflphone-common/src/sip/sipaccount.h +++ b/sflphone-common/src/sip/sipaccount.h @@ -258,6 +258,27 @@ class SIPAccount : public Account _bRegister = result; } + /** + * Get the registration stucture that is used + * for PJSIP in the registration process. + * Settings are loaded from configuration file. + * @param void + * @return pjsip_regc* A pointer to the registration structure + */ + pjsip_regc* getRegistrationInfo (void) const { + return _regc; + } + + /** + * Set the registration structure that is used + * for PJSIP in the registration process; + * @pram A pointer to the new registration structure + * @return void + */ + void setRegistrationInfo (pjsip_regc *regc) { + _regc = regc; + } + /** * Get the number of credentials defined for * this account. @@ -716,6 +737,8 @@ class SIPAccount : public Account pj_pool_t *_pool; + // The pjsip client registration information + pjsip_regc *_regc; // To check if the account is registered bool _bRegister; diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 9e036cd9c639b967b9de6429ac4dab9336f9a4a3..38c3b9dc053b514b9d8f43db7eda22213a02e022 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -404,6 +404,7 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) std::string tmp, hostname, username, password; SIPAccount *account = NULL; + pjsip_regc *regc; pjsip_hdr hdr_list; account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (id)); @@ -468,6 +469,8 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) _mutexSIP.enterMutex(); + // Get the client registration information for this particular account + regc = account->getRegistrationInfo(); account->setRegister (true); // Set the expire value of the message from the config file @@ -482,7 +485,8 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) account->setRegistrationState (Trying); // Create the registration according to the account ID - status = pjsip_regc_create (_endpt, (void *) &account->getAccountID(), ®istration_cb, &_regc); + // status = pjsip_regc_create (_endpt, (void*) account, ®istration_cb, ®c); + status = pjsip_regc_create (_endpt, (void *) &account->getAccountID(), ®istration_cb, ®c); if (status != PJ_SUCCESS) { _mutexSIP.leaveMutex(); @@ -518,7 +522,7 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) pj_cstr (&pjSrv, srvUri.c_str()); // Initializes registration - status = pjsip_regc_init (_regc, &pjSrv, &pjFrom, &pjFrom, 1, &pjContact, expire_value); + status = pjsip_regc_init (regc, &pjSrv, &pjFrom, &pjFrom, 1, &pjContact, expire_value); if (status != PJ_SUCCESS) { _mutexSIP.leaveMutex(); throw VoipLinkException("Unable to initialize account registration structure"); @@ -527,13 +531,13 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) // Fill route set if (! (account->getServiceRoute().empty())) { pjsip_route_hdr *route_set = createRouteSet(account, _pool); - pjsip_regc_set_route_set (_regc, route_set); + pjsip_regc_set_route_set (regc, route_set); } pjsip_cred_info *cred = account->getCredInfo(); unsigned credential_count = account->getCredentialCount(); _debug ("UserAgent: setting %u credentials in sendRegister", credential_count); - pjsip_regc_set_credentials (_regc, credential_count, cred); + pjsip_regc_set_credentials (regc, credential_count, cred); // Add User-Agent Header pj_list_init (&hdr_list); @@ -543,10 +547,10 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) pjsip_generic_string_hdr *h = pjsip_generic_string_hdr_create (_pool, &STR_USER_AGENT, &useragent); pj_list_push_back (&hdr_list, (pjsip_hdr*) h); - pjsip_regc_add_headers (_regc, &hdr_list); + pjsip_regc_add_headers (regc, &hdr_list); - if ((status = pjsip_regc_register (_regc, PJ_TRUE, &tdata)) != PJ_SUCCESS) { + if ((status = pjsip_regc_register (regc, PJ_TRUE, &tdata)) != PJ_SUCCESS) { _mutexSIP.leaveMutex(); throw VoipLinkException("Unable to initialize transaction data for account registration"); } @@ -556,7 +560,7 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) initTransportSelector (account->getAccountTransport (), &tp, _pool); // pjsip_regc_set_transport increments transport ref count by one - status = pjsip_regc_set_transport (_regc, tp); + status = pjsip_regc_set_transport (regc, tp); if (account->getAccountTransport()) { // decrease transport's ref count, counter icrementation is @@ -576,7 +580,7 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) // Send registration request // pjsip_regc_send increment the transport ref count by one, - status = pjsip_regc_send (_regc, tdata); + status = pjsip_regc_send (regc, tdata); if (account->getAccountTransport()) { // Decrease transport's ref count, since coresponding reference counter decrementation @@ -592,6 +596,8 @@ void SIPVoIPLink::sendRegister (AccountID id) throw(VoipLinkException) _mutexSIP.leaveMutex(); + account->setRegistrationInfo (regc); + if (account->getAccountTransport()) { _debug ("Sent account registration using transport: %s %s (refcnt=%d)", @@ -626,13 +632,17 @@ void SIPVoIPLink::sendUnregister (AccountID id) throw(VoipLinkException) return; } - status = pjsip_regc_unregister (_regc, &tdata); - _regc = NULL; + pjsip_regc *regc = account->getRegistrationInfo(); + if(regc == NULL) { + throw VoipLinkException("Registration structure is NULL"); + } + + status = pjsip_regc_unregister (regc, &tdata); if (status != PJ_SUCCESS) { throw VoipLinkException("Unable to unregister sip account"); } - status = pjsip_regc_send (_regc, tdata); + status = pjsip_regc_send (regc, tdata); if (status != PJ_SUCCESS) { throw VoipLinkException("Unable to send request to unregister sip account"); diff --git a/sflphone-common/src/sip/sipvoiplink.h b/sflphone-common/src/sip/sipvoiplink.h index f0b22eaa89080161d707ede9afa2e2a91faeb90e..74ecd8864909e8f2e83da68c7650f523cc0c6bad 100644 --- a/sflphone-common/src/sip/sipvoiplink.h +++ b/sflphone-common/src/sip/sipvoiplink.h @@ -552,8 +552,6 @@ class SIPVoIPLink : public VoIPLink */ int _clients; - // The pjsip client registration information - pjsip_regc *_regc; friend class SIPTest; };