aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_chanspy.c
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-03 23:30:37 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-03 23:30:37 +0000
commitc345657f48f506680d121ac479fe46af663d2ba3 (patch)
treeb469e85436e1552e41576dfd5a3045a35456e1bc /apps/app_chanspy.c
parent96aba6e67cfa62a6b6052d74e154f02434ecf929 (diff)
Make the difference clear about what the responsibilities of the core and a spy are when it comes to spying on a channel. The core is responsible for adding a spy to a channel, feeding frames into the spy, removing the spy from the channel, and notifying the spy that is has been detached. The spy is responsible for reading frames in, and cleaning itself up. Each side will not try to do the other's job.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@41959 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_chanspy.c')
-rw-r--r--apps/app_chanspy.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c
index f433c0d1a..56052a4a4 100644
--- a/apps/app_chanspy.c
+++ b/apps/app_chanspy.c
@@ -211,21 +211,6 @@ static int start_spying(struct ast_channel *chan, struct ast_channel *spychan, s
return res;
}
-static void stop_spying(struct ast_channel_spy *spy)
-{
- /* If our status has changed to DONE, then the channel we're spying on is gone....
- DON'T TOUCH IT!!! RUN AWAY!!! */
- if (spy->status == CHANSPY_DONE)
- return;
-
- if (!spy->chan)
- return;
-
- ast_channel_lock(spy->chan);
- ast_channel_spy_remove(spy->chan, spy);
- ast_channel_unlock(spy->chan);
-};
-
/* Map 'volume' levels from -4 through +4 into
decibel (dB) settings for channel drivers
*/
@@ -327,10 +312,11 @@ static int channel_spy(struct ast_channel *chan, struct ast_channel *spyee, int
*/
while ((res = ast_waitfor(chan, -1) > -1) &&
csth.spy.status == CHANSPY_RUNNING &&
- !ast_check_hangup(chan) &&
csth.spy.chan) {
- if (!(f = ast_read(chan)))
+ if (!(f = ast_read(chan)) || ast_check_hangup(chan)) {
+ running = -1;
break;
+ }
if (ast_test_flag(flags, OPTION_WHISPER) &&
(f->frametype == AST_FRAME_VOICE)) {
@@ -381,13 +367,16 @@ static int channel_spy(struct ast_channel *chan, struct ast_channel *spyee, int
else
ast_deactivate_generator(chan);
- stop_spying(&csth.spy);
+ /* If a channel still exists on our spy structure then we need to remove ourselves */
+ if (csth.spy.chan) {
+ csth.spy.status = CHANSPY_DONE;
+ ast_channel_spy_remove(csth.spy.chan, &csth.spy);
+ }
+ ast_channel_spy_free(&csth.spy);
if (option_verbose >= 2)
ast_verbose(VERBOSE_PREFIX_2 "Done Spying on channel %s\n", name);
- ast_mutex_destroy(&csth.spy.lock);
-
return running;
}
@@ -532,6 +521,8 @@ static int common_exec(struct ast_channel *chan, const struct ast_flags *flags,
peer = NULL;
}
}
+ if (res == -1)
+ break;
}
ast_clear_flag(chan, AST_FLAG_SPYING);