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

George Joseph asteriskteam at digium.com
Mon Aug 26 12:37:15 CDT 2019


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


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
M res/res_pjsip_session.exports.in
10 files changed, 88 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/99/12799/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index b0d5fda..9bfc175 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -2279,6 +2279,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 bbd0317..ff8a017 100644
--- a/configs/samples/pjsip.conf.sample
+++ b/configs/samples/pjsip.conf.sample
@@ -667,6 +667,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 5e8dd3a..913962e 100644
--- a/include/asterisk/res_pjsip.h
+++ b/include/asterisk/res_pjsip.h
@@ -562,6 +562,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 e2d4fcd..749b5bb 100644
--- a/include/asterisk/res_pjsip_session.h
+++ b/include/asterisk/res_pjsip_session.h
@@ -733,4 +733,18 @@
 		}							\
 	} while(0)
 
+/*!
+ * \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 c41b545..56d14e9 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 4f7beb6..f771722 100644
--- a/res/res_pjsip/pjsip_configuration.c
+++ b/res/res_pjsip/pjsip_configuration.c
@@ -1825,6 +1825,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, 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 0cc514a..f899162 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -1803,6 +1803,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);
 
diff --git a/res/res_pjsip_session.exports.in b/res/res_pjsip_session.exports.in
index 5bc0bf4..c0d220f 100644
--- a/res/res_pjsip_session.exports.in
+++ b/res/res_pjsip_session.exports.in
@@ -19,6 +19,7 @@
 		LINKER_SYMBOL_PREFIXast_sip_session_send_request;
 		LINKER_SYMBOL_PREFIXast_sip_session_create_invite;
 		LINKER_SYMBOL_PREFIXast_sip_session_create_outgoing;
+		LINKER_SYMBOL_PREFIXast_sip_session_set_local_contact_user;
 		LINKER_SYMBOL_PREFIXast_sip_session_suspend;
 		LINKER_SYMBOL_PREFIXast_sip_session_unsuspend;
 		LINKER_SYMBOL_PREFIXast_sip_dialog_get_session;

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ic2ca721f7bb5fab39c80907a33e16d4f94097f91
Gerrit-Change-Number: 12799
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/bf741a40/attachment-0001.html>


More information about the asterisk-code-review mailing list