瀏覽代碼

CAncel impl is on its way :)

Bogdan-Andrei Iancu 24 年之前
父節點
當前提交
6790ac440b
共有 4 個文件被更改,包括 30 次插入13 次删除
  1. 10 0
      modules/tm/h_table.c
  2. 4 0
      modules/tm/h_table.h
  3. 16 11
      modules/tm/t_funcs.c
  4. 0 2
      modules/tm/t_funcs.h

+ 10 - 0
modules/tm/h_table.c

@@ -163,6 +163,9 @@ struct cell*  build_cell( struct sip_msg* p_msg )
    /* nr of outbound requests is 0 */
    /* all pointers from outbound_request array are NULL */
    /* all pointers from outbound_response array are NULL */
+   /*init the links with the canceled / canceler transaction */
+   new_cell->T_canceled  = T_UNDEFINED;
+   new_cell->T_canceler  = T_UNDEFINED;
 
    return new_cell;
 }
@@ -209,6 +212,13 @@ void remove_from_hash_table( struct s_table *hash_table,  struct cell * p_cell )
 {
    struct entry*  p_entry  = &(hash_table->entrys[p_cell->hash_index]);
 
+   /*update the canceler and canceled links*/
+   if ( p_cell->T_canceled!=T_NULL && p_cell->T_canceled!=T_UNDEFINED)
+      p_cell->T_canceled->T_canceler = T_NULL;
+   if ( p_cell->T_canceler!=T_NULL && p_cell->T_canceler!=T_UNDEFINED)
+      p_cell->T_canceler->T_canceled = T_NULL;
+
+   /* unlink the cell from entry list */
    lock( p_entry->mutex );
 
    if ( p_cell->prev_cell )

+ 4 - 0
modules/tm/h_table.h

@@ -31,6 +31,10 @@ struct timer;
 #define MAX_FORK           20
 
 
+#define T_UNDEFINED 	( (struct cell*) -1 )
+#define T_NULL		( (struct cell*) 0 )
+
+
 /* timer list: includes head, tail and protection semaphore */
 typedef struct  timer
 {

+ 16 - 11
modules/tm/t_funcs.c

@@ -90,9 +90,6 @@ int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
    new_cell = build_cell( p_msg ) ;
    if  ( !new_cell )
       return -1;
-   /*init the links with the canceled / canceler transaction */
-   new_cell->T_canceled  = T_UNDEFINED;
-   new_cell->T_canceler  = T_UNDEFINED;
    /*insert the transaction into hash table*/
    insert_into_hash_table( hash_table , new_cell );
    DBG("DEBUG: t_add_transaction: new transaction inserted, hash: %d\n", new_cell->hash_index );
@@ -258,12 +255,14 @@ 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 */
-         if (!T->T_canceled)
+         if ( T->T_canceled==T_UNDEFINED )
             T->T_canceled = t_lookupOriginalT( hash_table , p_msg );
          /* if found */
-         if (T->T_canceled)
-         {  /* if in 1xx status, send to the same destination */
-          if ( (T->T_canceled->status/100)==1 )
+         if ( T->T_canceled!=T_NULL )
+         {
+            T->T_canceled->T_canceler = T;
+            /* 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;
@@ -326,11 +325,11 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
    {
        /* if no transaction to CANCEL */
       /* or if the canceled transaction has a final status -> drop the CANCEL*/
-      if ( !T->T_canceled || T->T_canceled->status>=200)
+      if ( T->T_canceled==T_NULL || T->T_canceled->status>=200)
        {
            remove_from_timer_list( hash_table , (&(T->outbound_request[branch]->tl[FR_TIMER_LIST])) , FR_TIMER_LIST);
            remove_from_timer_list( hash_table , (&(T->outbound_request[branch]->tl[RETRASMISSIONS_LIST])), RETRASMISSIONS_LIST );
-         return 1;
+           return 1;
        }
    }
 
@@ -591,6 +590,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
    }
 
    buf = build_res_buf_from_sip_req( code , text , T->inbound_request , &len );
+   DBG("DEBUG: t_send_reply: buffer computed\n");
 
    if (!buf)
    {
@@ -611,8 +611,10 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
    T->status = code;
 
    /* start/stops the proper timers*/
+   DBG("DEBUG: t_send_reply: update timers\n");
    t_update_timers_after_sending_reply( T->outbound_response );
 
+   DBG("DEBUG: t_send_reply: send reply\n");
    t_retransmit_reply( p_msg, 0 , 0);
 
    return 1;
@@ -1011,9 +1013,12 @@ int t_update_timers_after_sending_reply( struct retrans_buff *rb )
    }
    else if ( Trans->inbound_request->first_line.u.request.method_value==METHOD_CANCEL )
    {
-      if (!Trans->T_canceled)
+      if ( Trans->T_canceled==T_UNDEFINED )
             Trans->T_canceled = t_lookupOriginalT( hash_table , Trans->inbound_request );
-      if ( Trans->T_canceled && Trans->T_canceled->status>=200)
+      if ( Trans->T_canceled==T_NULL )
+            return 1;
+      Trans->T_canceled->T_canceler = Trans;
+     if ( Trans->T_canceled->status>=200)
             t_put_on_wait( Trans );
    }
    else if (Trans->status>=200)

+ 0 - 2
modules/tm/t_funcs.h

@@ -26,8 +26,6 @@ struct cell;
 #include "lock.h"
 #include "sip_msg.h"
 
-#define T_UNDEFINED 	( (struct cell*) -1 )
-#define T_NULL		( (struct cell*) 0 )
 
 /* already defined in msg_parser.h
 #define get_cseq( p_msg)    ((struct cseq_body*)p_msg->cseq->parsed)