Jelajahi Sumber

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

Andrei Pelinescu-Onciul 22 tahun lalu
induk
melakukan
c55adae857
3 mengubah file dengan 151 tambahan dan 9 penghapusan
  1. 4 1
      config.h
  2. 7 1
      data_lump.h
  3. 140 7
      msg_translator.c

+ 4 - 1
config.h

@@ -79,9 +79,12 @@
 #define CRLF "\r\n"
 #define CRLF "\r\n"
 #define CRLF_LEN 2
 #define CRLF_LEN 2
 
 
-#define RECEIVED   ";received="
+#define RECEIVED        ";received="
 #define RECEIVED_LEN 10
 #define RECEIVED_LEN 10
 
 
+#define TRANSPORT_PARAM ";transport="
+#define TRANSPORT_PARAM_LEN 11
+
 #define TOTAG_TOKEN ";tag="
 #define TOTAG_TOKEN ";tag="
 #define TOTAG_TOKEN_LEN (sizeof(TOTAG_TOKEN)-1)
 #define TOTAG_TOKEN_LEN (sizeof(TOTAG_TOKEN)-1)
 
 

+ 7 - 1
data_lump.h

@@ -31,6 +31,9 @@
  *  2003-01-29  s/int/enum ... more convenient for gdb (jiri)
  *  2003-01-29  s/int/enum ... more convenient for gdb (jiri)
  *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
  *  2003-03-31  added subst lumps -- they expand in ip addr, port a.s.o (andrei)
  *  2003-04-01  added opt (condition) lumps (andrei)
  *  2003-04-01  added opt (condition) lumps (andrei)
+ *  2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
+ *              => ip:port;transport=proto (andrei)
+ *
  */
  */
 
 
 
 
@@ -42,12 +45,15 @@ enum lump_op { LUMP_NOP=0, LUMP_DEL, LUMP_ADD, LUMP_ADD_SUBST, LUMP_ADD_OPT };
 enum lump_subst{ SUBST_NOP=0,                     /* do nothing */
 enum lump_subst{ SUBST_NOP=0,                     /* do nothing */
 				 SUBST_RCV_IP,    SUBST_SND_IP,   /* add ip address */
 				 SUBST_RCV_IP,    SUBST_SND_IP,   /* add ip address */
 				 SUBST_RCV_PORT,  SUBST_SND_PORT, /* add port no */
 				 SUBST_RCV_PORT,  SUBST_SND_PORT, /* add port no */
-				 SUBST_RCV_PROTO, SUBST_SND_PROTO /* add protocol */
+				 SUBST_RCV_PROTO, SUBST_SND_PROTO,/* add protocol(udp,tcp,tls)*/
+				 SUBST_RCV_ALL,   SUBST_SND_ALL   /*  ip:port;transport=proto */
 				};
 				};
 				/* Where:
 				/* Where:
 				   SND = sending, e.g the src ip of the outgoing message
 				   SND = sending, e.g the src ip of the outgoing message
 				   RCV = received e.g the dst ip of the original incoming msg,
 				   RCV = received e.g the dst ip of the original incoming msg,
 				    or the ip of the ser socket on which the msg was received
 				    or the ip of the ser socket on which the msg was received
+				   For SUBST_{RCV,SND}_ALL, :port is added only if port!=5060
+				    and transport=proto only if proto!=udp
 					*/
 					*/
 
 
 enum lump_conditions {	COND_FALSE,         /* always false */
 enum lump_conditions {	COND_FALSE,         /* always false */

+ 140 - 7
msg_translator.c

@@ -44,6 +44,8 @@
  * 2003-03-18  killed the build_warning snprintf (andrei)
  * 2003-03-18  killed the build_warning snprintf (andrei)
  * 2003-03-31  added subst lump support (andrei)
  * 2003-03-31  added subst lump support (andrei)
  * 2003-04-01  added opt (conditional) lump support (andrei)
  * 2003-04-01  added opt (conditional) lump support (andrei)
+ * 2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
+ *              => ip:port;transport=proto (andrei)
  *
  *
  */
  */
 
 
@@ -453,7 +455,25 @@ static inline int lumps_len(struct sip_msg* msg, struct socket_info* send_sock)
 				break; \
 				break; \
 			case SUBST_RCV_PROTO: \
 			case SUBST_RCV_PROTO: \
 				if (msg->rcv.bind_address){ \
 				if (msg->rcv.bind_address){ \
-					new_len+=send_sock->port_no_str.len; \
+					new_len+=3; \
+				}else{ \
+					/* FIXME */ \
+					LOG(L_CRIT, "FIXME: null bind_address\n"); \
+				}; \
+				break; \
+			case SUBST_RCV_ALL: \
+				if (msg->rcv.bind_address){ \
+					new_len+=msg->rcv.bind_address->address_str.len; \
+					if (msg->rcv.bind_address->address.af!=AF_INET) \
+						new_len+=2; \
+					if (msg->rcv.bind_address->port_no!=SIP_PORT){ \
+						/* add :port_no */ \
+						new_len+=1+msg->rcv.bind_address->port_no_str.len; \
+					}\
+					if(msg->rcv.bind_address->proto!=PROTO_UDP) {\
+						/*add;transport=xxx*/ \
+							new_len+=TRANSPORT_PARAM_LEN+3; \
+					}\
 				}else{ \
 				}else{ \
 					/* FIXME */ \
 					/* FIXME */ \
 					LOG(L_CRIT, "FIXME: null bind_address\n"); \
 					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)
 							" null send_sock\n"); \
 							" null send_sock\n"); \
 				}; \
 				}; \
 				break; \
 				break; \
+			case SUBST_SND_ALL: \
+				if (send_sock){ \
+					new_len+=send_sock->address_str.len; \
+					if (send_sock->address.af!=AF_INET) \
+						new_len+=2; \
+					if (send_sock->port_no!=SIP_PORT){ \
+						/* add :port_no */ \
+						new_len+=1+send_sock->port_no_str.len; \
+					}\
+					if(send_sock->proto!=PROTO_UDP) {\
+						/*add;transport=xxx*/ \
+							new_len+=TRANSPORT_PARAM_LEN+3; \
+					}\
+				}else{ \
+					/* FIXME */ \
+					LOG(L_CRIT, "FIXME: lumps_len called with" \
+							" null send_sock\n"); \
+				}; \
+				break; \
 			case SUBST_NOP: /* do nothing */ \
 			case SUBST_NOP: /* do nothing */ \
 				break; \
 				break; \
 			default: \
 			default: \
@@ -626,6 +665,53 @@ static inline void process_lumps(	struct sip_msg* msg,
 				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
 				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
 			}; \
 			}; \
 			break; \
 			break; \
+		case SUBST_RCV_ALL: \
+			if (msg->rcv.bind_address){  \
+				/* address */ \
+				if (msg->rcv.bind_address->address.af!=AF_INET){\
+					new_buf[offset]='['; offset++; \
+				}\
+				memcpy(new_buf+offset, msg->rcv.bind_address->address_str.s, \
+						msg->rcv.bind_address->address_str.len); \
+				offset+=msg->rcv.bind_address->address_str.len; \
+				if (msg->rcv.bind_address->address.af!=AF_INET){\
+					new_buf[offset]=']'; offset++; \
+				}\
+				/* :port */ \
+				if (msg->rcv.bind_address->port_no!=SIP_PORT){ \
+					new_buf[offset]=':'; offset++; \
+					memcpy(new_buf+offset, \
+							msg->rcv.bind_address->port_no_str.s, \
+							msg->rcv.bind_address->port_no_str.len); \
+					offset+=msg->rcv.bind_address->port_no_str.len; \
+				}\
+				switch(msg->rcv.bind_address->proto){ \
+					case PROTO_NONE: \
+					case PROTO_UDP: \
+						break; /* nothing to do, udp is default*/ \
+					case PROTO_TCP: \
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
+								TRANSPORT_PARAM_LEN); \
+						offset+=TRANSPORT_PARAM_LEN; \
+						memcpy(new_buf+offset, "tcp", 3); \
+						offset+=3; \
+						break; \
+					case PROTO_TLS: \
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
+								TRANSPORT_PARAM_LEN); \
+						offset+=TRANSPORT_PARAM_LEN; \
+						memcpy(new_buf+offset, "tls", 3); \
+						offset+=3; \
+						break; \
+					default: \
+						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
+								msg->rcv.bind_address->proto); \
+				} \
+			}else{  \
+				/*FIXME*/ \
+				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
+			}; \
+			break; \
 		case SUBST_SND_IP: \
 		case SUBST_SND_IP: \
 			if (send_sock){  \
 			if (send_sock){  \
 				if (send_sock->address.af!=AF_INET){\
 				if (send_sock->address.af!=AF_INET){\
@@ -654,6 +740,52 @@ static inline void process_lumps(	struct sip_msg* msg,
 						" null send_sock\n"); \
 						" null send_sock\n"); \
 			}; \
 			}; \
 			break; \
 			break; \
+		case SUBST_SND_ALL: \
+			if (send_sock){  \
+				/* address */ \
+				if (send_sock->address.af!=AF_INET){\
+					new_buf[offset]='['; offset++; \
+				}\
+				memcpy(new_buf+offset, send_sock->address_str.s, \
+						send_sock->address_str.len); \
+				offset+=send_sock->address_str.len; \
+				if (send_sock->address.af!=AF_INET){\
+					new_buf[offset]=']'; offset++; \
+				}\
+				/* :port */ \
+				if (send_sock->port_no!=SIP_PORT){ \
+					new_buf[offset]=':'; offset++; \
+					memcpy(new_buf+offset, send_sock->port_no_str.s, \
+							send_sock->port_no_str.len); \
+					offset+=send_sock->port_no_str.len; \
+				}\
+				switch(send_sock->proto){ \
+					case PROTO_NONE: \
+					case PROTO_UDP: \
+						break; /* nothing to do, udp is default*/ \
+					case PROTO_TCP: \
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
+								TRANSPORT_PARAM_LEN); \
+						offset+=TRANSPORT_PARAM_LEN; \
+						memcpy(new_buf+offset, "tcp", 3); \
+						offset+=3; \
+						break; \
+					case PROTO_TLS: \
+						memcpy(new_buf+offset, TRANSPORT_PARAM, \
+								TRANSPORT_PARAM_LEN); \
+						offset+=TRANSPORT_PARAM_LEN; \
+						memcpy(new_buf+offset, "tls", 3); \
+						offset+=3; \
+						break; \
+					default: \
+						LOG(L_CRIT, "BUG: process_lumps: unknown proto %d\n", \
+								send_sock->proto); \
+				} \
+			}else{  \
+				/*FIXME*/ \
+				LOG(L_CRIT, "FIXME: process_lumps: null bind_address\n"); \
+			}; \
+			break; \
 		case SUBST_RCV_PROTO: \
 		case SUBST_RCV_PROTO: \
 			if (msg->rcv.bind_address){ \
 			if (msg->rcv.bind_address){ \
 				switch(msg->rcv.bind_address->proto){ \
 				switch(msg->rcv.bind_address->proto){ \
@@ -676,7 +808,8 @@ static inline void process_lumps(	struct sip_msg* msg,
 				} \
 				} \
 			}else{  \
 			}else{  \
 				/*FIXME*/ \
 				/*FIXME*/ \
-				LOG(L_CRIT, "FIXME: process lumps: null bind_address\n"); \
+				LOG(L_CRIT, "FIXME: process_lumps: called with null" \
+							" send_sock \n"); \
 			}; \
 			}; \
 			break; \
 			break; \
 		case  SUBST_SND_PROTO: \
 		case  SUBST_SND_PROTO: \
@@ -1589,12 +1722,12 @@ char* via_builder( unsigned int *len,
 
 
 	via_len=MY_VIA_LEN+send_sock->address_str.len; /*space included in MY_VIA*/
 	via_len=MY_VIA_LEN+send_sock->address_str.len; /*space included in MY_VIA*/
 
 
-	memcpy(line_buf, MY_VIA, MY_VIA_LEN-4); /* without "UPD " */
-	if (proto==PROTO_UDP)
-		memcpy(line_buf+MY_VIA_LEN-4, "UDP ", 4);
-	else if (proto==PROTO_TCP)
+	memcpy(line_buf, MY_VIA, MY_VIA_LEN); 
+	if (proto==PROTO_UDP){
+		/* dop nothing */
+	}else if (proto==PROTO_TCP){
 		memcpy(line_buf+MY_VIA_LEN-4, "TCP ", 4);
 		memcpy(line_buf+MY_VIA_LEN-4, "TCP ", 4);
-	else{
+	}else{
 		LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", proto);
 		LOG(L_CRIT, "BUG: via_builder: unknown proto %d\n", proto);
 		return 0;
 		return 0;
 	}
 	}