@@ -66,6 +66,8 @@ static int fixup_nt_string(void** param);
6666static int fixup_nt_str (void * * param );
6767static int fixup_nt_str_free (void * * param );
6868static int fixup_via_hdl (void * * param );
69+ static int fixup_append_mbranch_flags (void * * param );
70+
6971
7072static int w_forward (struct sip_msg * msg , struct proxy_l * dest );
7173static int w_send (struct sip_msg * msg , struct proxy_l * dest , str * headers );
@@ -84,10 +86,14 @@ static int w_seturi(struct sip_msg *msg, str *uri);
8486static int w_prefix (struct sip_msg * msg , str * prefix );
8587static int w_strip (struct sip_msg * msg , int * nchars );
8688static int w_strip_tail (struct sip_msg * msg , int * nchars );
87- static int w_append_branch (struct sip_msg * msg , str * uri , int * qvalue );
88- static int w_remove_branch (struct sip_msg * msg , int * branch );
89- static int w_move_branch (struct sip_msg * msg , int * src_idx , int * dst_idx , int * keep );
90- static int w_swap_branches (struct sip_msg * msg , int * src_idx , int * dst_idx );
89+ static int w_append_branch_old (struct sip_msg * msg , str * uri , int * qvalue );
90+ static int w_append_msg_branch (struct sip_msg * msg , str * uri , int * qvalue ,
91+ void * flags );
92+ static int w_remove_msg_branch (struct sip_msg * msg , int * branch );
93+ static int w_move_msg_branch (struct sip_msg * msg ,
94+ int * src_idx , int * dst_idx , int * keep );
95+ static int w_swap_msg_branches (struct sip_msg * msg ,
96+ int * src_idx , int * dst_idx );
9197static int w_pv_printf (struct sip_msg * msg , pv_spec_t * var , str * fmt_str );
9298static int w_revert_uri (struct sip_msg * msg );
9399static int w_setdsturi (struct sip_msg * msg , str * uri );
@@ -191,21 +197,28 @@ const cmd_export_t core_cmds[]={
191197 {"strip_tail" , (cmd_function )w_strip_tail , {
192198 {CMD_PARAM_INT , 0 , 0 }, {0 ,0 ,0 }},
193199 ALL_ROUTES },
194- {"append_branch " , (cmd_function )w_append_branch , {
200+ {"append_branch_old " , (cmd_function )w_append_branch_old , {
195201 {CMD_PARAM_STR |CMD_PARAM_OPT , 0 , 0 },
196202 {CMD_PARAM_STR |CMD_PARAM_OPT |CMD_PARAM_FIX_NULL ,
197203 fixup_qvalue , 0 }, {0 ,0 ,0 }},
198204 ALL_ROUTES },
199- {"remove_branch" , (cmd_function )w_remove_branch , {
205+ {"append_msg_branch" , (cmd_function )w_append_msg_branch , {
206+ {CMD_PARAM_STR , 0 , 0 },
207+ {CMD_PARAM_STR |CMD_PARAM_OPT |CMD_PARAM_FIX_NULL ,
208+ fixup_qvalue , 0 },
209+ {CMD_PARAM_STR |CMD_PARAM_OPT ,fixup_append_mbranch_flags ,0 },
210+ {0 ,0 ,0 }},
211+ ALL_ROUTES },
212+ {"remove_msg_branch" , (cmd_function )w_remove_msg_branch , {
200213 {CMD_PARAM_INT , 0 , 0 }, {0 ,0 ,0 }},
201214 ALL_ROUTES },
202- {"move_branch " , (cmd_function )w_move_branch , {
215+ {"move_msg_branch " , (cmd_function )w_move_msg_branch , {
203216 {CMD_PARAM_INT |CMD_PARAM_OPT , fixup_branch_index , 0 },
204217 {CMD_PARAM_INT |CMD_PARAM_OPT , fixup_branch_index , 0 },
205218 {CMD_PARAM_STR |CMD_PARAM_OPT , fixup_branch_keep , 0 },
206219 {0 ,0 ,0 }},
207220 ALL_ROUTES },
208- {"swap_branches " , (cmd_function )w_swap_branches , {
221+ {"swap_msg_branches " , (cmd_function )w_swap_msg_branches , {
209222 {CMD_PARAM_INT |CMD_PARAM_OPT , fixup_branch_index , 0 },
210223 {CMD_PARAM_INT |CMD_PARAM_OPT , fixup_branch_index , 0 },
211224 {0 ,0 ,0 }},
@@ -888,15 +901,22 @@ static int w_strip_tail(struct sip_msg *msg, int *nchars)
888901 return rewrite_ruri (msg , 0 , * nchars , RW_RURI_STRIP_TAIL ) ? -1 : 1 ;
889902}
890903
891- static int w_append_branch (struct sip_msg * msg , str * uri , int * qvalue )
904+ static int w_append_branch_old (struct sip_msg * msg , str * uri , int * qvalue )
892905{
906+ struct msg_branch branch ;
893907 int ret ;
894908 qvalue_t q = (int )(long )qvalue ;
895909
910+ memset ( & branch , 0 , sizeof branch );
911+
896912 if (!uri ) {
897- ret = append_branch (msg , 0 , & msg -> dst_uri , & msg -> path_vec ,
898- (q == Q_UNSPECIFIED ) ? get_ruri_q (msg ) : q ,
899- getb0flags (msg ), msg -> force_send_socket );
913+ branch .uri = * GET_RURI (msg );
914+ branch .dst_uri = msg -> dst_uri ;
915+ branch .path = msg -> path_vec ;
916+ branch .q = (q == Q_UNSPECIFIED ) ? get_ruri_q (msg ) : q ;
917+ branch .force_send_socket = msg -> force_send_socket ;
918+ branch .bflags = msg -> ruri_bflags ;
919+ ret = append_msg_branch (& branch );
900920 /* reset all branch info */
901921 msg -> force_send_socket = 0 ;
902922 setb0flags (msg ,0 );
@@ -912,25 +932,73 @@ static int w_append_branch(struct sip_msg *msg, str *uri, int *qvalue)
912932
913933 return ret ;
914934 } else {
915- return append_branch (msg , uri , & msg -> dst_uri ,
916- & msg -> path_vec , q , getb0flags (msg ),
917- msg -> force_send_socket );
935+ branch .uri = * uri ;
936+ branch .dst_uri = msg -> dst_uri ;
937+ branch .path = msg -> path_vec ;
938+ branch .q = q ;
939+ branch .force_send_socket = msg -> force_send_socket ;
940+ branch .bflags = msg -> ruri_bflags ;
941+ return append_msg_branch (& branch );
942+ }
943+ }
944+
945+
946+ static str append_mbranch_flag_names [] =
947+ {
948+ str_init ("inherite" ),
949+ STR_NULL
950+ };
951+
952+ static int fixup_append_mbranch_flags (void * * param )
953+ {
954+ return fixup_named_flags (param , append_mbranch_flag_names , NULL , NULL );
955+ }
956+
957+
958+ static int w_append_msg_branch (struct sip_msg * msg , str * uri , int * qvalue ,
959+ void * flags )
960+ {
961+ unsigned int opts = (unsigned int )(unsigned long )flags ;
962+ struct msg_branch branch ;
963+ qvalue_t q = (int )(long )qvalue ;
964+
965+ if (ZSTRP (uri )) {
966+ LM_ERR ("appending emptry URI :(\n" );
967+ return -1 ;
968+ }
969+
970+ memset ( & branch , 0 , sizeof branch );
971+ branch .uri = * uri ;
972+
973+ if ( opts & (1 <<0 ) ) {
974+ /* inherite the rest of the branch attrs from RURI branch */
975+ branch .dst_uri = msg -> dst_uri ;
976+ branch .path = msg -> path_vec ;
977+ branch .q = (q == Q_UNSPECIFIED ) ? get_ruri_q (msg ) : q ;
978+ branch .force_send_socket = msg -> force_send_socket ;
979+ branch .bflags = msg -> ruri_bflags ;
980+ } else {
981+ branch .q = q ;
918982 }
983+ return append_msg_branch (& branch );
919984}
920985
921- static int w_remove_branch (struct sip_msg * msg , int * branch )
986+ static int w_remove_msg_branch (struct sip_msg * msg , int * branch )
922987{
923- return (remove_branch (* branch )== 0 )? 1 : -1 ;
988+ return (remove_msg_branch (* branch )== 0 ) ? 1 : -1 ;
924989}
925990
926- static int w_move_branch (struct sip_msg * msg , int * src_idx , int * dst_idx , int * keep )
991+ static int w_move_msg_branch (struct sip_msg * msg , int * src_idx ,
992+ int * dst_idx , int * keep )
927993{
928- return (move_branch (msg , (src_idx ?* src_idx :-1 ), (dst_idx ?* dst_idx :-1 ), (keep ?1 :0 ))== 0 )?1 :-1 ;
994+ return (move_msg_branch (msg ,
995+ (src_idx ?* src_idx :-1 ), (dst_idx ?* dst_idx :-1 ), (keep ?1 :0 ))== 0 ) ? 1 : -1 ;
929996}
930997
931- static int w_swap_branches (struct sip_msg * msg , int * src_idx , int * dst_idx )
998+ static int w_swap_msg_branches (struct sip_msg * msg , int * src_idx , int * dst_idx )
932999{
933- return (swap_branches (msg , (src_idx ?* src_idx :-1 ), (dst_idx ?* dst_idx :-1 ))== 0 )?1 :-1 ;
1000+ return (swap_msg_branches (msg ,
1001+ (src_idx ?* src_idx :-1 ), (dst_idx ?* dst_idx :-1 ))== 0 ) ? 1 : -1 ;
9341002}
9351003
9361004static int w_pv_printf (struct sip_msg * msg , pv_spec_t * var , str * fmt_str )
0 commit comments