<p>Kevin Harwell <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18284">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved; Approved for Submit
Benjamin Keith Ford: Looks good to me, but someone else must approve
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_mf, app_sf: Return -1 if channel hangs up.<br><br>The ReceiveMF and ReceiveSF applications currently always<br>return 0, even if a channel has hung up. The call will still<br>end but generally applications are expected to return -1 if<br>the channel has hung up.<br><br>We now return -1 if a hangup occured to bring this behavior<br>in line with this norm. This has no functional impact, but<br>merely increases conformity with how these modules interact<br>with the PBX core.<br><br>ASTERISK-29951 #close<br><br>Change-Id: I234d755050ab8ed58f197c6925b968ba26b14033<br>---<br>M apps/app_mf.c<br>M apps/app_sf.c<br>2 files changed, 31 insertions(+), 12 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_mf.c b/apps/app_mf.c</span><br><span>index 33c1aaa..eef5419 100644</span><br><span>--- a/apps/app_mf.c</span><br><span>+++ b/apps/app_mf.c</span><br><span>@@ -226,7 +226,7 @@</span><br><span> * \param maxdigits If greater than 0, only read this many digits no matter what</span><br><span> *</span><br><span> * \retval 0 if successful</span><br><span style="color: hsl(0, 100%, 40%);">- * \retval -1 if unsuccessful.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 if unsuccessful (including hangup).</span><br><span> */</span><br><span> static int read_mf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int features, int laxkp, int override, int no_kp, int no_st, int maxdigits) {</span><br><span> struct ast_dsp *dsp;</span><br><span>@@ -236,6 +236,7 @@</span><br><span> int digits_read = 0;</span><br><span> int is_start_digit = 0;</span><br><span> char *str = buf;</span><br><span style="color: hsl(120, 100%, 40%);">+ int res = 0;</span><br><span> </span><br><span> if (!(dsp = ast_dsp_new())) {</span><br><span> ast_log(LOG_WARNING, "Unable to allocate DSP!\n");</span><br><span>@@ -318,11 +319,12 @@</span><br><span> }</span><br><span> } else {</span><br><span> pbx_builtin_setvar_helper(chan, "RECEIVEMFSTATUS", "HANGUP");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = -1;</span><br><span> }</span><br><span> }</span><br><span> ast_dsp_free(dsp);</span><br><span> ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span> }</span><br><span> </span><br><span> static int read_mf_exec(struct ast_channel *chan, const char *data)</span><br><span>@@ -334,7 +336,7 @@</span><br><span> struct ast_flags flags = {0};</span><br><span> char *optargs[OPT_ARG_ARRAY_SIZE];</span><br><span> char *argcopy = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- int features = 0, maxdigits = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int res, features = 0, maxdigits = 0;</span><br><span> </span><br><span> AST_DECLARE_APP_ARGS(arglist,</span><br><span> AST_APP_ARG(variable);</span><br><span>@@ -392,15 +394,15 @@</span><br><span> features |= DSP_DIGITMODE_RELAXDTMF;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- read_mf_digits(chan, tmp, BUFFER_SIZE, to, features, (ast_test_flag(&flags, OPT_LAX_KP)),</span><br><span style="color: hsl(120, 100%, 40%);">+ res = read_mf_digits(chan, tmp, BUFFER_SIZE, to, features, (ast_test_flag(&flags, OPT_LAX_KP)),</span><br><span> (ast_test_flag(&flags, OPT_KP_OVERRIDE)), (ast_test_flag(&flags, OPT_NO_KP)), (ast_test_flag(&flags, OPT_NO_ST)), maxdigits);</span><br><span> pbx_builtin_setvar_helper(chan, arglist.variable, tmp);</span><br><span> if (!ast_strlen_zero(tmp)) {</span><br><span> ast_verb(3, "MF digits received: '%s'\n", tmp);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!res) { /* if channel hung up, don't print anything out */</span><br><span> ast_verb(3, "No MF digits received.\n");</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span> }</span><br><span> </span><br><span> static int sendmf_exec(struct ast_channel *chan, const char *vdata)</span><br><span>diff --git a/apps/app_sf.c b/apps/app_sf.c</span><br><span>index dadc9cc..70f60d4 100644</span><br><span>--- a/apps/app_sf.c</span><br><span>+++ b/apps/app_sf.c</span><br><span>@@ -155,6 +155,21 @@</span><br><span> static const char *readsf_name = "ReceiveSF";</span><br><span> static const char sendsf_name[] = "SendSF";</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Detects SF digits on channel using DSP</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param chan channel on which to read digits</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param buf Buffer in which to store digits</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param buflen Size of buffer</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param timeout ms to wait for all digits before giving up</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param maxdigits Maximum number of digits</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param freq Frequency to use</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param features DSP features</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param extrapulses Whether to recognize extra pulses</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if successful</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 if unsuccessful (including hangup).</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span> static int read_sf_digits(struct ast_channel *chan, char *buf, int buflen, int timeout, int maxdigits, int freq, int features, int extrapulses) {</span><br><span> /* Bell System Technical Journal 39 (Nov. 1960) */</span><br><span> #define SF_MIN_OFF 25</span><br><span>@@ -169,6 +184,7 @@</span><br><span> char *str = buf;</span><br><span> int hits = 0, digits_read = 0;</span><br><span> unsigned short int sf_on = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ int res = 0;</span><br><span> </span><br><span> if (!(dsp = ast_dsp_new())) {</span><br><span> ast_log(LOG_WARNING, "Unable to allocate DSP!\n");</span><br><span>@@ -261,7 +277,7 @@</span><br><span> ast_debug(2, "Got more than 10 pulses, truncating to 10\n");</span><br><span> hits = 0; /* 10 dial pulses = digit 0 */</span><br><span> *str++ = hits + '0';</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> if (hits == 10) {</span><br><span> hits = 0; /* 10 dial pulses = digit 0 */</span><br><span>@@ -281,13 +297,14 @@</span><br><span> ast_frfree(frame);</span><br><span> } else {</span><br><span> pbx_builtin_setvar_helper(chan, "RECEIVESFSTATUS", "HANGUP");</span><br><span style="color: hsl(120, 100%, 40%);">+ res = -1;</span><br><span> }</span><br><span> }</span><br><span> if (dsp) {</span><br><span> ast_dsp_free(dsp);</span><br><span> }</span><br><span> ast_debug(3, "channel '%s' - event loop stopped { timeout: %d, remaining_time: %d }\n", ast_channel_name(chan), timeout, remaining_time);</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span> }</span><br><span> </span><br><span> static int read_sf_exec(struct ast_channel *chan, const char *data)</span><br><span>@@ -297,7 +314,7 @@</span><br><span> double tosec;</span><br><span> struct ast_flags flags = {0};</span><br><span> char *argcopy = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">- int features = 0, digits = 0, to = 0, freq = 2600;</span><br><span style="color: hsl(120, 100%, 40%);">+ int res, features = 0, digits = 0, to = 0, freq = 2600;</span><br><span> </span><br><span> AST_DECLARE_APP_ARGS(arglist,</span><br><span> AST_APP_ARG(variable);</span><br><span>@@ -360,14 +377,14 @@</span><br><span> features |= DSP_DIGITMODE_RELAXDTMF;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- read_sf_digits(chan, tmp, BUFFER_SIZE, to, digits, freq, features, ast_test_flag(&flags, OPT_EXTRAPULSES));</span><br><span style="color: hsl(120, 100%, 40%);">+ res = read_sf_digits(chan, tmp, BUFFER_SIZE, to, digits, freq, features, ast_test_flag(&flags, OPT_EXTRAPULSES));</span><br><span> pbx_builtin_setvar_helper(chan, arglist.variable, tmp);</span><br><span> if (!ast_strlen_zero(tmp)) {</span><br><span> ast_verb(3, "SF digits received: '%s'\n", tmp);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!res) { /* if channel hung up, don't print anything out */</span><br><span> ast_verb(3, "No SF digits received.\n");</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ return res;</span><br><span> }</span><br><span> </span><br><span> static int sendsf_exec(struct ast_channel *chan, const char *vdata)</span><br><span></span><br></pre><div style="white-space:pre-wrap"></div><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18284">change 18284</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/+/18284"/><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: I234d755050ab8ed58f197c6925b968ba26b14033 </div>
<div style="display:none"> Gerrit-Change-Number: 18284 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.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: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>