Skip to content

Commit 27fb4fd

Browse files
InterLinked1kharwell
authored andcommitted
func_channel: Add lastcontext and lastexten.
Adds the lastcontext and lastexten channel fields to allow users to access previous dialplan execution locations. ASTERISK-29840 #close Change-Id: Ib455fe300cc8e9a127686896ee2d0bd11e900307
1 parent 3a3b8fb commit 27fb4fd

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Subject: channel_internal_api
2+
3+
CHANNEL(lastcontext) and CHANNEL(lastexten)
4+
are now available for use in the dialplan.

funcs/func_channel.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@
234234
<enum name="context">
235235
<para>R/O returns the context for an outbound channel.</para>
236236
</enum>
237+
<enum name="lastexten">
238+
<para>R/O returns the last unique extension for an outbound channel.</para>
239+
</enum>
240+
<enum name="lastcontext">
241+
<para>R/O returns the last unique context for an outbound channel.</para>
242+
</enum>
237243
<enum name="channame">
238244
<para>R/O returns the channel name for an outbound channel.</para>
239245
</enum>
@@ -410,6 +416,10 @@ static int func_channel_read(struct ast_channel *chan, const char *function,
410416
locked_copy_string(chan, buf, ast_channel_exten(chan), len);
411417
else if (!strcasecmp(data, "context"))
412418
locked_copy_string(chan, buf, ast_channel_context(chan), len);
419+
else if (!strcasecmp(data, "lastexten"))
420+
locked_copy_string(chan, buf, ast_channel_lastexten(chan), len);
421+
else if (!strcasecmp(data, "lastcontext"))
422+
locked_copy_string(chan, buf, ast_channel_lastcontext(chan), len);
413423
else if (!strcasecmp(data, "userfield"))
414424
locked_copy_string(chan, buf, ast_channel_userfield(chan), len);
415425
else if (!strcasecmp(data, "channame"))

include/asterisk/channel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4164,8 +4164,10 @@ void ast_channel_blockproc_set(struct ast_channel *chan, const char *value);
41644164
const char *ast_channel_data(const struct ast_channel *chan);
41654165
void ast_channel_data_set(struct ast_channel *chan, const char *value);
41664166

4167+
const char *ast_channel_lastcontext(const struct ast_channel *chan);
41674168
const char *ast_channel_context(const struct ast_channel *chan);
41684169
void ast_channel_context_set(struct ast_channel *chan, const char *value);
4170+
const char *ast_channel_lastexten(const struct ast_channel *chan);
41694171
const char *ast_channel_exten(const struct ast_channel *chan);
41704172
void ast_channel_exten_set(struct ast_channel *chan, const char *value);
41714173
const char *ast_channel_macrocontext(const struct ast_channel *chan);

main/channel_internal_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ struct ast_channel {
206206

207207
char context[AST_MAX_CONTEXT]; /*!< Dialplan: Current extension context */
208208
char exten[AST_MAX_EXTENSION]; /*!< Dialplan: Current extension number */
209+
char lastcontext[AST_MAX_CONTEXT]; /*!< Dialplan: Previous extension context */
210+
char lastexten[AST_MAX_EXTENSION]; /*!< Dialplan: Previous extension number */
209211
char macrocontext[AST_MAX_CONTEXT]; /*!< Macro: Current non-macro context. See app_macro.c */
210212
char macroexten[AST_MAX_EXTENSION]; /*!< Macro: Current non-macro extension. See app_macro.c */
211213
char unbridged; /*!< non-zero if the bridge core needs to re-evaluate the current
@@ -345,17 +347,33 @@ const char *ast_channel_context(const struct ast_channel *chan)
345347
{
346348
return chan->context;
347349
}
350+
const char *ast_channel_lastcontext(const struct ast_channel *chan)
351+
{
352+
return chan->lastcontext;
353+
}
348354
void ast_channel_context_set(struct ast_channel *chan, const char *value)
349355
{
356+
if (!*chan->lastcontext || strcmp(value, chan->context)) {
357+
/* only copy to last context when it changes, unless it's empty to begin with */
358+
ast_copy_string(chan->lastcontext, chan->context, sizeof(chan->lastcontext));
359+
}
350360
ast_copy_string(chan->context, value, sizeof(chan->context));
351361
ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN);
352362
}
353363
const char *ast_channel_exten(const struct ast_channel *chan)
354364
{
355365
return chan->exten;
356366
}
367+
const char *ast_channel_lastexten(const struct ast_channel *chan)
368+
{
369+
return chan->lastexten;
370+
}
357371
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
358372
{
373+
if (!*chan->lastexten || strcmp(value, chan->exten)) {
374+
/* only copy to last exten when it changes, unless it's empty to begin with */
375+
ast_copy_string(chan->lastexten, chan->exten, sizeof(chan->lastexten));
376+
}
359377
ast_copy_string(chan->exten, value, sizeof(chan->exten));
360378
ast_channel_snapshot_invalidate_segment(chan, AST_CHANNEL_SNAPSHOT_INVALIDATE_DIALPLAN);
361379
}

0 commit comments

Comments
 (0)