function used to get parameter from a route scope */
| 549 | |
| 550 | /* function used to get parameter from a route scope */ |
| 551 | static int route_param_get(struct sip_msg *msg, pv_param_t *ip, |
| 552 | pv_value_t *res, void *_params, void *_extra) |
| 553 | { |
| 554 | int index; |
| 555 | pv_value_t tv; |
| 556 | pv_value_t *params = (pv_value_t *)_params; |
| 557 | int params_no = (int)(unsigned long)_extra; |
| 558 | |
| 559 | if (params_no <= 0) { |
| 560 | LM_DBG("route without parameters\n"); |
| 561 | return pv_get_null(msg, ip, res); |
| 562 | } |
| 563 | |
| 564 | if(ip->pvn.type==PV_NAME_INTSTR) |
| 565 | { |
| 566 | if (ip->pvn.u.isname.type != 0) |
| 567 | { |
| 568 | LM_ERR("route $param variable accepts only integer indexes\n"); |
| 569 | return -1; |
| 570 | } |
| 571 | index = ip->pvn.u.isname.name.n; |
| 572 | } else |
| 573 | { |
| 574 | /* pvar -> it might be another $param variable! */ |
| 575 | route_rec_level--; |
| 576 | if(pv_get_spec_value(msg, (pv_spec_p)(ip->pvn.u.dname), &tv)!=0) |
| 577 | { |
| 578 | LM_ERR("cannot get spec value\n"); |
| 579 | route_rec_level++; |
| 580 | return -1; |
| 581 | } |
| 582 | route_rec_level++; |
| 583 | |
| 584 | if(tv.flags&PV_VAL_NULL || tv.flags&PV_VAL_EMPTY) |
| 585 | { |
| 586 | LM_ERR("null or empty name\n"); |
| 587 | return -1; |
| 588 | } |
| 589 | if (!(tv.flags&PV_VAL_INT) || str2int(&tv.rs,(unsigned int*)&index) < 0) |
| 590 | { |
| 591 | LM_ERR("invalid index <%.*s>\n", tv.rs.len, tv.rs.s); |
| 592 | return -1; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | if (!params) |
| 597 | { |
| 598 | LM_DBG("no parameter specified for this route\n"); |
| 599 | return pv_get_null(msg, ip, res); |
| 600 | } |
| 601 | |
| 602 | if (index < 1 || index > params_no) |
| 603 | { |
| 604 | LM_DBG("no such parameter index %d\n", index); |
| 605 | return pv_get_null(msg, ip, res); |
| 606 | } |
| 607 | |
| 608 | /* the parameters start at 0, whereas the index starts from 1 */ |
nothing calls this directly
no test coverage detected