| 2551 | |
| 2552 | |
| 2553 | static inline int _pv_get_tm_branch_field(struct sip_msg *msg, |
| 2554 | pv_param_t *param, pv_value_t *res, int field) |
| 2555 | { |
| 2556 | struct cell *t; |
| 2557 | int idx, idxf; |
| 2558 | int_str attr_val; |
| 2559 | int attr_name; |
| 2560 | unsigned short attr_flags; |
| 2561 | struct usr_avp **old_list, *avp; |
| 2562 | int active_indexing = 0; |
| 2563 | |
| 2564 | if(msg==NULL || res==NULL) |
| 2565 | return -1; |
| 2566 | |
| 2567 | t = get_t(); |
| 2568 | if (t==NULL || t==T_UNDEFINED) |
| 2569 | return -1; |
| 2570 | |
| 2571 | /* get the index */ |
| 2572 | if (param->pvn.type & BRANCH_IDX_ACTIVE_MASK) { |
| 2573 | active_indexing = 1; |
| 2574 | param->pvn.type &= ~BRANCH_IDX_ACTIVE_MASK; |
| 2575 | } |
| 2576 | if (pv_get_spec_index(msg, param, &idx, &idxf)!=0) { |
| 2577 | LM_ERR("invalid index\n"); |
| 2578 | return -1; |
| 2579 | } |
| 2580 | |
| 2581 | if (idxf==PV_IDX_ALL) { |
| 2582 | LM_ERR("STAR/ALL index not supported\n"); |
| 2583 | return -1; |
| 2584 | } |
| 2585 | |
| 2586 | if (idxf==0 && idx==0) { |
| 2587 | /* no index used at all, return for the current branch */ |
| 2588 | idx = get_branch_index(); |
| 2589 | } else { |
| 2590 | /* must be numerical index */ |
| 2591 | if (active_indexing) |
| 2592 | idx += t->first_branch; |
| 2593 | if (idx<0) { |
| 2594 | /* index from the end */ |
| 2595 | if (-idx > t->nr_of_outgoings) /* underflow */ |
| 2596 | return pv_get_null(NULL, NULL, res); |
| 2597 | idx = t->nr_of_outgoings + idx; |
| 2598 | } else |
| 2599 | if (idx >= t->nr_of_outgoings) /*overflow*/ |
| 2600 | return pv_get_null(NULL, NULL, res); |
| 2601 | } |
| 2602 | |
| 2603 | /* we have a valid TM-branch index now */ |
| 2604 | switch (field) { |
| 2605 | case BR_URI_ID: /* return URI */ |
| 2606 | res->rs = TM_BRANCH(t,idx).uri; |
| 2607 | res->flags = PV_VAL_STR; |
| 2608 | break; |
| 2609 | case BR_Q_ID: /* return Q */ |
| 2610 | res->rs.s = q2str(TM_BRANCH(t,idx).q, (unsigned int*)&res->rs.len); |
no test coverage detected