Browse code

tid/branch generation a la RFC 3261 introduced; hash==0 oddity fixed

Jiri Kuthan authored on 21/10/2002 19:21:50
Showing 8 changed files
... ...
@@ -142,4 +142,11 @@
142 142
 #define FIFO_REPLY_RETRIES	4
143 143
 #define FIFO_REPLY_WAIT		80000
144 144
 
145
+/* magic cookie for transaction matching as defined in RFC3261 */
146
+#define MCOOKIE "z9hG4bK"
147
+#define MCOOKIE_LEN (sizeof(MCOOKIE)-1)
148
+/* Maximum length of values appended to Via-branch parameter */
149
+#define MAX_BRANCH_PARAM_LEN  (MCOOKIE_LEN+48)
150
+
151
+
145 152
 #endif
... ...
@@ -94,8 +94,4 @@
94 94
 */
95 95
 #undef ACK_FORKING_HACK
96 96
 
97
-/* magic cookie for transaction matching as defined in RFC3261 */
98
-#define MCOOKIE "z9hG4bK"
99
-#define MCOOKIE_LEN (sizeof(MCOOKIE)-1)
100
-
101 97
 #endif
... ...
@@ -65,7 +65,9 @@ char *print_uac_request( struct cell *t, struct sip_msg *i_req,
65 65
 	shbuf=0;
66 66
 
67 67
 	/* ... we calculate branch ... */	
68
-	if (!t_setbranch( t, i_req, branch )) {
68
+	if (!t_calc_branch(t, branch, i_req->add_to_branch_s,
69
+			&i_req->add_to_branch_len ))
70
+	{
69 71
 		LOG(L_ERR, "ERROR: print_uac_request: branch computation failed\n");
70 72
 		goto error01;
71 73
 	}
... ...
@@ -507,8 +507,20 @@ int t_reply_matching( struct sip_msg *p_msg , int *p_branch )
507 507
 	if (!(p_msg->via1 && p_msg->via1->branch && p_msg->via1->branch->value.s))
508 508
 		goto nomatch2;
509 509
 
510
+	/* we do RFC 3261 tid matching and want to see first if there is
511
+	 * magic cookie in branch */
512
+	if (p_msg->via1->branch->value.len<=MCOOKIE_LEN)
513
+		goto nomatch2;
514
+	if (memcmp(p_msg->via1->branch->value.s, MCOOKIE, MCOOKIE_LEN)!=0)
515
+		goto nomatch2;
516
+
517
+	p=p_msg->via1->branch->value.s+MCOOKIE_LEN;
518
+	scan_space=p_msg->via1->branch->value.len-MCOOKIE_LEN;
519
+
520
+#ifdef OBSOLETED
510 521
 	p=p_msg->via1->branch->value.s;
511 522
 	scan_space=p_msg->via1->branch->value.len;
523
+#endif
512 524
 
513 525
 
514 526
 	/* hash_id */
... ...
@@ -329,8 +329,3 @@ int t_calc_branch(struct cell *t,
329 329
 			b, branch, branch_len );
330 330
 }
331 331
 
332
-int t_setbranch( struct cell *t, struct sip_msg *msg, int b )
333
-{
334
-	return t_calc_branch( t, b, 
335
-		msg->add_to_branch_s, &msg->add_to_branch_len );
336
-}
... ...
@@ -80,7 +80,6 @@ char *build_uac_request(  str msg_type, str dst, str from,
80 80
 
81 81
 int t_calc_branch(struct cell *t,
82 82
 	int b, char *branch, int *branch_len);
83
-int t_setbranch( struct cell *t, struct sip_msg *msg, int b );
84 83
 
85 84
 
86 85
 #endif
... ...
@@ -786,6 +786,7 @@ int branch_builder( unsigned int hash_index,
786 786
 	char *begin;
787 787
 	int size;
788 788
 
789
+#ifdef _OBSOLETED
789 790
 	/* no hash_id --- whoever called me wants to have
790 791
 	   very simple branch_id
791 792
 	*/
... ...
@@ -794,11 +795,16 @@ int branch_builder( unsigned int hash_index,
794 794
 		*len=1;
795 795
 		return *len;
796 796
 	}
797
+#endif
797 798
 
798 799
 	/* hash id provided ... start with it */
799 800
 	size=MAX_BRANCH_PARAM_LEN;
800 801
 	begin=branch_str;
801 802
 	*len=0;
803
+
804
+	memcpy(begin, MCOOKIE, MCOOKIE_LEN );
805
+	size-=MCOOKIE_LEN;begin+=MCOOKIE_LEN;
806
+
802 807
 	if (int2reverse_hex( &begin, &size, hash_index)==-1)
803 808
 		return 0;
804 809
 
... ...
@@ -34,6 +34,7 @@
34 34
 #include "../flags.h"
35 35
 #include "../ip_addr.h"
36 36
 #include "../md5utils.h"
37
+#include "../config.h"
37 38
 #include "parse_def.h"
38 39
 #include "parse_cseq.h"
39 40
 #include "parse_to.h"
... ...
@@ -42,14 +43,6 @@
42 42
 #include "hf.h"
43 43
 
44 44
 
45
-/* Maximum length of values appended to Via-branch parameter */
46
-#ifdef USE_SYNONIM
47
-#define MAX_BRANCH_PARAM_LEN  22
48
-#else
49
-#define MAX_BRANCH_PARAM_LEN  48
50
-#endif
51
-
52
-
53 45
 /* convenience short-cut macros */
54 46
 #define REQ_LINE(_msg) ((_msg)->first_line.u.request)
55 47
 #define REQ_METHOD first_line.u.request.method_value