<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/16077">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_stack: Adds conditional return application<br><br>Adds the ReturnIf application, which conditionally<br>returns from a gosub subroutine and works similarly<br>to other conditional applications.<br><br>ASTERISK-29493<br><br>Change-Id: I046b778bd98a2aa97bd58b058ee77f7504407425<br>---<br>M apps/app_stack.c<br>A doc/CHANGES-staging/app_stack.txt<br>2 files changed, 72 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/77/16077/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_stack.c b/apps/app_stack.c</span><br><span>index 179694b..2c896a6 100644</span><br><span>--- a/apps/app_stack.c</span><br><span>+++ b/apps/app_stack.c</span><br><span>@@ -113,6 +113,36 @@</span><br><span>                        any, is saved in the channel variable <variable>GOSUB_RETVAL</variable>.</para></span><br><span>            </description></span><br><span>                 <see-also></span><br><span style="color: hsl(120, 100%, 40%);">+                      <ref type="application">ReturnIf</ref></span><br><span style="color: hsl(120, 100%, 40%);">+                  <ref type="application">Gosub</ref></span><br><span style="color: hsl(120, 100%, 40%);">+                     <ref type="application">StackPop</ref></span><br><span style="color: hsl(120, 100%, 40%);">+          </see-also></span><br><span style="color: hsl(120, 100%, 40%);">+     </application></span><br><span style="color: hsl(120, 100%, 40%);">+  <application name="ReturnIf" language="en_US"></span><br><span style="color: hsl(120, 100%, 40%);">+              <synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+                      Conditionally return from gosub routine.</span><br><span style="color: hsl(120, 100%, 40%);">+              </synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+             <syntax argsep="?"></span><br><span style="color: hsl(120, 100%, 40%);">+                   <parameter name="expression" required="true" /></span><br><span style="color: hsl(120, 100%, 40%);">+                     <parameter name="execapp" required="true" argsep=":"></span><br><span style="color: hsl(120, 100%, 40%);">+                             <argument name="valueiftrue" required="true" hasparams="true"></span><br><span style="color: hsl(120, 100%, 40%);">+                                    <argument name="args" required="true" /></span><br><span style="color: hsl(120, 100%, 40%);">+                            </argument></span><br><span style="color: hsl(120, 100%, 40%);">+                             <argument name="valueiffalse" required="false" hasparams="true"></span><br><span style="color: hsl(120, 100%, 40%);">+                                  <argument name="args" required="true" /></span><br><span style="color: hsl(120, 100%, 40%);">+                            </argument></span><br><span style="color: hsl(120, 100%, 40%);">+                     </parameter></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>If <replaceable>expression</replaceable> is true, jumps to the last label on the stack,</span><br><span style="color: hsl(120, 100%, 40%);">+                       removing it. The return <replaceable>valueiftrue</replaceable>, if any, is saved in the channel</span><br><span style="color: hsl(120, 100%, 40%);">+                   variable <variable>GOSUB_RETVAL</variable>.</para> If <replaceable>expression</replaceable> is</span><br><span style="color: hsl(120, 100%, 40%);">+                  false, and <replaceable>valueiffalse</replaceable> is specified, jumps to the last</span><br><span style="color: hsl(120, 100%, 40%);">+                        label on the stack, removing it, and saving <replaceable>valueiffalse</replaceable></span><br><span style="color: hsl(120, 100%, 40%);">+                       in the the channel variable <variable>GOSUB_RETVAL</variable>.</span><br><span style="color: hsl(120, 100%, 40%);">+            </description></span><br><span style="color: hsl(120, 100%, 40%);">+          <see-also></span><br><span style="color: hsl(120, 100%, 40%);">+                      <ref type="application">Return</ref></span><br><span>                   <ref type="application">Gosub</ref></span><br><span>                    <ref type="application">StackPop</ref></span><br><span>                 </see-also></span><br><span>@@ -232,6 +262,7 @@</span><br><span> static const char app_gosub[] = "Gosub";</span><br><span> static const char app_gosubif[] = "GosubIf";</span><br><span> static const char app_return[] = "Return";</span><br><span style="color: hsl(120, 100%, 40%);">+static const char app_returnif[] = "ReturnIf";</span><br><span> static const char app_pop[] = "StackPop";</span><br><span> </span><br><span> static void gosub_free(void *data);</span><br><span>@@ -428,6 +459,42 @@</span><br><span>   return res;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int returnif_exec(struct ast_channel *chan, const char *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char *args;</span><br><span style="color: hsl(120, 100%, 40%);">+   int res=0;</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_DECLARE_APP_ARGS(cond,</span><br><span style="color: hsl(120, 100%, 40%);">+            AST_APP_ARG(ition);</span><br><span style="color: hsl(120, 100%, 40%);">+           AST_APP_ARG(values);</span><br><span style="color: hsl(120, 100%, 40%);">+  );</span><br><span style="color: hsl(120, 100%, 40%);">+    AST_DECLARE_APP_ARGS(value,</span><br><span style="color: hsl(120, 100%, 40%);">+           AST_APP_ARG(iftrue);</span><br><span style="color: hsl(120, 100%, 40%);">+          AST_APP_ARG(iffalse);</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 (ast_strlen_zero(data)) {</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_log(LOG_WARNING, "ReturnIf requires an argument: ReturnIf(cond?value1:value2\n");</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 style="color: hsl(120, 100%, 40%);">+   args = ast_strdupa(data);</span><br><span style="color: hsl(120, 100%, 40%);">+     AST_NONSTANDARD_RAW_ARGS(cond, args, '?');</span><br><span style="color: hsl(120, 100%, 40%);">+    if (cond.argc != 2) {</span><br><span style="color: hsl(120, 100%, 40%);">+         ast_log(LOG_WARNING, "ReturnIf requires an argument: ReturnIf(cond?value1:value2\n");</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 style="color: hsl(120, 100%, 40%);">+   AST_NONSTANDARD_RAW_ARGS(value, cond.values, ':');</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (pbx_checkcondition(cond.ition)) {</span><br><span style="color: hsl(120, 100%, 40%);">+         res = return_exec(chan, value.iftrue);</span><br><span style="color: hsl(120, 100%, 40%);">+        } else if (!ast_strlen_zero(value.iffalse)) {</span><br><span style="color: hsl(120, 100%, 40%);">+         res = return_exec(chan, value.iffalse);</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%);">+   return res;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span>  * \internal</span><br><span>  * \brief Add missing context and/or exten to Gosub application argument string.</span><br><span>@@ -1282,6 +1349,7 @@</span><br><span>  ast_agi_unregister(&gosub_agi_command);</span><br><span> </span><br><span>      ast_unregister_application(app_return);</span><br><span style="color: hsl(120, 100%, 40%);">+       ast_unregister_application(app_returnif);</span><br><span>    ast_unregister_application(app_pop);</span><br><span>         ast_unregister_application(app_gosubif);</span><br><span>     ast_unregister_application(app_gosub);</span><br><span>@@ -1304,6 +1372,7 @@</span><br><span> </span><br><span>   ast_register_application_xml(app_pop, pop_exec);</span><br><span>     ast_register_application_xml(app_return, return_exec);</span><br><span style="color: hsl(120, 100%, 40%);">+        ast_register_application_xml(app_returnif, returnif_exec);</span><br><span>   ast_register_application_xml(app_gosubif, gosubif_exec);</span><br><span>     ast_register_application_xml(app_gosub, gosub_exec);</span><br><span>         ast_custom_function_register(&local_function);</span><br><span>diff --git a/doc/CHANGES-staging/app_stack.txt b/doc/CHANGES-staging/app_stack.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..170d9af</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/app_stack.txt</span><br><span>@@ -0,0 +1,3 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: ReturnIf application</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Adds a conditional return application.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/16077">change 16077</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/+/16077"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I046b778bd98a2aa97bd58b058ee77f7504407425 </div>
<div style="display:none"> Gerrit-Change-Number: 16077 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>