Bogdan-Andrei Iancu 23 лет назад
Родитель
Сommit
af64f4fbdc
6 измененных файлов с 118 добавлено и 100 удалено
  1. 3 0
      config.h
  2. 4 4
      modules/tm/h_table.c
  3. 8 12
      modules/tm/t_funcs.c
  4. 92 81
      modules/tm/t_lookup.c
  5. 3 3
      msg_parser.c
  6. 8 0
      msg_translator.c

+ 3 - 0
config.h

@@ -33,6 +33,9 @@
 #define MY_VIA "Via: SIP/2.0/UDP "
 #define MY_VIA_LEN 17
 
+#define CONTENT_LEN "Content-Length: 0"
+#define CONTENT_LEN_LEN 17
+
 #define MY_BRANCH ";branch=0"
 #define MY_BRANCH_LEN 9
 

+ 4 - 4
modules/tm/h_table.c

@@ -150,10 +150,10 @@ struct cell*  build_cell( struct sip_msg* p_msg )
    /* filling with 0 */
    memset( new_cell, 0, sizeof( struct cell ) );
 
-	new_cell->outbound_response.retr_timer.tg=TG_RT;
-	new_cell->outbound_response.fr_timer.tg=TG_FR;
-	new_cell->wait_tl.tg=TG_WT;
-	new_cell->dele_tl.tg=TG_DEL;
+   new_cell->outbound_response.retr_timer.tg=TG_RT;
+   new_cell->outbound_response.fr_timer.tg=TG_FR;
+   new_cell->wait_tl.tg=TG_WT;
+   new_cell->dele_tl.tg=TG_DEL;
 
    /* hash index of the entry */
    /* new_cell->hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ); */

+ 8 - 12
modules/tm/t_funcs.c

@@ -67,26 +67,22 @@ static inline void reset_retr_timers( struct s_table *h_table,
 	/* lock the first timer list of the FR group -- all other
 	   lists share the same lock
 	*/
-	lock(  hash_table->timers[FR_TIMER_LIST].mutex );
-	/* reset_timer( h_table, &(p_cell->outbound_response.retr_timer)); */
+	lock(  hash_table->timers[RT_T1_TO_1].mutex );
 	remove_timer_unsafe( & p_cell->outbound_response.retr_timer );
-	for( ijk=0 ; ijk<(p_cell)->nr_of_outgoings ; ijk++ )  { 
+	for( ijk=0 ; ijk<(p_cell)->nr_of_outgoings ; ijk++ )  {
 			if ( rb = p_cell->outbound_request[ijk] ) {
-				/* reset_timer(h_table, &(rb->retr_timer)); */
 				remove_timer_unsafe( & rb->retr_timer );
 			}
-		} 
-	unlock(  hash_table->timers[FR_TIMER_LIST].mutex );
-	lock(  hash_table->timers[RT_T1_TO_1].mutex );
-	/* reset_timer( h_table, &(p_cell->outbound_response.fr_timer)); */
+		}
+	unlock(  hash_table->timers[RT_T1_TO_1].mutex );
+	lock(  hash_table->timers[FR_TIMER_LIST].mutex );
 	remove_timer_unsafe( & p_cell->outbound_response.fr_timer );
-	for( ijk=0 ; ijk<(p_cell)->nr_of_outgoings ; ijk++ )  { 
+	for( ijk=0 ; ijk<(p_cell)->nr_of_outgoings ; ijk++ )  {
 			if ( rb = p_cell->outbound_request[ijk] ) {
-				/* reset_timer(h_table, &(rb->fr_timer)); */
 				remove_timer_unsafe( & rb->fr_timer );
 			}
-		} 
-	unlock(  hash_table->timers[RT_T1_TO_1].mutex );
+		}
+	unlock(  hash_table->timers[FR_TIMER_LIST].mutex );
 	DBG("DEBUG:stop_RETR_and_FR_timers : stop\n");
 }
 

+ 92 - 81
modules/tm/t_lookup.c

@@ -80,94 +80,105 @@ inline static int int2reverse_hex( char **c, int *size, int nr )
  */
 int t_lookup_request( struct sip_msg* p_msg , int leave_new_locked )
 {
-   struct cell      *p_cell;
-   struct cell      *tmp_cell;
-   /* unsigned int  hash_index=0; */
-   unsigned int  isACK;
-   struct sip_msg	*t_msg;
+	struct cell         *p_cell;
+	struct cell         *tmp_cell;
+	unsigned int       isACK;
+	struct sip_msg  *t_msg;
 
-   /* parse all*/
-   if (check_transaction_quadruple(p_msg)==0)
-   {
-      LOG(L_ERR, "ERROR: TM module: t_lookup_request: too few headers\n");
-      T=0;
-      /* stop processing */
-      return 0;
-   }
-   /* start searching into the table */
-   p_msg->hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
-   isACK = p_msg->REQ_METHOD==METHOD_ACK;
-   DBG("t_lookup_request: start searching:  hash=%d, isACK=%d\n",p_msg->hash_index,isACK);
+	/* parse all*/
+	if (check_transaction_quadruple(p_msg)==0)
+	{
+		LOG(L_ERR, "ERROR: TM module: t_lookup_request: too few headers\n");
+		T=0;
+		/* stop processing */
+		return 0;
+	}
 
-   /* lock the hole entry*/
-   lock( hash_table->entrys[p_msg->hash_index].mutex );
+	/* start searching into the table */
+	p_msg->hash_index=hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
+	isACK = p_msg->REQ_METHOD==METHOD_ACK;
+	DBG("t_lookup_request: start searching: hash=%d, isACK=%d\n",
+		p_msg->hash_index,isACK);
 
-   /* all the transactions from the entry are compared */
-   p_cell     = hash_table->entrys[p_msg->hash_index].first_cell;
-   tmp_cell = 0;
-   while( p_cell )
-   {
-     t_msg = p_cell->inbound_request;
+	/* lock the hole entry*/
+	lock( hash_table->entrys[p_msg->hash_index].mutex );
 
-      /* is it the wanted transaction ? */
-      if ( !isACK )
-      { /* is not an ACK request */
-         /* first only the length are checked */
-         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 ( 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 ( 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 (get_to(t_msg)->body.len==get_to(p_msg)->body.len)
-                            if (p_cell->tag->len==get_to(p_msg)->tag_value.len )
-                            /* so far the lengths are the same -> let's check the contents */
-                                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 (!memcmp(get_to(t_msg)->body.s,get_to(p_msg)->body.s,get_to(t_msg)->body.len))
-                                                 if (!memcmp(p_cell->tag->s,get_to(p_msg)->tag_value.s , p_cell->tag->len))
-                                              { /* WE FOUND THE GOLDEN EGG !!!! */
-                                                 goto found;
-                                              }
-      }
-      /* next transaction */
-      tmp_cell = p_cell;
-      p_cell = p_cell->next_cell;
-   } /* synonym loop */
+	/* all the transactions from the entry are compared */
+	p_cell     = hash_table->entrys[p_msg->hash_index].first_cell;
+	tmp_cell = 0;
+	while( p_cell )
+	{
+		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 ( /*callied*/EQ_LEN(callid) && /*cseq*/EQ_LEN(cseq)
+			&& /*req URI*/EQ_REQ_URI_LEN && /*VIA*/EQ_VIA_LEN(via1)
+			&& /*from*/EQ_LEN(from) && /*to*/EQ_LEN(to)  )
+				/* so far the lengths are the same
+				-> let's check the contents */
+				if ( /*callid*/EQ_STR(callid) && /*cseq*/EQ_STR(cseq)
+				&& /*req URI*/EQ_REQ_URI_STR && /*VIA*/EQ_VIA_STR(via1)
+				&& /*from*/EQ_STR(from) && /*to*/EQ_STR(to) )
+					{ /* WE FOUND THE GOLDEN EGG !!!! */
+						goto found;
+					}
+		}
+		else
+		{ /* it's a ACK request*/
+			/* first only the length are checked */
+			if ( t_msg->first_line.u.request.method_value==METHOD_INVITE
+			&& /*callid length*/ EQ_LEN(callid)
+			&& get_cseq(t_msg)->number.len==get_cseq(p_msg)->number.len
+			&& /*from length*/ EQ_LEN(from)
+			&& /*to body*/get_to(t_msg)->body.len==get_to(p_msg)->body.len
+			&& printf("------>0.4   %d (%d,%d)\n",p_cell->status,p_cell->tag->len,get_to(p_msg)->tag_value.len)
+			&& /*to tag*/p_cell->tag->len==get_to(p_msg)->tag_value.len
+			&& printf("------>0.5   %d\n",p_cell->status)
+			&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_LEN )
+			&& printf("------>0.6   %d\n",p_cell->status)
+			&& /*VIA*/(p_cell->status==200 || EQ_VIA_LEN(via1))
+			&& printf("------>2   %d\n",p_cell->status)  )
+				/* so far the lengths are the same
+				-> let's check the contents */
+				if (/*callid*/!memcmp( t_msg->callid->body.s,
+					p_msg->callid->body.s,p_msg->callid->body.len)
+				&& /*cseq nr*/!memcmp(get_cseq(t_msg)->number.s,
+					get_cseq(p_msg)->number.s,get_cseq(p_msg)->number.len)
+				&& /*from*/EQ_STR(from)
+				&& /*to body*/!memcmp(get_to(t_msg)->body.s,
+					get_to(p_msg)->body.s,get_to(t_msg)->body.len)
+				&& /*to tag*/!memcmp(p_cell->tag->s,
+					get_to(p_msg)->tag_value.s,p_cell->tag->len)
+				&& /*req URI*/(p_cell->status==200 || EQ_REQ_URI_STR||
+					printf("------>1   %d\n",p_cell->status) )
+				&& /*VAI*/(p_cell->status==200 ||EQ_VIA_STR(via1) ||
+						printf("------>2   %d\n",p_cell->status) ) )
+					{ /* WE FOUND THE GOLDEN EGG !!!! */
+						goto found;
+					}
+		}
+		/* next transaction */
+		tmp_cell = p_cell;
+		p_cell = p_cell->next_cell;
+	} /* synonym loop */
 
-   /* no transaction found */
-   T = 0;
-   if (!leave_new_locked) unlock( hash_table->entrys[p_msg->hash_index].mutex );
-   DBG("DEBUG: t_lookup_request: no transaction found\n");
-   return -1;
+	/* no transaction found */
+	T = 0;
+	if (!leave_new_locked)
+		unlock( hash_table->entrys[p_msg->hash_index].mutex );
+	DBG("DEBUG: t_lookup_request: no transaction found\n");
+	return -1;
 
 found:
-   T=p_cell;
-   T_REF( T );
-   DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_lookup_request: "
-                   "transaction found ( T=%p , ref=%x)\n",T,T->ref_bitmap);
-   unlock( hash_table->entrys[p_msg->hash_index].mutex );
-   return 1;
+	T=p_cell;
+	T_REF( T );
+	DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_lookup_request: "
+		"transaction found ( T=%p , ref=%x)\n",T,T->ref_bitmap);
+	unlock( hash_table->entrys[p_msg->hash_index].mutex );
+	return 1;
 }
 
 

+ 3 - 3
msg_parser.c

@@ -36,7 +36,7 @@ char* parse_first_line(char* buffer, unsigned int len, struct msg_start * fl)
 	/* int l; */
 	char* end;
 	char s1,s2,s3;
-	
+
 	/* grammar:
 		request  =  method SP uri SP version CRLF
 		response =  version SP status  SP reason  CRLF
@@ -262,8 +262,8 @@ char* get_hdr_field(char* buf, char* end, struct hdr_field* hdr)
 			}
 			hdr->parsed=to_b;
 			hdr->body.len=tmp-hdr->body.s;
-			DBG("get_hdr_field: to <%s>: <%s> %c [%d]\n",
-				hdr->name.s, to_b->body.s,*tmp,hdr->body.len);
+			DBG("get_hdr_field: to <%s>: <%s>=[%d] %c [%d]\n",
+				hdr->name.s, to_b->body.s,to_b->body.len,*tmp,hdr->body.len);
 			break;
 		case HDR_FROM:
 		case HDR_CALLID:

+ 8 - 0
msg_translator.c

@@ -570,6 +570,8 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
 				hdr->type==HDR_CSEQ )
 			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) + CRLF_LEN;
 #endif
+	/*content length header*/
+	len +=CONTENT_LEN_LEN + CRLF_LEN;
 	/* end of message */
 	len += CRLF_LEN; /*new line*/
 
@@ -625,6 +627,12 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
 		}
 #endif
 
+	/* content length header*/
+	memcpy( p, CONTENT_LEN , CONTENT_LEN_LEN );
+	p+=CONTENT_LEN_LEN;
+	memcpy( p, CRLF, CRLF_LEN );
+	p+=CRLF_LEN;
+	/*end of message*/
 	memcpy( p, CRLF, CRLF_LEN );
 	p+=CRLF_LEN;
 	*(p++) = 0;