Browse code

carrierroute: updated cr_load_user_carrier() to support any output variable

- third parameter can be any writable
- added fixup-free function for it

Daniel-Constantin Mierla authored on 30/09/2022 09:16:48
Showing 5 changed files
... ...
@@ -88,7 +88,8 @@ static void mod_destroy(void);
88 88
 /************* Module Exports **********************************************/
89 89
 static cmd_export_t cmds[]={
90 90
 	{"cr_user_carrier",  (cmd_function)cr_load_user_carrier,  3,
91
-		cr_load_user_carrier_fixup, 0, REQUEST_ROUTE | FAILURE_ROUTE },
91
+		cr_load_user_carrier_fixup, cr_load_user_carrier_fixup_free,
92
+		REQUEST_ROUTE | FAILURE_ROUTE },
92 93
 	{"cr_route",         (cmd_function)cr_route5,              5,
93 94
 		cr_route_fixup,             0, REQUEST_ROUTE | FAILURE_ROUTE },
94 95
 	{"cr_route",         (cmd_function)cr_route,              6,
... ...
@@ -320,12 +320,36 @@ int cr_load_user_carrier_fixup(void ** param, int param_no) {
320 320
 		}
321 321
 	}
322 322
 	else if (param_no == 3) {
323
-		/* destination avp name */
324
-		if (avp_name_fixup(param) < 0) {
325
-			LM_ERR("cannot fixup parameter %d\n", param_no);
323
+		/* destination var name */
324
+		if(fixup_pvar_null(param, 1) != 0) {
325
+			LM_ERR("failed to fixup result pvar\n");
326
+			return -1;
327
+		}
328
+		if(((pv_spec_t *)(*param))->setf == NULL) {
329
+			LM_ERR("dst var is not writeble\n");
326 330
 			return -1;
327 331
 		}
332
+		return 0;
328 333
 	}
329 334
 
330 335
 	return 0;
331 336
 }
337
+
338
+/**
339
+ *
340
+ */
341
+int cr_load_user_carrier_fixup_free(void **param, int param_no)
342
+{
343
+	if((param_no >= 1) && (param_no <= 2)) {
344
+		return fixup_free_spve_null(param, 1);
345
+	}
346
+
347
+	if(param_no == 3) {
348
+		return fixup_free_pvar_null(param, 1);
349
+	}
350
+
351
+	LM_ERR("invalid parameter number <%d>\n", param_no);
352
+	return -1;
353
+}
354
+
355
+
... ...
@@ -53,6 +53,7 @@ int cr_route_fixup(void ** param, int param_no);
53 53
  */
54 54
 int cr_load_user_carrier_fixup(void ** param, int param_no);
55 55
 
56
+int cr_load_user_carrier_fixup_free(void ** param, int param_no);
56 57
 
57 58
 /**
58 59
  * Fixes the module functions' parameters, i.e. it maps
... ...
@@ -41,6 +41,7 @@
41 41
 #include "../../core/qvalue.h"
42 42
 #include "../../core/dset.h"
43 43
 #include "../../core/rand/kam_rand.h"
44
+#include "../../core/lvalue.h"
44 45
 #include "cr_map.h"
45 46
 #include "cr_rule.h"
46 47
 #include "cr_domain.h"
... ...
@@ -731,28 +732,31 @@ unlock_and_out:
731 732
  *
732 733
  * @return 1 on success, -1 on failure
733 734
  */
734
-int cr_load_user_carrier(struct sip_msg * _msg, gparam_t *_user, gparam_t *_domain, gparam_t *_dstavp) {
735
+int cr_load_user_carrier(struct sip_msg * _msg,
736
+		char *_user, char *_domain, char *_dstvar) {
735 737
 	str user, domain;
736
-	int_str avp_val;
737
-	
738
-	if (fixup_get_svalue(_msg, _user, &user)<0) {
738
+	pv_spec_t *dst;
739
+	pv_value_t val = {0};
740
+
741
+	if (fixup_get_svalue(_msg, (gparam_t*)_user, &user)<0) {
739 742
 		LM_ERR("cannot print the user\n");
740 743
 		return -1;
741 744
 	}
742 745
 
743
-	if (fixup_get_svalue(_msg, _domain, &domain)<0) {
746
+	if (fixup_get_svalue(_msg, (gparam_t*)_domain, &domain)<0) {
744 747
 		LM_ERR("cannot print the domain\n");
745 748
 		return -1;
746 749
 	}
747 750
 	/* get carrier id */
748
-	if ((avp_val.n = load_user_carrier(&user, &domain)) < 0) {
751
+	if ((val.ri = load_user_carrier(&user, &domain)) < 0) {
749 752
 		LM_ERR("error in load user carrier");
750 753
 		return -1;
751 754
 	} else {
752
-		/* set avp */
753
-		if (add_avp(_dstavp->v.pve->spec->pvp.pvn.u.isname.type,
754
-					_dstavp->v.pve->spec->pvp.pvn.u.isname.name, avp_val)<0) {
755
-			LM_ERR("add AVP failed\n");
755
+		/* set var */
756
+		dst = (pv_spec_t *)_dstvar;
757
+		val.flags = PV_VAL_INT|PV_TYPE_INT;
758
+		if(dst->setf(_msg, &dst->pvp, (int)EQ_T, &val)<0) {
759
+			LM_ERR("failed setting dst var\n");
756 760
 			return -1;
757 761
 		}
758 762
 	}
... ...
@@ -45,8 +45,8 @@
45 45
  *
46 46
  * @return 1 on success, -1 on failure
47 47
  */
48
-int cr_load_user_carrier(struct sip_msg * _msg, gparam_t *_user,
49
-		gparam_t *_domain, gparam_t *_dstavp);
48
+int cr_load_user_carrier(struct sip_msg * _msg, char *_user,
49
+		char *_domain, char *_dstavp);
50 50
 
51 51
 
52 52
 /**