Browse code

Merge 4816a86bf6fe82d8bf20c31909f5db6205added4 into 99fde923448d251fb0e04d443d9a2bffce15d1b1

Mvondo Eric authored on 19/08/2022 14:55:15 • GitHub committed on 19/08/2022 14:55:15
Showing 4 changed files
... ...
@@ -543,6 +543,34 @@ modparam("topos", "context", "srvone")
543 543
 ...
544 544
 modparam("topos", "methods_nocontact", "CANCEL,PRACK")
545 545
 ...
546
+</programlisting>
547
+		</example>
548
+	</section>
549
+	<section id="topos.p.separate_header_values">
550
+		<title><varname>separate_header_values</varname> (int)</title>
551
+		<para>
552
+			List of headers to disable multiple comma separated values inserted in compact form.
553
+			Altough compact form is RFC compliant this paramter gives possibilty to disable
554
+			compact form header values for UA that dont support/handle it.
555
+
556
+			The following options are available:
557
+
558
+			(1) - disable multiple comma separated values for Via  header
559
+			(2) - disable multiple comma separated values for Record-Route header
560
+			(4) - disable multiple comma separated values for Route header
561
+
562
+		</para>
563
+		<para>
564
+		<emphasis>
565
+			Default value is <quote>0</quote>.
566
+		</emphasis>
567
+		</para>
568
+		<example>
569
+		<title>Set <varname>separate_header_values</varname> parameter</title>
570
+		<programlisting format="linespecific">
571
+...
572
+modparam("topos", "separate_header_values", 1)
573
+...
546 574
 </programlisting>
547 575
 		</example>
548 576
 	</section>
... ...
@@ -81,6 +81,7 @@ static str _tps_db_url = str_init(DEFAULT_DB_URL);
81 81
 int _tps_param_mask_callid = 0;
82 82
 int _tps_sanity_checks = 0;
83 83
 int _tps_rr_update = 0;
84
+int _tps_separate_hv = 0;
84 85
 str _tps_storage = str_init("db");
85 86
 
86 87
 extern int _tps_branch_expire;
... ...
@@ -156,6 +157,7 @@ static param_export_t params[]={
156 157
 	{"db_url",		PARAM_STR, &_tps_db_url},
157 158
 	{"mask_callid",		PARAM_INT, &_tps_param_mask_callid},
158 159
 	{"sanity_checks",	PARAM_INT, &_tps_sanity_checks},
160
+	{"separate_header_values",	PARAM_INT, &_tps_separate_hv},
159 161
 	{"branch_expire",	PARAM_INT, &_tps_branch_expire},
160 162
 	{"dialog_expire",	PARAM_INT, &_tps_dialog_expire},
161 163
 	{"clean_interval",	PARAM_INT, &_tps_clean_interval},
... ...
@@ -50,6 +50,7 @@ extern int _tps_param_mask_callid;
50 50
 extern int _tps_contact_mode;
51 51
 extern str _tps_cparam_name;
52 52
 extern int _tps_rr_update;
53
+extern int _tps_separate_hv;
53 54
 
54 55
 extern str _tps_context_param;
55 56
 extern str _tps_context_value;
... ...
@@ -631,10 +632,53 @@ int tps_remove_name_headers(sip_msg_t *msg, str *hname)
631 632
 /**
632 633
  *
633 634
  */
635
+int tps_reappend_separate_header_values(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, str *hname)
636
+{
637
+
638
+        int i;
639
+        str sb;
640
+        char *p = NULL;
641
+
642
+        if(hbody==NULL || hbody->s==NULL || hbody->len<=0 || hbody->s[0]=='\0')
643
+            return 0;
644
+
645
+        sb.len = 1;
646
+        p = hbody->s;
647
+        for(i=0; i<hbody->len-1; i++) {
648
+            if(hbody->s[i]==',') {
649
+                if(sb.len>0) {
650
+                    sb.s = p;
651
+                    if(sb.s[sb.len-1]==',') sb.len--;
652
+                    if(tps_add_headers(msg, hname, &sb, 0)<0) {
653
+                        return -1;
654
+                    }
655
+                }
656
+                sb.len = 0;
657
+                p = hbody->s + i + 1;
658
+            }
659
+            sb.len++;
660
+        }
661
+
662
+
663
+        if(sb.len>0) {
664
+                sb.s = p;
665
+                if(sb.s[sb.len-1]==',') sb.len--;
666
+                if(tps_add_headers(msg, hname, &sb, 0)<0) {
667
+                    return -1;
668
+                }
669
+        }
670
+
671
+
672
+        return 0;
673
+}
674
+
634 675
 int tps_reappend_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
635 676
 {
636 677
 	str hname = str_init("Via");
637 678
 
679
+	if (TPS_SPLIT_VIA & _tps_separate_hv)
680
+		return tps_reappend_separate_header_values(msg, ptsd, hbody,&hname);
681
+
638 682
 	if(tps_add_headers(msg, &hname, hbody, 0)<0) {
639 683
 		return -1;
640 684
 	}
... ...
@@ -744,6 +788,9 @@ int tps_reappend_rr(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
744 788
 {
745 789
 	str hname = str_init("Record-Route");
746 790
 
791
+	if (TPS_SPLIT_RECORD_ROUTE & _tps_separate_hv)
792
+		return tps_reappend_separate_header_values(msg, ptsd, hbody,&hname);
793
+
747 794
 	if(tps_add_headers(msg, &hname, hbody, 0)<0) {
748 795
 		return -1;
749 796
 	}
... ...
@@ -798,6 +845,8 @@ int tps_reappend_route(sip_msg_t *msg, tps_data_t *ptsd, str *hbody, int rev)
798 845
 	trim_zeros_lr(&sb);
799 846
 	trim(&sb);
800 847
 	if(sb.len>0 && sb.s[sb.len-1]==',') sb.len--;
848
+	if (TPS_SPLIT_ROUTE & _tps_separate_hv)
849
+		return tps_reappend_separate_header_values(msg, ptsd, &sb,&hname);
801 850
 	if(tps_add_headers(msg, &hname, &sb, 0)<0) {
802 851
 		return -1;
803 852
 	}
... ...
@@ -31,6 +31,10 @@
31 31
 
32 32
 #include "../../core/parser/msg_parser.h"
33 33
 
34
+#define TPS_SPLIT_VIA            (1<<0)
35
+#define TPS_SPLIT_RECORD_ROUTE   (1<<1)
36
+#define TPS_SPLIT_ROUTE          (1<<2)
37
+
34 38
 int tps_update_hdr_replaces(sip_msg_t *msg);
35 39
 char* tps_msg_update(sip_msg_t *msg, unsigned int *olen);
36 40
 int tps_skip_msg(sip_msg_t *msg);