Module: sems
Branch: master
Commit: 8c674f318e2a85ad2fd5bc4cc7e3355bc8b3d3d1
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=8c674f318e2a85ad2fd5bc4cc7e3355bc8b3d3d1

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Wed Jul 20 03:34:22 2011 +0200

db_reg_agent: re-register if user or realm changed

---

 apps/db_reg_agent/DBRegAgent.cpp |   10 ++++++++++
 core/AmSipRegistration.cpp       |   18 ++++++++++++++++++
 doc/Readme.db_reg_agent.txt      |    8 ++++++++
 3 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/apps/db_reg_agent/DBRegAgent.cpp b/apps/db_reg_agent/DBRegAgent.cpp
index 8a35c7d..b38258c 100644
--- a/apps/db_reg_agent/DBRegAgent.cpp
+++ b/apps/db_reg_agent/DBRegAgent.cpp
@@ -449,6 +449,10 @@ void DBRegAgent::updateRegistration(long subscriber_id,
     return;
   }
 
+  bool need_reregister = it->second->getInfo().domain != realm ||
+    it->second->getInfo().user != user;
+  string old_realm = it->second->getInfo().domain;
+  string old_user = it->second->getInfo().user;
   it->second->setRegistrationInfo(SIPRegistrationInfo(realm, user,
                                                      user, // name
                                                      user, // auth_user
@@ -456,6 +460,12 @@ void DBRegAgent::updateRegistration(long subscriber_id,
                                                      outbound_proxy,   // proxy
                                                      contact)); // contact
   registrations_mut.unlock();
+  if (need_reregister) {
+    DBG("user/realm for registration %ld changed (%s@%s -> %s@%s). "
+       "Triggering immediate re-registration\n",
+       subscriber_id, old_user.c_str(), old_realm.c_str(), user.c_str(), 
realm.c_str());
+    scheduleRegistration(subscriber_id);
+  }
 }
 
 /** remove registration from our list */
diff --git a/core/AmSipRegistration.cpp b/core/AmSipRegistration.cpp
index f9aa35c..942000f 100644
--- a/core/AmSipRegistration.cpp
+++ b/core/AmSipRegistration.cpp
@@ -74,6 +74,24 @@ void AmSIPRegistration::setRegistrationInfo(const 
SIPRegistrationInfo& _info) {
   DBG("updating registration info for '%s@%s'\n",
       _info.user.c_str(), _info.domain.c_str());
   info = _info;
+
+  req.user     = info.user;
+  req.r_uri    = "sip:"+info.domain;
+  req.from     = info.name+" <sip:"+info.user+"@"+info.domain+">";
+  req.from_uri = "sip:"+info.user+"@"+info.domain;
+  req.to       = req.from;
+  req.to_tag   = "";
+
+  // to trigger setting dlg identifiers
+  dlg.callid.clear();
+  dlg.contact_uri.clear();
+
+  dlg.initFromLocalRequest(req);
+
+  if(!info.contact.empty()) {
+    dlg.contact_uri = SIP_HDR_COLSP(SIP_HDR_CONTACT) "<sip:";
+    dlg.contact_uri += info.contact + ">" + CRLF;
+  }
 }
 
 void AmSIPRegistration::setSessionEventHandler(AmSessionEventHandler* new_seh) 
{
diff --git a/doc/Readme.db_reg_agent.txt b/doc/Readme.db_reg_agent.txt
index 6817075..8411a32 100644
--- a/doc/Readme.db_reg_agent.txt
+++ b/doc/Readme.db_reg_agent.txt
@@ -38,6 +38,14 @@ it is recommended to set the registration_status in the DB 
to 5
 After removing a registration by issuing removeRegistration, the subcriber 
entry will
 be present with the status REMOVED, if delete_removed_registrations=no.
 
+If a registration is not found (subscriber_id unknown) when updateRegistration
+is executed, a warning is be printed to log and the registration will be 
created.
+
+updateRegistration triggers immediate re-Registration if the user or the realm 
has
+changed, in that case the old binding is not deregistered; if this is desired, 
then
+removeRegistation should be called first and the status should be checked in 
the
+database until it appears as de-register.
+
 Registration status (registration_status column)
 ------------------------------------------------
  REG_STATUS_INACTIVE      0

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to