| 1128 | } |
| 1129 | |
| 1130 | int t_inject_branch( struct cell *t, struct sip_msg *msg, int flags) |
| 1131 | { |
| 1132 | static struct sip_msg faked_req; |
| 1133 | branch_bm_t cancel_bm = BRANCH_BM_ZERO; |
| 1134 | str reason = str_init(CANCEL_REASON_200); |
| 1135 | struct cell *bk_t = NULL; |
| 1136 | int rc; |
| 1137 | |
| 1138 | /* does the transaction state still accept new branches ? */ |
| 1139 | if (t->uas.status >= 200) { |
| 1140 | LM_DBG("cannot add branches to a transaction with %d UAS\n", |
| 1141 | t->uas.status); |
| 1142 | return -2; |
| 1143 | } |
| 1144 | |
| 1145 | if (!fake_req( &faked_req, t->uas.request, &t->uas, NULL)) { |
| 1146 | LM_ERR("fake_req failed\n"); |
| 1147 | return -1; |
| 1148 | } |
| 1149 | |
| 1150 | /* do we have the branches to be injected ? */ |
| 1151 | if (flags&TM_INJECT_SRC_EVENT) { |
| 1152 | /* get the branch from Event AVPs, as populated by EVI/EBR */ |
| 1153 | if (ul_contact_event_to_msg( &faked_req )<0) { |
| 1154 | LM_ERR("failed to grab new branch from Event\n"); |
| 1155 | goto error; |
| 1156 | } |
| 1157 | } else { |
| 1158 | /* use the RURI+dset array as destinations to be injected */ |
| 1159 | if (msg->first_line.type==SIP_REQUEST) { |
| 1160 | /* take the RURI branch from the script msg and move it |
| 1161 | * into the faked msg (that will be used by t_fwd function) */ |
| 1162 | if (dst_to_msg( msg, &faked_req )<0) { |
| 1163 | LM_ERR("failed to grab new branch from Event\n"); |
| 1164 | goto error; |
| 1165 | } |
| 1166 | } else { |
| 1167 | /* current message is a reply, so take the first branch from dset |
| 1168 | * and move it into the faked msg (that will be used by t_fwd |
| 1169 | * function)*/ |
| 1170 | if (move_msg_branch_to_ruri( 0, &faked_req)<0) { |
| 1171 | LM_ERR("no branch found to be moved as new destination\n"); |
| 1172 | goto error; |
| 1173 | } |
| 1174 | /* remove it from set */ |
| 1175 | remove_msg_branch(0); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | /* t_forward_nonack() relies on T for various internal stuff, so be |
| 1180 | * we advertise the correct one */ |
| 1181 | bk_t = get_t(); |
| 1182 | set_t( t ); |
| 1183 | |
| 1184 | /* do we have to cancel the existing branches before injecting new ones? */ |
| 1185 | if (flags&TM_INJECT_FLAG_CANCEL) { |
| 1186 | which_cancel( t, cancel_bm ); |
| 1187 | } |
no test coverage detected