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 257
 	orig=msg->orig;
258 258
 	buf=msg->buf;
259 259
 	len=msg->len;
260
-	source_ip=&msg->src_ip;
261 260
 	received_len=0;
262 261
 	new_buf=0;
263 262
 	received_buf=0;
264
-	extra_len=0;
265 263
 
266 264
 
267 265
 	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 272
 	/* check if received needs to be added */
273 273
 	backup = msg->via1->host.s[msg->via1->host.len];
274 274
 	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 */
275
+	if (check_address(&msg->src_ip, msg->via1->host.s, received_dns)!=0){
276
+		if ((received_buf=received_builder(msg,&received_len))==0)
277
+			goto error;
300 278
 	}
301 279
 	msg->via1->host.s[msg->via1->host.len] = backup;
302 280
 
... ...
@@ -585,17 +603,33 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
585 585
 	struct lump_rpl   *lump;
586 586
 	int               i;
587 587
 	str               *tag_str;
588
+	char              backup;
589
+	char              *received_buf;
590
+	int               received_len;
588 591
 #ifdef VERY_NOISY_REPLIES
589 592
 	char              *warning;
590 593
 	unsigned int      warning_len;
591 594
 #endif
592 595
 
596
+	received_buf=0;
597
+	received_len=0;
598
+	buf=0;
599
+
593 600
 	/* force parsing all headers -- we want to return all
594 601
 	Via's in the reply and they may be scattered down to the
595 602
 	end of header (non-block Vias are a really poor property
596 603
 	of SIP :( ) */
597 604
 	parse_headers( msg, HDR_EOH );
598 605
 
606
+	/* check if received needs to be added */
607
+	backup = msg->via1->host.s[msg->via1->host.len];
608
+	msg->via1->host.s[msg->via1->host.len] = 0;
609
+	if (check_address(&msg->src_ip, msg->via1->host.s, received_dns)!=0){
610
+		if ((received_buf=received_builder(msg,&received_len))==0)
611
+			goto error;
612
+	}
613
+	msg->via1->host.s[msg->via1->host.len] = backup;
614
+
599 615
 	/*computes the lenght of the new response buffer*/
600 616
 	len = 0;
601 617
 	/* first line */
... ...
@@ -614,6 +648,7 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
614 614
 						len+=new_tag_len+5/*";tag="*/;
615 615
 				}
616 616
 			case HDR_VIA:
617
+				if (hdr==msg->h_via1) len += received_len;
617 618
 			case HDR_FROM:
618 619
 			case HDR_CALLID:
619 620
 			case HDR_CSEQ:
... ...
@@ -635,7 +670,6 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
635 635
 	/* end of message */
636 636
 	len += CRLF_LEN; /*new line*/
637 637
 	/*allocating mem*/
638
-	buf = 0;
639 638
 	buf = (char*) local_malloc( len+1 );
640 639
 	if (!buf)
641 640
 	{
... ...
@@ -685,6 +719,12 @@ char * build_res_buf_from_sip_req( unsigned int code, char *text,
685 685
 					break;
686 686
 				}
687 687
 			case HDR_VIA:
688
+				append_str_trans( p, hdr->name.s ,
689
+					((hdr->body.s+hdr->body.len )-hdr->name.s ),msg);
690
+				if (hdr==msg->h_via1 && received_buf)
691
+					append_str( p, received_buf, received_len, msg);
692
+				append_str( p, CRLF,CRLF_LEN,msg);
693
+				break;
688 694
 			case HDR_FROM:
689 695
 			case HDR_CALLID:
690 696
 			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();