summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--channels/chan_pjsip.c17
-rw-r--r--include/asterisk/res_pjsip_session.h8
-rw-r--r--res/res_pjsip_session.c34
-rw-r--r--res/res_pjsip_session.exports.in1
4 files changed, 44 insertions, 16 deletions
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 77e610ac3..b6bfeb5b4 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -1736,22 +1736,7 @@ static int hangup(void *data)
struct ast_sip_session *session = channel->session;
int cause = h_data->cause;
- if (!session->defer_terminate) {
- pj_status_t status;
- pjsip_tx_data *packet = NULL;
-
- if (session->inv_session->state == PJSIP_INV_STATE_NULL) {
- pjsip_inv_terminate(session->inv_session, cause ? cause : 603, PJ_TRUE);
- } else if (((status = pjsip_inv_end_session(session->inv_session, cause ? cause : 603, NULL, &packet)) == PJ_SUCCESS)
- && packet) {
- if (packet->msg->type == PJSIP_RESPONSE_MSG) {
- ast_sip_session_send_response(session, packet);
- } else {
- ast_sip_session_send_request(session, packet);
- }
- }
- }
-
+ ast_sip_session_terminate(session, cause);
clear_session_and_channel(session, ast, pvt);
ao2_cleanup(channel);
ao2_cleanup(h_data);
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index 9a133fcb3..990c9fe6f 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -436,6 +436,14 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
struct ast_format_cap *req_caps);
/*!
+ * \brief Terminate a session and, if possible, send the provided response code
+ *
+ * \param session The session to terminate
+ * \param response The response code to use for termination if possible
+ */
+void ast_sip_session_terminate(struct ast_sip_session *session, int response);
+
+/*!
* \brief Defer local termination of a session until remote side terminates, or an amount of time passes
*
* \param session The session to defer termination on
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 53cd8c823..46973ad29 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -528,6 +528,8 @@ static int send_delayed_request(struct ast_sip_session *session, struct ast_sip_
} else if (!strcmp(delay->method, "UPDATE")) {
ast_sip_session_refresh(session, delay->on_request_creation,
delay->on_sdp_creation, delay->on_response, AST_SIP_SESSION_REFRESH_METHOD_UPDATE, delay->generate_new_sdp);
+ } else if (!strcmp(delay->method, "BYE")) {
+ ast_sip_session_terminate(session, 0);
} else {
ast_log(LOG_WARNING, "Unexpected delayed %s request with no existing request structure\n", delay->method);
return -1;
@@ -1292,6 +1294,38 @@ struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint
return session;
}
+void ast_sip_session_terminate(struct ast_sip_session *session, int response)
+{
+ pj_status_t status;
+ pjsip_tx_data *packet = NULL;
+
+ if (session->defer_terminate) {
+ return;
+ }
+
+ if (!response) {
+ response = 603;
+ }
+
+ if ((session->inv_session->state == PJSIP_INV_STATE_CONFIRMED) && session->inv_session->invite_tsx) {
+ ast_debug(3, "Delaying sending BYE to %s because of outstanding transaction...\n",
+ ast_sorcery_object_get_id(session->endpoint));
+ /* If this is delayed the only thing that will happen is a BYE request so we don't
+ * actually need to store the response code for when it happens.
+ */
+ delay_request(session, NULL, NULL, NULL, 0, "BYE");
+ } else if (session->inv_session->state == PJSIP_INV_STATE_NULL) {
+ pjsip_inv_terminate(session->inv_session, response, PJ_TRUE);
+ } else if (((status = pjsip_inv_end_session(session->inv_session, response, NULL, &packet)) == PJ_SUCCESS)
+ && packet) {
+ if (packet->msg->type == PJSIP_RESPONSE_MSG) {
+ ast_sip_session_send_response(session, packet);
+ } else {
+ ast_sip_session_send_request(session, packet);
+ }
+ }
+}
+
static int session_termination_task(void *data)
{
RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
diff --git a/res/res_pjsip_session.exports.in b/res/res_pjsip_session.exports.in
index 07f26b7e9..5a21b1d2f 100644
--- a/res/res_pjsip_session.exports.in
+++ b/res/res_pjsip_session.exports.in
@@ -1,5 +1,6 @@
{
global:
+ LINKER_SYMBOL_PREFIXast_sip_session_terminate;
LINKER_SYMBOL_PREFIXast_sip_session_defer_termination;
LINKER_SYMBOL_PREFIXast_sip_session_register_sdp_handler;
LINKER_SYMBOL_PREFIXast_sip_session_unregister_sdp_handler;