Bogdan-Andrei Iancu пре 24 година
родитељ
комит
3d2e8729a6
5 измењених фајлова са 111 додато и 99 уклоњено
  1. 8 9
      modules/tm/sip_msg.c
  2. 9 4
      modules/tm/sip_msg.h
  3. 4 4
      modules/tm/t_funcs.c
  4. 69 75
      modules/tm/t_lookup.c
  5. 21 7
      ut.h

+ 8 - 9
modules/tm/sip_msg.c

@@ -11,7 +11,6 @@
 
 #define ROUND4(s) ((s)%4)?((s)+4)/4*4:(s)
 
-char*   translate_pointer( char* new_buf , char *org_buf , char* p);
 struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_body *org_via);
 struct hdr_field* header_cloner( struct sip_msg *new_msg , struct sip_msg *org_msg, struct hdr_field *hdr);
 
@@ -308,7 +307,7 @@ struct hdr_field* header_cloner( struct sip_msg *new_msg , struct sip_msg *org_m
 }
 
 
-
+ /*
 char*   translate_pointer( char* new_buf , char *org_buf , char* p)
 {
     if (!p)
@@ -316,7 +315,7 @@ char*   translate_pointer( char* new_buf , char *org_buf , char* p)
     else
 	return new_buf + (p-org_buf);
 }
-
+*/
 
 
 
@@ -532,7 +531,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
                    break;
       }
    }
-   /* length of the data lump structures */
+   /* length of the data lump structures
    if (org_msg->first_line.type==SIP_REQUEST)
       lump_chain = org_msg->add_rm;
    else
@@ -553,7 +552,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
          lump_tmp = lump_tmp->after;
       }
       lump_chain = lump_chain->next;
-   }
+   }  */
 
    p=(char *)sh_malloc(len);
    if (!p)
@@ -678,7 +677,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
 
    }
 
-   /* clonning data lump */
+   /* clonning data lump
    if (org_msg->first_line.type==SIP_REQUEST) {
       lump_chain = org_msg->add_rm;
       lump_anchor = &(new_msg->add_rm);
@@ -689,7 +688,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
    while (lump_chain)
    {
       lump_clone( (*lump_anchor) , lump_chain , p );
-      /*before list*/
+      /*before list/
       lump_tmp = lump_chain->before;
       lump_anchor2 = &((*lump_anchor)->before);
       while ( lump_tmp )
@@ -698,7 +697,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
          lump_anchor2 = &((*lump_anchor2)->before);
          lump_tmp = lump_tmp->before;
       }
-      /*after list*/
+      /*after list/
       lump_tmp = lump_chain->after;
       lump_anchor2 = &((*lump_anchor)->after);
       while ( lump_tmp )
@@ -709,7 +708,7 @@ struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg )
       }
       lump_anchor = &((*lump_anchor)->next);
       lump_chain = lump_chain->next;
-   }     
+   }           */
 
    return new_msg;
 }

+ 9 - 4
modules/tm/sip_msg.h

@@ -13,15 +13,20 @@
 #define sip_msg_cloner(p_msg) \
     sip_msg_cloner_2(p_msg)
 
-#define sip_msg_free(_p_msg) shm_free( (_p_msg ))
-#define sip_msg_free_unsafe(_p_msg) shm_free_unsafe( (_p_msg) )
-/*    sip_msg_free_2(p_msg) */
+#define  sip_msg_free(_p_msg) shm_free( (_p_msg ))
+#define  sip_msg_free_unsafe(_p_msg) shm_free_unsafe( (_p_msg) )
+
+#define  translate_pointer( _new_buf , _org_buf , _p) \
+              ( (_p)?(_new_buf + (_p-_org_buf)):(0) )
 
 
 struct sip_msg*  sip_msg_cloner_1( struct sip_msg *org_msg );
 struct sip_msg*  sip_msg_cloner_2( struct sip_msg *org_msg );
 void                     sip_msg_free_1( struct sip_msg *org_msg );
-/* void                     sip_msg_free_2( struct sip_msg *org_msg ); */
+
+
+
+//char*   translate_pointer( char* new_buf , char *org_buf , char* p);
 
 
 #endif

+ 4 - 4
modules/tm/t_funcs.c

@@ -194,7 +194,6 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
 	unsigned int  len;
 	char                          *buf, *shbuf;
 	struct retrans_buff  *rb;
-	struct cell                *T_tmp;
 
 	buf=NULL;
 	shbuf = NULL;
@@ -222,7 +221,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
 	 * when forwarding an ACK, this condition will be all the time false because
 	 * the forwarded INVITE is in the retransmission buffer */
 	if ( T->outbound_request[branch]==NULL )
-	{
+{
 		DBG("DEBUG: t_forward: first time forwarding\n");
 		/* special case : CANCEL */
 		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
 			DBG("DEBUG: t_forward: it's CANCEL\n");
 			/* find original cancelled transaction; if found, use its
 			   next-hops; otherwise use those passed by script */
-			T->T_canceled = t_lookupOriginalT( hash_table , p_msg );
+			if (T->T_canceled==T_UNDEFINED)
+				T->T_canceled = t_lookupOriginalT( hash_table , p_msg );
 			/* if found */
 			if ( T->T_canceled!=T_NULL )
 			{
 				/* if in 1xx status, send to the same destination */
-				if ( (T_tmp->status/100)==1 )
+				if ( (T->T_canceled->status/100)==1 )
 				{
 					DBG("DEBUG: t_forward: it's CANCEL and I will send "
 						"to the same place where INVITE went\n");

+ 69 - 75
modules/tm/t_lookup.c

@@ -11,12 +11,27 @@
 #include "hash_func.h"
 #include "t_funcs.h"
 #include "config.h"
+#include "sip_msg.h"
 
 
 #define EQ_LEN(_hf) (t_msg->_hf->body.len==p_msg->_hf->body.len)
 #define EQ_STR(_hf) (memcmp(t_msg->_hf->body.s, p_msg->_hf->body.s, \
-		p_msg->_hf->body.len)==0)
-
+	p_msg->_hf->body.len)==0)
+#define EQ_REQ_URI_LEN\
+	(p_msg->first_line.u.request.uri.len==t_msg->first_line.u.request.uri.len)
+#define EQ_REQ_URI_STR\
+	( memcmp( t_msg->first_line.u.request.uri.s,\
+	translate_pointer(p_msg->orig,p_msg->buf, p_msg->first_line.u.request.uri.s),\
+	p_msg->first_line.u.request.uri.len)==0)
+#define EQ_VIA_LEN(_via)\
+	( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
+	(t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
+
+#define EQ_VIA_STR(_via)\
+	( memcmp( t_msg->_via->name.s,\
+	 translate_pointer(p_msg->orig,p_msg->buf,p_msg->_via->name.s),\
+	 (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
+	)==0 )
 
 
 static int reverse_hex2int( char *c, int len )
@@ -78,7 +93,6 @@ int t_lookup_request( struct sip_msg* p_msg )
       /* stop processing */
       return 0;
    }
-
    /* start searching into the table */
    hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
    isACK = p_msg->REQ_METHOD==METHOD_ACK;
@@ -92,72 +106,47 @@ int t_lookup_request( struct sip_msg* p_msg )
    tmp_cell = 0;
    while( p_cell )
    {
-/*
-		int abba;
-
-		t_msg = p_cell->inbound_request;
-
-
-
-		if ( EQ_LEN(from) && EQ_LEN(callid) &&
-		  EQ_STR(callid) && EQ_STR(callid) &&
-		  /* we compare only numerical parts of CSEQ ...
-		     the method name should be the same as in first line
-		  memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s ,
-				get_cseq(p_msg)->number.len ) ==0 )
-		{
-			if (!isACK) {
-				if (t_msg->REQ_METHOD == p_msg->REQ_METHOD &&
-					EQ_LEN(to) && EQ_STR(to))
-					goto found;
-			} else { /* ACK
-				if (t_msg->REQ_METHOD == METHOD_INVITE  &&
-					//p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len &&
-            		//if ( /*tag memcmp( p_cell->tag->s , p_msg->tag->body.s ,
-					// p_msg->tag->body.len ) ==0 )
-					EQ_STR( to ) ) {
-					goto found;
-				}
-			} /* ACK
-		} /* common HFs equal
-*/
      t_msg = p_cell->inbound_request;
 
       /* is it the wanted transaction ? */
       if ( !isACK )
       { /* is not an ACK request */
          /* first only the length are checked */
-         if ( /*from length*/ EQ_LEN(from) )
-            if ( /*to length*/ EQ_LEN(to) )
-               if ( /*callid length*/ EQ_LEN(callid) )
-                  if ( /*cseq length*/ EQ_LEN(cseq) )
+         if ( EQ_LEN(callid) && EQ_LEN(cseq) )
+            if ( EQ_REQ_URI_LEN )
+                if ( EQ_VIA_LEN(via1) )
+                   if ( EQ_LEN(from) && EQ_LEN(to) )
                      /* so far the lengths are the same -> let's check the contents */
-                        if ( /*from*/ EQ_STR(from) )
-                           if ( /*to*/ EQ_STR(to) )
-                               if ( /*callid*/ EQ_STR(callid) )
-                                  if ( /*cseq*/ EQ_STR(cseq) )
-                                     { /* WE FOUND THE GOLDEN EGG !!!! */
-                                        goto found;
-                                     }
+                     if ( EQ_STR(callid) && EQ_STR(cseq) )
+                      if ( EQ_REQ_URI_STR )
+                          if ( EQ_VIA_STR(via1) )
+                             if ( EQ_STR(from) && EQ_STR(to) )
+                              { /* WE FOUND THE GOLDEN EGG !!!! */
+                                 goto found;
+                              }
       }
       else
       { /* it's a ACK request*/
          /* first only the length are checked */
-         if ( /*from length*/ EQ_LEN(from) )
-            //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
-               if ( /*callid length*/ EQ_LEN(callid) )
-                  if ( /*cseq_nr length*/ get_cseq(t_msg)->number.len == get_cseq(p_msg)->number.len )
-                      if ( /*cseq_method type*/ t_msg->first_line.u.request.method_value == METHOD_INVITE  )
-                         //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
+         if ( t_msg->first_line.u.request.method_value==METHOD_INVITE)
+            if ( /*callid length*/ EQ_LEN(callid) )
+               if ( get_cseq(t_msg)->number.len==get_cseq(p_msg)->number.len )
+                  if ( EQ_REQ_URI_LEN )
+                     if (/*VIA1 len*/ EQ_VIA_LEN(via1) )
+                       if ( /*from length*/ EQ_LEN(from) )
+                         //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
+                            //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
                             /* so far the lengths are the same -> let's check the contents */
-                            if ( /*from*/ EQ_STR(from) )
-                               //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
-                                  //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
-                                     if ( /*callid*/ !memcmp( t_msg->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
-                                        if ( /*cseq_nr*/ !memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
-                                           { /* WE FOUND THE GOLDEN EGG !!!! */
-                                              goto found;
-                                           }
+                                if ( /*callid*/ !memcmp( t_msg->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
+                                   if ( /*cseq_nr*/ !memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
+                                      if (/*URI len*/ EQ_REQ_URI_STR )
+                                         if (/*VIA1*/ EQ_VIA_STR(via1) )
+                                            if ( /*from*/ EQ_STR(from) )
+                                            //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
+                                              //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
+                                              { /* WE FOUND THE GOLDEN EGG !!!! */
+                                                 goto found;
+                                              }
       }
       /* next transaction */
       tmp_cell = p_cell;
@@ -188,9 +177,10 @@ found:
  */
 struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_msg )
 {
-   struct cell      *p_cell;
-   struct cell      *tmp_cell;
-   unsigned int  hash_index=0;
+   struct cell         *p_cell;
+   struct cell         *tmp_cell;
+   unsigned int       hash_index=0;
+   struct sip_msg	*t_msg;
 
    /* it's a CANCEL request for sure */
 
@@ -203,23 +193,26 @@ struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_
    tmp_cell = 0;
    while( p_cell )
    {
+     t_msg = p_cell->inbound_request;
+
       /* is it the wanted transaction ? */
       /* first only the length are checked */
-      if ( /*from length*/ p_cell->inbound_request->from->body.len == p_msg->from->body.len )
-         if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
-            //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) )
-               if ( /*callid length*/ p_cell->inbound_request->callid->body.len == p_msg->callid->body.len )
-                  if ( /*cseq_nr length*/ get_cseq(p_cell->inbound_request)->number.len == get_cseq(p_msg)->number.len )
-                      if ( /*cseq_method type*/ p_cell->inbound_request->REQ_METHOD!=METHOD_CANCEL )
-                         if ( /*req_uri length*/ p_cell->inbound_request->first_line.u.request.uri.len == p_msg->first_line.u.request.uri.len )
-                             /* so far the lengths are the same -> let's check the contents */
-                             if ( /*from*/ memcmp( p_cell->inbound_request->from->body.s , p_msg->from->body.s , p_msg->from->body.len )==0 )
-                                if ( /*to*/ memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)==0  )
-                                   //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) )
-                                      if ( /*callid*/ memcmp( p_cell->inbound_request->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len )==0 )
-                                          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 )
-                                             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 )
-                                             { /* WE FOUND THE GOLDEN EGG !!!! */
+      if ( p_cell->inbound_request->REQ_METHOD!=METHOD_CANCEL )
+         if ( /*callid length*/ EQ_LEN(callid) )
+            if ( get_cseq(t_msg)->number.len==get_cseq(p_msg)->number.len )
+               if ( EQ_REQ_URI_LEN )
+                   if ( EQ_VIA_LEN(via1) )
+                  if ( EQ_LEN(from) && EQ_LEN(to) )
+                        //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) )
+                           /* so far the lengths are the same -> let's check the contents */
+                            if ( /*callid*/ EQ_STR(callid) )
+                               if ( /*cseq_nr*/ memcmp( get_cseq(t_msg)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len )==0 )
+                                  if ( EQ_REQ_URI_STR )
+                                  if ( EQ_VIA_STR(via1) )
+                                  if ( EQ_STR(from) && EQ_STR(to) )
+                                            //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) )
+                                              { /* WE FOUND THE GOLDEN EGG !!!! */
+                                                DBG("DEBUG: t_lookupOriginalT: canceled transaction found (%x)! \n",p_cell );
                                                 return p_cell;
                                              }
       /* next transaction */
@@ -228,6 +221,7 @@ struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_
    }
 
    /* no transaction found */
+   DBG("DEBUG: t_lookupOriginalT: no CANCEL maching found! \n" );
    return 0;
 }
 

+ 21 - 7
ut.h

@@ -28,7 +28,7 @@
 			(_mystr).len--; \
 	})
 
-/* converts a str to an u. short, returns the u. short and sets *err on 
+/* converts a str to an u. short, returns the u. short and sets *err on
  * error and if err!=null
  * */
 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,
 	int i;
 	unsigned char *limit;
 	unsigned char *init;
-	
+
 	/*init*/
 	ret=i=0;
 	limit=str+len;
 	init=str;
-	
+
 	for(;str<limit ;str++){
 		if ( (*str <= '9' ) && (*str >= '0') ){
 				ret=ret*10+*str-'0';
@@ -56,7 +56,7 @@ static inline unsigned short str2s(unsigned char* str, unsigned int len,
 	}
 	if (err) *err=0;
 	return ret;
-	
+
 error_digits:
 	DBG("str2s: ERROR: too many letters in [%s]\n", init);
 	if (err) *err=1;
@@ -84,7 +84,7 @@ static inline unsigned int str2ip(unsigned char* str, unsigned int len,
 	ret=i=0;
 	limit=str+len;
 	init=str;
-	
+
 	for(;str<limit ;str++){
 		if (*str=='.'){
 				i++;
@@ -99,7 +99,7 @@ static inline unsigned int str2ip(unsigned char* str, unsigned int len,
 	}
 	if (err) *err=0;
 	return ret;
-	
+
 error_dots:
 	DBG("str2ip: ERROR: too many dots in [%s]\n", init);
 	if (err) *err=1;
@@ -112,8 +112,22 @@ error_char:
 
 
 
-/* faster memchr version */
+static inline int btostr( char *p,  unsigned char val)
+{
+	unsigned int a,b,i =0;
 
+	if ( (a=val/100)!=0 )
+		*(p+(i++)) = a+'0';         /*first digit*/
+	if ( (b=val%100/10)!=0 || a)
+		*(p+(i++)) = b+'0';        /*second digit*/
+	*(p+(i++)) = '0'+val%10;              /*third digit*/
+
+	return i;
+}
+
+
+
+/* faster memchr version */
 static inline char* q_memchr(char* p, int c, unsigned int size)
 {
 	char* end;