[sr-dev] git:andrei/rve_f_params: core: added generic fparam fixup_free functions

Andrei Pelinescu-Onciul andrei at iptel.org
Thu Aug 5 23:07:01 CEST 2010


Module: sip-router
Branch: andrei/rve_f_params
Commit: 6a40b4bdc0c9a481276cfdbfde3a70f833b85836
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6a40b4bdc0c9a481276cfdbfde3a70f833b85836

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Thu Aug  5 22:47:29 2010 +0200

core: added generic fparam fixup_free functions

Added generic fparam fixup_free functions that can be used to
clean up after a fparam fixup:

void fparam_free_restore(void** param);
int fixup_free_fparam_all(void** param, int param_no);
int fixup_free_fparam_1(void** param, int param_no);
int fixup_free_fparam_2(void** param, int param_no);

They will free anything that was allocated by the fixup and
restore the parameter pointer to the saved original value.

---

 mod_fix.c   |    1 +
 sr_module.c |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 sr_module.h |    9 ++++++++
 3 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/mod_fix.c b/mod_fix.c
index 2e5f076..69974b0 100644
--- a/mod_fix.c
+++ b/mod_fix.c
@@ -34,6 +34,7 @@
 
 #include "mod_fix.h"
 #include "mem/mem.h"
+#include "trim.h"
 
 
 
diff --git a/sr_module.c b/sr_module.c
index b729102..d552318 100644
--- a/sr_module.c
+++ b/sr_module.c
@@ -1169,6 +1169,7 @@ error:
 
 /** fparam_t free function.
  *  Frees the "content" of a fparam, but not the fparam itself.
+ *  Note: it doesn't free fp->orig!
  *  Assumes pkg_malloc'ed content.
  *  @param fp -  fparam to be freed
  *
@@ -1220,10 +1221,25 @@ void fparam_free_contents(fparam_t* fp)
 			}
 			break;
 	}
-	if (fp->orig){
-		pkg_free(fp->orig);
-		fp->orig=0;
-	}
+}
+
+
+
+/** generic free fixup type function for a fixed fparam.
+ * It will free whatever was allocated during the initial fparam fixup
+ * and restore the original param value.
+ */
+void fparam_free_restore(void** param)
+{
+	fparam_t *fp;
+	void *orig;
+	
+	fp = *param;
+	orig = fp->orig;
+	fp->orig = 0;
+	fparam_free_contents(fp);
+	pkg_free(fp);
+	*param = orig;
 }
 
 
@@ -1574,6 +1590,49 @@ int get_regex_fparam(regex_t *dst, struct sip_msg* msg, fparam_t* param)
 
 
 
+/** generic free fixup function for "pure" fparam type fixups.
+ * @param  param - double pointer to param, as for normal fixup functions.
+ * @param  param_no - parameter number, ignored.
+ * @return 0 on success (always).
+ */
+int fixup_free_fparam_all(void** param, int param_no)
+{
+	fparam_free_restore(param);
+	return 0;
+}
+
+
+
+/** generic free fixup function for "pure"  first parameter fparam type fixups.
+ * @param  param - double pointer to param, as for normal fixup functions.
+ * @param  param_no - parameter number: the function will work only for
+ *                     param_no == 1 (first parameter).
+ * @return 0 on success (always).
+ */
+int fixup_free_fparam_1(void** param, int param_no)
+{
+	if (param_no == 1)
+		fparam_free_restore(param);
+	return 0;
+}
+
+
+
+/** generic free fixup function for "pure"  2nd parameter fparam type fixups.
+ * @param  param - double pointer to param, as for normal fixup functions.
+ * @param  param_no - parameter number: the function will work only for
+ *                     param_no == 2 (2nd parameter).
+ * @return 0 on success (always).
+ */
+int fixup_free_fparam_2(void** param, int param_no)
+{
+	if (param_no == 2)
+		fparam_free_restore(param);
+	return 0;
+}
+
+
+
 /** returns true if a fixup is a fparam_t* one.
  * Used to automatically detect fparam fixups that can be used with non
  * contant RVEs.
diff --git a/sr_module.h b/sr_module.h
index 8048b6c..17606ab 100644
--- a/sr_module.h
+++ b/sr_module.h
@@ -591,4 +591,13 @@ int get_regex_fparam(regex_t *dst, struct sip_msg* msg, fparam_t* param);
 
 int is_fparam_rve_fixup(fixup_function f);
 
+
+/** generic free fixup type function for a fixed fparam.
+ * It will free whatever was allocated during the initial fparam fixup
+ * and restore the original param value.
+ */
+void fparam_free_restore(void** param);
+int fixup_free_fparam_all(void** param, int param_no);
+int fixup_free_fparam_1(void** param, int param_no);
+int fixup_free_fparam_2(void** param, int param_no);
 #endif /* sr_module_h */




More information about the sr-dev mailing list