[asterisk-dev] [why I cannot write to ast_channel_exten(chan)]
Walter Doekes
walter+asterisk-dev at osso.nl
Thu Jan 24 02:00:48 CST 2013
On 24/01/13 07:11, Jeremy Kister wrote:
> > ast_copy_string(ast_channel_exten(chan), results,
> sizeof(ast_channel_exten(chan)) - 1);
ast_copy_string takes a non-const char, because it will be writing to it.
ast_channel_exten returns a const-string, which is by definition immutable.
If you try to write to a const, you'll get compiler warnings in the best
case and undefined mayhem in the worst.
This change was the "channel opaqification" introduced in asterisk 12.
If means you're not allowed to read/write from/to any channel internals
directly anymore.
I.e. not chan->exten, but ast_channel_exten() for reading, and probably
a writing counterpart.
Let's see:
$ grep ast_channel_exten . -r
...
ast_channel_exten_set(transferee, ast_channel_exten(chan1));
That looks like a likely candidate.
In include/asterisk/channel.h, the getters and setters are placed
conveniently right next to each other:
const char *ast_channel_context(const struct ast_channel *chan);
void ast_channel_context_set(struct ast_channel *chan, const char
*value);
const char *ast_channel_exten(const struct ast_channel *chan);
void ast_channel_exten_set(struct ast_channel *chan, const char *value);
const char *ast_channel_macrocontext(const struct ast_channel *chan);
void ast_channel_macrocontext_set(struct ast_channel *chan, const
char *value);
Cheers,
/w
More information about the asterisk-dev
mailing list