Browse code

core: added function to help fixup of PVE, string and expressions

- existing function could convert single pv PVE in PVAR, which can cause
troubles as PVE value should be always zero terminated

Daniel-Constantin Mierla authored on 19/12/2011 20:58:24
Showing 2 changed files
... ...
@@ -1385,6 +1385,43 @@ int fixup_var_str_2(void** param, int param_no)
1385 1385
 	else return 0;
1386 1386
 }
1387 1387
 
1388
+/** fixup variable-pve-only-string.
1389
+ * The parameter can be a PVE (pv based format string)
1390
+ * or string.
1391
+ * non-static PVEs  identifiers will be resolved to
1392
+ * their values during runtime.
1393
+ * The parameter value will be converted to fparam structure
1394
+ * @param  param - double pointer to param, as for normal fixup functions.
1395
+ * @param  param_no - parameter number, ignored.
1396
+ * @return -1 on an error, 0 on success.
1397
+ */
1398
+int fixup_var_pve_12(void** param, int param_no)
1399
+{
1400
+	int ret;
1401
+	fparam_t* fp;
1402
+	if (fixup_get_param_type(param) != STRING_RVE_ST) {
1403
+		/* if called with a RVE already converted to string =>
1404
+		   don't try PVE again (to avoid double
1405
+		   deref., e.g.: $foo="$bar"; f($foo) ) */
1406
+		if ((ret = fix_param(FPARAM_PVE, param)) <= 0) {
1407
+			if (ret < 0)
1408
+				return ret;
1409
+			/* check if it resolved to a dynamic or "static" PVE.
1410
+			   If the resulting PVE is static (normal string), discard
1411
+			   it and use the normal string fixup (faster at runtime) */
1412
+			fp = (fparam_t*)*param;
1413
+			if (fp->v.pve->spec.getf == 0)
1414
+				fparam_free_restore(param); /* fallback to STR below */
1415
+			else
1416
+				return ret; /* dynamic PVE => return */
1417
+		}
1418
+		
1419
+	}
1420
+	if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
1421
+	ERR("Error while fixing parameter - PVE or str conversions failed\n");
1422
+	return -1;
1423
+}
1424
+
1388 1425
 
1389 1426
 
1390 1427
 /** fixup variable-pve-string.
... ...
@@ -542,6 +542,9 @@ int fixup_var_str_1(void** param, int param_no);
542 542
 /** Same as fixup_var_str_12 but applies to the 2nd parameter only */
543 543
 int fixup_var_str_2(void** param, int param_no);
544 544
 
545
+/** fixup variable-pve-only-string. */
546
+int fixup_var_pve_12(void** param, int param_no);
547
+
545 548
 /** fixup variable-pve-string.
546 549
  * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
547 550
  * or string.