[svn-commits] file: branch 12 r403207 - in /branches/12: include/asterisk/ res/ res/res_pjsip/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Nov 27 18:36:57 CST 2013


Author: file
Date: Wed Nov 27 18:36:53 2013
New Revision: 403207

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403207
Log:
res_pjsip_session: Add configurable behavior for redirects.

The action taken when a redirect occurs is now configurable on a
per-endpoint basis. The redirect can either be treated as a redirect
to a local extension, to a URI that is dialed through the Asterisk
core, or to a URI that is dialed within PJSIP itself.

(closes issue ASTERISK-21710)
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/2963/

Modified:
    branches/12/include/asterisk/res_pjsip.h
    branches/12/res/res_pjsip.c
    branches/12/res/res_pjsip/pjsip_configuration.c
    branches/12/res/res_pjsip_session.c

Modified: branches/12/include/asterisk/res_pjsip.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/res_pjsip.h?view=diff&rev=403207&r1=403206&r2=403207
==============================================================================
--- branches/12/include/asterisk/res_pjsip.h (original)
+++ branches/12/include/asterisk/res_pjsip.h Wed Nov 27 18:36:53 2013
@@ -314,6 +314,15 @@
 	AST_SIP_MEDIA_ENCRYPT_SDES,
 	/*! Offer encrypted session media with datagram TLS key exchange */
 	AST_SIP_MEDIA_ENCRYPT_DTLS,
+};
+
+enum ast_sip_session_redirect {
+	/*! User portion of the target URI should be used as the target in the dialplan */
+	AST_SIP_REDIRECT_USER = 0,
+	/*! Target URI should be used as the target in the dialplan */
+	AST_SIP_REDIRECT_URI_CORE,
+	/*! Target URI should be used as the target within chan_pjsip itself */
+	AST_SIP_REDIRECT_URI_PJSIP,
 };
 
 /*!
@@ -574,6 +583,8 @@
 	unsigned int faxdetect;
 	/*! Determines if transfers (using REFER) are allowed by this endpoint */
 	unsigned int allowtransfer;
+	/*! Method used when handling redirects */
+	enum ast_sip_session_redirect redirect_method;
 };
 
 /*!

Modified: branches/12/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip.c?view=diff&rev=403207&r1=403206&r2=403207
==============================================================================
--- branches/12/res/res_pjsip.c (original)
+++ branches/12/res/res_pjsip.c Wed Nov 27 18:36:53 2013
@@ -241,6 +241,27 @@
 						the endpoint can be identified in multiple ways.</para></note>
 						<enumlist>
 							<enum name="username" />
+						</enumlist>
+					</description>
+				</configOption>
+				<configOption name="redirect_method">
+					<synopsis>How redirects received from an endpoint are handled</synopsis>
+					<description><para>
+						When a redirect is received from an endpoint there are multiple ways it can be handled.
+						If this option is set to <literal>user</literal> the user portion of the redirect target
+						is treated as an extension within the dialplan and dialed using a Local channel. If this option
+						is set to <literal>uri_core</literal> the target URI is returned to the dialing application
+						which dials it using the PJSIP channel driver and endpoint originally used. If this option is
+						set to <literal>uri_pjsip</literal> the redirect occurs within chan_pjsip itself and is not exposed
+						to the core at all. The <literal>uri_pjsip</literal> option has the benefit of being more efficient
+						and also supporting multiple potential redirect targets. The con is that since redirection occurs
+						within chan_pjsip redirecting information is not forwarded and redirection can not be
+						prevented.
+						</para>
+						<enumlist>
+							<enum name="user" />
+							<enum name="uri_core" />
+							<enum name="uri_pjsip" />
 						</enumlist>
 					</description>
 				</configOption>

Modified: branches/12/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_configuration.c?view=diff&rev=403207&r1=403206&r2=403207
==============================================================================
--- branches/12/res/res_pjsip/pjsip_configuration.c (original)
+++ branches/12/res/res_pjsip/pjsip_configuration.c Wed Nov 27 18:36:53 2013
@@ -452,6 +452,25 @@
 	}
 
 	*buf = ast_strdup(*buf);
+	return 0;
+}
+
+static int redirect_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
+{
+	struct ast_sip_endpoint *endpoint = obj;
+
+	if (!strcasecmp(var->value, "user")) {
+		endpoint->redirect_method = AST_SIP_REDIRECT_USER;
+	} else if (!strcasecmp(var->value, "uri_core")) {
+		endpoint->redirect_method = AST_SIP_REDIRECT_URI_CORE;
+	} else if (!strcasecmp(var->value, "uri_pjsip")) {
+		endpoint->redirect_method = AST_SIP_REDIRECT_URI_PJSIP;
+	} else {
+		ast_log(LOG_ERROR, "Unrecognized redirect method %s specified for endpoint %s\n",
+			var->value, ast_sorcery_object_get_id(endpoint));
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -1353,6 +1372,7 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_ca_path", "", dtls_handler, dtlscapath_to_str, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_setup", "", dtls_handler, dtlssetup_to_str, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "srtp_tag_32", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.rtp.srtp_tag_32));
+	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "redirect_method", "user", redirect_handler, NULL, 0, 0);
 
 	if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");

Modified: branches/12/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_session.c?view=diff&rev=403207&r1=403206&r2=403207
==============================================================================
--- branches/12/res/res_pjsip_session.c (original)
+++ branches/12/res/res_pjsip_session.c Wed Nov 27 18:36:53 2013
@@ -2065,13 +2065,31 @@
 static pjsip_redirect_op session_inv_on_redirected(pjsip_inv_session *inv, const pjsip_uri *target, const pjsip_event *e)
 {
 	struct ast_sip_session *session = inv->mod_data[session_module.id];
-
-	if (PJSIP_URI_SCHEME_IS_SIP(target) || PJSIP_URI_SCHEME_IS_SIPS(target)) {
-		const pjsip_sip_uri *uri = pjsip_uri_get_uri(target);
+	const pjsip_sip_uri *uri;
+
+	if (session->endpoint->redirect_method == AST_SIP_REDIRECT_URI_PJSIP) {
+		return PJSIP_REDIRECT_ACCEPT;
+	}
+
+	if (!PJSIP_URI_SCHEME_IS_SIP(target) && !PJSIP_URI_SCHEME_IS_SIPS(target)) {
+		return PJSIP_REDIRECT_STOP;
+	}
+
+	uri = pjsip_uri_get_uri(target);
+
+	if (session->endpoint->redirect_method == AST_SIP_REDIRECT_USER) {
 		char exten[AST_MAX_EXTENSION];
 
 		ast_copy_pj_str(exten, &uri->user, sizeof(exten));
 		ast_channel_call_forward_set(session->channel, exten);
+	} else if (session->endpoint->redirect_method == AST_SIP_REDIRECT_URI_CORE) {
+		char target_uri[PJSIP_MAX_URL_SIZE];
+		/* PJSIP/ + endpoint length + / + max URL size */
+		char forward[8 + strlen(ast_sorcery_object_get_id(session->endpoint)) + PJSIP_MAX_URL_SIZE];
+
+		pjsip_uri_print(PJSIP_URI_IN_REQ_URI, uri, target_uri, sizeof(target_uri));
+		sprintf(forward, "PJSIP/%s/%s", ast_sorcery_object_get_id(session->endpoint), target_uri);
+		ast_channel_call_forward_set(session->channel, forward);
 	}
 
 	return PJSIP_REDIRECT_STOP;




More information about the svn-commits mailing list