Module: sip-router Branch: master Commit: f5cff79c5d6fa7270c56b1a7ca6e2d6902999c8c URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=f5cff79c...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri May 29 21:21:08 2009 +0300
kex: added K pv_printf() function
---
modules_k/kex/kex_mod.c | 2 + modules_k/kex/km_core.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++ modules_k/kex/km_core.h | 2 + 3 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/modules_k/kex/kex_mod.c b/modules_k/kex/kex_mod.c index 64f26a8..7fa5830 100644 --- a/modules_k/kex/kex_mod.c +++ b/modules_k/kex/kex_mod.c @@ -74,6 +74,8 @@ static cmd_export_t cmds[]={ 0, ANY_ROUTE }, {"isdsturiset", (cmd_function)w_isdsturiset, 0, 0, 0, ANY_ROUTE }, + {"pv_printf", (cmd_function)w_pv_printf, 2, pv_printf_fixup, + 0, ANY_ROUTE },
{0,0,0,0,0,0} }; diff --git a/modules_k/kex/km_core.c b/modules_k/kex/km_core.c index cea12ea..72e2dde 100644 --- a/modules_k/kex/km_core.c +++ b/modules_k/kex/km_core.c @@ -27,6 +27,8 @@ #include "../../dprint.h" #include "../../dset.h" #include "../../flags.h" +#include "../../pvar.h" +#include "../../lvalue.h" #include "../../mod_fix.h" #include "km_core.h"
@@ -95,3 +97,75 @@ int w_isdsturiset(struct sip_msg *msg, char *uri, str *s2) return 1; }
+int pv_printf_fixup(void** param, int param_no) +{ + pv_spec_t *spec=NULL; + pv_elem_t *pvmodel=NULL; + str tstr; + + if(param_no==1) + { + spec = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t)); + if(spec==NULL) + { + LM_ERR("out of pkg\n"); + return -1; + } + memset(spec, 0, sizeof(pv_spec_t)); + tstr.s = (char*)(*param); + tstr.len = strlen(tstr.s); + if(pv_parse_spec(&tstr, spec)==NULL) + { + LM_ERR("unknown script variable in first parameter"); + pkg_free(spec); + return -1; + } + if(!pv_is_w(spec)) + { + LM_ERR("read-only script variable in first parameter"); + pkg_free(spec); + return -1; + } + *param = spec; + } else if(param_no==2) { + pvmodel = 0; + tstr.s = (char*)(*param); + tstr.len = strlen(tstr.s); + if(pv_parse_format(&tstr, &pvmodel)<0) + { + LM_ERR("error in second parameter"); + return -1; + } + *param = pvmodel; + } + return 0; +} + +int w_pv_printf(struct sip_msg *msg, char *s1, str *s2) +{ + pv_spec_t *spec=NULL; + pv_elem_t *model=NULL; + pv_value_t val; + + spec = (pv_spec_t*)s1; + + model = (pv_elem_t*)s2; + + memset(&val, 0, sizeof(pv_value_t)); + if(pv_printf_s(msg, model, &val.rs)!=0) + { + LM_ERR("cannot eval second parameter\n"); + goto error; + } + val.flags = PV_VAL_STR; + if(spec->setf(msg, &spec->pvp, EQ_T, &val)<0) + { + LM_ERR("setting PV failed\n"); + goto error; + } + + return 1; +error: + return -1; +} + diff --git a/modules_k/kex/km_core.h b/modules_k/kex/km_core.h index 84fe5dd..5fa08f8 100644 --- a/modules_k/kex/km_core.h +++ b/modules_k/kex/km_core.h @@ -29,5 +29,7 @@ int w_km_append_branch(struct sip_msg *msg, char *uri, str *s2); int w_setdsturi(struct sip_msg *msg, char *uri, str *s2); int w_resetdsturi(struct sip_msg *msg, char *uri, str *s2); int w_isdsturiset(struct sip_msg *msg, char *uri, str *s2); +int w_pv_printf(struct sip_msg *msg, char *s1, str *s2); +int pv_printf_fixup(void** param, int param_no);
#endif