[asterisk-commits] mmichelson: branch group/pimp_my_sip r380016 - in /team/group/pimp_my_sip: ch...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 23 13:11:58 CST 2013
Author: mmichelson
Date: Wed Jan 23 13:11:54 2013
New Revision: 380016
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380016
Log:
Fix mishandling of INVITE state during error conditions.
We were attempting to use pjsip_inv_end_session(), which results
in an assertion being raised in PJSIP because the inv_session is
in an invalid state.
What we have to do instead is to use pjsip_inv_initial_answer()
up until we send a 100 Trying (or other provisional response). After
that point, we can end the session by using pjsip_inv_end_session().
This also moves the transmission of the 100 Trying response to incoming
INVITEs from chan_gulp into res_sip_session just before calling out
to supplements.
Modified:
team/group/pimp_my_sip/channels/chan_gulp.c
team/group/pimp_my_sip/res/res_sip_session.c
Modified: team/group/pimp_my_sip/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/channels/chan_gulp.c?view=diff&rev=380016&r1=380015&r2=380016
==============================================================================
--- team/group/pimp_my_sip/channels/chan_gulp.c (original)
+++ team/group/pimp_my_sip/channels/chan_gulp.c Wed Jan 23 13:11:54 2013
@@ -629,14 +629,6 @@
return -1;
}
- if (pjsip_inv_initial_answer(session->inv_session, rdata, 100, NULL, NULL, &packet) != PJ_SUCCESS) {
- ast_channel_hangupcause_set(session->channel, AST_CAUSE_SWITCH_CONGESTION);
- ast_hangup(session->channel);
- return -1;
- }
-
- ast_sip_session_send_response(session, packet);
-
ast_setstate(session->channel, AST_STATE_RING);
res = ast_pbx_start(session->channel);
Modified: team/group/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_session.c?view=diff&rev=380016&r1=380015&r2=380016
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Wed Jan 23 13:11:54 2013
@@ -630,7 +630,10 @@
return NULL;
}
if (pjsip_dlg_add_usage(dlg, &session_module, NULL) != PJ_SUCCESS) {
- pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+ if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) != PJ_SUCCESS) {
+ pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+ }
+ pjsip_inv_send_msg(inv_session, tdata);
return NULL;
}
return inv_session;
@@ -660,35 +663,47 @@
endpoint = ast_sip_identify_endpoint(rdata);
if (!endpoint) {
- if (pjsip_inv_end_session(inv_session, 403, NULL, &tdata) == PJ_SUCCESS) {
+ if (pjsip_inv_initial_answer(inv_session, rdata, 403, NULL, NULL, &tdata) == PJ_SUCCESS) {
pjsip_inv_send_msg(inv_session, tdata);
- } else {
+ } else {
pjsip_inv_terminate(inv_session, 403, PJ_FALSE);
}
+ return;
}
session = ast_sip_session_alloc(endpoint, inv_session);
if (!session) {
- if (pjsip_inv_end_session(inv_session, 403, NULL, &tdata) == PJ_SUCCESS) {
- ast_sip_session_send_response(session, tdata);
+ if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
+ pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
} else {
- pjsip_inv_terminate(inv_session, 403, PJ_FALSE);
+ pjsip_inv_send_msg(inv_session, tdata);
}
return;
}
+
+ /* From this point on, any calls to pjsip_inv_terminate have the last argument as PJ_TRUE
+ * so that we will be notified so we can destroy the session properly
+ */
if (ast_sip_requires_authentication(endpoint, rdata)) {
if (ast_sip_authenticate_request(endpoint, rdata)) {
struct ast_sip_digest_challenge_data challenge_data;
- if (pjsip_inv_end_session(inv_session, 401, NULL, &tdata) != PJ_SUCCESS) {
- /* CRAP */
+ if (pjsip_inv_initial_answer(inv_session, rdata, 401, NULL, NULL, &tdata) != PJ_SUCCESS) {
+ pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
+ return;
}
memset(&challenge_data, 0, sizeof(challenge_data));
if (ast_sip_get_authentication_credentials(endpoint, &challenge_data)) {
- /* CRAP */
+ if (pjsip_inv_answer(inv_session, 500, NULL, NULL, &tdata) != PJ_SUCCESS) {
+ ast_sip_session_send_response(session, tdata);
+ } else {
+ pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
+ }
+ return;
}
ast_sip_add_digest_to_challenge(&challenge_data, tdata);
ast_sip_session_send_response(session, tdata);
+ return;
}
}
@@ -697,30 +712,29 @@
/* Things worked. Keep going */
break;
case SIP_GET_DEST_UNSUPPORTED_URI:
- if (pjsip_inv_end_session(inv_session, 416, NULL, &tdata) == PJ_SUCCESS) {
+ if (pjsip_inv_initial_answer(inv_session, rdata, 416, NULL, NULL, &tdata) == PJ_SUCCESS) {
ast_sip_session_send_response(session, tdata);
- } else {
- pjsip_inv_terminate(inv_session, 416, PJ_FALSE);
+ } else {
+ pjsip_inv_terminate(inv_session, 416, PJ_TRUE);
}
return;
case SIP_GET_DEST_EXTEN_NOT_FOUND:
case SIP_GET_DEST_EXTEN_PARTIAL:
default:
- if (pjsip_inv_end_session(inv_session, 404, NULL, &tdata) == PJ_SUCCESS) {
+ if (pjsip_inv_initial_answer(inv_session, rdata, 404, NULL, NULL, &tdata) == PJ_SUCCESS) {
ast_sip_session_send_response(session, tdata);
- } else {
- pjsip_inv_terminate(inv_session, 404, PJ_FALSE);
- }
- ao2_cleanup(session);
+ } else {
+ pjsip_inv_terminate(inv_session, 404, PJ_TRUE);
+ }
return;
};
if ((sdp_info = pjsip_rdata_get_sdp_info(rdata)) && (sdp_info->sdp_err == PJ_SUCCESS)) {
if (handle_incoming_sdp(session, sdp_info->sdp)) {
- if (pjsip_inv_end_session(inv_session, 500, NULL, &tdata) == PJ_SUCCESS) {
+ if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
ast_sip_session_send_response(session, tdata);
- } else {
- pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+ } else {
+ pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
}
return;
}
@@ -733,16 +747,22 @@
/* If we were unable to create a local SDP terminate the session early, it won't go anywhere */
if (!local) {
- if (pjsip_inv_end_session(inv_session, 500, NULL, &tdata) == PJ_SUCCESS) {
+ if (pjsip_inv_initial_answer(inv_session, rdata, 500, NULL, NULL, &tdata) == PJ_SUCCESS) {
ast_sip_session_send_response(session, tdata);
- } else {
- pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
- }
- ao2_cleanup(session);
+ } else {
+ pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
+ }
return;
} else {
pjsip_inv_set_local_sdp(inv_session, local);
}
+
+ /* At this point, we've verified what we can, so let's go ahead and send a 100 Trying out */
+ if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS) {
+ pjsip_inv_terminate(inv_session, 500, PJ_TRUE);
+ return;
+ }
+ ast_sip_session_send_response(session, tdata);
handle_incoming_request(session, rdata);
}
More information about the asterisk-commits
mailing list