When naming variables inside a <para> element you can use:<br><variable>foo</variable><br><br>+ is the same as ${foo}, since the value of
<replaceable>n</replaceable> peeks under 0 levels of<br><br><div class="gmail_quote">On Tue, Dec 2, 2008 at 4:39 PM, SVN commits to the Asterisk project <span dir="ltr"><<a href="mailto:asterisk-commits@lists.digium.com">asterisk-commits@lists.digium.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Author: tilghman<br>
Date: Tue Dec 2 12:39:12 2008<br>
New Revision: 160344<br>
<br>
URL: <a href="http://svn.digium.com/view/asterisk?view=rev&rev=160344" target="_blank">http://svn.digium.com/view/asterisk?view=rev&rev=160344</a><br>
Log:<br>
Add LOCAL_PEEK function, as requested by lmadsen.<br>
<br>
Modified:<br>
trunk/apps/app_stack.c<br>
<br>
Modified: trunk/apps/app_stack.c<br>
URL: <a href="http://svn.digium.com/view/asterisk/trunk/apps/app_stack.c?view=diff&rev=160344&r1=160343&r2=160344" target="_blank">http://svn.digium.com/view/asterisk/trunk/apps/app_stack.c?view=diff&rev=160344&r1=160343&r2=160344</a><br>
==============================================================================<br>
--- trunk/apps/app_stack.c (original)<br>
+++ trunk/apps/app_stack.c Tue Dec 2 12:39:12 2008<br>
@@ -142,6 +142,27 @@<br>
<ref type="application">Return</ref><br>
</see-also><br>
</function><br>
+ <function name="LOCAL_PEEK" language="en_US"><br>
+ <synopsis><br>
+ Retrieve variables hidden by the local gosub stack frame.<br>
+ </synopsis><br>
+ <syntax><br>
+ <parameter name="n" required="true" /><br>
+ <parameter name="varname" required="true" /><br>
+ </syntax><br>
+ <description><br>
+ <para>Read a variable <replaceable>varname</replaceable> hidden by<br>
+ <replaceable>n</replaceable> levels of gosub stack frames. Note that ${LOCAL_PEEK(0,foo)}<br>
+ is the same as ${foo}, since the value of <replaceable>n</replaceable> peeks under 0 levels of<br>
+ stack frames; in other words, 0 is the current level. If <replaceable>n</replaceable> exceeds<br>
+ the available number of stack frames, then an empty string is returned.</para><br>
+ </description><br>
+ <see-also><br>
+ <ref type="application">Gosub</ref><br>
+ <ref type="application">GosubIf</ref><br>
+ <ref type="application">Return</ref><br>
+ </see-also><br>
+ </function><br>
***/<br>
<br>
static const char *app_gosub = "Gosub";<br>
@@ -469,6 +490,42 @@<br>
.name = "LOCAL",<br>
.write = local_write,<br>
.read = local_read,<br>
+};<br>
+<br>
+static int peek_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)<br>
+{<br>
+ int found = 0, n;<br>
+ struct ast_var_t *variables;<br>
+ AST_DECLARE_APP_ARGS(args,<br>
+ AST_APP_ARG(n);<br>
+ AST_APP_ARG(name);<br>
+ );<br>
+<br>
+ if (!chan) {<br>
+ ast_log(LOG_ERROR, "LOCAL_PEEK must be called on an active channel\n");<br>
+ return -1;<br>
+ }<br>
+<br>
+ AST_STANDARD_APP_ARGS(args, data);<br>
+ n = atoi(args.n);<br>
+ *buf = '\0';<br>
+<br>
+ ast_channel_lock(chan);<br>
+ AST_LIST_TRAVERSE(&chan->varshead, variables, entries) {<br>
+ if (!strcmp(<a href="http://args.name" target="_blank">args.name</a>, ast_var_name(variables)) && ++found > n) {<br>
+ ast_copy_string(buf, ast_var_value(variables), len);<br>
+ break;<br>
+ }<br>
+ }<br>
+ ast_channel_unlock(chan);<br>
+ return 0;<br>
+}<br>
+<br>
+static struct ast_custom_function peek_function = {<br>
+ .name = "LOCAL_PEEK",<br>
+ .synopsis = "Peeks at variables within the variable stack",<br>
+ .syntax = "LOCAL_PEEK(<n>|<varname>)",<br>
+ .read = peek_read,<br>
};<br>
<br>
static int handle_gosub(struct ast_channel *chan, AGI *agi, int argc, char **argv)<br>
@@ -585,6 +642,7 @@<br>
ast_unregister_application(app_gosubif);<br>
ast_unregister_application(app_gosub);<br>
ast_custom_function_unregister(&local_function);<br>
+ ast_custom_function_unregister(&peek_function);<br>
<br>
return 0;<br>
}<br>
@@ -607,6 +665,7 @@<br>
ast_register_application_xml(app_gosubif, gosubif_exec);<br>
ast_register_application_xml(app_gosub, gosub_exec);<br>
ast_custom_function_register(&local_function);<br>
+ ast_custom_function_register(&peek_function);<br>
<br>
return 0;<br>
}<br>
<br>
<br>
_______________________________________________<br>
--Bandwidth and Colocation Provided by <a href="http://www.api-digital.com--" target="_blank">http://www.api-digital.com--</a><br>
<br>
asterisk-commits mailing list<br>
To UNSUBSCRIBE or update options visit:<br>
<a href="http://lists.digium.com/mailman/listinfo/asterisk-commits" target="_blank">http://lists.digium.com/mailman/listinfo/asterisk-commits</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Eliel Sardaņons<br>