Browse code

*** empty log message ***

Bogdan-Andrei Iancu authored on 28/11/2001 23:55:25
Showing 5 changed files
... ...
@@ -103,25 +103,16 @@ error:
103 103
 /* removes first via & sends msg to the second */
104 104
 int forward_reply(struct sip_msg* msg)
105 105
 {
106
-
107
-
108
-	unsigned int new_len, via_len,r;
106
+	int  r;
109 107
 	char* new_buf;
110
-	unsigned offset, s_offset, size;
111 108
 	struct hostent* he;
112 109
 	struct sockaddr_in* to;
113
-	char* orig;
114
-	char* buf;
115
-	unsigned int len;
110
+	unsigned int new_len;
116 111
 #ifdef DNS_IP_HACK
117 112
 	int err;
118 113
 #endif
119 114
 
120 115
 
121
-	orig=msg->orig;
122
-	buf=msg->buf;
123
-	len=msg->len;
124
-	new_buf=0;
125 116
 	to=0;
126 117
 	to=(struct sockaddr_in*)malloc(sizeof(struct sockaddr));
127 118
 	if (to==0){
... ...
@@ -140,37 +131,16 @@ int forward_reply(struct sip_msg* msg)
140 131
 			goto error;
141 132
 		}
142 133
 	}
143
-	/* we must remove the first via */
144
-	via_len=msg->via1->bsize;
145
-	size=msg->via1->hdr.s-buf;
146
-	DBG("via len: %d, initial size: %d\n", via_len, size);
147
-	if (msg->via1->next){
148
-		/* add hdr size*/
149
-		size+=msg->via1->hdr.len+1;
150
-	    DBG(" adjusted via len: %d, initial size: %d\n",
151
-				via_len, size);
152
-	}else{
153
-		/* add hdr size ("Via:")*/
154
-		via_len+=msg->via1->hdr.len+1;
155
-	}
156
-	new_len=len-via_len;
157 134
 
158
-	DBG(" old size: %d, new size: %d\n", len, new_len);
159
-	new_buf=(char*)malloc(new_len+1);/* +1 is for debugging
160
-											(\0 to print it )*/
161
-	if (new_buf==0){
162
-		LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
135
+	/* here will be called the T Module !!!!!!  */
136
+
137
+	new_buf = build_buf_from_sip_request( msg, &new_len);
138
+	if (!new_buf){
139
+		LOG(L_ERR, "ERROR: forward_reply: building failed\n");
163 140
 		goto error;
164 141
 	}
165
-	new_buf[new_len]=0; /* debug: print the message */
166
-	memcpy(new_buf, orig, size);
167
-	offset=size;
168
-	s_offset=size+via_len;
169
-	memcpy(new_buf+offset,orig+s_offset, len-s_offset);
142
+
170 143
 	 /* send it! */
171
-	DBG(" copied size: orig:%d, new: %d, rest: %d\n",
172
-			s_offset, offset,
173
-			len-s_offset );
174 144
 	DBG("Sending: to %s:%d, \n%s.\n",
175 145
 			msg->via2->host.s,
176 146
 			(unsigned short)msg->via2->port,
... ...
@@ -210,7 +180,7 @@ int forward_reply(struct sip_msg* msg)
210 180
 #ifdef STATS
211 181
 	else update_sent_response(  msg->first_line.u.reply.statusclass );
212 182
 #endif
213
-	
183
+
214 184
 	free(new_buf);
215 185
 	free(to);
216 186
 	return 0;
... ...
@@ -252,11 +252,13 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
252 252
       T->outbound_request[0]->to.sin_port     = htonl( dest_port ) ;
253 253
       T->outbound_request[0]->to.sin_addr.s_addr = ntohl( dest_ip ) ;
254 254
 
255
-      // buf = build_message( p_mesg , &len );      TO DO!!
256
-      // T->outbound_request[0]->bufflen     = len ;
257
-      // T->outbound_request[0]->buffer = (struct retans_buff*)sh_malloc( len );
258
-      // memcpy( T->outbound_request[0]->buffer , buf , len );
259
-      // free( buf ) ;
255
+      buf = build_buf_from_sip_request  ( p_msg, &len);
256
+      if (!buf)
257
+         return -1;
258
+      T->outbound_request[0]->bufflen = len ;
259
+      T->outbound_request[0]->buffer   = (char*)sh_malloc( len );
260
+      memcpy( T->outbound_request[0]->buffer , buf , len );
261
+      free( buf ) ;
260 262
    }/* end for the first time */
261 263
 
262 264
 
... ...
@@ -649,6 +651,9 @@ int relay_lowest_reply_upstream( struct cell *Trans , struct sip_msg *p_msg )
649 651
   */
650 652
 int push_reply_from_uac_to_uas( struct sip_msg *p_msg , unsigned int branch )
651 653
 {
654
+   char *buf;
655
+   unsigned int len;
656
+
652 657
    /* if there is a reply, release the buffer (everything else stays same) */
653 658
    if ( T->inbound_response )
654 659
    {
... ...
@@ -657,8 +662,7 @@ int push_reply_from_uac_to_uas( struct sip_msg *p_msg , unsigned int branch )
657 662
    else
658 663
    {
659 664
       struct hostent  *nhost;
660
-     char foo,*buf;
661
-      unsigned int len;
665
+     char foo;
662 666
 
663 667
       T->inbound_response = (struct retrans_buff*)sh_malloc( sizeof(struct retrans_buff) );
664 668
       memset( T->inbound_response , 0 , sizeof (struct retrans_buff) );
... ...
@@ -677,11 +681,13 @@ int push_reply_from_uac_to_uas( struct sip_msg *p_msg , unsigned int branch )
677 681
    }
678 682
 
679 683
    /*  */
680
-   // buf = build_message( p_mesg , &len );      TO DO!!
681
-   // T->inbound_request->bufflen     = len ;
682
-   // T->outbound_request[0]->buffer = (struct retans_buff*)sh_malloc( len );
683
-   // memcpy( T->inbound_request->buffer , buf , len );
684
-   // free( buf ) ;
684
+   buf = build_buf_from_sip_response  ( p_msg, &len);
685
+   if (!buf)
686
+        return -1;
687
+   T->inbound_response->bufflen = len ;
688
+   T->inbound_response->buffer   = (char*)sh_malloc( len );
689
+   memcpy( T->inbound_response->buffer , buf , len );
690
+   free( buf ) ;
685 691
 
686 692
    /* make sure that if we send something final upstream, everything else will be cancelled */
687 693
    if (T->outbound_response[branch]->first_line.u.reply.statusclass>=2 )
... ...
@@ -7,6 +7,8 @@
7 7
 #include "../../msg_parser.h"
8 8
 #include "../../globals.h"
9 9
 #include "../../udp_server.h"
10
+#include "../../msg_translator.h"
11
+#include "../../mem.h"
10 12
 
11 13
 struct s_table;
12 14
 struct timer;
... ...
@@ -398,4 +398,63 @@ error:
398 398
 
399 399
 
400 400
 
401
+char * build_buf_from_sip_response(struct sip_msg* msg, unsigned int *returned_len)
402
+{
403
+	unsigned int new_len, via_len,r;
404
+	char* new_buf;
405
+	unsigned offset, s_offset, size;
406
+	struct hostent* he;
407
+	char* orig;
408
+	char* buf;
409
+	unsigned int len;
410
+#ifdef DNS_IP_HACK
411
+	int err;
412
+#endif
413
+
414
+
415
+	orig=msg->orig;
416
+	buf=msg->buf;
417
+	len=msg->len;
418
+	new_buf=0;
419
+	/* we must remove the first via */
420
+	via_len=msg->via1->bsize;
421
+	size=msg->via1->hdr.s-buf;
422
+	DBG("via len: %d, initial size: %d\n", via_len, size);
423
+	if (msg->via1->next){
424
+		/* add hdr size*/
425
+		size+=msg->via1->hdr.len+1;
426
+	    DBG(" adjusted via len: %d, initial size: %d\n",
427
+				via_len, size);
428
+	}else{
429
+		/* add hdr size ("Via:")*/
430
+		via_len+=msg->via1->hdr.len+1;
431
+	}
432
+	new_len=len-via_len;
433
+
434
+	DBG(" old size: %d, new size: %d\n", len, new_len);
435
+	new_buf=(char*)malloc(new_len+1);/* +1 is for debugging
436
+											(\0 to print it )*/
437
+	if (new_buf==0){
438
+		LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
439
+		goto error;
440
+	}
441
+	new_buf[new_len]=0; /* debug: print the message */
442
+	memcpy(new_buf, orig, size);
443
+	offset=size;
444
+	s_offset=size+via_len;
445
+	memcpy(new_buf+offset,orig+s_offset, len-s_offset);
446
+	 /* send it! */
447
+	DBG(" copied size: orig:%d, new: %d, rest: %d\n",
448
+			s_offset, offset,
449
+			len-s_offset );
450
+
451
+	*returned_len=new_len;
452
+	return new_buf;
453
+error:
454
+	if (new_buf) free(new_buf);
455
+	*returned_len=0;
456
+	return 0;
457
+}
458
+
459
+
401 460
 
... ...
@@ -3,7 +3,8 @@
3 3
 
4 4
 #include "msg_parser.h"
5 5
 
6
-char * build_buf_from_sip_request(struct sip_msg* msg, unsigned int *returned_len);
6
+char * build_buf_from_sip_request  (struct sip_msg* msg, unsigned int *returned_len);
7
+char * build_buf_from_sip_response(struct sip_msg* msg, unsigned int *returned_len);
7 8
 
8 9
 
9 10