2
0
Эх сурвалжийг харах

core: functions to get a fixup corresp. fixup_free function

Added functions  that given a known fixup, returns its
corresponding fixup_free function.
The known fixups are the fparam style fixups and the kamailio
style fixups (from mod_fix.h).
Andrei Pelinescu-Onciul 15 жил өмнө
parent
commit
0b52bcff63
4 өөрчлөгдсөн 87 нэмэгдсэн , 2 устгасан
  1. 30 0
      mod_fix.c
  2. 4 0
      mod_fix.h
  3. 50 2
      sr_module.c
  4. 3 0
      sr_module.h

+ 30 - 0
mod_fix.c

@@ -497,3 +497,33 @@ FIXUP_F_SPVE_T(spve_spve, 1, 2, 2, 0)
 FIXUP_F_SPVE_T(spve_uint, 1, 2, 1, FPARAM_INT)
 FIXUP_F_SPVE_T(spve_str, 1, 2, 1, FPARAM_STR)
 FIXUP_F_SPVE_T(spve_null, 1, 1, 1, 0)
+
+/** get the corresp. fixup_free* function.
+ * @param f -fixup function pointer.
+ * @return  - pointer to free_fixup function if known, 0 otherwise.
+ */
+free_fixup_function mod_fix_get_fixup_free(fixup_function f)
+{
+	if (f == fixup_str_null) return fixup_free_str_null;
+	if (f == fixup_str_str) return fixup_free_str_str;
+	/* no free fixup for fixup_uint_* (they overwrite the pointer
+	   value with a number and the original value cannot be recovered) */
+	if (f == fixup_uint_null) return 0;
+	if (f == fixup_uint_uint) return 0;
+	if (f == fixup_regexp_null) return fixup_free_regexp_null;
+	if (f == fixup_pvar_null) return fixup_free_pvar_null;
+	if (f == fixup_pvar_pvar) return fixup_free_pvar_pvar;
+	if (f == fixup_pvar_str) return fixup_free_pvar_str;
+	if (f == fixup_pvar_str_str) return fixup_free_pvar_str_str;
+	if (f == fixup_igp_igp) return fixup_free_igp_igp;
+	if (f == fixup_igp_null) return fixup_free_igp_null;
+	if (f == fixup_igp_pvar) return fixup_free_igp_pvar;
+	if (f == fixup_igp_pvar_pvar) return fixup_free_igp_pvar_pvar;
+	if (f == fixup_spve_spve) return fixup_free_spve_spve;
+	if (f == fixup_spve_null) return fixup_free_spve_null;
+	/* no free fixup, because of the uint part (the uint cannot be freed,
+	   see above fixup_uint_null) */
+	if (f == fixup_spve_uint) return 0;
+	if (f == fixup_spve_str) return fixup_free_spve_str;
+	return 0;
+}

+ 4 - 0
mod_fix.h

@@ -125,4 +125,8 @@ int fixup_spve_uint(void** param, int param_no);
 int fixup_spve_str(void** param, int param_no);
 int fixup_free_spve_str(void** param, int param_no);
 
+
+/** get the corresp. free fixup function.*/
+free_fixup_function mod_fix_get_fixup_free(fixup_function f);
+
 #endif

+ 50 - 2
sr_module.c

@@ -49,6 +49,7 @@
  */
 
 #include "sr_module.h"
+#include "mod_fix.h"
 #include "dprint.h"
 #include "error.h"
 #include "mem/mem.h"
@@ -1634,7 +1635,7 @@ int fixup_free_fparam_2(void** param, int param_no)
 
 
 /** returns true if a fixup is a fparam_t* one.
- * Used to automatically detect fparam fixups that can be used with non
+ * Used to automatically detect "pure" fparam fixups that can be used with non
  * contant RVEs.
  * @param f - function pointer
  * @return 1 for fparam fixups, 0 for others.
@@ -1652,7 +1653,54 @@ int is_fparam_rve_fixup(fixup_function f)
 		f == fixup_int_2 ||
 		f == fixup_str_12 ||
 		f == fixup_str_1 ||
-		f == fixup_str_2)
+		f == fixup_str_2 ||
+		f == fixup_regex_12 ||
+		f == fixup_regex_1 ||
+		f == fixup_regex_2
+		)
 		return 1;
 	return 0;
 }
+
+
+
+/** returns the corresponding fixup_free* for various known fixup types.
+ * Used to automatically fill in free_fixup* functions.
+ * @param f - fixup function pointer
+ * @return - free fixup function pointer on success, 0 on failure (unknown
+ *           fixup or no free fixup function).
+ */
+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_int_12 ||
+		f == fixup_int_12 ||
+		f == fixup_str_12 ||
+		f == fixup_regex_12)
+		return fixup_free_fparam_all;
+	
+	/* "pure" fparam, 1st parameter */
+	if (f == fixup_var_str_1 ||
+		f == fixup_var_int_1 ||
+		f == fixup_int_1 ||
+		f == fixup_str_1 ||
+		f == fixup_regex_1)
+		return fixup_free_fparam_1;
+	
+	/* "pure" fparam, 2nd parameters */
+	if (f == fixup_var_str_2 ||
+		f == fixup_var_int_2 ||
+		f == fixup_int_2 ||
+		f == fixup_str_2 ||
+		f == fixup_regex_2)
+		return fixup_free_fparam_2;
+	
+	/* mod_fix.h kamailio style fixups */
+	if ((ret = mod_fix_get_fixup_free(f)) != 0)
+		return ret;
+	
+	/* unknown */
+	return 0;
+}

+ 3 - 0
sr_module.h

@@ -600,4 +600,7 @@ 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);
+
+free_fixup_function get_fixup_free(fixup_function f);
+
 #endif /* sr_module_h */