Module: kamailio Branch: master Commit: fe0e98427b703d9ca41d626b24d99fc5a1c1f9d0 URL: https://github.com/kamailio/kamailio/commit/fe0e98427b703d9ca41d626b24d99fc5...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-05-02T09:09:36+02:00
core: pv - helper function to evaluate a dynamic string
---
Modified: pv_core.c Modified: pvar.h
---
Diff: https://github.com/kamailio/kamailio/commit/fe0e98427b703d9ca41d626b24d99fc5... Patch: https://github.com/kamailio/kamailio/commit/fe0e98427b703d9ca41d626b24d99fc5...
---
diff --git a/pv_core.c b/pv_core.c index 3d49552..3279a0a 100644 --- a/pv_core.c +++ b/pv_core.c @@ -53,7 +53,8 @@ static int pv_get_retcode(struct sip_msg* msg, pv_param_t* p, pv_value_t* res)
-/** register built-in core pvars. +/** + * register built-in core pvars. * should be called before parsing the config script. * @return 0 on success */ @@ -62,4 +63,32 @@ int pv_register_core_vars(void) return register_pvars_mod("core", core_pvs); }
+/** + * + */ +int pv_eval_str(sip_msg_t *msg, str *dst, str *src) +{ + pv_elem_t *xmodel=NULL; + str sval = STR_NULL; + + if(pv_parse_format(src, &xmodel)<0) { + LM_ERR("error in parsing src parameter\n"); + return -1; + } + + if(pv_printf_s(msg, xmodel, &sval)!=0) { + LM_ERR("cannot eval parsed parameter\n"); + pv_elem_free_all(xmodel); + goto error; + } + + dst->s = sval.s; + dst->len = sval.len; + pv_elem_free_all(xmodel); + + return 1; +error: + return -1; +} + /* vi: set ts=4 sw=4 tw=79:ai:cindent: */ diff --git a/pvar.h b/pvar.h index 6ad3d8c..68955ad 100644 --- a/pvar.h +++ b/pvar.h @@ -300,5 +300,7 @@ typedef struct _pv_xavp_name { struct _pv_xavp_name *next; } pv_xavp_name_t;
+int pv_eval_str(sip_msg_t *msg, str *dst, str *src); + #endif