diff options
author | Terry Wilson <twilson@digium.com> | 2012-01-09 22:15:50 +0000 |
---|---|---|
committer | Terry Wilson <twilson@digium.com> | 2012-01-09 22:15:50 +0000 |
commit | 04da92c3799e546fa4d84bdaeebd499fb64aea7a (patch) | |
tree | 9617b8b2d6d06f96ba27c0baefc5b93eb9e3bc5b /main/app.c | |
parent | 64d1b247c407de2af029392a6c32a99bf11c7ded (diff) |
Replace direct access to channel name with accessor functions
There are many benefits to making the ast_channel an opaque handle, from
increasing maintainability to presenting ways to kill masquerades. This patch
kicks things off by taking things a field at a time, renaming the field to
'__do_not_use_${fieldname}' and then writing setters/getters and converting the
existing code to using them. When all fields are done, we can move ast_channel
to a C file from channel.h and lop off the '__do_not_use_'.
This patch sets up main/channel_interal_api.c to be the only file that actually
accesses the ast_channel's fields directly. The intent would be for any API
functions in channel.c to use the accessor functions. No more monkeying around
with channel internals. We should use our own APIs.
The interesting changes in this patch are the addition of
channel_internal_api.c, the moving of the AST_DATA stuff from channel.c to
channel_internal_api.c (note: the AST_DATA stuff will have to be reworked to
use accessor functions when ast_channel is really opaque), and some re-working
of the way channel iterators/callbacks are handled so as to avoid creating fake
ast_channels on the stack to pass in matching data by directly accessing fields
(since "name" is a stringfield and the fake channel doesn't init the
stringfields, you can't use the ast_channel_name_set() function). I went with
ast_channel_name(chan) for a getter, and ast_channel_name_set(chan, name) for a
setter.
The majority of the grunt-work for this change was done by writing a semantic
patch using Coccinelle ( http://coccinelle.lip6.fr/ ).
Review: https://reviewboard.asterisk.org/r/1655/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@350223 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/app.c')
-rw-r--r-- | main/app.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/main/app.c b/main/app.c index 3e3cf5614..ca25964a5 100644 --- a/main/app.c +++ b/main/app.c @@ -183,7 +183,7 @@ enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *promp filename = ast_strdupa(prompt); while ((front = strsep(&filename, "&"))) { - ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", front, c->name); + ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", front, ast_channel_name(c)); if (!ast_strlen_zero(front)) { res = ast_streamfile(c, front, c->language); if (res) @@ -455,7 +455,7 @@ static void linear_release(struct ast_channel *chan, void *params) struct linear_state *ls = params; if (ls->origwfmt.id && ast_set_write_format(chan, &ls->origwfmt)) { - ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt.id); + ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", ast_channel_name(chan), ls->origwfmt.id); } if (ls->autoclose) { @@ -513,7 +513,7 @@ static void *linear_alloc(struct ast_channel *chan, void *params) ast_format_copy(&ls->origwfmt, &chan->writeformat); if (ast_set_write_format_by_id(chan, AST_FORMAT_SLINEAR)) { - ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name); + ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", ast_channel_name(chan)); ast_free(ls); ls = params = NULL; } @@ -700,7 +700,7 @@ int ast_play_and_wait(struct ast_channel *chan, const char *fn) { int d = 0; - ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", fn, chan->name); + ast_test_suite_event_notify("PLAYBACK", "Message: %s\r\nChannel: %s", fn, ast_channel_name(chan)); if ((d = ast_streamfile(chan, fn, chan->language))) { return d; } @@ -771,7 +771,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, } ast_debug(1, "play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt); - snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name); + snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, ast_channel_name(chan)); if (playfile || beep) { if (!beep) { @@ -853,7 +853,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, ast_debug(1, "One waitfor failed, trying another\n"); /* Try one more time in case of masq */ if (!(res = ast_waitfor(chan, 2000))) { - ast_log(LOG_WARNING, "No audio available on %s??\n", chan->name); + ast_log(LOG_WARNING, "No audio available on %s??\n", ast_channel_name(chan)); res = -1; } } @@ -1031,7 +1031,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, } } if (rfmt.id && ast_set_read_format(chan, &rfmt)) { - ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(&rfmt), chan->name); + ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(&rfmt), ast_channel_name(chan)); } if ((outmsg == 2) && (!skip_confirmation_sound)) { ast_stream_and_wait(chan, "auth-thankyou", ""); |