[svn-commits] mmichelson: branch mmichelson/pool_shark2 r381561 - in /team/mmichelson/pool_...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Feb 15 12:19:23 CST 2013


Author: mmichelson
Date: Fri Feb 15 12:19:19 2013
New Revision: 381561

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381561
Log:
Endpoint identification now occurs before a request enters the transaction layer.

In order to facilitate this, we have to create wrappers for pjsip_rx_data_clone
and pjsip_rx_data_free_cloned so that the endpoint (and all rdata mod_data) gets
copied over to the clone. This way the endpoint can be retrieved from the rdata.


Modified:
    team/mmichelson/pool_shark2/include/asterisk/res_sip.h
    team/mmichelson/pool_shark2/res/res_sip.exports.in
    team/mmichelson/pool_shark2/res/res_sip/sip_configuration.c
    team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c
    team/mmichelson/pool_shark2/res/res_sip/sip_options.c
    team/mmichelson/pool_shark2/res/res_sip_endpoint_identifier_ip.c
    team/mmichelson/pool_shark2/res/res_sip_session.c

Modified: team/mmichelson/pool_shark2/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/include/asterisk/res_sip.h?view=diff&rev=381561&r1=381560&r2=381561
==============================================================================
--- team/mmichelson/pool_shark2/include/asterisk/res_sip.h (original)
+++ team/mmichelson/pool_shark2/include/asterisk/res_sip.h Fri Feb 15 12:19:19 2013
@@ -701,4 +701,8 @@
  */
 void ast_copy_pj_str(char *dest, pj_str_t *src, size_t size);
 
+struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata);
+pjsip_rx_data *ast_pjsip_rx_data_clone(pjsip_rx_data *rdata);
+void ast_pjsip_rx_data_free_cloned(pjsip_rx_data *rdata);
+
 #endif /* _RES_SIP_H */

Modified: team/mmichelson/pool_shark2/res/res_sip.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip.exports.in?view=diff&rev=381561&r1=381560&r2=381561
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip.exports.in (original)
+++ team/mmichelson/pool_shark2/res/res_sip.exports.in Fri Feb 15 12:19:19 2013
@@ -26,6 +26,9 @@
 		LINKER_SYMBOL_PREFIXast_sip_get_sorcery;
 		LINKER_SYMBOL_PREFIXast_sip_get_endpoint_from_location;
 		LINKER_SYMBOL_PREFIXast_sip_endpoint_get_location;
+		LINKER_SYMBOL_PREFIXast_pjsip_rdata_get_endpoint;
+		LINKER_SYMBOL_PREFIXast_pjsip_rx_data_clone;
+		LINKER_SYMBOL_PREFIXast_pjsip_rx_data_free_cloned;
 		LINKER_SYMBOL_PREFIXpj_*;
 		LINKER_SYMBOL_PREFIXpjsip_*;
 		LINKER_SYMBOL_PREFIXpjmedia_*;

Modified: team/mmichelson/pool_shark2/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip/sip_configuration.c?view=diff&rev=381561&r1=381560&r2=381561
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip/sip_configuration.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip/sip_configuration.c Fri Feb 15 12:19:19 2013
@@ -76,6 +76,7 @@
 static void sip_location_to_endpoint_destroy(void *obj)
 {
 	struct sip_location_to_endpoint *location_to_endpoint = obj;
+	ast_log(LOG_NOTICE, "Destroying location to endpoint?\n");
 	ast_free((char *)location_to_endpoint->endpoint_name);
 }
 
@@ -315,6 +316,8 @@
 
 	ast_string_field_free_memory(endpoint);
 
+	ast_log(LOG_NOTICE, "Destroying endpoint?\n");
+
 	if (endpoint->codecs) {
 		ast_format_cap_destroy(endpoint->codecs);
 	}

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=381561&r1=381560&r2=381561
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip/sip_distributor.c Fri Feb 15 12:19:19 2013
@@ -29,7 +29,6 @@
 {
 	pjsip_rx_data *clone;
 	pjsip_rx_data_clone(rdata, 0, &clone);
-	ast_log(LOG_NOTICE, "Pushing clone task yo!\n");
 	ast_sip_push_task(NULL, distribute, clone);
 	return PJ_TRUE;
 }
@@ -49,13 +48,64 @@
 	};
 	pj_bool_t handled;
 	pjsip_rx_data *rdata = data;
-	ast_log(LOG_NOTICE, "And now I be distroing!\n");
+	int is_request = rdata->msg_info.msg->type == PJSIP_REQUEST_MSG;
+	int is_ack = is_request ? rdata->msg_info.msg->line.req.method.id == PJSIP_ACK_METHOD : 0;
+	struct ast_sip_endpoint *endpoint;
+
+	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);
+		}
+		return 0;
+	}
+	rdata->endpt_info.mod_data[cloner_mod.id] = endpoint;
+
 	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 */
 	}
+	ao2_cleanup(endpoint);
 	pjsip_rx_data_free_cloned(rdata);
 	return 0;
+}
+
+struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata)
+{
+	struct ast_sip_endpoint *endpoint = rdata->endpt_info.mod_data[cloner_mod.id];
+	if (endpoint) {
+		ao2_ref(endpoint, +1);
+	}
+	return endpoint;
+}
+
+pjsip_rx_data *ast_pjsip_rx_data_clone(pjsip_rx_data *rdata)
+{
+	pjsip_rx_data *clone;
+	pj_status_t status;
+	struct ast_sip_endpoint *endpoint;
+	status = pjsip_rx_data_clone(rdata, 0, &clone);
+	if (status != PJ_SUCCESS) {
+		return NULL;
+	}
+	memcpy(clone->endpt_info.mod_data, rdata->endpt_info.mod_data, sizeof(clone->endpt_info.mod_data));
+	endpoint = clone->endpt_info.mod_data[cloner_mod.id];
+	if (endpoint) {
+		ao2_ref(endpoint, +1);
+	}
+	return clone;
+}
+
+void ast_pjsip_rx_data_free_cloned(pjsip_rx_data *rdata)
+{
+	struct ast_sip_endpoint *endpoint;
+	endpoint = rdata->endpt_info.mod_data[cloner_mod.id];
+	pjsip_rx_data_free_cloned(rdata);
+	ao2_cleanup(endpoint);
 }
 
 int ast_sip_initialize_distributor(void)

Modified: team/mmichelson/pool_shark2/res/res_sip/sip_options.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip/sip_options.c?view=diff&rev=381561&r1=381560&r2=381561
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip/sip_options.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip/sip_options.c Fri Feb 15 12:19:19 2013
@@ -165,11 +165,8 @@
 	pjsip_dialog *dlg = iod->dialog;
 	char exten[AST_MAX_EXTENSION];
 
-	/* If no endpoint is available for the request treat them as completely untrusted */
-	if (!(endpoint = ast_sip_identify_endpoint(rdata))) {
-		send_options_response(rdata, dlg, 404);
-		return -1;
-	}
+	endpoint = ast_pjsip_rdata_get_endpoint(rdata);
+	ast_assert(endpoint != NULL);
 
 	ruri = rdata->msg_info.msg->line.req.uri;
 	if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {

Modified: team/mmichelson/pool_shark2/res/res_sip_endpoint_identifier_ip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip_endpoint_identifier_ip.c?view=diff&rev=381561&r1=381560&r2=381561
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip_endpoint_identifier_ip.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip_endpoint_identifier_ip.c Fri Feb 15 12:19:19 2013
@@ -42,7 +42,9 @@
 
 	endpoint = ast_sip_get_endpoint_from_location(host);
 	if (endpoint) {
-		ast_debug(3, "Retrieved endpoint %s\n", ast_sorcery_object_get_id(endpoint));
+		ast_debug(3, "Retrieved endpoint %s for IP address %s\n", ast_sorcery_object_get_id(endpoint), host);
+	} else {
+		ast_debug(3, "Could not find endpoint based on IP address %s\n", host);
 	}
 	return endpoint;
 }

Modified: team/mmichelson/pool_shark2/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark2/res/res_sip_session.c?view=diff&rev=381561&r1=381560&r2=381561
==============================================================================
--- team/mmichelson/pool_shark2/res/res_sip_session.c (original)
+++ team/mmichelson/pool_shark2/res/res_sip_session.c Fri Feb 15 12:19:19 2013
@@ -709,13 +709,14 @@
 	if (!nrd) {
 		return NULL;
 	}
-	if (pjsip_rx_data_clone(rdata, 0, &nrd->rdata) != PJ_SUCCESS) {
+	nrd->rdata = ast_pjsip_rx_data_clone(rdata);
+	if (!nrd->rdata) {
 		ast_free(nrd);
 		return NULL;
 	}
 	nrd->serializer = ast_sip_create_serializer();
 	if (!nrd->serializer) {
-		pjsip_rx_data_free_cloned(nrd->rdata);
+		ast_pjsip_rx_data_free_cloned(nrd->rdata);
 		ast_free(nrd);
 		return NULL;
 	}
@@ -743,11 +744,8 @@
 	pjmedia_sdp_session *local = NULL;
 	int destroy_serializer = 1;
 
-	endpoint = ast_sip_identify_endpoint(rdata);
-	if (!endpoint) {
-		pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 403, NULL, NULL, NULL);
-		goto end;
-	}
+	endpoint = ast_pjsip_rdata_get_endpoint(rdata);
+	ast_assert(endpoint != NULL);
 
 	inv_session = pre_session_setup(rdata, endpoint);
 	if (!inv_session) {
@@ -861,7 +859,7 @@
 	if (destroy_serializer) {
 		ast_taskprocessor_unreference(serializer);
 	}
-	pjsip_rx_data_free_cloned(rdata);
+	ast_pjsip_rx_data_free_cloned(rdata);
 	ast_free(nrd);
 	return 0;
 }
@@ -903,7 +901,7 @@
 		if (ast_sip_push_task(nrd->serializer, handle_new_invite_request, nrd)) {
 			ast_log(LOG_WARNING, "Failed to pass new INVITE to the threadpool\n");
 			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
-			pjsip_rx_data_free_cloned(nrd->rdata);
+			ast_pjsip_rx_data_free_cloned(nrd->rdata);
 			ast_taskprocessor_unreference(nrd->serializer);
 			ast_free(nrd);
 		}
@@ -969,7 +967,7 @@
 {
 	struct handle_incoming_data *hid = obj;
 	if (hid->rdata) {
-		pjsip_rx_data_free_cloned(hid->rdata);
+		ast_pjsip_rx_data_free_cloned(hid->rdata);
 	}
 	if (hid->session) {
 		ao2_ref(hid->session, -1);
@@ -982,7 +980,8 @@
 	if (!hid) {
 		return NULL;
 	}
-	if (pjsip_rx_data_clone(rdata, 0, &hid->rdata) != PJ_SUCCESS) {
+	hid->rdata = ast_pjsip_rx_data_clone(rdata);
+	if (!hid->rdata) {
 		ao2_ref(hid, -1);
 		return NULL;
 	}




More information about the svn-commits mailing list