[Asterisk-code-review] pjsip: Added "subscribe context" to endpoint (asterisk[13])

Alexei Gradinari asteriskteam at digium.com
Mon Jul 4 13:57:34 CDT 2016


Alexei Gradinari has uploaded a new change for review.

  https://gerrit.asterisk.org/3145

Change subject: pjsip: Added "subscribe_context" to endpoint
......................................................................

pjsip: Added "subscribe_context" to endpoint

If specified, incoming SUBSCRIBE requests will be searched for the matching
extension in the indicated context. If no "subscribe_context" is specified,
then the "context" setting is used.

ASTERISK-25471 #close

Change-Id: I3fb7a15f5bc154079bd348c08b7ad1cdd2d5e514
---
M CHANGES
A contrib/ast-db-manage/config/versions/9deac0ae4717_pjsip_add_subscribe_context.py
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip_exten_state.c
6 files changed, 58 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/45/3145/1

diff --git a/CHANGES b/CHANGES
index 55ec329..eed5724 100644
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,17 @@
 ==============================================================================
 
 ------------------------------------------------------------------------------
+--- Functionality changes from Asterisk 13.10.0 to Asterisk 13.11.0 ----------
+------------------------------------------------------------------------------
+
+res_pjsip
+------------------
+ * Added "subscribe_context" to endpoint.
+   If specified, incoming SUBSCRIBE requests will be searched for the matching
+   extension in the indicated context. If no "subscribe_context" is specified,
+   then the "context" setting is used.
+
+------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 13.9.0 to Asterisk 13.10.0 -----------
 ------------------------------------------------------------------------------
 
diff --git a/contrib/ast-db-manage/config/versions/9deac0ae4717_pjsip_add_subscribe_context.py b/contrib/ast-db-manage/config/versions/9deac0ae4717_pjsip_add_subscribe_context.py
new file mode 100644
index 0000000..2358fdd
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/9deac0ae4717_pjsip_add_subscribe_context.py
@@ -0,0 +1,21 @@
+"""pjsip_add_subscribe_context
+
+Revision ID: 9deac0ae4717
+Revises: ef7efc2d3964
+Create Date: 2016-07-04 12:11:28.117788
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '9deac0ae4717'
+down_revision = 'ef7efc2d3964'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    op.add_column('ps_endpoints', sa.Column('subscribe_context', sa.String(40)))
+
+def downgrade():
+    op.drop_column('ps_endpoints', 'subscribe_context')
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index 5b830ea..21137c3 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -497,6 +497,10 @@
  * \brief Endpoint subscription configuration
  */
 struct ast_sip_endpoint_subscription_configuration {
+	AST_DECLARE_STRING_FIELDS(
+		/* Context for SUBSCRIBE requests */
+		AST_STRING_FIELD(context);
+	);
 	/*! Indicates if endpoint is allowed to initiate subscriptions */
 	unsigned int allow;
 	/*! The minimum allowed expiration for subscriptions from endpoint */
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 07b8217..de8eb3e 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -897,6 +897,15 @@
 						mask with a slash ('/')
 					</para></description>
 				</configOption>
+				<configOption name="subscribe_context">
+					<synopsis>Context for incoming MESSAGE requests.</synopsis>
+					<description><para>
+						If specified, incoming SUBSCRIBE requests will be searched for the matching
+						extension in the indicated context.
+						If no <replaceable>subscribe_context</replaceable> is specified,
+						then the <replaceable>context</replaceable> setting is used.
+					</para></description>
+				</configOption>
 			</configObject>
 			<configObject name="auth">
 				<synopsis>Authentication type</synopsis>
@@ -1958,6 +1967,9 @@
 				<parameter name="ActiveChannels">
 					<para>The number of active channels associated with this endpoint.</para>
 				</parameter>
+				<parameter name="SubscribeContext">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='subscribe_context']/synopsis/node())"/></para>
+				</parameter>
 			</syntax>
 		</managerEventInstance>
 	</managerEvent>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 8791816..66ffbc7 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1861,6 +1861,7 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_deny", "", endpoint_acl_handler, NULL, NULL, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_permit", "", endpoint_acl_handler, NULL, NULL, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "contact_acl", "", endpoint_acl_handler, contact_acl_to_str, NULL, 0, 0);
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "subscribe_context", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.context));
 
 	if (ast_sip_initialize_sorcery_transport()) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");
@@ -1960,6 +1961,7 @@
 {
 	ast_string_field_free_memory(&subscription->mwi);
 	ast_free(subscription->mwi.voicemail_extension);
+	ast_string_field_free_memory(subscription);
 }
 
 static void info_configuration_destroy(struct ast_sip_endpoint_info_configuration *info)
@@ -1995,7 +1997,7 @@
 
 static int init_subscription_configuration(struct ast_sip_endpoint_subscription_configuration *subscription)
 {
-	return ast_string_field_init(&subscription->mwi, 64);
+	return ast_string_field_init(subscription, 64) || ast_string_field_init(&subscription->mwi, 64);
 }
 
 static int init_info_configuration(struct ast_sip_endpoint_info_configuration *info)
diff --git a/res/res_pjsip_exten_state.c b/res/res_pjsip_exten_state.c
index 69a4589..e6f3a0f 100644
--- a/res/res_pjsip_exten_state.c
+++ b/res/res_pjsip_exten_state.c
@@ -352,9 +352,11 @@
 static int new_subscribe(struct ast_sip_endpoint *endpoint,
 		const char *resource)
 {
-	if (!ast_exists_extension(NULL, endpoint->context, resource, PRIORITY_HINT, NULL)) {
+	const char *context=(ast_strlen_zero(endpoint->subscription.context)?endpoint->context:endpoint->subscription.context);
+
+	if (!ast_exists_extension(NULL, context, resource, PRIORITY_HINT, NULL)) {
 		ast_log(LOG_NOTICE, "Extension state subscription failed: Extension %s does not exist in context '%s' or has no associated hint\n",
-			resource, endpoint->context);
+			resource, context);
 		return 404;
 	}
 
@@ -372,7 +374,9 @@
 		return -1;
 	}
 
-	ast_copy_string(exten_state_sub->context, endpoint->context, sizeof(exten_state_sub->context));
+	ast_copy_string(exten_state_sub->context,
+		(ast_strlen_zero(endpoint->subscription.context)?endpoint->context:endpoint->subscription.context),
+		sizeof(exten_state_sub->context));
 	ast_copy_string(exten_state_sub->exten, resource, sizeof(exten_state_sub->exten));
 
 	if ((exten_state_sub->id = ast_extension_state_add_destroy_extended(

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3fb7a15f5bc154079bd348c08b7ad1cdd2d5e514
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