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

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date:   Mon Dec 19 21:58:24 2011 +0100

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

---

 sr_module.c |   37 +++++++++++++++++++++++++++++++++++++
 sr_module.h |    3 +++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/sr_module.c b/sr_module.c
index 853c7a2..8bc52d9 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -1385,6 +1385,43 @@ int fixup_var_str_2(void** param, int param_no)
        else return 0;
 }
 
+/** fixup variable-pve-only-string.
+ * The parameter can be a PVE (pv based format string)
+ * or string.
+ * 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_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 PVE again (to avoid double
+                  deref., e.g.: $foo="$bar"; f($foo) ) */
+               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 - PVE or str conversions failed\n");
+       return -1;
+}
+
 
 
 /** fixup variable-pve-string.
diff --git a/sr_module.h b/sr_module.h
index ce8c781..810008f 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -542,6 +542,9 @@ 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-only-string. */
+int fixup_var_pve_12(void** param, int param_no);
+
 /** fixup variable-pve-string.
  * The parameter can be a PVAR, AVP, SELECT, PVE (pv based format string)
  * or string.


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to