Browse code

pv: xavp_push_dst(xname) function

- push a destination from XAVP attributes

Daniel-Constantin Mierla authored on 13/05/2022 13:52:26
Showing 1 changed files
... ...
@@ -29,6 +29,7 @@
29 29
 #include "../../core/mod_fix.h"
30 30
 #include "../../core/xavp.h"
31 31
 #include "../../core/kemi.h"
32
+#include "../../core/dset.h"
32 33
 #include "../../core/rpc.h"
33 34
 #include "../../core/rpc_lookup.h"
34 35
 #include "../../core/strutils.h"
... ...
@@ -611,6 +612,7 @@ static int w_xavi_rm(sip_msg_t *msg, char *prname, char *p2);
611 612
 static int w_xavi_child_rm(sip_msg_t *msg, char *prname, char *pcname);
612 613
 
613 614
 static int w_xavp_lshift(sip_msg_t *msg, char *pxname, char *pidx);
615
+static int w_xavp_push_dst(sip_msg_t *msg, char *pxname, char *p2);
614 616
 
615 617
 int pv_xavp_copy_fixup(void** param, int param_no);
616 618
 int pv_evalx_fixup(void** param, int param_no);
... ...
@@ -691,6 +693,9 @@ static cmd_export_t cmds[]={
691 693
 	{"xavp_lshift", (cmd_function)w_xavp_lshift,
692 694
 		2, fixup_spve_igp, fixup_free_spve_igp,
693 695
 		ANY_ROUTE},
696
+	{"xavp_push_dst", (cmd_function)w_xavp_push_dst,
697
+		1, fixup_spve_null, fixup_free_spve_null,
698
+		ANY_ROUTE},
694 699
 	{"sbranch_set_ruri",  (cmd_function)w_sbranch_set_ruri,  0, 0, 0,
695 700
 		ANY_ROUTE },
696 701
 	{"sbranch_append",    (cmd_function)w_sbranch_append,    0, 0, 0,
... ...
@@ -943,6 +948,84 @@ static int w_xavp_lshift(sip_msg_t *msg, char *pxname, char *pidx)
943 948
 	return ki_xavp_lshift(msg, &xname, idx);
944 949
 }
945 950
 
951
+/**
952
+ *
953
+ */
954
+static int ki_xavp_push_dst(sip_msg_t *msg, str *xname)
955
+{
956
+	sr_xavp_t *rxavp = NULL;
957
+	sr_xavp_t *lxavp = NULL;
958
+	str fxname = STR_NULL;
959
+	socket_info_t *si;
960
+
961
+	rxavp = xavp_get(xname, NULL);
962
+	if(rxavp == NULL || rxavp->val.type != SR_XTYPE_XAVP) {
963
+		LM_DBG("no xavp with destination attributes\n");
964
+		return -1;
965
+	}
966
+
967
+	/* retrieve attributes from sub list */
968
+	rxavp = rxavp->val.v.xavp;
969
+
970
+	STR_STATIC_SET(fxname, "uri")
971
+	lxavp = xavp_get(&fxname, rxavp);
972
+	if(lxavp!=NULL && lxavp->val.type==SR_XTYPE_STR) {
973
+		LM_DBG("xavp uri field in next destination record (%p)\n", lxavp);
974
+		if(rewrite_uri(msg, &lxavp->val.v.s) < 0) {
975
+			LM_ERR("error while setting r-uri with: %.*s\n",
976
+					lxavp->val.v.s.len, lxavp->val.v.s.s);
977
+			return -1;
978
+		}
979
+	}
980
+
981
+	STR_STATIC_SET(fxname, "dsturi")
982
+	lxavp = xavp_get(&fxname, rxavp);
983
+	if(lxavp!=NULL && lxavp->val.type==SR_XTYPE_STR) {
984
+		LM_DBG("xavp dsturi field in next destination record (%p)\n", lxavp);
985
+		if(set_dst_uri(msg, &lxavp->val.v.s) < 0) {
986
+			LM_ERR("error while setting dst uri with: %.*s\n",
987
+					lxavp->val.v.s.len, lxavp->val.v.s.s);
988
+			return -1;
989
+		}
990
+		/* dst_uri changes, so it makes sense to re-use the current uri for
991
+		 * forking */
992
+		ruri_mark_new(); /* re-use uri for serial forking */
993
+	}
994
+
995
+	STR_STATIC_SET(fxname, "socket")
996
+	lxavp = xavp_get(&fxname, rxavp);
997
+	if(lxavp!=NULL && lxavp->val.type==SR_XTYPE_STR) {
998
+		si = ksr_get_socket_by_address(&lxavp->val.v.s);
999
+		if(si != NULL) {
1000
+			set_force_socket(msg, si);
1001
+		}
1002
+	} else {
1003
+		STR_STATIC_SET(fxname, "sockptr")
1004
+		lxavp = xavp_get(&fxname, rxavp);
1005
+		if(lxavp!=NULL && lxavp->val.type==SR_XTYPE_VPTR) {
1006
+			LM_DBG("socket enforced in next destination record\n");
1007
+			set_force_socket(msg, lxavp->val.v.vptr);
1008
+		}
1009
+	}
1010
+
1011
+	return 1;
1012
+}
1013
+
1014
+/**
1015
+ *
1016
+ */
1017
+static int w_xavp_push_dst(sip_msg_t *msg, char *pxname, char *p2)
1018
+{
1019
+	str xname = STR_NULL;
1020
+
1021
+	if(fixup_get_svalue(msg, (gparam_t*)pxname, &xname)<0) {
1022
+		LM_ERR("failed to get the xavp name\n");
1023
+		return -1;
1024
+	}
1025
+
1026
+	return ki_xavp_push_dst(msg, &xname);
1027
+}
1028
+
946 1029
 static int ki_xavu_print(sip_msg_t* msg)
947 1030
 {
948 1031
 	xavu_print_list(NULL);
... ...
@@ -3222,6 +3305,11 @@ static sr_kemi_t sr_kemi_pvx_exports[] = {
3222 3305
 		{ SR_KEMIP_STR, SR_KEMIP_INT, SR_KEMIP_NONE,
3223 3306
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3224 3307
 	},
3308
+	{ str_init("pvx"), str_init("xavp_push_dst"),
3309
+		SR_KEMIP_INT, ki_xavp_push_dst,
3310
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
3311
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
3312
+	},
3225 3313
 
3226 3314
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
3227 3315
 };