Browse code

pv: new config variable $fsn - forced send socket name

- retrieve the name of the forced send socket
- setting the send socket can be done by assigning socket name:
$fsn = "sock1";

Daniel-Constantin Mierla authored on 02/04/2020 10:22:51
Showing 3 changed files
... ...
@@ -250,6 +250,9 @@ static pv_export_t mod_pvs[] = {
250 250
 	{{"fs", (sizeof("fs")-1)}, /* */
251 251
 		PVT_OTHER, pv_get_force_sock, pv_set_force_sock,
252 252
 		0, 0, 0, 0},
253
+	{{"fsn", (sizeof("fsn")-1)}, /* */
254
+		PVT_OTHER, pv_get_force_sock_name, pv_set_force_sock_name,
255
+		0, 0, 0, 0},
253 256
 	{{"ft", (sizeof("ft")-1)}, /* */
254 257
 		PVT_OTHER, pv_get_from_attr, 0,
255 258
 		0, 0, pv_init_iname, 4},
... ...
@@ -1021,6 +1021,21 @@ int pv_get_force_sock(struct sip_msg *msg, pv_param_t *param,
1021 1021
 	return pv_get_strval(msg, param, res, &msg->force_send_socket->sock_str);
1022 1022
 }
1023 1023
 
1024
+int pv_get_force_sock_name(struct sip_msg *msg, pv_param_t *param,
1025
+		pv_value_t *res)
1026
+{
1027
+	if(msg==NULL) {
1028
+		return -1;
1029
+	}
1030
+
1031
+	if (msg->force_send_socket==0
1032
+				|| msg->force_send_socket->sockname.s == NULL) {
1033
+		return pv_get_null(msg, param, res);
1034
+	}
1035
+
1036
+	return pv_get_strval(msg, param, res, &msg->force_send_socket->sockname);
1037
+}
1038
+
1024 1039
 int pv_get_useragent(struct sip_msg *msg, pv_param_t *param,
1025 1040
 		pv_value_t *res)
1026 1041
 {
... ...
@@ -2655,6 +2670,40 @@ error:
2655 2670
 	return -1;
2656 2671
 }
2657 2672
 
2673
+int pv_set_force_sock_name(struct sip_msg* msg, pv_param_t *param,
2674
+		int op, pv_value_t *val)
2675
+{
2676
+	struct socket_info *si;
2677
+
2678
+	if(msg==NULL || param==NULL) {
2679
+		LM_ERR("bad parameters\n");
2680
+		return -1;
2681
+	}
2682
+
2683
+	if(val==NULL || (val->flags&PV_VAL_NULL)) {
2684
+		reset_force_socket(msg);
2685
+		return 0;
2686
+	}
2687
+
2688
+	if(!(val->flags&PV_VAL_STR) || val->rs.len<=0) {
2689
+		LM_ERR("str value required to set the force send sock\n");
2690
+		goto error;
2691
+	}
2692
+
2693
+	LM_DBG("trying to set send-socket to name [%.*s]\n", val->rs.len, val->rs.s);
2694
+	si = ksr_get_socket_by_name(&val->rs);
2695
+	if (si!=NULL) {
2696
+		set_force_socket(msg, si);
2697
+	} else {
2698
+		LM_WARN("no socket found to match name [%.*s]\n",
2699
+				val->rs.len, val->rs.s);
2700
+	}
2701
+
2702
+	return 0;
2703
+error:
2704
+	return -1;
2705
+}
2706
+
2658 2707
 int pv_set_mflags(struct sip_msg* msg, pv_param_t *param,
2659 2708
 		int op, pv_value_t *val)
2660 2709
 {
... ...
@@ -175,6 +175,9 @@ int pv_get_rcvadv_uri_full(struct sip_msg *msg, pv_param_t *param,
175 175
 int pv_get_force_sock(struct sip_msg *msg, pv_param_t *param,
176 176
 		pv_value_t *res);
177 177
 
178
+int pv_get_force_sock_name(struct sip_msg *msg, pv_param_t *param,
179
+		pv_value_t *res);
180
+
178 181
 int pv_get_useragent(struct sip_msg *msg, pv_param_t *param,
179 182
 		pv_value_t *res);
180 183
 
... ...
@@ -295,6 +298,9 @@ int pv_set_branch(struct sip_msg* msg, pv_param_t *param,
295 298
 int pv_set_force_sock(struct sip_msg* msg, pv_param_t *param,
296 299
 		int op, pv_value_t *val);
297 300
 
301
+int pv_set_force_sock_name(struct sip_msg* msg, pv_param_t *param,
302
+		int op, pv_value_t *val);
303
+
298 304
 int pv_set_mflags(struct sip_msg* msg, pv_param_t *param,
299 305
 		int op, pv_value_t *val);
300 306