| 3585 | |
| 3586 | |
| 3587 | static int _int_pv_set_branch_fields(struct sip_msg* msg, pv_param_t *param, |
| 3588 | int op, pv_value_t *val, int field, int has_ruri_branch) |
| 3589 | { |
| 3590 | int size, is_ruri_branch = 0; |
| 3591 | int idx; |
| 3592 | int idxf; |
| 3593 | str *s; |
| 3594 | qvalue_t q; |
| 3595 | unsigned int flags; |
| 3596 | const struct socket_info *si; |
| 3597 | |
| 3598 | if (msg==NULL || param==NULL) { |
| 3599 | LM_ERR("bad parameters\n"); |
| 3600 | return -1; |
| 3601 | } |
| 3602 | |
| 3603 | if (msg->first_line.type == SIP_REPLY) |
| 3604 | return -1; |
| 3605 | |
| 3606 | /* get the index */ |
| 3607 | if (pv_get_spec_index(msg, param, &idx, &idxf)!=0) { |
| 3608 | LM_ERR("invalid index\n"); |
| 3609 | return -1; |
| 3610 | } |
| 3611 | |
| 3612 | if (idxf==PV_IDX_ALL) { |
| 3613 | LM_ERR("SCRIPT BUG - * not allowed in branch assignment\n"); |
| 3614 | return -1; |
| 3615 | } |
| 3616 | |
| 3617 | if (has_ruri_branch) { |
| 3618 | size = get_dset_size() + 1 ; |
| 3619 | /* no branch set, consider the last one */ |
| 3620 | if (idxf==0 && idx==0) |
| 3621 | idx = size - 1; |
| 3622 | else |
| 3623 | /* if negative, count from the end */ |
| 3624 | if (idx<0) |
| 3625 | idx = size + idx; |
| 3626 | /* now evaluate and ajust the idx to dset only */ |
| 3627 | if (idx==0) { |
| 3628 | is_ruri_branch = 1; |
| 3629 | } else { |
| 3630 | /* offset with -1 */ |
| 3631 | idx--; |
| 3632 | } |
| 3633 | } else { |
| 3634 | size = get_dset_size(); |
| 3635 | /* if negative, count from the end */ |
| 3636 | if (idx<0) |
| 3637 | idx = size + idx; |
| 3638 | } |
| 3639 | |
| 3640 | if (!is_ruri_branch) { |
| 3641 | /* if not RURI branch, it is a msg branch, so check the idx*/ |
| 3642 | if (idx<0 || idx>=get_dset_size()) { |
| 3643 | LM_ERR("inexisting branch assignment [%d/%d]\n", size, idx); |
| 3644 | return -1; |
no test coverage detected