sip-router

SIP Router Project

Tasklist

FS#78 - function for evaluating string value

Attached to Project: sip-router
Opened by Juha Heinanen (jh) - Wednesday, 30 June 2010, 14:49 GMT
Task Type Feature Request
Category Module
Status New
Assigned To No-one
Operating System All
Severity Medium
Priority Normal
Reported Version Development
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No

Details

it 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

Comment by Daniel-Constantin Mierla (miconda) - Wednesday, 30 June 2010, 19:55 GMT

That might not be that easy right now in cfg – if I got right what you want it is not even in other languages – i.e., evaluating C code from a char* variable.

However, #!subst or #!define preprocessor directives should help to some extent.

Example:

#!define MYID "$(ru{uri.user})"

myfunction(MYID);

Comment by Juha Heinanen (jh) - Thursday, 01 July 2010, 07:08 GMT

defines do not work here, since the idea is to be able to dynamically at runtime to change string values of cfg variables that may contain pseudo variables and transformations. such strings may, for example, appear as parameters of http_queries,

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?

Loading...