<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/12929">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Benjamin Keith Ford: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">channel/chan_pjsip: add dialplan function for music on hold<br><br>Add a new dialplan function PJSIP_MOH_PASSTHROUGH that allows<br>the on-hold behavior to be controlled on a per-call basis<br><br>ASTERISK-28542 #close<br><br>Change-Id: Iebe905b2ad6dbaa87ab330267147180b05a3c3a8<br>---<br>M channels/chan_pjsip.c<br>M channels/pjsip/dialplan_functions.c<br>M channels/pjsip/include/dialplan_functions.h<br>A doc/CHANGES-staging/chan_pjsip_moh_passthrough.txt<br>M include/asterisk/res_pjsip_session.h<br>M res/res_pjsip_session.c<br>6 files changed, 113 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index 5b91dfd..c091082 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -1744,7 +1744,7 @@</span><br><span> device_buf = alloca(device_buf_size);</span><br><span> ast_channel_get_device_name(ast, device_buf, device_buf_size);</span><br><span> ast_devstate_changed_literal(AST_DEVICE_ONHOLD, 1, device_buf);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!channel->session->endpoint->moh_passthrough) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!channel->session->moh_passthrough) {</span><br><span> ast_moh_start(ast, data, NULL);</span><br><span> } else {</span><br><span> if (ast_sip_push_task(channel->session->serializer, remote_send_hold, ao2_bump(channel->session))) {</span><br><span>@@ -1760,7 +1760,7 @@</span><br><span> device_buf = alloca(device_buf_size);</span><br><span> ast_channel_get_device_name(ast, device_buf, device_buf_size);</span><br><span> ast_devstate_changed_literal(AST_DEVICE_UNKNOWN, 1, device_buf);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!channel->session->endpoint->moh_passthrough) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!channel->session->moh_passthrough) {</span><br><span> ast_moh_stop(ast);</span><br><span> } else {</span><br><span> if (ast_sip_push_task(channel->session->serializer, remote_send_unhold, ao2_bump(channel->session))) {</span><br><span>@@ -3228,6 +3228,12 @@</span><br><span> .write = pjsip_acf_dtmf_mode_write</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_custom_function moh_passthrough_function = {</span><br><span style="color: hsl(120, 100%, 40%);">+ .name = "PJSIP_MOH_PASSTHROUGH",</span><br><span style="color: hsl(120, 100%, 40%);">+ .read = pjsip_acf_moh_passthrough_read,</span><br><span style="color: hsl(120, 100%, 40%);">+ .write = pjsip_acf_moh_passthrough_write</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct ast_custom_function session_refresh_function = {</span><br><span> .name = "PJSIP_SEND_SESSION_REFRESH",</span><br><span> .write = pjsip_acf_session_refresh_write,</span><br><span>@@ -3280,6 +3286,11 @@</span><br><span> goto end;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_custom_function_register(&moh_passthrough_function)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Unable to register PJSIP_MOH_PASSTHROUGH dialplan function\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ goto end;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (ast_custom_function_register(&session_refresh_function)) {</span><br><span> ast_log(LOG_WARNING, "Unable to register PJSIP_SEND_SESSION_REFRESH dialplan function\n");</span><br><span> goto end;</span><br><span>@@ -3325,6 +3336,7 @@</span><br><span> ast_sip_session_unregister_supplement(&call_pickup_supplement);</span><br><span> ast_sip_unregister_service(&refer_callback_module);</span><br><span> ast_custom_function_unregister(&dtmf_mode_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&moh_passthrough_function);</span><br><span> ast_custom_function_unregister(&media_offer_function);</span><br><span> ast_custom_function_unregister(&chan_pjsip_dial_contacts_function);</span><br><span> ast_custom_function_unregister(&chan_pjsip_parse_uri_function);</span><br><span>@@ -3352,6 +3364,7 @@</span><br><span> ast_sip_unregister_service(&refer_callback_module);</span><br><span> </span><br><span> ast_custom_function_unregister(&dtmf_mode_function);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_custom_function_unregister(&moh_passthrough_function);</span><br><span> ast_custom_function_unregister(&media_offer_function);</span><br><span> ast_custom_function_unregister(&chan_pjsip_dial_contacts_function);</span><br><span> ast_custom_function_unregister(&chan_pjsip_parse_uri_function);</span><br><span>diff --git a/channels/pjsip/dialplan_functions.c b/channels/pjsip/dialplan_functions.c</span><br><span>index 2081bad..7cc4506 100644</span><br><span>--- a/channels/pjsip/dialplan_functions.c</span><br><span>+++ b/channels/pjsip/dialplan_functions.c</span><br><span>@@ -80,6 +80,19 @@</span><br><span> <para>This function uses the same DTMF mode naming as the dtmf_mode configuration option</para></span><br><span> </description></span><br><span> </function></span><br><span style="color: hsl(120, 100%, 40%);">+<function name="PJSIP_MOH_PASSTHROUGH" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ Get or change the on-hold behavior for a SIP call.</span><br><span style="color: hsl(120, 100%, 40%);">+ </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ <syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ </syntax></span><br><span style="color: hsl(120, 100%, 40%);">+ <description></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>When read, returns the current moh passthrough mode</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>When written, sets the current moh passthrough mode</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>If <replaceable>yes</replaceable>, on-hold re-INVITEs are sent. If <replaceable>no</replaceable>, music on hold is generated.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>This function can be used to override the moh_passthrough configuration option</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </description></span><br><span style="color: hsl(120, 100%, 40%);">+</function></span><br><span> <function name="PJSIP_SEND_SESSION_REFRESH" language="en_US"></span><br><span> <synopsis></span><br><span> W/O: Initiate a session refresh via an UPDATE or re-INVITE on an established media session</span><br><span>@@ -1431,6 +1444,34 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int pjsip_acf_moh_passthrough_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_channel_pvt *channel;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (len < 3) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "%s: buffer too small\n", cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ channel = ast_channel_tech_pvt(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ strncpy(buf, AST_YESNO(channel->session->moh_passthrough), len);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct refresh_data {</span><br><span> struct ast_sip_session *session;</span><br><span> enum ast_sip_session_refresh_method method;</span><br><span>@@ -1574,6 +1615,30 @@</span><br><span> return ast_sip_push_task_wait_serializer(channel->session->serializer, dtmf_mode_refresh_cb, &rdata);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int pjsip_acf_moh_passthrough_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_channel_pvt *channel;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!chan) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_lock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ channel = ast_channel_tech_pvt(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ channel->session->moh_passthrough = ast_true(value);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int refresh_write_cb(void *obj)</span><br><span> {</span><br><span> struct refresh_data *data = obj;</span><br><span>diff --git a/channels/pjsip/include/dialplan_functions.h b/channels/pjsip/include/dialplan_functions.h</span><br><span>index a9332a2..d0bf130 100644</span><br><span>--- a/channels/pjsip/include/dialplan_functions.h</span><br><span>+++ b/channels/pjsip/include/dialplan_functions.h</span><br><span>@@ -73,6 +73,31 @@</span><br><span> int pjsip_acf_dtmf_mode_write(struct ast_channel *chan, const char *cmd, char *data, const char *value);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief PJSIP_MOH_PASSTHROUGH function read callback</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param chan The channel the function is called on</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param cmd The name of the function</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param data Arguments passed to the function</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param buf Out buffer that should be populated with the data</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param len Size of the buffer</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 on success</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 on failure</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int pjsip_acf_moh_passthrough_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief PJSIP_MOH_PASSTHROUGH function write callback</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param chan The channel the function is called on</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param cmd The name of the function</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param data Arguments passed to the function</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param value Value to be set by the function</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 on success</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 on failure</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int pjsip_acf_moh_passthrough_write(struct ast_channel *chan, const char *cmd, char *data, const char *value);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief PJSIP_MEDIA_OFFER function read callback</span><br><span> * \param chan The channel the function is called on</span><br><span> * \param cmd The name of the function</span><br><span>diff --git a/doc/CHANGES-staging/chan_pjsip_moh_passthrough.txt b/doc/CHANGES-staging/chan_pjsip_moh_passthrough.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..cb874a5</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/chan_pjsip_moh_passthrough.txt</span><br><span>@@ -0,0 +1,5 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: chan_pjsip</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+A new dialplan function, PJSIP_MOH_PASSTRHOUGH, has been added to chan_pjsip. This</span><br><span style="color: hsl(120, 100%, 40%);">+allows the behaviour of the moh_passthrough endpoint option to be read or changed</span><br><span style="color: hsl(120, 100%, 40%);">+in the dialplan. This allows control on a per-call basis.</span><br><span>diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h</span><br><span>index a6f8bde..43ac9c0 100644</span><br><span>--- a/include/asterisk/res_pjsip_session.h</span><br><span>+++ b/include/asterisk/res_pjsip_session.h</span><br><span>@@ -211,6 +211,8 @@</span><br><span> unsigned int defer_end:1;</span><br><span> /*! Session end (remote hangup) requested while termination deferred */</span><br><span> unsigned int ended_while_deferred:1;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Whether to pass through hold and unhold using re-invites with recvonly and sendrecv */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int moh_passthrough:1;</span><br><span> /*! DTMF mode to use with this session, from endpoint but can change */</span><br><span> enum ast_sip_dtmf_mode dtmf;</span><br><span> /*! Initial incoming INVITE Request-URI. NULL otherwise. */</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index 5fe8836..dc476ff 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -2306,6 +2306,7 @@</span><br><span> session->inv_session = inv_session;</span><br><span> </span><br><span> session->dtmf = endpoint->dtmf;</span><br><span style="color: hsl(120, 100%, 40%);">+ session->moh_passthrough = endpoint->moh_passthrough;</span><br><span> </span><br><span> if (ast_sip_session_add_supplements(session)) {</span><br><span> /* Release the ref held by session->inv_session */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/12929">change 12929</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/12929"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: Iebe905b2ad6dbaa87ab330267147180b05a3c3a8 </div>
<div style="display:none"> Gerrit-Change-Number: 12929 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>