Browse Source

just debugging again :)

Bogdan-Andrei Iancu 24 years ago
parent
commit
f26c0cf020
6 changed files with 51 additions and 36 deletions
  1. 2 2
      modules/tm/h_table.c
  2. 4 0
      modules/tm/h_table.h
  3. 8 2
      modules/tm/sip_msg.c
  4. 23 21
      modules/tm/t_funcs.c
  5. 2 1
      modules/tm/test/kill_sem.sh
  6. 12 10
      msg_translator.c

+ 2 - 2
modules/tm/h_table.c

@@ -105,10 +105,10 @@ struct s_table* init_hash_table()
    for(  i=0 ; i<NR_OF_TIMER_LISTS ; i++ )
       init_timerlist_lock( hash_table, i );
 
-#ifdef THREAD
+//#ifdef THREAD
    /* starts the timer thread/ process */
    pthread_create( thread, NULL, timer_routine, hash_table );
-#endif
+//#endif
 
    return  hash_table;
 

+ 4 - 0
modules/tm/h_table.h

@@ -55,10 +55,14 @@ typedef struct retrans_buff
    socklen_t tolen;
    */
    size_t tolen;
+
    /* a message can be linked just to retransmission and FR list */
    struct timer_link tl[2];
    unsigned int timeout_ceiling;
    unsigned int timeout_value;
+
+   /*the cell that containes this retrans_buff*/
+   struct cell* my_T;
 }retrans_buff_type;
 
 

+ 8 - 2
modules/tm/sip_msg.c

@@ -274,9 +274,11 @@ void clean_hdr_field(struct hdr_field* hf)
       switch(hf->type)
       {
          case HDR_VIA:
+   DBG("DEBUG: sip_msg_free : via headers\n");
                free_via_list(hf->parsed);
              break;
          case HDR_CSEQ:
+   DBG("DEBUG: sip_msg_free : cseq headers\n");
                 sh_free(hf->parsed);
              break;
          default:
@@ -291,9 +293,11 @@ void clean_hdr_field(struct hdr_field* hf)
 void free_hdr_field_lst(struct hdr_field* hf)
 {
    struct hdr_field* foo;
+  DBG("DEBUG: free_hdr_field_lst : \n");
 
    while(hf)
     {
+      DBG("DEBUG: free_hdr_field_lst : \n");
        foo=hf;
        hf=hf->next;
        clean_hdr_field(foo);
@@ -311,8 +315,10 @@ void sip_msg_free(struct sip_msg* msg)
       sh_free(msg->new_uri.s);
       msg->new_uri.len=0;
    }
-   if (msg->headers)
-      free_hdr_field_lst(msg->headers);
+   DBG("DEBUG: sip_msg_free : headers\n");
+   //if (msg->headers)
+    //  free_hdr_field_lst(msg->headers);
+   DBG("DEBUG: sip_msg_free : lump\n");
    if (msg->add_rm)
       free_lump_list(msg->add_rm);
    if (msg->repl_add_rm)

+ 23 - 21
modules/tm/t_funcs.c

@@ -232,13 +232,6 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
       char               *buf;
 
       DBG("DEBUG: t_forward: first time forwarding\n");
-      /* allocates a new retrans_buff for the outbound request */
-      T->outbound_request[branch] = (struct retrans_buff*)sh_malloc( sizeof(struct retrans_buff) );
-      memset( T->outbound_request[branch] , 0 , sizeof (struct retrans_buff) );
-      T->outbound_request[branch]->tl[RETRASMISSIONS_LIST].payload = "cucu bau";// T->outbound_request[branch];
-      T->outbound_request[branch]->tl[FR_TIMER_LIST].payload =  T->outbound_request[branch];
-      DBG("DEBUG: t_forward: ************PAYLOAD=%p\n",T->outbound_request[branch]);
-      T->nr_of_outgoings = 1;
 
       /* special case : CANCEL */
       if ( p_msg->first_line.u.request.method_value==METHOD_CANCEL  )
@@ -265,10 +258,15 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
          }
       }/* end special case CANCEL*/
 
-      /* store */
+      /* allocates a new retrans_buff for the outbound request */
       DBG("DEBUG: t_forward: building outbound request\n");
-      T->outbound_request[branch]->tl[RETRASMISSIONS_LIST].payload = &(T->outbound_request[branch]);
+      T->outbound_request[branch] = (struct retrans_buff*)sh_malloc( sizeof(struct retrans_buff) );
+      memset( T->outbound_request[branch] , 0 , sizeof (struct retrans_buff) );
+      T->outbound_request[branch]->tl[RETRASMISSIONS_LIST].payload =  T->outbound_request[branch];
+      T->outbound_request[branch]->tl[FR_TIMER_LIST].payload =  T->outbound_request[branch];
       T->outbound_request[branch]->to.sin_family = AF_INET;
+      T->outbound_request[branch]->my_T =  T;
+      T->nr_of_outgoings = 1;
 
       if (add_branch_label( T, p_msg , branch )==-1) return -1;
       DBG("DEBUG: XXX: branch_size after call to add_branch_label: %d\n", p_msg->add_to_branch_len );
@@ -286,7 +284,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
 
       DBG("DEBUG: t_forward: starting timers (retrans and FR)\n");
       /*sets and starts the FINAL RESPONSE timer */
-      //add_to_tail_of_timer_list( hash_table , &(T->outbound_request[branch]->tl[FR_TIMER_LIST]) , FR_TIMER_LIST, FR_TIME_OUT );
+      add_to_tail_of_timer_list( hash_table , &(T->outbound_request[branch]->tl[FR_TIMER_LIST]) , FR_TIMER_LIST, FR_TIME_OUT );
 
       /* sets and starts the RETRANS timer */
       T->outbound_request[branch]->timeout_ceiling  = RETR_T2;
@@ -473,10 +471,15 @@ int t_put_on_wait(  struct sip_msg  *p_msg  )
 
    /* make double-sure we have finished everything */
    /* remove from  retranssmision  and  final response   list */
-   remove_from_timer_list( hash_table , &(T->inbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST );
-   remove_from_timer_list( hash_table , &(T->inbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST );
+   DBG("DEBUG: t_put_on_wait: remove inboud stuff from lists\n");
+   if ( T->inbound_response )
+   {
+      remove_from_timer_list( hash_table , &(T->inbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST );
+      remove_from_timer_list( hash_table , &(T->inbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST );
+   }
    for( i=0 ; i<T->nr_of_outgoings ; i++ )
    {
+      DBG("DEBUG: t_put_on_wait: remove outboud stuff[%d] from lists\n",i);
       remove_from_timer_list( hash_table , &(T->outbound_request[i]->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST );
       remove_from_timer_list( hash_table , &(T->outbound_request[i]->tl[FR_TIMER_LIST]) , FR_TIMER_LIST );
    }
@@ -521,7 +524,9 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
       unsigned int len;
       char * buf;
 
+         DBG("DEBUG: t_send_reply: before build\n");
       buf = build_res_buf_from_sip_req( code , text , T->inbound_request , &len );
+         DBG("DEBUG: t_send_reply: after build\n");
       if (!buf)
       {
          DBG("DEBUG: t_send_reply: response building failed\n");
@@ -1073,20 +1078,17 @@ void retransmission_handler( void *attr)
    struct retrans_buff* r_buf = (struct retrans_buff*)attr;
 
    /* the transaction is already removed from RETRANSMISSION_LIST by the timer */
-   DBG("DEBUG: retransmission_handler : payload received=%s\n",(char*)attr);
-   return;
+
    /* computs the new timeout. */
    if ( r_buf->timeout_value<r_buf->timeout_ceiling )
       r_buf->timeout_value *=2;
 
    /* retransmision */
    DBG("DEBUG: retransmission_handler : resending\n");
-   //udp_send( r_buf->buffer, r_buf->bufflen, (struct sockaddr*)&(r_buf->to) , sizeof(struct sockaddr_in) );
+   udp_send( r_buf->buffer, r_buf->bufflen, (struct sockaddr*)&(r_buf->to) , sizeof(struct sockaddr_in) );
 
    /* re-insert into RETRASMISSIONS_LIST */
-   DBG("DEBUG: retransmission_handler : before insert\n");
    insert_into_timer_list( hash_table , &(r_buf->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST , r_buf->timeout_value );
-   DBG("DEBUG: retransmission_handler : after insert\n");
 }
 
 
@@ -1094,14 +1096,14 @@ void retransmission_handler( void *attr)
 
 void final_response_handler( void *attr)
 {
-   struct cell *p_cell = (struct cell*)attr;
+   struct retrans_buff* r_buf = (struct retrans_buff*)attr;
 
    /* the transaction is already removed from FR_LIST by the timer */
    /* send a 408 */
    DBG("DEBUG: final_response_handler : sending 408\n");
-   t_send_reply( p_cell->inbound_request , 408 , "Request Timeout" );
+   t_send_reply( r_buf->my_T->inbound_request , 408 , "Request Timeout" );
    /* put it on WT_LIST - transaction is over */
-   t_put_on_wait(  p_cell->inbound_request );
+   t_put_on_wait(  r_buf->my_T->inbound_request );
 }
 
 
@@ -1161,7 +1163,7 @@ int add_branch_label( struct cell *trans, struct sip_msg *p_msg, int branch )
 		return -1;
 	} else {
 		p_msg->add_to_branch_len += n;
-		DBG("DEBUG: XXX branch label created now: %*s (%d)\n", p_msg->add_to_branch_len, 
+		DBG("DEBUG: XXX branch label created now: %*s (%d)\n", p_msg->add_to_branch_len,
 			p_msg->add_to_branch_s );
 		return 0;
 	}

+ 2 - 1
modules/tm/test/kill_sem.sh

@@ -1,3 +1,4 @@
 #!/bin/sh
 
-ipcrm sem `ipcs -s | awk '{ print $2; }'` 
+ipcrm sem `ipcs -s | awk '{ print $2; }'`
+ipcrm shm `ipcs -m | awk '{ print $2; }'` 

+ 12 - 10
msg_translator.c

@@ -516,12 +516,13 @@ error:
 
 char * build_res_buf_from_sip_req(	unsigned int code ,
 									char *text ,
-									struct sip_msg* msg, 
+									struct sip_msg* msg,
 									unsigned int *returned_len)
 {
 	char                    *buf=0, *p;
-	unsigned int       len,foo,i;
+	unsigned int       len,foo;
 	struct hdr_field  *hdr;
+	int                       i;
 
 	/*computes the lenght of the new response buffer*/
 	len = 0;
@@ -532,12 +533,13 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
 		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
 				hdr->type==HDR_CALLID || hdr->type==HDR_TO ||
 				hdr->type==HDR_CSEQ )
-			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) +1;
+			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) ;
 	/* end of message */
 	len += 1; /*new line*/
 
 	/*allocating mem*/
-	buf = (char*) malloc( len );
+	buf = (char*) malloc( len+1 );
+	p=buf;
 	if (!buf)
 	{
 		LOG(L_ERR, "ERROR: build_res_buf_from_sip_req: out of memory\n");
@@ -556,16 +558,16 @@ char * build_res_buf_from_sip_req(	unsigned int code ,
 	/* headers*/
 	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
 		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM ||
-				hdr->type==HDR_CALLID || hdr->type==HDR_TO ||
-				hdr->type==HDR_CSEQ )
+		hdr->type==HDR_CALLID || hdr->type==HDR_TO || hdr->type==HDR_CSEQ )
 		{
-			memcpy( p , hdr->name.s ,  ((hdr->body.s+hdr->body.len ) -
-						hdr->name.s ) );
-			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s );
-			*(p++) = '\n';
+			memcpy( p , msg->orig+(hdr->name.s-msg->buf) ,
+					((hdr->body.s+hdr->body.len ) -
+					hdr->name.s ) );
+			p += ((hdr->body.s+hdr->body.len ) - hdr->name.s );
 		}
 
 	*(p++) = '\n';
+	*(p++) = 0;
 	*returned_len=len;
 	return buf;
 error: