Browse code

*** empty log message ***

Bogdan-Andrei Iancu authored on 11/06/2002 11:04:01
Showing 3 changed files
... ...
@@ -1,8 +1,4 @@
1
-<<<<<<< Makefile.defs
2 1
 # $Id$
3
-=======
4
-# $Id$
5
->>>>>>> 1.99
6 2
 #
7 3
 # makefile defs (CC, LD,a.s.o)
8 4
 #
... ...
@@ -63,7 +63,7 @@ int check_address(struct ip_addr* ip, char *name, int resolver)
63 63
 		DBG("check_address: doing dns lookup\n");
64 64
 		/* try all names ips */
65 65
 		he=resolvehost(name);
66
-		if (he && ip->af==he->h_addrtype){
66
+		if (ip->af==he->h_addrtype){
67 67
 			for(i=0;he && he->h_addr_list[i];i++){
68 68
 				if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)
69 69
 					return 0;
... ...
@@ -235,21 +235,63 @@ done:
235 235
 
236 236
 
237 237
 
238
+char* received_builder(struct sip_msg *msg, int *received_len)
239
+{
240
+	char *buf;
241
+	int  len;
242
+	struct ip_addr *source_ip;
243
+	char *tmp;
244
+	int  tmp_len;
245
+	int extra_len;
246
+
247
+	extra_len = 0;
248
+	source_ip=&msg->src_ip;
249
+	buf = 0;
250
+
251
+	buf=pkg_malloc(sizeof(char)*MAX_RECEIVED_SIZE);
252
+	if (buf==0){
253
+		ser_error=E_OUT_OF_MEM;
254
+		LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: out of memory\n");
255
+		return 0;
256
+	}
257
+	/*
258
+	received_len=snprintf(buf, MAX_RECEIVED_SIZE,
259
+							";received=%s",
260
+							inet_ntoa(*(struct in_addr *)&source_ip));
261
+	*/
262
+	memcpy(buf, RECEIVED, RECEIVED_LEN);
263
+	tmp=ip_addr2a(source_ip);
264
+	tmp_len=strlen(tmp);
265
+	len=RECEIVED_LEN+tmp_len;
266
+	if(source_ip->af==AF_INET6){
267
+		len+=2;
268
+		buf[RECEIVED_LEN]='[';
269
+		buf[RECEIVED_LEN+tmp_len+1]=']';
270
+		extra_len=1;
271
+	}
272
+	
273
+	memcpy(buf+RECEIVED_LEN+extra_len, tmp, tmp_len);
274
+	buf[len]=0; /*null terminate it */
275
+
276
+	*received_len = len;
277
+	return buf;
278
+}
279
+
280
+
281
+
282
+
238 283
 char * build_req_buf_from_sip_req( struct sip_msg* msg,
239 284
 								unsigned int *returned_len,
240 285
 								struct socket_info* send_sock)
241 286
 {
242
-	unsigned int len, new_len, received_len, uri_len, via_len, extra_len;
287
+	unsigned int len, new_len, received_len, uri_len, via_len;
243 288
 	char* line_buf;
244 289
 	char* received_buf;
245
-	char* tmp;
246
-	int tmp_len;
247 290
 	char* new_buf;
248 291
 	char* orig;
249 292
 	char* buf;
250 293
 	char  backup;
251 294
 	unsigned int offset, s_offset, size;
252
-	struct ip_addr* source_ip;
253 295
 	struct lump *t,*r;
254 296
 	struct lump* anchor;
255 297
 
... ...
@@ -257,11 +299,9 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
257 299
 	orig=msg->orig;
258 300
 	buf=msg->buf;
259 301
 	len=msg->len;
260
-	source_ip=&msg->src_ip;
261 302
 	received_len=0;
262 303
 	new_buf=0;
263 304
 	received_buf=0;
264
-	extra_len=0;
265 305
 
266 306
 
267 307
 	line_buf = via_builder( msg, &via_len, send_sock);
... ...
@@ -272,31 +312,9 @@ char * build_req_buf_from_sip_req( struct sip_msg* msg,
272 312
 	/* check if received needs to be added */
273 313
 	backup = msg->via1->host.s[msg->via1->host.len];
274 314
 	msg->via1->host.s[msg->via1->host.len] = 0;
275
-	if (check_address(source_ip, msg->via1->host.s, received_dns)!=0){
276
-		received_buf=pkg_malloc(sizeof(char)*MAX_RECEIVED_SIZE);
277
-		if (received_buf==0){
278
-			ser_error=E_OUT_OF_MEM;
279
-			LOG(L_ERR, "ERROR: build_req_buf_from_sip_req: out of memory\n");
280
-			goto error1;
281
-		}
282
-		/*
283
-		received_len=snprintf(received_buf, MAX_RECEIVED_SIZE,
284
-								";received=%s",
285
-								inet_ntoa(*(struct in_addr *)&source_ip));
286
-		*/
287
-		memcpy(received_buf, RECEIVED, RECEIVED_LEN);
288
-		tmp=ip_addr2a(source_ip);
289
-		tmp_len=strlen(tmp);
290
-		received_len=RECEIVED_LEN+tmp_len;
291
-		if(source_ip->af==AF_INET6){
292
-			received_len+=2;
293
-			received_buf[RECEIVED_LEN]='[';
294
-			received_buf[RECEIVED_LEN+tmp_len+1]=']';
295
-			extra_len=1;
296
-		}
297
-		
298
-		memcpy(received_buf+RECEIVED_LEN+extra_len, tmp, tmp_len);
299
-		received_buf[received_len]=0; /*null terminate it */
315
+	if (check_address(&msg->src_ip, msg->via1->host.s, received_dns)!=0){
316
+		if ((received_buf=received_builder(msg,&received_len))==0)
317
+			goto error;
300 318
 	}
301 319
 	msg->via1->host.s[msg->via1->host.len] = backup;
302 320
 
... ...
@@ -585,17 +603,33 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
585 603
 	struct lump_rpl   *lump;
586 604
 	int               i;
587 605
 	str               *tag_str;
606
+	char              backup;
607
+	char              *received_buf;
608
+	int               received_len;
588 609
 #ifdef VERY_NOISY_REPLIES
589 610
 	char              *warning;
590 611
 	unsigned int      warning_len;
591 612
 #endif
592 613
 
614
+	received_buf=0;
615
+	received_len=0;
616
+	buf=0;
617
+
593 618
 	/* force parsing all headers -- we want to return all
594 619
 	Via's in the reply and they may be scattered down to the
595 620
 	end of header (non-block Vias are a really poor property
596 621
 	of SIP :( ) */
597 622
 	parse_headers( msg, HDR_EOH );
598 623
 
624
+	/* check if received needs to be added */
625
+	backup = msg->via1->host.s[msg->via1->host.len];
626
+	msg->via1->host.s[msg->via1->host.len] = 0;
627
+	if (check_address(&msg->src_ip, msg->via1->host.s, received_dns)!=0){
628
+		if ((received_buf=received_builder(msg,&received_len))==0)
629
+			goto error;
630
+	}
631
+	msg->via1->host.s[msg->via1->host.len] = backup;
632
+
599 633
 	/*computes the lenght of the new response buffer*/
600 634
 	len = 0;
601 635
 	/* first line */
... ...
@@ -614,6 +648,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
614 648
 						len+=new_tag_len+5/*";tag="*/;
615 649
 				}
616 650
 			case HDR_VIA:
651
+				if (hdr==msg->h_via1) len += received_len;
617 652
 			case HDR_FROM:
618 653
 			case HDR_CALLID:
619 654
 			case HDR_CSEQ:
... ...
@@ -635,7 +670,6 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
635 670
 	/* end of message */
636 671
 	len += CRLF_LEN; /*new line*/
637 672
 	/*allocating mem*/
638
-	buf = 0;
639 673
 	buf = (char*) local_malloc( len+1 );
640 674
 	if (!buf)
641 675
 	{
... ...
@@ -685,6 +719,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
685 719
 					break;
686 720
 				}
687 721
 			case HDR_VIA:
722
+				append_str_trans( p, hdr->name.s ,
723
+					((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
724
+				if (hdr==msg->h_via1 && received_buf)
725
+					append_str( p, received_buf, received_len, msg);
726
+				append_str( p, CRLF,CRLF_LEN,msg);
727
+				break;
688 728
 			case HDR_FROM:
689 729
 			case HDR_CALLID:
690 730
 			case HDR_CSEQ:
... ...
@@ -100,7 +100,10 @@ route{
100 100
 	};
101 101
 */
102 102
 
103
-
103
+	if (method=="MESSAGE") {
104
+		sl_send_reply("200","OK");
105
+		break;
106
+	};
104 107
 	pike_check_req();
105 108
 	forward(uri:host,uri:port);
106 109
 	#t_relay();