[Asterisk-code-review] res pjsip outbound publish: add transport for outbound PUBLISH (asterisk[13])

Alexei Gradinari asteriskteam at digium.com
Tue Apr 5 16:58:04 CDT 2016


Alexei Gradinari has uploaded a new change for review.

  https://gerrit.asterisk.org/2537

Change subject: res_pjsip_outbound_publish: add transport for outbound PUBLISH
......................................................................

res_pjsip_outbound_publish: add transport for outbound PUBLISH

The first available transport of the appropriate type is used now.
This patch added new config option 'transport' for outbound-publish.
If transport is set then outbound PUBLISH requests will use this transport.

Change-Id: Ib389130489b70e36795b0003fa5fd386e2680151
---
M res/res_pjsip_outbound_publish.c
1 file changed, 32 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/37/2537/1

diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c
index c16ced3..dafffcf 100644
--- a/res/res_pjsip_outbound_publish.c
+++ b/res/res_pjsip_outbound_publish.c
@@ -87,6 +87,13 @@
 				<configOption name="max_auth_attempts" default="5">
 					<synopsis>Maximum number of authentication attempts before stopping the publication.</synopsis>
 				</configOption>
+                                <configOption name="transport">
+                                        <synopsis>Transport used for outbound publish</synopsis>
+                                        <description>
+                                                <note><para>A <replaceable>transport</replaceable> configured in
+                                                <literal>pjsip.conf</literal>. As with other <literal>res_pjsip</literal> modules, this will use the first available transport of the appropriate type if unconfigured.</para></note>
+                                        </description>
+                                </configOption>
 				<configOption name="type">
 					<synopsis>Must be of type 'outbound-publish'.</synopsis>
 				</configOption>
@@ -117,6 +124,8 @@
 		AST_STRING_FIELD(from_uri);
 		/*! \brief URI for the To header */
 		AST_STRING_FIELD(to_uri);
+                /*! \brief Explicit transport to use for publish */
+                AST_STRING_FIELD(transport);
 		/*! \brief Outbound proxy to use */
 		AST_STRING_FIELD(outbound_proxy);
 		/*! \brief The event type to publish */
@@ -150,6 +159,8 @@
 	unsigned int destroy;
 	/*! \brief Outbound publish information */
 	struct ast_sip_outbound_publish *publish;
+        /*! \brief The name of the transport to be used for the publish */
+        char *transport_name;
 };
 
 /*! \brief Outbound publish state information (persists for lifetime of a publish) */
@@ -329,8 +340,14 @@
 {
 	struct ast_sip_outbound_publish_client *client = data;
 	pjsip_tx_data *tdata;
+	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
 
 	if (pjsip_publishc_unpublish(client->client, &tdata) == PJ_SUCCESS) {
+    		if (!ast_strlen_zero(client->transport_name)) {
+            		ast_sip_set_tpselector_from_transport_name(client->transport_name, &selector);
+            		pjsip_tx_data_set_transport(tdata, &selector);
+    		}
+
 		pjsip_publishc_send(client->client, tdata);
 	}
 
@@ -551,6 +568,7 @@
 	struct sip_outbound_publish_message *message;
 	pjsip_tx_data *tdata;
 	pj_status_t status;
+	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
 
 	if (client->destroy || client->sending || !(message = AST_LIST_FIRST(&client->queue))) {
 		return 0;
@@ -564,6 +582,11 @@
 		ast_sip_add_body(tdata, &message->body)) {
 		pjsip_tx_data_dec_ref(tdata);
 		goto fatal;
+	}
+
+	if (!ast_strlen_zero(client->transport_name)) {
+		ast_sip_set_tpselector_from_transport_name(client->transport_name, &selector);
+		pjsip_tx_data_set_transport(tdata, &selector);
 	}
 
 	status = pjsip_publishc_send(client->client, tdata);
@@ -647,6 +670,7 @@
 
 	ao2_cleanup(client->datastores);
 	ao2_cleanup(client->publish);
+	ast_free(client->transport_name);
 
 	/* if unloading the module and all objects have been unpublished
 	   send the signal to finish unloading */
@@ -848,6 +872,7 @@
 	RAII_VAR(struct ast_sip_outbound_publish *, publish, ao2_bump(client->publish), ao2_cleanup);
 	SCOPED_AO2LOCK(lock, client);
 	pjsip_tx_data *tdata;
+	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
 
 	if (client->destroy) {
 		if (client->sending) {
@@ -869,6 +894,11 @@
 	if (param->code == 401 || param->code == 407) {
 		if (!ast_sip_create_request_with_auth(&publish->outbound_auths,
 				param->rdata, pjsip_rdata_get_tsx(param->rdata), &tdata)) {
+    			if (!ast_strlen_zero(client->transport_name)) {
+		                ast_sip_set_tpselector_from_transport_name(client->transport_name, &selector);
+    			        pjsip_tx_data_set_transport(tdata, &selector);
+    			}
+
 			pjsip_publishc_send(client->client, tdata);
 		}
 		client->auth_attempts++;
@@ -1028,6 +1058,7 @@
 
 	state->client->timer.user_data = state->client;
 	state->client->timer.cb = sip_outbound_publish_timer_cb;
+	state->client->transport_name = ast_strdup(publish->transport);
 	state->client->publish = ao2_bump(publish);
 
 	strcpy(state->id, id);
@@ -1121,6 +1152,7 @@
 	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, outbound_proxy));
 	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "expiration", "3600", OPT_UINT_T, 0, FLDSET(struct ast_sip_outbound_publish, expiration));
 	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "max_auth_attempts", "5", OPT_UINT_T, 0, FLDSET(struct ast_sip_outbound_publish, max_auth_attempts));
+	ast_sorcery_object_field_register(ast_sip_get_sorcery(), "outbound-publish", "transport", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_outbound_publish, transport));
 	ast_sorcery_object_field_register_custom(ast_sip_get_sorcery(), "outbound-publish", "outbound_auth", "", outbound_auth_handler, NULL, NULL, 0, 0);
 
 	ast_sorcery_reload_object(ast_sip_get_sorcery(), "outbound-publish");

-- 
To view, visit https://gerrit.asterisk.org/2537
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib389130489b70e36795b0003fa5fd386e2680151
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>



More information about the asterisk-code-review mailing list