Browse code

core: don't try to fixup to PVE in fixup_var_str*

Moved PVE (PV based format string) fixing attempts from
fixup_var_str* into new fixup functions: fixup_var_pve_str*.
If the argument is a constant string, fixup_var_pve_str*() will
try first "fixing" it to a PVAR, then (if it fails) to an AVP,
SELECT, PVE and finally normal string. If the PVE fixup returned a
"static" PVE, the result will be discarded and a normal string
fparam will be created (a little bit faster at runtime).
The only difference between fixup_var_str*() and
fixup_var_pve_str*() is that fixup_var_str*() will not attempt
fixing to PVE (does not support PV style format strings).

Andrei Pelinescu-Onciul authored on 24/08/2010 10:27:08
Showing 2 changed files
... ...
@@ -41,11 +41,9 @@
41 41
  *  2008-11-26  added fparam_free_contents() and fix_param_types (andrei)
42 42
  */
43 43
 
44
-/*!
45
- * \file
46
- * \brief SIP-router core :: 
47
- * \ingroup core
48
- * Module: \ref core
44
+/** module loading, standard fixups.
45
+ * @file sr_module.c
46
+ * @ingroup core
49 47
  */
50 48
 
51 49
 #include "sr_module.h"
... ...
@@ -1299,9 +1297,6 @@ int fixup_var_str_12(void** param, int param_no)
1299 1297
 		if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
1300 1298
 		if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
1301 1299
 		if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
1302
-		/* FIXME: if not PVE (string only), fix as string! or
1303
-		   make a separate fixup  fixup_varpve_... */
1304
-		if ((ret = fix_param(FPARAM_PVE, param)) <= 0) return ret;
1305 1300
 	}
1306 1301
 	if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
1307 1302
 	ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
... ...
@@ -1324,6 +1319,64 @@ int fixup_var_str_2(void** param, int param_no)
1324 1319
 }
1325 1320
 
1326 1321
 
1322
+
1323
+/** fixup variable-pve-string.
1324
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
1325
+ * or string.
1326
+ * PVAR, AVP and select and non-static PVEs  identifiers will be resolved to
1327
+ * their values during runtime.
1328
+ * The parameter value will be converted to fparam structure
1329
+ * @param  param - double pointer to param, as for normal fixup functions.
1330
+ * @param  param_no - parameter number, ignored.
1331
+ * @return -1 on an error, 0 on success.
1332
+ */
1333
+int fixup_var_pve_str_12(void** param, int param_no)
1334
+{
1335
+	int ret;
1336
+	fparam_t* fp;
1337
+	if (fixup_get_param_type(param) != STRING_RVE_ST) {
1338
+		/* if called with a RVE already converted to string =>
1339
+		   don't try AVP, PVAR, SELECT or PVE again (to avoid double
1340
+		   deref., e.g.: $foo="$bar"; f($foo) ) */
1341
+		if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
1342
+		if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
1343
+		if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
1344
+		if ((ret = fix_param(FPARAM_PVE, param)) <= 0) {
1345
+			if (ret < 0)
1346
+				return ret;
1347
+			/* check if it resolved to a dynamic or "static" PVE.
1348
+			   If the resulting PVE is static (normal string), discard
1349
+			   it and use the normal string fixup (faster at runtime) */
1350
+			fp = (fparam_t*)*param;
1351
+			if (fp->v.pve->spec.getf == 0)
1352
+				fparam_free_restore(param); /* fallback to STR below */
1353
+			else
1354
+				return ret; /* dynamic PVE => return */
1355
+		}
1356
+		
1357
+	}
1358
+	if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
1359
+	ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
1360
+			" failed\n");
1361
+	return -1;
1362
+}
1363
+
1364
+/* Same as fixup_var_pve_str_12 but applies to the 1st parameter only */
1365
+int fixup_var_pve_str_1(void** param, int param_no)
1366
+{
1367
+	if (param_no == 1) return fixup_var_pve_str_12(param, param_no);
1368
+	else return 0;
1369
+}
1370
+
1371
+/* Same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
1372
+int fixup_var_pve_str_2(void** param, int param_no)
1373
+{
1374
+	if (param_no == 2) return fixup_var_pve_str_12(param, param_no);
1375
+	else return 0;
1376
+}
1377
+
1378
+
1379
+
1327 1380
 /*
1328 1381
  * Fixup variable integer, the parameter can be
1329 1382
  * AVP, SELECT, or ordinary integer. AVP and select
... ...
@@ -1654,6 +1707,9 @@ int is_fparam_rve_fixup(fixup_function f)
1654 1707
 	if (f == fixup_var_str_12 ||
1655 1708
 		f == fixup_var_str_1 ||
1656 1709
 		f == fixup_var_str_2 ||
1710
+		f == fixup_var_pve_str_12 ||
1711
+		f == fixup_var_pve_str_1 ||
1712
+		f == fixup_var_pve_str_2 ||
1657 1713
 		f == fixup_var_int_12 ||
1658 1714
 		f == fixup_var_int_1 ||
1659 1715
 		f == fixup_var_int_2 ||
... ...
@@ -1684,6 +1740,7 @@ free_fixup_function get_fixup_free(fixup_function f)
1684 1740
 	free_fixup_function ret;
1685 1741
 	/* "pure" fparam, all parameters */
1686 1742
 	if (f == fixup_var_str_12 ||
1743
+		f == fixup_var_pve_str_12 ||
1687 1744
 		f == fixup_var_int_12 ||
1688 1745
 		f == fixup_int_12 ||
1689 1746
 		f == fixup_str_12 ||
... ...
@@ -1692,6 +1749,7 @@ free_fixup_function get_fixup_free(fixup_function f)
1692 1749
 	
1693 1750
 	/* "pure" fparam, 1st parameter */
1694 1751
 	if (f == fixup_var_str_1 ||
1752
+		f == fixup_var_pve_str_1 ||
1695 1753
 		f == fixup_var_int_1 ||
1696 1754
 		f == fixup_int_1 ||
1697 1755
 		f == fixup_str_1 ||
... ...
@@ -1700,6 +1758,7 @@ free_fixup_function get_fixup_free(fixup_function f)
1700 1758
 	
1701 1759
 	/* "pure" fparam, 2nd parameters */
1702 1760
 	if (f == fixup_var_str_2 ||
1761
+		f == fixup_var_pve_str_2 ||
1703 1762
 		f == fixup_var_int_2 ||
1704 1763
 		f == fixup_int_2 ||
1705 1764
 		f == fixup_str_2 ||
... ...
@@ -49,9 +49,8 @@
49 49
  *  2008-11-26  added fparam_free_contents() and fix_param_types (andrei)
50 50
  */
51 51
 
52
-/*!
53
- * \file
54
- * \brief modules/plug-in structures declarations
52
+/** modules structures/exports declarations and utilities (fixups a.s.o).
53
+ * @file sr_module.h
55 54
  */
56 55
 
57 56
 
... ...
@@ -515,6 +514,18 @@ int fixup_var_str_1(void** param, int param_no);
515 514
 /* Same as fixup_var_str_12 but applies to the 2nd parameter only */
516 515
 int fixup_var_str_2(void** param, int param_no);
517 516
 
517
+/** fixup variable-pve-string.
518
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
519
+ * or string.
520
+ */
521
+int fixup_var_pve_str_12(void** param, int param_no);
522
+
523
+/* same as fixup_var_pve_str_12 but applies to the 1st parameter only */
524
+int fixup_var_pve_str_1(void** param, int param_no);
525
+
526
+/* same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
527
+int fixup_var_pve_str_2(void** param, int param_no);
528
+
518 529
 /*
519 530
  * Fixup variable integer, the parameter can be
520 531
  * AVP, SELECT, or ordinary integer. AVP and select