Browse code

lot and hard debugging

Bogdan-Andrei Iancu authored on 04/12/2001 06:57:37
Showing 6 changed files
... ...
@@ -148,7 +148,7 @@ struct cell*  build_cell( struct sip_msg* p_msg )
148 148
 
149 149
    /* inbound request */
150 150
    /* force parsing all the needed headers*/
151
-   parse_headers(p_msg, HDR_VIA|HDR_TO|HDR_FROM|HDR_CALLID|HDR_CSEQ );
151
+   parse_headers(p_msg, HDR_EOH );
152 152
    new_cell->inbound_request =  sip_msg_cloner(p_msg) ;
153 153
    /* inbound response is NULL*/
154 154
    /* status is 0 */
... ...
@@ -51,11 +51,16 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
51 51
 
52 52
     /* via1 (via_body* type) */
53 53
     if (org_msg->via1)
54
-	 new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , org_msg->via1 );
54
+         new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , org_msg->via1 );
55 55
 
56 56
     /* via2 (via_body* type) */
57 57
     if (org_msg->via2)
58
-	new_msg->via2 = via_body_cloner( new_msg->buf , org_msg->buf , org_msg->via2 );
58
+    {
59
+        if (org_msg->via1 && org_msg->via1->next )
60
+            new_msg->via2 = new_msg->via1->next;
61
+        else
62
+            new_msg->via2 = via_body_cloner( new_msg->buf , org_msg->buf , org_msg->via2 );
63
+    }
59 64
 
60 65
     /* all the headers */
61 66
     new_msg->h_via1=0;
... ...
@@ -91,6 +96,7 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
91 96
 		  new_hdr->parsed = (void*)sh_malloc( sizeof(struct cseq_body) );
92 97
 		  memcpy( new_hdr->parsed , header->parsed , sizeof(struct cseq_body) );
93 98
 		  ((struct cseq_body*)new_hdr->parsed)->number.s = translate_pointer( new_msg->buf , org_msg->buf , ((struct cseq_body*)header->parsed)->number.s );
99
+		  ((struct cseq_body*)new_hdr->parsed)->method.s = translate_pointer( new_msg->buf , org_msg->buf , ((struct cseq_body*)header->parsed)->method.s );
94 100
 		}
95 101
 		new_msg->cseq = new_hdr;
96 102
 		break;
... ...
@@ -188,7 +194,9 @@ struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_bod
188 194
     }
189 195
 
190 196
     if ( new_via->next )
191
-	new_via->next = via_body_cloner( new_buf , org_buf , org_via->next );
197
+        new_via->next = via_body_cloner( new_buf , org_buf , org_via->next );
198
+
199
+   return new_via;
192 200
 }
193 201
 
194 202
 
... ...
@@ -224,7 +232,52 @@ char*   translate_pointer( char* new_buf , char *org_buf , char* p)
224 232
 
225 233
 /* Frees the memory occupied by a SIP message
226 234
   */
227
-void free_uri(struct sip_uri* u)
235
+void sh_free_lump(struct lump* lmp)
236
+{
237
+	if (lmp && (lmp->op==LUMP_ADD)){
238
+		if (lmp->u.value) sh_free(lmp->u.value);
239
+		lmp->u.value=0;
240
+		lmp->len=0;
241
+	}
242
+}
243
+
244
+
245
+
246
+void sh_free_lump_list(struct lump* l)
247
+{
248
+	struct lump* t, *r, *foo,*crt;
249
+	t=l;
250
+	while(t){
251
+		crt=t;
252
+		t=t->next;
253
+	/*
254
+		 dangerous recursive clean
255
+		if (crt->before) free_lump_list(crt->before);
256
+		if (crt->after)  free_lump_list(crt->after);
257
+	*/
258
+		/* no more recursion, clean after and before and that's it */
259
+		r=crt->before;
260
+		while(r){
261
+			foo=r; r=r->before;
262
+			sh_free_lump(foo);
263
+			sh_free(foo);
264
+		}
265
+		r=crt->after;
266
+		while(r){
267
+			foo=r; r=r->after;
268
+			sh_free_lump(foo);
269
+			sh_free(foo);
270
+		}
271
+
272
+		/*clean current elem*/
273
+		sh_free_lump(crt);
274
+		sh_free(crt);
275
+	}
276
+}
277
+
278
+
279
+
280
+void sh_free_uri(struct sip_uri* u)
228 281
 {
229 282
    if (u)
230 283
    {
... ...
@@ -245,7 +298,7 @@ void free_uri(struct sip_uri* u)
245 298
 
246 299
 
247 300
 
248
-void free_via_param_list(struct via_param* vp)
301
+void sh_free_via_param_list(struct via_param* vp)
249 302
 {
250 303
    struct via_param* foo;
251 304
    while(vp)
... ...
@@ -258,7 +311,7 @@ void free_via_param_list(struct via_param* vp)
258 311
 
259 312
 
260 313
 
261
-void free_via_list(struct via_body* vb)
314
+void sh_free_via_list(struct via_body* vb)
262 315
 {
263 316
    struct via_body* foo;
264 317
    while(vb)
... ...
@@ -266,7 +319,7 @@ void free_via_list(struct via_body* vb)
266 319
       foo=vb;
267 320
       vb=vb->next;
268 321
      if (foo->param_lst)
269
-        free_via_param_list(foo->param_lst);
322
+        sh_free_via_param_list(foo->param_lst);
270 323
       sh_free(foo);
271 324
     }
272 325
 }
... ...
@@ -274,21 +327,22 @@ void free_via_list(struct via_body* vb)
274 327
 
275 328
 /* frees a hdr_field structure,
276 329
  * WARNING: it frees only parsed (and not name.s, body.s)*/
277
-void clean_hdr_field(struct hdr_field* hf)
330
+void sh_clean_hdr_field(struct hdr_field* hf)
278 331
 {
279 332
    if (hf->parsed)
280 333
    {
281 334
       switch(hf->type)
282 335
       {
283 336
          case HDR_VIA:
284
-   DBG("DEBUG: sip_msg_free : via headers\n");
285
-               free_via_list(hf->parsed);
337
+   DBG("DEBUG: sh_clean_hdr_field : via headers\n");
338
+               sh_free_via_list(hf->parsed);
286 339
              break;
287 340
          case HDR_CSEQ:
288
-   DBG("DEBUG: sip_msg_free : cseq headers\n");
341
+   DBG("DEBUG: sh_clean_hdr_field : cseq headers\n");
289 342
                 sh_free(hf->parsed);
290 343
              break;
291 344
          default:
345
+   DBG("DEBUG: sh_clean_hdr_field : unknown headers\n");
292 346
       }
293 347
    }
294 348
 }
... ...
@@ -297,18 +351,17 @@ void clean_hdr_field(struct hdr_field* hf)
297 351
 
298 352
 /* frees a hdr_field list,
299 353
  * WARNING: frees only ->parsed and ->next*/
300
-void free_hdr_field_lst(struct hdr_field* hf)
354
+void sh_free_hdr_field_lst(struct hdr_field* hf)
301 355
 {
302 356
    struct hdr_field* foo;
303
-  DBG("DEBUG: free_hdr_field_lst : \n");
304 357
 
305 358
    while(hf)
306 359
     {
307
-      DBG("DEBUG: free_hdr_field_lst : \n");
360
+      DBG("DEBUG: free_hdr_field_lst : %s [%d]\n",hf->name.s, hf->type);
308 361
        foo=hf;
309 362
        hf=hf->next;
310
-       clean_hdr_field(foo);
311
-       pkg_free(foo);
363
+       sh_clean_hdr_field(foo);
364
+       sh_free(foo);
312 365
     }
313 366
 }
314 367
 
... ...
@@ -319,20 +372,20 @@ void sip_msg_free(struct sip_msg* msg)
319 372
 {
320 373
    if (!msg) return;
321 374
 
375
+   DBG("DEBUG: sip_msg_free : start\n");
376
+
322 377
    if (msg->new_uri.s)
323 378
    {
324 379
       sh_free(msg->new_uri.s);
325 380
       msg->new_uri.len=0;
326 381
    }
327
-   LOG(L_ERR, "ERROR: sip_msg_free : headers and via1/via2 freeing still missing\n");
328
-   //if (msg->headers)
329
-    //  free_hdr_field_lst(msg->headers);
330
-   DBG("DEBUG: sip_msg_free : lump\n");
382
+   if (msg->headers)
383
+      sh_free_hdr_field_lst(msg->headers);
331 384
    if (msg->add_rm)
332
-      free_lump_list(msg->add_rm);
385
+      sh_free_lump_list(msg->add_rm);
333 386
    if (msg->repl_add_rm)
334
-      free_lump_list(msg->repl_add_rm);
387
+      sh_free_lump_list(msg->repl_add_rm);
335 388
    if (msg->orig) sh_free( msg->orig );
336 389
    if (msg->buf) sh_free( msg->buf );
337
-   
390
+
338 391
 }
... ...
@@ -172,14 +172,14 @@ int t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  )
172 172
       { /* it's a ACK request*/
173 173
          /* first only the length are checked */
174 174
          if ( /*from length*/ p_cell->inbound_request->from->body.len == p_msg->from->body.len )
175
-            if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
175
+            //if ( /*to length*/ p_cell->inbound_request->to->body.len == p_msg->to->body.len )
176 176
                if ( /*callid length*/ p_cell->inbound_request->callid->body.len == p_msg->callid->body.len )
177 177
                   if ( /*cseq_nr length*/ get_cseq(p_cell->inbound_request)->number.len == get_cseq(p_msg)->number.len )
178 178
                       if ( /*cseq_method type*/ p_cell->inbound_request->first_line.u.request.method_value == METHOD_INVITE  )
179 179
                          //if ( /*tag length*/ p_cell->tag &&  p_cell->tag->len==p_msg->tag->body.len )
180 180
                             /* so far the lengths are the same -> let's check the contents */
181 181
                             if ( /*from*/ !memcmp( p_cell->inbound_request->from->body.s , p_msg->from->body.s , p_msg->from->body.len ) )
182
-                               if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
182
+                               //if ( /*to*/ !memcmp( p_cell->inbound_request->to->body.s , p_msg->to->body.s , p_msg->to->body.len)  )
183 183
                                   //if ( /*tag*/ !memcmp( p_cell->tag->s , p_msg->tag->body.s , p_msg->tag->body.len ) )
184 184
                                      if ( /*callid*/ !memcmp( p_cell->inbound_request->callid->body.s , p_msg->callid->body.s , p_msg->callid->body.len ) )
185 185
                                         if ( /*cseq_nr*/ !memcmp( get_cseq(p_cell->inbound_request)->number.s , get_cseq(p_msg)->number.s , get_cseq(p_msg)->number.len ) )
... ...
@@ -393,7 +393,7 @@ int t_forward_uri( struct sip_msg* p_msg, char* foo, char* bar  )
393 393
   */
394 394
 int t_on_reply_received( struct sip_msg  *p_msg )
395 395
 {
396
-   unsigned int  branch;
396
+   unsigned int  branch,len;
397 397
 
398 398
    global_msg_id = p_msg->id;
399 399
 
... ...
@@ -403,16 +403,18 @@ int t_on_reply_received( struct sip_msg  *p_msg )
403 403
    /* if no T found ->tell the core router to forward statelessly */
404 404
    if ( T<=0 )
405 405
       return 1;
406
+   DBG("DEBUG: t_on_reply_received: Original status =%d\n",T->status);
406 407
 
407 408
    /* stop retransmission */
408 409
    remove_from_timer_list( hash_table , &(T->outbound_request[branch]->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST );
410
+   // ??? what about FR_TIMER ????
409 411
 
410 412
    /* on a non-200 reply to INVITE, generate local ACK */
411 413
    if ( T->inbound_request->first_line.u.request.method_value==METHOD_INVITE && p_msg->first_line.u.reply.statusclass>2 )
412 414
    {
413 415
       DBG("DEBUG: t_on_reply_received: >=3xx reply to INVITE: send ACK\n");
414
-      t_build_and_send_ACK( T , branch );
415
-      t_store_incoming_reply( T , branch , p_msg );
416
+      //t_store_incoming_reply( T , branch , p_msg );
417
+      t_build_and_send_ACK( T , branch , p_msg );
416 418
    }
417 419
 
418 420
    #ifdef FORKING
... ...
@@ -420,7 +422,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
420 422
    #endif
421 423
 
422 424
    /*let's check the current inbound response status (is final or not) */
423
-   if ( T->inbound_response && (T->status/100)>1 )
425
+   if ( T->inbound_response[branch] && (T->status/100)>1 )
424 426
    {  /*a final reply was already sent upstream */
425 427
       /* alway relay 2xx immediately ; drop anything else */
426 428
       DBG("DEBUG: t_on_reply_received: something final had been relayed\n");
... ...
@@ -444,7 +446,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
444 446
       /* relay ringing and OK immediately */
445 447
       if ( p_msg->first_line.u.reply.statusclass ==1 || p_msg->first_line.u.reply.statusclass ==2  )
446 448
       {
447
-	   DBG("DEBUG: t_on_reply_received:  relay ringing and OK immediately \n");
449
+           DBG("DEBUG: t_on_reply_received:  relay ringing and OK immediately \n");
448 450
            if ( p_msg->first_line.u.reply.statuscode > T->status )
449 451
               t_relay_reply( T , branch , p_msg );
450 452
          return 0;
... ...
@@ -453,7 +455,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
453 455
       /* error final responses are only stored */
454 456
       if ( p_msg->first_line.u.reply.statusclass>=3 && p_msg->first_line.u.reply.statusclass<=5 )
455 457
       {
456
-	   DBG("DEBUG: t_on_reply_received:  error final responses are only stored  \n");
458
+         DBG("DEBUG: t_on_reply_received:  error final responses are only stored  \n");
457 459
          t_store_incoming_reply( T , branch , p_msg );
458 460
          if ( t_all_final(T) )
459 461
               relay_lowest_reply_upstream( T , p_msg );
... ...
@@ -588,6 +590,7 @@ int t_send_reply(  struct sip_msg* p_msg , unsigned int code , char * text )
588 590
 
589 591
       T->outbound_response->tl[RETRASMISSIONS_LIST].payload = T->outbound_response;
590 592
       T->outbound_response->tl[FR_TIMER_LIST].payload = T->outbound_response;
593
+      T->outbound_response->to.sin_family = AF_INET;
591 594
       T->outbound_response->my_T = T;
592 595
    }
593 596
 
... ...
@@ -741,20 +744,21 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
741 744
    /* split the branch into pieces: loop_detection_check(ignored),
742 745
       hash_table_id, synonym_id, branch_id
743 746
    */
747
+
744 748
    if (! ( p_msg->via1 && p_msg->via1->branch && p_msg->via1->branch->value.s) )
745 749
 	goto nomatch;
746 750
 
747 751
    p=p_msg->via1->branch->value.s;
748 752
    scan_space=p_msg->via1->branch->value.len;
749 753
 
750
-   /* loop detection ... ignore */ 
754
+   /* loop detection ... ignore */
751 755
    n=eat_token2_end( p, p+scan_space, '.');
752 756
    scan_space-=n-p;
753 757
    if (n==p || scan_space<2 || *n!='.') goto nomatch;
754 758
    p=n+1; scan_space--;
755 759
 
756 760
    /* hash_id */
757
-   n=eat_token2_end( p, p+scan_space, '.'); 
761
+   n=eat_token2_end( p, p+scan_space, '.');
758 762
    hashl=n-p;
759 763
    scan_space-=hashl;
760 764
    if (!hashl || scan_space<2 || *n!='.') goto nomatch;
... ...
@@ -773,7 +777,7 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
773 777
    /* branch id */  /*  should exceed the scan_space */
774 778
    n=eat_token_end( p, p+scan_space );
775 779
    branchl=n-p;
776
-   if (!branchl ) goto nomatch; 
780
+   if (!branchl ) goto nomatch;
777 781
    branchi=p;
778 782
 
779 783
 
... ...
@@ -781,7 +785,7 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
781 785
    entry_label=str_unsigned_hex_2_int(syni, synl);
782 786
    branch_id=str_unsigned_hex_2_int(branchi, branchl);
783 787
 
784
-   DBG("DEBUG: t_reply_matching: hash %d label %d branch %d\n", 
788
+   DBG("DEBUG: t_reply_matching: hash %d label %d branch %d\n",
785 789
 	hash_index, entry_label, branch_id );
786 790
 
787 791
    /* sanity check */
... ...
@@ -799,13 +803,14 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
799 803
       /* the transaction is referenceted for reading */
800 804
       ref_cell( p_cell );
801 805
       /* is it the cell with the wanted entry_label? */
802
-      if ( p_cell->label = entry_label )
806
+      if ( p_cell->label == entry_label )
803 807
       /* has the transaction the wanted branch? */
804 808
       if ( p_cell->nr_of_outgoings>branch_id && p_cell->outbound_request[branch_id] )
805 809
       {/* WE FOUND THE GOLDEN EGG !!!! */
806 810
 		*p_Trans = p_cell;
807 811
 		*p_branch = branch_id;
808 812
 		unref_cell( p_cell );
813
+                              DBG("DEBUG: t_reply_matching: reply matched!\n");
809 814
 		return 1;
810 815
 	}
811 816
       /* next cell */
... ...
@@ -838,8 +843,16 @@ int t_store_incoming_reply( struct cell* Trans, unsigned int branch, struct sip_
838 843
    if ( Trans->inbound_response[branch] )
839 844
       free_sip_msg( Trans->inbound_response[branch] ) ;
840 845
    /* force parsing all the needed headers*/
841
-   parse_headers(p_msg, HDR_VIA|HDR_TO|HDR_FROM|HDR_CALLID|HDR_CSEQ );
846
+   if ( parse_headers(p_msg, HDR_VIA1|HDR_VIA2|HDR_TO )==-1 ||
847
+        !p_msg->via1 || !p_msg->via2 || !p_msg->to )
848
+   {
849
+      LOG( L_ERR , "ERROR: t_store_incoming_reply: unable to parse headers !\n"  );
850
+      return -1;
851
+   }
842 852
    Trans->inbound_response[branch] = sip_msg_cloner( p_msg );
853
+   Trans->status = p_msg->first_line.u.reply.statuscode;
854
+   DBG("DEBUG: t_store_incoming_reply: reply stored\n");
855
+   return 1;
843 856
 }
844 857
 
845 858
 
... ...
@@ -895,10 +908,11 @@ int t_all_final( struct cell *Trans )
895 908
    unsigned int i;
896 909
 
897 910
    for( i=0 ; i<Trans->nr_of_outgoings ; i++  )
898
-      if (  !Trans->inbound_response[i] || (Trans->inbound_response[i]) && Trans->inbound_response[i]->first_line.u.reply.statuscode<200 )
911
+      if (  !Trans->inbound_response[i] ||  Trans->inbound_response[i]->first_line.u.reply.statuscode<=200 )
899 912
          return 0;
900 913
 
901
-   return 1;
914
+  DBG("DEBUG: t_all_final: final state!!!!:)) \n");
915
+  return 1;
902 916
 }
903 917
 
904 918
 
... ...
@@ -922,6 +936,8 @@ int relay_lowest_reply_upstream( struct cell *Trans , struct sip_msg *p_msg )
922 936
          lowest_v = T->inbound_response[i]->first_line.u.reply.statuscode;
923 937
       }
924 938
 
939
+   DBG("DEBUG: relay_lowest_reply_upstream: lowest reply [%d]=%d\n",lowest_i,lowest_v);
940
+
925 941
    if ( lowest_i != -1 )
926 942
       push_reply_from_uac_to_uas( T ,lowest_i );
927 943
 
... ...
@@ -944,6 +960,7 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
944 960
    {
945 961
       sh_free( trans->outbound_response->retr_buffer );
946 962
       remove_from_timer_list( hash_table , &(trans->outbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST );
963
+      // final response ????
947 964
    }
948 965
    else
949 966
    {
... ...
@@ -956,8 +973,13 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
956 973
 	trans->outbound_response = NULL;
957 974
 	return -1;
958 975
       }
976
+      /*init retrans buffer*/
959 977
       memset( trans->outbound_response , 0 , sizeof (struct retrans_buff) );
960 978
       trans->outbound_response->tl[RETRASMISSIONS_LIST].payload = trans->outbound_response;
979
+      trans->outbound_response->tl[FR_TIMER_LIST].payload = trans->outbound_response;
980
+      trans->outbound_response->to.sin_family = AF_INET;
981
+      trans->outbound_response->my_T = trans;
982
+
961 983
       if (update_sock_struct_from_via(  &(trans->outbound_response->to),  trans->inbound_response[branch]->via2 )==-1) {
962 984
 	LOG(L_ERR, "ERROR: push_reply_from_uac_to_uas: cannot lookup reply dst: %s\n",
963 985
 		trans->inbound_response[branch]->via2->host.s );
... ...
@@ -968,7 +990,9 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
968 990
    }
969 991
 
970 992
    /*  */
993
+   DBG("DEBUG: push_reply_from_uac_to_uas: building buf from response\n");
971 994
    buf = build_res_buf_from_sip_res ( trans->inbound_response[branch], &len);
995
+   DBG("DEBUG: push_reply_from_uac_to_uas: after building\n");
972 996
    if (!buf) {
973 997
 	LOG(L_ERR, "ERROR: push_reply_from_uac_to_uas: no shmem for outbound reply buffer\n");
974 998
         return -1;
... ...
@@ -979,10 +1003,24 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
979 1003
    free( buf ) ;
980 1004
 
981 1005
    /* make sure that if we send something final upstream, everything else will be cancelled */
1006
+   if ( trans->status>=300 &&  trans->inbound_request->first_line.u.request.method_value==METHOD_INVITE )
1007
+   {
1008
+            T->outbound_response->timeout_ceiling  = RETR_T2;
1009
+            T->outbound_response->timeout_value    = RETR_T1;
1010
+            remove_from_timer_list( hash_table , &(T->outbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST );
1011
+            insert_into_timer_list( hash_table , &(T->outbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST , RETR_T1 );
1012
+            remove_from_timer_list( hash_table , &(T->outbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST );
1013
+            insert_into_timer_list( hash_table , &(T->outbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST , FR_TIME_OUT );
1014
+   }
1015
+   else if (trans->status>=200)
1016
+            t_put_on_wait( trans->inbound_request );
1017
+
1018
+    /*
1019
+   // make sure that if we send something final upstream, everything else will be cancelled
982 1020
    if (trans->inbound_response[branch]->first_line.u.reply.statusclass>=2 )
983 1021
       t_put_on_wait( trans->inbound_request );
984 1022
 
985
-   /* if the code is 3,4,5,6 class for an INVITE-> starts retrans timer*/
1023
+   // if the code is 3,4,5,6 class for an INVITE-> starts retrans timer
986 1024
    if ( trans->inbound_request->first_line.u.request.method_value==METHOD_INVITE &&
987 1025
          trans->inbound_response[branch]->first_line.u.reply.statusclass>=300)
988 1026
          {
... ...
@@ -991,7 +1029,7 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
991 1029
             insert_into_timer_list( hash_table , &(trans->outbound_response->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST , RETR_T1 );
992 1030
             insert_into_timer_list( hash_table , &(trans->outbound_response->tl[FR_TIMER_LIST]) , FR_TIMER_LIST , FR_TIME_OUT );
993 1031
          }
994
-
1032
+    */
995 1033
    t_retransmit_reply( trans->inbound_request, 0 , 0 );
996 1034
 }
997 1035
 
... ...
@@ -1016,48 +1054,83 @@ int copy_hf( char **dst, struct hdr_field* hf, char *bumper )
1016 1054
    *dst+= hf->name.len ;
1017 1055
    **dst = ':'; (*dst)++;
1018 1056
    **dst = ' '; (*dst)++;
1019
-   memcpy(*dst, hf->body.s, hf->body.len);
1057
+   memcpy(*dst, hf->body.s, hf->body.len-1);
1020 1058
    *dst+= hf->body.len;
1021 1059
    memcpy( *dst, CRLF, CRLF_LEN );
1022 1060
    *dst+=CRLF_LEN;
1023 1061
    return 0;
1024 1062
 }
1025
-  
1063
+
1026 1064
 
1027 1065
 
1028 1066
 
1029 1067
 /* Builds an ACK request based on an INVITE request. ACK is send
1030 1068
   * to same address
1031 1069
   */
1032
-int t_build_and_send_ACK( struct cell *Trans, unsigned int branch)
1070
+int t_build_and_send_ACK( struct cell *Trans, unsigned int branch, struct sip_msg* rpl)
1033 1071
 {
1034
-    struct sip_msg* p_msg = T->inbound_request;
1072
+   struct sip_msg* p_msg , *r_msg;
1035 1073
     struct via_body *via;
1036 1074
     struct hdr_field *hdr;
1037
-    char *ack_buf=NULL, *p;
1075
+    char *ack_buf, *p;
1038 1076
     unsigned int len;
1039 1077
     int n;
1040 1078
 
1041
-   /* enough place for first line and Via ? */
1079
+
1080
+   p_msg = T->inbound_request;
1081
+   r_msg = rpl;
1082
+
1083
+   if ( parse_headers(rpl,HDR_TO)==-1 || !rpl->to )
1084
+   {
1085
+	LOG(L_ERR, "ERROR: t_build_and_send_ACK: cannot generate a HBH ACK if key HFs in INVITE missing\n");
1086
+	goto error;
1087
+   }
1088
+
1089
+    len = 0;
1090
+    /*first line's len */
1091
+    len += 4+p_msg->first_line.u.request.uri.len+1+p_msg->first_line.u.request.version.len+CRLF_LEN;
1092
+    /*via*/
1093
+    len+= MY_VIA_LEN + names_len[0] + 1+ port_no_str_len + MY_BRANCH_LEN + 3*sizeof(unsigned int) /*branch*/ + CRLF_LEN;
1094
+    /*headers*/
1095
+   for ( hdr=p_msg->headers ; hdr ; hdr=hdr->next )
1096
+      if ( hdr->type==HDR_FROM || hdr->type==HDR_CALLID || hdr->type==HDR_CSEQ )
1097
+                 len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) ;
1098
+      else if ( hdr->type==HDR_TO )
1099
+                 len += ((r_msg->to->body.s+r_msg->to->body.len ) - r_msg->to->name.s ) ;
1100
+
1101
+   /* CSEQ method : from INVITE-> ACK*/
1102
+   len -= 3;
1103
+   /* end of message */
1104
+   len += CRLF_LEN; /*new line*/
1105
+
1106
+   /*
1107
+   // enough place for first line and Via ?
1042 1108
    if ( 4 + p_msg->first_line.u.request.uri.len + 1 + p_msg->first_line.u.request.version.len +
1043
-	CRLF_LEN + MY_VIA_LEN + names_len[0] + 1 + port_no_str_len + MY_BRANCH_LEN  < MAX_ACK_LEN ) {
1109
+	CRLF_LEN + MY_VIA_LEN + names_len[0] + 1 + port_no_str_len + MY_BRANCH_LEN  > MAX_ACK_LEN ) {
1044 1110
 		LOG( L_ERR, "ERROR: t_build_and_send_ACK: no place for FL/Via\n");
1045 1111
 		goto error;
1046 1112
    }
1113
+   */
1114
+   ack_buf = (char *)malloc( len +1);
1115
+   if (!ack_buf)
1116
+   {
1117
+       LOG(L_ERR, "ERROR: t_build_and_send_ACK: cannot allocate memory\n");
1118
+       goto error;
1119
+   }
1047 1120
 
1048
-   ack_buf = (char *)malloc( MAX_ACK_LEN );
1049 1121
    p = ack_buf;
1122
+   DBG("DEBUG: t_build_and_send_ACK: len = %d \n",len);
1050 1123
 
1051 1124
    /* first line */
1052 1125
    memcpy( p , "ACK " , 4);
1053 1126
    p += 4;
1054 1127
 
1055
-   memcpy( p , p_msg->first_line.u.request.uri.s , p_msg->first_line.u.request.uri.len );
1128
+   memcpy( p , p_msg->orig+(p_msg->first_line.u.request.uri.s-p_msg->buf) , p_msg->first_line.u.request.uri.len );
1056 1129
    p += p_msg->first_line.u.request.uri.len;
1057 1130
 
1058 1131
    *(p++) = ' ';
1059 1132
 
1060
-   memcpy( p , p_msg->first_line.u.request.version.s , p_msg->first_line.u.request.version.len );
1133
+   memcpy( p , p_msg->orig+(p_msg->first_line.u.request.version.s-p_msg->buf) , p_msg->first_line.u.request.version.len );
1061 1134
    p += p_msg->first_line.u.request.version.len;
1062 1135
 
1063 1136
    memcpy( p, CRLF, CRLF_LEN );
... ...
@@ -1070,7 +1143,7 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch)
1070 1143
    memcpy( p , names[0] , names_len[0] );
1071 1144
    p += names_len[0];
1072 1145
 
1073
-   *(p++) = ':';
1146
+  // *(p++) = ':';
1074 1147
 
1075 1148
    memcpy( p , port_no_str , port_no_str_len );
1076 1149
    p += port_no_str_len;
... ...
@@ -1078,37 +1151,59 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch)
1078 1151
    memcpy( p, MY_BRANCH, MY_BRANCH_LEN );
1079 1152
    p+=MY_BRANCH_LEN;
1080 1153
 
1081
-   n=snprintf( p, ack_buf + MAX_ACK_LEN - p,
1082
-                 ".%x.%x.%x%s",
1154
+   n=sprintf( p /*, ack_buf + MAX_ACK_LEN - p*/, ".%x.%x.%x%s",
1083 1155
                  Trans->hash_index, Trans->label, branch, CRLF );
1084 1156
 
1085 1157
    if (n==-1) {
1086
-	LOG(L_ERR, "ERROR: t_build_and_send_ACK: not enough memory for branch\n");
1158
+	LOG(L_ERR, "ERROR: t_build_and_send_ACK: unable to generate branch\n");
1087 1159
 	goto error;
1088 1160
    }
1089 1161
    p+=n;
1090 1162
 
1091
-   if (!check_transaction_quadruple( p_msg )) {
1092
-	LOG(L_ERR, "ERROR: t_build_and_send_ACK: cannot generate a HBH ACK if key HFs in INVITE missing\n");
1093
-	goto error;
1094
-   }
1095 1163
 
1096
-   /* To */
1164
+
1165
+   for ( hdr=p_msg->headers ; hdr ; hdr=hdr->next )
1166
+   {
1167
+      if ( hdr->type==HDR_FROM || hdr->type==HDR_CALLID  )
1168
+	{
1169
+		memcpy( p , p_msg->orig+(hdr->name.s-p_msg->buf) ,
1170
+			((hdr->body.s+hdr->body.len ) - hdr->name.s ) );
1171
+		p += ((hdr->body.s+hdr->body.len ) - hdr->name.s );
1172
+	}
1173
+      else if ( hdr->type==HDR_TO )
1174
+	{
1175
+		memcpy( p , r_msg->orig+(r_msg->to->name.s-r_msg->buf) ,
1176
+			((r_msg->to->body.s+r_msg->to->body.len ) - r_msg->to->name.s ) );
1177
+		p += ((r_msg->to->body.s+r_msg->to->body.len ) - r_msg->to->name.s );
1178
+	}
1179
+       else if ( hdr->type==HDR_CSEQ )
1180
+	{
1181
+		memcpy( p , p_msg->orig+(hdr->name.s-p_msg->buf) ,
1182
+			(( ((struct cseq_body*)hdr->parsed)->method.s ) - hdr->name.s ) );
1183
+		p += (( ((struct cseq_body*)hdr->parsed)->method.s ) - hdr->name.s );
1184
+		memcpy( p , "ACK" CRLF, 3+CRLF_LEN );
1185
+		p += 3+CRLF_LEN;
1186
+	}
1187
+    }
1188
+
1189
+
1190
+/*
1191
+   // To
1097 1192
    if (copy_hf( &p, p_msg->to , ack_buf + MAX_ACK_LEN )==-1) {
1098 1193
 	LOG(L_ERR, "ERROR: t_build_and_send_ACK: no place for To\n");
1099 1194
 	goto error;
1100 1195
    }
1101
-   /* From */
1196
+   // From
1102 1197
    if (copy_hf( &p, p_msg->from, ack_buf + MAX_ACK_LEN )==-1) {
1103 1198
 	LOG(L_ERR, "ERROR: t_build_and_send_ACK: no place for From\n");
1104 1199
 	goto error;
1105 1200
    }
1106
-   /* CallId */
1201
+   // CallId
1107 1202
    if (copy_hf( &p, p_msg->callid, ack_buf + MAX_ACK_LEN )==-1) {
1108 1203
 	LOG(L_ERR, "ERROR: t_build_and_send_ACK: no place for callid\n");
1109 1204
 	goto error;
1110 1205
    }
1111
-   /* CSeq, EoH */
1206
+   // CSeq, EoH
1112 1207
    n=snprintf( p, ack_buf + MAX_ACK_LEN - p,
1113 1208
                  "Cseq: %*s ACK%s%s", get_cseq(p_msg)->number.len,
1114 1209
 		get_cseq(p_msg)->number.s, CRLF, CRLF );
... ...
@@ -1117,10 +1212,13 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch)
1117 1212
 	goto error;
1118 1213
    }
1119 1214
    p+=n;
1120
-
1215
+*/
1216
+    memcpy( p , CRLF , CRLF_LEN );
1217
+    p += CRLF_LEN;
1121 1218
 
1122 1219
    /* sends the ACK message to the same destination as the INVITE */
1123 1220
    udp_send( ack_buf, p-ack_buf, (struct sockaddr*)&(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) );
1221
+   DBG("DEBUG: t_build_and_send_ACK: ACK sent\n",);
1124 1222
 
1125 1223
    /* free mem*/
1126 1224
    if (ack_buf) free( ack_buf );
... ...
@@ -114,7 +114,7 @@ int t_store_incoming_reply( struct cell* , unsigned int , struct sip_msg* );
114 114
 int t_relay_reply( struct cell* , unsigned int , struct sip_msg* );
115 115
 int t_check( struct s_table* , struct sip_msg*  );
116 116
 int t_all_final( struct cell * );
117
-int t_build_and_send_ACK( struct cell *Trans , unsigned int brach );
117
+int t_build_and_send_ACK( struct cell *Trans , unsigned int brach , struct sip_msg* rpl);
118 118
 int relay_lowest_reply_upstream( struct cell *Trans , struct sip_msg *p_msg );
119 119
 int push_reply_from_uac_to_uas( struct cell* Trans , unsigned int );
120 120
 int t_cancel_branch(unsigned int branch); //TO DO
... ...
@@ -24,6 +24,7 @@
24 24
 static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2);
25 25
 static int w_t_forward(struct sip_msg* msg, char* str, char* str2);
26 26
 static int w_t_forward_def(struct sip_msg* msg, char* str, char* str2);
27
+static int w_t_put_on_wait(struct sip_msg* msg, char* str, char* str2);
27 28
 static int fixup_t_forward(void** param, int param_no);
28 29
 static int fixup_t_forward_def(void** param, int param_no);
29 30
 static int fixup_t_send_reply(void** param, int param_no);
... ...
@@ -47,7 +48,7 @@ static struct module_exports nm_exports= {
47 48
 					t_forward_uri,
48 49
 					w_t_send_reply,
49 50
 					t_retransmit_reply,
50
-					t_put_on_wait
51
+					w_t_put_on_wait
51 52
 					},
52 53
 	(int[]){
53 54
 				0,
... ...
@@ -213,6 +214,10 @@ static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2)
213 214
 	return t_send_reply(msg, (unsigned int) str, str2);
214 215
 }
215 216
 
217
+static int w_t_put_on_wait(struct sip_msg* msg, char* str, char* str2)
218
+{
219
+	return t_put_on_wait(msg);
220
+}
216 221
 
217 222
 
218 223
 
... ...
@@ -677,7 +677,7 @@ error:
677 677
    time; if you call it twice and the HF is found on second time too,
678 678
    it's not replaced in the well-known HF pointer but just added to
679 679
    header list; if you want to use a dumbie convenience function which will
680
-   give you the first occurance of a header you are interested in, 
680
+   give you the first occurance of a header you are interested in,
681 681
    look at check_transaction_quadruple
682 682
 */
683 683
 int parse_headers(struct sip_msg* msg, int flags)
... ...
@@ -686,10 +686,10 @@ int parse_headers(struct sip_msg* msg, int flags)
686 686
 	char* tmp;
687 687
 	char* rest;
688 688
 	char* end;
689
-	
689
+
690 690
 	end=msg->buf+msg->len;
691 691
 	tmp=msg->unparsed;
692
-	
692
+
693 693
 	DBG("parse_headers: flags=%d\n", flags);
694 694
 	while( tmp<end && (flags & msg->parsed_flag) != flags){
695 695
 		hf=pkg_malloc(sizeof(struct hdr_field));
... ...
@@ -707,6 +707,7 @@ int parse_headers(struct sip_msg* msg, int flags)
707 707
 			case HDR_EOH:
708 708
 				msg->eoh=tmp; /* or rest?*/
709 709
 				msg->parsed_flag|=HDR_EOH;
710
+				pkg_free(hf);
710 711
 				goto skip;
711 712
 			case HDR_OTHER: /*do nothing*/
712 713
 				break;
... ...
@@ -769,7 +770,7 @@ int parse_headers(struct sip_msg* msg, int flags)
769 770
 skip:
770 771
 	msg->unparsed=tmp;
771 772
 	return 0;
772
-	
773
+
773 774
 error:
774 775
 	if (hf) pkg_free(hf);
775 776
 	return -1;