Module: sip-router Branch: andrei/rve_f_params Commit: 0b52bcff633ea5482d6812d9f5a84faa7bbc2738 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=0b52bcff...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Thu Aug 5 23:09:26 2010 +0200
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).
---
mod_fix.c | 30 ++++++++++++++++++++++++++++++ mod_fix.h | 4 ++++ sr_module.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- sr_module.h | 3 +++ 4 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/mod_fix.c b/mod_fix.c index 0f4db9c..0182e6f 100644 --- a/mod_fix.c +++ b/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; +} diff --git a/mod_fix.h b/mod_fix.h index bd5d8a9..ec395b4 100644 --- a/mod_fix.h +++ b/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 diff --git a/sr_module.c b/sr_module.c index d552318..2628226 100644 --- a/sr_module.c +++ b/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; +} diff --git a/sr_module.h b/sr_module.h index 17606ab..7bbc19d 100644 --- a/sr_module.h +++ b/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 */