[asterisk-commits] murf: branch murf/bug_7598 r38647 - in
/team/murf/bug_7598: ./ apps/ channels...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Aug 1 09:06:04 MST 2006
Author: murf
Date: Tue Aug 1 11:06:03 2006
New Revision: 38647
URL: http://svn.digium.com/view/asterisk?rev=38647&view=rev
Log:
Merged revisions 38283,38286,38291,38311,38329-38330,38348,38368-38369,38371,38374,38389,38418,38421-38422,38439,38441,38452,38454,38464-38466,38476,38489,38502,38521,38532-38533,38548,38573,38586-38587,38612,38633 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk
................
r38283 | russell | 2006-07-26 19:29:57 -0600 (Wed, 26 Jul 2006) | 3 lines
fix some breakage of ast_cli() that resulted in seg faults on Josh's machine.
I'm not sure why this never caused problems for me ...
................
r38286 | russell | 2006-07-26 19:49:57 -0600 (Wed, 26 Jul 2006) | 3 lines
fix crashes with MALLOC_DEBUG enabled that were a result of my recent thread
storage changes (fixes issue #7595)
................
r38291 | russell | 2006-07-26 20:00:20 -0600 (Wed, 26 Jul 2006) | 11 lines
Merged revisions 38288 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38288 | russell | 2006-07-26 21:58:41 -0400 (Wed, 26 Jul 2006) | 3 lines
fix a crash when MALLOC_DEBUG is enabled and the regexten is enabled. The crash
would occur when the extension got removed. (fixes issue #7484)
........
................
r38311 | kpfleming | 2006-07-26 20:46:22 -0600 (Wed, 26 Jul 2006) | 10 lines
Merged revisions 38310 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38310 | kpfleming | 2006-07-26 21:43:49 -0500 (Wed, 26 Jul 2006) | 2 lines
don't do useless translation destroy/build when the channel is already in the correct format
........
................
r38329 | russell | 2006-07-26 22:28:09 -0600 (Wed, 26 Jul 2006) | 12 lines
Merged revisions 38328 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38328 | russell | 2006-07-27 00:25:41 -0400 (Thu, 27 Jul 2006) | 4 lines
Fix crash when using the "regexten" option with MALLOC_DEBUG enabled. This was
not reported in the bug tracker but the same bug has been demonstrated in other
places in the code.
........
................
r38330 | russell | 2006-07-26 22:44:49 -0600 (Wed, 26 Jul 2006) | 3 lines
fix seg fault when the parked call that timed out was the last one in the list
of parked calls (fixes issue #7565)
................
r38348 | kpfleming | 2006-07-27 09:42:49 -0600 (Thu, 27 Jul 2006) | 10 lines
Merged revisions 38347 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38347 | kpfleming | 2006-07-27 10:40:03 -0500 (Thu, 27 Jul 2006) | 2 lines
do a better job avoiding translation path teardown/setup when not needed
........
................
r38368 | kpfleming | 2006-07-27 16:20:52 -0600 (Thu, 27 Jul 2006) | 8 lines
various cleanups:
use API call for finding channel by name prefix
code formatting to match guidelines (lost about half the of the indenting)
remove useless automatic variable initializations
don't set the spying channel's read format to SLINEAR when we don't do anything with the voice frames we read from it anyway
use proper option argument checking for volume argument
................
r38369 | kpfleming | 2006-07-27 16:21:46 -0600 (Thu, 27 Jul 2006) | 2 lines
restore infinite timeout for ast_waitfor() call
................
r38371 | kpfleming | 2006-07-27 16:24:19 -0600 (Thu, 27 Jul 2006) | 2 lines
block this patch from 1.2, it's already fixed here as part of a larger commit
................
r38374 | kpfleming | 2006-07-27 17:00:27 -0600 (Thu, 27 Jul 2006) | 3 lines
remove local channel finding wrappers
move guts of dialplan application into separate function, so it can be shared bythe new application i'm about to add :-)
................
r38389 | kpfleming | 2006-07-27 17:16:08 -0600 (Thu, 27 Jul 2006) | 4 lines
more simplification, and correct a bug i introduced in the last commit
fix prototype for a channel walking function to use a const input pointer
use existing channel walk by name prefix instead of reproducing that code in this app
................
r38418 | kpfleming | 2006-07-28 12:03:57 -0600 (Fri, 28 Jul 2006) | 4 lines
more slinfactory structure definition to inside implementation module
make read/write/hold work on samples, not bytes
add an API call to find out how many samples are available in a slinfactory
................
r38421 | file | 2006-07-28 12:53:43 -0600 (Fri, 28 Jul 2006) | 10 lines
Merged revisions 38420 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38420 | file | 2006-07-28 14:49:00 -0400 (Fri, 28 Jul 2006) | 2 lines
Make a copy of the request URI in check_user_full instead of modifying the one on the structure, and also strip params properly from the user portion of the SIP URI so as to preserve the domain (issue #7552 reported by dan42)
........
................
r38422 | kpfleming | 2006-07-28 12:59:59 -0600 (Fri, 28 Jul 2006) | 3 lines
move slinfactory structure definition back to header... it's just easier to use this way
add infrastructure for whispering onto a channel
................
r38439 | russell | 2006-07-28 13:17:56 -0600 (Fri, 28 Jul 2006) | 8 lines
As discussed and decided on the asterisk-dev mailing list ...
- Fix some breakage I introduced a while ago that made the timestamps option
not functional for CLI verbose output.
- Remove the use of the timestamps option for log output, since it was not
functional.
- clarify text referring to the timestamps option so that it is clear that it
only applies to CLI verbose output
................
r38441 | kpfleming | 2006-07-28 13:58:53 -0600 (Fri, 28 Jul 2006) | 2 lines
just for fun, let's lock the whisper buffer for writing AND reading :-)
................
r38452 | russell | 2006-07-28 16:14:49 -0600 (Fri, 28 Jul 2006) | 14 lines
Add the function attribute "pure" or "const" to various functions that perform
int to string or string to int operations.
"pure" essentially says that this function has no side effects aside from its
result, and the result depends on nothing else other than its arguments and
global variables. "const" is a more strict form of "pure", where the function
also doesn't access any global variables.
>From the gcc manual: "Such a function can be subject to common subexpression
elimination and loop optimization just as an arithmetic operator would be."
This also tells the compiler that it is safe to call the function fewer times
than the code says to, given the same arguments, since the result will always
be the same.
................
r38454 | russell | 2006-07-28 16:50:54 -0600 (Fri, 28 Jul 2006) | 3 lines
add macros for the pure and const attributes to compiler.h, in case they ever
need to be handled differently for a specific compiler
................
r38464 | russell | 2006-07-28 17:30:18 -0600 (Fri, 28 Jul 2006) | 4 lines
the pure attribute was not implemented before gcc 2.96. Since we have this
version check here anwyay, define attribute_pure to be empty if it's an earlier
version.
................
r38465 | kpfleming | 2006-07-28 17:36:06 -0600 (Fri, 28 Jul 2006) | 4 lines
add ExtenSpy variant of ChanSpy
implement whisper mode for ExtenSpy/ChanSpy
................
r38466 | kpfleming | 2006-07-28 17:47:05 -0600 (Fri, 28 Jul 2006) | 2 lines
play a beep tone into the spied-on channel if we are about to whisper to them
................
r38476 | kpfleming | 2006-07-28 18:19:18 -0600 (Fri, 28 Jul 2006) | 2 lines
update cleancount because the channel structure changed today
................
r38489 | markster | 2006-07-29 16:02:37 -0600 (Sat, 29 Jul 2006) | 3 lines
Allow updates to match specific lines, allow specification of object or
no when appending.
................
r38502 | file | 2006-07-29 17:19:36 -0600 (Sat, 29 Jul 2006) | 9 lines
Blocked revisions 38501 via svnmerge
........
r38501 | file | 2006-07-29 19:18:00 -0400 (Sat, 29 Jul 2006) | 2 lines
How many attempts does it take to make a SIP URI parser that works well? I'm up to 5 personally. On to the good stuff - parse the domain first, user second, and get rid of port & options/params last. (issue #7616 reported by andrew)
........
................
r38521 | tilghman | 2006-07-30 09:02:34 -0600 (Sun, 30 Jul 2006) | 3 lines
Add details about flash and wait to doxygen about DTMF.
Reformat the lines to break at column 80.
................
r38532 | russell | 2006-07-30 17:11:07 -0600 (Sun, 30 Jul 2006) | 2 lines
allow the gtk console to build and load
................
r38533 | russell | 2006-07-30 17:16:23 -0600 (Sun, 30 Jul 2006) | 2 lines
suppress some compiler warnings ...
................
r38548 | russell | 2006-07-30 22:10:43 -0600 (Sun, 30 Jul 2006) | 15 lines
Merged revisions 38546-38547 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38546 | russell | 2006-07-31 00:04:02 -0400 (Mon, 31 Jul 2006) | 2 lines
Make the frame counting done with TRACE_FRAMES defined thread-safe
........
r38547 | russell | 2006-07-31 00:06:16 -0400 (Mon, 31 Jul 2006) | 2 lines
one more small tweak for thread-safety of TRACE_FRAMES
........
................
r38573 | file | 2006-07-31 09:24:05 -0600 (Mon, 31 Jul 2006) | 2 lines
Poking at a structure when it may not even be allocated is not healthy. Essentially make sure an RTCP structure exists before trying to delete it's scheduled item. (issue #7514 reported by jmls fixed by AuPix)
................
r38586 | file | 2006-07-31 11:11:51 -0600 (Mon, 31 Jul 2006) | 9 lines
Blocked revisions 38585 via svnmerge
........
r38585 | file | 2006-07-31 13:09:10 -0400 (Mon, 31 Jul 2006) | 2 lines
Add missing code to bring transferee channel out of MOH/autoservice under certain circumstance (issue #7611 reported by guillecabeza with minor mods by myself)
........
................
r38587 | russell | 2006-07-31 11:27:42 -0600 (Mon, 31 Jul 2006) | 2 lines
make the counting of ingress, outgress, and total frames thread-safe
................
r38612 | kpfleming | 2006-07-31 15:31:44 -0600 (Mon, 31 Jul 2006) | 12 lines
Merged revisions 38611 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r38611 | kpfleming | 2006-07-31 16:14:11 -0500 (Mon, 31 Jul 2006) | 4 lines
don't reissue hangup requests for SIP channels that have expired their RTP timeouts (one time is enough)
don't rescan the SIP private structure list too fast, it can cause channels to not be able to hang up (issue #7495, and probably others)
use ast_softhangup_nolock() since we already hold the channel's lock
........
................
r38633 | tilghman | 2006-08-01 07:15:15 -0600 (Tue, 01 Aug 2006) | 2 lines
Set permissions completely open and modify by umask
................
Modified:
team/murf/bug_7598/ (props changed)
team/murf/bug_7598/.cleancount
team/murf/bug_7598/apps/app_chanspy.c
team/murf/bug_7598/apps/app_voicemail.c
team/murf/bug_7598/asterisk.c
team/murf/bug_7598/channel.c
team/murf/bug_7598/channels/chan_iax2.c
team/murf/bug_7598/channels/chan_sip.c
team/murf/bug_7598/channels/iax2-parser.c
team/murf/bug_7598/cli.c
team/murf/bug_7598/config.c
team/murf/bug_7598/doc/asterisk-conf.txt
team/murf/bug_7598/frame.c
team/murf/bug_7598/include/asterisk/app.h
team/murf/bug_7598/include/asterisk/channel.h
team/murf/bug_7598/include/asterisk/compiler.h
team/murf/bug_7598/include/asterisk/config.h
team/murf/bug_7598/include/asterisk/frame.h
team/murf/bug_7598/include/asterisk/options.h
team/murf/bug_7598/include/asterisk/slinfactory.h
team/murf/bug_7598/logger.c
team/murf/bug_7598/manager.c
team/murf/bug_7598/pbx/pbx_gtkconsole.c
team/murf/bug_7598/res/res_features.c
team/murf/bug_7598/rtp.c
team/murf/bug_7598/slinfactory.c
team/murf/bug_7598/utils.c
Propchange: team/murf/bug_7598/
------------------------------------------------------------------------------
Binary property 'branch-1.2-blocked' - no diff available.
Propchange: team/murf/bug_7598/
------------------------------------------------------------------------------
Binary property 'branch-1.2-merged' - no diff available.
Propchange: team/murf/bug_7598/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Aug 1 11:06:03 2006
@@ -1,1 +1,1 @@
-/trunk:1-38278
+/trunk:1-38645
Modified: team/murf/bug_7598/.cleancount
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7598/.cleancount?rev=38647&r1=38646&r2=38647&view=diff
==============================================================================
--- team/murf/bug_7598/.cleancount (original)
+++ team/murf/bug_7598/.cleancount Tue Aug 1 11:06:03 2006
@@ -1,1 +1,1 @@
-19
+20
Modified: team/murf/bug_7598/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7598/apps/app_chanspy.c?rev=38647&r1=38646&r2=38647&view=diff
==============================================================================
--- team/murf/bug_7598/apps/app_chanspy.c (original)
+++ team/murf/bug_7598/apps/app_chanspy.c Tue Aug 1 11:06:03 2006
@@ -51,46 +51,76 @@
#include "asterisk/module.h"
#include "asterisk/lock.h"
-AST_MUTEX_DEFINE_STATIC(modlock);
-
#define AST_NAME_STRLEN 256
-#define ALL_DONE(u, ret) LOCAL_USER_REMOVE(u); return ret;
-#define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0
-
-static const char *tdesc = "Listen to the audio of an active channel";
-static const char *app = "ChanSpy";
-static const char *desc =
+
+static const char *tdesc = "Listen to a channel, and optionally whisper into it";
+static const char *app_chan = "ChanSpy";
+static const char *desc_chan =
" ChanSpy([chanprefix][|options]): This application is used to listen to the\n"
-"audio from an active Asterisk channel. This includes the audio coming in and\n"
+"audio from an Asterisk channel. This includes the audio coming in and\n"
"out of the channel being spied on. If the 'chanprefix' parameter is specified,\n"
"only channels beginning with this string will be spied upon.\n"
-" While Spying, the following actions may be performed:\n"
+" While spying, the following actions may be performed:\n"
" - Dialing # cycles the volume level.\n"
" - Dialing * will stop spying and look for another channel to spy on.\n"
" - Dialing a series of digits followed by # builds a channel name to append\n"
" to 'chanprefix'. For example, executing ChanSpy(Agent) and then dialing\n"
-" the digits '1234#' while spying will begin spying on the channel,\n"
+" the digits '1234#' while spying will begin spying on the channel\n"
" 'Agent/1234'.\n"
" Options:\n"
-" b - Only spy on channels involved in a bridged call.\n"
-" g(grp) - Match only channels where their ${SPYGROUP} variable is set to\n"
-" contain 'grp' in an optional : delimited list.\n"
-" q - Don't play a beep when beginning to spy on a channel.\n"
+" b - Only spy on channels involved in a bridged call.\n"
+" g(grp) - Match only channels where their ${SPYGROUP} variable is set to\n"
+" contain 'grp' in an optional : delimited list.\n"
+" q - Don't play a beep when beginning to spy on a channel, or speak the\n"
+" selected channel name.\n"
" r[(basename)] - Record the session to the monitor spool directory. An\n"
" optional base for the filename may be specified. The\n"
" default is 'chanspy'.\n"
-" v([value]) - Adjust the initial volume in the range from -4 to 4. A\n"
-" negative value refers to a quieter setting.\n"
+" v([value]) - Adjust the initial volume in the range from -4 to 4. A\n"
+" negative value refers to a quieter setting.\n"
+" w - Enable 'whisper' mode, so the spying channel can talk to\n"
+" the spied-on channel.\n"
+" W - Enable 'private whisper' mode, so the spying channel can\n"
+" talk to the spied-on channel but cannot listen to that\n"
+" channel.\n"
;
-static const char *chanspy_spy_type = "ChanSpy";
+static const char *app_ext = "ExtenSpy";
+static const char *desc_ext =
+" ExtenSpy(exten[@context][|options]): This application is used to listen to the\n"
+"audio from an Asterisk channel. This includes the audio coming in and\n"
+"out of the channel being spied on. Only channels created by outgoing calls for the\n"
+"specified extension will be selected for spying. If the optional context is not\n"
+"supplied, the current channel's context will be used.\n"
+" While spying, the following actions may be performed:\n"
+" - Dialing # cycles the volume level.\n"
+" - Dialing * will stop spying and look for another channel to spy on.\n"
+" Options:\n"
+" b - Only spy on channels involved in a bridged call.\n"
+" g(grp) - Match only channels where their ${SPYGROUP} variable is set to\n"
+" contain 'grp' in an optional : delimited list.\n"
+" q - Don't play a beep when beginning to spy on a channel, or speak the\n"
+" selected channel name.\n"
+" r[(basename)] - Record the session to the monitor spool directory. An\n"
+" optional base for the filename may be specified. The\n"
+" default is 'chanspy'.\n"
+" v([value]) - Adjust the initial volume in the range from -4 to 4. A\n"
+" negative value refers to a quieter setting.\n"
+" w - Enable 'whisper' mode, so the spying channel can talk to\n"
+" the spied-on channel.\n"
+" W - Enable 'private whisper' mode, so the spying channel can\n"
+" talk to the spied-on channel but cannot listen to that\n"
+" channel.\n"
+;
enum {
OPTION_QUIET = (1 << 0), /* Quiet, no announcement */
OPTION_BRIDGED = (1 << 1), /* Only look at bridged calls */
OPTION_VOLUME = (1 << 2), /* Specify initial volume */
OPTION_GROUP = (1 << 3), /* Only look at channels in group */
- OPTION_RECORD = (1 << 4), /* Record */
+ OPTION_RECORD = (1 << 4),
+ OPTION_WHISPER = (1 << 5),
+ OPTION_PRIVATE = (1 << 6), /* Private Whisper mode */
} chanspy_opt_flags;
enum {
@@ -100,9 +130,11 @@
OPT_ARG_ARRAY_SIZE,
} chanspy_opt_args;
-AST_APP_OPTIONS(chanspy_opts, {
+AST_APP_OPTIONS(spy_opts, {
AST_APP_OPTION('q', OPTION_QUIET),
AST_APP_OPTION('b', OPTION_BRIDGED),
+ AST_APP_OPTION('w', OPTION_WHISPER),
+ AST_APP_OPTION('W', OPTION_PRIVATE),
AST_APP_OPTION_ARG('v', OPTION_VOLUME, OPT_ARG_VOLUME),
AST_APP_OPTION_ARG('g', OPTION_GROUP, OPT_ARG_GROUP),
AST_APP_OPTION_ARG('r', OPTION_RECORD, OPT_ARG_RECORD),
@@ -116,34 +148,6 @@
int fd;
int volfactor;
};
-
-static struct ast_channel *local_channel_walk(struct ast_channel *chan)
-{
- struct ast_channel *ret;
- ast_mutex_lock(&modlock);
- if ((ret = ast_channel_walk_locked(chan))) {
- ast_mutex_unlock(&ret->lock);
- }
- ast_mutex_unlock(&modlock);
- return ret;
-}
-
-static struct ast_channel *local_get_channel_begin_name(char *name)
-{
- struct ast_channel *chan, *ret = NULL;
- ast_mutex_lock(&modlock);
- chan = local_channel_walk(NULL);
- while (chan) {
- if (!strncmp(chan->name, name, strlen(name))) {
- ret = chan;
- break;
- }
- chan = local_channel_walk(chan);
- }
- ast_mutex_unlock(&modlock);
-
- return ret;
-}
static void *spy_alloc(struct ast_channel *chan, void *data)
{
@@ -185,7 +189,6 @@
return 0;
}
-
static struct ast_generator spygen = {
.alloc = spy_alloc,
.release = spy_release,
@@ -203,26 +206,25 @@
res = ast_channel_spy_add(chan, spy);
ast_channel_unlock(chan);
- if (!res && ast_test_flag(chan, AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan))) {
+ if (!res && ast_test_flag(chan, AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan)))
ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);
- }
return res;
}
-static void stop_spying(struct ast_channel *chan, struct ast_channel_spy *spy)
+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 (!chan)
+ if (!spy->chan)
return;
- ast_channel_lock(chan);
- ast_channel_spy_remove(chan, spy);
- ast_channel_unlock(chan);
+ 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
@@ -250,332 +252,463 @@
if (!ast_channel_setoption(chan, AST_OPTION_TXGAIN, &volume_adjust, sizeof(volume_adjust), 0))
csth->volfactor = 0;
-}
-
-static int channel_spy(struct ast_channel *chan, struct ast_channel *spyee, int *volfactor, int fd)
+ csth->spy.read_vol_adjustment = csth->volfactor;
+ csth->spy.write_vol_adjustment = csth->volfactor;
+}
+
+static int channel_spy(struct ast_channel *chan, struct ast_channel *spyee, int *volfactor, int fd,
+ const struct ast_flags *flags)
{
struct chanspy_translation_helper csth;
- int running, res = 0, x = 0;
- char inp[24];
- char *name=NULL;
+ int running, res, x = 0;
+ char inp[24] = {0};
+ char *name;
struct ast_frame *f;
-
- running = (chan && !ast_check_hangup(chan) && spyee && !ast_check_hangup(spyee));
-
- if (running) {
- memset(inp, 0, sizeof(inp));
- name = ast_strdupa(spyee->name);
- if (option_verbose >= 2)
- ast_verbose(VERBOSE_PREFIX_2 "Spying on channel %s\n", name);
-
- memset(&csth, 0, sizeof(csth));
- ast_set_flag(&csth.spy, CHANSPY_FORMAT_AUDIO);
- ast_set_flag(&csth.spy, CHANSPY_TRIGGER_NONE);
- ast_set_flag(&csth.spy, CHANSPY_MIXAUDIO);
- csth.spy.type = chanspy_spy_type;
- csth.spy.status = CHANSPY_RUNNING;
- csth.spy.read_queue.format = AST_FORMAT_SLINEAR;
- csth.spy.write_queue.format = AST_FORMAT_SLINEAR;
- ast_mutex_init(&csth.spy.lock);
- csth.volfactor = *volfactor;
- set_volume(chan, &csth);
- csth.spy.read_vol_adjustment = csth.volfactor;
- csth.spy.write_vol_adjustment = csth.volfactor;
- csth.fd = fd;
-
- if (start_spying(spyee, chan, &csth.spy))
+ struct ast_silence_generator *silgen = NULL;
+
+ if (ast_check_hangup(chan) || ast_check_hangup(spyee))
+ return 0;
+
+ name = ast_strdupa(spyee->name);
+ if (option_verbose >= 2)
+ ast_verbose(VERBOSE_PREFIX_2 "Spying on channel %s\n", name);
+
+ memset(&csth, 0, sizeof(csth));
+ ast_set_flag(&csth.spy, CHANSPY_FORMAT_AUDIO);
+ ast_set_flag(&csth.spy, CHANSPY_TRIGGER_NONE);
+ ast_set_flag(&csth.spy, CHANSPY_MIXAUDIO);
+ csth.spy.type = "ChanSpy";
+ csth.spy.status = CHANSPY_RUNNING;
+ csth.spy.read_queue.format = AST_FORMAT_SLINEAR;
+ csth.spy.write_queue.format = AST_FORMAT_SLINEAR;
+ ast_mutex_init(&csth.spy.lock);
+ csth.volfactor = *volfactor;
+ set_volume(chan, &csth);
+ csth.fd = fd;
+
+ if (start_spying(spyee, chan, &csth.spy)) {
+ ast_mutex_destroy(&csth.spy.lock);
+ return 0;
+ }
+
+ if (ast_test_flag(flags, OPTION_WHISPER)) {
+ struct ast_filestream *beepstream;
+
+ ast_channel_whisper_start(csth.spy.chan);
+ if ((beepstream = ast_openstream_full(chan, "beep", chan->language, 1))) {
+ struct ast_frame *f;
+
+ while ((f = ast_readframe(beepstream))) {
+ ast_channel_whisper_feed(csth.spy.chan, f);
+ ast_frfree(f);
+ }
+
+ ast_closestream(beepstream);
+ }
+ }
+
+ if (ast_test_flag(flags, OPTION_PRIVATE))
+ silgen = ast_channel_start_silence_generator(chan);
+ else
+ ast_activate_generator(chan, &spygen, &csth);
+
+ /* We can no longer rely on 'spyee' being an actual channel;
+ it can be hung up and freed out from under us. However, the
+ channel destructor will put NULL into our csth.spy.chan
+ field when that happens, so that is our signal that the spyee
+ channel has gone away.
+ */
+
+ /* Note: it is very important that the ast_waitfor() be the first
+ condition in this expression, so that if we wait for some period
+ of time before receiving a frame from our spying channel, we check
+ for hangup on the spied-on channel _after_ knowing that a frame
+ has arrived, since the spied-on channel could have gone away while
+ we were waiting
+ */
+ while ((res = ast_waitfor(chan, -1) > -1) &&
+ csth.spy.status == CHANSPY_RUNNING &&
+ !ast_check_hangup(chan) &&
+ csth.spy.chan) {
+ if (!(f = ast_read(chan)))
+ break;
+
+ if (ast_test_flag(flags, OPTION_WHISPER) &&
+ (f->frametype == AST_FRAME_VOICE)) {
+ ast_channel_whisper_feed(csth.spy.chan, f);
+ ast_frfree(f);
+ continue;
+ }
+
+ res = (f->frametype == AST_FRAME_DTMF) ? f->subclass : 0;
+ ast_frfree(f);
+ if (!res)
+ continue;
+
+ if (x == sizeof(inp))
+ x = 0;
+
+ if (res < 0) {
+ running = -1;
+ break;
+ }
+
+ if (res == '*') {
running = 0;
- }
-
- if (running) {
- running = 1;
- ast_activate_generator(chan, &spygen, &csth);
-
- while (csth.spy.status == CHANSPY_RUNNING &&
- chan && !ast_check_hangup(chan) &&
- spyee &&
- !ast_check_hangup(spyee) &&
- running == 1 &&
- (res = ast_waitfor(chan, -1) > -1)) {
- if ((f = ast_read(chan))) {
- res = 0;
- if (f->frametype == AST_FRAME_DTMF) {
- res = f->subclass;
- }
- ast_frfree(f);
- if (!res) {
- continue;
- }
- } else {
+ break;
+ } else if (res == '#') {
+ if (!ast_strlen_zero(inp)) {
+ running = atoi(inp);
break;
}
- if (x == sizeof(inp)) {
- x = 0;
+
+ (*volfactor)++;
+ if (*volfactor > 4)
+ *volfactor = -4;
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "Setting spy volume on %s to %d\n", chan->name, *volfactor);
+ csth.volfactor = *volfactor;
+ set_volume(chan, &csth);
+ } else if (res >= '0' && res <= '9') {
+ inp[x++] = res;
+ }
+ }
+
+ if (ast_test_flag(flags, OPTION_WHISPER) && csth.spy.chan)
+ ast_channel_whisper_stop(csth.spy.chan);
+
+ if (ast_test_flag(flags, OPTION_PRIVATE))
+ ast_channel_stop_silence_generator(chan, silgen);
+ else
+ ast_deactivate_generator(chan);
+
+ stop_spying(&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;
+}
+
+static struct ast_channel *next_channel(const struct ast_channel *last, const char *spec,
+ const char *exten, const char *context)
+{
+ struct ast_channel *this;
+
+ if (spec)
+ this = ast_walk_channel_by_name_prefix_locked(last, spec, strlen(spec));
+ else if (exten)
+ this = ast_walk_channel_by_exten_locked(last, exten, context);
+ else
+ this = ast_channel_walk_locked(last);
+
+ if (this)
+ ast_channel_unlock(this);
+
+ return this;
+}
+
+static int common_exec(struct ast_channel *chan, const struct ast_flags *flags,
+ int volfactor, const int fd, const char *mygroup, const char *spec,
+ const char *exten, const char *context)
+{
+ struct ast_channel *peer, *prev, *next;
+ char nameprefix[AST_NAME_STRLEN];
+ char peer_name[AST_NAME_STRLEN + 5];
+ signed char zero_volume = 0;
+ int waitms;
+ int res;
+ char *ptr;
+ int num;
+
+ if (chan->_state != AST_STATE_UP)
+ ast_answer(chan);
+
+ ast_set_flag(chan, AST_FLAG_SPYING); /* so nobody can spy on us while we are spying */
+
+ waitms = 100;
+
+ for (;;) {
+ if (!ast_test_flag(flags, OPTION_QUIET)) {
+ res = ast_streamfile(chan, "beep", chan->language);
+ if (!res)
+ res = ast_waitstream(chan, "");
+ else if (res < 0) {
+ ast_clear_flag(chan, AST_FLAG_SPYING);
+ break;
}
- if (res < 0) {
- running = -1;
+ }
+
+ res = ast_waitfordigit(chan, waitms);
+ if (res < 0) {
+ ast_clear_flag(chan, AST_FLAG_SPYING);
+ break;
+ }
+
+ /* reset for the next loop around, unless overridden later */
+ waitms = 100;
+ peer = prev = next = NULL;
+
+ for (peer = next_channel(peer, spec, exten, context);
+ peer;
+ prev = peer, peer = next ? next : next_channel(peer, spec, exten, context), next = NULL) {
+ const char *group;
+ int igrp = !mygroup;
+ char *groups[25];
+ int num_groups = 0;
+ char *dup_group;
+ int x;
+ char *s;
+
+ if (peer == prev)
+ break;
+
+ if (peer == chan)
+ continue;
+
+ if (ast_test_flag(flags, OPTION_BRIDGED) && !ast_bridged_channel(peer))
+ continue;
+
+ if (ast_check_hangup(peer) || ast_test_flag(peer, AST_FLAG_SPYING))
+ continue;
+
+ if (mygroup) {
+ if ((group = pbx_builtin_getvar_helper(peer, "SPYGROUP"))) {
+ dup_group = ast_strdupa(group);
+ num_groups = ast_app_separate_args(dup_group, ':', groups,
+ sizeof(groups) / sizeof(groups[0]));
+ }
+
+ for (x = 0; x < num_groups; x++) {
+ if (!strcmp(mygroup, groups[x])) {
+ igrp = 1;
+ break;
+ }
+ }
}
- if (res == 0) {
+
+ if (!igrp)
continue;
- } else if (res == '*') {
- running = 0;
- } else if (res == '#') {
- if (!ast_strlen_zero(inp)) {
- running = x ? atoi(inp) : -1;
- break;
+
+ strcpy(peer_name, "spy-");
+ strncat(peer_name, peer->name, AST_NAME_STRLEN);
+ ptr = strchr(peer_name, '/');
+ *ptr++ = '\0';
+
+ for (s = peer_name; s < ptr; s++)
+ *s = tolower(*s);
+
+ if (!ast_test_flag(flags, OPTION_QUIET)) {
+ if (ast_fileexists(peer_name, NULL, NULL) != -1) {
+ res = ast_streamfile(chan, peer_name, chan->language);
+ if (!res)
+ res = ast_waitstream(chan, "");
+ if (res)
+ break;
+ } else
+ res = ast_say_character_str(chan, peer_name, "", chan->language);
+ if ((num = atoi(ptr)))
+ ast_say_digits(chan, atoi(ptr), "", chan->language);
+ }
+
+ waitms = 5000;
+ res = channel_spy(chan, peer, &volfactor, fd, flags);
+
+ if (res == -1) {
+ break;
+ } else if (res > 1 && spec) {
+ snprintf(nameprefix, AST_NAME_STRLEN, "%s/%d", spec, res);
+ if ((next = ast_get_channel_by_name_prefix_locked(nameprefix, strlen(nameprefix)))) {
+ ast_channel_unlock(next);
} else {
- (*volfactor)++;
- if (*volfactor > 4) {
- *volfactor = -4;
- }
- if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "Setting spy volume on %s to %d\n", chan->name, *volfactor);
- }
- csth.volfactor = *volfactor;
- set_volume(chan, &csth);
- csth.spy.read_vol_adjustment = csth.volfactor;
- csth.spy.write_vol_adjustment = csth.volfactor;
+ /* stay on this channel */
+ next = peer;
}
- } else if (res >= 48 && res <= 57) {
- inp[x++] = res;
+ peer = NULL;
}
}
- ast_deactivate_generator(chan);
- stop_spying(spyee, &csth.spy);
-
- if (option_verbose >= 2) {
- ast_verbose(VERBOSE_PREFIX_2 "Done Spying on channel %s\n", name);
- }
- } else {
- running = 0;
- }
-
- ast_mutex_destroy(&csth.spy.lock);
-
- return running;
+ }
+
+ ast_clear_flag(chan, AST_FLAG_SPYING);
+
+ ast_channel_setoption(chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);
+
+ return res;
}
static int chanspy_exec(struct ast_channel *chan, void *data)
{
struct localuser *u;
- struct ast_channel *peer=NULL, *prev=NULL;
- char name[AST_NAME_STRLEN],
- peer_name[AST_NAME_STRLEN + 5],
- *args,
- *ptr = NULL,
- *options = NULL,
- *spec = NULL,
- *argv[5],
- *mygroup = NULL,
- *recbase = NULL;
- int res = -1,
- volfactor = 0,
- silent = 0,
- argc = 0,
- bronly = 0,
- chosen = 0,
- count=0,
- waitms = 100,
- num = 0,
- oldrf = 0,
- oldwf = 0,
- fd = 0;
+ char *options = NULL;
+ char *spec = NULL;
+ char *argv[2];
+ char *mygroup = NULL;
+ char *recbase = NULL;
+ int fd = 0;
struct ast_flags flags;
- signed char zero_volume = 0;
-
- if (!(args = ast_strdupa(data)))
- return -1;
+ int oldwf = 0;
+ int argc = 0;
+ int volfactor = 0;
+ int res;
+
+ data = ast_strdupa(data);
LOCAL_USER_ADD(u);
- oldrf = chan->readformat;
+ if ((argc = ast_app_separate_args(data, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
+ spec = argv[0];
+ if (argc > 1)
+ options = argv[1];
+
+ if (ast_strlen_zero(spec) || !strcmp(spec, "all"))
+ spec = NULL;
+ }
+
+ if (options) {
+ char *opts[OPT_ARG_ARRAY_SIZE];
+
+ ast_app_parse_options(spy_opts, &flags, opts, options);
+ if (ast_test_flag(&flags, OPTION_GROUP))
+ mygroup = opts[OPT_ARG_GROUP];
+
+ if (ast_test_flag(&flags, OPTION_RECORD) &&
+ !(recbase = opts[OPT_ARG_RECORD]))
+ recbase = "chanspy";
+
+ if (ast_test_flag(&flags, OPTION_VOLUME) && opts[OPT_ARG_VOLUME]) {
+ int vol;
+
+ if ((sscanf(opts[OPT_ARG_VOLUME], "%d", &vol) != 1) || (vol > 4) || (vol < -4))
+ ast_log(LOG_NOTICE, "Volume factor must be a number between -4 and 4\n");
+ else
+ volfactor = vol;
+ }
+
+ if (ast_test_flag(&flags, OPTION_PRIVATE))
+ ast_set_flag(&flags, OPTION_WHISPER);
+ }
+
oldwf = chan->writeformat;
- if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
- ast_log(LOG_ERROR, "Could Not Set Read Format.\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
LOCAL_USER_REMOVE(u);
return -1;
}
- ast_answer(chan);
-
- ast_set_flag(chan, AST_FLAG_SPYING); /* so nobody can spy on us while we are spying */
-
- if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
- spec = argv[0];
- if ( argc > 1) {
+ if (recbase) {
+ char filename[512];
+
+ snprintf(filename, sizeof(filename), "%s/%s.%d.raw", ast_config_AST_MONITOR_DIR, recbase, (int) time(NULL));
+ if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644)) <= 0) {
+ ast_log(LOG_WARNING, "Cannot open '%s' for recording\n", filename);
+ fd = 0;
+ }
+ }
+
+ res = common_exec(chan, &flags, volfactor, fd, mygroup, spec, NULL, NULL);
+
+ if (fd)
+ close(fd);
+
+ if (oldwf && ast_set_write_format(chan, oldwf) < 0)
+ ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+
+ LOCAL_USER_REMOVE(u);
+
+ return res;
+}
+
+static int extenspy_exec(struct ast_channel *chan, void *data)
+{
+ struct localuser *u;
+ char *options = NULL;
+ char *exten = NULL;
+ char *context = NULL;
+ char *argv[2];
+ char *mygroup = NULL;
+ char *recbase = NULL;
+ int fd = 0;
+ struct ast_flags flags;
+ int oldwf = 0;
+ int argc = 0;
+ int volfactor = 0;
+ int res;
+
+ data = ast_strdupa(data);
+
+ LOCAL_USER_ADD(u);
+
+ if ((argc = ast_app_separate_args(data, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
+ context = argv[0];
+ exten = strsep(&context, "@");
+ if (ast_strlen_zero(context))
+ context = ast_strdupa(chan->context);
+ if (argc > 1)
options = argv[1];
- }
- if (ast_strlen_zero(spec) || !strcmp(spec, "all")) {
- spec = NULL;
- }
}
if (options) {
char *opts[OPT_ARG_ARRAY_SIZE];
- ast_app_parse_options(chanspy_opts, &flags, opts, options);
- if (ast_test_flag(&flags, OPTION_GROUP)) {
- mygroup = opts[1];
- }
- if (ast_test_flag(&flags, OPTION_RECORD)) {
- if (!(recbase = opts[2])) {
- recbase = "chanspy";
- }
- }
- silent = ast_test_flag(&flags, OPTION_QUIET);
- bronly = ast_test_flag(&flags, OPTION_BRIDGED);
- if (ast_test_flag(&flags, OPTION_VOLUME) && opts[1]) {
+
+ ast_app_parse_options(spy_opts, &flags, opts, options);
+ if (ast_test_flag(&flags, OPTION_GROUP))
+ mygroup = opts[OPT_ARG_GROUP];
+
+ if (ast_test_flag(&flags, OPTION_RECORD) &&
+ !(recbase = opts[OPT_ARG_RECORD]))
+ recbase = "chanspy";
+
+ if (ast_test_flag(&flags, OPTION_VOLUME) && opts[OPT_ARG_VOLUME]) {
int vol;
- if ((sscanf(opts[0], "%d", &vol) != 1) || (vol > 4) || (vol < -4))
+ if ((sscanf(opts[OPT_ARG_VOLUME], "%d", &vol) != 1) || (vol > 4) || (vol < -4))
ast_log(LOG_NOTICE, "Volume factor must be a number between -4 and 4\n");
else
volfactor = vol;
- }
+ }
+
+ if (ast_test_flag(&flags, OPTION_PRIVATE))
+ ast_set_flag(&flags, OPTION_WHISPER);
+ }
+
+ oldwf = chan->writeformat;
+ if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
+ ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+ LOCAL_USER_REMOVE(u);
+ return -1;
}
if (recbase) {
char filename[512];
- snprintf(filename,sizeof(filename),"%s/%s.%d.raw",ast_config_AST_MONITOR_DIR, recbase, (int)time(NULL));
+
+ snprintf(filename, sizeof(filename), "%s/%s.%d.raw", ast_config_AST_MONITOR_DIR, recbase, (int) time(NULL));
if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644)) <= 0) {
- ast_log(LOG_WARNING, "Cannot open %s for recording\n", filename);
+ ast_log(LOG_WARNING, "Cannot open '%s' for recording\n", filename);
fd = 0;
}
}
- for(;;) {
- if (!silent) {
- res = ast_streamfile(chan, "beep", chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- if (res < 0) {
- ast_clear_flag(chan, AST_FLAG_SPYING);
- break;
- }
- }
-
- count = 0;
- res = ast_waitfordigit(chan, waitms);
- if (res < 0) {
- ast_clear_flag(chan, AST_FLAG_SPYING);
- break;
- }
-
- peer = local_channel_walk(NULL);
- prev=NULL;
- while(peer) {
- if (peer != chan) {
- const char *group = NULL;
- int igrp = 1;
- char *groups[25] = {0};
- int num_groups = 0;
- char *dup_group;
-
- if (peer == prev && !chosen) {
- break;
- }
- chosen = 0;
-
- if (mygroup) {
- int x;
-
- if ((group = pbx_builtin_getvar_helper(peer, "SPYGROUP"))) {
- dup_group = ast_strdupa(group);
- num_groups = ast_app_separate_args(dup_group, ':', groups, sizeof(groups) / sizeof(groups[0]));
- }
-
- igrp = 0;
- if (num_groups) {
- for (x = 0; x < num_groups; x++) {
- if (!strcmp(mygroup, groups[x])) {
- igrp = 1;
- break;
- }
- }
- }
- }
-
- if (igrp && (!spec || ((strlen(spec) <= strlen(peer->name) &&
- !strncasecmp(peer->name, spec, strlen(spec)))))) {
- if (peer && (!bronly || ast_bridged_channel(peer)) &&
- !ast_check_hangup(peer) && !ast_test_flag(peer, AST_FLAG_SPYING)) {
- int x = 0;
- strncpy(peer_name, "spy-", 5);
- strncpy(peer_name + strlen(peer_name), peer->name, AST_NAME_STRLEN);
- ptr = strchr(peer_name, '/');
- *ptr = '\0';
- ptr++;
- for (x = 0 ; x < strlen(peer_name) ; x++) {
- if (peer_name[x] == '/') {
- break;
- }
- peer_name[x] = tolower(peer_name[x]);
- }
-
- if (!silent) {
- if (ast_fileexists(peer_name, NULL, NULL) != -1) {
- res = ast_streamfile(chan, peer_name, chan->language);
- if (!res)
- res = ast_waitstream(chan, "");
- if (res)
- break;
- } else
- res = ast_say_character_str(chan, peer_name, "", chan->language);
- if ((num=atoi(ptr)))
- ast_say_digits(chan, atoi(ptr), "", chan->language);
- }
- count++;
- prev = peer;
- res = channel_spy(chan, peer, &volfactor, fd);
- if (res == -1) {
- break;
- } else if (res > 1 && spec) {
- snprintf(name, AST_NAME_STRLEN, "%s/%d", spec, res);
- if ((peer = local_get_channel_begin_name(name))) {
- chosen = 1;
- }
- continue;
- }
- }
- }
- }
- if ((peer = local_channel_walk(peer)) == NULL) {
- break;
- }
- }
- waitms = count ? 100 : 5000;
- }
-
-
- if (fd > 0) {
+ res = common_exec(chan, &flags, volfactor, fd, mygroup, NULL, exten, context);
+
+ if (fd)
close(fd);
- }
-
- if (oldrf && ast_set_read_format(chan, oldrf) < 0) {
- ast_log(LOG_ERROR, "Could Not Set Read Format.\n");
- }
-
- if (oldwf && ast_set_write_format(chan, oldwf) < 0) {
+
+ if (oldwf && ast_set_write_format(chan, oldwf) < 0)
ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
- }
-
- ast_clear_flag(chan, AST_FLAG_SPYING);
-
- ast_channel_setoption(chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0);
-
- ALL_DONE(u, res);
+
+ LOCAL_USER_REMOVE(u);
+
+ return res;
}
static int unload_module(void *mod)
{
- int res;
-
[... 1442 lines stripped ...]
More information about the asterisk-commits
mailing list