MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / route_params_expand

Function route_params_expand

action.c:470–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468}
469
470static pv_value_t *route_params_expand(struct sip_msg *msg,
471 void *params, int params_no)
472{
473 str tmp;
474 int index;
475 pv_value_t *route_vals, *res;
476 action_elem_p actions = (action_elem_p)params;
477
478 route_vals = pkg_malloc(params_no * sizeof(*route_vals));
479 if (!route_vals) {
480 LM_ERR("oom\n");
481 return NULL;
482 }
483 memset(route_vals, 0, params_no * sizeof(*route_vals));
484
485 for (index = 0; index < params_no; index++) {
486 res = &route_vals[index];
487 switch (actions[index].type)
488 {
489 case STRING_ST:
490 res->rs.s = actions[index].u.string;
491 res->rs.len = strlen(res->rs.s);
492 res->flags = PV_VAL_STR;
493 break;
494
495 case NUMBER_ST:
496 res->ri = actions[index].u.number;
497 res->flags = PV_VAL_INT|PV_TYPE_INT;
498 tmp.s = sint2str(res->ri, &tmp.len);
499 if (pkg_str_dup(&res->rs, &tmp) == 0)
500 res->flags |= PV_VAL_STR|PV_VAL_PKG;
501 else
502 LM_ERR("cannot duplicate param value\n");
503 break;
504
505 case SCRIPTVAR_ST:
506 if(pv_get_spec_value(msg, (pv_spec_p)actions[index].u.data, res)==0)
507 {
508 if (pvv_is_str(res)) {
509 /* but we need to duplicate the string */
510 if (pkg_str_dup(&tmp, &res->rs) == 0) {
511 res->rs.s = tmp.s;
512 res->flags |= PV_VAL_PKG;
513 break;
514 } else {
515 LM_ERR("cannot duplicate param value\n");
516 }
517 } else {
518 break;
519 }
520 } else {
521 LM_ERR("cannot get spec value\n");
522 }
523 /* fallback */
524
525 default:
526 LM_ALERT("BUG: invalid parameter type %d\n",
527 actions[index].type);

Callers 1

do_actionFunction · 0.85

Calls 3

sint2strFunction · 0.85
pkg_str_dupFunction · 0.85
pv_get_spec_valueFunction · 0.85

Tested by

no test coverage detected