SIP Router Project
FS#78 - function for evaluating string value
|
Detailsit would improve dynamic configuration of sip proxy if a function or transformation would exist for evaluating a string value stored in a pseudo variable that contains pseudo variables, transformations, etc.
i tried to implement such function (below), but was not able to make it work. any help is appreciated. -- juha /* * Evaluates first param (string) and saves result to second param (pvar) */ int eval(struct sip_msg* _m, char* _string, char* _dst) { str value, result; char **param; pv_spec_t *dst; pv_value_t val; fparam_t *fp; if (fixup_get_svalue(_m, (gparam_p)_string, &value) != 0) { LM_ERR("cannot get parameter value\n"); return -1; } param = &(value.s); LM_INFO("param value as string is <%s>\n", *param); if (fixup_spve_null((void **)param, 1) != 0) { LM_ERR("failed to evaluate parameter <%.*s>\n", value.len, value.s); return -1; } fp = (fparam_t *)param; LM_INFO("orig <%s>, type <%d>\n", fp->orig, fp->type); if (get_str_fparam(&result, _m, fp) != 0) { LM_ERR("cannot get result value\n"); return -1; } val.rs.s = result.s; val.rs.len = result.len; LM_INFO("eval result: %.*s\n", val.rs.len, val.rs.s); val.flags = PV_VAL_STR; dst = (pv_spec_t *)_dst; dst->setf(_m, &dst->pvp, (int)EQ_T, &val); return 1; } |
This task depends upon
However, #!subst or #!define preprocessor directives should help to some extent.
Example:
#!define MYID "$(ru{uri.user})"
myfunction(MYID);
what comes to implementation, this kind of stuff is normal in interpreted languages, for example
#!/usr/bin/php
<?
$format = "Printing number %d\n";
printf($format, 1234);
?>
correctly produces
jh@rautu:~$ /tmp/test.php
Printing number 1234
what comes to my the specific trial implementation, it first calls spve fixup on the string value that may contain pseudo variables and then tries to get final string value based on the fixup result. what exactly is wrong with this? why all calls succeed, but final string value is not correct?