[sr-dev] git:master: core: don't try to fixup to PVE in fixup_var_str*

Andrei Pelinescu-Onciul andrei at iptel.org
Tue Aug 24 12:38:33 CEST 2010


Module: sip-router
Branch: master
Commit: a5b499a42d9b0613cc3e99619e744cbe894db3c1
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a5b499a42d9b0613cc3e99619e744cbe894db3c1

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Tue Aug 24 12:27:08 2010 +0200

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).

---

 sr_module.c |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 sr_module.h |   17 +++++++++++--
 2 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/sr_module.c b/sr_module.c
index c759a17..f975062 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -41,11 +41,9 @@
  *  2008-11-26  added fparam_free_contents() and fix_param_types (andrei)
  */
 
-/*!
- * \file
- * \brief SIP-router core :: 
- * \ingroup core
- * Module: \ref core
+/** module loading, standard fixups.
+ * @file sr_module.c
+ * @ingroup core
  */
 
 #include "sr_module.h"
@@ -1299,9 +1297,6 @@ int fixup_var_str_12(void** param, int param_no)
 		if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
 		if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
 		if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
-		/* FIXME: if not PVE (string only), fix as string! or
-		   make a separate fixup  fixup_varpve_... */
-		if ((ret = fix_param(FPARAM_PVE, param)) <= 0) return ret;
 	}
 	if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
 	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)
 }
 
 
+
+/** fixup variable-pve-string.
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
+ * or string.
+ * PVAR, AVP and select and non-static PVEs  identifiers will be resolved to
+ * their values during runtime.
+ * The parameter value will be converted to fparam structure
+ * @param  param - double pointer to param, as for normal fixup functions.
+ * @param  param_no - parameter number, ignored.
+ * @return -1 on an error, 0 on success.
+ */
+int fixup_var_pve_str_12(void** param, int param_no)
+{
+	int ret;
+	fparam_t* fp;
+	if (fixup_get_param_type(param) != STRING_RVE_ST) {
+		/* if called with a RVE already converted to string =>
+		   don't try AVP, PVAR, SELECT or PVE again (to avoid double
+		   deref., e.g.: $foo="$bar"; f($foo) ) */
+		if ((ret = fix_param(FPARAM_PVS, param)) <= 0) return ret;
+		if ((ret = fix_param(FPARAM_AVP, param)) <= 0) return ret;
+		if ((ret = fix_param(FPARAM_SELECT, param)) <= 0) return ret;
+		if ((ret = fix_param(FPARAM_PVE, param)) <= 0) {
+			if (ret < 0)
+				return ret;
+			/* check if it resolved to a dynamic or "static" PVE.
+			   If the resulting PVE is static (normal string), discard
+			   it and use the normal string fixup (faster at runtime) */
+			fp = (fparam_t*)*param;
+			if (fp->v.pve->spec.getf == 0)
+				fparam_free_restore(param); /* fallback to STR below */
+			else
+				return ret; /* dynamic PVE => return */
+		}
+		
+	}
+	if ((ret = fix_param(FPARAM_STR, param)) <= 0) return ret;
+	ERR("Error while fixing parameter, PV, AVP, SELECT, and str conversions"
+			" failed\n");
+	return -1;
+}
+
+/* Same as fixup_var_pve_str_12 but applies to the 1st parameter only */
+int fixup_var_pve_str_1(void** param, int param_no)
+{
+	if (param_no == 1) return fixup_var_pve_str_12(param, param_no);
+	else return 0;
+}
+
+/* Same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
+int fixup_var_pve_str_2(void** param, int param_no)
+{
+	if (param_no == 2) return fixup_var_pve_str_12(param, param_no);
+	else return 0;
+}
+
+
+
 /*
  * Fixup variable integer, the parameter can be
  * AVP, SELECT, or ordinary integer. AVP and select
@@ -1654,6 +1707,9 @@ int is_fparam_rve_fixup(fixup_function f)
 	if (f == fixup_var_str_12 ||
 		f == fixup_var_str_1 ||
 		f == fixup_var_str_2 ||
+		f == fixup_var_pve_str_12 ||
+		f == fixup_var_pve_str_1 ||
+		f == fixup_var_pve_str_2 ||
 		f == fixup_var_int_12 ||
 		f == fixup_var_int_1 ||
 		f == fixup_var_int_2 ||
@@ -1684,6 +1740,7 @@ free_fixup_function get_fixup_free(fixup_function f)
 	free_fixup_function ret;
 	/* "pure" fparam, all parameters */
 	if (f == fixup_var_str_12 ||
+		f == fixup_var_pve_str_12 ||
 		f == fixup_var_int_12 ||
 		f == fixup_int_12 ||
 		f == fixup_str_12 ||
@@ -1692,6 +1749,7 @@ free_fixup_function get_fixup_free(fixup_function f)
 	
 	/* "pure" fparam, 1st parameter */
 	if (f == fixup_var_str_1 ||
+		f == fixup_var_pve_str_1 ||
 		f == fixup_var_int_1 ||
 		f == fixup_int_1 ||
 		f == fixup_str_1 ||
@@ -1700,6 +1758,7 @@ free_fixup_function get_fixup_free(fixup_function f)
 	
 	/* "pure" fparam, 2nd parameters */
 	if (f == fixup_var_str_2 ||
+		f == fixup_var_pve_str_2 ||
 		f == fixup_var_int_2 ||
 		f == fixup_int_2 ||
 		f == fixup_str_2 ||
diff --git a/sr_module.h b/sr_module.h
index 4d32514..fb8be8b 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -49,9 +49,8 @@
  *  2008-11-26  added fparam_free_contents() and fix_param_types (andrei)
  */
 
-/*!
- * \file
- * \brief modules/plug-in structures declarations
+/** modules structures/exports declarations and utilities (fixups a.s.o).
+ * @file sr_module.h
  */
 
 
@@ -515,6 +514,18 @@ int fixup_var_str_1(void** param, int param_no);
 /* Same as fixup_var_str_12 but applies to the 2nd parameter only */
 int fixup_var_str_2(void** param, int param_no);
 
+/** fixup variable-pve-string.
+ * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
+ * or string.
+ */
+int fixup_var_pve_str_12(void** param, int param_no);
+
+/* same as fixup_var_pve_str_12 but applies to the 1st parameter only */
+int fixup_var_pve_str_1(void** param, int param_no);
+
+/* same as fixup_var_pve_str_12 but applies to the 2nd parameter only */
+int fixup_var_pve_str_2(void** param, int param_no);
+
 /*
  * Fixup variable integer, the parameter can be
  * AVP, SELECT, or ordinary integer. AVP and select




More information about the sr-dev mailing list