[asterisk-commits] mmichelson: branch group/pimp_my_sip r379391 - /team/group/pimp_my_sip/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jan 17 18:30:41 CST 2013
Author: mmichelson
Date: Thu Jan 17 18:30:37 2013
New Revision: 379391
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379391
Log:
Separate pre-session creation logic into its own function.
This plus erasing some XXX comments means that the handle_new_invite
function has tightened up some.
Modified:
team/group/pimp_my_sip/res/res_sip_session.c
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=379391&r1=379390&r2=379391
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Thu Jan 17 18:30:37 2013
@@ -500,6 +500,36 @@
return SIP_GET_DEST_EXTEN_NOT_FOUND;
}
+static pjsip_inv_session *pre_session_setup(pjsip_rx_data *rdata)
+{
+ pjsip_tx_data *tdata = NULL;
+ pjsip_dialog *dlg = NULL;
+ pjsip_inv_session *inv_session = NULL;
+
+ if (pjsip_inv_verify_request(rdata, NULL, NULL, NULL, ast_sip_get_pjsip_endpoint(), &tdata) != PJ_SUCCESS) {
+ if (tdata) {
+ pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
+ } else {
+ pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
+ }
+ return NULL;
+ }
+ if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg) != PJ_SUCCESS) {
+ pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
+ return NULL;
+ }
+ if (pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session) != PJ_SUCCESS) {
+ pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
+ pjsip_dlg_terminate(dlg);
+ return NULL;
+ }
+ if (pjsip_dlg_add_usage(dlg, &session_module, NULL) != PJ_SUCCESS) {
+ pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+ return NULL;
+ }
+ return inv_session;
+}
+
static void handle_new_invite(pjsip_rx_data *rdata)
{
/* The goal here is to create SIP work and throw it into
@@ -510,55 +540,36 @@
* endpoint thread.
*/
pjsip_tx_data *tdata = NULL;
- pjsip_dialog *dlg = NULL;
pjsip_inv_session *inv_session = NULL;
struct ast_sip_endpoint *endpoint = NULL;
struct ast_sip_session *session = NULL;
struct ast_sip_session_supplement *supplement = NULL;
- if (pjsip_inv_verify_request(rdata, NULL, NULL, NULL, ast_sip_get_pjsip_endpoint(), &tdata) != PJ_SUCCESS) {
- if (tdata) {
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
- } else {
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
- }
+ inv_session = pre_session_setup(rdata);
+ if (!inv_session) {
+ /* pre_session_setup() returns a response on failure */
return;
}
- if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg) != PJ_SUCCESS) {
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
- return;
- }
- if (pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session) != PJ_SUCCESS) {
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
- pjsip_dlg_terminate(dlg);
- return;
- }
- if (pjsip_dlg_add_usage(dlg, &session_module, NULL) != PJ_SUCCESS) {
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
- return;
- }
- if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
- {
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
- return;
- }
- /* XXX ast_sip_endpoint doesn't exist yet :( */
+
endpoint = ast_sip_identify_endpoint(rdata);
if (!endpoint) {
if (pjsip_inv_end_session(inv_session, 403, NULL, &tdata) == PJ_SUCCESS) {
- /*XXX Should replace this with res_sip or res_sip_session call */
pjsip_inv_send_msg(inv_session, tdata);
} else {
- /*XXX Should replace this with res_sip or res_sip_session call */
pjsip_inv_terminate(inv_session, 403, PJ_FALSE);
}
}
+
+ 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);
+ } else {
+ pjsip_inv_terminate(inv_session, 403, PJ_FALSE);
+ }
+ return;
+ }
+
if (ast_sip_requires_authentication(endpoint, rdata)) {
if (ast_sip_authenticate_request(endpoint, rdata)) {
struct ast_sip_digest_challenge_data challenge_data;
@@ -570,20 +581,10 @@
/* CRAP */
}
ast_sip_add_digest_to_challenge(&challenge_data, tdata);
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_inv_send_msg(inv_session, tdata);
- }
- }
- 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);
- } else {
- /*XXX Should replace this with res_sip or res_sip_session call */
- pjsip_inv_terminate(inv_session, 403, PJ_FALSE);
- }
- return;
- }
+ }
+ }
+
switch (get_destination(session, rdata)) {
case SIP_GET_DEST_EXTEN_FOUND:
@@ -593,7 +594,6 @@
if (pjsip_inv_end_session(inv_session, 416, NULL, &tdata) == PJ_SUCCESS) {
ast_sip_session_send_response(session, tdata);
} else {
- /*XXX Should replace this with res_sip or res_sip_session call */
pjsip_inv_terminate(inv_session, 416, PJ_FALSE);
}
return;
@@ -601,10 +601,8 @@
case SIP_GET_DEST_EXTEN_PARTIAL:
default:
if (pjsip_inv_end_session(inv_session, 404, NULL, &tdata) == PJ_SUCCESS) {
- /*XXX Should replace this with res_sip or res_sip_session call */
ast_sip_session_send_response(session, tdata);
} else {
- /*XXX Should replace this with res_sip or res_sip_session call */
pjsip_inv_terminate(inv_session, 404, PJ_FALSE);
}
return;
@@ -620,7 +618,6 @@
if (pjsip_inv_end_session(inv_session, 488, NULL, &tdata) == PJ_SUCCESS) {
ast_sip_session_send_response(session, tdata);
} else {
- /*XXX Should replace this with res_sip or res_sip_session call */
pjsip_inv_terminate(inv_session, 488, PJ_FALSE);
}
return;
More information about the asterisk-commits
mailing list