[asterisk-commits] mmichelson: branch mmichelson/outbound_auth r383338 - /team/mmichelson/outbou...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 19 10:33:29 CDT 2013


Author: mmichelson
Date: Tue Mar 19 10:33:25 2013
New Revision: 383338

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383338
Log:
Separate logic for getting tpselector from an endpoint out of ast_sip_create_dialog().

This is step one towards being able to write the ast_sip_send_request() function. There
are several bits of logic that are in the middle of large functions that need to be separated
out into their own functions so that they can be called by ast_sip_send_request(). The
other things that need factoring out are

1) The determination of the remote URI to send a request to (currently in ast_sip_session_create_outbound)
2) Potentially, sip_dialog_create_from() needs to be written in such a way as to not be dialog-specific.
However, it's not really that dialog-specific to begin with.

With all that separated out, creating an out-of-dialog request will be a cakewalk.


Modified:
    team/mmichelson/outbound_auth/res/res_sip.c

Modified: team/mmichelson/outbound_auth/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/outbound_auth/res/res_sip.c?view=diff&rev=383338&r1=383337&r2=383338
==============================================================================
--- team/mmichelson/outbound_auth/res/res_sip.c (original)
+++ team/mmichelson/outbound_auth/res/res_sip.c Tue Mar 19 10:33:25 2013
@@ -270,6 +270,15 @@
 	pjsip_sip_uri *sip_uri;
 	pjsip_transport_type_e type = PJSIP_TRANSPORT_UNSPECIFIED;
 	int local_port;
+	char uuid_str[AST_UUID_STR_LEN];
+
+	if (!user) {
+		RAII_VAR(struct ast_uuid *, uuid, ast_uuid_generate(), ast_free_ptr);
+		if (!uuid) {
+			return -1;
+		}
+		user = ast_uuid_to_str(uuid, uuid_str, sizeof(uuid_str));
+	}
 
 	/* Parse the provided target URI so we can determine what transport it will end up using */
 	pj_strdup_with_null(pool, &tmp, target);
@@ -326,47 +335,54 @@
 	return 0;
 }
 
+static int sip_get_tpselector_from_endpoint(const struct ast_sip_endpoint *endpoint, pjsip_tpselector *selector)
+{
+	RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
+	const char *transport_name = endpoint->transport;
+	
+	if (ast_strlen_zero(transport_name)) {
+		return 0;
+	}
+	
+	transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_name);
+
+	if (!transport || !transport->state) {
+		return -1;
+	}
+
+	if (transport->type == AST_SIP_TRANSPORT_UDP) {
+		selector->type = PJSIP_TPSELECTOR_TRANSPORT;
+		selector->u.transport = transport->state->transport;
+	} else if (transport->type == AST_SIP_TRANSPORT_TCP || transport->type == AST_SIP_TRANSPORT_TLS) {
+		selector->type = PJSIP_TPSELECTOR_LISTENER;
+		selector->u.listener = transport->state->factory;
+	} else {
+		return -1;
+	}
+
+	return 0;
+}
+
 pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user)
 {
-	RAII_VAR(struct ast_uuid *, uuid, ast_uuid_generate(), ast_free_ptr);
-	char uuid_str[AST_UUID_STR_LEN];
 	pj_str_t local_uri = { "sip:temp at temp", 13 }, remote_uri;
 	pjsip_dialog *dlg = NULL;
-	const char *transport_name = endpoint->transport, *outbound_proxy = endpoint->outbound_proxy;
+	const char *outbound_proxy = endpoint->outbound_proxy;
 	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
 	static const pj_str_t HCONTACT = { "Contact", 7 };
 
-	if (!uuid) {
-		return NULL;
-	}
-
 	pj_cstr(&remote_uri, uri);
 
 	if (pjsip_dlg_create_uac(pjsip_ua_instance(), &local_uri, NULL, &remote_uri, NULL, &dlg) != PJ_SUCCESS) {
 		return NULL;
 	}
 
-	if (!ast_strlen_zero(transport_name)) {
-		RAII_VAR(struct ast_sip_transport *, transport, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_name), ao2_cleanup);
-
-		if (!transport || !transport->state) {
-			pjsip_dlg_terminate(dlg);
-			return NULL;
-		}
-
-		if (transport->type == AST_SIP_TRANSPORT_UDP) {
-			selector.type = PJSIP_TPSELECTOR_TRANSPORT;
-			selector.u.transport = transport->state->transport;
-		} else if (transport->type == AST_SIP_TRANSPORT_TCP || transport->type == AST_SIP_TRANSPORT_TLS) {
-			selector.type = PJSIP_TPSELECTOR_LISTENER;
-			selector.u.listener = transport->state->factory;
-		} else {
-			pjsip_dlg_terminate(dlg);
-			return NULL;
-		}
-	}
-
-	if (sip_dialog_create_from(dlg->pool, &local_uri, ast_uuid_to_str(uuid, uuid_str, AST_UUID_STR_LEN), &remote_uri, &selector)) {
+	if (sip_get_tpselector_from_endpoint(endpoint, &selector)) {
+		pjsip_dlg_terminate(dlg);
+		return NULL;
+	}
+
+	if (sip_dialog_create_from(dlg->pool, &local_uri, NULL, &remote_uri, &selector)) {
 		pjsip_dlg_terminate(dlg);
 		return NULL;
 	}
@@ -465,21 +481,6 @@
 
 static int send_out_of_dialog_request(const pjsip_method *method, const struct ast_sip_body *body, struct ast_sip_endpoint *endpoint)
 {
-	/*XXX Stub
-	 *
-	 * We need to get the destinations from the endpoint and then call
-	 * pjsip_endpt_create_request to create requests to each destination.
-	 * 
-	 * Once we create the outgoing requests, we can create a pjsip_auth_clt_sess
-	 * for each one, and call pjsip_auth_clt_init_req() on each created request.
-	 * We can then add the body as necessary and transmit with pjsip_endpt_send_request().
-	 * We can pass the pjsip_auth_clt_sess we created as the "token" parameter and
-	 * set a callback that will set auth parameters appropriately if we receive
-	 * a 401 or 407 response.
-	 *
-	 * Once endpoint location work is committed, we can actually write this
-	 * function.
-	 */
 	return 0;
 }
 




More information about the asterisk-commits mailing list