Browse code

- use new SET_HOSTALL_T action in ds_set_domain() - simplified ping mechanism - new module parameter to control append_branch() behavior in failure_route

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

Daniel-Constantin Mierla authored on 13/01/2009 22:46:05
Showing 5 changed files
... ...
@@ -55,6 +55,7 @@ Carsten Bock
55 55
               1.3.17. ds_ping_interval (int)
56 56
               1.3.18. ds_probing_threshhold (int)
57 57
               1.3.19. ds_probing_mode (int)
58
+              1.3.20. ds_append_branch (int)
58 59
 
59 60
         1.4. Exported Functions
60 61
 
... ...
@@ -102,9 +103,10 @@ Carsten Bock
102 103
    1.18. Set the "ds_ping_interval" parameter
103 104
    1.19. Set the "ds_probing_threshhold" parameter
104 105
    1.20. Set the "ds_probing_mode" parameter
105
-   1.21. ds_select_dst usage
106
-   1.22. dispatcher list file
107
-   1.23. Kamailio config script - sample dispatcher usage
106
+   1.21. Set the "ds_append_branch" parameter
107
+   1.22. ds_select_dst usage
108
+   1.23. dispatcher list file
109
+   1.24. Kamailio config script - sample dispatcher usage
108 110
 
109 111
 Chapter 1. Admin Guide
110 112
 
... ...
@@ -402,7 +404,7 @@ Note
402 404
    Controls what gateways are tested to see if they are reachable.
403 405
    If set to 0, only the gateways with state PROBING are tested,
404 406
    if set to 1, all gateways are tested. If set to 1 and the
405
-   response is 407 (timeout), an active gateway is set to PROBING
407
+   response is 408 (timeout), an active gateway is set to PROBING
406 408
    state.
407 409
 
408 410
    Default value is "0".
... ...
@@ -412,6 +414,19 @@ Note
412 414
  modparam("dispatcher", "ds_probing_mode", 1)
413 415
  ...
414 416
 
417
+1.3.20. ds_append_branch (int)
418
+
419
+   If set to 1, functions will automaticall append a new branch if
420
+   called in FAILURE_ROUTE. If set to 0, script writer has to call
421
+   append_branch() in config after calling dispatcher functions.
422
+
423
+   Default value is "1".
424
+
425
+   Example 1.21. Set the "ds_append_branch" parameter
426
+ ...
427
+ modparam("dispatcher", "ds_append_branch", 0)
428
+ ...
429
+
415 430
 1.4. Exported Functions
416 431
 
417 432
 1.4.1.  ds_select_dst(set, alg)
... ...
@@ -444,7 +459,7 @@ Note
444 459
 
445 460
    This function can be used from REQUEST_ROUTE.
446 461
 
447
-   Example 1.21. ds_select_dst usage
462
+   Example 1.22. ds_select_dst usage
448 463
 ...
449 464
 ds_select_dst("1", "0");
450 465
 ...
... ...
@@ -583,7 +598,7 @@ ds_select_dst("1", "0");
583 598
    address must be a valid SIP URI. Empty lines or lines starting
584 599
    with "#" are ignored.
585 600
 
586
-   Example 1.22. dispatcher list file
601
+   Example 1.23. dispatcher list file
587 602
 ...
588 603
 # $Id$
589 604
 # dispatcher destination sets
... ...
@@ -607,7 +622,7 @@ ds_select_dst("1", "0");
607 622
 
608 623
    Next picture displays a sample usage of dispatcher.
609 624
 
610
-   Example 1.23. Kamailio config script - sample dispatcher usage
625
+   Example 1.24. Kamailio config script - sample dispatcher usage
611 626
 ...
612 627
 # $Id$
613 628
 # sample config file for dispatcher module
... ...
@@ -960,7 +960,7 @@ static inline int ds_update_dst(struct sip_msg *msg, str *uri, int mode)
960 960
 	switch(mode)
961 961
 	{
962 962
 		case 1:
963
-			act.type = SET_HOSTPORT_T;
963
+			act.type = SET_HOSTALL_T;
964 964
 			act.elem[0].type = STRING_ST;
965 965
 			if(uri->len>4 
966 966
 					&& strncasecmp(uri->s,"sip:",4)==0)
... ...
@@ -973,31 +973,22 @@ static inline int ds_update_dst(struct sip_msg *msg, str *uri, int mode)
973 973
 				LM_ERR("error while setting host\n");
974 974
 				return -1;
975 975
 			}
976
-			if(route_type==FAILURE_ROUTE)
977
-			{
978
-				if (append_branch(msg, 0, 0, 0, Q_UNSPECIFIED, 0, 0)!=1 )
979
-				{
980
-					LM_ERR("append_branch action failed\n");
981
-					return -1;
982
-				}
983
-			}
984 976
 		break;
985 977
 		default:
986
-			if(route_type==FAILURE_ROUTE)
987
-			{
988
-				if (append_branch(msg, 0, uri, 0, Q_UNSPECIFIED, 0, 0)!=1 )
989
-				{
990
-					LM_ERR("append_branch action failed\n");
991
-					return -1;
992
-				}
993
-			} else {
994
-				if (set_dst_uri(msg, uri) < 0) {
995
-					LM_ERR("error while setting dst uri\n");
996
-					return -1;
997
-				}	
998
-			}
978
+			if (set_dst_uri(msg, uri) < 0) {
979
+				LM_ERR("error while setting dst uri\n");
980
+				return -1;
981
+			}	
999 982
 		break;
1000 983
 	}
984
+	if(ds_append_branch!=0 && route_type==FAILURE_ROUTE)
985
+	{
986
+		if (append_branch(msg, 0, 0, 0, Q_UNSPECIFIED, 0, 0)!=1 )
987
+		{
988
+			LM_ERR("append_branch action failed\n");
989
+			return -1;
990
+		}
991
+	}
1001 992
 	return 0;
1002 993
 }
1003 994
 
... ...
@@ -1556,15 +1547,8 @@ static void ds_options_callback( struct cell *t, int type,
1556 1547
  */
1557 1548
 void ds_check_timer(unsigned int ticks, void* param)
1558 1549
 {
1559
-	
1560
-	struct socket_info* send_sock = 0;
1561
-	struct sip_uri curi;
1562
-	union sockaddr_union to;
1563
-	struct hostent* he;
1564
-	unsigned short proto;
1565
-	dlg_t * dialog;	
1566
-	ds_set_p list;
1567 1550
 	int j;
1551
+	ds_set_p list;
1568 1552
 	
1569 1553
 	/* Check for the list. */
1570 1554
 	if(_ds_list==NULL || _ds_list_nr<=0)
... ...
@@ -1585,57 +1569,21 @@ void ds_check_timer(unsigned int ticks, void* param)
1585 1569
 				LM_DBG("probing set #%d, URI %.*s\n", list->id,
1586 1570
 						list->dlist[j].uri.len, list->dlist[j].uri.s);
1587 1571
 				
1588
-				/* Parse the URI of the destination, we want to probe (we need
1589
-				 * more information about the destination) */
1590
-				if (parse_uri(list->dlist[j].uri.s,
1591
-							list->dlist[j].uri.len, &curi) < 0)
1592
-				{
1593
-					LM_ERR("unable to parse URI (%.*s)\n",
1594
-							list->dlist[j].uri.len, list->dlist[j].uri.s);
1595
-					continue;
1596
-				}
1597
-				
1598
-				/* If the port is not set, we use the default-SIP-Port.*/
1599
-				if (curi.port_no == 0)
1600
-					curi.port_no = SIP_PORT;
1601
-
1602
-				/* Resolve the Hostnamme */
1603
-				proto = curi.proto;
1604
-				he = sip_resolvehost(&curi.host, &curi.port_no, &proto, 
1605
-						(curi.type==SIPS_URI_T)?1:0 , 0);
1606
-				if (he == NULL)
1607
-				{
1608
-					LM_ERR("can't resolve_host\n");
1609
-					continue;
1610
-				}
1611
-				
1612
-				/* Determine the sending-socket for sending the OPTIONS-Request
1613
-				 * Maybe, later, provide the possibility to use a specific
1614
-				 * socket */
1615
-				hostent2su(&to, he, 0, curi.port_no);
1616
-				if (send_sock==0) {
1617
-					/* send_sock=force_socket ? force_socket : 
1618
-						get_send_socket(0, &to, PROTO_UDP); */
1619
-					send_sock=get_send_socket(0, &to, PROTO_UDP);
1620
-				}
1621
-				if (send_sock == NULL) {
1622
-					LM_ERR("can't get sending socket\n");
1623
-					continue;
1624
-				}
1625
-				
1626
-				/* Execute the Dialog using the "req_outside"-Method of the
1627
-				 * TM-Module.
1628
-				 * req_outside(str* m, str* t, str* f, str* h, str* b,
1629
-				 *		dlg_t** d, transaction_cb c, void* cp); */
1630
-				if (tmb.t_request_outside(&ds_ping_method,
1572
+				/* Send ping using TM-Module.
1573
+				 * int request(str* m, str* ruri, str* to, str* from, str* h,
1574
+				 *		str* b, str *oburi,
1575
+				 *		transaction_cb cb, void* cbp); */
1576
+				if (tmb.t_request(&ds_ping_method,
1577
+							&list->dlist[j].uri,
1631 1578
 							&list->dlist[j].uri,
1632 1579
 							&ds_ping_from,
1633 1580
 							NULL,
1634 1581
 							NULL,
1635
-							&dialog,
1582
+							NULL,
1636 1583
 							ds_options_callback,
1637 1584
 							(void*)(long)list->id) < 0) {
1638
-					LM_ERR("unable to execute dialog\n");
1585
+					LM_ERR("unable to ping [%.*s]\n",
1586
+							list->dlist[j].uri.len, list->dlist[j].uri.s);
1639 1587
 				}
1640 1588
 			}
1641 1589
 		}
... ...
@@ -81,6 +81,7 @@ extern str ds_ping_from;
81 81
 extern int probing_threshhold; /*!< number of failed requests,
82 82
 						before a destination is taken into probing */ 
83 83
 extern int ds_probing_mode;
84
+extern int ds_append_branch;
84 85
 
85 86
 int init_data(void);
86 87
 int init_ds_db(void);
... ...
@@ -96,7 +96,8 @@ int probing_threshhold = 3; /* number of failed requests, before a destination
96 96
 str ds_ping_method = {"OPTIONS",7};
97 97
 str ds_ping_from   = {"sip:dispatcher@localhost", 24};
98 98
 static int ds_ping_interval = 0;
99
-int ds_probing_mode = 0;
99
+int ds_probing_mode  = 0;
100
+int ds_append_branch = 1;
100 101
 
101 102
 /*db */
102 103
 str ds_db_url         = {NULL, 0};
... ...
@@ -164,6 +165,7 @@ static param_export_t params[]={
164 165
 	{"ds_ping_from",       STR_PARAM, &ds_ping_from.s},
165 166
 	{"ds_ping_interval",   INT_PARAM, &ds_ping_interval},
166 167
 	{"ds_probing_mode",    INT_PARAM, &ds_probing_mode},
168
+	{"ds_append_branch",   INT_PARAM, &ds_append_branch},
167 169
 	{0,0,0}
168 170
 };
169 171
 
... ...
@@ -489,6 +489,28 @@ modparam("dispatcher", "force_dst", 1)
489 489
  		</example>
490 490
 	</section>
491 491
 
492
+ 	<section>
493
+ 		<title><varname>ds_append_branch</varname> (int)</title>
494
+ 		<para>
495
+		If set to 1, functions will automaticall append a new branch if
496
+		called in FAILURE_ROUTE. If set to 0, script writer has to call
497
+		append_branch() in config after calling dispatcher functions.
498
+ 		</para>
499
+ 		<para>
500
+ 		<emphasis>
501
+ 			Default value is <quote>1</quote>.
502
+ 		</emphasis>
503
+ 		</para>
504
+ 		<example>
505
+ 		<title>Set the <quote>ds_append_branch</quote> parameter</title>
506
+ <programlisting format="linespecific">
507
+ ...
508
+ modparam("dispatcher", "ds_append_branch", 0)
509
+ ...
510
+ </programlisting>
511
+ 		</example>
512
+	</section>
513
+
492 514
 	</section>
493 515
 
494 516
 	<section>