Browse code

*** empty log message ***

Bogdan-Andrei Iancu authored on 28/01/2002 20:31:50
Showing 5 changed files
... ...
@@ -11,7 +11,6 @@
11 11
 
12 12
 #define ROUND4(s) ((s)%4)?((s)+4)/4*4:(s)
13 13
 
14
-char*   translate_pointer( char* new_buf , char *org_buf , char* p);
15 14
 struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_body *org_via);
16 15
 struct hdr_field* header_cloner( struct sip_msg *new_msg , struct sip_msg *org_msg, struct hdr_field *hdr);
17 16
 
... ...
@@ -308,7 +307,7 @@ struct hdr_field* header_cloner( struct sip_msg *new_msg , struct sip_msg *org_m
308 308
 }
309 309
 
310 310
 
311
-
311
+ /*
312 312
 char*   translate_pointer( char* new_buf , char *org_buf , char* p)
313 313
 {
314 314
     if (!p)
... ...
@@ -316,7 +315,7 @@ char*   translate_pointer( char* new_buf , char *org_buf , char* p)
316 316
     else
317 317
 	return new_buf + (p-org_buf);
318 318
 }
319
-
319
+*/
320 320
 
321 321
 
322 322
 
... ...
@@ -532,7 +531,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
532 532
                    break;
533 533
       }
534 534
    }
535
-   /* length of the data lump structures */
535
+   /* length of the data lump structures
536 536
    if (org_msg->first_line.type==SIP_REQUEST)
537 537
       lump_chain = org_msg->add_rm;
538 538
    else
... ...
@@ -553,7 +552,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
553 553
          lump_tmp = lump_tmp->after;
554 554
       }
555 555
       lump_chain = lump_chain->next;
556
-   }
556
+   }  */
557 557
 
558 558
    p=(char *)sh_malloc(len);
559 559
    if (!p)
... ...
@@ -678,7 +677,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
678 678
 
679 679
    }
680 680
 
681
-   /* clonning data lump */
681
+   /* clonning data lump
682 682
    if (org_msg->first_line.type==SIP_REQUEST) {
683 683
       lump_chain = org_msg->add_rm;
684 684
       lump_anchor = &(new_msg->add_rm);
... ...
@@ -689,7 +688,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
689 689
    while (lump_chain)
690 690
    {
691 691
       lump_clone( (*lump_anchor) , lump_chain , p );
692
-      /*before list*/
692
+      /*before list/
693 693
       lump_tmp = lump_chain->before;
694 694
       lump_anchor2 = &((*lump_anchor)->before);
695 695
       while ( lump_tmp )
... ...
@@ -698,7 +697,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
698 698
          lump_anchor2 = &((*lump_anchor2)->before);
699 699
          lump_tmp = lump_tmp->before;
700 700
       }
701
-      /*after list*/
701
+      /*after list/
702 702
       lump_tmp = lump_chain->after;
703 703
       lump_anchor2 = &((*lump_anchor)->after);
704 704
       while ( lump_tmp )
... ...
@@ -709,7 +708,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
709 709
       }
710 710
       lump_anchor = &((*lump_anchor)->next);
711 711
       lump_chain = lump_chain->next;
712
-   }     
712
+   }           */
713 713
 
714 714
    return new_msg;
715 715
 }
... ...
@@ -13,15 +13,20 @@
13 13
 #define sip_msg_cloner(p_msg) \
14 14
     sip_msg_cloner_2(p_msg)
15 15
 
16
-#define sip_msg_free(_p_msg) shm_free( (_p_msg ))
17
-#define sip_msg_free_unsafe(_p_msg) shm_free_unsafe( (_p_msg) )
18
-/*    sip_msg_free_2(p_msg) */
16
+#define  sip_msg_free(_p_msg) shm_free( (_p_msg ))
17
+#define  sip_msg_free_unsafe(_p_msg) shm_free_unsafe( (_p_msg) )
18
+
19
+#define  translate_pointer( _new_buf , _org_buf , _p) \
20
+              ( (_p)?(_new_buf + (_p-_org_buf)):(0) )
19 21
 
20 22
 
21 23
 struct sip_msg*  sip_msg_cloner_1( struct sip_msg *org_msg );
22 24
 struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg );
23 25
 void                     sip_msg_free_1( struct sip_msg *org_msg );
24
-/* void                     sip_msg_free_2( struct sip_msg *org_msg ); */
26
+
27
+
28
+
29
+//char*   translate_pointer( char* new_buf , char *org_buf , char* p);
25 30
 
26 31
 
27 32
 #endif
... ...
@@ -194,7 +194,6 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
194 194
 	unsigned int  len;
195 195
 	char                          *buf, *shbuf;
196 196
 	struct retrans_buff  *rb;
197
-	struct cell                *T_tmp;
198 197
 
199 198
 	buf=NULL;
200 199
 	shbuf = NULL;
... ...
@@ -222,7 +221,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
222 222
 	 * when forwarding an ACK, this condition will be all the time false because
223 223
 	 * the forwarded INVITE is in the retransmission buffer */
224 224
 	if ( T->outbound_request[branch]==NULL )
225
-	{
225
+{
226 226
 		DBG("DEBUG: t_forward: first time forwarding\n");
227 227
 		/* special case : CANCEL */
228 228
 		if ( p_msg->REQ_METHOD==METHOD_CANCEL  )
... ...
@@ -230,12 +229,13 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
230 230
 			DBG("DEBUG: t_forward: it's CANCEL\n");
231 231
 			/* find original cancelled transaction; if found, use its
232 232
 			   next-hops; otherwise use those passed by script */
233
-			T->T_canceled = t_lookupOriginalT( hash_table , p_msg );
233
+			if (T->T_canceled==T_UNDEFINED)
234
+				T->T_canceled = t_lookupOriginalT( hash_table , p_msg );
234 235
 			/* if found */
235 236
 			if ( T->T_canceled!=T_NULL )
236 237
 			{
237 238
 				/* if in 1xx status, send to the same destination */
238
-				if ( (T_tmp->status/100)==1 )
239
+				if ( (T->T_canceled->status/100)==1 )
239 240
 				{
240 241
 					DBG("DEBUG: t_forward: it's CANCEL and I will send "
241 242
 						"to the same place where INVITE went\n");
... ...
@@ -11,12 +11,27 @@
11 11
 #include "hash_func.h"
12 12
 #include "t_funcs.h"
13 13
 #include "config.h"
14
+#include "sip_msg.h"
14 15
 
15 16
 
16 17
 #define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
17 18
 #define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s, p_msg->_hf->body.s, \
18
-		p_msg->_hf->body.len)==0)
19
-
19
+	p_msg->_hf->body.len)==0)
20
+#define EQ_REQ_URI_LEN\
21
+	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
22
+#define EQ_REQ_URI_STR\
23
+	( memcmp( t_msg->first_line.u.request.uri.s,\
24
+	translate_pointer(p_msg->orig,p_msg->buf, p_msg->first_line.u.request.uri.s),\
25
+	p_msg->first_line.u.request.uri.len)==0)
26
+#define EQ_VIA_LEN(_via)\
27
+	( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
28
+	(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
29
+
30
+#define EQ_VIA_STR(_via)\
31
+	( memcmp( t_msg->_via->name.s,\
32
+	 translate_pointer(p_msg->orig,p_msg->buf,p_msg->_via->name.s),\
33
+	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
34
+	)==0 )
20 35
 
21 36
 
22 37
 static int reverse_hex2int( char *c, int len )
... ...
@@ -78,7 +93,6 @@ int t_lookup_request( struct sip_msg* p_msg )
78 78
       /* stop processing */
79 79
       return 0;
80 80
    }
81
-
82 81
    /* start searching into the table */
83 82
    hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
84 83
    isACK = p_msg->REQ_METHOD==METHOD_ACK;
... ...
@@ -92,72 +106,47 @@ int t_lookup_request( struct sip_msg* p_msg )
92 92
    tmp_cell = 0;
93 93
    while( p_cell )
94 94
    {
95
-/*
96
-		int abba;
97
-
98
-		t_msg = p_cell->inbound_request;
99
-
100
-
101
-
102
-		if ( EQ_LEN(from) && EQ_LEN(callid) &&
103
-		  EQ_STR(callid) && EQ_STR(callid) &&
104
-		  /* we compare only numerical parts of CSEQ ...
105
-		     the method name should be the same as in first line
106
-		  memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s ,
107
-				get_cseq(p_msg)->number.len ) ==0 )
108
-		{
109
-			if (!isACK) {
110
-				if (t_msg->REQ_METHOD == p_msg->REQ_METHOD &&
111
-					EQ_LEN(to) && EQ_STR(to))
112
-					goto found;
113
-			} else { /* ACK
114
-				if (t_msg->REQ_METHOD == METHOD_INVITE  &&
115
-					//p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len &&
116
-            		//if ( /*tag memcmp( p_cell->tag->s , p_msg->tag->body.s ,
117
-					// p_msg->tag->body.len ) ==0 )
118
-					EQ_STR( to ) ) {
119
-					goto found;
120
-				}
121
-			} /* ACK
122
-		} /* common HFs equal
123
-*/
124 95
      t_msg = p_cell->inbound_request;
125 96
 
126 97
       /* is it the wanted transaction ? */
127 98
       if ( !isACK )
128 99
       { /* is not an ACK request */
129 100
          /* first only the length are checked */
130
-         if ( /*from length*/ EQ_LEN(from) )
131
-            if ( /*to length*/ EQ_LEN(to) )
132
-               if ( /*callid length*/ EQ_LEN(callid) )
133
-                  if ( /*cseq length*/ EQ_LEN(cseq) )
101
+         if ( EQ_LEN(callid) && EQ_LEN(cseq) )
102
+            if ( EQ_REQ_URI_LEN )
103
+                if ( EQ_VIA_LEN(via1) )
104
+                   if ( EQ_LEN(from) && EQ_LEN(to) )
134 105
                      /* so far the lengths are the same -> let's check the contents */
135
-                        if ( /*from*/ EQ_STR(from) )
136
-                           if ( /*to*/ EQ_STR(to) )
137
-                               if ( /*callid*/ EQ_STR(callid) )
138
-                                  if ( /*cseq*/ EQ_STR(cseq) )
139
-                                     { /* WE FOUND THE GOLDEN EGG !!!! */
140
-                                        goto found;
141
-                                     }
106
+                     if ( EQ_STR(callid) && EQ_STR(cseq) )
107
+                      if ( EQ_REQ_URI_STR )
108
+                          if ( EQ_VIA_STR(via1) )
109
+                             if ( EQ_STR(from) && EQ_STR(to) )
110
+                              { /* WE FOUND THE GOLDEN EGG !!!! */
111
+                                 goto found;
112
+                              }
142 113
       }
143 114
       else
144 115
       { /* it's a ACK request*/
145 116
          /* first only the length are checked */
146
-         if ( /*from length*/ EQ_LEN(from) )
147
-            //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
148
-               if ( /*callid length*/ EQ_LEN(callid) )
149
-                  if ( /*cseq_nr length*/ get_cseq(t_msg)->number.len == get_cseq(p_msg)->number.len )
150
-                      if ( /*cseq_method type*/ t_msg->first_line.u.request.method_value == METHOD_INVITE  )
151
-                         //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
117
+         if ( t_msg->first_line.u.request.method_value==METHOD_INVITE)
118
+            if ( /*callid length*/ EQ_LEN(callid) )
119
+               if ( get_cseq(t_msg)->number.len==get_cseq(p_msg)->number.len )
120
+                  if ( EQ_REQ_URI_LEN )
121
+                     if (/*VIA1 len*/ EQ_VIA_LEN(via1) )
122
+                       if ( /*from length*/ EQ_LEN(from) )
123
+                         //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
124
+                            //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
152 125
                             /* so far the lengths are the same -> let's check the contents */
153
-                            if ( /*from*/ EQ_STR(from) )
154
-                               //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
155
-                                  //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
156
-                                     if ( /*callid*/ !memcmp( t_msg->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
157
-                                        if ( /*cseq_nr*/ !memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
158
-                                           { /* WE FOUND THE GOLDEN EGG !!!! */
159
-                                              goto found;
160
-                                           }
126
+                                if ( /*callid*/ !memcmp( t_msg->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
127
+                                   if ( /*cseq_nr*/ !memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
128
+                                      if (/*URI len*/ EQ_REQ_URI_STR )
129
+                                         if (/*VIA1*/ EQ_VIA_STR(via1) )
130
+                                            if ( /*from*/ EQ_STR(from) )
131
+                                            //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
132
+                                              //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
133
+                                              { /* WE FOUND THE GOLDEN EGG !!!! */
134
+                                                 goto found;
135
+                                              }
161 136
       }
162 137
       /* next transaction */
163 138
       tmp_cell = p_cell;
... ...
@@ -188,9 +177,10 @@ found:
188 188
  */
189 189
 struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_msg )
190 190
 {
191
-   struct cell      *p_cell;
192
-   struct cell      *tmp_cell;
193
-   unsigned int  hash_index=0;
191
+   struct cell         *p_cell;
192
+   struct cell         *tmp_cell;
193
+   unsigned int       hash_index=0;
194
+   struct sip_msg	*t_msg;
194 195
 
195 196
    /* it's a CANCEL request for sure */
196 197
 
... ...
@@ -203,23 +193,26 @@ struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_
203 203
    tmp_cell = 0;
204 204
    while( p_cell )
205 205
    {
206
+     t_msg = p_cell->inbound_request;
207
+
206 208
       /* is it the wanted transaction ? */
207 209
       /* first only the length are checked */
208
-      if ( /*from length*/ p_cell->inbound_request->from->body.len == p_msg->from->body.len )
209
-         if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
210
-            //if ( /*tag length*/ (!p_cell->inbound_request->tag && !p_msg->tag) || (p_cell->inbound_request->tag && p_msg->tag && p_cell->inbound_request->tag->body.len == p_msg->tag->body.len) )
211
-               if ( /*callid length*/ p_cell->inbound_request->callid->body.len == p_msg->callid->body.len )
212
-                  if ( /*cseq_nr length*/ get_cseq(p_cell->inbound_request)->number.len == get_cseq(p_msg)->number.len )
213
-                      if ( /*cseq_method type*/ p_cell->inbound_request->REQ_METHOD!=METHOD_CANCEL )
214
-                         if ( /*req_uri length*/ p_cell->inbound_request->first_line.u.request.uri.len == p_msg->first_line.u.request.uri.len )
215
-                             /* so far the lengths are the same -> let's check the contents */
216
-                             if ( /*from*/ memcmp( p_cell->inbound_request->from->body.s , p_msg->from->body.s , p_msg->from->body.len )==0 )
217
-                                if ( /*to*/ memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)==0  )
218
-                                   //if ( /*tag*/ (!p_cell->inbound_request->tag && !p_msg->tag) || (p_cell->inbound_request->tag && p_msg->tag && memcmp( p_cell->inbound_request->tag->body.s , p_msg->tag->body.s , p_msg->tag->body.len )==0) )
219
-                                      if ( /*callid*/ memcmp( p_cell->inbound_request->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len )==0 )
220
-                                          if ( /*cseq_nr*/ memcmp( get_cseq(p_cell->inbound_request)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len )==0 )
221
-                                             if ( /*req_uri*/ memcmp( p_cell->inbound_request->first_line.u.request.uri.s , p_msg->first_line.u.request.uri.s , p_msg->first_line.u.request.uri.len )==0 )
222
-                                             { /* WE FOUND THE GOLDEN EGG !!!! */
210
+      if ( p_cell->inbound_request->REQ_METHOD!=METHOD_CANCEL )
211
+         if ( /*callid length*/ EQ_LEN(callid) )
212
+            if ( get_cseq(t_msg)->number.len==get_cseq(p_msg)->number.len )
213
+               if ( EQ_REQ_URI_LEN )
214
+                   if ( EQ_VIA_LEN(via1) )
215
+                  if ( EQ_LEN(from) && EQ_LEN(to) )
216
+                        //if ( /*tag length*/ (!p_cell->inbound_request->tag && !p_msg->tag) || (p_cell->inbound_request->tag && p_msg->tag && p_cell->inbound_request->tag->body.len == p_msg->tag->body.len) )
217
+                           /* so far the lengths are the same -> let's check the contents */
218
+                            if ( /*callid*/ EQ_STR(callid) )
219
+                               if ( /*cseq_nr*/ memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len )==0 )
220
+                                  if ( EQ_REQ_URI_STR )
221
+                                  if ( EQ_VIA_STR(via1) )
222
+                                  if ( EQ_STR(from) && EQ_STR(to) )
223
+                                            //if ( /*tag*/ (!p_cell->inbound_request->tag && !p_msg->tag) || (p_cell->inbound_request->tag && p_msg->tag && memcmp( p_cell->inbound_request->tag->body.s , p_msg->tag->body.s , p_msg->tag->body.len )==0) )
224
+                                              { /* WE FOUND THE GOLDEN EGG !!!! */
225
+                                                DBG("DEBUG: t_lookupOriginalT: canceled transaction found (%x)! \n",p_cell );
223 226
                                                 return p_cell;
224 227
                                              }
225 228
       /* next transaction */
... ...
@@ -228,6 +221,7 @@ struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_
228 228
    }
229 229
 
230 230
    /* no transaction found */
231
+   DBG("DEBUG: t_lookupOriginalT: no CANCEL maching found! \n" );
231 232
    return 0;
232 233
 }
233 234
 
... ...
@@ -28,7 +28,7 @@
28 28
 			(_mystr).len--; \
29 29
 	})
30 30
 
31
-/* converts a str to an u. short, returns the u. short and sets *err on 
31
+/* converts a str to an u. short, returns the u. short and sets *err on
32 32
  * error and if err!=null
33 33
  * */
34 34
 static inline unsigned short str2s(unsigned char* str, unsigned int len,
... ...
@@ -38,12 +38,12 @@ static inline unsigned short str2s(unsigned char* str, unsigned int len,
38 38
 	int i;
39 39
 	unsigned char *limit;
40 40
 	unsigned char *init;
41
-	
41
+
42 42
 	/*init*/
43 43
 	ret=i=0;
44 44
 	limit=str+len;
45 45
 	init=str;
46
-	
46
+
47 47
 	for(;str<limit ;str++){
48 48
 		if ( (*str <= '9' ) && (*str >= '0') ){
49 49
 				ret=ret*10+*str-'0';
... ...
@@ -56,7 +56,7 @@ static inline unsigned short str2s(unsigned char* str, unsigned int len,
56 56
 	}
57 57
 	if (err) *err=0;
58 58
 	return ret;
59
-	
59
+
60 60
 error_digits:
61 61
 	DBG("str2s: ERROR: too many letters in [%s]\n", init);
62 62
 	if (err) *err=1;
... ...
@@ -84,7 +84,7 @@ static inline unsigned int str2ip(unsigned char* str, unsigned int len,
84 84
 	ret=i=0;
85 85
 	limit=str+len;
86 86
 	init=str;
87
-	
87
+
88 88
 	for(;str<limit ;str++){
89 89
 		if (*str=='.'){
90 90
 				i++;
... ...
@@ -99,7 +99,7 @@ static inline unsigned int str2ip(unsigned char* str, unsigned int len,
99 99
 	}
100 100
 	if (err) *err=0;
101 101
 	return ret;
102
-	
102
+
103 103
 error_dots:
104 104
 	DBG("str2ip: ERROR: too many dots in [%s]\n", init);
105 105
 	if (err) *err=1;
... ...
@@ -112,8 +112,22 @@ error_char:
112 112
 
113 113
 
114 114
 
115
-/* faster memchr version */
115
+static inline int btostr( char *p,  unsigned char val)
116
+{
117
+	unsigned int a,b,i =0;
116 118
 
119
+	if ( (a=val/100)!=0 )
120
+		*(p+(i++)) = a+'0';         /*first digit*/
121
+	if ( (b=val%100/10)!=0 || a)
122
+		*(p+(i++)) = b+'0';        /*second digit*/
123
+	*(p+(i++)) = '0'+val%10;              /*third digit*/
124
+
125
+	return i;
126
+}
127
+
128
+
129
+
130
+/* faster memchr version */
117 131
 static inline char* q_memchr(char* p, int c, unsigned int size)
118 132
 {
119 133
 	char* end;