<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7228">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_record: Don't set RECORD_STATUS chan var until file is closed<br><br>We've been calling pbx_builtin_setvar_helper to set the<br>RECORD_STATUS variable before actually closing the recorded file.<br>If a client is watching VarSet events and tries to do something with<br>the file when a RECORD_STATUS event is seen, they might attempt to<br>do so while the file it's still open.<br><br>We now delay calling pbx_builtin_setvar_helper until after we close<br>the file.<br><br>ASTERISK-27423<br><br>Change-Id: I7fe9de99953e46b4bafa2b38cf151fe8f6488254<br>---<br>M apps/app_record.c<br>1 file changed, 39 insertions(+), 17 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/apps/app_record.c b/apps/app_record.c<br>index 104daa5..d1cdeab 100644<br>--- a/apps/app_record.c<br>+++ b/apps/app_record.c<br>@@ -139,6 +139,12 @@<br> OPTION_NO_TRUNCATE = (1 << 9),<br> };<br> <br>+enum dtmf_response {<br>+ RESPONSE_NO_MATCH = 0,<br>+ RESPONSE_OPERATOR,<br>+ RESPONSE_DTMF,<br>+};<br>+<br> AST_APP_OPTIONS(app_opts,{<br> AST_APP_OPTION('a', OPTION_APPEND),<br> AST_APP_OPTION('k', OPTION_KEEP),<br>@@ -162,24 +168,22 @@<br> * \param dtmf_integer the integer value of the DTMF key received<br> * \param terminator key currently set to be pressed for normal termination<br> *<br>- * \retval 0 do not exit<br>- * \retval -1 do exit<br>+ * \returns One of enum dtmf_response<br> */<br>-static int record_dtmf_response(struct ast_channel *chan, struct ast_flags *flags, int dtmf_integer, int terminator)<br>+static enum dtmf_response record_dtmf_response(struct ast_channel *chan,<br>+ struct ast_flags *flags, int dtmf_integer, int terminator)<br> {<br> if ((dtmf_integer == OPERATOR_KEY) &&<br> (ast_test_flag(flags, OPTION_OPERATOR_EXIT))) {<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "OPERATOR");<br>- return -1;<br>+ return RESPONSE_OPERATOR;<br> }<br> <br> if ((dtmf_integer == terminator) ||<br> (ast_test_flag(flags, OPTION_ANY_TERMINATE))) {<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "DTMF");<br>- return -1;<br>+ return RESPONSE_DTMF;<br> }<br> <br>- return 0;<br>+ return RESPONSE_NO_MATCH;<br> }<br> <br> static int create_destination_directory(const char *path)<br>@@ -248,6 +252,7 @@<br> );<br> int ms;<br> struct timeval start;<br>+ const char *status_response = "ERROR";<br> <br> /* The next few lines of code parse out the filename and header from the input string */<br> if (ast_strlen_zero(data)) { /* no data implies no filename or anything is present */<br>@@ -345,7 +350,7 @@<br> <br> if (res) {<br> ast_log(LOG_WARNING, "Could not answer channel '%s'\n", ast_channel_name(chan));<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");<br>+ status_response = "ERROR";<br> goto out;<br> }<br> <br>@@ -381,7 +386,7 @@<br> <br> if (create_destination_directory(tmp)) {<br> ast_log(LOG_WARNING, "Could not create directory for file %s\n", args.filename);<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");<br>+ status_response = "ERROR";<br> goto out;<br> }<br> <br>@@ -390,7 +395,7 @@<br> <br> if (!s) {<br> ast_log(LOG_WARNING, "Could not create file %s\n", args.filename);<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");<br>+ status_response = "ERROR";<br> goto out;<br> }<br> <br>@@ -425,7 +430,7 @@<br> if (res) {<br> ast_log(LOG_WARNING, "Problem writing frame\n");<br> ast_frfree(f);<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");<br>+ status_response = "ERROR";<br> break;<br> }<br> <br>@@ -441,7 +446,7 @@<br> /* Ended happily with silence */<br> ast_frfree(f);<br> gotsilence = 1;<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "SILENCE");<br>+ status_response = "SILENCE";<br> break;<br> }<br> }<br>@@ -450,12 +455,26 @@<br> <br> if (res) {<br> ast_log(LOG_WARNING, "Problem writing frame\n");<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "ERROR");<br>+ status_response = "ERROR";<br> ast_frfree(f);<br> break;<br> }<br> } else if (f->frametype == AST_FRAME_DTMF) {<br>- if (record_dtmf_response(chan, &flags, f->subclass.integer, terminator)) {<br>+ enum dtmf_response rc =<br>+ record_dtmf_response(chan, &flags, f->subclass.integer, terminator);<br>+ switch(rc) {<br>+ case RESPONSE_NO_MATCH:<br>+ break;<br>+ case RESPONSE_OPERATOR:<br>+ status_response = "OPERATOR";<br>+ ast_debug(1, "Got OPERATOR\n");<br>+ break;<br>+ case RESPONSE_DTMF:<br>+ status_response = "DTMF";<br>+ ast_debug(1, "Got DTMF\n");<br>+ break;<br>+ }<br>+ if (rc != RESPONSE_NO_MATCH) {<br> ast_frfree(f);<br> break;<br> }<br>@@ -465,13 +484,13 @@<br> <br> if (maxduration > 0 && !ms) {<br> gottimeout = 1;<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "TIMEOUT");<br>+ status_response = "TIMEOUT";<br> }<br> <br> if (!f) {<br> ast_debug(1, "Got hangup\n");<br> res = -1;<br>- pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "HANGUP");<br>+ status_response = "HANGUP";<br> if (!ast_test_flag(&flags, OPTION_KEEP)) {<br> ast_filedelete(args.filename, NULL);<br> }<br>@@ -506,6 +525,9 @@<br> if (sildet) {<br> ast_dsp_free(sildet);<br> }<br>+<br>+ pbx_builtin_setvar_helper(chan, "RECORD_STATUS", status_response);<br>+<br> return res;<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7228">change 7228</a>. To unsubscribe, 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/7228"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I7fe9de99953e46b4bafa2b38cf151fe8f6488254 </div>
<div style="display:none"> Gerrit-Change-Number: 7228 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>