Просмотр исходного кода

performance and memory leak fixes

Jiri Kuthan 23 лет назад
Родитель
Сommit
aa7ffe9011
3 измененных файлов с 23 добавлено и 369 удалено
  1. 0 276
      modules/tm/t_funcs.c
  2. 23 11
      modules/tm/t_reply.c
  3. 0 82
      modules/tm/tm.c

+ 0 - 276
modules/tm/t_funcs.c

@@ -203,282 +203,6 @@ int t_add_transaction( struct sip_msg* p_msg )
 
 
 
-#ifdef _OBSOLETED_TM
-/* function returns:
- *       1 - forward successfull
- *      -1 - error during forward
- */
-int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int dest_port_param )
-{
-	unsigned int  dest_ip     = dest_ip_param;
-	unsigned int  dest_port  = dest_port_param;
-	int           branch;
-	unsigned int  len;
-	char         *buf, *shbuf;
-	struct retrans_buff  *rb;
-	struct cell  *T_source = T;
-
-	buf=NULL;
-	shbuf = NULL;
-	branch = 0;	/* we don't do any forking right now */
-
-	/*if it's an ACK and the status is not final or is final, but error the
-	ACK is not forwarded*/
-	if ( p_msg->REQ_METHOD==METHOD_ACK  && (T->status/100)!=2 ) {
-		DBG("DEBUG: t_forward: local ACK; don't forward\n");
-		return 1;
-	}
-
-	/* if it's forwarded for the first time, else the request is retransmited
-	from the transaction buffer 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  )
-		{
-			DBG("DEBUG: t_forward: it's CANCEL\n");
-			if (T->outgoing_cancel[branch]!=NO_CANCEL)
-			{
-				DBG("DEBUG: t_forward: CANCEL already send on this branch ->"
-					" dropping current CANCEL!!\n");
-				return 1;
-			}
-			/* find original cancelled transaction; if found, use its
-			   next-hops; otherwise use those passed by script */
-			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->T_canceled->status/100)==1 )
-				{
-					DBG("DEBUG: t_forward: it's CANCEL and I will send "
-						"to the same place where INVITE went\n");
-					dest_ip=T->T_canceled->outbound_request[branch]->
-						to.sin_addr.s_addr;
-					dest_port = T->T_canceled->outbound_request[branch]->
-						to.sin_port;
-#ifdef USE_SYNONIM
-					T_source = T->T_canceled;
-					T->label  = T->T_canceled->label;
-#endif
-				} else { /* transaction exists, but nothing to cancel */
-					DBG("DEBUG: t_forward: it's CANCEL but "
-						"I have nothing to cancel here\n");
-					/* continue forwarding CANCEL as a stand-alone transaction */
-				}
-			} else { /* transaction does not exists  */
-				DBG("DEBUG: t_forward: canceled request not found! "
-					"nothing to CANCEL\n");
-			}
-		}/* end special case CANCEL*/
-
-		if ( add_branch_label( T_source, T->inbound_request , branch )==-1)
-			goto error;
-		if ( add_branch_label( T_source, p_msg , branch )==-1)
-			goto error;
-		if ( !(buf = build_req_buf_from_sip_req  ( p_msg, &len)))
-			goto error;
-
-		/* allocates a new retrans_buff for the outbound request */
-		DBG("DEBUG: t_forward: building outbound request\n");
-		shm_lock();
-		T->outbound_request[branch] = rb = (struct retrans_buff*)
-			shm_malloc_unsafe(sizeof(struct retrans_buff));
-		if (!rb)
-		{
-			LOG(L_ERR, "ERROR: t_forward: out of shmem\n");
-			shm_unlock();
-			goto error;
-		}
-		shbuf = (char *) shm_malloc_unsafe( len );
-		if (!shbuf)
-		{
-			LOG(L_ERR, "ERROR: t_forward: out of shmem buffer\n");
-			shm_unlock();
-			goto error;
-		}
-		shm_unlock();
-		memset( rb , 0 , sizeof (struct retrans_buff) );
-		rb->retr_timer.tg=TG_RT;
-		rb->fr_timer.tg=TG_FR;
-		rb->retr_buffer = shbuf;
-		rb->retr_timer.payload =  rb;
-		rb->fr_timer.payload =  rb;
-		rb->to.sin_family = AF_INET;
-		rb->my_T =  T;
-		rb->branch = branch;
-		T->nr_of_outgoings = 1;
-		rb->bufflen = len ;
-		memcpy( rb->retr_buffer , buf , len );
-		free( buf ) ; buf=NULL;
-
-		DBG("DEBUG: t_forward: starting timers (retrans and FR) %d\n",
-			get_ticks() );
-		/*sets and starts the FINAL RESPONSE timer */
-		set_timer( hash_table, &(rb->fr_timer), FR_TIMER_LIST );
-
-		/* sets and starts the RETRANS timer */
-		rb->retr_list = RT_T1_TO_1;
-		set_timer( hash_table, &(rb->retr_timer), RT_T1_TO_1 );
-	}/* end for the first time */
-
-	/* if we are forwarding an ACK*/
-	if (  p_msg->REQ_METHOD==METHOD_ACK &&
-		T->relaied_reply_branch>=0 &&
-		T->relaied_reply_branch<=T->nr_of_outgoings)
-	{
-		DBG("DEBUG: t_forward: forwarding ACK [%d]\n",T->relaied_reply_branch);
-		t_build_and_send_ACK( T, branch ,
-			T->inbound_response[T->relaied_reply_branch] );
-		T->inbound_request_isACKed = 1;
-		return 1;
-	} else /* if we are forwarding a CANCEL*/
-	if (  p_msg->REQ_METHOD==METHOD_CANCEL )
-	{
-		DBG("DEBUG: t_forward: forwarding CANCEL \n");
-		/* if no transaction to CANCEL
-		or if the canceled transaction has a final status -> drop the CANCEL*/
-		if ( T->T_canceled!=T_NULL && T->T_canceled->status>=200)
-		{
-			reset_timer( hash_table, &(rb->fr_timer ));
-			reset_timer( hash_table, &(rb->retr_timer ));
-			return 1;
-		}
-		T->outgoing_cancel = EXTERNAL_CANCEL;
-	}
-
-	/* send the request */
-	/* known to be in network order */
-	rb->to.sin_port     =  dest_port;
-	rb->to.sin_addr.s_addr =  dest_ip;
-	rb->to.sin_family = AF_INET;
-
-	SEND_BUFFER( rb );
-
-   return 1;
-
-error:
-	if (shbuf) shm_free(shbuf);
-	if (rb) {
-		shm_free(rb);
-		T->outbound_request[branch]=NULL;
-	}
-	if (buf) free( buf );
-
-	return -1;
-
-}
-
-
-/* Forwards the inbound request to dest. from via.  Returns:
- *       1 - forward successfull
- *      -1 - error during forward
- */
-int t_forward_uri( struct sip_msg* p_msg  )
-{
-   unsigned int     ip, port;
-
-   if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
-   {
-      LOG( L_ERR , "ERROR: t_forward_uri: unable to parse uri!\n");
-      return -1;
-   }
-
-   return t_forward( p_msg , ip , port );
-}
-#endif
-
-
-#ifdef _OBSOLETED_TM
-int t_on_request_received( struct sip_msg  *p_msg , 
-	unsigned int ip , unsigned int port)
-{
-	if ( t_check( p_msg , 0 , 0 ) )
-	{
-		if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
-		{
-			DBG( "SER: ACK received -> t_release\n");
-			if ( !t_forward( p_msg , ip , port ) )
-			{
-				DBG( "SER: WARNING: bad forward\n");
-			}
-			if ( !t_release_transaction( p_msg ) )
-			{
-				DBG( "SER: WARNING: bad t_release\n");
-			}
-		}
-		else
-		{
-			if ( !t_retransmit_reply( p_msg ) )
-			{
-				DBG( "SER: WARNING: bad t_retransmit_reply\n");
-			}
-			DBG( "SER: yet another annoying retranmission\n");
-		}
-		t_unref( /* p_msg */ );
-	} else {
-		if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
-		{
-			DBG( "SER: forwarding ACK  statelessly\n");
-			/* no established transaction ... forward ACK just statelessly*/
-			forward_request( p_msg , mk_proxy_from_ip(ip,port) );
-		}
-		else
-		{
-			/* establish transaction*/
-			if ( !t_add_transaction(p_msg) )
-			{
-				DBG( "SER: ERROR in ser: t_add_transaction\n");
-			}
-			/* reply */
-			if ( p_msg->first_line.u.request.method_value==METHOD_CANCEL)
-			{
-				DBG( "SER: new CANCEL\n");
-				if ( !t_send_reply( p_msg , 200, "glad to cancel") )
-				{
-					DBG( "SER:ERROR: t_send_reply\n");
-				}
-			} else {
-				DBG( "SER: new transaction\n");
-				if ( !t_send_reply( p_msg , 100 , "trying -- your call is important to us") )
-				{
-					DBG( "SER: ERROR: t_send_reply (100)\n");
-				}
-			}
-			if ( !t_forward( p_msg, ip, port ) )
-			{
-				DBG( "SER:ERROR: t_forward \n");
-			}
-			t_unref( /* p_msg */ );
-		}
-	}
-
-}
-
-
-
-
-int t_on_request_received_uri( struct sip_msg  *p_msg )
-{
-	unsigned int     ip, port;
-
-	if ( get_ip_and_port_from_uri( p_msg , &ip, &port)<0 )
-	{
-		LOG( L_ERR , "ERROR: t_on_request_received_uri: \
-		    unable to extract ip and port from uri!\n" );
-		return -1;
-	}
-
-	return t_on_request_received( p_msg , ip , port );
-}
-
-#endif
-
 
 /*   returns 1 if everything was OK or -1 for error
 */

+ 23 - 11
modules/tm/t_reply.c

@@ -149,10 +149,12 @@ int t_retransmit_reply( /* struct sip_msg* p_msg    */ )
 	LOCK_REPLIES( T );
 
 #ifdef SRL
-	if (!(b=pkg_malloc( len=T->outbound_response.bufflen ))) {
+	len=T->outbound_response.bufflen;
+	b=pkg_malloc( len );
+	if (!b) {
 		UNLOCK_REPLIES( T );
 		return -1;
-	};
+	}
 	memcpy( b, T->outbound_response.retr_buffer, len );
 #else
 	SEND_BUFFER( & T->outbound_response );
@@ -418,7 +420,7 @@ int t_on_reply( struct sip_msg  *p_msg )
 {
 	unsigned int branch,len, msg_status, msg_class, save_clone;
 	unsigned int local_cancel;
-	struct sip_msg *clone;
+	struct sip_msg *clone, *backup;
 	int relay;
 	int start_fr;
 	int is_invite;
@@ -436,6 +438,11 @@ int t_on_reply( struct sip_msg  *p_msg )
 	/* ... if there is no such, tell the core router to forward statelessly */
 	if ( T<=0 ) return 1;
 
+	/* by default, don't store incoming replies */
+	save_clone = 0;
+
+	backup = 0;
+
 	DBG("DEBUG: t_on_reply_received: Original status=%d (%d,%d)\n",
 		T->status,branch,local_cancel);
 
@@ -535,21 +542,25 @@ int t_on_reply( struct sip_msg  *p_msg )
 
 		orp_rb->bufflen=orp_len;
 		memcpy( orp_rb->retr_buffer, buf, orp_len );
+
+		/* update the status ... */
+		if ((T->status = p_msg->REPLY_STATUS) >=200 &&
+		/* ... and dst for a possible ACK if we are sending final downstream */
+			T->relaied_reply_branch==-1 ) {
+				memcpy( & T->ack_to, & T->outbound_request[ branch ]->to,
+				sizeof( struct sockaddr_in ) );
+   				T->relaied_reply_branch = branch;
+		}
+
+
 	}; /* if relay ... */
 
 	if (save_clone) {
+		backup = T->inbound_response[branch];
 		T->inbound_response[branch]=clone;
 		T->tag=&(get_to(clone)->tag_value);
 	}
 
-	/* update the status ... */
-	if ((T->status = p_msg->REPLY_STATUS) >=200 &&
-	/* ... and dst for a possible ACK if we are sending final downstream */
-		T->relaied_reply_branch==-1 ) {
-			memcpy( & T->ack_to, & T->outbound_request[ branch ]->to,
-			sizeof( struct sockaddr_in ) );
-   			T->relaied_reply_branch = branch;
-	}
 
 cleanup:
 	UNLOCK_REPLIES( T );
@@ -588,6 +599,7 @@ cleanup:
 		orq_rb->retr_list = RT_T2;
 		set_timer( hash_table, &(orq_rb->retr_timer), RT_T2 );
 	}
+	if (backup) sip_msg_free( backup );
 error2:
 	if (start_fr) set_timer( hash_table, &(orq_rb->fr_timer), FR_INV_TIMER_LIST );
 	if (buf) free( buf );

+ 0 - 82
modules/tm/tm.c

@@ -23,14 +23,6 @@
 /*static int test_f(struct sip_msg*, char*,char*);*/
 static int w_t_check(struct sip_msg* msg, char* str, char* str2);
 static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2);
-#ifdef _OBSOLETED_TM
-static int w_t_forward(struct sip_msg* msg, char* str, char* str2);
-static int w_t_on_request_received(struct sip_msg* msg, char* str, char* str2);
-static int w_t_on_request_received_uri(struct sip_msg* msg, char* str, char* str2);
-int w_t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  );
-//static int fixup_t_on_request_received(void** param, int param_no);
-static int w_t_forward_def(struct sip_msg* msg, char* str, char* str2);
-#endif
 static int w_t_release(struct sip_msg* msg, char* str, char* str2);
 static int fixup_t_forward(void** param, int param_no);
 static int fixup_t_forward_def(void** param, int param_no);
@@ -48,13 +40,6 @@ static void w_onbreak(struct sip_msg* msg) { t_unref(); }
 static struct module_exports nm_exports= {
 	"tm_module",
 	(char*[]){			
-#ifdef _OBSOLETED_TM
-				"t_forward",
-				"t_forward_def",
-				"t_forward_uri",
-				"t_on_request_receive_uri",
-				"t_on_request_receive_to",
-#endif
 				"t_add_transaction",
 				"t_lookup_request",
 				"t_send_reply",
@@ -67,14 +52,6 @@ static struct module_exports nm_exports= {
 				"t_forward_ack"
 			},
 	(cmd_function[]){
-#ifdef _OBSOLETED_TM
-					w_t_forward,
-					w_t_forward_def,
-					w_t_forward_uri,
-					w_t_on_request_received_uri,
-					w_t_on_request_received,
-#endif
-
 					w_t_add_transaction,
 					w_t_check,
 					w_t_send_reply,
@@ -87,13 +64,6 @@ static struct module_exports nm_exports= {
 					w_t_forward_ack
 					},
 	(int[]){
-#ifdef _OBSOLETED_TM
-				2, /* t_forward */
-				1, /* t_forward_def */
-				0, /* t_forward_uri */
-				0, /* t_on_request_receive_uri */
-				2, /* t_on_request_receive_to */
-#endif
 				0, /* t_add_transaction */
 				0, /* t_lookup_request */
 				2, /* t_send_reply */
@@ -106,13 +76,6 @@ static struct module_exports nm_exports= {
 				2  /* t_forward_ack */
 			},
 	(fixup_function[]){
-#ifdef _OBSOLETED_TM
-				fixup_t_forward,		/* t_forward */ 
-				fixup_t_forward_def,	/* t_forward_def */
-				0,						/* t_forward_uri */
-				0,						/* t_on_request_receive_uri */
-				fixup_t_forward,		/* t_on_request_receive_to */
-#endif
 				0,						/* t_add_transaction */
 				0,						/* t_lookup_request */
 				fixup_t_send_reply,		/* t_send_reply */
@@ -124,11 +87,7 @@ static struct module_exports nm_exports= {
 				fixup_t_forward, 		/* t_forward_nonack */
 				fixup_t_forward 		/* t_forward_ack */
 		},
-#ifdef _OBSOLETED_TM
-	15,
-#else
 	10,
-#endif
 #ifdef SRL
 	(response_function) t_on_reply,
 #else
@@ -270,47 +229,6 @@ static int w_t_check(struct sip_msg* msg, char* str, char* str2)
 	return t_check( msg , 0 , 0 ) ? 1 : -1;
 }
 
-#ifdef _OBSOLETED_TM
-static int w_t_forward(struct sip_msg* msg, char* str, char* str2)
-{
-	if (t_check( msg , 0 , 0 )==-1) return -1;
-	if (!T) {
-		DBG("DEBUG: t_forward: no transaction found for request forwarding\n");
-		return -1;
-	}
-	return t_forward(msg, (unsigned int) str, (unsigned int) str2);
-}
-static int w_t_forward_def(struct sip_msg* msg, char* str, char* str2)
-{
-	if (t_check( msg , 0 , 0 )==-1) return -1;
-	if (!T) {
-		DBG("DEBUG: t_forward: no transaction found for request forwarding\n");
-		return -1;
-	}
-	return t_forward(msg, (unsigned int) str, 5060 );
-}
-
-int w_t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  ) {
-	if (t_check( p_msg , 0 , 0)==-1) return -1;
-	if (!T) {
-		DBG("DEBUG: t_forward: no transaction found for request forwarding\n");
-		return -1;
-	}
-	return t_forward_uri(p_msg  );
-}
-static int w_t_on_request_received(struct sip_msg* msg, char* str, char* str2)
-{
-	return t_on_request_received(msg, (unsigned int) str, (unsigned int) str2);
-}
-
-static int w_t_on_request_received_uri(struct sip_msg* msg, char* str, char* str2)
-{
-	return t_on_request_received_uri(msg);
-}
-
-
-#endif
-
 static int w_t_forward_ack(struct sip_msg* msg, char* str, char* str2)
 {
 	if (t_check( msg , 0 , 0 )==-1) return -1;