Browse code

- 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 authored on 22/01/2009 13:43:17
Showing 3 changed files
... ...
@@ -46,11 +46,11 @@ Henning Westerholt
46 46
 
47 47
               1.4.1. cr_user_carrier(user, domain, dstavp)
48 48
               1.4.2. cr_route(carrier, domain, prefix_matching,
49
-                      rewrite_user, hash_source, dstavp)
49
+                      rewrite_user, hash_source, descavp)
50 50
 
51 51
               1.4.3. cr_prime_route(carrier, domain,
52 52
                       prefix_matching, rewrite_user, hash_source,
53
-                      dstavp)
53
+                      descavp)
54 54
 
55 55
               1.4.4. cr_next_domain(carrier, domain,
56 56
                       prefix_matching, host, reply_code, dstavp)
... ...
@@ -452,15 +452,17 @@ cr_tree_rewrite_uri(tree, domain)
452 452
      * dstavp - Name of the AVP where to store the carrier id.
453 453
 
454 454
 1.4.2.  cr_route(carrier, domain, prefix_matching, rewrite_user,
455
-hash_source, dstavp)
455
+hash_source, descavp)
456 456
 
457 457
    This function searches for the longest match for the user given
458 458
    in prefix_matching at the given domain in the given carrier
459 459
    tree. The Request URI is rewritten using rewrite_user and the
460 460
    given hash source and algorithm. Returns -1 if there is no data
461 461
    found or an empty rewrite host on the longest match is found.
462
-   Otherwise the rewritten host is stored in the given AVP (if
463
-   obmitted, the host is not stored in an AVP).
462
+   On sucess also the description is stored in the given AVP (if
463
+   obmitted, nothing is stored in an AVP). This is useful if you
464
+   need some additional informations that belongs to each gw, like
465
+   the destination or the number of channels.
464 466
 
465 467
    This function is only usable with rewrite_user and
466 468
    prefix_matching containing a valid string. This string needs to
... ...
@@ -492,19 +494,21 @@ hash_source, dstavp)
492 494
        configuration parameter max_targets. Possible values for
493 495
        hash_source are: call_id, from_uri, from_user, to_uri and
494 496
        to_user.
495
-     * dstavp - Name of the AVP where to store the rewritten host.
497
+     * decsavp - Name of the AVP where to store the description.
496 498
        This parameter is optional.
497 499
 
498 500
 1.4.3.  cr_prime_route(carrier, domain, prefix_matching,
499
-rewrite_user, hash_source, dstavp)
501
+rewrite_user, hash_source, descavp)
500 502
 
501 503
    This function searches for the longest match for the user given
502 504
    in prefix_matching at the given domain in the given carrier
503 505
    tree. The Request URI is rewritten using rewrite_user and the
504 506
    given hash source and algorithm. Returns -1 if there is no data
505 507
    found or an empty rewrite host on the longest match is found.
506
-   Otherwise the rewritten host is stored in the given AVP (if
507
-   obmitted, the host is not stored in an AVP). This function is
508
+   On success also the description is stored in the given AVP (if
509
+   obmitted, nothing is stored in an AVP). This is useful if you
510
+   need some additional informations that belongs to each gw, like
511
+   the destination or the number of channels. This function is
508 512
    only usable with rewrite_user and prefix_matching containing a
509 513
    valid string. This string needs to be numerical if the
510 514
    match_mode parameter is set to 10. It uses the prime hash
... ...
@@ -527,7 +531,7 @@ rewrite_user, hash_source, dstavp)
527 531
        configuration parameter max_targets. Possible values for
528 532
        hash_source are: call_id, from_uri, from_user, to_uri and
529 533
        to_user.
530
-     * dstavp - Name of the AVP where to store the rewritten host.
534
+     * descavp - Name of the AVP where to store the description.
531 535
        This parameter is optional.
532 536
 
533 537
 1.4.4.  cr_next_domain(carrier, domain, prefix_matching, host,
... ...
@@ -727,10 +731,13 @@ route[1] {
727 731
         # just an example domain
728 732
         $avp(s:domain)="start";
729 733
         if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
730
-                        "call_id", "$avp(s:host)")) {
734
+                        "call_id")) {
731 735
                 xlog("L_ERR", "cr_route failed\n");
732 736
                 exit;
733 737
         }
738
+        # if you store also the port as part of the rewrite host,
739
+        # otherwise you can just use $rd later
740
+        $avp(s:host)= $rd+":"+$rp;
734 741
         t_on_failure("1");
735 742
                 if (!t_relay()) {
736 743
                         sl_reply_error();
... ...
@@ -746,10 +753,11 @@ failure_route[1] {
746 753
                 exit;
747 754
         }
748 755
         if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
749
-                        "call_id", "$avp(s:host)")) {
756
+                        "call_id")) {
750 757
                 xlog("L_ERR", "cr_route failed\n");
751 758
                 exit;
752 759
         }
760
+        $avp(s:host)= $rd+":"+$rp;
753 761
         t_on_failure("1");
754 762
         append_branch();
755 763
         if (!t_relay()) {
... ...
@@ -269,14 +269,14 @@ static struct route_rule * get_rule_by_hash(const struct route_flags * rf,
269 269
  * @param dest the returned new destination URI
270 270
  * @param msg the sip message
271 271
  * @param user the localpart of the uri to be rewritten
272
- * @param dstavp the name of the destination AVP where the used host name is stored
272
+ * @param descavp the name of the AVP where the description is stored
273 273
  *
274 274
  * @return 0 on success, -1 on failure
275 275
  *
276 276
  * @see rewrite_on_rule()
277 277
  */
278 278
 static int actually_rewrite(const struct route_rule *rs, str *dest,
279
-		const struct sip_msg *msg, const str * user, gparam_t *dstavp) {
279
+		const struct sip_msg *msg, const str * user, gparam_t *descavp) {
280 280
 	size_t len;
281 281
 	char *p;
282 282
 	int_str avp_val;
... ...
@@ -327,10 +327,10 @@ static int actually_rewrite(const struct route_rule *rs, str *dest,
327 327
 	p += rs->host.len;
328 328
 	*p = '\0';
329 329
 
330
-	if (dstavp) {
331
-		avp_val.s = rs->host;
332
-		if (add_avp(AVP_VAL_STR | dstavp->v.pve->spec.pvp.pvn.u.isname.type,
333
-					dstavp->v.pve->spec.pvp.pvn.u.isname.name, avp_val)<0) {
330
+	if (descavp) {
331
+		avp_val.s = rs->comment;
332
+		if (add_avp(AVP_VAL_STR | descavp->v.pve->spec.pvp.pvn.u.isname.type,
333
+					descavp->v.pve->spec.pvp.pvn.u.isname.name, avp_val)<0) {
334 334
 			LM_ERR("set AVP failed\n");
335 335
 			pkg_free(dest->s);
336 336
 			return -1;
... ...
@@ -416,16 +416,18 @@ cr_tree_rewrite_uri(tree, domain)
416 416
 	</section>
417 417
 	<section>
418 418
 	    <title>
419
-		<function moreinfo="none">cr_route(carrier, domain, prefix_matching, rewrite_user, hash_source, dstavp)</function>
419
+		<function moreinfo="none">cr_route(carrier, domain, prefix_matching, rewrite_user, hash_source, descavp)</function>
420 420
 	    </title>
421 421
 	    <para>
422 422
         This function searches for the longest match for the user given
423 423
         in prefix_matching at the given domain in the given carrier tree.
424 424
         The Request URI is rewritten using rewrite_user and the given
425 425
         hash source and algorithm. Returns -1 if there is no data found
426
-        or an empty rewrite host on the longest match is found. Otherwise
427
-        the rewritten host is stored in the given AVP (if obmitted, the
428
-        host is not stored in an AVP).
426
+        or an empty rewrite host on the longest match is found. On sucess
427
+        also the description is stored in the given AVP (if obmitted, nothing
428
+        is stored in an AVP). This is useful if you need some additional
429
+        informations that belongs to each gw, like the destination or the
430
+        number of channels.
429 431
         </para>
430 432
         <para>
431 433
         This function is only usable with rewrite_user and prefix_matching
... ...
@@ -477,7 +479,7 @@ cr_tree_rewrite_uri(tree, domain)
477 479
   		    </para>
478 480
         </listitem>
479 481
         <listitem>
480
-		      <para><emphasis>dstavp</emphasis> - Name of the AVP where to store the rewritten host.
482
+		      <para><emphasis>decsavp</emphasis> - Name of the AVP where to store the description.
481 483
 			This parameter is optional.
482 484
   		    </para>
483 485
         </listitem>
... ...
@@ -485,16 +487,18 @@ cr_tree_rewrite_uri(tree, domain)
485 487
 	</section>
486 488
 		<section>
487 489
 	    <title>
488
-		<function moreinfo="none">cr_prime_route(carrier, domain, prefix_matching, rewrite_user, hash_source, dstavp)</function>
490
+		<function moreinfo="none">cr_prime_route(carrier, domain, prefix_matching, rewrite_user, hash_source, descavp)</function>
489 491
 	    </title>
490 492
 	    <para>
491 493
         This function searches for the longest match for the user given
492 494
         in prefix_matching at the given domain in the given carrier tree.
493 495
         The Request URI is rewritten using rewrite_user and the given
494 496
         hash source and algorithm. Returns -1 if there is no data found
495
-        or an empty rewrite host on the longest match is found. Otherwise
496
-				the rewritten host is stored in the given AVP (if obmitted, the
497
-				host is not stored in an AVP).
497
+        or an empty rewrite host on the longest match is found. On success
498
+        also the description is stored in the given AVP (if obmitted, nothing
499
+        is stored in an AVP). This is useful if you need some additional
500
+        informations that belongs to each gw, like the destination or the
501
+        number of channels.
498 502
         This function is only usable with rewrite_user and prefix_matching
499 503
         containing a valid string. This string needs to be numerical if the match_mode
500 504
 		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)
535 539
   		    </para>
536 540
         </listitem>
537 541
         <listitem>
538
-		      <para><emphasis>dstavp</emphasis> - Name of the AVP where to store the rewritten host.
542
+		      <para><emphasis>descavp</emphasis> - Name of the AVP where to store the description.
539 543
 			This parameter is optional.
540 544
   		    </para>
541 545
         </listitem>
... ...
@@ -854,10 +858,13 @@ route[1] {
854 858
 	# just an example domain
855 859
 	$avp(s:domain)="start";
856 860
 	if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
857
-			"call_id", "$avp(s:host)")) {
861
+			"call_id")) {
858 862
 		xlog("L_ERR", "cr_route failed\n");
859 863
 		exit;
860 864
 	}
865
+	# if you store also the port as part of the rewrite host,
866
+	# otherwise you can just use $rd later
867
+	$avp(s:host)= $rd+":"+$rp;
861 868
 	t_on_failure("1");
862 869
 		if (!t_relay()) {
863 870
 			sl_reply_error();
... ...
@@ -872,10 +879,11 @@ failure_route[1] {
872 879
 		exit;
873 880
 	}
874 881
 	if (!cr_route("$avp(s:carrier)", "$avp(s:domain)", "$rU", "$rU",
875
-			"call_id", "$avp(s:host)")) {
882
+			"call_id")) {
876 883
 		xlog("L_ERR", "cr_route failed\n");
877 884
 		exit;
878 885
 	}
886
+	$avp(s:host)= $rd+":"+$rp;
879 887
 	t_on_failure("1");
880 888
 	append_branch();
881 889
 	if (!t_relay()) {