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

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Tue May  3 11:34:00 2011 +0200

enables specifying contact in SIP registration

based on a patch by Andreas agranig at sipwise

---

 apps/reg_agent/RegistrationAgent.cpp         |   15 +++++++-----
 apps/reg_agent/RegistrationAgent.h           |    1 +
 apps/reg_agent/etc/reg_agent.conf            |    3 ++
 apps/registrar_client/SIPRegistrarClient.cpp |   32 +++++++++++++++++++------
 apps/registrar_client/SIPRegistrarClient.h   |    9 +++++--
 doc/Readme.reg_agent.txt                     |    7 +++--
 doc/Readme.registrar_client.txt              |    3 ++
 7 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/apps/reg_agent/RegistrationAgent.cpp 
b/apps/reg_agent/RegistrationAgent.cpp
index 4605d72..716e6bf 100644
--- a/apps/reg_agent/RegistrationAgent.cpp
+++ b/apps/reg_agent/RegistrationAgent.cpp
@@ -42,6 +42,7 @@
 #define CFG_PARAM_AUTH    "auth_user"
 #define CFG_PARAM_PASS    "pwd"
 #define CFG_PARAM_PROXY   "proxy"
+#define CFG_PARAM_CONTACT "contact"
 
 #define MAX_ACCOUNTS      100
 
@@ -72,6 +73,7 @@ int RegistrationAgentFactory::onLoad()
     ri.auth_user = cfg.getParameter(CFG_PARAM_AUTH+idx_str,"");
     ri.passwd = cfg.getParameter(CFG_PARAM_PASS+idx_str,"");
     ri.proxy = cfg.getParameter(CFG_PARAM_PROXY+idx_str,"");
+    ri.contact = cfg.getParameter(CFG_PARAM_CONTACT+idx_str,"");
 
     if (!ri.domain.length() || !ri.user.length()) {
       // not including the passwd: might be IP based registration
@@ -85,9 +87,9 @@ int RegistrationAgentFactory::onLoad()
       ri.auth_user = ri.user;
 
     dialer.add_reg(ri);
-    DBG("Adding registration account #%d (%s %s %s %s %s)\n", i, 
+    DBG("Adding registration account #%d (%s %s %s %s %s %s)\n", i,
         ri.domain.c_str(), ri.user.c_str(), ri.display_name.c_str(), 
-        ri.auth_user.c_str(), ri.proxy.c_str());
+        ri.auth_user.c_str(), ri.proxy.c_str(), ri.contact.c_str());
 
     i ++;
     idx_str = int2str(i);
@@ -130,10 +132,11 @@ void RegThread::create_registration(RegInfo& ri) {
       di_args.push(ri.domain.c_str());
       di_args.push(ri.user.c_str());
       di_args.push(ri.display_name.c_str()); // display name
-      di_args.push(ri.auth_user.c_str());  // auth_user
-      di_args.push(ri.passwd.c_str());    // pwd
-      di_args.push("reg_agent"); //sess_link
-      di_args.push(ri.proxy.c_str()); 
+      di_args.push(ri.auth_user.c_str());    // auth_user
+      di_args.push(ri.passwd.c_str());       // pwd
+      di_args.push("reg_agent");             //sess_link
+      di_args.push(ri.proxy.c_str());
+      di_args.push(ri.contact.c_str());
                        
       uac_auth_i->invoke("createRegistration", di_args, reg_handle);
       if (reg_handle.size()) 
diff --git a/apps/reg_agent/RegistrationAgent.h 
b/apps/reg_agent/RegistrationAgent.h
index 05459a3..0620d9a 100644
--- a/apps/reg_agent/RegistrationAgent.h
+++ b/apps/reg_agent/RegistrationAgent.h
@@ -41,6 +41,7 @@ struct RegInfo {
   string auth_user;
   string passwd;
   string proxy;
+  string contact;
 
   string handle;
 };
diff --git a/apps/reg_agent/etc/reg_agent.conf 
b/apps/reg_agent/etc/reg_agent.conf
index 3262a6a..e9ce4ca 100644
--- a/apps/reg_agent/etc/reg_agent.conf
+++ b/apps/reg_agent/etc/reg_agent.conf
@@ -15,6 +15,8 @@
 #auth_user=myuser
 # optional (defaults to resolved by domain):
 #proxy=sip.mydomain.net:5060
+# optional (default to <user>@<publicip/localip>):
+#contact=sip:[email protected]
 
 #
 # For multiple registrations add more entries
@@ -26,6 +28,7 @@
 #display_name1=xyz
 #auth_user1=xyz
 #proxy1=sip.iptel.org:5060
+#contact1=sip:[email protected]
 
 #domain2=iptel.org
 #user2=xyz
diff --git a/apps/registrar_client/SIPRegistrarClient.cpp 
b/apps/registrar_client/SIPRegistrarClient.cpp
index e76729e..1a1a666 100644
--- a/apps/registrar_client/SIPRegistrarClient.cpp
+++ b/apps/registrar_client/SIPRegistrarClient.cpp
@@ -79,6 +79,10 @@ SIPRegistration::SIPRegistration(const string& handle,
   // clear dlg.callid? ->reregister?
   dlg.updateStatusFromLocalRequest(req);
   dlg.cseq = 50;
+  if(!info.contact.empty()) {
+      dlg.contact_uri = SIP_HDR_COLSP(SIP_HDR_CONTACT) "<sip:";
+      dlg.contact_uri += info.contact + ">" + CRLF;
+  }
 }
 
 SIPRegistration::~SIPRegistration() {
@@ -102,12 +106,16 @@ void SIPRegistration::doRegistration()
     // set outbound proxy as next hop 
     if (!info.proxy.empty()) {
        dlg.outbound_proxy = info.proxy;
-    } else if (!AmConfig::OutboundProxy.empty()) 
+    } else if (!AmConfig::OutboundProxy.empty()) {
        dlg.outbound_proxy = AmConfig::OutboundProxy;
-    //else 
-    //    dlg.outbound_proxy = "";
+    }
+
+    if(!info.contact.empty()) {
+      dlg.contact_uri = SIP_HDR_COLSP(SIP_HDR_CONTACT) "<"
+        + info.contact + ">" + CRLF;
+    }
     
-    if (dlg.sendRequest(req.method, "", "", "Expires: 1000\n") < 0)
+    if (dlg.sendRequest(req.method, "", "", "Expires: 3600\n") < 0)
       ERROR("failed to send registration.\n");
     
     // save TS
@@ -131,6 +139,10 @@ void SIPRegistration::doUnregister()
        dlg.outbound_proxy = AmConfig::OutboundProxy;
     //else 
     //    dlg.outbound_proxy = "";
+    if(!info.contact.empty()) {
+        dlg.contact_uri = SIP_HDR_COLSP(SIP_HDR_CONTACT) "<";
+        dlg.contact_uri += info.contact + ">" + CRLF;
+    }
     
     if (dlg.sendRequest(req.method, "", "", "Expires: 0\n") < 0)
       ERROR("failed to send deregistration.\n");
@@ -592,13 +604,14 @@ string SIPRegistrarClient::createRegistration(const 
string& domain,
                                              const string& auth_user,
                                              const string& pwd,
                                              const string& sess_link,
-                                             const string& proxy) {
+                                             const string& proxy,
+                                              const string& contact) {
        
   string handle = AmSession::getNewId();
   instance()->
     postEvent(new SIPNewRegistrationEvent(SIPRegistrationInfo(domain, user, 
                                                              name, auth_user, 
pwd, 
-                                                             proxy),
+                                                             proxy, contact),
                                          handle, sess_link));
   return handle;
 }
@@ -639,6 +652,7 @@ void SIPRegistrarClient::listRegistrations(AmArg& res) {
     r["auth_user"] = it->second->getInfo().auth_user;
     r["proxy"] = it->second->getInfo().proxy;
     r["event_sink"] = it->second->getEventSink();
+    r["contact"] = it->second->getInfo().contact;
     res.push(r);
   }
 
@@ -650,9 +664,11 @@ void SIPRegistrarClient::invoke(const string& method, 
const AmArg& args,
                                AmArg& ret)
 {
   if(method == "createRegistration"){
-    string proxy;
+    string proxy, contact;
     if (args.size() > 6)
       proxy = args.get(6).asCStr();
+    if (args.size() > 7)
+      contact = args.get(7).asCStr();
 
     ret.push(createRegistration(args.get(0).asCStr(),
                                args.get(1).asCStr(),
@@ -660,7 +676,7 @@ void SIPRegistrarClient::invoke(const string& method, const 
AmArg& args,
                                args.get(3).asCStr(),
                                args.get(4).asCStr(),
                                args.get(5).asCStr(),
-                               proxy
+                               proxy, contact
                                ).c_str());
   }
   else if(method == "removeRegistration"){
diff --git a/apps/registrar_client/SIPRegistrarClient.h 
b/apps/registrar_client/SIPRegistrarClient.h
index 21686e4..45929b4 100644
--- a/apps/registrar_client/SIPRegistrarClient.h
+++ b/apps/registrar_client/SIPRegistrarClient.h
@@ -49,15 +49,17 @@ struct SIPRegistrationInfo {
   string auth_user;
   string pwd;
   string proxy;
+  string contact;
 
   SIPRegistrationInfo(const string& domain,
                      const string& user,
                      const string& name,
                      const string& auth_user,
                      const string& pwd,
-                     const string& proxy)
+                     const string& proxy,
+                     const string& contact)
     : domain(domain),user(user),name(name),
-    auth_user(auth_user),pwd(pwd),proxy(proxy)
+    auth_user(auth_user),pwd(pwd),proxy(proxy),contact(contact)
   { }
 };
 
@@ -211,7 +213,8 @@ class SIPRegistrarClient  : public AmThread,
                            const string& auth_user,
                            const string& pwd,
                            const string& sess_link,
-                           const string& proxy);
+                           const string& proxy,
+                           const string& contact);
   void removeRegistration(const string& handle);
 
   bool hasRegistration(const string& handle);
diff --git a/doc/Readme.reg_agent.txt b/doc/Readme.reg_agent.txt
index 967bd48..79ac974 100644
--- a/doc/Readme.reg_agent.txt
+++ b/doc/Readme.reg_agent.txt
@@ -1,8 +1,9 @@
 Readme for reg_agent module
 
-This module uses the registrar_client to register the contact
-sems@<local_ip>:<sip_port> at a SIP registrar. The accounts 
-(identities) are set in the config file.
+This module uses the registrar_client to register SEMS
+at a SIP registrar. The accounts  (identities) are set in
+the config file.
+
 If the registration is not successful, it tries to 
 re-register.
 
diff --git a/doc/Readme.registrar_client.txt b/doc/Readme.registrar_client.txt
index c5bebde..bfa3717 100644
--- a/doc/Readme.registrar_client.txt
+++ b/doc/Readme.registrar_client.txt
@@ -22,6 +22,9 @@ args:
           CStr pwd       : password
           CStr sess_link : local tag of session or name of factory that 
receives
                         events about the status of the registration
+   optional:
+           CStr proxy     : proxy to be used for registration
+           CStr contact   : contact to register
 
 returns: CStr handle  : used to remove the registration or correlate events
 

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

Reply via email to