[asterisk-commits] file: branch group/pimp_my_sip r380251 - in /team/group/pimp_my_sip: configs/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 28 13:31:09 CST 2013


Author: file
Date: Mon Jan 28 13:31:05 2013
New Revision: 380251

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380251
Log:
Add the ability to specify an explicit transport for dialogs created to an endpoint.

Modified:
    team/group/pimp_my_sip/configs/res_sip.conf.sample
    team/group/pimp_my_sip/include/asterisk/res_sip.h
    team/group/pimp_my_sip/res/res_sip/sip_configuration.c
    team/group/pimp_my_sip/res/res_sip_session.c

Modified: team/group/pimp_my_sip/configs/res_sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/configs/res_sip.conf.sample?view=diff&rev=380251&r1=380250&r2=380251
==============================================================================
--- team/group/pimp_my_sip/configs/res_sip.conf.sample (original)
+++ team/group/pimp_my_sip/configs/res_sip.conf.sample Mon Jan 28 13:31:05 2013
@@ -13,3 +13,4 @@
 disallow=all
 allow=ulaw
 dtmfmode=rfc4733 ; Supported DTMF modes are rfc4733, inband, info, and none
+;transport=local ; Name of a specific transport to use when placing calls

Modified: team/group/pimp_my_sip/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip.h?view=diff&rev=380251&r1=380250&r2=380251
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip.h Mon Jan 28 13:31:05 2013
@@ -181,13 +181,13 @@
 	AST_DECLARE_STRING_FIELDS(
 		/*! Context to send incoming calls to */
 		AST_STRING_FIELD(context);
+                /*! Name of an explicit transport to use */
+                AST_STRING_FIELD(transport);
 	);
 	/*! Identification information for this endpoint */
 	struct ast_party_id id;
 	/*! Domain to which this endpoint belongs */
 	struct ast_sip_domain *domain;
-	/*! Transport used to send messages to the endpoint */
-	struct ast_sip_transport *transport;
 	/*! Address of record for incoming registrations */
 	struct ast_sip_aor *aor;
 	/*! Codec preferences */

Modified: team/group/pimp_my_sip/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip/sip_configuration.c?view=diff&rev=380251&r1=380250&r2=380251
==============================================================================
--- team/group/pimp_my_sip/res/res_sip/sip_configuration.c (original)
+++ team/group/pimp_my_sip/res/res_sip/sip_configuration.c Mon Jan 28 13:31:05 2013
@@ -190,6 +190,7 @@
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "qualify_frequency", 0, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_endpoint, qualify_frequency), 0, 86400);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "host", "", host_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtmfmode", "rfc4733", dtmf_handler, NULL, 0, 0);
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "transport", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, transport));
 
 	ast_sorcery_load(sip_sorcery);
 

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=380251&r1=380250&r2=380251
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Mon Jan 28 13:31:05 2013
@@ -469,7 +469,7 @@
 	return session;
 }
 
-static int sip_session_create_from(pj_pool_t *pool, pj_str_t *from, const char *user, const pj_str_t *target)
+static int sip_session_create_from(pj_pool_t *pool, pj_str_t *from, const char *user, const pj_str_t *target, pjsip_tpselector *selector)
 {
 	pj_str_t tmp, local_addr;
 	pjsip_uri *uri;
@@ -506,20 +506,28 @@
 	}
 
 	/* Get the local bound address for the transport that will be used when communicating with the provided URI */
-	if (pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), pool, type, NULL,
+	if (pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), pool, type, selector,
 							      &local_addr, &local_port) != PJ_SUCCESS) {
 		return -1;
 	}
 
-	/* TODO: This needs to add the transport if needed */
+	/* If IPv6 was not specified in the host but is in the transport, set the proper type */
+	if (!pj_strchr(&sip_uri->host, ':') && pj_strchr(&local_addr, ':')) {
+		type = (pjsip_transport_type_e)(((int)type) + PJSIP_TRANSPORT_IPV6);
+	}
+
 	from->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
 	from->slen = pj_ansi_snprintf(from->ptr, PJSIP_MAX_URL_SIZE,
-				      "<%s:%s@%.*s:%d>",
+				      "<%s:%s@%s%.*s%s:%d%s%s>",
 				      (pjsip_transport_get_flag_from_type(type) & PJSIP_TRANSPORT_SECURE) ? "sips" : "sip",
 				      user,
+				      (type & PJSIP_TRANSPORT_IPV6) ? "[" : "",
 				      (int)local_addr.slen,
 				      local_addr.ptr,
-				      local_port);
+				      (type & PJSIP_TRANSPORT_IPV6) ? "]" : "",
+				      local_port,
+				      (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
+				      (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "");
 
 	return 0;
 }
@@ -532,12 +540,33 @@
 	pjsip_inv_session *inv_session = NULL;
 	struct ast_sip_session *session = NULL;
 	pjmedia_sdp_session *offer = NULL;
+	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
 
 	if (pjsip_dlg_create_uac(pjsip_ua_instance(), &local_uri, NULL, &remote_uri, NULL, &dlg) != PJ_SUCCESS) {
 		return NULL;
 	}
 
-	if (sip_session_create_from(dlg->pool, &local_uri, "test", &remote_uri)) {
+	if (!ast_strlen_zero(endpoint->transport)) {
+		RAII_VAR(struct ast_sip_transport *, transport, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", endpoint->transport), 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_session_create_from(dlg->pool, &local_uri, "test", &remote_uri, &selector)) {
 		pjsip_dlg_terminate(dlg);
 		return NULL;
 	}
@@ -551,6 +580,8 @@
 		pjsip_dlg_terminate(dlg);
 		return NULL;
 	}
+
+	pjsip_dlg_set_transport(dlg, &selector);
 	
 	if (pjsip_dlg_add_usage(dlg, &session_module, NULL) != PJ_SUCCESS) {
 		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);




More information about the asterisk-commits mailing list