this is the code which decides what and when shall be relayed upstream; note well -- it assumes it is entered locked with REPLY_LOCK and it returns unlocked! */
| 1243 | REPLY_LOCK and it returns unlocked! |
| 1244 | */ |
| 1245 | enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, |
| 1246 | unsigned int msg_status, branch_bm_t cancel_bitmap ) |
| 1247 | { |
| 1248 | int relay; |
| 1249 | int save_clone; |
| 1250 | char *buf; |
| 1251 | /* length of outbound reply */ |
| 1252 | unsigned int res_len; |
| 1253 | int relayed_code; |
| 1254 | struct sip_msg *relayed_msg; |
| 1255 | struct bookmark bm; |
| 1256 | int totag_retr; |
| 1257 | enum rps reply_status; |
| 1258 | /* retransmission structure of outbound reply and request */ |
| 1259 | struct retr_buf *uas_rb; |
| 1260 | str cb_s; |
| 1261 | str text; |
| 1262 | |
| 1263 | /* keep compiler warnings about use of uninit vars silent */ |
| 1264 | res_len=0; |
| 1265 | buf=0; |
| 1266 | relayed_msg=0; |
| 1267 | relayed_code=0; |
| 1268 | totag_retr=0; |
| 1269 | |
| 1270 | |
| 1271 | /* remember, what was sent upstream to know whether we are |
| 1272 | * forwarding a first final reply or not */ |
| 1273 | |
| 1274 | /* *** store and relay message as needed *** */ |
| 1275 | reply_status = t_should_relay_response(t, msg_status, branch, |
| 1276 | &save_clone, &relay, cancel_bitmap, p_msg ); |
| 1277 | LM_DBG("T_state=%d, branch=%d, save=%d, relay=%d, " |
| 1278 | "cancel_BM="BRANCH_BM_SPECS"\n", reply_status, branch, |
| 1279 | save_clone, relay, BRANCH_BM_ARGS(cancel_bitmap)); |
| 1280 | |
| 1281 | /* store the message if needed */ |
| 1282 | if (save_clone) /* save for later use, typically branch picking */ |
| 1283 | { |
| 1284 | if (!store_reply( t, branch, p_msg )) |
| 1285 | goto error01; |
| 1286 | } |
| 1287 | |
| 1288 | uas_rb = & t->uas.response; |
| 1289 | if (relay >= 0 ) { |
| 1290 | /* initialize sockets for outbound reply */ |
| 1291 | uas_rb->activ_type=msg_status; |
| 1292 | |
| 1293 | t->relaied_reply_branch = relay; |
| 1294 | |
| 1295 | /* try building the outbound reply from either the current |
| 1296 | * or a stored message */ |
| 1297 | relayed_msg = branch==relay ? p_msg : TM_BRANCH(t,relay).reply; |
| 1298 | if (relayed_msg==FAKED_REPLY) { |
| 1299 | relayed_code = branch==relay |
| 1300 | ? msg_status : TM_BRANCH(t,relay).last_received; |
| 1301 | |
| 1302 | text.s = error_text(relayed_code); |
no test coverage detected