<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7229">View Change</a></p><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(+), 15 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/29/7229/1</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 8c3a577..95c681d 100644<br>--- a/apps/app_record.c<br>+++ b/apps/app_record.c<br>@@ -137,6 +137,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>@@ -163,21 +169,20 @@<br>  * \retval 0 do not exit<br>  * \retval -1 do exit<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>@@ -246,6 +251,7 @@<br>     );<br>    int ms;<br>       struct timeval start;<br>+        const char *status_response;<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>@@ -343,7 +349,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>@@ -379,7 +385,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>@@ -388,7 +394,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>@@ -423,7 +429,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>@@ -439,7 +445,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>@@ -448,12 +454,27 @@<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>+                   {<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>@@ -463,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>@@ -504,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/7229">change 7229</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/7229"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I7fe9de99953e46b4bafa2b38cf151fe8f6488254 </div>
<div style="display:none"> Gerrit-Change-Number: 7229 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>