Browse code

topos: enable multiple Via values in separate via header

emvondo authored on 16/08/2022 18:24:59
Showing 2 changed files
... ...
@@ -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_via = 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_via",    PARAM_INT, &_tps_separate_via},
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_via;
53 54
 
54 55
 extern str _tps_context_param;
55 56
 extern str _tps_context_value;
... ...
@@ -631,10 +632,57 @@ int tps_remove_name_headers(sip_msg_t *msg, str *hname)
631 632
 /**
632 633
  *
633 634
  */
635
+int tps_reappend_via_separate_header(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
636
+{
637
+        str hname = str_init("Via");
638
+        int i;
639
+        int c;
640
+        str sb;
641
+        char *p = NULL;
642
+
643
+        if(hbody==NULL || hbody->s==NULL || hbody->len<=0 || hbody->s[0]=='\0')
644
+            return 0;
645
+
646
+
647
+        c = 0;
648
+        sb.len = 1;
649
+        p = hbody->s;
650
+        for(i=0; i<hbody->len-1; i++) {
651
+            if(hbody->s[i]==',') {
652
+                c = 1;
653
+                if(sb.len>0) {
654
+                    sb.s = p;
655
+                    if(sb.s[sb.len-1]==',') sb.len--;
656
+                    if(tps_add_headers(msg, &hname, &sb, 0)<0) {
657
+                        return -1;
658
+                    }
659
+                }
660
+                sb.len = 0;
661
+                p = hbody->s + i + 1;
662
+            }
663
+            sb.len++;
664
+        }
665
+
666
+        if(c==0 || c== 1) {
667
+            if(sb.len>0) {
668
+                sb.s = p;
669
+                if(sb.s[sb.len-1]==',') sb.len--;
670
+                if(tps_add_headers(msg, &hname, &sb, 0)<0) {
671
+                    return -1;
672
+                }
673
+            }
674
+        }
675
+
676
+        return 0;
677
+}
678
+
634 679
 int tps_reappend_via(sip_msg_t *msg, tps_data_t *ptsd, str *hbody)
635 680
 {
636 681
 	str hname = str_init("Via");
637 682
 
683
+    if (_tps_separate_via!= 0)
684
+        return tps_reappend_via_separate_header(msg, ptsd, hbody);
685
+
638 686
 	if(tps_add_headers(msg, &hname, hbody, 0)<0) {
639 687
 		return -1;
640 688
 	}