diff options
author | Mark Michelson <mmichelson@digium.com> | 2015-07-06 11:52:47 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2015-07-06 11:52:47 -0500 |
commit | 3cdbe696a3f98f345cdeb739cb738f41cb830c15 (patch) | |
tree | c286a989059e87681cba5e3e18a6a811ec98e710 /res/res_pjsip_session.c | |
parent | 38a3c27a0993762c6782eb9c389f34a12b09243f (diff) | |
parent | 74135c8efa826a9ce47604dadb6a65b56c10c71d (diff) |
Merge "res_pjsip: Failover when server is not available"
Diffstat (limited to 'res/res_pjsip_session.c')
-rw-r--r-- | res/res_pjsip_session.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index bbd74eeb5..c72959400 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -2267,6 +2267,29 @@ static int session_end(struct ast_sip_session *session) return 0; } +static int check_request_status(pjsip_inv_session *inv, pjsip_event *e) +{ + struct ast_sip_session *session = inv->mod_data[session_module.id]; + pjsip_transaction *tsx = e->body.tsx_state.tsx; + + if (tsx->status_code != 503 && tsx->status_code != 408) { + return 0; + } + + if (!ast_sip_failover_request(tsx->last_tx)) { + return 0; + } + + pjsip_inv_uac_restart(inv, PJ_FALSE); + /* + * Bump the ref since it will be on a new transaction and + * we don't want it to go away along with the old transaction. + */ + pjsip_tx_data_add_ref(tsx->last_tx); + ast_sip_session_send_request(session, tsx->last_tx); + return 1; +} + static void session_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e) { struct ast_sip_session *session = inv->mod_data[session_module.id]; @@ -2299,11 +2322,20 @@ static void session_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e) handle_outgoing(session, e->body.tsx_state.src.tdata); break; case PJSIP_EVENT_RX_MSG: - handle_incoming(session, e->body.tsx_state.src.rdata, type, - AST_SIP_SESSION_BEFORE_MEDIA); + if (!check_request_status(inv, e)) { + handle_incoming(session, e->body.tsx_state.src.rdata, type, + AST_SIP_SESSION_BEFORE_MEDIA); + } break; case PJSIP_EVENT_TRANSPORT_ERROR: case PJSIP_EVENT_TIMER: + /* + * Check the request status on transport error or timeout. A transport + * error can occur when a TCP socket closes and that can be the result + * of a 503. Also we may need to failover on a timeout (408). + */ + check_request_status(inv, e); + break; case PJSIP_EVENT_USER: case PJSIP_EVENT_UNKNOWN: case PJSIP_EVENT_TSX_STATE: |