Browse code

core: send_flags support in the onsend_route

send_flags can now be set also in the onsend_route
(via set_forward_no_connect() or set_forward_close()).

E.g.:
onsend_route{
if (dsp_ip!=10.0.0.0/8)
set_forward_no_connect(); # don't open new connection,
# only reuse
}

Andrei Pelinescu-Onciul authored on 18/09/2009 18:58:20
Showing 2 changed files
... ...
@@ -2053,6 +2053,10 @@ fcmd:
2053 2053
 				case ISFLAGSET_T:
2054 2054
 				case IF_T:
2055 2055
 				case MODULE_T:
2056
+				case SET_FWD_NO_CONNECT_T:
2057
+				case SET_RPL_NO_CONNECT_T:
2058
+				case SET_FWD_CLOSE_T:
2059
+				case SET_RPL_CLOSE_T:
2056 2060
 					$$=$1;
2057 2061
 					break;
2058 2062
 				default:
... ...
@@ -55,6 +55,7 @@ extern struct onsend_info* p_onsend;
55 55
 
56 56
 /*
57 57
  * returns: 0 drop the message, >= ok, <0 error (but forward the message)
58
+ * it also migh change dst->send_flags!
58 59
  * WARNING: buf must be 0 terminated (to allow regex matches on it) */
59 60
 static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
60 61
 								char* buf, int len)
... ...
@@ -63,6 +64,8 @@ static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
63 63
 	int ret;
64 64
 	struct run_act_ctx ra_ctx;
65 65
 	int backup_route_type;
66
+	snd_flags_t fwd_snd_flags_bak;
67
+	snd_flags_t rpl_snd_flags_bak;
66 68
 	
67 69
 	ret=1;
68 70
 	if (onsend_rt.rlist[DEFAULT_RT]){
... ...
@@ -74,8 +77,17 @@ static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
74 74
 		backup_route_type=get_route_type();
75 75
 		set_route_type(ONSEND_ROUTE);
76 76
 		if (exec_pre_script_cb(orig_msg, ONSEND_CB_TYPE)>0) {
77
+			/* backup orig_msg send flags */
78
+			fwd_snd_flags_bak=orig_msg->fwd_send_flags;
79
+			rpl_snd_flags_bak=orig_msg->rpl_send_flags;
80
+			orig_msg->fwd_send_flags=dst->send_flags; /* intial value */
77 81
 			init_run_actions_ctx(&ra_ctx);
78 82
 			ret=run_actions(&ra_ctx, onsend_rt.rlist[DEFAULT_RT], orig_msg);
83
+			/* update dst send_flags */
84
+			dst->send_flags=orig_msg->fwd_send_flags;
85
+			/* restore orig_msg flags */
86
+			orig_msg->fwd_send_flags=fwd_snd_flags_bak;
87
+			orig_msg->rpl_send_flags=rpl_snd_flags_bak;
79 88
 			exec_post_script_cb(orig_msg, ONSEND_CB_TYPE);
80 89
 		} else {
81 90
 			ret=0; /* drop the message */