Browse code

the famous bug fixed!

Bogdan-Andrei Iancu authored on 05/12/2001 21:09:01
Showing 4 changed files
... ...
@@ -40,7 +40,7 @@ NAME=ser
40 40
 #                  twice, trying to free a pointer alloc'ed with a different
41 41
 #                  malloc etc.)
42 42
 DEFS=-DTHREAD -DNOCR -DMACROEATER -DDNS_IP_HACK  -DSHM_MEM \
43
-	 -DPKG_MALLOC -DDBG_QM_MALLOC#-DNO_DEBUG
43
+	 -DPKG_MALLOC #-DDBG_QM_MALLOC -DNO_DEBUG
44 44
 # -DUSE_SHM_MEM
45 45
 #-DNO_DEBUG 
46 46
 #-DPKG_MALLOC
... ...
@@ -49,41 +49,37 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
49 49
 	new_msg->first_line.u.reply.reason.s =  translate_pointer( new_msg->buf , org_msg->buf , org_msg->first_line.u.reply.reason.s );
50 50
     }
51 51
 
52
-    /* via1 (via_body* type) */
53
-    if (org_msg->via1)
54
-         new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , org_msg->via1 );
55
-
56
-    /* via2 (via_body* type) */
57
-    if (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
-    }
64
-
65 52
     /* all the headers */
66
-    new_msg->h_via1=0;
67
-    new_msg->h_via2=0;
68
-    for( header = org_msg->headers , last_hdr=0  ;  header;header=header->next)
53
+    new_msg->via1=0;
54
+    new_msg->via2=0;
55
+    for( header = org_msg->headers , last_hdr=0  ;  header ; header=header->next)
69 56
     {
70 57
 	switch ( header->type )
71 58
 	{
72
-	    case HDR_VIA1 :
59
+	    case HDR_VIA :
73 60
 		new_hdr = header_cloner( new_msg , org_msg , header );
74
-		new_hdr->parsed  = (void*)new_msg->via1;
75
-		if (new_msg->h_via1==0)
61
+		if ( !new_msg->via1 )
62
+		{
76 63
 		    new_msg->h_via1 = new_hdr;
77
-		else if(new_msg->h_via2==0)
78
-		    new_msg->h_via2 = new_hdr;
79
-		break;
80
-	    case HDR_CALLID :
81
-		new_hdr = header_cloner( new_msg , org_msg , header );
82
-		new_msg->callid = new_hdr;
83
-		break;
84
-	    case HDR_TO :
85
-		new_hdr = header_cloner( new_msg , org_msg , header );
86
-		new_msg->to = new_hdr;
64
+		    new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
65
+		    new_hdr->parsed  = (void*)new_msg->via1;
66
+		     if ( new_msg->via1->next )
67
+		        new_msg->via2 = new_msg->via1->next;
68
+		}
69
+		else if ( !new_msg->via2 && new_msg->via1 )
70
+		{
71
+		     new_msg->h_via2 = new_hdr;
72
+		     if ( new_msg->via1->next )
73
+		        new_hdr->parsed = (void*)new_msg->via1->next;
74
+		     else{
75
+		        new_msg->via2 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
76
+		        new_hdr->parsed  = (void*)new_msg->via2;
77
+		     }
78
+		}
79
+		else if ( new_msg->via2 && new_msg->via1 )
80
+		{
81
+		    new_hdr->parsed  = new_msg->via1 = via_body_cloner( new_msg->buf , org_msg->buf , (struct via_body*)header->parsed );
82
+		}
87 83
 		break;
88 84
 	    case HDR_FROM :
89 85
 		new_hdr = header_cloner( new_msg , org_msg , header );
... ...
@@ -100,6 +96,10 @@ struct sip_msg* sip_msg_cloner( struct sip_msg *org_msg )
100 96
 		}
101 97
 		new_msg->cseq = new_hdr;
102 98
 		break;
99
+	    case HDR_CALLID :
100
+		new_hdr = header_cloner( new_msg , org_msg , header );
101
+		new_msg->callid = new_hdr;
102
+		break;
103 103
 	    case HDR_CONTACT :
104 104
 		new_hdr = header_cloner( new_msg , org_msg , header );
105 105
 		new_msg->contact = new_hdr;
... ...
@@ -173,7 +173,7 @@ struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_bod
173 173
     if ( new_via->param_lst )
174 174
     {
175 175
        struct via_param *vp, *new_vp, *last_new_vp;
176
-       for( vp=new_via->param_lst, last_new_vp=0 ; vp ; vp=vp->next )
176
+       for( vp=org_via->param_lst, last_new_vp=0 ; vp ; vp=vp->next )
177 177
        {
178 178
           new_vp = (struct via_param*)sh_malloc(sizeof(struct via_param));
179 179
           memcpy( new_vp , vp , sizeof(struct via_param));
... ...
@@ -183,7 +183,7 @@ struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_bod
183 183
           if (new_vp->type==PARAM_BRANCH)
184 184
              new_via->branch = new_vp;
185 185
 
186
-        if (last_new_vp)
186
+          if (last_new_vp)
187 187
              last_new_vp->next = new_vp;
188 188
           else
189 189
              new_via->param_lst = new_vp;
... ...
@@ -193,7 +193,8 @@ struct via_body* via_body_cloner( char* new_buf , char *org_buf , struct via_bod
193 193
        new_via->last_param = new_vp;
194 194
     }
195 195
 
196
-    if ( new_via->next )
196
+
197
+    if ( org_via->next )
197 198
         new_via->next = via_body_cloner( new_buf , org_buf , org_via->next );
198 199
 
199 200
    return new_via;
... ...
@@ -334,15 +335,12 @@ void sh_clean_hdr_field(struct hdr_field* hf)
334 335
       switch(hf->type)
335 336
       {
336 337
          case HDR_VIA:
337
-   DBG("DEBUG: sh_clean_hdr_field: sip_msg_free : via headers\n");
338 338
                sh_free_via_list(hf->parsed);
339 339
              break;
340 340
          case HDR_CSEQ:
341
-   DBG("DEBUG: sh_clean_hdr_field : cseq headers\n");
342 341
                 sh_free(hf->parsed);
343 342
              break;
344 343
          default:
345
-   DBG("DEBUG: sh_clean_hdr_field : unknown headers\n");
346 344
       }
347 345
    }
348 346
 }
... ...
@@ -357,7 +355,6 @@ void sh_free_hdr_field_lst(struct hdr_field* hf)
357 355
 
358 356
    while(hf)
359 357
     {
360
-      DBG("DEBUG: free_hdr_field_lst : %s [%d] (adr=%x)\n",hf->name.s, hf->type,hf);
361 358
        foo=hf;
362 359
        hf=hf->next;
363 360
        sh_clean_hdr_field(foo);
... ...
@@ -373,7 +370,6 @@ void sip_msg_free(struct sip_msg* msg)
373 370
    if (!msg) return;
374 371
 
375 372
    DBG("DEBUG: sip_msg_free : start\n");
376
-   //return;
377 373
 
378 374
    if (msg->new_uri.s)
379 375
    {
... ...
@@ -389,4 +385,5 @@ void sip_msg_free(struct sip_msg* msg)
389 385
    if (msg->orig) sh_free( msg->orig );
390 386
    if (msg->buf) sh_free( msg->buf );
391 387
 
388
+   DBG("DEBUG: sip_msg_free : done\n");
392 389
 }
... ...
@@ -133,10 +133,9 @@ int t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  )
133 133
    }
134 134
    /* start searching into the table */
135 135
    hash_index = hash( p_msg->callid->body , get_cseq(p_msg)->number ) ;
136
-   DBG("hash_index=%d\n", hash_index);
137 136
    if ( p_msg->first_line.u.request.method_value==METHOD_ACK  )
138 137
       isACK = 1;
139
-   DBG("t_lookup_request: 1.continue searching\n");
138
+   DBG("t_lookup_request: continue searching;  hash=%d, isACK=5d\n",hash_index,isACK);
140 139
 
141 140
    /* all the transactions from the entry are compared */
142 141
    p_cell     = hash_table->entrys[hash_index].first_cell;
... ...
@@ -908,6 +907,7 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
908 907
    char *buf;
909 908
    unsigned int len;
910 909
 
910
+   DBG("DEBUG: push_reply_from_uac_to_uas: start\n");
911 911
    /* if there is a reply, release the buffer (everything else stays same) */
912 912
    if ( trans->outbound_response )
913 913
    {
... ...
@@ -957,7 +957,7 @@ int push_reply_from_uac_to_uas( struct cell* trans , unsigned int branch )
957 957
    t_update_timers_after_sending_reply( T->outbound_response );
958 958
 
959 959
    /*send the reply*/
960
-   t_retransmit_reply( trans->inbound_request, 0 , 0 );
960
+   t_retransmit_reply( trans->inbound_response[branch], 0 , 0 );
961 961
 
962 962
    return 1;
963 963
 }
... ...
@@ -170,6 +170,7 @@ void* qm_malloc(struct qm_block* qm, unsigned int size)
170 170
 			f->file=file;
171 171
 			f->func=func;
172 172
 			f->line=line;
173
+	DBG("qm_malloc(%x, %d) returns address %x\n", qm, size,(char*)f+sizeof(struct qm_frag) );
173 174
 #endif
174 175
 			return (char*)f+sizeof(struct qm_frag);
175 176
 		}