[Asterisk-code-review] res_pjsip: Add "send_cid_in_contact_user" option to endpoint (...asterisk[16])

George Joseph asteriskteam at digium.com
Mon Aug 26 12:42:17 CDT 2019


George Joseph has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/12800


Change subject: res_pjsip: Add "send_cid_in_contact_user" option to endpoint
......................................................................

res_pjsip: Add "send_cid_in_contact_user" option to endpoint

A new option "send_cid_in_contact_user" has been added to endpoint.
Some Public Service Access Points (PSAPs) require that the
caller id be sent in the user portion of the Contact header.
If set to yes, we send the callerid number regardless of any
privacy settings that might be in effect.

Change-Id: Ic2ca721f7bb5fab39c80907a33e16d4f94097f91
---
M channels/chan_pjsip.c
M configs/samples/pjsip.conf.sample
A contrib/ast-db-manage/config/versions/bbcf3b472a11_add_send_cid_in_contact_user_to_endpoint.py
A doc/CHANGES-staging/send_cid_in_contact_user.txt
M include/asterisk/res_pjsip.h
M include/asterisk/res_pjsip_session.h
M res/res_pjsip.c
M res/res_pjsip/pjsip_configuration.c
M res/res_pjsip_session.c
9 files changed, 87 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/12800/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 8ab1549..16eba87 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -2669,6 +2669,14 @@
 		return NULL;
 	}
 
+	if (session->endpoint->id.send_cid_in_contact_user && requestor) {
+		struct ast_party_caller *caller = ast_channel_caller((struct ast_channel *)requestor);
+
+		if (caller) {
+			ast_sip_session_set_local_contact_user(session, caller->id.number.str);
+		}
+	}
+
 	return session->channel;
 }
 
diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample
index 59c7a0d..e868062 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -669,6 +669,11 @@
 ;send_pai=no    ; Send the P Asserted Identity header (default: "no")
 ;send_rpid=no   ; Send the Remote Party ID header (default: "no")
 ;rpid_immediate=no      ; Send connected line updates on unanswered incoming calls immediately. (default: "no")
+;send_cid_in_contact_user=no ; Send the CallerID number in the user part of the Contact URI.
+                ; Some Public Service Access Points (PSAPs) require that the
+                ; caller id be sent in the user portion of the Contact header.
+                ; If set to yes, we send the callerid number regardless of any
+                ; privacy settings that might be in effect.
 ;timers_min_se=90       ; Minimum session timers expiration period (default:
                         ; "90")
 ;timers=yes     ; Session timers for SIP packets (default: "yes")
diff --git a/contrib/ast-db-manage/config/versions/bbcf3b472a11_add_send_cid_in_contact_user_to_endpoint.py b/contrib/ast-db-manage/config/versions/bbcf3b472a11_add_send_cid_in_contact_user_to_endpoint.py
new file mode 100644
index 0000000..445238b
--- /dev/null
+++ b/contrib/ast-db-manage/config/versions/bbcf3b472a11_add_send_cid_in_contact_user_to_endpoint.py
@@ -0,0 +1,32 @@
+"""Add send_cid_in_contact_user to endpoint
+
+Revision ID: bbcf3b472a11
+Revises: 3a094a18e75b
+Create Date: 2019-08-26 11:25:55.775327
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = 'bbcf3b472a11'
+down_revision = '3a094a18e75b'
+
+from alembic import op
+import sqlalchemy as sa
+from sqlalchemy.dialects.postgresql import ENUM
+
+YESNO_NAME = 'yesno_values'
+YESNO_VALUES = ['yes', 'no']
+
+def upgrade():
+    ############################# Enums ##############################
+
+    # yesno_values have already been created, so use postgres enum object
+    # type to get around "already created" issue - works okay with mysql
+    yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)
+
+    op.add_column('ps_endpoints', sa.Column('send_cid_in_contact_user', yesno_values))
+
+def downgrade():
+    if op.get_context().bind.dialect.name == 'mssql':
+        op.drop_constraint('ck_ps_endpoints_send_cid_in_contact_user_yesno_values','ps_endpoints')
+    op.drop_column('ps_endpoints', 'send_cid_in_contact_user')
diff --git a/doc/CHANGES-staging/send_cid_in_contact_user.txt b/doc/CHANGES-staging/send_cid_in_contact_user.txt
new file mode 100644
index 0000000..a38359e
--- /dev/null
+++ b/doc/CHANGES-staging/send_cid_in_contact_user.txt
@@ -0,0 +1,7 @@
+Subject: res_pjsip
+
+A new option "send_cid_in_contact_user" has been added to endpoint.
+Some Public Service Access Points (PSAPs) require that the
+caller id be sent in the user portion of the Contact header.
+If set to yes, we send the callerid number regardless of any
+privacy settings that might be in effect.
diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h
index e295765..08b3e7d 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -568,6 +568,8 @@
 	unsigned int send_diversion;
 	/*! When performing connected line update, which method should be used */
 	enum ast_sip_session_refresh_method refresh_method;
+	/*! Do we send the callerid number as the contact user on requests? */
+	unsigned int send_cid_in_contact_user;
 };
 
 /*!
diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h
index a6f8bde..e602d76 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -908,4 +908,18 @@
  */
 struct ast_sip_session_media *ast_sip_session_media_get_transport(struct ast_sip_session *session, struct ast_sip_session_media *session_media);
 
+/*!
+ * \brief Sets the Contact URI user in outgoing requests
+ * \since 13,29.0
+ * \since 16.6.0
+ *
+ * \param session The UAC session which needs the contact user set
+ * \param contact_user The new value to set the user portion of the contact to
+ *
+ * \retval 0 Successfully updated the SDP answer
+ * \retval -1 Failure to updated the SDP answer
+ *
+ */
+int ast_sip_session_set_local_contact_user(struct ast_sip_session *session, const char *contact_user);
+
 #endif /* _RES_PJSIP_SESSION_H */
diff --git a/res/res_pjsip.c b/res/res_pjsip.c
index 7123938..230ddea 100644
--- a/res/res_pjsip.c
+++ b/res/res_pjsip.c
@@ -452,6 +452,14 @@
 						dialplan application such as <emphasis>Ringing</emphasis>.</para>
 					</description>
 				</configOption>
+				<configOption name="send_cid_in_contact_user" default="no">
+					<synopsis>Send the CallerID number in the user part of the Contact URI</synopsis>
+					<description><para>Some Public Service Access Points (PSAPs) require that the
+					caller id be sent in the user portion of the Contact header.
+					If set to yes, we send the callerid number regardless of any
+					privacy settings that might be in effect. </para>
+					</description>
+				</configOption>
 				<configOption name="timers_min_se" default="90">
 					<synopsis>Minimum session timers expiration period</synopsis>
 					<description><para>
diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c
index cc19603..e908e2e 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1866,6 +1866,7 @@
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_rpid", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.send_rpid));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rpid_immediate", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.rpid_immediate));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_diversion", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.send_diversion));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_cid_in_contact_user", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.send_cid_in_contact_user));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.mailboxes));
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "voicemail_extension", "", voicemail_extension_handler, voicemail_extension_to_str, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "aggregate_mwi", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.aggregate));
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 5fe8836..cbb56c0 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -2679,6 +2679,16 @@
 	return ret_session;
 }
 
+int ast_sip_session_set_local_contact_user(struct ast_sip_session *session, const char *contact_user)
+{
+	if (contact_user && session->inv_session && session->inv_session->role == PJSIP_ROLE_UAC) {
+		pjsip_sip_uri *sip_uri = pjsip_uri_get_uri(session->inv_session->dlg->local.contact->uri);
+
+		pj_strdup2(session->inv_session->dlg->pool, &sip_uri->user, contact_user);
+	}
+	return 0;
+}
+
 static int session_end(void *vsession);
 static int session_end_completion(void *vsession);
 

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ic2ca721f7bb5fab39c80907a33e16d4f94097f91
Gerrit-Change-Number: 12800
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190826/34ed2ed4/attachment.html>


More information about the asterisk-code-review mailing list