[asterisk-commits] mmichelson: branch mmichelson/pool_shark2 r381589 - in /team/mmichelson/pool_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Feb 15 15:45:58 CST 2013


Author: mmichelson
Date: Fri Feb 15 15:45:55 2013
New Revision: 381589

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381589
Log:
Do not do endpoint lookups for in-dialog messages.

Once a dialog has been established, it should not be necessary
to look up the endpoint any more since the user of the dialog
should save the endpoint looked up originally locally somewhere.

This prevents loads of unnecessary endpoint lookups for cases
like SIP sessions where the endpoint is saved in the SIP session.

In addition, this changeset also removes the "Unhandled" PJSIP
module since we can now detect unhandled requests from the
distributor.


Modified:
    team/mmichelson/pool_shark2/res/res_sip.c
    team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c

Modified: team/mmichelson/pool_shark2/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip.c?view=diff&rev=381589&r1=381588&r2=381589
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip.c Fri Feb 15 15:45:55 2013
@@ -450,21 +450,6 @@
 	pj_thread_join(monitor_thread);
 }
 
-static pj_bool_t unhandled_on_rx_request(pjsip_rx_data *rdata)
-{
-	if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_ack_method)) {
-		pjsip_endpt_respond_stateless(ast_pjsip_endpoint, rdata, 501, NULL, NULL, NULL);
-	}
-
-	return PJ_TRUE;
-}
-
-static pjsip_module unhandled_module = {
-	.name = { "Unhandled", 9 },
-	.priority = PJSIP_MOD_PRIORITY_APPLICATION + 32,
-	.on_rx_request = unhandled_on_rx_request,
-};
-
 AST_THREADSTORAGE(pj_thread_storage);
 
 static void sip_thread_start(void)
@@ -545,11 +530,6 @@
 		goto error;
 	}
 
-	if (pjsip_endpt_register_module(ast_pjsip_endpoint, &unhandled_module)) {
-		ast_log(LOG_ERROR, "Failed to register unhandled request module. Aborting load\n");
-		goto error;
-	}
-
 	ast_res_sip_init_options_handling(0);
 
 return AST_MODULE_LOAD_SUCCESS;

Modified: team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c?view=diff&rev=381589&r1=381588&r2=381589
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c Fri Feb 15 15:45:55 2013
@@ -51,45 +51,49 @@
 	int is_request = rdata->msg_info.msg->type == PJSIP_REQUEST_MSG;
 	pjsip_method *req_method = is_request ? &rdata->msg_info.msg->line.req.method : NULL;
 	int is_ack = req_method ? req_method->id == PJSIP_ACK_METHOD : 0;
-	struct ast_sip_endpoint *endpoint;
+	struct ast_sip_endpoint *endpoint = NULL;
+	pjsip_to_hdr *to_header = PJSIP_MSG_TO_HDR(rdata->msg_info.msg);
+	int in_dialog = pj_strlen(&to_header->tag) > 0;
 
-	endpoint = ast_sip_identify_endpoint(rdata);
-	if (!endpoint) {
-		if (is_request && !is_ack) {
-			/* XXX When we do an alwaysauthreject-like option, we'll need to take that into account
-			 * for this option. Either that, or have a pseudo-endpoint to pass along so that authentication
-			 * will fail
-			 */
-			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, NULL, NULL);
+	if (!in_dialog) {
+		endpoint = ast_sip_identify_endpoint(rdata);
+		if (!endpoint) {
+			if (is_request && !is_ack) {
+				/* XXX When we do an alwaysauthreject-like option, we'll need to take that into account
+				 * for this option. Either that, or have a pseudo-endpoint to pass along so that authentication
+				 * will fail
+				 */
+				pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, NULL, NULL);
+			}
+			goto end;
 		}
-		goto end;
-	}
-	rdata->endpt_info.mod_data[cloner_mod.id] = endpoint;
+		rdata->endpt_info.mod_data[cloner_mod.id] = endpoint;
 
-	if (is_request && pjsip_method_creates_dialog(req_method)) {
-		if (ast_sip_requires_authentication(endpoint, rdata)) {
-			pjsip_tx_data *tdata;
-			pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, 401, NULL, &tdata);
-			switch (ast_sip_check_authentication(endpoint, rdata, tdata)) {
-			case AST_SIP_AUTHENTICATION_CHALLENGE:
-				/* Send the 401 we created for them */
-				pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
-				goto end;
-			case AST_SIP_AUTHENTICATION_SUCCESS:
-				break;
-			case AST_SIP_AUTHENTICATION_FAILED:
-				pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, NULL, NULL);
-				goto end;
-			case AST_SIP_AUTHENTICATION_ERROR:
-				pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
-				goto end;
+		if (is_request) {
+			if (ast_sip_requires_authentication(endpoint, rdata)) {
+				pjsip_tx_data *tdata;
+				pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, 401, NULL, &tdata);
+				switch (ast_sip_check_authentication(endpoint, rdata, tdata)) {
+				case AST_SIP_AUTHENTICATION_CHALLENGE:
+					/* Send the 401 we created for them */
+					pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
+					goto end;
+				case AST_SIP_AUTHENTICATION_SUCCESS:
+					break;
+				case AST_SIP_AUTHENTICATION_FAILED:
+					pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, NULL, NULL);
+					goto end;
+				case AST_SIP_AUTHENTICATION_ERROR:
+					pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
+					goto end;
+				}
 			}
 		}
 	}
 
 	pjsip_endpt_process_rx_data(ast_sip_get_pjsip_endpoint(), rdata, &param, &handled);
-	if (!handled) {
-	    /* This will never happen right now due to the Unhandled module */
+	if (!handled && is_request && !is_ack) {
+		pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 501, NULL, NULL, NULL);
 	}
 
 end:




More information about the asterisk-commits mailing list