Browse Source

core: send flags support

Added support for send flags and per message send flags.
Right now there are 2 flags defined:
 - SND_F_FORCE_CON_REUSE (forces connection reuse, send will fail if
   a connection does not already exist to the destination)
 - SND_F_CON_CLOSE (hint that after the send completes the
   connection should be closed).
The send flags can be passed directly to msg_send() via
dest_info.send_flags or they can be set for each sip_msg, in which
case forward_request() and forward_reply() will obey them.
The sip_msg flags can be set for replies or for forwarding.
Andrei Pelinescu-Onciul 16 years ago
parent
commit
67c9277aaa
3 changed files with 21 additions and 5 deletions
  1. 10 5
      forward.c
  2. 9 0
      ip_addr.h
  3. 2 0
      parser/msg_parser.h

+ 10 - 5
forward.c

@@ -384,9 +384,12 @@ int check_self_port(unsigned short port, unsigned short proto)
  *               default port or non srv. lookup is desired, the port must
  *               default port or non srv. lookup is desired, the port must
  *               be !=0 
  *               be !=0 
  *   port      - used only if dst!=0 (else the port in send_info->to is used)
  *   port      - used only if dst!=0 (else the port in send_info->to is used)
- *   send_info - filled dest_info structure:
- *               if the send_socket member is null, a send_socket will be 
- *               chosen automatically
+ *   send_info - value/result partially filled dest_info structure:
+ *                 - send_info->proto and comp are used
+ *                 - send_info->to will be filled (dns)
+ *                 - send_info->send_flags is filled from the message
+ *                 - if the send_socket member is null, a send_socket will be 
+ *                   chosen automatically
  * WARNING: don't forget to zero-fill all the  unused members (a non-zero 
  * WARNING: don't forget to zero-fill all the  unused members (a non-zero 
  * random id along with proto==PROTO_TCP can have bad consequences, same for
  * random id along with proto==PROTO_TCP can have bad consequences, same for
  *   a bogus send_socket value)
  *   a bogus send_socket value)
@@ -438,13 +441,14 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
 			goto error;
 			goto error;
 		}
 		}
 	}/* dst */
 	}/* dst */
+	send_info->send_flags=msg->fwd_send_flags;
 	/* calculate branch for outbound request;  if syn_branch is turned off,
 	/* calculate branch for outbound request;  if syn_branch is turned off,
 	   calculate is from transaction key, i.e., as an md5 of From/To/CallID/
 	   calculate is from transaction key, i.e., as an md5 of From/To/CallID/
 	   CSeq exactly the same way as TM does; good for reboot -- than messages
 	   CSeq exactly the same way as TM does; good for reboot -- than messages
 	   belonging to transaction lost due to reboot will still be forwarded
 	   belonging to transaction lost due to reboot will still be forwarded
 	   with the same branch parameter and will be match-able downstream
 	   with the same branch parameter and will be match-able downstream
-
-       if it is turned on, we don't care about reboot; we simply put a simple
+	
+	   if it is turned on, we don't care about reboot; we simply put a simple
 	   value in there; better for performance
 	   value in there; better for performance
 	*/
 	*/
 	if (syn_branch ) {
 	if (syn_branch ) {
@@ -694,6 +698,7 @@ int forward_reply(struct sip_msg* msg)
 	}
 	}
 
 
 	dst.proto=msg->via2->proto;
 	dst.proto=msg->via2->proto;
+	dst.send_flags=msg->fwd_send_flags | msg->rpl_send_flags;
 	if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error;
 	if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error;
 #ifdef USE_COMP
 #ifdef USE_COMP
 	dst.comp=msg->via2->comp_no;
 	dst.comp=msg->via2->comp_no;

+ 9 - 0
ip_addr.h

@@ -34,6 +34,7 @@
  *  2006-04-21  added init_dst_from_rcv (andrei)
  *  2006-04-21  added init_dst_from_rcv (andrei)
  *  2007-06-26  added ip_addr_mk_any() (andrei)
  *  2007-06-26  added ip_addr_mk_any() (andrei)
  *  2008-05-21  added su2a(), ip_addr2sbuf(), ip4tosbuf(), ip62sbuf() (andrei)
  *  2008-05-21  added su2a(), ip_addr2sbuf(), ip4tosbuf(), ip62sbuf() (andrei)
+ *  2009-09-14  added send flags support to dest_info (andrei)
  */
  */
 
 
 #ifndef ip_addr_h
 #ifndef ip_addr_h
@@ -136,11 +137,18 @@ struct receive_info{
 };
 };
 
 
 
 
+/* send flags */
+#define SND_F_FORCE_CON_REUSE	1 /* reuse an existing connection or fail */
+#define SND_F_CON_CLOSE			2 /* close the connection after sending */
+
+typedef unsigned char  snd_flags_t;
+
 struct dest_info{
 struct dest_info{
 	struct socket_info* send_sock;
 	struct socket_info* send_sock;
 	union sockaddr_union to;
 	union sockaddr_union to;
 	int id; /* tcp stores the connection id here */ 
 	int id; /* tcp stores the connection id here */ 
 	char proto;
 	char proto;
+	snd_flags_t send_flags;
 #ifdef USE_COMP
 #ifdef USE_COMP
 	short comp;
 	short comp;
 #endif
 #endif
@@ -748,6 +756,7 @@ inline static void init_dst_from_rcv(struct dest_info* dst,
 		dst->to=rcv->src_su;
 		dst->to=rcv->src_su;
 		dst->id=rcv->proto_reserved1;
 		dst->id=rcv->proto_reserved1;
 		dst->proto=rcv->proto;
 		dst->proto=rcv->proto;
+		dst->send_flags=0;
 #ifdef USE_COMP
 #ifdef USE_COMP
 		dst->comp=rcv->comp;
 		dst->comp=rcv->comp;
 #endif
 #endif

+ 2 - 0
parser/msg_parser.h

@@ -246,6 +246,8 @@ typedef struct msg_body {
 
 
 typedef struct sip_msg {
 typedef struct sip_msg {
 	unsigned int id;               /* message id, unique/process*/
 	unsigned int id;               /* message id, unique/process*/
+	snd_flags_t fwd_send_flags;    /* send flags for forwarding */
+	snd_flags_t rpl_send_flags;    /* send flags for replies */
 	struct msg_start first_line;   /* Message first line */
 	struct msg_start first_line;   /* Message first line */
 	struct via_body* via1;         /* The first via */
 	struct via_body* via1;         /* The first via */
 	struct via_body* via2;         /* The second via */
 	struct via_body* via2;         /* The second via */