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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Dec 14 11:25:53 CST 2013


Author: file
Date: Sat Dec 14 11:25:51 2013
New Revision: 403811

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403811
Log:
res_pjsip: Apply outbound proxy to all SIP requests.

Objects which are involved in SIP request creation and sending
now allow an outbound proxy to be specified. For cases where
an endpoint is used the outbound proxy specified there will
be applied.

(closes issue ASTERISK-22673)
Reported by: Antti Yrjola

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

Modified:
    branches/12/include/asterisk/res_pjsip.h
    branches/12/res/res_pjsip.c
    branches/12/res/res_pjsip/location.c
    branches/12/res/res_pjsip/pjsip_options.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=403811&r1=403810&r2=403811
==============================================================================
--- branches/12/include/asterisk/res_pjsip.h (original)
+++ branches/12/include/asterisk/res_pjsip.h Sat Dec 14 11:25:51 2013
@@ -144,6 +144,8 @@
 	AST_DECLARE_STRING_FIELDS(
 		/*! Full URI of the contact */
 		AST_STRING_FIELD(uri);
+		/*! Outbound proxy to use for qualify */
+		AST_STRING_FIELD(outbound_proxy);
 	);
 	/*! Absolute time that this contact is no longer valid after */
 	struct timeval expiration_time;
@@ -188,6 +190,8 @@
 	AST_DECLARE_STRING_FIELDS(
 		/*! Voicemail boxes for this AOR */
 		AST_STRING_FIELD(mailboxes);
+		/*! Outbound proxy for OPTIONS requests */
+		AST_STRING_FIELD(outbound_proxy);
 	);
 	/*! Minimum expiration time */
 	unsigned int minimum_expiration;
@@ -1281,6 +1285,16 @@
 struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata);
 
 /*!
+ * \brief Set the outbound proxy for an outbound SIP message
+ *
+ * \param tdata The message to set the outbound proxy on
+ * \param proxy SIP uri of the proxy
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy);
+
+/*!
  * \brief Add a header to an outbound SIP message
  *
  * \param tdata The message to add the header to

Modified: branches/12/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip.c?view=diff&rev=403811&r1=403810&r2=403811
==============================================================================
--- branches/12/res/res_pjsip.c (original)
+++ branches/12/res/res_pjsip.c Sat Dec 14 11:25:51 2013
@@ -868,6 +868,13 @@
 						If <literal>0</literal> never qualify. Time in seconds.
 					</para></description>
 				</configOption>
+				<configOption name="outbound_proxy">
+					<synopsis>Outbound proxy used when sending OPTIONS request</synopsis>
+					<description><para>
+						If set the provided URI will be used as the outbound proxy when an
+						OPTIONS request is sent to a contact for qualify purposes.
+					</para></description>
+				</configOption>
 			</configObject>
 			<configObject name="aor">
 				<synopsis>The configuration for a location of an endpoint</synopsis>
@@ -962,6 +969,13 @@
 					<description><para>
 						If true and a qualify request receives a challenge or authenticate response
 						authentication is attempted before declaring the contact available.
+					</para></description>
+				</configOption>
+				<configOption name="outbound_proxy">
+					<synopsis>Outbound proxy used when sending OPTIONS request</synopsis>
+					<description><para>
+						If set the provided URI will be used as the outbound proxy when an
+						OPTIONS request is sent to a contact for qualify purposes.
 					</para></description>
 				</configOption>
 			</configObject>
@@ -1637,6 +1651,15 @@
 		return -1;
 	}
 
+	/* If an outbound proxy is specified on the endpoint apply it to this request */
+	if (endpoint && !ast_strlen_zero(endpoint->outbound_proxy) &&
+		ast_sip_set_outbound_proxy((*tdata), endpoint->outbound_proxy)) {
+		ast_log(LOG_ERROR, "Unable to apply outbound proxy on request %.*s to endpoint %s\n",
+			(int) pj_strlen(&method->name), pj_strbuf(&method->name), ast_sorcery_object_get_id(endpoint));
+		pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
+		return -1;
+	}
+
 	/* We can release this pool since request creation copied all the necessary
 	 * data into the outbound request's pool
 	 */
@@ -1711,6 +1734,22 @@
 	} else {
 		return send_out_of_dialog_request(tdata, endpoint);
 	}
+}
+
+int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy)
+{
+	pjsip_route_hdr *route;
+	static const pj_str_t ROUTE_HNAME = { "Route", 5 };
+	pj_str_t tmp;
+
+	pj_strdup2_with_null(tdata->pool, &tmp, proxy);
+	if (!(route = pjsip_parse_hdr(tdata->pool, &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL))) {
+		return -1;
+	}
+
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)route);
+
+	return 0;
 }
 
 int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)

Modified: branches/12/res/res_pjsip/location.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/location.c?view=diff&rev=403811&r1=403810&r2=403811
==============================================================================
--- branches/12/res/res_pjsip/location.c (original)
+++ branches/12/res/res_pjsip/location.c Sat Dec 14 11:25:51 2013
@@ -193,6 +193,10 @@
 	contact->qualify_frequency = aor->qualify_frequency;
 	contact->authenticate_qualify = aor->authenticate_qualify;
 
+	if (!ast_strlen_zero(aor->outbound_proxy)) {
+		ast_string_field_set(contact, outbound_proxy, aor->outbound_proxy);
+	}
+
 	return ast_sorcery_create(ast_sip_get_sorcery(), contact);
 }
 
@@ -388,6 +392,7 @@
 	ast_sorcery_object_field_register_custom(sorcery, "contact", "expiration_time", "", expiration_str2struct, expiration_struct2str, 0, 0);
 	ast_sorcery_object_field_register(sorcery, "contact", "qualify_frequency", 0, OPT_UINT_T,
 					  PARSE_IN_RANGE, FLDSET(struct ast_sip_contact, qualify_frequency), 0, 86400);
+	ast_sorcery_object_field_register(sorcery, "contact", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, outbound_proxy));
 
 	ast_sorcery_object_field_register(sorcery, "aor", "type", "", OPT_NOOP_T, 0, 0);
 	ast_sorcery_object_field_register(sorcery, "aor", "minimum_expiration", "60", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, minimum_expiration));
@@ -399,6 +404,7 @@
 	ast_sorcery_object_field_register(sorcery, "aor", "remove_existing", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, remove_existing));
 	ast_sorcery_object_field_register_custom(sorcery, "aor", "contact", "", permanent_uri_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register(sorcery, "aor", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, mailboxes));
+	ast_sorcery_object_field_register(sorcery, "aor", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, outbound_proxy));
 
 	ast_sip_register_endpoint_formatter(&endpoint_aor_formatter);
 	return 0;

Modified: branches/12/res/res_pjsip/pjsip_options.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_options.c?view=diff&rev=403811&r1=403810&r2=403811
==============================================================================
--- branches/12/res/res_pjsip/pjsip_options.c (original)
+++ branches/12/res/res_pjsip/pjsip_options.c Sat Dec 14 11:25:51 2013
@@ -258,6 +258,15 @@
 		return -1;
 	}
 
+	/* If an outbound proxy is specified set it on this request */
+	if (!ast_strlen_zero(contact->outbound_proxy) &&
+		ast_sip_set_outbound_proxy(tdata, contact->outbound_proxy)) {
+		pjsip_tx_data_dec_ref(tdata);
+		ast_log(LOG_ERROR, "Unable to apply outbound proxy on request to qualify contact %s\n",
+			contact->uri);
+		return -1;
+	}
+
 	init_start_time(contact);
 
 	ao2_ref(contact, +1);
@@ -795,6 +804,7 @@
 	struct ast_sip_aor *aor = arg;
 
 	contact->qualify_frequency = aor->qualify_frequency;
+
 	qualify_and_schedule(contact);
 
 	return 0;




More information about the asterisk-commits mailing list