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 1299
 		if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
1300 1300
 		if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
1301 1301
 		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 1302
 	}
1306 1303
 	if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
1307 1304
 	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 1324
 }
1325 1325
 
1326 1326
 
1327
+
1328
+/** fixup variable-pve-string.
1329
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
1330
+ * or string.
1331
+ * PVAR, AVP and select and non-static PVEs  identifiers will be resolved to
1332
+ * their values during runtime.
1333
+ * The parameter value will be converted to fparam structure
1334
+ * @param  param - double pointer to param, as for normal fixup functions.
1335
+ * @param  param_no - parameter number, ignored.
1336
+ * @return -1 on an error, 0 on success.
1337
+ */
1338
+int fixup_var_pve_str_12(void** param, int param_no)
1339
+{
1340
+	int ret;
1341
+	fparam_t* fp;
1342
+	if (fixup_get_param_type(param) != STRING_RVE_ST) {
1343
+		/* if called with a RVE already converted to string =>
1344
+		   don't try AVP, PVAR, SELECT or PVE again (to avoid double
1345
+		   deref., e.g.: $foo="$bar"; f($foo) ) */
1346
+		if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
1347
+		if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
1348
+		if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
1349
+		if ((ret = fix_param(FPARAM_PVE, param)) <= 0) {
1350
+			if (ret < 0)
1351
+				return ret;
1352
+			/* check if it resolved to a dynamic or "static" PVE.
1353
+			   If the resulting PVE is static (normal string), discard
1354
+			   it and use the normal string fixup (faster at runtime) */
1355
+			fp = (fparam_t*)*param;
1356
+			if (fp->v.pve->spec.getf == 0)
1357
+				fparam_free_restore(param); /* fallback to STR below */
1358
+			else
1359
+				return ret; /* dynamic PVE => return */
1360
+		}
1361
+		
1362
+	}
1363
+	if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
1364
+	ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
1365
+			" failed\n");
1366
+	return -1;
1367
+}
1368
+
1369
+/* Same as fixup_var_pve_str_12 but applies to the 1st parameter only */
1370
+int fixup_var_pve_str_1(void** param, int param_no)
1371
+{
1372
+	if (param_no == 1) return fixup_var_pve_str_12(param, param_no);
1373
+	else return 0;
1374
+}
1375
+
1376
+/* Same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
1377
+int fixup_var_pve_str_2(void** param, int param_no)
1378
+{
1379
+	if (param_no == 2) return fixup_var_pve_str_12(param, param_no);
1380
+	else return 0;
1381
+}
1382
+
1383
+
1384
+
1327 1385
 /*
1328 1386
  * Fixup variable integer, the parameter can be
1329 1387
  * AVP, SELECT, or ordinary integer. AVP and select
... ...
@@ -1654,6 +1707,9 @@ int is_fparam_rve_fixup(fixup_function f)
1654 1654
 	if (f == fixup_var_str_12 ||
1655 1655
 		f == fixup_var_str_1 ||
1656 1656
 		f == fixup_var_str_2 ||
1657
+		f == fixup_var_pve_str_12 ||
1658
+		f == fixup_var_pve_str_1 ||
1659
+		f == fixup_var_pve_str_2 ||
1657 1660
 		f == fixup_var_int_12 ||
1658 1661
 		f == fixup_var_int_1 ||
1659 1662
 		f == fixup_var_int_2 ||
... ...
@@ -1684,6 +1740,7 @@ free_fixup_function get_fixup_free(fixup_function f)
1684 1684
 	free_fixup_function ret;
1685 1685
 	/* "pure" fparam, all parameters */
1686 1686
 	if (f == fixup_var_str_12 ||
1687
+		f == fixup_var_pve_str_12 ||
1687 1688
 		f == fixup_var_int_12 ||
1688 1689
 		f == fixup_int_12 ||
1689 1690
 		f == fixup_str_12 ||
... ...
@@ -1692,6 +1749,7 @@ free_fixup_function get_fixup_free(fixup_function f)
1692 1692
 	
1693 1693
 	/* "pure" fparam, 1st parameter */
1694 1694
 	if (f == fixup_var_str_1 ||
1695
+		f == fixup_var_pve_str_1 ||
1695 1696
 		f == fixup_var_int_1 ||
1696 1697
 		f == fixup_int_1 ||
1697 1698
 		f == fixup_str_1 ||
... ...
@@ -1700,6 +1758,7 @@ free_fixup_function get_fixup_free(fixup_function f)
1700 1700
 	
1701 1701
 	/* "pure" fparam, 2nd parameters */
1702 1702
 	if (f == fixup_var_str_2 ||
1703
+		f == fixup_var_pve_str_2 ||
1703 1704
 		f == fixup_var_int_2 ||
1704 1705
 		f == fixup_int_2 ||
1705 1706
 		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 515
 /* Same as fixup_var_str_12 but applies to the 2nd parameter only */
516 516
 int fixup_var_str_2(void** param, int param_no);
517 517
 
518
+/** fixup variable-pve-string.
519
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
520
+ * or string.
521
+ */
522
+int fixup_var_pve_str_12(void** param, int param_no);
523
+
524
+/* same as fixup_var_pve_str_12 but applies to the 1st parameter only */
525
+int fixup_var_pve_str_1(void** param, int param_no);
526
+
527
+/* same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
528
+int fixup_var_pve_str_2(void** param, int param_no);
529
+
518 530
 /*
519 531
  * Fixup variable integer, the parameter can be
520 532
  * AVP, SELECT, or ordinary integer. AVP and select