Browse Source

- change functionality in cr_route, cr_prime_route to not store information
about the destination host in the given AVP, instead the content of the
routing description is stored
- no existing functionality is lost, $rt, or $rd + $rp can be used instead
- fix tests to work after modification


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5497 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 16 years ago
parent
commit
0d6a380220

+ 20 - 12
modules/carrierroute/README

@@ -46,11 +46,11 @@ Henning Westerholt
 
 
               1.4.1. cr_user_carrier(user, domain, dstavp)
               1.4.1. cr_user_carrier(user, domain, dstavp)
               1.4.2. cr_route(carrier, domain, prefix_matching,
               1.4.2. cr_route(carrier, domain, prefix_matching,
-                      rewrite_user, hash_source, dstavp)
+                      rewrite_user, hash_source, descavp)
 
 
               1.4.3. cr_prime_route(carrier, domain,
               1.4.3. cr_prime_route(carrier, domain,
                       prefix_matching, rewrite_user, hash_source,
                       prefix_matching, rewrite_user, hash_source,
-                      dstavp)
+                      descavp)
 
 
               1.4.4. cr_next_domain(carrier, domain,
               1.4.4. cr_next_domain(carrier, domain,
                       prefix_matching, host, reply_code, dstavp)
                       prefix_matching, host, reply_code, dstavp)
@@ -452,15 +452,17 @@ cr_tree_rewrite_uri(tree, domain)
      * dstavp - Name of the AVP where to store the carrier id.
      * dstavp - Name of the AVP where to store the carrier id.
 
 
 1.4.2.  cr_route(carrier, domain, prefix_matching, rewrite_user,
 1.4.2.  cr_route(carrier, domain, prefix_matching, rewrite_user,
-hash_source, dstavp)
+hash_source, descavp)
 
 
    This function searches for the longest match for the user given
    This function searches for the longest match for the user given
    in prefix_matching at the given domain in the given carrier
    in prefix_matching at the given domain in the given carrier
    tree. The Request URI is rewritten using rewrite_user and the
    tree. The Request URI is rewritten using rewrite_user and the
    given hash source and algorithm. Returns -1 if there is no data
    given hash source and algorithm. Returns -1 if there is no data
    found or an empty rewrite host on the longest match is found.
    found or an empty rewrite host on the longest match is found.
-   Otherwise the rewritten host is stored in the given AVP (if
-   obmitted, the host is not stored in an AVP).
+   On sucess also the description is stored in the given AVP (if
+   obmitted, nothing is stored in an AVP). This is useful if you
+   need some additional informations that belongs to each gw, like
+   the destination or the number of channels.
 
 
    This function is only usable with rewrite_user and
    This function is only usable with rewrite_user and
    prefix_matching containing a valid string. This string needs to
    prefix_matching containing a valid string. This string needs to
@@ -492,19 +494,21 @@ hash_source, dstavp)
        configuration parameter max_targets. Possible values for
        configuration parameter max_targets. Possible values for
        hash_source are: call_id, from_uri, from_user, to_uri and
        hash_source are: call_id, from_uri, from_user, to_uri and
        to_user.
        to_user.
-     * dstavp - Name of the AVP where to store the rewritten host.
+     * decsavp - Name of the AVP where to store the description.
        This parameter is optional.
        This parameter is optional.
 
 
 1.4.3.  cr_prime_route(carrier, domain, prefix_matching,
 1.4.3.  cr_prime_route(carrier, domain, prefix_matching,
-rewrite_user, hash_source, dstavp)
+rewrite_user, hash_source, descavp)
 
 
    This function searches for the longest match for the user given
    This function searches for the longest match for the user given
    in prefix_matching at the given domain in the given carrier
    in prefix_matching at the given domain in the given carrier
    tree. The Request URI is rewritten using rewrite_user and the
    tree. The Request URI is rewritten using rewrite_user and the
    given hash source and algorithm. Returns -1 if there is no data
    given hash source and algorithm. Returns -1 if there is no data
    found or an empty rewrite host on the longest match is found.
    found or an empty rewrite host on the longest match is found.
-   Otherwise the rewritten host is stored in the given AVP (if
-   obmitted, the host is not stored in an AVP). This function is
+   On success also the description is stored in the given AVP (if
+   obmitted, nothing is stored in an AVP). This is useful if you
+   need some additional informations that belongs to each gw, like
+   the destination or the number of channels. This function is
    only usable with rewrite_user and prefix_matching containing a
    only usable with rewrite_user and prefix_matching containing a
    valid string. This string needs to be numerical if the
    valid string. This string needs to be numerical if the
    match_mode parameter is set to 10. It uses the prime hash
    match_mode parameter is set to 10. It uses the prime hash
@@ -527,7 +531,7 @@ rewrite_user, hash_source, dstavp)
        configuration parameter max_targets. Possible values for
        configuration parameter max_targets. Possible values for
        hash_source are: call_id, from_uri, from_user, to_uri and
        hash_source are: call_id, from_uri, from_user, to_uri and
        to_user.
        to_user.
-     * dstavp - Name of the AVP where to store the rewritten host.
+     * descavp - Name of the AVP where to store the description.
        This parameter is optional.
        This parameter is optional.
 
 
 1.4.4.  cr_next_domain(carrier, domain, prefix_matching, host,
 1.4.4.  cr_next_domain(carrier, domain, prefix_matching, host,
@@ -727,10 +731,13 @@ route[1] {
         # just an example domain
         # just an example domain
         $avp(s:domain)="start";
         $avp(s:domain)="start";
         if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
         if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
-                        "call_id", "$avp(s:host)")) {
+                        "call_id")) {
                 xlog("L_ERR", "cr_route failed\n");
                 xlog("L_ERR", "cr_route failed\n");
                 exit;
                 exit;
         }
         }
+        # if you store also the port as part of the rewrite host,
+        # otherwise you can just use $rd later
+        $avp(s:host)= $rd+":"+$rp;
         t_on_failure("1");
         t_on_failure("1");
                 if (!t_relay()) {
                 if (!t_relay()) {
                         sl_reply_error();
                         sl_reply_error();
@@ -746,10 +753,11 @@ failure_route[1] {
                 exit;
                 exit;
         }
         }
         if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
         if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
-                        "call_id", "$avp(s:host)")) {
+                        "call_id")) {
                 xlog("L_ERR", "cr_route failed\n");
                 xlog("L_ERR", "cr_route failed\n");
                 exit;
                 exit;
         }
         }
+        $avp(s:host)= $rd+":"+$rp;
         t_on_failure("1");
         t_on_failure("1");
         append_branch();
         append_branch();
         if (!t_relay()) {
         if (!t_relay()) {

+ 6 - 6
modules/carrierroute/cr_func.c

@@ -269,14 +269,14 @@ static struct route_rule * get_rule_by_hash(const struct route_flags * rf,
  * @param dest the returned new destination URI
  * @param dest the returned new destination URI
  * @param msg the sip message
  * @param msg the sip message
  * @param user the localpart of the uri to be rewritten
  * @param user the localpart of the uri to be rewritten
- * @param dstavp the name of the destination AVP where the used host name is stored
+ * @param descavp the name of the AVP where the description is stored
  *
  *
  * @return 0 on success, -1 on failure
  * @return 0 on success, -1 on failure
  *
  *
  * @see rewrite_on_rule()
  * @see rewrite_on_rule()
  */
  */
 static int actually_rewrite(const struct route_rule *rs, str *dest,
 static int actually_rewrite(const struct route_rule *rs, str *dest,
-		const struct sip_msg *msg, const str * user, gparam_t *dstavp) {
+		const struct sip_msg *msg, const str * user, gparam_t *descavp) {
 	size_t len;
 	size_t len;
 	char *p;
 	char *p;
 	int_str avp_val;
 	int_str avp_val;
@@ -327,10 +327,10 @@ static int actually_rewrite(const struct route_rule *rs, str *dest,
 	p += rs->host.len;
 	p += rs->host.len;
 	*p = '\0';
 	*p = '\0';
 
 
-	if (dstavp) {
-		avp_val.s = rs->host;
-		if (add_avp(AVP_VAL_STR | dstavp->v.pve->spec.pvp.pvn.u.isname.type,
-					dstavp->v.pve->spec.pvp.pvn.u.isname.name, avp_val)<0) {
+	if (descavp) {
+		avp_val.s = rs->comment;
+		if (add_avp(AVP_VAL_STR | descavp->v.pve->spec.pvp.pvn.u.isname.type,
+					descavp->v.pve->spec.pvp.pvn.u.isname.name, avp_val)<0) {
 			LM_ERR("set AVP failed\n");
 			LM_ERR("set AVP failed\n");
 			pkg_free(dest->s);
 			pkg_free(dest->s);
 			return -1;
 			return -1;

+ 20 - 12
modules/carrierroute/doc/carrierroute_admin.xml

@@ -416,16 +416,18 @@ cr_tree_rewrite_uri(tree, domain)
 	</section>
 	</section>
 	<section>
 	<section>
 	    <title>
 	    <title>
-		<function moreinfo="none">cr_route(carrier, domain, prefix_matching, rewrite_user, hash_source, dstavp)</function>
+		<function moreinfo="none">cr_route(carrier, domain, prefix_matching, rewrite_user, hash_source, descavp)</function>
 	    </title>
 	    </title>
 	    <para>
 	    <para>
         This function searches for the longest match for the user given
         This function searches for the longest match for the user given
         in prefix_matching at the given domain in the given carrier tree.
         in prefix_matching at the given domain in the given carrier tree.
         The Request URI is rewritten using rewrite_user and the given
         The Request URI is rewritten using rewrite_user and the given
         hash source and algorithm. Returns -1 if there is no data found
         hash source and algorithm. Returns -1 if there is no data found
-        or an empty rewrite host on the longest match is found. Otherwise
-        the rewritten host is stored in the given AVP (if obmitted, the
-        host is not stored in an AVP).
+        or an empty rewrite host on the longest match is found. On sucess
+        also the description is stored in the given AVP (if obmitted, nothing
+        is stored in an AVP). This is useful if you need some additional
+        informations that belongs to each gw, like the destination or the
+        number of channels.
         </para>
         </para>
         <para>
         <para>
         This function is only usable with rewrite_user and prefix_matching
         This function is only usable with rewrite_user and prefix_matching
@@ -477,7 +479,7 @@ cr_tree_rewrite_uri(tree, domain)
   		    </para>
   		    </para>
         </listitem>
         </listitem>
         <listitem>
         <listitem>
-		      <para><emphasis>dstavp</emphasis> - Name of the AVP where to store the rewritten host.
+		      <para><emphasis>decsavp</emphasis> - Name of the AVP where to store the description.
 			This parameter is optional.
 			This parameter is optional.
   		    </para>
   		    </para>
         </listitem>
         </listitem>
@@ -485,16 +487,18 @@ cr_tree_rewrite_uri(tree, domain)
 	</section>
 	</section>
 		<section>
 		<section>
 	    <title>
 	    <title>
-		<function moreinfo="none">cr_prime_route(carrier, domain, prefix_matching, rewrite_user, hash_source, dstavp)</function>
+		<function moreinfo="none">cr_prime_route(carrier, domain, prefix_matching, rewrite_user, hash_source, descavp)</function>
 	    </title>
 	    </title>
 	    <para>
 	    <para>
         This function searches for the longest match for the user given
         This function searches for the longest match for the user given
         in prefix_matching at the given domain in the given carrier tree.
         in prefix_matching at the given domain in the given carrier tree.
         The Request URI is rewritten using rewrite_user and the given
         The Request URI is rewritten using rewrite_user and the given
         hash source and algorithm. Returns -1 if there is no data found
         hash source and algorithm. Returns -1 if there is no data found
-        or an empty rewrite host on the longest match is found. Otherwise
-				the rewritten host is stored in the given AVP (if obmitted, the
-				host is not stored in an AVP).
+        or an empty rewrite host on the longest match is found. On success
+        also the description is stored in the given AVP (if obmitted, nothing
+        is stored in an AVP). This is useful if you need some additional
+        informations that belongs to each gw, like the destination or the
+        number of channels.
         This function is only usable with rewrite_user and prefix_matching
         This function is only usable with rewrite_user and prefix_matching
         containing a valid string. This string needs to be numerical if the match_mode
         containing a valid string. This string needs to be numerical if the match_mode
 		parameter is set to 10. It uses the prime hash algorithm to calculate the hash values.
 		parameter is set to 10. It uses the prime hash algorithm to calculate the hash values.
@@ -535,7 +539,7 @@ cr_tree_rewrite_uri(tree, domain)
   		    </para>
   		    </para>
         </listitem>
         </listitem>
         <listitem>
         <listitem>
-		      <para><emphasis>dstavp</emphasis> - Name of the AVP where to store the rewritten host.
+		      <para><emphasis>descavp</emphasis> - Name of the AVP where to store the description.
 			This parameter is optional.
 			This parameter is optional.
   		    </para>
   		    </para>
         </listitem>
         </listitem>
@@ -854,10 +858,13 @@ route[1] {
 	# just an example domain
 	# just an example domain
 	$avp(s:domain)="start";
 	$avp(s:domain)="start";
 	if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
 	if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
-			"call_id", "$avp(s:host)")) {
+			"call_id")) {
 		xlog("L_ERR", "cr_route failed\n");
 		xlog("L_ERR", "cr_route failed\n");
 		exit;
 		exit;
 	}
 	}
+	# if you store also the port as part of the rewrite host,
+	# otherwise you can just use $rd later
+	$avp(s:host)= $rd+":"+$rp;
 	t_on_failure("1");
 	t_on_failure("1");
 		if (!t_relay()) {
 		if (!t_relay()) {
 			sl_reply_error();
 			sl_reply_error();
@@ -872,10 +879,11 @@ failure_route[1] {
 		exit;
 		exit;
 	}
 	}
 	if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
 	if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
-			"call_id", "$avp(s:host)")) {
+			"call_id")) {
 		xlog("L_ERR", "cr_route failed\n");
 		xlog("L_ERR", "cr_route failed\n");
 		exit;
 		exit;
 	}
 	}
+	$avp(s:host)= $rd+":"+$rp;
 	t_on_failure("1");
 	t_on_failure("1");
 	append_branch();
 	append_branch();
 	if (!t_relay()) {
 	if (!t_relay()) {