<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/18084">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_channel: Add lastcontext and lastexten.<br><br>Adds the lastcontext and lastexten channel fields to allow users<br>to access previous dialplan execution locations.<br><br>ASTERISK-29840 #close<br><br>Change-Id: Ib455fe300cc8e9a127686896ee2d0bd11e900307<br>---<br>A doc/CHANGES-staging/channel_internal_api.txt<br>M funcs/func_channel.c<br>M include/asterisk/channel.h<br>M main/channel_internal_api.c<br>4 files changed, 34 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/84/18084/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/doc/CHANGES-staging/channel_internal_api.txt b/doc/CHANGES-staging/channel_internal_api.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..f40a4c7</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/channel_internal_api.txt</span><br><span>@@ -0,0 +1,4 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: channel_internal_api</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+CHANNEL(lastcontext) and CHANNEL(lastexten)</span><br><span style="color: hsl(120, 100%, 40%);">+are now available for use in the dialplan.</span><br><span>diff --git a/funcs/func_channel.c b/funcs/func_channel.c</span><br><span>index c6e5ec1..49c4b05 100644</span><br><span>--- a/funcs/func_channel.c</span><br><span>+++ b/funcs/func_channel.c</span><br><span>@@ -234,6 +234,12 @@</span><br><span> <enum name="context"></span><br><span> <para>R/O returns the context for an outbound channel.</para></span><br><span> </enum></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="lastexten"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>R/O returns the last unique extension for an outbound channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </enum></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="lastcontext"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>R/O returns the last unique context for an outbound channel.</para></span><br><span style="color: hsl(120, 100%, 40%);">+ </enum></span><br><span> <enum name="channame"></span><br><span> <para>R/O returns the channel name for an outbound channel.</para></span><br><span> </enum></span><br><span>@@ -410,6 +416,10 @@</span><br><span> locked_copy_string(chan, buf, ast_channel_exten(chan), len);</span><br><span> else if (!strcasecmp(data, "context"))</span><br><span> locked_copy_string(chan, buf, ast_channel_context(chan), len);</span><br><span style="color: hsl(120, 100%, 40%);">+ else if (!strcasecmp(data, "lastexten"))</span><br><span style="color: hsl(120, 100%, 40%);">+ locked_copy_string(chan, buf, ast_channel_lastexten(chan), len);</span><br><span style="color: hsl(120, 100%, 40%);">+ else if (!strcasecmp(data, "lastcontext"))</span><br><span style="color: hsl(120, 100%, 40%);">+ locked_copy_string(chan, buf, ast_channel_lastcontext(chan), len);</span><br><span> else if (!strcasecmp(data, "userfield"))</span><br><span> locked_copy_string(chan, buf, ast_channel_userfield(chan), len);</span><br><span> else if (!strcasecmp(data, "channame"))</span><br><span>diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h</span><br><span>index 59d25a8..1c56d20 100644</span><br><span>--- a/include/asterisk/channel.h</span><br><span>+++ b/include/asterisk/channel.h</span><br><span>@@ -4164,8 +4164,10 @@</span><br><span> const char *ast_channel_data(const struct ast_channel *chan);</span><br><span> void ast_channel_data_set(struct ast_channel *chan, const char *value);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_channel_lastcontext(const struct ast_channel *chan);</span><br><span> const char *ast_channel_context(const struct ast_channel *chan);</span><br><span> void ast_channel_context_set(struct ast_channel *chan, const char *value);</span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_channel_lastexten(const struct ast_channel *chan);</span><br><span> const char *ast_channel_exten(const struct ast_channel *chan);</span><br><span> void ast_channel_exten_set(struct ast_channel *chan, const char *value);</span><br><span> const char *ast_channel_macrocontext(const struct ast_channel *chan);</span><br><span>diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c</span><br><span>index 9dd72ae..131faae 100644</span><br><span>--- a/main/channel_internal_api.c</span><br><span>+++ b/main/channel_internal_api.c</span><br><span>@@ -206,6 +206,8 @@</span><br><span> </span><br><span> char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */</span><br><span> char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */</span><br><span style="color: hsl(120, 100%, 40%);">+ char lastcontext[AST_MAX_CONTEXT]; /*!< Dialplan: Previous extension context */</span><br><span style="color: hsl(120, 100%, 40%);">+ char lastexten[AST_MAX_EXTENSION]; /*!< Dialplan: Previous extension number */</span><br><span> char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */</span><br><span> char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */</span><br><span> char unbridged; /*!< non-zero if the bridge core needs to re-evaluate the current</span><br><span>@@ -345,8 +347,16 @@</span><br><span> {</span><br><span> return chan->context;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_channel_lastcontext(const struct ast_channel *chan)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return chan->lastcontext;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> void ast_channel_context_set(struct ast_channel *chan, const char *value)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!*chan->lastcontext || strcmp(value, chan->context)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* only copy to last context when it changes, unless it's empty to begin with */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_string(chan->lastcontext, chan->context, sizeof(chan->lastcontext));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> ast_copy_string(chan->context, value, sizeof(chan->context));</span><br><span> ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN);</span><br><span> }</span><br><span>@@ -354,8 +364,16 @@</span><br><span> {</span><br><span> return chan->exten;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_channel_lastexten(const struct ast_channel *chan)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return chan->lastexten;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> void ast_channel_exten_set(struct ast_channel *chan, const char *value)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!*chan->lastexten || strcmp(value, chan->exten)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* only copy to last exten when it changes, unless it's empty to begin with */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_copy_string(chan->lastexten, chan->exten, sizeof(chan->lastexten));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> ast_copy_string(chan->exten, value, sizeof(chan->exten));</span><br><span> ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN);</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18084">change 18084</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/+/18084"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: Ib455fe300cc8e9a127686896ee2d0bd11e900307 </div>
<div style="display:none"> Gerrit-Change-Number: 18084 </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>