Browse code

- added more subst lumps: SUBST_{SND,RCV}_ALL => ip:port;transport=proto

Andrei Pelinescu-Onciul authored on 02/04/2003 16:39:06
Showing 3 changed files
... ...
@@ -79,9 +79,12 @@
79 79
 #define CRLF "\r\n"
80 80
 #define CRLF_LEN 2
81 81
 
82
-#define RECEIVED   ";received="
82
+#define RECEIVED        ";received="
83 83
 #define RECEIVED_LEN 10
84 84
 
85
+#define TRANSPORT_PARAM ";transport="
86
+#define TRANSPORT_PARAM_LEN 11
87
+
85 88
 #define TOTAG_TOKEN ";tag="
86 89
 #define TOTAG_TOKEN_LEN (sizeof(TOTAG_TOKEN)-1)
87 90
 
... ...
@@ -31,6 +31,9 @@
31 31
  *  2003-01-29  s/int/enum ... more convenient for gdb (jiri)
32 32
  *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
33 33
  *  2003-04-01  added opt (condition) lumps (andrei)
34
+ *  2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
35
+ *              => ip:port;transport=proto (andrei)
36
+ *
34 37
  */
35 38
 
36 39
 
... ...
@@ -42,12 +45,15 @@ enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST, LUMP_ADD_OPT };
42 42
 enum lump_subst{ SUBST_NOP=0,                     /* do nothing */
43 43
 				 SUBST_RCV_IP,    SUBST_SND_IP,   /* add ip address */
44 44
 				 SUBST_RCV_PORT,  SUBST_SND_PORT, /* add port no */
45
-				 SUBST_RCV_PROTO, SUBST_SND_PROTO /* add protocol */
45
+				 SUBST_RCV_PROTO, SUBST_SND_PROTO,/* add protocol(udp,tcp,tls)*/
46
+				 SUBST_RCV_ALL,   SUBST_SND_ALL   /*  ip:port;transport=proto */
46 47
 				};
47 48
 				/* Where:
48 49
 				   SND = sending, e.g the src ip of the outgoing message
49 50
 				   RCV = received e.g the dst ip of the original incoming msg,
50 51
 				    or the ip of the ser socket on which the msg was received
52
+				   For SUBST_{RCV,SND}_ALL, :port is added only if port!=5060
53
+				    and transport=proto only if proto!=udp
51 54
 					*/
52 55
 
53 56
 enum lump_conditions {	COND_FALSE,         /* always false */
... ...
@@ -44,6 +44,8 @@
44 44
  * 2003-03-18  killed the build_warning snprintf (andrei)
45 45
  * 2003-03-31  added subst lump support (andrei)
46 46
  * 2003-04-01  added opt (conditional) lump support (andrei)
47
+ * 2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
48
+ *              => ip:port;transport=proto (andrei)
47 49
  *
48 50
  */
49 51
 
... ...
@@ -453,7 +455,25 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
453 453
 				break; \
454 454
 			case SUBST_RCV_PROTO: \
455 455
 				if (msg->rcv.bind_address){ \
456
-					new_len+=send_sock->port_no_str.len; \
456
+					new_len+=3; \
457
+				}else{ \
458
+					/* FIXME */ \
459
+					LOG(L_CRIT, "FIXME: null bind_address\n"); \
460
+				}; \
461
+				break; \
462
+			case SUBST_RCV_ALL: \
463
+				if (msg->rcv.bind_address){ \
464
+					new_len+=msg->rcv.bind_address->address_str.len; \
465
+					if (msg->rcv.bind_address->address.af!=AF_INET) \
466
+						new_len+=2; \
467
+					if (msg->rcv.bind_address->port_no!=SIP_PORT){ \
468
+						/* add :port_no */ \
469
+						new_len+=1+msg->rcv.bind_address->port_no_str.len; \
470
+					}\
471
+					if(msg->rcv.bind_address->proto!=PROTO_UDP) {\
472
+						/*add;transport=xxx*/ \
473
+							new_len+=TRANSPORT_PARAM_LEN+3; \
474
+					}\
457 475
 				}else{ \
458 476
 					/* FIXME */ \
459 477
 					LOG(L_CRIT, "FIXME: null bind_address\n"); \
... ...
@@ -485,6 +505,25 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
485 485
 							" null send_sock\n"); \
486 486
 				}; \
487 487
 				break; \
488
+			case SUBST_SND_ALL: \
489
+				if (send_sock){ \
490
+					new_len+=send_sock->address_str.len; \
491
+					if (send_sock->address.af!=AF_INET) \
492
+						new_len+=2; \
493
+					if (send_sock->port_no!=SIP_PORT){ \
494
+						/* add :port_no */ \
495
+						new_len+=1+send_sock->port_no_str.len; \
496
+					}\
497
+					if(send_sock->proto!=PROTO_UDP) {\
498
+						/*add;transport=xxx*/ \
499
+							new_len+=TRANSPORT_PARAM_LEN+3; \
500
+					}\
501
+				}else{ \
502
+					/* FIXME */ \
503
+					LOG(L_CRIT, "FIXME: lumps_len called with" \
504
+							" null send_sock\n"); \
505
+				}; \
506
+				break; \
488 507
 			case SUBST_NOP: /* do nothing */ \
489 508
 				break; \
490 509
 			default: \
... ...
@@ -626,6 +665,53 @@ static inline void process_lumps(	struct sip_msg* msg,
626 626
 				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
627 627
 			}; \
628 628
 			break; \
629
+		case SUBST_RCV_ALL: \
630
+			if (msg->rcv.bind_address){  \
631
+				/* address */ \
632
+				if (msg->rcv.bind_address->address.af!=AF_INET){\
633
+					new_buf[offset]='['; offset++; \
634
+				}\
635
+				memcpy(new_buf+offset, msg->rcv.bind_address->address_str.s, \
636
+						msg->rcv.bind_address->address_str.len); \
637
+				offset+=msg->rcv.bind_address->address_str.len; \
638
+				if (msg->rcv.bind_address->address.af!=AF_INET){\
639
+					new_buf[offset]=']'; offset++; \
640
+				}\
641
+				/* :port */ \
642
+				if (msg->rcv.bind_address->port_no!=SIP_PORT){ \
643
+					new_buf[offset]=':'; offset++; \
644
+					memcpy(new_buf+offset, \
645
+							msg->rcv.bind_address->port_no_str.s, \
646
+							msg->rcv.bind_address->port_no_str.len); \
647
+					offset+=msg->rcv.bind_address->port_no_str.len; \
648
+				}\
649
+				switch(msg->rcv.bind_address->proto){ \
650
+					case PROTO_NONE: \
651
+					case PROTO_UDP: \
652
+						break; /* nothing to do, udp is default*/ \
653
+					case PROTO_TCP: \
654
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
655
+								TRANSPORT_PARAM_LEN); \
656
+						offset+=TRANSPORT_PARAM_LEN; \
657
+						memcpy(new_buf+offset, "tcp", 3); \
658
+						offset+=3; \
659
+						break; \
660
+					case PROTO_TLS: \
661
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
662
+								TRANSPORT_PARAM_LEN); \
663
+						offset+=TRANSPORT_PARAM_LEN; \
664
+						memcpy(new_buf+offset, "tls", 3); \
665
+						offset+=3; \
666
+						break; \
667
+					default: \
668
+						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
669
+								msg->rcv.bind_address->proto); \
670
+				} \
671
+			}else{  \
672
+				/*FIXME*/ \
673
+				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
674
+			}; \
675
+			break; \
629 676
 		case SUBST_SND_IP: \
630 677
 			if (send_sock){  \
631 678
 				if (send_sock->address.af!=AF_INET){\
... ...
@@ -654,6 +740,52 @@ static inline void process_lumps(	struct sip_msg* msg,
654 654
 						" null send_sock\n"); \
655 655
 			}; \
656 656
 			break; \
657
+		case SUBST_SND_ALL: \
658
+			if (send_sock){  \
659
+				/* address */ \
660
+				if (send_sock->address.af!=AF_INET){\
661
+					new_buf[offset]='['; offset++; \
662
+				}\
663
+				memcpy(new_buf+offset, send_sock->address_str.s, \
664
+						send_sock->address_str.len); \
665
+				offset+=send_sock->address_str.len; \
666
+				if (send_sock->address.af!=AF_INET){\
667
+					new_buf[offset]=']'; offset++; \
668
+				}\
669
+				/* :port */ \
670
+				if (send_sock->port_no!=SIP_PORT){ \
671
+					new_buf[offset]=':'; offset++; \
672
+					memcpy(new_buf+offset, send_sock->port_no_str.s, \
673
+							send_sock->port_no_str.len); \
674
+					offset+=send_sock->port_no_str.len; \
675
+				}\
676
+				switch(send_sock->proto){ \
677
+					case PROTO_NONE: \
678
+					case PROTO_UDP: \
679
+						break; /* nothing to do, udp is default*/ \
680
+					case PROTO_TCP: \
681
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
682
+								TRANSPORT_PARAM_LEN); \
683
+						offset+=TRANSPORT_PARAM_LEN; \
684
+						memcpy(new_buf+offset, "tcp", 3); \
685
+						offset+=3; \
686
+						break; \
687
+					case PROTO_TLS: \
688
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
689
+								TRANSPORT_PARAM_LEN); \
690
+						offset+=TRANSPORT_PARAM_LEN; \
691
+						memcpy(new_buf+offset, "tls", 3); \
692
+						offset+=3; \
693
+						break; \
694
+					default: \
695
+						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
696
+								send_sock->proto); \
697
+				} \
698
+			}else{  \
699
+				/*FIXME*/ \
700
+				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
701
+			}; \
702
+			break; \
657 703
 		case SUBST_RCV_PROTO: \
658 704
 			if (msg->rcv.bind_address){ \
659 705
 				switch(msg->rcv.bind_address->proto){ \
... ...
@@ -676,7 +808,8 @@ static inline void process_lumps(	struct sip_msg* msg,
676 676
 				} \
677 677
 			}else{  \
678 678
 				/*FIXME*/ \
679
-				LOG(L_CRIT, "FIXME: process lumps: null bind_address\n"); \
679
+				LOG(L_CRIT, "FIXME: process_lumps: called with null" \
680
+							" send_sock \n"); \
680 681
 			}; \
681 682
 			break; \
682 683
 		case  SUBST_SND_PROTO: \
... ...
@@ -1589,12 +1722,12 @@ char* via_builder( unsigned int *len,
1589 1589
 
1590 1590
 	via_len=MY_VIA_LEN+send_sock->address_str.len; /*space included in MY_VIA*/
1591 1591
 
1592
-	memcpy(line_buf, MY_VIA, MY_VIA_LEN-4); /* without "UPD " */
1593
-	if (proto==PROTO_UDP)
1594
-		memcpy(line_buf+MY_VIA_LEN-4, "UDP ", 4);
1595
-	else if (proto==PROTO_TCP)
1592
+	memcpy(line_buf, MY_VIA, MY_VIA_LEN); 
1593
+	if (proto==PROTO_UDP){
1594
+		/* dop nothing */
1595
+	}else if (proto==PROTO_TCP){
1596 1596
 		memcpy(line_buf+MY_VIA_LEN-4, "TCP ", 4);
1597
-	else{
1597
+	}else{
1598 1598
 		LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", proto);
1599 1599
 		return 0;
1600 1600
 	}