Browse code

- new parameter to set the value of destination list id in a variable when calling ds_is_from_list() with no parameter - helps to identify the source by group id

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

Daniel-Constantin Mierla authored on 11/04/2008 09:47:51
Showing 5 changed files
... ...
@@ -49,10 +49,11 @@ Carsten Bock
49 49
               1.3.11. grp_avp (str)
50 50
               1.3.12. cnt_avp (str)
51 51
               1.3.13. hash_pvar (str)
52
-              1.3.14. ds_ping_method (string)
53
-              1.3.15. ds_ping_from (string)
54
-              1.3.16. ds_ping_interval (int)
55
-              1.3.17. ds_probing_threshhold (int)
52
+              1.3.14. setid_pvar (str)
53
+              1.3.15. ds_ping_method (string)
54
+              1.3.16. ds_ping_from (string)
55
+              1.3.17. ds_ping_interval (int)
56
+              1.3.18. ds_probing_threshhold (int)
56 57
 
57 58
         1.4. Exported Functions
58 59
 
... ...
@@ -94,13 +95,14 @@ Carsten Bock
94 95
    1.12. Set the "cnt_avp" parameter
95 96
    1.13. Use $avp(i:273) for hashing:
96 97
    1.14. Use combination of PVs for hashing:
97
-   1.15. Set the "ds_ping_method" parameter
98
-   1.16. Set the "ds_ping_from" parameter
99
-   1.17. Set the "ds_ping_interval" parameter
100
-   1.18. Set the "ds_probing_threshhold" parameter
101
-   1.19. ds_select_dst usage
102
-   1.20. dispatcher list file
103
-   1.21. OpenSER config script - sample dispatcher usage
98
+   1.15. Set the "setid_pvar" parameter
99
+   1.16. Set the "ds_ping_method" parameter
100
+   1.17. Set the "ds_ping_from" parameter
101
+   1.18. Set the "ds_ping_interval" parameter
102
+   1.19. Set the "ds_probing_threshhold" parameter
103
+   1.20. ds_select_dst usage
104
+   1.21. dispatcher list file
105
+   1.22. OpenSER config script - sample dispatcher usage
104 106
 
105 107
 Chapter 1. Admin Guide
106 108
 
... ...
@@ -326,7 +328,19 @@ Note
326 328
  modparam("dispatcher", "hash_pvar", "hash the $fU@$ci")
327 329
  ...
328 330
 
329
-1.3.14. ds_ping_method (string)
331
+1.3.14. setid_pvar (str)
332
+
333
+   The name of the PV where to store the set ID (group ID) when
334
+   calling ds_is_from_list() with no parameter.
335
+
336
+   Default value is "null" - don't set PV.
337
+
338
+   Example 1.15. Set the "setid_pvar" parameter
339
+ ...
340
+ modparam("dispatcher", "setid_pvar", "$var(setid)")
341
+ ...
342
+
343
+1.3.15. ds_ping_method (string)
330 344
 
331 345
    With this Method you can define, with which method you want to
332 346
    probe the failed gateways. This method is only available, if
... ...
@@ -334,12 +348,12 @@ Note
334 348
 
335 349
    Default value is "OPTIONS".
336 350
 
337
-   Example 1.15. Set the "ds_ping_method" parameter
351
+   Example 1.16. Set the "ds_ping_method" parameter
338 352
  ...
339 353
  modparam("dispatcher", "ds_ping_method", "INFO")
340 354
  ...
341 355
 
342
-1.3.15. ds_ping_from (string)
356
+1.3.16. ds_ping_from (string)
343 357
 
344 358
    With this Method you can define the "From:"-Line for the
345 359
    request, sent to the failed gateways. This method is only
... ...
@@ -348,12 +362,12 @@ Note
348 362
 
349 363
    Default value is "sip:dispatcher@localhost".
350 364
 
351
-   Example 1.16. Set the "ds_ping_from" parameter
365
+   Example 1.17. Set the "ds_ping_from" parameter
352 366
  ...
353 367
  modparam("dispatcher", "ds_ping_from", "sip:proxy@sip.somehost.com")
354 368
  ...
355 369
 
356
-1.3.16. ds_ping_interval (int)
370
+1.3.17. ds_ping_interval (int)
357 371
 
358 372
    With this Method you can define the interval for sending a
359 373
    request to a failed gateway. This parameter is only used, when
... ...
@@ -362,12 +376,12 @@ Note
362 376
 
363 377
    Default value is "10".
364 378
 
365
-   Example 1.17. Set the "ds_ping_interval" parameter
379
+   Example 1.18. Set the "ds_ping_interval" parameter
366 380
  ...
367 381
  modparam("dispatcher", "ds_ping_interval", 30)
368 382
  ...
369 383
 
370
-1.3.17. ds_probing_threshhold (int)
384
+1.3.18. ds_probing_threshhold (int)
371 385
 
372 386
    If you want to set a gateway into probing mode, you will need a
373 387
    specific number of requests until it will change from "active"
... ...
@@ -376,7 +390,7 @@ Note
376 390
 
377 391
    Default value is "3".
378 392
 
379
-   Example 1.18. Set the "ds_probing_threshhold" parameter
393
+   Example 1.19. Set the "ds_probing_threshhold" parameter
380 394
  ...
381 395
  modparam("dispatcher", "ds_probing_threshhold", 10)
382 396
  ...
... ...
@@ -412,7 +426,7 @@ Note
412 426
 
413 427
    This function can be used from REQUEST_ROUTE.
414 428
 
415
-   Example 1.19. ds_select_dst usage
429
+   Example 1.20. ds_select_dst usage
416 430
 ...
417 431
 ds_select_dst("1", "0");
418 432
 ...
... ...
@@ -551,7 +565,7 @@ ds_select_dst("1", "0");
551 565
    address must be a valid SIP URI. Empty lines or lines starting
552 566
    with "#" are ignored.
553 567
 
554
-   Example 1.20. dispatcher list file
568
+   Example 1.21. dispatcher list file
555 569
 ...
556 570
 # $Id$
557 571
 # dispatcher destination sets
... ...
@@ -575,7 +589,7 @@ ds_select_dst("1", "0");
575 589
 
576 590
    Next picture displays a sample usage of dispatcher.
577 591
 
578
-   Example 1.21. OpenSER config script - sample dispatcher usage
592
+   Example 1.22. OpenSER config script - sample dispatcher usage
579 593
 ...
580 594
 # $Id$
581 595
 # sample config file for dispatcher module
... ...
@@ -1390,28 +1390,46 @@ int ds_print_list(FILE *fout)
1390 1390
 /* Checks, if the request (sip_msg *_m) comes from a host in a group
1391 1391
  * (group-id or -1 for all groups)
1392 1392
  */
1393
-int ds_is_from_list(struct sip_msg *_m, int group) {
1394
-    
1393
+int ds_is_from_list(struct sip_msg *_m, int group)
1394
+{
1395
+	pv_value_t val;
1395 1396
 	ds_set_p list;
1396 1397
 	int j;
1397 1398
 
1399
+	memset(&val, 0, sizeof(pv_value_t));
1400
+	val.flags = PV_VAL_INT|PV_TYPE_INT;
1401
+
1398 1402
 	for(list = _ds_list; list!= NULL; list= list->next)
1399 1403
 	{
1400
-		if ((group == -1) || (group == list->id)) 
1404
+		// LM_ERR("list id: %d (n: %d)\n", list->id, list->nr);
1405
+		if ((group == -1) || (group == list->id))
1401 1406
 		{
1402 1407
 			for(j=0; j<list->nr; j++)
1403 1408
 			{
1404
-				if (ip_addr_cmp(&_m->rcv.src_ip,
1405
- 							&list->dlist[j].ip_address)
1406
-  					&& (_m->rcv.src_port == list->dlist[j].port)) {
1407
-  				return 1;
1408
-  				}
1409
- 			}
1409
+				// LM_ERR("port no: %d (%d)\n", list->dlist[j].port, j);
1410
+				if (ip_addr_cmp(&_m->rcv.src_ip, &list->dlist[j].ip_address)
1411
+						&& (list->dlist[j].port==0
1412
+						|| _m->rcv.src_port == list->dlist[j].port))
1413
+				{
1414
+					if(group==-1 && ds_setid_pvname.s!=0)
1415
+					{
1416
+						val.ri = list->id;
1417
+						if(ds_setid_pv.setf(_m, &ds_setid_pv.pvp,
1418
+								(int)EQ_T, &val)<0)
1419
+						{
1420
+							LM_ERR("setting PV failed\n");
1421
+							return -2;
1422
+						}
1423
+					}
1424
+					return 1;
1425
+				}
1426
+			}
1410 1427
 		}
1411 1428
 	}
1412 1429
 	return -1;
1413 1430
 }
1414 1431
 
1432
+
1415 1433
 int ds_print_mi_list(struct mi_node* rpl)
1416 1434
 {
1417 1435
 	int len, j;
... ...
@@ -66,6 +66,9 @@ extern unsigned short cnt_avp_type;
66 66
 
67 67
 extern pv_elem_t * hash_param_model;
68 68
 
69
+extern str ds_setid_pvname;
70
+extern pv_spec_t ds_setid_pv;
71
+
69 72
 /* Structure containing pointers to TM-functions */
70 73
 struct tm_binds tmb;
71 74
 extern str ds_ping_method;
... ...
@@ -91,6 +91,8 @@ str ds_dest_uri_col   = str_init(DS_DEST_URI_COL);
91 91
 str ds_dest_flags_col = str_init(DS_DEST_FLAGS_COL);
92 92
 str ds_table_name     = str_init(DS_TABLE_NAME);
93 93
 
94
+str ds_setid_pvname   = {NULL, 0};
95
+pv_spec_t ds_setid_pv;
94 96
 
95 97
 /** module functions */
96 98
 static int mod_init(void);
... ...
@@ -142,6 +144,7 @@ static param_export_t params[]={
142 144
 	{"grp_avp",         STR_PARAM, &grp_avp_param.s},
143 145
 	{"cnt_avp",         STR_PARAM, &cnt_avp_param.s},
144 146
 	{"hash_pvar",       STR_PARAM, &hash_pvar_param.s},
147
+	{"setid_pvname",    STR_PARAM, &ds_setid_pvname.s},
145 148
 	{"ds_probing_threshhold", INT_PARAM, &probing_threshhold},
146 149
 	{"ds_ping_method",     STR_PARAM, &ds_ping_method.s},
147 150
 	{"ds_ping_from",       STR_PARAM, &ds_ping_from.s},
... ...
@@ -188,7 +191,9 @@ static int mod_init(void)
188 191
 	if (cnt_avp_param.s)
189 192
 		cnt_avp_param.len = strlen(cnt_avp_param.s);	
190 193
 	if (hash_pvar_param.s)
191
-		hash_pvar_param.len = strlen(hash_pvar_param.s);	
194
+		hash_pvar_param.len = strlen(hash_pvar_param.s);
195
+	if (ds_setid_pvname.s)
196
+		ds_setid_pvname.len = strlen(ds_setid_pvname.s);
192 197
 	if (ds_ping_from.s) ds_ping_from.len = strlen(ds_ping_from.s);
193 198
 	if (ds_ping_method.s) ds_ping_method.len = strlen(ds_ping_method.s);
194 199
 
... ...
@@ -289,7 +294,16 @@ static int mod_init(void)
289 294
 	} else {
290 295
 		hash_param_model = NULL;
291 296
 	}
292
-
297
+	
298
+	if(ds_setid_pvname.s!=0)
299
+	{
300
+		if(pv_parse_spec(&ds_setid_pvname, &ds_setid_pv)==NULL
301
+				|| !pv_is_w(&ds_setid_pv))
302
+		{
303
+			LM_ERR("[%s]- invalid setid_pvname\n", ds_setid_pvname.s);
304
+			return -1;
305
+		}
306
+	}
293 307
 	/* Only, if the Probing-Timer is enabled the TM-API needs to be loaded: */
294 308
 	if (ds_ping_interval > 0)
295 309
 	{
... ...
@@ -361,6 +361,27 @@ modparam("dispatcher", "force_dst", 1)
361 361
  </programlisting>
362 362
  		</example>
363 363
  	</section>
364
+ 	<section>
365
+ 		<title><varname>setid_pvar</varname> (str)</title>
366
+ 		<para>
367
+		The name of the PV where to store the set ID (group ID) when calling
368
+		ds_is_from_list() with no parameter.
369
+ 		</para>
370
+ 		<para>
371
+ 		<emphasis>
372
+ 			Default value is <quote>null</quote> - don't set PV.
373
+ 		</emphasis>
374
+ 		</para>
375
+ 		<example>
376
+ 		<title>Set the <quote>setid_pvar</quote> parameter</title>
377
+ <programlisting format="linespecific">
378
+ ...
379
+ modparam("dispatcher", "setid_pvar", "$var(setid)")
380
+ ...
381
+ </programlisting>
382
+ 		</example>
383
+ 	</section>
384
+
364 385
  	<section>
365 386
  		<title><varname>ds_ping_method</varname> (string)</title>
366 387
  		<para>