[Asterisk-code-review] pjsip: new endpoint's options to control Connected Line updates (asterisk[13])

George Joseph asteriskteam at digium.com
Wed Oct 31 13:56:48 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10480 )

Change subject: pjsip: new endpoint's options to control Connected Line updates
......................................................................

pjsip: new endpoint's options to control Connected Line updates

This patch adds new options 'trust_connected_line' and 'send_connected_line'
to the endpoint.

The option 'trust_connected_line' is to control if connected line updates
are accepted from this endpoint.

The option 'send_connected_line' is to control if connected line updates
can be sent to this endpoint.

The default value is 'yes' for both options.

Change-Id: I16af967815efd904597ec2f033337e4333d097cd
---
M CHANGES
M channels/chan_pjsip.c
M configs/samples/pjsip.conf.sample
A contrib/ast-db-manage/config/versions/1ac563b350a8_add_pjsip_trust_send__connected_line.py
M include/asterisk/res_pjsip.h
M res/res_pjsip.c
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip_caller_id.c
8 files changed, 79 insertions(+), 3 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/CHANGES b/CHANGES
index 45c964e..b191f40 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,15 @@
 --- Functionality changes from Asterisk 13.23.0 to Asterisk 13.24.0 ----------
 ------------------------------------------------------------------------------
 
+res_pjsip
+------------------
+ * New options 'trust_connected_line' and 'send_connected_line' have been
+   added to the endpoint. The option 'trust_connected_line' is to control
+   if connected line updates are accepted from this endpoint.
+   The option 'send_connected_line' is to control if connected line updates
+   can be sent to this endpoint.
+   The default value is 'yes' for both options.
+
 res_rtp_asterisk
 ------------------
  * The existing strictrtp option in rtp.conf has a new choice availabe, called
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 4da0361..5bbd025 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -1268,7 +1268,8 @@
 	struct ast_party_id connected_id;
 	int update_allowed = 0;
 
-	if (!session->endpoint->id.send_pai && !session->endpoint->id.send_rpid) {
+	if (!session->endpoint->send_connected_line
+		|| (!session->endpoint->id.send_pai && !session->endpoint->id.send_rpid)) {
 		return 0;
 	}
 
diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample
index 7f78783..56e7849 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -608,6 +608,10 @@
 ;direct_media_glare_mitigation=none     ; Mitigation of direct media re INVITE
                                         ; glare (default: "none")
 ;direct_media_method=invite     ; Direct Media method type (default: "invite")
+;trust_connected_line=yes       ; Accept Connected Line updates from this endpoint
+                                ; (default: "yes")
+;send_connected_line=yes        ; Send Connected Line updates to this endpoint
+                                ; (default: "yes")
 ;connected_line_method=invite   ; Connected line method type.
                                 ; When set to "invite", check the remote's
                                 ; Allow header and if UPDATE is allowed, send
diff --git a/contrib/ast-db-manage/config/versions/1ac563b350a8_add_pjsip_trust_send__connected_line.py b/contrib/ast-db-manage/config/versions/1ac563b350a8_add_pjsip_trust_send__connected_line.py
new file mode 100644
index 0000000..6ca6d23
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/1ac563b350a8_add_pjsip_trust_send__connected_line.py
@@ -0,0 +1,40 @@
+"""add pjsip trust/send _connected_line
+
+Revision ID: 1ac563b350a8
+Revises: 2bb1a85135ad
+Create Date: 2018-10-12 17:10:34.530282
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '1ac563b350a8'
+down_revision = '2bb1a85135ad'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+AST_BOOL_NAME = 'ast_bool_values'
+# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write
+# those aliases.
+AST_BOOL_VALUES = [ '0', '1',
+                    'off', 'on',
+                    'false', 'true',
+                    'no', 'yes' ]
+
+def upgrade():
+    ############################# Enums ##############################
+
+    # ast_bool_values has already been created, so use postgres enum object
+    # type to get around "already created" issue - works okay with mysql
+    ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_NAME, create_type=False)
+
+    op.add_column('ps_endpoints', sa.Column('trust_connected_line', ast_bool_values))
+    op.add_column('ps_endpoints', sa.Column('send_connected_line', ast_bool_values))
+
+def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_trust_connected_line_ast_bool_values', 'ps_endpoints')
+        op.drop_constraint('ck_ps_endpoints_send_connected_line_ast_bool_values', 'ps_endpoints')
+    op.drop_column('ps_endpoints', 'trust_connected_line')
+    op.drop_column('ps_endpoints', 'send_connected_line')
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index eb0905b..902cfe8 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -796,6 +796,10 @@
 	unsigned int accept_multiple_sdp_answers;
 	/*! Suppress Q.850 Reason headers on this endpoint */
 	unsigned int suppress_q850_reason_headers;
+	/*! Do we accept connected line updates from this endpoint? */
+	unsigned int trust_connected_line;
+	/*! Do we send connected line updates to this endpoint? */
+	unsigned int send_connected_line;
 };
 
 /*! URI parameter for symmetric transport */
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 93fa6a3..1f34c99 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -189,6 +189,12 @@
 						</enumlist>
 					</description>
 				</configOption>
+				<configOption name="trust_connected_line">
+					<synopsis>Accept Connected Line updates from this endpoint</synopsis>
+				</configOption>
+				<configOption name="send_connected_line">
+					<synopsis>Send Connected Line updates to this endpoint</synopsis>
+				</configOption>
 				<configOption name="connected_line_method" default="invite">
 					<synopsis>Connected line method type</synopsis>
 					<description>
@@ -2120,6 +2126,12 @@
 				<parameter name="DirectMediaMethod">
 					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='direct_media_method']/synopsis/node())"/></para>
 				</parameter>
+				<parameter name="TrustConnectedLine">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='trust_connected_line']/synopsis/node())"/></para>
+				</parameter>
+				<parameter name="SendConnectedLine">
+					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='send_connected_line']/synopsis/node())"/></para>
+				</parameter>
 				<parameter name="ConnectedLineMethod">
 					<para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='connected_line_method']/synopsis/node())"/></para>
 				</parameter>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index 477b317..3616dba 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1778,6 +1778,8 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "identify_by", "username,ip", ident_handler, ident_to_str, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "direct_media", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.direct_media.enabled));
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_method", "invite", direct_media_method_handler, direct_media_method_to_str, NULL, 0, 0);
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "trust_connected_line", "yes", OPT_YESNO_T, 1, FLDSET(struct ast_sip_endpoint, trust_connected_line));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_connected_line", "yes", OPT_YESNO_T, 1, FLDSET(struct ast_sip_endpoint, send_connected_line));
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "connected_line_method", "invite", connected_line_method_handler, connected_line_method_to_str, NULL, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_glare_mitigation", "none", direct_media_glare_mitigation_handler, direct_media_glare_mitigation_to_str, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "disable_direct_media_on_nat", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.direct_media.disable_on_nat));
diff --git a/res/res_pjsip_caller_id.c b/res/res_pjsip_caller_id.c
index d240496..24822bf 100644
--- a/res/res_pjsip_caller_id.c
+++ b/res/res_pjsip_caller_id.c
@@ -342,7 +342,8 @@
 {
 	struct ast_party_id id;
 
-	if (!session->endpoint->id.trust_inbound) {
+	if (!session->endpoint->trust_connected_line
+		|| !session->endpoint->id.trust_inbound) {
 		return;
 	}
 
@@ -750,7 +751,10 @@
 	struct ast_party_id effective_id;
 	struct ast_party_id connected_id;
 
-	if (!session->channel) {
+	if (!session->channel
+		|| (!session->endpoint->send_connected_line
+			&& session->inv_session
+			&& session->inv_session->state >= PJSIP_INV_STATE_EARLY)) {
 		return;
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/10480
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I16af967815efd904597ec2f033337e4333d097cd
Gerrit-Change-Number: 10480
Gerrit-PatchSet: 5
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181031/694b8b83/attachment-0001.html>


More information about the asterisk-code-review mailing list