Browse code

ref_conter fixed

Bogdan-Andrei Iancu authored on 13/12/2001 19:26:04
Showing 7 changed files
... ...
@@ -46,7 +46,7 @@ ARCH = $(shell uname -s)
46 46
 #		malloc etc.)
47 47
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
48 48
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
49
-	 -DDBG_QM_MALLOC -DNO_DEBUG #
49
+	 -DNO_DEBUG #-DDBG_QM_MALLOC
50 50
 #-DEXTRA_DEBUG
51 51
 # -DUSE_SHM_MEM
52 52
 #-DNO_DEBUG 
... ...
@@ -58,7 +58,7 @@ void free_cell( struct cell* dead_cell )
58 58
    release_cell_lock( dead_cell );
59 59
    /* the cell's body */
60 60
    sh_free( dead_cell );
61
-   DBG("DEBUG: free_cell: start\n");
61
+   DBG("DEBUG: free_cell: done\n");
62 62
 }
63 63
 
64 64
 
... ...
@@ -140,12 +140,14 @@ struct cell*  build_cell( struct sip_msg* p_msg )
140 140
    struct cell*  new_cell;
141 141
    int                i;
142 142
 
143
+    DBG("DEBUG: build_cell : start\n");
143 144
     /* do we have the source for the build process? */
144 145
    if (!p_msg)
145 146
       return NULL;
146 147
 
147 148
    /* allocs a new cell */
148 149
    new_cell = (struct cell*)sh_malloc( sizeof( struct cell ) );
150
+   DBG("DEBUG: build_cell : malloc done\n");
149 151
    if  ( !new_cell )
150 152
       return NULL;
151 153
 
... ...
@@ -164,6 +166,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
164 166
    if (parse_headers(p_msg, HDR_EOH )==-1)
165 167
 	goto error;
166 168
    new_cell->inbound_request =  sip_msg_cloner(p_msg) ;
169
+   DBG("DEBUG: build_cell : clone done\n");
167 170
    if (!new_cell->inbound_request)
168 171
 	goto error;
169 172
    /* inbound response is NULL*/
... ...
@@ -181,6 +184,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
181 184
 
182 185
    init_cell_lock(  new_cell );
183 186
 
187
+   DBG("DEBUG: build_cell : done\n");
184 188
    return new_cell;
185 189
 
186 190
 error:
... ...
@@ -253,20 +257,6 @@ void remove_from_hash_table( struct s_table *hash_table,  struct cell * p_cell )
253 257
 }
254 258
 
255 259
 
256
-void ref_cell( struct cell* p_cell)
257
-{
258
-   lock( p_cell->mutex );
259
-   p_cell->ref_counter++;
260
-  unlock( p_cell->mutex );
261
-}
262
-
263
-
264
-void unref_cell( struct cell* p_cell)
265
-{
266
-   lock( p_cell->mutex );
267
-   p_cell->ref_counter--;
268
-   unlock( p_cell->mutex );
269
-}
270 260
 
271 261
 
272 262
 
... ...
@@ -145,9 +145,4 @@ struct cell*  build_cell( struct sip_msg* p_msg );
145 145
 void remove_from_hash_table( struct s_table *hash_table,  struct cell * p_cell );
146 146
 void    insert_into_hash_table( struct s_table *hash_table,  struct cell * p_cell );
147 147
 
148
-void      ref_cell( struct cell* p_cell);
149
-void unref_cell( struct cell* p_cell);
150
-
151
-
152
-
153 148
 #endif
... ...
@@ -43,6 +43,13 @@
43 43
 #define remove_from_timer(hash_table,tl,list_id) \
44 44
 	remove_from_timer_list( (hash_table), (tl) , (list_id))
45 45
 
46
+#define unref_T(T_cell) \
47
+	do{\
48
+		lock( hash_table->entrys[T_cell->hash_index].mutex );\
49
+		T_cell->ref_counter--;\
50
+		DBG("DEBUG: XXXXXXXXXXXXXXXXXXXXX unref_T : T=%p , ref=%d\n",T_cell,T_cell->ref_counter);\
51
+		unlock( hash_table->entrys[T_cell->hash_index].mutex );\
52
+	}while(0);
46 53
 
47 54
 
48 55
 
... ...
@@ -119,30 +126,27 @@ int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
119 126
    struct cell*    new_cell;
120 127
 
121 128
    DBG("DEBUG: t_add_transaction: adding......\n");
122
-   /* it's about the same transaction or not?*/
123
-   if ( global_msg_id != p_msg->id )
129
+
130
+   /* sanity check: ACKs can never establish a transaction */
131
+   if ( p_msg->first_line.u.request.method_value==METHOD_ACK )
124 132
    {
125
-      T = T_UNDEFINED;
126
-      global_msg_id = p_msg->id;
133
+       LOG(L_ERR, "ERROR: add_transaction: ACK can't be used to add transaction\n");
134
+      return -1;
127 135
    }
128 136
 
129
-    /* if the transaction is not found yet we are tring to look for it*/
130
-   if ( T==T_UNDEFINED )
131
-      /* if the lookup's result is not 0 means that it's a retransmission */
132
-      if ( t_lookup_request( p_msg, foo, bar ) )
133
-      {
134
-         LOG(L_ERR,"ERROR: t_add_transaction: won't add a retransmission\n");
135
-         return -1;
136
-      }
137
+   /* it's about the same transaction or not?*/
138
+   t_check( p_msg , 0 );
137 139
 
138
-   /* sanity check: ACKs can never establish a transaction */
139
-   if ( p_msg->first_line.u.request.method_value==METHOD_ACK ) {
140
-	LOG(L_ERR, "ERROR: add_transaction: ACK can't be used to add transaction\n");
141
-	return -1;
140
+   /* if the lookup's result is not 0 means that it's a retransmission */
141
+   if ( T )
142
+   {
143
+      LOG(L_ERR,"ERROR: t_add_transaction: won't add a retransmission\n");
144
+      return -1;
142 145
    }
143 146
 
144 147
    /* creates a new transaction */
145 148
    new_cell = build_cell( p_msg ) ;
149
+   DBG("DEBUG: t_add_transaction: new transaction created %p\n", new_cell);
146 150
    if  ( !new_cell ){
147 151
 	   LOG(L_ERR, "ERROR: add_transaction: out of mem:\n");
148 152
 	   sh_status();
... ...
@@ -153,6 +157,7 @@ int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
153 157
    DBG("DEBUG: t_add_transaction: new transaction inserted, hash: %d\n", new_cell->hash_index );
154 158
 
155 159
    T = new_cell;
160
+   T->ref_counter =1;
156 161
    return 1;
157 162
 }
158 163
 
... ...
@@ -163,53 +168,37 @@ int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
163 168
  *      -1 - transaction wasn't found
164 169
  *       1  - transaction found
165 170
  */
166
-int t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  )
171
+int t_lookup_request( struct sip_msg* p_msg )
167 172
 {
168 173
    struct cell      *p_cell;
169 174
    struct cell      *tmp_cell;
170 175
    unsigned int  hash_index=0;
171 176
    unsigned int  isACK = 0;
172 177
 
173
-   /* it's about the same transaction or not?*/
174
-   if ( global_msg_id != p_msg->id )
175
-   {
176
-      T = T_UNDEFINED;
177
-      global_msg_id = p_msg->id;
178
-   }
179
-
180
-    /* if  T is previous found -> return found */
181
-   if ( T!=T_UNDEFINED && T )	{
182
-      DBG("DEBUG: t_lookup_request: T already exists\n");
183
-      return 1;
184
-   }
178
+   DBG("t_lookup_request: start searching\n");
185 179
 
186
-    /* if T was previous searched and not found -> return not found*/
187
-   if ( !T )	{
188
-	DBG("DEBUG: t_lookup_request: T previously sought and not found\n");
180
+   /* parse all*/
181
+   if (check_transaction_quadruple(p_msg)==0)
182
+   {
183
+      LOG(L_ERR, "ERROR: TM module: t_lookup_request: too few headers\n");
184
+      T=0;
189 185
       return -1;
190 186
    }
191 187
 
192
-   DBG("t_lookup_request: start searching\n");
193
-   /* parse all*/
194
-   if (check_transaction_quadruple(p_msg)==0) {
195
-	   LOG(L_ERR, "ERROR: TM module: t_lookup_request: too few headers\n");
196
-	   T=T_NULL;
197
-	   return -1;
198
-   }
199 188
    /* start searching into the table */
200 189
    hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
201 190
    if ( p_msg->first_line.u.request.method_value==METHOD_ACK  )
202 191
       isACK = 1;
203 192
    DBG("t_lookup_request: continue searching;  hash=%d, isACK=%d\n",hash_index,isACK);
204 193
 
194
+   /* lock the hole entry*/
195
+   lock( hash_table->entrys[hash_index].mutex );
196
+
205 197
    /* all the transactions from the entry are compared */
206 198
    p_cell     = hash_table->entrys[hash_index].first_cell;
207 199
    tmp_cell = 0;
208 200
    while( p_cell )
209 201
    {
210
-      /* the transaction is referenceted for reading */
211
-      ref_cell( p_cell );
212
-
213 202
       /* is it the wanted transaction ? */
214 203
       if ( !isACK )
215 204
       { /* is not an ACK request */
... ...
@@ -224,9 +213,10 @@ int t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  )
224 213
                                if ( /*callid*/ !memcmp( p_cell->inbound_request->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
225 214
                                   if ( /*cseq*/ !memcmp( p_cell->inbound_request->cseq->body.s , p_msg->cseq->body.s , p_msg->cseq->body.len ) )
226 215
                                      { /* WE FOUND THE GOLDEN EGG !!!! */
227
-                                        DBG("DEBUG: t_lookup_request: non-ACK found\n");
228 216
                                         T = p_cell;
229
-                                        unref_cell( p_cell );
217
+                                        T->ref_counter ++;
218
+                                        DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_lookup_request: non-ACK found ( T=%p , ref=%d)\n",T,T->ref_counter);
219
+                                        unlock( hash_table->entrys[hash_index].mutex );
230 220
                                         return 1;
231 221
                                      }
232 222
       }
... ...
@@ -246,23 +236,22 @@ int t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  )
246 236
                                      if ( /*callid*/ !memcmp( p_cell->inbound_request->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
247 237
                                         if ( /*cseq_nr*/ !memcmp( get_cseq(p_cell->inbound_request)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
248 238
                                            { /* WE FOUND THE GOLDEN EGG !!!! */
249
-                                              DBG("DEBUG: t_lookup_request: ACK found\n");
250 239
                                               T = p_cell;
251
-                                              unref_cell( p_cell );
240
+                                              T->ref_counter ++;
241
+                                              DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_lookup_request: ACK found ( T=%p , ref=%d)\n",T,T->ref_counter);
242
+                                              unlock( hash_table->entrys[hash_index].mutex );
252 243
                                                return 1;
253 244
                                            }
254 245
       } /* end if is ACK or not*/
255 246
       /* next transaction */
256 247
       tmp_cell = p_cell;
257 248
       p_cell = p_cell->next_cell;
258
-
259
-      /* the transaction is dereferenceted */
260
-      unref_cell( tmp_cell );
261 249
    }
262 250
 
263 251
    /* no transaction found */
264
-   DBG("DEBUG: t_lookup_request: no transaction found\n");
265 252
    T = 0;
253
+   unlock( hash_table->entrys[hash_index].mutex );
254
+   DBG("DEBUG: t_lookup_request: no transaction found\n");
266 255
    return -1;
267 256
 }
268 257
 
... ...
@@ -285,19 +274,14 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
285 274
    branch = 0;	/* we don't do any forking right now */
286 275
 
287 276
    /* it's about the same transaction or not? */
288
-   if ( global_msg_id != p_msg->id )
289
-   {
290
-      T = T_UNDEFINED;
291
-      global_msg_id = p_msg->id;
292
-   }
293
-
294
-   /* if  T hasn't been previous searched -> search for it */
295
-   if ( T == T_UNDEFINED )
296
-      t_lookup_request( p_msg, 0 , 0 );
277
+   t_check( p_msg  , 0 );
297 278
 
298 279
    /*if T hasn't been found after all -> return not found (error) */
299 280
    if ( !T )
281
+   {
282
+      DBG("DEBUG: t_forward: no transaction found in order  to forward the request\n");
300 283
       return -1;
284
+   }
301 285
 
302 286
    /*if it's an ACK and the status is not final or is final, but error the ACK is not forwarded*/
303 287
    if ( p_msg->first_line.u.request.method_value==METHOD_ACK  && (T->status/100)!=2 ) {
... ...
@@ -437,19 +421,14 @@ int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
437 421
    int                      err;
438 422
 
439 423
    /* it's about the same transaction or not? */
440
-   if ( global_msg_id != p_msg->id )
441
-   {
442
-      T = T_UNDEFINED;
443
-      global_msg_id = p_msg->id;
444
-   }
445
-
446
-   /* if  T hasn't been previous searched -> search for it */
447
-   if ( T==T_UNDEFINED )
448
-      t_lookup_request( p_msg, 0 , 0 );
424
+   t_check( p_msg , 0);
449 425
 
450 426
    /*if T hasn't been found after all -> return not found (error) */
451 427
    if ( !T )
428
+   {
429
+      DBG("DEBUG: t_forward_uri: no transaction found in order  to forward the request\n");
452 430
       return -1;
431
+   }
453 432
 
454 433
    /* the original uri has been changed? */
455 434
    if (p_msg->new_uri.s==0 || p_msg->new_uri.len==0)
... ...
@@ -506,7 +485,6 @@ int t_on_reply_received( struct sip_msg  *p_msg )
506 485
    struct sip_msg *clone;
507 486
    int relay;
508 487
 
509
-   global_msg_id = p_msg->id;
510 488
    clone=NULL;
511 489
 
512 490
    /* parse_headers( p_msg , HDR_EOH ); */ /*????*/
... ...
@@ -523,7 +501,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
523 501
 	return 1;
524 502
 
525 503
    /* we use label-matching to lookup for T */
526
-   t_reply_matching( hash_table , p_msg , &T , &branch  );
504
+   t_check( p_msg , &branch );
527 505
 
528 506
    /* if no T found ->tell the core router to forward statelessly */
529 507
    if ( T<=0 )
... ...
@@ -593,7 +571,6 @@ int t_on_reply_received( struct sip_msg  *p_msg )
593 571
       {
594 572
         T->inbound_response[branch]=NULL;
595 573
         sip_msg_free( clone );
596
-       DBG("DEBUG: t_store_incoming_reply: DONE WITH ERROR!! :((((((((((((((((((((((((((((\n");
597 574
         return -1;
598 575
       }
599 576
    }
... ...
@@ -607,8 +584,6 @@ int t_on_reply_received( struct sip_msg  *p_msg )
607 584
    }
608 585
 
609 586
    /* nothing to do for the ser core */
610
-
611
-   DBG("DEBUG: t_store_incoming_reply: DONE WITH SUCCESS!! :)))))))))))))))))))))))\n");
612 587
    return 0;
613 588
 }
614 589
 
... ...
@@ -619,7 +594,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
619 594
   */
620 595
 int t_release_transaction( struct sip_msg* p_msg)
621 596
 {
622
-   t_check( hash_table , p_msg );
597
+   t_check( p_msg , 0 );
623 598
 
624 599
    if ( T && T!=T_UNDEFINED )
625 600
       return t_put_on_wait( T );
... ...
@@ -639,7 +614,7 @@ int t_release_transaction( struct sip_msg* p_msg)
639 614
   */
640 615
 int t_retransmit_reply( struct sip_msg* p_msg, char* foo, char* bar  )
641 616
 {
642
-   t_check( hash_table, p_msg );
617
+   t_check( p_msg , 0 );
643 618
 
644 619
    /* if no transaction exists or no reply to be resend -> out */
645 620
    if ( T  && T->outbound_response )
... ...
@@ -671,11 +646,11 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
671 646
    char *b;
672 647
 
673 648
    DBG("DEBUG: t_send_reply: entered\n");
674
-   t_check( hash_table, p_msg );
649
+   t_check( p_msg , 0 );
675 650
 
676 651
    if (!T)
677 652
    {
678
-      LOG(L_ERR, "ERROR: cannot send a t_reply to a message for which no T-state has been established\n");
653
+      LOG(L_ERR, "ERROR: t_send_reply: cannot send a t_reply to a message for which no T-state has been established\n");
679 654
      return -1;
680 655
    }
681 656
 
... ...
@@ -784,9 +759,6 @@ struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_
784 759
    tmp_cell = 0;
785 760
    while( p_cell )
786 761
    {
787
-      /* the transaction is referenceted for reading */
788
-      ref_cell( p_cell );
789
-
790 762
       /* is it the wanted transaction ? */
791 763
       /* first only the length are checked */
792 764
       if ( /*from length*/ p_cell->inbound_request->from->body.len == p_msg->from->body.len )
... ...
@@ -804,15 +776,11 @@ struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_
804 776
                                           if ( /*cseq_nr*/ !memcmp( get_cseq(p_cell->inbound_request)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
805 777
                                              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 ) )
806 778
                                              { /* WE FOUND THE GOLDEN EGG !!!! */
807
-                                                unref_cell( p_cell );
808 779
                                                 return p_cell;
809 780
                                              }
810 781
       /* next transaction */
811 782
       tmp_cell = p_cell;
812 783
       p_cell = p_cell->next_cell;
813
-
814
-      /* the transaction is dereferenceted */
815
-      unref_cell( tmp_cell );
816 784
    }
817 785
 
818 786
    /* no transaction found */
... ...
@@ -852,7 +820,7 @@ int str_unsigned_hex_2_int( char *c, int len )
852 820
 /* Returns 0 - nothing found
853 821
   *              1  - T found
854 822
   */
855
-int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struct cell **p_Trans , unsigned int *p_branch )
823
+int t_reply_matching( struct sip_msg *p_msg , unsigned int *p_branch )
856 824
 {
857 825
    struct cell*  p_cell;
858 826
    struct cell* tmp_cell;
... ...
@@ -864,8 +832,7 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
864 832
    int scan_space;
865 833
 
866 834
    /* split the branch into pieces: loop_detection_check(ignored),
867
-      hash_table_id, synonym_id, branch_id
868
-   */
835
+      hash_table_id, synonym_id, branch_id*/
869 836
 
870 837
    if (! ( p_msg->via1 && p_msg->via1->branch && p_msg->via1->branch->value.s) )
871 838
 	goto nomatch;
... ...
@@ -911,36 +878,34 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
911 878
 	hash_index, entry_label, branch_id );
912 879
 
913 880
    /* sanity check */
914
-   if (hash_index==-1 || hash_index >=TABLE_ENTRIES ||
915
-       entry_label==-1 || branch_id==-1 ||
916
-	branch_id>=MAX_FORK )
917
-		goto nomatch;
881
+   if (hash_index<0 || hash_index >=TABLE_ENTRIES ||
882
+       entry_label<0 || branch_id<0 || branch_id>=MAX_FORK )
883
+          goto nomatch;
918 884
 
885
+   /* lock the hole entry*/
886
+   lock( hash_table->entrys[hash_index].mutex );
919 887
 
920 888
    /*all the cells from the entry are scan to detect an entry_label matching */
921 889
    p_cell     = hash_table->entrys[hash_index].first_cell;
922 890
    tmp_cell = 0;
923 891
    while( p_cell )
924 892
    {
925
-      /* the transaction is referenceted for reading */
926
-      ref_cell( p_cell );
927 893
       /* is it the cell with the wanted entry_label? */
928 894
       if ( p_cell->label == entry_label )
929 895
       /* has the transaction the wanted branch? */
930 896
       if ( p_cell->nr_of_outgoings>branch_id && p_cell->outbound_request[branch_id] )
931 897
       {/* WE FOUND THE GOLDEN EGG !!!! */
932
-		*p_Trans = p_cell;
933
-		*p_branch = branch_id;
934
-		unref_cell( p_cell );
935
-                              DBG("DEBUG: t_reply_matching: reply matched!\n");
936
-		return 1;
937
-	}
898
+          T = p_cell;
899
+          *p_branch = branch_id;
900
+          T->ref_counter ++;
901
+          unlock( hash_table->entrys[hash_index].mutex );
902
+          DBG("DEBUG:XXXXXXXXXXXXXXXXXXXXX t_reply_matching: reply matched (T=%p, ref=%d)!\n",T,T->ref_counter);
903
+        return 1;
904
+      }
938 905
       /* next cell */
939 906
       tmp_cell = p_cell;
940 907
       p_cell = p_cell->next_cell;
941 908
 
942
-      /* the transaction is dereferenceted */
943
-      unref_cell( tmp_cell );
944 909
    } /* while p_cell */
945 910
 
946 911
    /* nothing found */
... ...
@@ -949,69 +914,44 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
949 914
 nomatch:
950 915
    DBG("DEBUG: t_reply_matching: failure to match a transaction\n");
951 916
    *p_branch = -1;
952
-   *p_Trans = NULL;
953
-   return 0;
954
-}
955
-
956
-
957
-
958
-
959
-/* We like this incoming reply, so, let's store it, we'll decide
960
-  * later what to d with that
961
-  */
962
-
963
-/*
964
-int t_store_incoming_reply( struct cell* Trans, unsigned int branch, struct sip_msg* p_msg )
965
-{
966
-   DBG("DEBUG: t_store_incoming_reply: starting [%d]....\n",branch);
967
-   if ( parse_headers(p_msg, HDR_VIA1|HDR_VIA2|HDR_TO|HDR_CSEQ )==-1 ||
968
-        !p_msg->via1 || !p_msg->via2 || !p_msg->to || !p_msg->cseq )
969
-   {
970
-      LOG( L_ERR , "ERROR: t_store_incoming_reply: unable to parse headers !\n"  );
971
-      return -1;
972
-   }
973
-   if ( Trans->inbound_response[branch] ) {
974
-      sip_msg_free( Trans->inbound_response[branch] ) ;
975
-      DBG("DEBUG: t_store_incoming_reply: sip_msg_free done....\n");
976
-   }
977
-
978
-   Trans->inbound_response[branch] = sip_msg_cloner( p_msg );
979
-   if (!Trans->inbound_response[branch])
980
-	return -1;
981
-   Trans->status = p_msg->first_line.u.reply.statuscode;
982
-   DBG("DEBUG: t_store_incoming_reply: reply stored\n");
983
-   return 1;
917
+   T = 0;
918
+   unlock( hash_table->entrys[hash_index].mutex );
919
+   return -1;
984 920
 }
985 921
 
986
-*/
987
-
988 922
 
989 923
 
990 924
 
991 925
 /* Functions update T (T gets either a valid pointer in it or it equals zero) if no transaction
992 926
   * for current message exists;
993
-  * Returns 1 if T was modified or 0 if not.
994 927
   */
995
-int t_check( struct s_table *hash_table , struct sip_msg* p_msg )
928
+int t_check( struct sip_msg* p_msg , int *param_branch)
996 929
 {
997
-   unsigned int branch;
930
+   int local_branch;
998 931
 
999 932
    /* is T still up-to-date ? */
1000 933
    DBG("DEBUG: t_check : msg id=%d , global msg id=%d , T=%p\n", p_msg->id,global_msg_id,T);
1001 934
    if ( p_msg->id != global_msg_id || T==T_UNDEFINED )
1002 935
    {
1003 936
       global_msg_id = p_msg->id;
937
+      if ( T && T!=T_UNDEFINED )
938
+         unref_T(T);
1004 939
       T = T_UNDEFINED;
1005 940
       /* transaction lookup */
1006
-     if ( p_msg->first_line.type=SIP_REQUEST )
1007
-         t_lookup_request( p_msg, 0, 0 );
941
+     if ( p_msg->first_line.type==SIP_REQUEST )
942
+         t_lookup_request( p_msg );
943
+     else
944
+         t_reply_matching( p_msg , ((param_branch!=0)?(param_branch):(&local_branch)) );
945
+   }
946
+   else
947
+   {
948
+      if (T)
949
+         DBG("DEBUG: t_check: T alredy found!\n");
1008 950
       else
1009
-         t_reply_matching( hash_table , p_msg , &T , &branch );
1010
-
1011
-      return 1;
951
+          DBG("DEBUG: t_check: T previously sought and not found\n");
1012 952
    }
1013 953
 
1014
-   return 0;
954
+   return ((T)?1:-1) ;
1015 955
 }
1016 956
 
1017 957
 
... ...
@@ -1459,7 +1399,7 @@ void delete_handler( void *attr)
1459 1399
     }
1460 1400
     else
1461 1401
     {
1462
-       DBG("DEBUG: delete_handler : re post for delete\n");
1402
+       DBG("DEBUG: delete_handler : re post for delete (%d)\n",p_cell->ref_counter);
1463 1403
        /* else it's readded to del list for future del */
1464 1404
        add_to_tail_of_timer( hash_table, (&(p_cell->dele_tl)), DELETE_LIST, DEL_TIME_OUT );
1465 1405
     }
... ...
@@ -52,7 +52,7 @@ int  t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar  );
52 52
  *      -1 - transaction wasn't found
53 53
  *       1 - transaction found
54 54
  */
55
-int  t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  );
55
+int t_check( struct sip_msg* , int *branch );
56 56
 
57 57
 
58 58
 
... ...
@@ -112,9 +112,9 @@ int t_send_reply( struct sip_msg * , unsigned int , char *  );
112 112
 
113 113
 
114 114
 struct cell* t_lookupOriginalT(  struct s_table* hash_table , struct sip_msg* p_msg );
115
-int t_reply_matching( struct s_table* , struct sip_msg* , struct cell** , unsigned int*  );
115
+int t_reply_matching( struct sip_msg* , unsigned int*  );
116 116
 int t_store_incoming_reply( struct cell* , unsigned int , struct sip_msg* );
117
-int t_check( struct s_table* , struct sip_msg*  );
117
+int  t_lookup_request( struct sip_msg* p_msg );
118 118
 int t_all_final( struct cell * );
119 119
 int t_build_and_send_ACK( struct cell *Trans , unsigned int brach , struct sip_msg* rpl);
120 120
 int t_cancel_branch(unsigned int branch); //TO DO
... ...
@@ -22,6 +22,7 @@
22 22
 
23 23
 
24 24
 /*static int test_f(struct sip_msg*, char*,char*);*/
25
+static int w_t_check(struct sip_msg* msg, char* str, char* str2);
25 26
 static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2);
26 27
 static int w_t_forward(struct sip_msg* msg, char* str, char* str2);
27 28
 static int w_t_forward_def(struct sip_msg* msg, char* str, char* str2);
... ...
@@ -32,7 +33,7 @@ static int fixup_t_send_reply(void** param, int param_no);
32 33
 
33 34
 static struct module_exports nm_exports= {
34 35
 	"tm_module",
35
-	(char*[]){	"t_add_transaction",
36
+	(char*[]){			"t_add_transaction",
36 37
 				"t_lookup_request",
37 38
 				"t_forward",
38 39
 				"t_forward_def",
... ...
@@ -43,7 +44,7 @@ static struct module_exports nm_exports= {
43 44
 			},
44 45
 	(cmd_function[]){
45 46
 					t_add_transaction,
46
-					t_lookup_request,
47
+					t_check,
47 48
 					w_t_forward,
48 49
 					w_t_forward_def,
49 50
 					t_forward_uri,
... ...
@@ -203,6 +204,11 @@ static int fixup_t_send_reply(void** param, int param_no)
203 204
 
204 205
 
205 206
 
207
+static int w_t_check(struct sip_msg* msg, char* str, char* str2)
208
+{
209
+	return t_check( msg , 0 );
210
+}
211
+
206 212
 static int w_t_forward(struct sip_msg* msg, char* str, char* str2)
207 213
 {
208 214
 	return t_forward(msg, (unsigned int) str, (unsigned int) str2);
... ...
@@ -1,4 +1,4 @@
1
-debug=9          # debug level (cmd line: -dddddddddd)
1
+debug=3          # debug level (cmd line: -dddddddddd)
2 2
 check_via=yes     # (cmd. line: -v)
3 3
 dns=on           # (cmd. line: -r)
4 4
 rev_dns=yes      # (cmd. line: -R)
... ...
@@ -15,16 +15,10 @@ loadmodule "modules/print/print.so"
15 15
 #loadmodule "modules/tm/tm.so"
16 16
 
17 17
 route{
18
-	#rewritehost("iptel.org");
19
-#	forward(uri:host,uri:port);
20
-#	forward(127.0.0.1, 5090);
21
-#	sethost("127.0.0.1");
22
-#	setport("5090");
23
-
24 18
 	if ( t_lookup_request()) {
25 19
 		if ( method=="ACK" )	{
26 20
 			log("SER: ACK received -> t_release\n");
27
-			if (! t_forward("127.0.0.1", "5090" )) {
21
+			if (! t_forward("195.37.78.233", "6666" )) {
28 22
 				log("SER: WARNING: bad forward\n");
29 23
 			};
30 24
 			if (! t_release()) {
... ...
@@ -38,39 +32,36 @@ route{
38 32
 		};
39 33
 	} else {
40 34
 		if (! t_add_transaction()){
41
-			log("SER: ERROR: t_add_transaction\n");
42
-		};
43
-		if (method=="CANCEL") {
44
-			log("SER: new CANCEL\n");
45
-			# XXX ... it wants me to put status code in ""
46
-			if (! t_send_reply( "200", "glad to cancel")){
47
-				log("SER:ERROR: t_send_reply\n");
35
+			log("ERROR in ser: t_add_transaction\n");
36
+			if (method=="BYE") {
37
+				forward("195.37.78.233", 5555);
38
+			}else{
39
+				forward("195.37.78.233", 6666 );
48 40
 			};
49 41
 		} else {
50
-			log("SER: new transaction\n");
51
-			if (! t_send_reply("100", "trying -- your call is important to us")
52
-				){
53
-				log("SER: ERROR: t_send_reply (100)\n");
42
+			if (method=="CANCEL") {
43
+				log("SER: new CANCEL\n");
44
+				if (! t_send_reply( "200", "glad to cancel")){
45
+					log("SER:ERROR: t_send_reply\n");
46
+				};
47
+			} else {
48
+				log("SER: new transaction\n");
49
+				if (! t_send_reply("100", "trying -- your call is important to us")
50
+					){
51
+					log("SER: ERROR: t_send_reply (100)\n");
52
+				};
54 53
 			};
55
-		};
56
-		#rewritehost("iptel.org");
57
-		# XXX ... it wants me to put port nr in ""
58
-		#t_forward("benetnash.fokus.gmd.de", "5080" );
59
-		if (method=="BYE") {
60
-			log("SER: BYE received, HACK: forwarding to client\n");
61
-			if (! t_forward("127.0.0.1", "5000")){
62
-				log("SER:ERROR: t_forward (..., 5555)\n");
63
-			};
64
-
65
-		}else{
66
-			if (! t_forward("127.0.0.1", "5090" )){
67
-				log("SER:ERROR: t_forward (..., 6666)\n");
54
+			if (method=="BYE") {
55
+				log("SER: BYE received, HACK: forwarding to client\n");
56
+				if (! t_forward("195.37.78.233", "5555")){
57
+					log("SER:ERROR: t_forward (..., 5555)\n");
58
+				};
59
+			}else{
60
+				if (! t_forward("195.37.78.233", "6666" )){
61
+					log("SER:ERROR: t_forward (..., 6666)\n");
62
+				};
68 63
 			};
69 64
 		};
70
-		#t_forward_uri();
71
-		# XXX ... it doesn't like default port numbers
72
-		# t_forward("fox.iptel.org" );
73
-		# XXX t_forward_uri ... not done yet
74 65
 	};
75 66
 
76 67
 }