Browse code

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 authored on 15/09/2009 15:38:06
Showing 3 changed files
... ...
@@ -384,9 +384,12 @@ int check_self_port(unsigned short port, unsigned short proto)
384 384
  *               default port or non srv. lookup is desired, the port must
385 385
  *               be !=0 
386 386
  *   port      - used only if dst!=0 (else the port in send_info->to is used)
387
- *   send_info - filled dest_info structure:
388
- *               if the send_socket member is null, a send_socket will be 
389
- *               chosen automatically
387
+ *   send_info - value/result partially filled dest_info structure:
388
+ *                 - send_info->proto and comp are used
389
+ *                 - send_info->to will be filled (dns)
390
+ *                 - send_info->send_flags is filled from the message
391
+ *                 - if the send_socket member is null, a send_socket will be 
392
+ *                   chosen automatically
390 393
  * WARNING: don't forget to zero-fill all the  unused members (a non-zero 
391 394
  * random id along with proto==PROTO_TCP can have bad consequences, same for
392 395
  *   a bogus send_socket value)
... ...
@@ -438,13 +441,14 @@ int forward_request(struct sip_msg* msg, str* dst, unsigned short port,
438 438
 			goto error;
439 439
 		}
440 440
 	}/* dst */
441
+	send_info->send_flags=msg->fwd_send_flags;
441 442
 	/* calculate branch for outbound request;  if syn_branch is turned off,
442 443
 	   calculate is from transaction key, i.e., as an md5 of From/To/CallID/
443 444
 	   CSeq exactly the same way as TM does; good for reboot -- than messages
444 445
 	   belonging to transaction lost due to reboot will still be forwarded
445 446
 	   with the same branch parameter and will be match-able downstream
446
-
447
-       if it is turned on, we don't care about reboot; we simply put a simple
447
+	
448
+	   if it is turned on, we don't care about reboot; we simply put a simple
448 449
 	   value in there; better for performance
449 450
 	*/
450 451
 	if (syn_branch ) {
... ...
@@ -694,6 +698,7 @@ int forward_reply(struct sip_msg* msg)
694 694
 	}
695 695
 
696 696
 	dst.proto=msg->via2->proto;
697
+	dst.send_flags=msg->fwd_send_flags | msg->rpl_send_flags;
697 698
 	if (update_sock_struct_from_via( &dst.to, msg, msg->via2 )==-1) goto error;
698 699
 #ifdef USE_COMP
699 700
 	dst.comp=msg->via2->comp_no;
... ...
@@ -34,6 +34,7 @@
34 34
  *  2006-04-21  added init_dst_from_rcv (andrei)
35 35
  *  2007-06-26  added ip_addr_mk_any() (andrei)
36 36
  *  2008-05-21  added su2a(), ip_addr2sbuf(), ip4tosbuf(), ip62sbuf() (andrei)
37
+ *  2009-09-14  added send flags support to dest_info (andrei)
37 38
  */
38 39
 
39 40
 #ifndef ip_addr_h
... ...
@@ -136,11 +137,18 @@ struct receive_info{
136 136
 };
137 137
 
138 138
 
139
+/* send flags */
140
+#define SND_F_FORCE_CON_REUSE	1 /* reuse an existing connection or fail */
141
+#define SND_F_CON_CLOSE			2 /* close the connection after sending */
142
+
143
+typedef unsigned char  snd_flags_t;
144
+
139 145
 struct dest_info{
140 146
 	struct socket_info* send_sock;
141 147
 	union sockaddr_union to;
142 148
 	int id; /* tcp stores the connection id here */ 
143 149
 	char proto;
150
+	snd_flags_t send_flags;
144 151
 #ifdef USE_COMP
145 152
 	short comp;
146 153
 #endif
... ...
@@ -748,6 +756,7 @@ inline static void init_dst_from_rcv(struct dest_info* dst,
748 748
 		dst->to=rcv->src_su;
749 749
 		dst->id=rcv->proto_reserved1;
750 750
 		dst->proto=rcv->proto;
751
+		dst->send_flags=0;
751 752
 #ifdef USE_COMP
752 753
 		dst->comp=rcv->comp;
753 754
 #endif
... ...
@@ -246,6 +246,8 @@ typedef struct msg_body {
246 246
 
247 247
 typedef struct sip_msg {
248 248
 	unsigned int id;               /* message id, unique/process*/
249
+	snd_flags_t fwd_send_flags;    /* send flags for forwarding */
250
+	snd_flags_t rpl_send_flags;    /* send flags for replies */
249 251
 	struct msg_start first_line;   /* Message first line */
250 252
 	struct via_body* via1;         /* The first via */
251 253
 	struct via_body* via2;         /* The second via */