@@ -2216,8 +2216,8 @@ static int pv_get_msg_branch_fields(struct sip_msg *msg, pv_param_t *param,
22162216 }
22172217
22182218 if (idxf != PV_IDX_ALL && idx == 0 ) {
2219- /* no index specified -> return the first branch */
2220- return get_msg_branch_field ( msg , 0 , field , res );
2219+ /* no index specified -> operate with the last branch */
2220+ return get_msg_branch_field ( msg , size - 1 , field , res );
22212221 }
22222222
22232223 if (idxf == PV_IDX_ALL ) {
@@ -2354,6 +2354,13 @@ static int pv_get_msg_branch_attr(struct sip_msg *msg, pv_param_t *param,
23542354 return 0 ;
23552355}
23562356
2357+ static int pv_get_msg_branch_lastidx (struct sip_msg * msg , pv_param_t * param ,
2358+ pv_value_t * res )
2359+ {
2360+ /* the last index is the size -1, counting all branches, as RURI as
2361+ * branch 0 followed by the added branches in dset */
2362+ return get_dset_size ();
2363+ }
23572364
23582365
23592366/******** LISTENING SOCKETS related vars & functions **********/
@@ -4554,8 +4561,9 @@ const pv_export_t _pv_names_table[] = {
45544561 {str_const_init ("msg.branch.attr" ), /* */
45554562 PVT_BRANCH , pv_get_msg_branch_attr , pv_set_msg_branch_attr ,
45564563 pv_parse_avp_name , pv_parse_index , 0 , 0 },
4557-
4558-
4564+ {str_const_init ("msg.branch.last_idx" ), /* */
4565+ PVT_BRANCH , pv_get_msg_branch_lastidx , NULL ,
4566+ NULL , NULL , 0 , 0 },
45594567 {str_const_init ("mi" ), /* */
45604568 PVT_MSGID , pv_get_msgid , 0 ,
45614569 0 , 0 , 0 , 0 },
0 commit comments