浏览代码

modules/ims_registrar_scscf: added function lookup_path_to_contact
- useful for trying to find a loose-routed path to a speccific contact

Jason Penton 10 年之前
父节点
当前提交
66589d42e1

+ 81 - 39
modules/ims_registrar_scscf/doc/ims_registrar_scscf_admin.xml

@@ -67,10 +67,9 @@
       contact parameters, this value will be used for newly created S-CSCF
       contact parameters, this value will be used for newly created S-CSCF
       usrloc records. The parameter contains number of second to expire (for
       usrloc records. The parameter contains number of second to expire (for
       example use 3600 for one hour). If it is set to a lower value than the
       example use 3600 for one hour). If it is set to a lower value than the
-      min_expires parameter then it will be ignored. This
-      parameter can be modified via ser config framework. A random value in a
-      specific interval can be selected by using the default_expires_range
-      parameter</para>
+      min_expires parameter then it will be ignored. This parameter can be
+      modified via ser config framework. A random value in a specific interval
+      can be selected by using the default_expires_range parameter</para>
 
 
       <para><emphasis> Default value is 3600. </emphasis></para>
       <para><emphasis> Default value is 3600. </emphasis></para>
 
 
@@ -87,14 +86,13 @@
       <title>default_expires_range (int)</title>
       <title>default_expires_range (int)</title>
 
 
       <para>This parameter specifies that the expiry used for newly created
       <para>This parameter specifies that the expiry used for newly created
-      S-CSCF usrloc records are not fixed(when default_expires
-      applies), but a random value in the intervalrdq
-      [default_expires-default_expires_range%,
-      default_expires+default_expires_range%]. The value is between 0
-      and 100 and represent the maximim percentage from default_expires that
-      will be substracted or added when computing the value. Default in 0,
-      meaning default_expires is left unmodified. This parameter can be
-      modified via ser config framework.</para>
+      S-CSCF usrloc records are not fixed(when default_expires applies), but a
+      random value in the intervalrdq [default_expires-default_expires_range%,
+      default_expires+default_expires_range%]. The value is between 0 and 100
+      and represent the maximim percentage from default_expires that will be
+      substracted or added when computing the value. Default in 0, meaning
+      default_expires is left unmodified. This parameter can be modified via
+      ser config framework.</para>
 
 
       <para><emphasis> Default value is 0. </emphasis></para>
       <para><emphasis> Default value is 0. </emphasis></para>
 
 
@@ -144,21 +142,23 @@
 ...</programlisting>
 ...</programlisting>
       </example>
       </example>
     </section>
     </section>
-    
+
     <section>
     <section>
       <title>subscription_default_expires (int)</title>
       <title>subscription_default_expires (int)</title>
 
 
       <para>If the processed message contains neither Expires HFs nor expires
       <para>If the processed message contains neither Expires HFs nor expires
-      contact parameters, this value will be used for newly created subscriptions.
-      The parameter contains number of second to expire (for example use 3600 for one hour). 
-      If it is set to a lower value than the subscription_min_expires parameter 
-      then it will be ignored. A random value in a specific interval can be selected 
-      by using the subscription_expires_range parameter</para>
+      contact parameters, this value will be used for newly created
+      subscriptions. The parameter contains number of second to expire (for
+      example use 3600 for one hour). If it is set to a lower value than the
+      subscription_min_expires parameter then it will be ignored. A random
+      value in a specific interval can be selected by using the
+      subscription_expires_range parameter</para>
 
 
       <para><emphasis> Default value is 3600. </emphasis></para>
       <para><emphasis> Default value is 3600. </emphasis></para>
 
 
       <example>
       <example>
-        <title>Set <varname>subscription_default_expires</varname> parameter</title>
+        <title>Set <varname>subscription_default_expires</varname>
+        parameter</title>
 
 
         <programlisting format="linespecific">...
         <programlisting format="linespecific">...
         modparam("ims_registrar_scscf", "subscription_default_expires", 3600)
         modparam("ims_registrar_scscf", "subscription_default_expires", 3600)
@@ -170,19 +170,20 @@
       <title>subscription_expires_range (int)</title>
       <title>subscription_expires_range (int)</title>
 
 
       <para>This parameter specifies that the expiry used for newly created
       <para>This parameter specifies that the expiry used for newly created
-      subscriptions are not fixed(when subscription_default_expires
-      applies), but a random value in the interval
+      subscriptions are not fixed(when subscription_default_expires applies),
+      but a random value in the interval
       [subscription_default_expires-subscription_expires_range%,
       [subscription_default_expires-subscription_expires_range%,
-      subscription_default_expires+subscription_expires_range%]. 
-      The value is between 0 and 100 and represent the maximim percentage 
-      from subscription_default_expires that will be substracted or added when 
-      computing the value. Default in 0, meaning subscription_default_expires is 
-      left unmodified.</para>
+      subscription_default_expires+subscription_expires_range%]. The value is
+      between 0 and 100 and represent the maximim percentage from
+      subscription_default_expires that will be substracted or added when
+      computing the value. Default in 0, meaning subscription_default_expires
+      is left unmodified.</para>
 
 
       <para><emphasis> Default value is 0. </emphasis></para>
       <para><emphasis> Default value is 0. </emphasis></para>
 
 
       <example>
       <example>
-        <title>Set <varname>subscription_expires_range </varname>parameter</title>
+        <title>Set <varname>subscription_expires_range
+        </varname>parameter</title>
 
 
         <programlisting format="linespecific">...
         <programlisting format="linespecific">...
         modparam("ims_registrar_scscf", "subscription_expires_range", 30) # +- 30% from subscription_expires_range
         modparam("ims_registrar_scscf", "subscription_expires_range", 30) # +- 30% from subscription_expires_range
@@ -193,14 +194,15 @@
     <section>
     <section>
       <title>subscription_min_expires (int)</title>
       <title>subscription_min_expires (int)</title>
 
 
-      <para>The minimum expires value of a subscription, values lower than this
-      minimum will be automatically set to the minimum. Value 0 disables the
-      checking.</para>
+      <para>The minimum expires value of a subscription, values lower than
+      this minimum will be automatically set to the minimum. Value 0 disables
+      the checking.</para>
 
 
       <para><emphasis> Default value is 10. </emphasis></para>
       <para><emphasis> Default value is 10. </emphasis></para>
 
 
       <example>
       <example>
-        <title>Set <varname>subscription_min_expires</varname>parameter</title>
+        <title>Set
+        <varname>subscription_min_expires</varname>parameter</title>
 
 
         <programlisting format="linespecific">...
         <programlisting format="linespecific">...
         modparam("subscription_min_expires", "min_expires", 1800)
         modparam("subscription_min_expires", "min_expires", 1800)
@@ -211,14 +213,15 @@
     <section>
     <section>
       <title>subscription_max_expires (int)</title>
       <title>subscription_max_expires (int)</title>
 
 
-      <para>The maximum expires value of a subscription, values higher than this
-      maximum will be automatically set to the maximum. Value 0 disables the
-      checking.</para>
+      <para>The maximum expires value of a subscription, values higher than
+      this maximum will be automatically set to the maximum. Value 0 disables
+      the checking.</para>
 
 
       <para><emphasis> Default value is 1000000. </emphasis></para>
       <para><emphasis> Default value is 1000000. </emphasis></para>
 
 
       <example>
       <example>
-        <title>Set <varname>subscription_max_expires</varname>parameter</title>
+        <title>Set
+        <varname>subscription_max_expires</varname>parameter</title>
 
 
         <programlisting format="linespecific">...
         <programlisting format="linespecific">...
         modparam("ims_registrar_scscf", "subscription_max_expires", 3600)
         modparam("ims_registrar_scscf", "subscription_max_expires", 3600)
@@ -386,12 +389,12 @@
 ...</programlisting>
 ...</programlisting>
       </example>
       </example>
     </section>
     </section>
-    
+
     <section>
     <section>
       <title>user_data_always (integer)</title>
       <title>user_data_always (integer)</title>
 
 
-      <para>If specified this will make the S-CSCF always request user
-	  data from HSS.</para>
+      <para>If specified this will make the S-CSCF always request user data
+      from HSS.</para>
 
 
       <para><emphasis> Default value is 0 (disabled)</emphasis></para>
       <para><emphasis> Default value is 0 (disabled)</emphasis></para>
 
 
@@ -404,7 +407,6 @@
 	</programlisting>
 	</programlisting>
       </example>
       </example>
     </section>
     </section>
-    
   </section>
   </section>
 
 
   <section>
   <section>
@@ -513,6 +515,46 @@ switch ($retcode) {
       </example>
       </example>
     </section>
     </section>
 
 
+    <section>
+      <title><function
+      moreinfo="none">lookup_path_to_contact(uri)</function></title>
+
+      <para>This function take a URI and tries to find the contact in usrloc.
+      If the contact is found and has a path set, then a path header is added
+      to the SIP message so it can be loose routed.</para>
+
+      <para>Meaning of the parameters is as follows:</para>
+
+      <para><itemizedlist>
+          <listitem>
+            <para>uri - URI of contact to lookup</para>
+          </listitem>
+        </itemizedlist></para>
+
+      <para>Return codes:</para>
+
+      <para><itemizedlist>
+          <listitem>
+            <para><emphasis>1</emphasis> - Success</para>
+          </listitem>
+
+          <listitem>
+            <para>-1 - Failure</para>
+          </listitem>
+        </itemizedlist></para>
+
+      <para>This function can be used from REQUEST_ROUTE, FAILURE_ROUTE</para>
+
+      <example>
+        <title><function>lookup</function> usage</title>
+
+        <programlisting format="linespecific">...
+lookup_path_to_contact($ruri);
+...
+</programlisting>
+      </example>
+    </section>
+
     <section>
     <section>
       <title><function moreinfo="none">unregister(domain)</function></title>
       <title><function moreinfo="none">unregister(domain)</function></title>
 
 

+ 39 - 0
modules/ims_registrar_scscf/lookup.c

@@ -123,6 +123,10 @@ int lookup(struct sip_msg* _m, udomain_t* _d) {
 		ret = -3;
 		ret = -3;
 		goto done;
 		goto done;
 	    }
 	    }
+	    if (set_path_vector(_m, &ptr->path) < 0) {
+		LM_ERR("failed to set path vector\n");
+		return -1;
+	    }
 	    if (set_dst_uri(_m, &path_dst) < 0) {
 	    if (set_dst_uri(_m, &path_dst) < 0) {
 		LM_ERR("failed to set dst_uri of Path\n");
 		LM_ERR("failed to set dst_uri of Path\n");
 		ret = -3;
 		ret = -3;
@@ -177,6 +181,41 @@ done:
     return ret;
     return ret;
 }
 }
 
 
+int lookup_path_to_contact(struct sip_msg* _m, char* contact_uri) {
+    ucontact_t* contact;
+    str s_contact_uri;
+    str path_dst;
+    
+    if (get_str_fparam(&s_contact_uri, _m, (fparam_t*) contact_uri) < 0) {
+	    LM_ERR("failed to get RURI\n");
+	    return -1;
+    }
+    LM_DBG("Looking up contact [%.*s]\n", s_contact_uri.len, s_contact_uri.s);
+
+    if (ul.get_ucontact(NULL, &s_contact_uri, 0, 0, 0, &contact) == 0) { //get_contact returns with lock
+	LM_DBG("CONTACT FOUND and path is [%.*s]\n", contact->path.len, contact->path.s);
+	
+	if (get_path_dst_uri(&contact->path, &path_dst) < 0) {
+	    LM_ERR("failed to get dst_uri for Path\n");
+	    return -1;
+	}
+	if (set_path_vector(_m, &contact->path) < 0) {
+	    LM_ERR("failed to set path vector\n");
+	    return -1;
+	}
+	if (set_dst_uri(_m, &path_dst) < 0) {
+	    LM_ERR("failed to set dst_uri of Path\n");
+	    return -1;
+	}
+	
+	ul.release_ucontact(contact);
+	return 1;
+    }
+
+    LM_DBG("no contact found for [%.*s]\n", s_contact_uri.len, s_contact_uri.s);
+    return -1;
+}
+
 /*! \brief the impu_registered() function
 /*! \brief the impu_registered() function
  * Return true if the AOR in the To Header is registered
  * Return true if the AOR in the To Header is registered
  */
  */

+ 1 - 1
modules/ims_registrar_scscf/lookup.h

@@ -40,7 +40,7 @@
  * Lookup a contact in usrloc and rewrite R-URI if found
  * Lookup a contact in usrloc and rewrite R-URI if found
  */
  */
 int lookup(struct sip_msg* _m, udomain_t* _d);
 int lookup(struct sip_msg* _m, udomain_t* _d);
-
+int lookup_path_to_contact(struct sip_msg* _m, char* contact_uri);
 
 
 /*! \brief
 /*! \brief
  * Return true if the AOR in the Request-URI is registered,
  * Return true if the AOR in the Request-URI is registered,

+ 6 - 0
modules/ims_registrar_scscf/reg_mod.c

@@ -113,6 +113,7 @@ static void mod_destroy(void);
 static int w_save(struct sip_msg* _m, char * _route, char* _d, char* mode, char* _cflags);
 static int w_save(struct sip_msg* _m, char * _route, char* _d, char* mode, char* _cflags);
 static int w_assign_server_unreg(struct sip_msg* _m, char* _route, char* _d, char* _direction);
 static int w_assign_server_unreg(struct sip_msg* _m, char* _route, char* _d, char* _direction);
 static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
 static int w_lookup(struct sip_msg* _m, char* _d, char* _p2);
+static int w_lookup_path_to_contact(struct sip_msg* _m, char* contact_uri);
 
 
 /*! \brief Fixup functions */
 /*! \brief Fixup functions */
 static int domain_fixup(void** param, int param_no);
 static int domain_fixup(void** param, int param_no);
@@ -190,6 +191,7 @@ static pv_export_t mod_pvs[] = {
 static cmd_export_t cmds[] = {
 static cmd_export_t cmds[] = {
     {"save", (cmd_function) w_save, 2, assign_save_fixup3_async, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
     {"save", (cmd_function) w_save, 2, assign_save_fixup3_async, 0, REQUEST_ROUTE | ONREPLY_ROUTE},
     {"lookup", (cmd_function) w_lookup, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"lookup", (cmd_function) w_lookup, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
+    {"lookup_path_to_contact", (cmd_function) w_lookup_path_to_contact, 1, fixup_var_str_12, 0, REQUEST_ROUTE},
     {"term_impu_registered", (cmd_function) term_impu_registered, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"term_impu_registered", (cmd_function) term_impu_registered, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"impu_registered", (cmd_function) impu_registered, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"impu_registered", (cmd_function) impu_registered, 1, domain_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE},
     {"assign_server_unreg", (cmd_function) w_assign_server_unreg, 3, assign_save_fixup3_async, 0, REQUEST_ROUTE},
     {"assign_server_unreg", (cmd_function) w_assign_server_unreg, 3, assign_save_fixup3_async, 0, REQUEST_ROUTE},
@@ -533,6 +535,10 @@ static int w_assign_server_unreg(struct sip_msg* _m, char* _route, char* _d, cha
 
 
 }
 }
 
 
+static int w_lookup_path_to_contact(struct sip_msg* _m, char* contact_uri) {
+    return lookup_path_to_contact(_m, contact_uri);
+}
+
 /*! \brief
 /*! \brief
  * Wrapper to lookup(location)
  * Wrapper to lookup(location)
  */
  */