2001-09-28 13:19:43 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2001-09-28 13:19:43 +00:00
|
|
|
*
|
2006-02-15 00:38:27 +00:00
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
2001-09-28 13:19:43 +00:00
|
|
|
*
|
2004-09-22 15:21:36 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2001-09-28 13:19:43 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2001-09-28 13:19:43 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief AGI - the Asterisk Gateway Interface
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2008-06-18 00:33:31 +00:00
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2009-01-24 19:33:15 +00:00
|
|
|
*
|
|
|
|
* \todo Convert the rest of the AGI commands over to XML documentation
|
2001-09-28 13:19:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
#include <math.h>
|
2003-09-08 16:48:07 +00:00
|
|
|
#include <signal.h>
|
2001-09-28 13:19:43 +00:00
|
|
|
#include <sys/time.h>
|
2006-05-25 18:31:19 +00:00
|
|
|
#include <sys/wait.h>
|
2007-06-25 13:00:49 +00:00
|
|
|
#include <sys/stat.h>
|
2007-12-25 02:57:58 +00:00
|
|
|
#include <pthread.h>
|
2005-06-06 22:12:19 +00:00
|
|
|
|
2007-11-20 23:16:15 +00:00
|
|
|
#include "asterisk/paths.h" /* use many ast_config_AST_*_DIR */
|
2007-11-17 14:11:53 +00:00
|
|
|
#include "asterisk/network.h"
|
2005-06-06 22:12:19 +00:00
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/astdb.h"
|
|
|
|
#include "asterisk/callerid.h"
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/image.h"
|
|
|
|
#include "asterisk/say.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
#include "asterisk/dsp.h"
|
|
|
|
#include "asterisk/musiconhold.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/lock.h"
|
2005-08-22 23:00:23 +00:00
|
|
|
#include "asterisk/strings.h"
|
2008-01-03 06:16:48 +00:00
|
|
|
#include "asterisk/manager.h"
|
2008-02-26 20:02:14 +00:00
|
|
|
#include "asterisk/ast_version.h"
|
2007-12-03 21:03:05 +00:00
|
|
|
#include "asterisk/speech.h"
|
2007-12-14 17:29:27 +00:00
|
|
|
#include "asterisk/manager.h"
|
2008-11-12 00:17:43 +00:00
|
|
|
#include "asterisk/term.h"
|
|
|
|
#include "asterisk/xmldoc.h"
|
2010-01-19 00:28:49 +00:00
|
|
|
#include "asterisk/srv.h"
|
2010-02-10 16:01:28 +00:00
|
|
|
#include "asterisk/test.h"
|
2012-02-29 20:31:48 +00:00
|
|
|
#include "asterisk/netsock2.h"
|
2013-06-06 19:51:12 +00:00
|
|
|
#include "asterisk/stasis_channels.h"
|
|
|
|
#include "asterisk/stasis_message_router.h"
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
#include "asterisk/format_cache.h"
|
2008-11-12 00:17:43 +00:00
|
|
|
|
2008-11-26 21:20:50 +00:00
|
|
|
#define AST_API_MODULE
|
|
|
|
#include "asterisk/agi.h"
|
|
|
|
|
2008-11-12 00:17:43 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<agi name="answer" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Answer channel
|
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>Answers channel if not already in answer state. Returns <literal>-1</literal> on
|
|
|
|
channel failure, or <literal>0</literal> if successful.</para>
|
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="agi">hangup</ref>
|
|
|
|
</see-also>
|
|
|
|
</agi>
|
2009-05-04 19:29:13 +00:00
|
|
|
<agi name="asyncagi break" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Interrupts Async AGI
|
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>Interrupts expected flow of Async AGI commands and returns control to previous source
|
|
|
|
(typically, the PBX dialplan).</para>
|
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="agi">hangup</ref>
|
|
|
|
</see-also>
|
|
|
|
</agi>
|
2008-11-12 00:17:43 +00:00
|
|
|
<agi name="channel status" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Returns status of the connected channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="channelname" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Returns the status of the specified <replaceable>channelname</replaceable>.
|
|
|
|
If no channel name is given then returns the status of the current channel.</para>
|
|
|
|
<para>Return values:</para>
|
|
|
|
<enumlist>
|
|
|
|
<enum name="0">
|
|
|
|
<para>Channel is down and available.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="1">
|
|
|
|
<para>Channel is down, but reserved.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="2">
|
|
|
|
<para>Channel is off hook.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="3">
|
|
|
|
<para>Digits (or equivalent) have been dialed.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="4">
|
|
|
|
<para>Line is ringing.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="5">
|
|
|
|
<para>Remote end is ringing.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="6">
|
|
|
|
<para>Line is up.</para>
|
|
|
|
</enum>
|
|
|
|
<enum name="7">
|
|
|
|
<para>Line is busy.</para>
|
|
|
|
</enum>
|
|
|
|
</enumlist>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2009-05-24 16:17:31 +00:00
|
|
|
<agi name="control stream file" language="en_US">
|
|
|
|
<synopsis>
|
2010-09-27 13:04:23 +00:00
|
|
|
Sends audio file on channel and allows the listener to control the stream.
|
2009-05-24 16:17:31 +00:00
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="filename" required="true">
|
|
|
|
<para>The file extension must not be included in the filename.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
<parameter name="skipms" />
|
|
|
|
<parameter name="ffchar">
|
2014-10-28 14:57:01 +00:00
|
|
|
<para>Defaults to <literal>#</literal></para>
|
2009-05-24 16:17:31 +00:00
|
|
|
</parameter>
|
|
|
|
<parameter name="rewchr">
|
2014-10-28 14:57:01 +00:00
|
|
|
<para>Defaults to <literal>*</literal></para>
|
2009-05-24 16:17:31 +00:00
|
|
|
</parameter>
|
|
|
|
<parameter name="pausechr" />
|
2013-07-31 23:48:35 +00:00
|
|
|
<parameter name="offsetms">
|
|
|
|
<para>Offset, in milliseconds, to start the audio playback</para>
|
|
|
|
</parameter>
|
2009-05-24 16:17:31 +00:00
|
|
|
</syntax>
|
|
|
|
<description>
|
2010-09-27 13:04:23 +00:00
|
|
|
<para>Send the given file, allowing playback to be controlled by the given
|
2009-05-24 16:17:31 +00:00
|
|
|
digits, if any. Use double quotes for the digits if you wish none to be
|
2013-07-31 23:48:35 +00:00
|
|
|
permitted. If offsetms is provided then the audio will seek to offsetms
|
|
|
|
before play starts. Returns <literal>0</literal> if playback completes without a digit
|
2009-05-24 16:17:31 +00:00
|
|
|
being pressed, or the ASCII numerical value of the digit if one was pressed,
|
2013-07-31 23:48:35 +00:00
|
|
|
or <literal>-1</literal> on error or if the channel was disconnected. Returns the
|
|
|
|
position where playback was terminated as endpos.</para>
|
|
|
|
|
2013-01-22 15:16:20 +00:00
|
|
|
<para>It sets the following channel variables upon completion:</para>
|
|
|
|
<variablelist>
|
|
|
|
<variable name="CPLAYBACKSTATUS">
|
|
|
|
<para>Contains the status of the attempt as a text string</para>
|
|
|
|
<value name="SUCCESS" />
|
|
|
|
<value name="USERSTOPPED" />
|
|
|
|
<value name="REMOTESTOPPED" />
|
|
|
|
<value name="ERROR" />
|
|
|
|
</variable>
|
|
|
|
<variable name="CPLAYBACKOFFSET">
|
|
|
|
<para>Contains the offset in ms into the file where playback
|
|
|
|
was at when it stopped. <literal>-1</literal> is end of file.</para>
|
|
|
|
</variable>
|
|
|
|
<variable name="CPLAYBACKSTOPKEY">
|
|
|
|
<para>If the playback is stopped by the user this variable contains
|
|
|
|
the key that was pressed.</para>
|
|
|
|
</variable>
|
|
|
|
</variablelist>
|
2009-05-24 16:17:31 +00:00
|
|
|
</description>
|
|
|
|
</agi>
|
2008-11-12 02:20:05 +00:00
|
|
|
<agi name="database del" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Removes database key/value
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="family" required="true" />
|
|
|
|
<parameter name="key" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Deletes an entry in the Asterisk database for a given
|
|
|
|
<replaceable>family</replaceable> and <replaceable>key</replaceable>.</para>
|
|
|
|
<para>Returns <literal>1</literal> if successful, <literal>0</literal>
|
|
|
|
otherwise.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2008-11-12 13:43:46 +00:00
|
|
|
<agi name="database deltree" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Removes database keytree/value
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="family" required="true" />
|
|
|
|
<parameter name="keytree" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Deletes a <replaceable>family</replaceable> or specific <replaceable>keytree</replaceable>
|
|
|
|
within a <replaceable>family</replaceable> in the Asterisk database.</para>
|
|
|
|
<para>Returns <literal>1</literal> if successful, <literal>0</literal> otherwise.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="database get" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets database value
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="family" required="true" />
|
|
|
|
<parameter name="key" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Retrieves an entry in the Asterisk database for a given <replaceable>family</replaceable>
|
|
|
|
and <replaceable>key</replaceable>.</para>
|
|
|
|
<para>Returns <literal>0</literal> if <replaceable>key</replaceable> is not set.
|
|
|
|
Returns <literal>1</literal> if <replaceable>key</replaceable> is set and returns the variable
|
|
|
|
in parenthesis.</para>
|
|
|
|
<para>Example return code: 200 result=1 (testvariable)</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2008-11-12 02:20:05 +00:00
|
|
|
<agi name="database put" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Adds/updates database value
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="family" required="true" />
|
|
|
|
<parameter name="key" required="true" />
|
|
|
|
<parameter name="value" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Adds or updates an entry in the Asterisk database for a given
|
|
|
|
<replaceable>family</replaceable>, <replaceable>key</replaceable>, and
|
|
|
|
<replaceable>value</replaceable>.</para>
|
|
|
|
<para>Returns <literal>1</literal> if successful, <literal>0</literal> otherwise.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2008-11-12 13:43:46 +00:00
|
|
|
<agi name="exec" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Executes a given Application
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="application" required="true" />
|
|
|
|
<parameter name="options" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Executes <replaceable>application</replaceable> with given
|
|
|
|
<replaceable>options</replaceable>.</para>
|
|
|
|
<para>Returns whatever the <replaceable>application</replaceable> returns, or
|
|
|
|
<literal>-2</literal> on failure to find <replaceable>application</replaceable>.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="get data" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Prompts for DTMF on a channel
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="file" required="true" />
|
|
|
|
<parameter name="timeout" />
|
|
|
|
<parameter name="maxdigits" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
2010-09-27 13:04:23 +00:00
|
|
|
<para>Stream the given <replaceable>file</replaceable>, and receive DTMF data.</para>
|
2008-11-12 13:43:46 +00:00
|
|
|
<para>Returns the digits received from the channel at the other end.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="get full variable" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Evaluates a channel expression
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="variablename" required="true" />
|
|
|
|
<parameter name="channel name" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Returns <literal>0</literal> if <replaceable>variablename</replaceable> is not set
|
|
|
|
or channel does not exist. Returns <literal>1</literal> if <replaceable>variablename</replaceable>
|
|
|
|
is set and returns the variable in parenthesis. Understands complex variable names and builtin
|
|
|
|
variables, unlike GET VARIABLE.</para>
|
|
|
|
<para>Example return code: 200 result=1 (testvariable)</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2008-12-04 13:45:32 +00:00
|
|
|
<agi name="get option" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Stream file, prompt for DTMF, with timeout.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="filename" required="true" />
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
<parameter name="timeout" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Behaves similar to STREAM FILE but used with a timeout option.</para>
|
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="agi">stream file</ref>
|
|
|
|
</see-also>
|
|
|
|
</agi>
|
|
|
|
<agi name="get variable" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Gets a channel variable.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="variablename" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Returns <literal>0</literal> if <replaceable>variablename</replaceable> is not set.
|
|
|
|
Returns <literal>1</literal> if <replaceable>variablename</replaceable> is set and returns
|
|
|
|
the variable in parentheses.</para>
|
|
|
|
<para>Example return code: 200 result=1 (testvariable)</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="hangup" language="en_US">
|
|
|
|
<synopsis>
|
2011-06-13 19:03:46 +00:00
|
|
|
Hangup a channel.
|
2008-12-04 13:45:32 +00:00
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="channelname" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Hangs up the specified channel. If no channel name is given, hangs
|
|
|
|
up the current channel</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="noop" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Does nothing.
|
|
|
|
</synopsis>
|
|
|
|
<syntax />
|
|
|
|
<description>
|
|
|
|
<para>Does nothing.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2009-05-18 20:18:43 +00:00
|
|
|
<agi name="receive char" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Receives one character from channels supporting it.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="timeout" required="true">
|
|
|
|
<para>The maximum time to wait for input in milliseconds, or <literal>0</literal>
|
|
|
|
for infinite. Most channels</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Receives a character of text on a channel. Most channels do not support
|
|
|
|
the reception of text. Returns the decimal value of the character
|
|
|
|
if one is received, or <literal>0</literal> if the channel does not support
|
|
|
|
text reception. Returns <literal>-1</literal> only on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="receive text" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Receives text from channels supporting it.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="timeout" required="true">
|
|
|
|
<para>The timeout to be the maximum time to wait for input in
|
|
|
|
milliseconds, or <literal>0</literal> for infinite.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
2013-07-31 23:48:35 +00:00
|
|
|
<para>Receives a string of text on a channel. Most channels
|
2009-05-18 20:18:43 +00:00
|
|
|
do not support the reception of text. Returns <literal>-1</literal> for failure
|
2013-07-31 23:48:35 +00:00
|
|
|
or <literal>1</literal> for success, and the string in parenthesis.</para>
|
2009-05-18 20:18:43 +00:00
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="record file" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Records to a given file.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="filename" required="true" />
|
|
|
|
<parameter name="format" required="true" />
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
<parameter name="timeout" required="true" />
|
|
|
|
<parameter name="offset samples" />
|
|
|
|
<parameter name="BEEP" />
|
|
|
|
<parameter name="s=silence" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Record to a file until a given dtmf digit in the sequence is received.
|
|
|
|
Returns <literal>-1</literal> on hangup or error. The format will specify what kind of file
|
|
|
|
will be recorded. The <replaceable>timeout</replaceable> is the maximum record time in
|
|
|
|
milliseconds, or <literal>-1</literal> for no <replaceable>timeout</replaceable>.
|
|
|
|
<replaceable>offset samples</replaceable> is optional, and, if provided, will seek
|
|
|
|
to the offset without exceeding the end of the file. <replaceable>silence</replaceable> is
|
|
|
|
the number of seconds of silence allowed before the function returns despite the
|
|
|
|
lack of dtmf digits or reaching <replaceable>timeout</replaceable>. <replaceable>silence</replaceable>
|
2010-07-02 15:57:02 +00:00
|
|
|
value must be preceded by <literal>s=</literal> and is also optional.</para>
|
2009-05-18 20:18:43 +00:00
|
|
|
</description>
|
|
|
|
</agi>
|
2009-05-22 19:11:44 +00:00
|
|
|
<agi name="say alpha" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Says a given character string.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="number" required="true" />
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Say a given character string, returning early if any of the given DTMF digits
|
|
|
|
are received on the channel. Returns <literal>0</literal> if playback completes
|
|
|
|
without a digit being pressed, or the ASCII numerical value of the digit if one
|
|
|
|
was pressed or <literal>-1</literal> on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="say digits" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Says a given digit string.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="number" required="true" />
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Say a given digit string, returning early if any of the given DTMF digits
|
|
|
|
are received on the channel. Returns <literal>0</literal> if playback completes
|
|
|
|
without a digit being pressed, or the ASCII numerical value of the digit if one
|
|
|
|
was pressed or <literal>-1</literal> on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="say number" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Says a given number.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="number" required="true" />
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
<parameter name="gender" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Say a given number, returning early if any of the given DTMF digits
|
|
|
|
are received on the channel. Returns <literal>0</literal> if playback
|
|
|
|
completes without a digit being pressed, or the ASCII numerical value of
|
|
|
|
the digit if one was pressed or <literal>-1</literal> on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="say phonetic" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Says a given character string with phonetics.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="string" required="true" />
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Say a given character string with phonetics, returning early if any of the
|
|
|
|
given DTMF digits are received on the channel. Returns <literal>0</literal> if
|
|
|
|
playback completes without a digit pressed, the ASCII numerical value of the digit
|
|
|
|
if one was pressed, or <literal>-1</literal> on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="say date" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Says a given date.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="date" required="true">
|
|
|
|
<para>Is number of seconds elapsed since 00:00:00 on January 1, 1970.
|
|
|
|
Coordinated Universal Time (UTC).</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Say a given date, returning early if any of the given DTMF digits are
|
|
|
|
received on the channel. Returns <literal>0</literal> if playback
|
|
|
|
completes without a digit being pressed, or the ASCII numerical value of the
|
|
|
|
digit if one was pressed or <literal>-1</literal> on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="say time" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Says a given time.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="time" required="true">
|
|
|
|
<para>Is number of seconds elapsed since 00:00:00 on January 1, 1970.
|
|
|
|
Coordinated Universal Time (UTC).</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Say a given time, returning early if any of the given DTMF digits are
|
|
|
|
received on the channel. Returns <literal>0</literal> if playback completes
|
|
|
|
without a digit being pressed, or the ASCII numerical value of the digit if
|
|
|
|
one was pressed or <literal>-1</literal> on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2009-05-23 21:11:31 +00:00
|
|
|
<agi name="say datetime" language="en_US">
|
|
|
|
<synopsis>
|
2010-09-27 12:42:30 +00:00
|
|
|
Says a given time as specified by the format given.
|
2009-05-23 21:11:31 +00:00
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="time" required="true">
|
|
|
|
<para>Is number of seconds elapsed since 00:00:00
|
|
|
|
on January 1, 1970, Coordinated Universal Time (UTC)</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="escape_digits" required="true" />
|
|
|
|
<parameter name="format">
|
|
|
|
<para>Is the format the time should be said in. See
|
|
|
|
<filename>voicemail.conf</filename> (defaults to <literal>ABdY
|
|
|
|
'digits/at' IMp</literal>).</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="timezone">
|
|
|
|
<para>Acceptable values can be found in <filename>/usr/share/zoneinfo</filename>
|
|
|
|
Defaults to machine default.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Say a given time, returning early if any of the given DTMF digits are
|
|
|
|
received on the channel. Returns <literal>0</literal> if playback
|
|
|
|
completes without a digit being pressed, or the ASCII numerical value of the
|
|
|
|
digit if one was pressed or <literal>-1</literal> on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="send image" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Sends images to channels supporting it.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="image" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Sends the given image on a channel. Most channels do not support the
|
|
|
|
transmission of images. Returns <literal>0</literal> if image is sent, or if
|
|
|
|
the channel does not support image transmission. Returns <literal>-1</literal>
|
|
|
|
only on error/hangup. Image names should not include extensions.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="send text" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Sends text to channels supporting it.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="text to send" required="true">
|
|
|
|
<para>Text consisting of greater than one word should be placed
|
|
|
|
in quotes since the command only accepts a single argument.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Sends the given text on a channel. Most channels do not support the
|
|
|
|
transmission of text. Returns <literal>0</literal> if text is sent, or if the
|
|
|
|
channel does not support text transmission. Returns <literal>-1</literal> only
|
|
|
|
on error/hangup.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="set autohangup" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Autohangup channel in some time.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="time" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Cause the channel to automatically hangup at <replaceable>time</replaceable>
|
|
|
|
seconds in the future. Of course it can be hungup before then as well. Setting to
|
|
|
|
<literal>0</literal> will cause the autohangup feature to be disabled on this channel.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="set callerid" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Sets callerid for the current channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="number" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Changes the callerid of the current channel.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="set context" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Sets channel context.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="desired context" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Sets the context for continuation upon exiting the application.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="set extension" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Changes channel extension.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="new extension" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Changes the extension for continuation upon exiting the application.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2008-11-12 02:20:05 +00:00
|
|
|
<agi name="set music" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Enable/Disable Music on hold generator
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter required="true">
|
|
|
|
<enumlist>
|
|
|
|
<enum>
|
|
|
|
<parameter name="on" literal="true" required="true" />
|
|
|
|
</enum>
|
|
|
|
<enum>
|
|
|
|
<parameter name="off" literal="true" required="true" />
|
|
|
|
</enum>
|
|
|
|
</enumlist>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="class" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Enables/Disables the music on hold generator. If <replaceable>class</replaceable>
|
|
|
|
is not specified, then the <literal>default</literal> music on hold class will be
|
2012-09-28 12:17:41 +00:00
|
|
|
used. This generator will be stopped automatically when playing a file.</para>
|
2008-11-12 02:20:05 +00:00
|
|
|
<para>Always returns <literal>0</literal>.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2009-05-24 16:17:31 +00:00
|
|
|
<agi name="set priority" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Set channel dialplan priority.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="priority" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Changes the priority for continuation upon exiting the application.
|
|
|
|
The priority must be a valid priority or label.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="set variable" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Sets a channel variable.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="variablename" required="true" />
|
|
|
|
<parameter name="value" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Sets a variable to the current channel.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="stream file" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Sends audio file on channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="filename" required="true">
|
|
|
|
<para>File name to play. The file extension must not be
|
|
|
|
included in the <replaceable>filename</replaceable>.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="escape_digits" required="true">
|
|
|
|
<para>Use double quotes for the digits if you wish none to be
|
|
|
|
permitted.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="sample offset">
|
|
|
|
<para>If sample offset is provided then the audio will seek to sample
|
|
|
|
offset before play starts.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Send the given file, allowing playback to be interrupted by the given
|
|
|
|
digits, if any. Returns <literal>0</literal> if playback completes without a digit
|
|
|
|
being pressed, or the ASCII numerical value of the digit if one was pressed,
|
2012-09-28 12:17:41 +00:00
|
|
|
or <literal>-1</literal> on error or if the channel was disconnected. If
|
|
|
|
musiconhold is playing before calling stream file it will be automatically
|
|
|
|
stopped and will not be restarted after completion.</para>
|
2013-01-22 15:16:20 +00:00
|
|
|
<para>It sets the following channel variables upon completion:</para>
|
|
|
|
<variablelist>
|
|
|
|
<variable name="PLAYBACKSTATUS">
|
|
|
|
<para>The status of the playback attempt as a text string.</para>
|
|
|
|
<value name="SUCCESS"/>
|
|
|
|
<value name="FAILED"/>
|
|
|
|
</variable>
|
|
|
|
</variablelist>
|
2009-05-24 16:17:31 +00:00
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="agi">control stream file</ref>
|
|
|
|
</see-also>
|
|
|
|
</agi>
|
|
|
|
<agi name="tdd mode" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Toggles TDD mode (for the deaf).
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="boolean" required="true">
|
|
|
|
<enumlist>
|
|
|
|
<enum name="on" />
|
|
|
|
<enum name="off" />
|
|
|
|
</enumlist>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Enable/Disable TDD transmission/reception on a channel. Returns <literal>1</literal> if
|
|
|
|
successful, or <literal>0</literal> if channel is not TDD-capable.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="verbose" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Logs a message to the asterisk verbose log.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="message" required="true" />
|
|
|
|
<parameter name="level" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Sends <replaceable>message</replaceable> to the console via verbose
|
2010-09-27 13:04:23 +00:00
|
|
|
message system. <replaceable>level</replaceable> is the verbose level (1-4).
|
2009-05-24 16:17:31 +00:00
|
|
|
Always returns <literal>1</literal></para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="wait for digit" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Waits for a digit to be pressed.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="timeout" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Waits up to <replaceable>timeout</replaceable> milliseconds for channel to
|
|
|
|
receive a DTMF digit. Returns <literal>-1</literal> on channel failure, <literal>0</literal>
|
|
|
|
if no digit is received in the timeout, or the numerical value of the ascii of the digit if
|
|
|
|
one is received. Use <literal>-1</literal> for the <replaceable>timeout</replaceable> value if
|
2010-11-22 18:43:31 +00:00
|
|
|
you desire the call to block indefinitely.</para>
|
2009-05-24 16:17:31 +00:00
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech create" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Creates a speech object.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="engine" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Create a speech object to be used by the other Speech AGI commands.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech set" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Sets a speech engine setting.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="name" required="true" />
|
|
|
|
<parameter name="value" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Set an engine-specific setting.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech destroy" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Destroys a speech object.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Destroy the speech object created by <literal>SPEECH CREATE</literal>.</para>
|
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="agi">speech create</ref>
|
|
|
|
</see-also>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech load grammar" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Loads a grammar.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="grammar name" required="true" />
|
|
|
|
<parameter name="path to grammar" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Loads the specified grammar as the specified name.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech unload grammar" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Unloads a grammar.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="grammar name" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Unloads the specified grammar.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech activate grammar" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Activates a grammar.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="grammar name" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Activates the specified grammar on the speech object.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech deactivate grammar" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Deactivates a grammar.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="grammar name" required="true" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Deactivates the specified grammar on the speech object.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
|
|
|
<agi name="speech recognize" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Recognizes speech.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="prompt" required="true" />
|
|
|
|
<parameter name="timeout" required="true" />
|
|
|
|
<parameter name="offset" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Plays back given <replaceable>prompt</replaceable> while listening for
|
|
|
|
speech and dtmf.</para>
|
|
|
|
</description>
|
|
|
|
</agi>
|
2009-06-01 15:38:48 +00:00
|
|
|
<application name="AGI" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Executes an AGI compliant application.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<parameter name="command" required="true" />
|
|
|
|
<parameter name="args">
|
|
|
|
<argument name="arg1" required="true" />
|
|
|
|
<argument name="arg2" multiple="yes" />
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Executes an Asterisk Gateway Interface compliant
|
|
|
|
program on a channel. AGI allows Asterisk to launch external programs written
|
|
|
|
in any language to control a telephony channel, play audio, read DTMF digits,
|
|
|
|
etc. by communicating with the AGI protocol on <emphasis>stdin</emphasis> and
|
|
|
|
<emphasis>stdout</emphasis>. As of <literal>1.6.0</literal>, this channel will
|
|
|
|
not stop dialplan execution on hangup inside of this application. Dialplan
|
|
|
|
execution will continue normally, even upon hangup until the AGI application
|
|
|
|
signals a desire to stop (either by exiting or, in the case of a net script, by
|
|
|
|
closing the connection). A locally executed AGI script will receive SIGHUP on
|
|
|
|
hangup from the channel except when using DeadAGI. A fast AGI server will
|
2010-06-16 18:43:22 +00:00
|
|
|
correspondingly receive a HANGUP inline with the command dialog. Both of theses
|
|
|
|
signals may be disabled by setting the <variable>AGISIGHUP</variable> channel
|
2012-02-14 00:43:50 +00:00
|
|
|
variable to <literal>no</literal> before executing the AGI application.
|
|
|
|
Alternatively, if you would like the AGI application to exit immediately
|
|
|
|
after a channel hangup is detected, set the <variable>AGIEXITONHANGUP</variable>
|
|
|
|
variable to <literal>yes</literal>.</para>
|
2010-02-10 16:01:28 +00:00
|
|
|
<para>Use the CLI command <literal>agi show commands</literal> to list available agi
|
2009-06-01 15:38:48 +00:00
|
|
|
commands.</para>
|
|
|
|
<para>This application sets the following channel variable upon completion:</para>
|
|
|
|
<variablelist>
|
|
|
|
<variable name="AGISTATUS">
|
|
|
|
<para>The status of the attempt to the run the AGI script
|
|
|
|
text string, one of:</para>
|
|
|
|
<value name="SUCCESS" />
|
|
|
|
<value name="FAILURE" />
|
|
|
|
<value name="NOTFOUND" />
|
|
|
|
<value name="HANGUP" />
|
|
|
|
</variable>
|
|
|
|
</variablelist>
|
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="application">EAGI</ref>
|
|
|
|
<ref type="application">DeadAGI</ref>
|
|
|
|
</see-also>
|
|
|
|
</application>
|
|
|
|
<application name="EAGI" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Executes an EAGI compliant application.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/syntax/parameter[@name='command'])" />
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/syntax/parameter[@name='args'])" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Using 'EAGI' provides enhanced AGI, with incoming audio available out of band
|
|
|
|
on file descriptor 3.</para>
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/description/para)" />
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/description/variablelist)" />
|
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="application">AGI</ref>
|
|
|
|
<ref type="application">DeadAGI</ref>
|
|
|
|
</see-also>
|
|
|
|
</application>
|
|
|
|
<application name="DeadAGI" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Executes AGI on a hungup channel.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/syntax/parameter[@name='command'])" />
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/syntax/parameter[@name='args'])" />
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/description/para)" />
|
|
|
|
<xi:include xpointer="xpointer(/docs/application[@name='AGI']/description/variablelist)" />
|
|
|
|
</description>
|
|
|
|
<see-also>
|
|
|
|
<ref type="application">AGI</ref>
|
|
|
|
<ref type="application">EAGI</ref>
|
|
|
|
</see-also>
|
|
|
|
</application>
|
|
|
|
<manager name="AGI" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Add an AGI command to execute by Async AGI.
|
|
|
|
</synopsis>
|
|
|
|
<syntax>
|
|
|
|
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
|
|
|
|
<parameter name="Channel" required="true">
|
|
|
|
<para>Channel that is currently in Async AGI.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="Command" required="true">
|
|
|
|
<para>Application to execute.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="CommandID">
|
|
|
|
<para>This will be sent back in CommandID header of AsyncAGI exec
|
|
|
|
event notification.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
|
|
|
<para>Add an AGI command to the execute queue of the channel in Async AGI.</para>
|
|
|
|
</description>
|
|
|
|
</manager>
|
2013-06-06 19:51:12 +00:00
|
|
|
<managerEvent language="en_US" name="AsyncAGIStart">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_AGI">
|
|
|
|
<synopsis>Raised when a channel starts AsyncAGI command processing.</synopsis>
|
|
|
|
<syntax>
|
2013-08-01 17:07:52 +00:00
|
|
|
<channel_snapshot/>
|
2013-06-06 19:51:12 +00:00
|
|
|
<parameter name="Env">
|
|
|
|
<para>URL encoded string read from the AsyncAGI server.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
|
|
|
<managerEvent language="en_US" name="AsyncAGIEnd">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_AGI">
|
|
|
|
<synopsis>Raised when a channel stops AsyncAGI command processing.</synopsis>
|
|
|
|
<syntax>
|
2013-08-01 17:07:52 +00:00
|
|
|
<channel_snapshot/>
|
2013-06-06 19:51:12 +00:00
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
|
|
|
<managerEvent language="en_US" name="AsyncAGIExec">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_AGI">
|
|
|
|
<synopsis>Raised when AsyncAGI completes an AGI command.</synopsis>
|
|
|
|
<syntax>
|
2013-08-01 17:07:52 +00:00
|
|
|
<channel_snapshot/>
|
2013-06-06 19:51:12 +00:00
|
|
|
<parameter name="CommandID" required="false">
|
|
|
|
<para>Optional command ID sent by the AsyncAGI server to identify the command.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="Result">
|
|
|
|
<para>URL encoded result string from the executed AGI command.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
|
|
|
<managerEvent language="en_US" name="AGIExecStart">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_AGI">
|
|
|
|
<synopsis>Raised when a received AGI command starts processing.</synopsis>
|
|
|
|
<syntax>
|
2013-08-01 17:07:52 +00:00
|
|
|
<channel_snapshot/>
|
2013-06-06 19:51:12 +00:00
|
|
|
<parameter name="Command">
|
|
|
|
<para>The AGI command as received from the external source.</para>
|
|
|
|
</parameter>
|
|
|
|
<parameter name="CommandId">
|
|
|
|
<para>Random identification number assigned to the execution of this command.</para>
|
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
|
|
|
<managerEvent language="en_US" name="AGIExecEnd">
|
|
|
|
<managerEventInstance class="EVENT_FLAG_AGI">
|
|
|
|
<synopsis>Raised when a received AGI command completes processing.</synopsis>
|
|
|
|
<syntax>
|
2013-08-01 17:07:52 +00:00
|
|
|
<channel_snapshot/>
|
2013-06-06 19:51:12 +00:00
|
|
|
<xi:include xpointer="xpointer(/docs/managerEvent[@name='AGIExecStart']/managerEventInstance/syntax/parameter)" />
|
|
|
|
<parameter name="ResultCode">
|
|
|
|
<para>The numeric result code from AGI</para>
|
2013-06-06 20:37:48 +00:00
|
|
|
</parameter>
|
2013-06-06 19:51:12 +00:00
|
|
|
<parameter name="Result">
|
|
|
|
<para>The text result reason from AGI</para>
|
2013-06-06 20:37:48 +00:00
|
|
|
</parameter>
|
2013-06-06 19:51:12 +00:00
|
|
|
</syntax>
|
|
|
|
</managerEventInstance>
|
|
|
|
</managerEvent>
|
2008-11-12 00:17:43 +00:00
|
|
|
***/
|
2001-09-28 13:19:43 +00:00
|
|
|
|
|
|
|
#define MAX_ARGS 128
|
2008-11-12 00:17:43 +00:00
|
|
|
#define MAX_CMD_LEN 80
|
2007-09-11 15:28:46 +00:00
|
|
|
#define AGI_NANDFS_RETRY 3
|
|
|
|
#define AGI_BUF_LEN 2048
|
2010-01-19 00:28:49 +00:00
|
|
|
#define SRV_PREFIX "_agi._tcp."
|
2001-09-28 13:19:43 +00:00
|
|
|
|
|
|
|
static char *app = "AGI";
|
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
static char *eapp = "EAGI";
|
|
|
|
|
2004-03-03 18:58:57 +00:00
|
|
|
static char *deadapp = "DeadAGI";
|
|
|
|
|
2004-09-25 14:22:27 +00:00
|
|
|
static int agidebug = 0;
|
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
#define TONE_BLOCK_SIZE 200
|
|
|
|
|
2004-09-22 15:21:36 +00:00
|
|
|
/* Max time to connect to an AGI remote host */
|
|
|
|
#define MAX_AGI_CONNECT 2000
|
|
|
|
|
|
|
|
#define AGI_PORT 4573
|
|
|
|
|
2011-04-18 16:27:14 +00:00
|
|
|
/*! Special return code for "asyncagi break" command. */
|
|
|
|
#define ASYNC_AGI_BREAK 3
|
|
|
|
|
2006-05-25 16:44:22 +00:00
|
|
|
enum agi_result {
|
2008-07-30 19:05:35 +00:00
|
|
|
AGI_RESULT_FAILURE = -1,
|
2006-05-25 16:44:22 +00:00
|
|
|
AGI_RESULT_SUCCESS,
|
2007-09-18 22:46:05 +00:00
|
|
|
AGI_RESULT_SUCCESS_FAST,
|
2008-01-03 06:16:48 +00:00
|
|
|
AGI_RESULT_SUCCESS_ASYNC,
|
2007-06-21 15:58:05 +00:00
|
|
|
AGI_RESULT_NOTFOUND,
|
|
|
|
AGI_RESULT_HANGUP,
|
2006-05-25 16:44:22 +00:00
|
|
|
};
|
|
|
|
|
2013-10-08 15:12:46 +00:00
|
|
|
static struct ast_manager_event_blob *agi_channel_to_ami(const char *type, struct stasis_message *message)
|
2013-06-06 19:51:12 +00:00
|
|
|
{
|
|
|
|
struct ast_channel_blob *obj = stasis_message_data(message);
|
2013-10-08 15:12:46 +00:00
|
|
|
RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
|
2013-06-06 19:51:12 +00:00
|
|
|
RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
|
|
|
|
|
2013-10-08 15:12:46 +00:00
|
|
|
channel_string = ast_manager_build_channel_state_string(obj->snapshot);
|
2013-06-06 19:51:12 +00:00
|
|
|
event_string = ast_manager_str_from_json_object(obj->blob, NULL);
|
2013-10-08 15:12:46 +00:00
|
|
|
if (!channel_string || !event_string) {
|
|
|
|
return NULL;
|
2013-06-06 19:51:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 15:12:46 +00:00
|
|
|
return ast_manager_event_blob_create(EVENT_FLAG_AGI, type,
|
2013-06-06 19:51:12 +00:00
|
|
|
"%s"
|
|
|
|
"%s",
|
2013-10-08 15:12:46 +00:00
|
|
|
ast_str_buffer(channel_string),
|
2013-06-06 19:51:12 +00:00
|
|
|
ast_str_buffer(event_string));
|
|
|
|
}
|
|
|
|
|
2013-10-08 15:12:46 +00:00
|
|
|
static struct ast_manager_event_blob *agi_exec_start_to_ami(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
return agi_channel_to_ami("AGIExecStart", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_manager_event_blob *agi_exec_end_to_ami(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
return agi_channel_to_ami("AGIExecEnd", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_manager_event_blob *agi_async_start_to_ami(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
return agi_channel_to_ami("AsyncAGIStart", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_manager_event_blob *agi_async_exec_to_ami(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
return agi_channel_to_ami("AsyncAGIExec", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ast_manager_event_blob *agi_async_end_to_ami(struct stasis_message *message)
|
|
|
|
{
|
|
|
|
return agi_channel_to_ami("AsyncAGIEnd", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_exec_start_type,
|
|
|
|
.to_ami = agi_exec_start_to_ami,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_exec_end_type,
|
|
|
|
.to_ami = agi_exec_end_to_ami,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_async_start_type,
|
|
|
|
.to_ami = agi_async_start_to_ami,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_async_exec_type,
|
|
|
|
.to_ami = agi_async_exec_to_ami,
|
|
|
|
);
|
|
|
|
STASIS_MESSAGE_TYPE_DEFN_LOCAL(agi_async_end_type,
|
|
|
|
.to_ami = agi_async_end_to_ami,
|
|
|
|
);
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static agi_command *find_command(const char * const cmds[], int exact);
|
2007-07-23 22:02:05 +00:00
|
|
|
|
2007-07-30 19:35:33 +00:00
|
|
|
AST_THREADSTORAGE(agi_buf);
|
|
|
|
#define AGI_BUF_INITSIZE 256
|
|
|
|
|
2009-06-15 16:07:23 +00:00
|
|
|
int AST_OPTIONAL_API_NAME(ast_agi_send)(int fd, struct ast_channel *chan, char *fmt, ...)
|
2004-09-25 14:22:27 +00:00
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
va_list ap;
|
2007-07-30 19:35:33 +00:00
|
|
|
struct ast_str *buf;
|
|
|
|
|
|
|
|
if (!(buf = ast_str_thread_get(&agi_buf, AGI_BUF_INITSIZE)))
|
|
|
|
return -1;
|
|
|
|
|
2004-09-25 14:22:27 +00:00
|
|
|
va_start(ap, fmt);
|
2007-07-30 19:35:33 +00:00
|
|
|
res = ast_str_set_va(&buf, 0, fmt, ap);
|
2004-09-25 14:22:27 +00:00
|
|
|
va_end(ap);
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2004-09-25 14:22:27 +00:00
|
|
|
if (res == -1) {
|
|
|
|
ast_log(LOG_ERROR, "Out of memory\n");
|
2007-07-30 19:18:24 +00:00
|
|
|
return -1;
|
2004-09-25 14:22:27 +00:00
|
|
|
}
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2007-11-07 00:00:38 +00:00
|
|
|
if (agidebug) {
|
|
|
|
if (chan) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verbose("<%s>AGI Tx >> %s", ast_channel_name(chan), ast_str_buffer(buf));
|
2007-11-07 00:00:38 +00:00
|
|
|
} else {
|
2008-12-13 08:36:35 +00:00
|
|
|
ast_verbose("AGI Tx >> %s", ast_str_buffer(buf));
|
2007-11-07 00:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
2007-07-30 19:35:33 +00:00
|
|
|
|
2008-12-13 08:36:35 +00:00
|
|
|
return ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100);
|
2004-09-25 14:22:27 +00:00
|
|
|
}
|
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
/* linked list of AGI commands ready to be executed by Async AGI */
|
|
|
|
struct agi_cmd {
|
|
|
|
char *cmd_buffer;
|
|
|
|
char *cmd_id;
|
|
|
|
AST_LIST_ENTRY(agi_cmd) entry;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void free_agi_cmd(struct agi_cmd *cmd)
|
|
|
|
{
|
|
|
|
ast_free(cmd->cmd_buffer);
|
|
|
|
ast_free(cmd->cmd_id);
|
|
|
|
ast_free(cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AGI datastore destructor */
|
|
|
|
static void agi_destroy_commands_cb(void *data)
|
|
|
|
{
|
|
|
|
struct agi_cmd *cmd;
|
|
|
|
AST_LIST_HEAD(, agi_cmd) *chan_cmds = data;
|
|
|
|
AST_LIST_LOCK(chan_cmds);
|
2008-06-18 00:33:31 +00:00
|
|
|
while ( (cmd = AST_LIST_REMOVE_HEAD(chan_cmds, entry)) ) {
|
2008-01-03 06:16:48 +00:00
|
|
|
free_agi_cmd(cmd);
|
2008-06-18 00:33:31 +00:00
|
|
|
}
|
2008-01-03 06:16:48 +00:00
|
|
|
AST_LIST_UNLOCK(chan_cmds);
|
|
|
|
AST_LIST_HEAD_DESTROY(chan_cmds);
|
|
|
|
ast_free(chan_cmds);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* channel datastore to keep the queue of AGI commands in the channel */
|
|
|
|
static const struct ast_datastore_info agi_commands_datastore_info = {
|
|
|
|
.type = "AsyncAGI",
|
|
|
|
.destroy = agi_destroy_commands_cb
|
|
|
|
};
|
|
|
|
|
2012-09-25 14:53:42 +00:00
|
|
|
/*!
|
|
|
|
* \brief Retrieve the list head to the requested channel's AGI datastore
|
|
|
|
* \param chan Channel datastore is requested for
|
|
|
|
* \param cmd Pointer to the struct pointer which will reference the head of the agi command list.
|
|
|
|
*
|
|
|
|
* \retval 0 if the datastore was valid and the list head was retrieved appropriately (even if it's
|
|
|
|
* NULL and the list is empty)
|
|
|
|
* \retval -1 if the datastore could not be retrieved causing an error
|
|
|
|
*/
|
|
|
|
static int get_agi_cmd(struct ast_channel *chan, struct agi_cmd **cmd)
|
2008-01-03 06:16:48 +00:00
|
|
|
{
|
|
|
|
struct ast_datastore *store;
|
|
|
|
AST_LIST_HEAD(, agi_cmd) *agi_commands;
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
store = ast_channel_datastore_find(chan, &agi_commands_datastore_info, NULL);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
if (!store) {
|
2011-04-13 17:51:14 +00:00
|
|
|
ast_log(LOG_ERROR, "Huh? Async AGI datastore disappeared on Channel %s!\n",
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_channel_name(chan));
|
2012-09-25 14:53:42 +00:00
|
|
|
*cmd = NULL;
|
|
|
|
return -1;
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
|
|
|
agi_commands = store->data;
|
|
|
|
AST_LIST_LOCK(agi_commands);
|
2012-09-25 14:53:42 +00:00
|
|
|
*cmd = AST_LIST_REMOVE_HEAD(agi_commands, entry);
|
2008-01-03 06:16:48 +00:00
|
|
|
AST_LIST_UNLOCK(agi_commands);
|
2012-09-25 14:53:42 +00:00
|
|
|
return 0;
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
|
|
|
|
2008-07-09 03:39:59 +00:00
|
|
|
/* channel is locked when calling this one either from the CLI or manager thread */
|
2008-01-03 06:16:48 +00:00
|
|
|
static int add_agi_cmd(struct ast_channel *chan, const char *cmd_buff, const char *cmd_id)
|
|
|
|
{
|
|
|
|
struct ast_datastore *store;
|
|
|
|
struct agi_cmd *cmd;
|
|
|
|
AST_LIST_HEAD(, agi_cmd) *agi_commands;
|
|
|
|
|
|
|
|
store = ast_channel_datastore_find(chan, &agi_commands_datastore_info, NULL);
|
|
|
|
if (!store) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Channel %s is not setup for Async AGI.\n", ast_channel_name(chan));
|
2008-01-03 06:16:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
agi_commands = store->data;
|
|
|
|
cmd = ast_calloc(1, sizeof(*cmd));
|
|
|
|
if (!cmd) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cmd->cmd_buffer = ast_strdup(cmd_buff);
|
|
|
|
if (!cmd->cmd_buffer) {
|
|
|
|
ast_free(cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cmd->cmd_id = ast_strdup(cmd_id);
|
|
|
|
if (!cmd->cmd_id) {
|
|
|
|
ast_free(cmd->cmd_buffer);
|
|
|
|
ast_free(cmd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
AST_LIST_LOCK(agi_commands);
|
|
|
|
AST_LIST_INSERT_TAIL(agi_commands, cmd, entry);
|
|
|
|
AST_LIST_UNLOCK(agi_commands);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_to_agi(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct ast_datastore *datastore;
|
|
|
|
AST_LIST_HEAD(, agi_cmd) *agi_cmds_list;
|
|
|
|
|
|
|
|
/* check if already on AGI */
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
datastore = ast_channel_datastore_find(chan, &agi_commands_datastore_info, NULL);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
if (datastore) {
|
2008-06-18 00:33:31 +00:00
|
|
|
/* we already have an AGI datastore, let's just
|
2008-01-03 06:16:48 +00:00
|
|
|
return success */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the channel has never been on Async AGI,
|
|
|
|
let's allocate it's datastore */
|
2008-08-05 16:56:11 +00:00
|
|
|
datastore = ast_datastore_alloc(&agi_commands_datastore_info, "AGI");
|
2008-01-03 06:16:48 +00:00
|
|
|
if (!datastore) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
agi_cmds_list = ast_calloc(1, sizeof(*agi_cmds_list));
|
|
|
|
if (!agi_cmds_list) {
|
|
|
|
ast_log(LOG_ERROR, "Unable to allocate Async AGI commands list.\n");
|
2008-08-05 16:56:11 +00:00
|
|
|
ast_datastore_free(datastore);
|
2008-01-03 06:16:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
datastore->data = agi_cmds_list;
|
|
|
|
AST_LIST_HEAD_INIT(agi_cmds_list);
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
ast_channel_datastore_add(chan, datastore);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2008-06-18 00:33:31 +00:00
|
|
|
* \brief CLI command to add applications to execute in Async AGI
|
2008-01-03 06:16:48 +00:00
|
|
|
* \param e
|
2008-06-18 00:33:31 +00:00
|
|
|
* \param cmd
|
2008-01-03 06:16:48 +00:00
|
|
|
* \param a
|
|
|
|
*
|
|
|
|
* \retval CLI_SUCCESS on success
|
|
|
|
* \retval NULL when init or tab completion is used
|
|
|
|
*/
|
|
|
|
static char *handle_cli_agi_add_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
struct ast_channel *chan;
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "agi exec";
|
|
|
|
e->usage = "Usage: agi exec <channel name> <app and arguments> [id]\n"
|
|
|
|
" Add AGI command to the execute queue of the specified channel in Async AGI\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
if (a->pos == 2)
|
|
|
|
return ast_complete_channels(a->line, a->word, a->pos, a->n, 2);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
if (a->argc < 4) {
|
2008-01-03 06:16:48 +00:00
|
|
|
return CLI_SHOWUSAGE;
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(chan = ast_channel_get_by_name(a->argv[2]))) {
|
2011-04-13 17:51:14 +00:00
|
|
|
ast_cli(a->fd, "Channel %s does not exist.\n", a->argv[2]);
|
2008-01-03 06:16:48 +00:00
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2011-04-13 17:21:50 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
if (add_agi_cmd(chan, a->argv[3], (a->argc > 4 ? a->argv[4] : ""))) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_cli(a->fd, "Failed to add AGI command to queue of channel %s\n", ast_channel_name(chan));
|
2008-01-03 06:16:48 +00:00
|
|
|
ast_channel_unlock(chan);
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
2008-01-03 06:16:48 +00:00
|
|
|
return CLI_FAILURE;
|
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_debug(1, "Added AGI command to channel %s queue\n", ast_channel_name(chan));
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
ast_channel_unlock(chan);
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Add a new command to execute by the Async AGI application
|
|
|
|
* \param s
|
|
|
|
* \param m
|
|
|
|
*
|
|
|
|
* It will append the application to the specified channel's queue
|
|
|
|
* if the channel is not inside Async AGI application it will return an error
|
|
|
|
* \retval 0 on success or incorrect use
|
2008-06-18 00:33:31 +00:00
|
|
|
* \retval 1 on failure to add the command ( most likely because the channel
|
2008-01-03 06:16:48 +00:00
|
|
|
* is not in Async AGI loop )
|
|
|
|
*/
|
|
|
|
static int action_add_agi_cmd(struct mansession *s, const struct message *m)
|
|
|
|
{
|
|
|
|
const char *channel = astman_get_header(m, "Channel");
|
|
|
|
const char *cmdbuff = astman_get_header(m, "Command");
|
|
|
|
const char *cmdid = astman_get_header(m, "CommandID");
|
|
|
|
struct ast_channel *chan;
|
|
|
|
char buf[256];
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
if (ast_strlen_zero(channel) || ast_strlen_zero(cmdbuff)) {
|
|
|
|
astman_send_error(s, m, "Both, Channel and Command are *required*");
|
|
|
|
return 0;
|
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
|
|
|
if (!(chan = ast_channel_get_by_name(channel))) {
|
2011-04-13 17:51:14 +00:00
|
|
|
snprintf(buf, sizeof(buf), "Channel %s does not exist.", channel);
|
2008-01-03 06:16:48 +00:00
|
|
|
astman_send_error(s, m, buf);
|
2008-04-05 13:24:12 +00:00
|
|
|
return 0;
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
if (add_agi_cmd(chan, cmdbuff, cmdid)) {
|
2012-01-09 22:15:50 +00:00
|
|
|
snprintf(buf, sizeof(buf), "Failed to add AGI command to channel %s queue", ast_channel_name(chan));
|
2008-01-03 06:16:48 +00:00
|
|
|
astman_send_error(s, m, buf);
|
|
|
|
ast_channel_unlock(chan);
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
2008-04-05 13:24:12 +00:00
|
|
|
return 0;
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
ast_channel_unlock(chan);
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
|
|
|
|
|
|
|
astman_send_ack(s, m, "Added AGI command to queue");
|
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-13 16:37:06 +00:00
|
|
|
static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead);
|
2008-01-03 06:16:48 +00:00
|
|
|
static void setup_env(struct ast_channel *chan, char *request, int fd, int enhanced, int argc, char *argv[]);
|
2011-04-13 17:51:14 +00:00
|
|
|
|
2011-04-18 16:27:14 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Read and handle a channel frame for Async AGI.
|
|
|
|
*
|
|
|
|
* \param chan Channel to read a frame from.
|
|
|
|
*
|
|
|
|
* \retval AGI_RESULT_SUCCESS on success.
|
|
|
|
* \retval AGI_RESULT_HANGUP on hangup.
|
|
|
|
* \retval AGI_RESULT_FAILURE on error.
|
|
|
|
*/
|
|
|
|
static enum agi_result async_agi_read_frame(struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct ast_frame *f;
|
|
|
|
|
|
|
|
f = ast_read(chan);
|
|
|
|
if (!f) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_debug(3, "No frame read on channel %s, going out ...\n", ast_channel_name(chan));
|
2011-04-18 16:27:14 +00:00
|
|
|
return AGI_RESULT_HANGUP;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_CONTROL) {
|
|
|
|
/*
|
|
|
|
* Is there any other frame we should care about besides
|
|
|
|
* AST_CONTROL_HANGUP?
|
|
|
|
*/
|
|
|
|
switch (f->subclass.integer) {
|
|
|
|
case AST_CONTROL_HANGUP:
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_debug(3, "Got HANGUP frame on channel %s, going out ...\n", ast_channel_name(chan));
|
2011-04-18 16:27:14 +00:00
|
|
|
ast_frfree(f);
|
|
|
|
return AGI_RESULT_HANGUP;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
|
|
|
|
|
|
|
return AGI_RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-06-10 16:03:51 +00:00
|
|
|
static enum agi_result launch_asyncagi(struct ast_channel *chan, int argc, char *argv[], int *efd)
|
2008-01-03 06:16:48 +00:00
|
|
|
{
|
|
|
|
/* This buffer sizes might cause truncation if the AGI command writes more data
|
2008-06-18 00:33:31 +00:00
|
|
|
than AGI_BUF_SIZE as result. But let's be serious, is there an AGI command
|
|
|
|
that writes a response larger than 1024 bytes?, I don't think so, most of
|
|
|
|
them are just result=blah stuff. However probably if GET VARIABLE is called
|
|
|
|
and the variable has large amount of data, that could be a problem. We could
|
2008-01-03 06:16:48 +00:00
|
|
|
make this buffers dynamic, but let's leave that as a second step.
|
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
AMI_BUF_SIZE is twice AGI_BUF_SIZE just for the sake of choosing a safe
|
|
|
|
number. Some characters of AGI buf will be url encoded to be sent to manager
|
|
|
|
clients. An URL encoded character will take 3 bytes, but again, to cause
|
|
|
|
truncation more than about 70% of the AGI buffer should be URL encoded for
|
|
|
|
that to happen. Not likely at all.
|
2008-01-03 06:16:48 +00:00
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
On the other hand. I wonder if read() could eventually return less data than
|
|
|
|
the amount already available in the pipe? If so, how to deal with that?
|
2008-01-03 06:16:48 +00:00
|
|
|
So far, my tests on Linux have not had any problems.
|
|
|
|
*/
|
|
|
|
#define AGI_BUF_SIZE 1024
|
|
|
|
#define AMI_BUF_SIZE 2048
|
2011-04-18 16:27:14 +00:00
|
|
|
enum agi_result cmd_status;
|
2008-01-03 06:16:48 +00:00
|
|
|
struct agi_cmd *cmd;
|
2011-04-18 16:27:14 +00:00
|
|
|
int res;
|
|
|
|
int fds[2];
|
|
|
|
int hungup;
|
2008-06-18 00:33:31 +00:00
|
|
|
int timeout = 100;
|
2008-01-03 06:16:48 +00:00
|
|
|
char agi_buffer[AGI_BUF_SIZE + 1];
|
|
|
|
char ami_buffer[AMI_BUF_SIZE];
|
2011-04-18 16:27:14 +00:00
|
|
|
enum agi_result returnstatus = AGI_RESULT_SUCCESS;
|
2008-01-03 06:16:48 +00:00
|
|
|
AGI async_agi;
|
2013-06-06 19:51:12 +00:00
|
|
|
RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
|
2008-01-03 06:16:48 +00:00
|
|
|
|
|
|
|
if (efd) {
|
|
|
|
ast_log(LOG_WARNING, "Async AGI does not support Enhanced AGI yet\n");
|
|
|
|
return AGI_RESULT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add AsyncAGI datastore to the channel */
|
|
|
|
if (add_to_agi(chan)) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_ERROR, "Failed to start Async AGI on channel %s\n", ast_channel_name(chan));
|
2008-01-03 06:16:48 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2008-06-18 00:33:31 +00:00
|
|
|
}
|
2008-01-03 06:16:48 +00:00
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
/* this pipe allows us to create a "fake" AGI struct to use
|
2008-01-03 06:16:48 +00:00
|
|
|
the AGI commands */
|
|
|
|
res = pipe(fds);
|
|
|
|
if (res) {
|
2011-04-13 17:51:14 +00:00
|
|
|
ast_log(LOG_ERROR, "Failed to create Async AGI pipe\n");
|
2011-04-13 22:54:08 +00:00
|
|
|
/*
|
|
|
|
* Intentionally do not remove the datastore added with
|
|
|
|
* add_to_agi() the from channel. It will be removed when the
|
|
|
|
* channel is hung up anyway.
|
|
|
|
*/
|
2008-01-03 06:16:48 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
|
|
|
}
|
2008-02-14 10:19:09 +00:00
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
/* handlers will get the pipe write fd and we read the AGI responses
|
2008-01-03 06:16:48 +00:00
|
|
|
from the pipe read fd */
|
2008-06-18 00:33:31 +00:00
|
|
|
async_agi.fd = fds[1];
|
2008-01-03 06:16:48 +00:00
|
|
|
async_agi.ctrl = fds[1];
|
|
|
|
async_agi.audio = -1; /* no audio support */
|
|
|
|
async_agi.fast = 0;
|
2010-01-08 22:17:03 +00:00
|
|
|
async_agi.speech = NULL;
|
2008-01-03 06:16:48 +00:00
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
/* notify possible manager users of a new channel ready to
|
|
|
|
receive commands */
|
2013-06-10 16:03:51 +00:00
|
|
|
setup_env(chan, "async", fds[1], 0, argc, argv);
|
2008-01-03 06:16:48 +00:00
|
|
|
/* read the environment */
|
|
|
|
res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
|
2012-04-17 21:14:49 +00:00
|
|
|
if (res <= 0) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s: %s\n",
|
|
|
|
ast_channel_name(chan), res < 0 ? strerror(errno) : "EOF");
|
2008-01-03 06:16:48 +00:00
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
2011-04-18 16:27:14 +00:00
|
|
|
goto async_agi_abort;
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
|
|
|
agi_buffer[res] = '\0';
|
2008-06-18 00:33:31 +00:00
|
|
|
/* encode it and send it thru the manager so whoever is going to take
|
|
|
|
care of AGI commands on this channel can decide which AGI commands
|
2008-01-03 06:16:48 +00:00
|
|
|
to execute based on the setup info */
|
2011-01-24 18:59:22 +00:00
|
|
|
ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
|
2013-06-06 19:51:12 +00:00
|
|
|
startblob = ast_json_pack("{s: s}", "Env", ami_buffer);
|
|
|
|
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ast_channel_publish_cached_blob(chan, agi_async_start_type(), startblob);
|
|
|
|
|
|
|
|
hungup = ast_check_hangup_locked(chan);
|
|
|
|
|
2011-04-18 16:27:14 +00:00
|
|
|
for (;;) {
|
|
|
|
/*
|
|
|
|
* Process as many commands as we can. Commands are added via
|
|
|
|
* the manager or the cli threads.
|
|
|
|
*/
|
2012-09-25 14:53:42 +00:00
|
|
|
while (!hungup) {
|
2013-06-06 19:51:12 +00:00
|
|
|
RAII_VAR(struct ast_json *, execblob, NULL, ast_json_unref);
|
2012-09-25 14:53:42 +00:00
|
|
|
res = get_agi_cmd(chan, &cmd);
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
|
|
|
goto async_agi_done;
|
|
|
|
} else if (!cmd) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-18 16:27:14 +00:00
|
|
|
/* OK, we have a command, let's call the command handler. */
|
|
|
|
cmd_status = agi_handle_command(chan, &async_agi, cmd->cmd_buffer, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The command handler must have written to our fake AGI struct
|
|
|
|
* fd (the pipe), let's read the response.
|
|
|
|
*/
|
2008-01-03 06:16:48 +00:00
|
|
|
res = read(fds[0], agi_buffer, AGI_BUF_SIZE);
|
2012-04-17 21:14:49 +00:00
|
|
|
if (res <= 0) {
|
|
|
|
ast_log(LOG_ERROR, "Failed to read from Async AGI pipe on channel %s: %s\n",
|
|
|
|
ast_channel_name(chan), res < 0 ? strerror(errno) : "EOF");
|
2008-01-03 06:16:48 +00:00
|
|
|
free_agi_cmd(cmd);
|
2011-04-18 16:27:14 +00:00
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
|
|
|
goto async_agi_done;
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
2011-04-18 16:27:14 +00:00
|
|
|
/*
|
|
|
|
* We have a response, let's send the response thru the manager.
|
|
|
|
* Include the CommandID if it was specified when the command
|
|
|
|
* was added.
|
|
|
|
*/
|
2008-01-03 06:16:48 +00:00
|
|
|
agi_buffer[res] = '\0';
|
2011-01-24 18:59:22 +00:00
|
|
|
ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
|
2013-06-06 19:51:12 +00:00
|
|
|
|
|
|
|
execblob = ast_json_pack("{s: s}", "Result", ami_buffer);
|
|
|
|
if (execblob && !ast_strlen_zero(cmd->cmd_id)) {
|
|
|
|
ast_json_object_set(execblob, "CommandId", ast_json_string_create(cmd->cmd_id));
|
2011-04-18 16:27:14 +00:00
|
|
|
}
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ast_channel_publish_cached_blob(chan, agi_async_exec_type(), execblob);
|
2013-06-06 19:51:12 +00:00
|
|
|
|
2008-01-03 06:16:48 +00:00
|
|
|
free_agi_cmd(cmd);
|
2011-04-18 16:27:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the command status to determine if we should continue
|
|
|
|
* executing more commands.
|
|
|
|
*/
|
|
|
|
hungup = ast_check_hangup(chan);
|
|
|
|
switch (cmd_status) {
|
|
|
|
case AGI_RESULT_FAILURE:
|
|
|
|
if (!hungup) {
|
|
|
|
/* The failure was not because of a hangup. */
|
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
|
|
|
goto async_agi_done;
|
|
|
|
}
|
2008-01-03 06:16:48 +00:00
|
|
|
break;
|
2011-04-18 16:27:14 +00:00
|
|
|
case AGI_RESULT_SUCCESS_ASYNC:
|
|
|
|
/* Only the "asyncagi break" command does this. */
|
|
|
|
returnstatus = AGI_RESULT_SUCCESS_ASYNC;
|
|
|
|
goto async_agi_done;
|
|
|
|
default:
|
2008-01-03 06:16:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-18 16:27:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!hungup) {
|
|
|
|
/* Wait a bit for a frame to read or to poll for a new command. */
|
|
|
|
res = ast_waitfor(chan, timeout);
|
|
|
|
if (res < 0) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_debug(1, "ast_waitfor returned <= 0 on chan %s\n", ast_channel_name(chan));
|
2011-04-18 16:27:14 +00:00
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
2008-01-03 06:16:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-18 16:27:14 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Read the channel control queue until it is dry so we can
|
|
|
|
* quit.
|
|
|
|
*/
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
if (0 < res) {
|
|
|
|
do {
|
|
|
|
cmd_status = async_agi_read_frame(chan);
|
|
|
|
if (cmd_status != AGI_RESULT_SUCCESS) {
|
|
|
|
returnstatus = cmd_status;
|
|
|
|
goto async_agi_done;
|
|
|
|
}
|
|
|
|
hungup = ast_check_hangup(chan);
|
|
|
|
} while (hungup);
|
|
|
|
} else {
|
|
|
|
hungup = ast_check_hangup(chan);
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-18 16:27:14 +00:00
|
|
|
async_agi_done:
|
2009-03-27 15:46:46 +00:00
|
|
|
|
|
|
|
if (async_agi.speech) {
|
|
|
|
ast_speech_destroy(async_agi.speech);
|
|
|
|
}
|
2012-09-28 22:11:19 +00:00
|
|
|
/* notify manager users this channel cannot be controlled anymore by Async AGI */
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ast_channel_publish_cached_blob(chan, agi_async_end_type(), NULL);
|
2008-01-03 06:16:48 +00:00
|
|
|
|
2011-04-18 16:27:14 +00:00
|
|
|
async_agi_abort:
|
2008-01-03 06:16:48 +00:00
|
|
|
/* close the pipe */
|
|
|
|
close(fds[0]);
|
|
|
|
close(fds[1]);
|
|
|
|
|
2011-04-13 22:54:08 +00:00
|
|
|
/*
|
|
|
|
* Intentionally do not remove the datastore added with
|
|
|
|
* add_to_agi() the from channel. There might be commands still
|
|
|
|
* in the queue or in-flight to us and AsyncAGI may get called
|
|
|
|
* again. The datastore destructor will be called on channel
|
|
|
|
* destruction anyway.
|
|
|
|
*/
|
2008-01-03 06:16:48 +00:00
|
|
|
|
2011-04-18 16:27:14 +00:00
|
|
|
if (returnstatus == AGI_RESULT_SUCCESS) {
|
|
|
|
returnstatus = AGI_RESULT_SUCCESS_ASYNC;
|
|
|
|
}
|
2008-01-03 06:16:48 +00:00
|
|
|
return returnstatus;
|
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
#undef AGI_BUF_SIZE
|
|
|
|
#undef AMI_BUF_SIZE
|
2008-01-03 06:16:48 +00:00
|
|
|
}
|
|
|
|
|
2013-02-22 19:40:02 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief Handle the connection that was started by launch_netscript.
|
|
|
|
*
|
|
|
|
* \param agiurl Url that we are trying to connect to.
|
|
|
|
* \param addr Address that host was resolved to.
|
|
|
|
* \param netsockfd File descriptor of socket.
|
|
|
|
*
|
|
|
|
* \retval 0 when connection is succesful.
|
|
|
|
* \retval 1 when there is an error.
|
|
|
|
*/
|
|
|
|
static int handle_connection(const char *agiurl, const struct ast_sockaddr addr, const int netsockfd)
|
|
|
|
{
|
|
|
|
struct pollfd pfds[1];
|
|
|
|
int res, conresult;
|
|
|
|
socklen_t reslen;
|
|
|
|
|
|
|
|
reslen = sizeof(conresult);
|
|
|
|
|
|
|
|
pfds[0].fd = netsockfd;
|
|
|
|
pfds[0].events = POLLOUT;
|
|
|
|
|
|
|
|
while ((res = ast_poll(pfds, 1, MAX_AGI_CONNECT)) != 1) {
|
|
|
|
if (errno != EINTR) {
|
|
|
|
if (!res) {
|
|
|
|
ast_log(LOG_WARNING, "FastAGI connection to '%s' timed out after MAX_AGI_CONNECT (%d) milliseconds.\n",
|
|
|
|
agiurl, MAX_AGI_CONNECT);
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getsockopt(pfds[0].fd, SOL_SOCKET, SO_ERROR, &conresult, &reslen) < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Connection to %s failed with error: %s\n",
|
|
|
|
ast_sockaddr_stringify(&addr), strerror(errno));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conresult) {
|
|
|
|
ast_log(LOG_WARNING, "Connecting to '%s' failed for url '%s': %s\n",
|
|
|
|
ast_sockaddr_stringify(&addr), agiurl, strerror(conresult));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-08 19:35:20 +00:00
|
|
|
/* launch_netscript: The fastagi handler.
|
|
|
|
FastAGI defaults to port 4573 */
|
2010-01-19 00:28:49 +00:00
|
|
|
static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds)
|
2004-09-22 15:21:36 +00:00
|
|
|
{
|
2013-02-22 19:40:02 +00:00
|
|
|
int s = 0, flags;
|
2012-02-29 20:31:48 +00:00
|
|
|
char *host, *script;
|
|
|
|
int num_addrs = 0, i = 0;
|
|
|
|
struct ast_sockaddr *addrs;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2010-01-19 00:28:49 +00:00
|
|
|
/* agiurl is "agi://host.domain[:port][/script/name]" */
|
2005-01-08 19:35:20 +00:00
|
|
|
host = ast_strdupa(agiurl + 6); /* Remove agi:// */
|
2012-02-29 20:31:48 +00:00
|
|
|
|
2004-09-22 15:21:36 +00:00
|
|
|
/* Strip off any script name */
|
2010-01-19 00:28:49 +00:00
|
|
|
if ((script = strchr(host, '/'))) {
|
|
|
|
*script++ = '\0';
|
|
|
|
} else {
|
|
|
|
script = "";
|
2004-09-22 15:21:36 +00:00
|
|
|
}
|
2010-01-19 00:28:49 +00:00
|
|
|
|
2012-02-29 20:31:48 +00:00
|
|
|
if (!(num_addrs = ast_sockaddr_resolve(&addrs, host, 0, AST_AF_UNSPEC))) {
|
2004-09-22 15:21:36 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to locate host '%s'\n", host);
|
2011-05-28 00:29:48 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2004-09-22 15:21:36 +00:00
|
|
|
}
|
2012-02-29 20:31:48 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_addrs; i++) {
|
|
|
|
if (!ast_sockaddr_port(&addrs[i])) {
|
|
|
|
ast_sockaddr_set_port(&addrs[i], AGI_PORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s = socket(addrs[i].ss.ss_family, SOCK_STREAM, IPPROTO_TCP)) < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags = fcntl(s, F_GETFL)) < 0) {
|
|
|
|
ast_log(LOG_WARNING, "fcntl(F_GETFL) failed: %s\n", strerror(errno));
|
|
|
|
close(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0) {
|
|
|
|
ast_log(LOG_WARNING, "fnctl(F_SETFL) failed: %s\n", strerror(errno));
|
|
|
|
close(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-02-22 19:40:02 +00:00
|
|
|
if (ast_connect(s, &addrs[i]) && errno == EINPROGRESS) {
|
|
|
|
|
|
|
|
if (handle_connection(agiurl, addrs[i], s)) {
|
|
|
|
close(s);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2012-02-29 20:31:48 +00:00
|
|
|
ast_log(LOG_WARNING, "Connection to %s failed with unexpected error: %s\n",
|
2013-02-22 19:40:02 +00:00
|
|
|
ast_sockaddr_stringify(&addrs[i]), strerror(errno));
|
2012-02-29 20:31:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2004-09-22 15:21:36 +00:00
|
|
|
}
|
2012-02-29 20:31:48 +00:00
|
|
|
|
|
|
|
ast_free(addrs);
|
|
|
|
|
|
|
|
if (i == num_addrs) {
|
|
|
|
ast_log(LOG_WARNING, "Couldn't connect to any host. FastAGI failed.\n");
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2004-09-22 15:21:36 +00:00
|
|
|
}
|
2006-02-15 00:38:27 +00:00
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
if (ast_agi_send(s, NULL, "agi_network: yes\n") < 0) {
|
2006-02-15 00:38:27 +00:00
|
|
|
if (errno != EINTR) {
|
|
|
|
ast_log(LOG_WARNING, "Connect to '%s' failed: %s\n", agiurl, strerror(errno));
|
|
|
|
close(s);
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2006-02-15 00:38:27 +00:00
|
|
|
}
|
2004-09-22 15:21:36 +00:00
|
|
|
}
|
2005-01-08 19:35:20 +00:00
|
|
|
|
|
|
|
/* If we have a script parameter, relay it to the fastagi server */
|
2006-10-17 23:06:13 +00:00
|
|
|
/* Script parameters take the form of: AGI(agi://my.example.com/?extension=${EXTEN}) */
|
2013-02-22 19:40:02 +00:00
|
|
|
if (!ast_strlen_zero(script)) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(s, NULL, "agi_network_script: %s\n", script);
|
2013-02-22 19:40:02 +00:00
|
|
|
}
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(4, "Wow, connected!\n");
|
2004-09-22 15:21:36 +00:00
|
|
|
fds[0] = s;
|
|
|
|
fds[1] = s;
|
2007-09-18 22:46:05 +00:00
|
|
|
return AGI_RESULT_SUCCESS_FAST;
|
2004-09-22 15:21:36 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 00:28:49 +00:00
|
|
|
/*!
|
|
|
|
* \internal
|
|
|
|
* \brief The HA fastagi handler.
|
|
|
|
* \param agiurl The request URL as passed to Agi() in the dial plan
|
|
|
|
* \param argv The parameters after the URL passed to Agi() in the dial plan
|
|
|
|
* \param fds Input/output file descriptors
|
|
|
|
*
|
|
|
|
* Uses SRV lookups to try to connect to a list of FastAGI servers. The hostname in
|
|
|
|
* the URI is prefixed with _agi._tcp. prior to the DNS resolution. For
|
|
|
|
* example, if you specify the URI \a hagi://agi.example.com/foo.agi the DNS
|
|
|
|
* query would be for \a _agi._tcp.agi.example.com and you'll need to make sure
|
|
|
|
* this resolves.
|
|
|
|
*
|
|
|
|
* This function parses the URI, resolves the SRV service name, forms new URIs
|
|
|
|
* with the results of the DNS lookup, and then calls launch_netscript on the
|
|
|
|
* new URIs until one succeeds.
|
|
|
|
*
|
|
|
|
* \return the result of the AGI operation.
|
|
|
|
*/
|
|
|
|
static enum agi_result launch_ha_netscript(char *agiurl, char *argv[], int *fds)
|
|
|
|
{
|
|
|
|
char *host, *script;
|
2011-05-28 00:29:48 +00:00
|
|
|
enum agi_result result;
|
2010-01-19 00:28:49 +00:00
|
|
|
struct srv_context *context = NULL;
|
|
|
|
int srv_ret;
|
|
|
|
char service[256];
|
|
|
|
char resolved_uri[1024];
|
|
|
|
const char *srvhost;
|
|
|
|
unsigned short srvport;
|
|
|
|
|
|
|
|
/* format of agiurl is "hagi://host.domain[:port][/script/name]" */
|
2012-07-31 20:21:43 +00:00
|
|
|
if (strlen(agiurl) < 7) { /* Remove hagi:// */
|
2010-01-19 00:28:49 +00:00
|
|
|
ast_log(LOG_WARNING, "An error occurred parsing the AGI URI: %s", agiurl);
|
|
|
|
return AGI_RESULT_FAILURE;
|
|
|
|
}
|
2012-07-31 20:21:43 +00:00
|
|
|
host = ast_strdupa(agiurl + 7);
|
2010-01-19 00:28:49 +00:00
|
|
|
|
|
|
|
/* Strip off any script name */
|
|
|
|
if ((script = strchr(host, '/'))) {
|
|
|
|
*script++ = '\0';
|
|
|
|
} else {
|
|
|
|
script = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strchr(host, ':')) {
|
|
|
|
ast_log(LOG_WARNING, "Specifying a port number disables SRV lookups: %s\n", agiurl);
|
|
|
|
return launch_netscript(agiurl + 1, argv, fds); /* +1 to strip off leading h from hagi:// */
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(service, sizeof(service), "%s%s", SRV_PREFIX, host);
|
|
|
|
|
|
|
|
while (!(srv_ret = ast_srv_lookup(&context, service, &srvhost, &srvport))) {
|
|
|
|
snprintf(resolved_uri, sizeof(resolved_uri), "agi://%s:%d/%s", srvhost, srvport, script);
|
|
|
|
result = launch_netscript(resolved_uri, argv, fds);
|
|
|
|
if (result == AGI_RESULT_FAILURE || result == AGI_RESULT_NOTFOUND) {
|
|
|
|
ast_log(LOG_WARNING, "AGI request failed for host '%s' (%s:%d)\n", host, srvhost, srvport);
|
|
|
|
} else {
|
2011-05-28 00:29:48 +00:00
|
|
|
/* The script launched so we must cleanup the context. */
|
|
|
|
ast_srv_cleanup(&context);
|
|
|
|
return result;
|
2010-01-19 00:28:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-28 00:29:48 +00:00
|
|
|
/*
|
|
|
|
* The DNS SRV lookup failed or we ran out of servers to check.
|
|
|
|
* ast_srv_lookup() has already cleaned up the context for us.
|
|
|
|
*/
|
2010-01-19 00:28:49 +00:00
|
|
|
if (srv_ret < 0) {
|
|
|
|
ast_log(LOG_WARNING, "SRV lookup failed for %s\n", agiurl);
|
2011-05-28 00:29:48 +00:00
|
|
|
}
|
2010-01-19 00:28:49 +00:00
|
|
|
|
2011-05-28 00:29:48 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2010-01-19 00:28:49 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 16:03:51 +00:00
|
|
|
static enum agi_result launch_script(struct ast_channel *chan, char *script, int argc, char *argv[], int *fds, int *efd, int *opid)
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
char tmp[256];
|
2008-04-16 22:57:54 +00:00
|
|
|
int pid, toast[2], fromast[2], audio[2], res;
|
2007-06-22 16:19:53 +00:00
|
|
|
struct stat st;
|
|
|
|
|
2010-01-19 00:28:49 +00:00
|
|
|
if (!strncasecmp(script, "agi://", 6)) {
|
|
|
|
return (efd == NULL) ? launch_netscript(script, argv, fds) : AGI_RESULT_FAILURE;
|
|
|
|
}
|
|
|
|
if (!strncasecmp(script, "hagi://", 7)) {
|
|
|
|
return (efd == NULL) ? launch_ha_netscript(script, argv, fds) : AGI_RESULT_FAILURE;
|
|
|
|
}
|
|
|
|
if (!strncasecmp(script, "agi:async", sizeof("agi:async") - 1)) {
|
2013-06-10 16:03:51 +00:00
|
|
|
return launch_asyncagi(chan, argc, argv, efd);
|
2010-01-19 00:28:49 +00:00
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
if (script[0] != '/') {
|
2006-11-04 01:40:49 +00:00
|
|
|
snprintf(tmp, sizeof(tmp), "%s/%s", ast_config_AST_AGI_DIR, script);
|
2001-09-28 13:19:43 +00:00
|
|
|
script = tmp;
|
|
|
|
}
|
2007-06-21 15:58:05 +00:00
|
|
|
|
|
|
|
/* Before even trying let's see if the file actually exists */
|
2007-06-22 16:19:53 +00:00
|
|
|
if (stat(script, &st)) {
|
2007-06-21 15:58:05 +00:00
|
|
|
ast_log(LOG_WARNING, "Failed to execute '%s': File does not exist.\n", script);
|
|
|
|
return AGI_RESULT_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
if (pipe(toast)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create toast pipe: %s\n",strerror(errno));
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
if (pipe(fromast)) {
|
|
|
|
ast_log(LOG_WARNING, "unable to create fromast pipe: %s\n", strerror(errno));
|
|
|
|
close(toast[0]);
|
|
|
|
close(toast[1]);
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2003-02-23 06:00:11 +00:00
|
|
|
if (efd) {
|
|
|
|
if (pipe(audio)) {
|
|
|
|
ast_log(LOG_WARNING, "unable to create audio pipe: %s\n", strerror(errno));
|
|
|
|
close(fromast[0]);
|
|
|
|
close(fromast[1]);
|
|
|
|
close(toast[0]);
|
|
|
|
close(toast[1]);
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2003-02-23 06:00:11 +00:00
|
|
|
}
|
|
|
|
res = fcntl(audio[1], F_GETFL);
|
2008-06-18 00:33:31 +00:00
|
|
|
if (res > -1)
|
2003-02-23 06:00:11 +00:00
|
|
|
res = fcntl(audio[1], F_SETFL, res | O_NONBLOCK);
|
|
|
|
if (res < 0) {
|
|
|
|
ast_log(LOG_WARNING, "unable to set audio pipe parameters: %s\n", strerror(errno));
|
|
|
|
close(fromast[0]);
|
|
|
|
close(fromast[1]);
|
|
|
|
close(toast[0]);
|
|
|
|
close(toast[1]);
|
|
|
|
close(audio[0]);
|
|
|
|
close(audio[1]);
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2003-02-23 06:00:11 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-11 00:52:19 +00:00
|
|
|
|
2008-04-16 22:57:54 +00:00
|
|
|
if ((pid = ast_safe_fork(1)) < 0) {
|
2001-09-28 13:19:43 +00:00
|
|
|
ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
if (!pid) {
|
2006-01-21 05:22:18 +00:00
|
|
|
/* Pass paths to AGI via environmental variables */
|
|
|
|
setenv("AST_CONFIG_DIR", ast_config_AST_CONFIG_DIR, 1);
|
|
|
|
setenv("AST_CONFIG_FILE", ast_config_AST_CONFIG_FILE, 1);
|
|
|
|
setenv("AST_MODULE_DIR", ast_config_AST_MODULE_DIR, 1);
|
|
|
|
setenv("AST_SPOOL_DIR", ast_config_AST_SPOOL_DIR, 1);
|
|
|
|
setenv("AST_MONITOR_DIR", ast_config_AST_MONITOR_DIR, 1);
|
|
|
|
setenv("AST_VAR_DIR", ast_config_AST_VAR_DIR, 1);
|
2006-04-15 22:53:53 +00:00
|
|
|
setenv("AST_DATA_DIR", ast_config_AST_DATA_DIR, 1);
|
2006-01-21 05:22:18 +00:00
|
|
|
setenv("AST_LOG_DIR", ast_config_AST_LOG_DIR, 1);
|
|
|
|
setenv("AST_AGI_DIR", ast_config_AST_AGI_DIR, 1);
|
|
|
|
setenv("AST_KEY_DIR", ast_config_AST_KEY_DIR, 1);
|
|
|
|
setenv("AST_RUN_DIR", ast_config_AST_RUN_DIR, 1);
|
|
|
|
|
2006-06-12 15:30:32 +00:00
|
|
|
/* Don't run AGI scripts with realtime priority -- it causes audio stutter */
|
|
|
|
ast_set_priority(0);
|
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
/* Redirect stdin and out, provide enhanced audio channel if desired */
|
2001-09-28 13:19:43 +00:00
|
|
|
dup2(fromast[0], STDIN_FILENO);
|
|
|
|
dup2(toast[1], STDOUT_FILENO);
|
2007-07-11 21:09:42 +00:00
|
|
|
if (efd)
|
2003-02-23 06:00:11 +00:00
|
|
|
dup2(audio[0], STDERR_FILENO + 1);
|
2007-07-11 21:09:42 +00:00
|
|
|
else
|
2003-02-23 06:00:11 +00:00
|
|
|
close(STDERR_FILENO + 1);
|
2006-12-11 00:52:19 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
/* Close everything but stdin/out/error */
|
2008-04-16 22:57:54 +00:00
|
|
|
ast_close_fds_above_n(STDERR_FILENO + 1);
|
2005-08-03 04:17:12 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
/* Execute script */
|
2006-10-17 23:06:13 +00:00
|
|
|
/* XXX argv should be deprecated in favor of passing agi_argX paramaters */
|
2004-03-23 12:50:15 +00:00
|
|
|
execv(script, argv);
|
2003-02-06 22:11:43 +00:00
|
|
|
/* Can't use ast_log since FD's are closed */
|
2008-04-16 22:57:54 +00:00
|
|
|
ast_child_verbose(1, "Failed to execute '%s': %s", script, strerror(errno));
|
2008-04-17 12:59:04 +00:00
|
|
|
/* Special case to set status of AGI to failure */
|
|
|
|
fprintf(stdout, "failure\n");
|
2006-02-01 20:40:45 +00:00
|
|
|
fflush(stdout);
|
2006-10-27 17:42:57 +00:00
|
|
|
_exit(1);
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "Launched AGI Script %s\n", script);
|
2001-09-28 13:19:43 +00:00
|
|
|
fds[0] = toast[0];
|
|
|
|
fds[1] = fromast[1];
|
2007-07-11 21:09:42 +00:00
|
|
|
if (efd)
|
2003-02-23 06:00:11 +00:00
|
|
|
*efd = audio[1];
|
2001-09-28 13:19:43 +00:00
|
|
|
/* close what we're not using in the parent */
|
|
|
|
close(toast[1]);
|
|
|
|
close(fromast[0]);
|
2003-12-27 23:39:57 +00:00
|
|
|
|
2006-05-25 16:44:22 +00:00
|
|
|
if (efd)
|
2004-01-01 00:26:11 +00:00
|
|
|
close(audio[0]);
|
2003-12-27 23:39:57 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
*opid = pid;
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_SUCCESS;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2006-10-17 23:06:13 +00:00
|
|
|
static void setup_env(struct ast_channel *chan, char *request, int fd, int enhanced, int argc, char *argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2006-10-17 23:06:13 +00:00
|
|
|
int count;
|
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
/* Print initial environment, with agi_request always being the first
|
|
|
|
thing */
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_request: %s\n", request);
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_channel: %s\n", ast_channel_name(chan));
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_language: %s\n", ast_channel_language(chan));
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_type: %s\n", ast_channel_tech(chan)->type);
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_uniqueid: %s\n", ast_channel_uniqueid(chan));
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_version: %s\n", ast_get_version());
|
2001-09-28 13:19:43 +00:00
|
|
|
|
|
|
|
/* ANI/DNIS */
|
2010-07-14 15:48:36 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_callerid: %s\n",
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, "unknown"));
|
2010-07-14 15:48:36 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_calleridname: %s\n",
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.name.valid, ast_channel_caller(chan)->id.name.str, "unknown"));
|
2010-07-14 15:48:36 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_callingpres: %d\n",
|
2012-02-29 16:52:47 +00:00
|
|
|
ast_party_id_presentation(&ast_channel_caller(chan)->id));
|
|
|
|
ast_agi_send(fd, chan, "agi_callingani2: %d\n", ast_channel_caller(chan)->ani2);
|
|
|
|
ast_agi_send(fd, chan, "agi_callington: %d\n", ast_channel_caller(chan)->id.number.plan);
|
|
|
|
ast_agi_send(fd, chan, "agi_callingtns: %d\n", ast_channel_dialed(chan)->transit_network_select);
|
|
|
|
ast_agi_send(fd, chan, "agi_dnid: %s\n", S_OR(ast_channel_dialed(chan)->number.str, "unknown"));
|
2010-07-14 15:48:36 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_rdnis: %s\n",
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_redirecting(chan)->from.number.valid, ast_channel_redirecting(chan)->from.number.str, "unknown"));
|
2001-09-28 13:19:43 +00:00
|
|
|
|
|
|
|
/* Context information */
|
2012-02-13 17:27:06 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_context: %s\n", ast_channel_context(chan));
|
|
|
|
ast_agi_send(fd, chan, "agi_extension: %s\n", ast_channel_exten(chan));
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_priority: %d\n", ast_channel_priority(chan));
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0");
|
2001-09-28 13:19:43 +00:00
|
|
|
|
2005-01-08 19:35:20 +00:00
|
|
|
/* User information */
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_accountcode: %s\n", ast_channel_accountcode(chan) ? ast_channel_accountcode(chan) : "");
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_threadid: %ld\n", (long)pthread_self());
|
2007-07-23 22:02:05 +00:00
|
|
|
|
2006-10-17 23:06:13 +00:00
|
|
|
/* Send any parameters to the fastagi server that have been passed via the agi application */
|
|
|
|
/* Agi application paramaters take the form of: AGI(/path/to/example/script|${EXTEN}) */
|
|
|
|
for(count = 1; count < argc; count++)
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(fd, chan, "agi_arg_%d: %s\n", count, argv[count]);
|
2006-10-17 23:06:13 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
/* End with empty return */
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(fd, chan, "\n");
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_answer(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2002-06-14 15:50:42 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* Answer the channel */
|
2012-02-20 23:43:27 +00:00
|
|
|
if (ast_channel_state(chan) != AST_STATE_UP)
|
2002-06-14 15:50:42 +00:00
|
|
|
res = ast_answer(chan);
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2002-06-14 15:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_asyncagi_break(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2009-05-04 19:29:13 +00:00
|
|
|
{
|
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2011-04-18 16:27:14 +00:00
|
|
|
return ASYNC_AGI_BREAK;
|
2009-05-04 19:29:13 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_waitfordigit(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2010-11-22 18:43:31 +00:00
|
|
|
int res, to;
|
|
|
|
|
|
|
|
if (argc != 4)
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[3], "%30d", &to) != 1)
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2010-11-22 18:43:31 +00:00
|
|
|
res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
|
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_sendtext(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
int res;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2001-12-27 11:07:33 +00:00
|
|
|
/* At the moment, the parser (perhaps broken) returns with
|
|
|
|
the last argument PLUS the newline at the end of the input
|
|
|
|
buffer. This probably needs to be fixed, but I wont do that
|
|
|
|
because other stuff may break as a result. The right way
|
|
|
|
would probably be to strip off the trailing newline before
|
|
|
|
parsing, then here, add a newline at the end of the string
|
|
|
|
before sending it to ast_sendtext --DUDE */
|
2001-09-28 13:19:43 +00:00
|
|
|
res = ast_sendtext(chan, argv[2]);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_recvchar(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-12-27 11:07:33 +00:00
|
|
|
{
|
|
|
|
int res;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2001-12-27 11:07:33 +00:00
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2001-12-27 11:07:33 +00:00
|
|
|
res = ast_recvchar(chan,atoi(argv[2]));
|
|
|
|
if (res == 0) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (timeout)\n", res);
|
2001-12-27 11:07:33 +00:00
|
|
|
return RESULT_SUCCESS;
|
2008-06-18 00:33:31 +00:00
|
|
|
}
|
2001-12-27 11:07:33 +00:00
|
|
|
if (res > 0) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2001-12-27 11:07:33 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (hangup)\n", res);
|
2008-05-14 11:51:09 +00:00
|
|
|
return RESULT_FAILURE;
|
2001-12-27 11:07:33 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_recvtext(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2005-06-21 01:16:18 +00:00
|
|
|
{
|
|
|
|
char *buf;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2005-06-21 01:16:18 +00:00
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2008-05-14 11:51:09 +00:00
|
|
|
buf = ast_recvtext(chan, atoi(argv[2]));
|
2005-06-21 01:16:18 +00:00
|
|
|
if (buf) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", buf);
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(buf);
|
2008-06-18 00:33:31 +00:00
|
|
|
} else {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1\n");
|
2005-06-21 01:16:18 +00:00
|
|
|
}
|
2005-07-11 20:40:02 +00:00
|
|
|
return RESULT_SUCCESS;
|
2005-06-21 01:16:18 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_tddmode(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-12-27 11:07:33 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res, x;
|
|
|
|
|
2001-12-27 11:07:33 +00:00
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2008-05-14 11:51:09 +00:00
|
|
|
if (!strncasecmp(argv[2],"on",2)) {
|
2008-06-18 00:33:31 +00:00
|
|
|
x = 1;
|
2008-05-14 11:51:09 +00:00
|
|
|
} else {
|
2005-01-08 19:35:20 +00:00
|
|
|
x = 0;
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
|
|
|
if (!strncasecmp(argv[2],"mate",4)) {
|
2005-01-08 19:35:20 +00:00
|
|
|
x = 2;
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
|
|
|
if (!strncasecmp(argv[2],"tdd",3)) {
|
2005-01-08 19:35:20 +00:00
|
|
|
x = 1;
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2005-01-08 19:35:20 +00:00
|
|
|
res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
|
2011-04-13 17:51:14 +00:00
|
|
|
if (res) {
|
|
|
|
/* Set channel option failed */
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2008-05-14 11:51:09 +00:00
|
|
|
} else {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2005-06-05 21:00:33 +00:00
|
|
|
return RESULT_SUCCESS;
|
2001-12-27 11:07:33 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_sendimage(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
int res;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2008-05-14 11:51:09 +00:00
|
|
|
if (argc != 3) {
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
res = ast_send_image(chan, argv[2]);
|
2008-05-14 11:51:09 +00:00
|
|
|
if (!ast_check_hangup(chan)) {
|
2001-09-28 13:19:43 +00:00
|
|
|
res = 0;
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_controlstreamfile(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2005-08-22 21:59:24 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res = 0, skipms = 3000;
|
2009-05-21 21:13:09 +00:00
|
|
|
const char *fwd = "#", *rev = "*", *suspend = NULL, *stop = NULL; /* Default values */
|
2013-01-22 15:16:20 +00:00
|
|
|
char stopkeybuf[2];
|
|
|
|
long offsetms = 0;
|
|
|
|
char offsetbuf[20];
|
2005-08-22 21:59:24 +00:00
|
|
|
|
2013-07-31 23:48:35 +00:00
|
|
|
if (argc < 5 || argc > 10) {
|
2005-08-22 21:59:24 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2005-08-22 21:59:24 +00:00
|
|
|
|
2008-05-14 11:51:09 +00:00
|
|
|
if (!ast_strlen_zero(argv[4])) {
|
2005-08-22 21:59:24 +00:00
|
|
|
stop = argv[4];
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2009-08-10 19:20:57 +00:00
|
|
|
if ((argc > 5) && (sscanf(argv[5], "%30d", &skipms) != 1)) {
|
2005-08-22 21:59:24 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2005-08-22 21:59:24 +00:00
|
|
|
|
2008-05-14 11:51:09 +00:00
|
|
|
if (argc > 6 && !ast_strlen_zero(argv[6])) {
|
2005-08-22 21:59:24 +00:00
|
|
|
fwd = argv[6];
|
2008-06-18 00:33:31 +00:00
|
|
|
}
|
2005-08-22 21:59:24 +00:00
|
|
|
|
2008-05-14 11:51:09 +00:00
|
|
|
if (argc > 7 && !ast_strlen_zero(argv[7])) {
|
2005-08-22 21:59:24 +00:00
|
|
|
rev = argv[7];
|
2008-05-14 11:51:09 +00:00
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2008-05-14 11:51:09 +00:00
|
|
|
if (argc > 8 && !ast_strlen_zero(argv[8])) {
|
2008-08-10 00:47:56 +00:00
|
|
|
suspend = argv[8];
|
2008-06-18 00:33:31 +00:00
|
|
|
}
|
|
|
|
|
2013-07-31 23:48:35 +00:00
|
|
|
if (argc > 9 && (sscanf(argv[9], "%30ld", &offsetms) != 1)) {
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = ast_control_streamfile(chan, argv[3], fwd, rev, stop, suspend, NULL, skipms, &offsetms);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2013-01-22 15:16:20 +00:00
|
|
|
/* If we stopped on one of our stop keys, return 0 */
|
|
|
|
if (res > 0 && stop && strchr(stop, res)) {
|
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
|
|
|
|
snprintf(stopkeybuf, sizeof(stopkeybuf), "%c", res);
|
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTOPKEY", stopkeybuf);
|
|
|
|
} else if (res > 0 && res == AST_CONTROL_STREAM_STOP) {
|
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "REMOTESTOPPED");
|
|
|
|
res = 0;
|
|
|
|
} else {
|
|
|
|
if (res < 0) {
|
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
|
|
|
|
} else {
|
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(offsetbuf, sizeof(offsetbuf), "%ld", offsetms);
|
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKOFFSET", offsetbuf);
|
|
|
|
|
2013-07-31 23:48:35 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, offsetms);
|
2005-08-22 21:59:24 +00:00
|
|
|
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2005-08-22 21:59:24 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2011-05-03 20:45:32 +00:00
|
|
|
int res;
|
2007-07-11 21:09:42 +00:00
|
|
|
struct ast_filestream *fs, *vfs;
|
|
|
|
long sample_offset = 0, max_length;
|
2009-05-21 21:13:09 +00:00
|
|
|
const char *edigits = "";
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2011-09-29 09:32:34 +00:00
|
|
|
if (argc < 4 || argc > 5) {
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2011-09-29 09:32:34 +00:00
|
|
|
}
|
2006-07-20 16:18:07 +00:00
|
|
|
|
2011-09-29 09:32:34 +00:00
|
|
|
if (argv[3]) {
|
2006-07-20 16:18:07 +00:00
|
|
|
edigits = argv[3];
|
2011-09-29 09:32:34 +00:00
|
|
|
}
|
2006-07-20 16:18:07 +00:00
|
|
|
|
2011-09-29 09:32:34 +00:00
|
|
|
if ((argc > 4) && (sscanf(argv[4], "%30ld", &sample_offset) != 1)) {
|
2003-02-06 22:11:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2011-09-29 09:32:34 +00:00
|
|
|
}
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
if (!(fs = ast_openstream(chan, argv[2], ast_channel_language(chan)))) {
|
2013-07-18 12:54:50 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1 endpos=%ld\n", sample_offset);
|
|
|
|
return RESULT_FAILURE;
|
2007-09-10 13:41:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
if ((vfs = ast_openvstream(chan, argv[2], ast_channel_language(chan)))) {
|
2007-09-10 13:41:54 +00:00
|
|
|
ast_debug(1, "Ooh, found a video stream, too\n");
|
2011-09-29 09:32:34 +00:00
|
|
|
}
|
2014-12-12 22:54:02 +00:00
|
|
|
ast_verb(3, "<%s> Playing '%s.%s' (escape_digits=%s) (sample_offset %ld) (language '%s')\n",
|
|
|
|
ast_channel_name(chan), argv[2], ast_format_get_name(ast_channel_writeformat(chan)),
|
|
|
|
edigits, sample_offset, S_OR(ast_channel_language(chan), "default"));
|
2006-07-20 16:18:07 +00:00
|
|
|
|
2003-02-06 22:11:43 +00:00
|
|
|
ast_seekstream(fs, 0, SEEK_END);
|
|
|
|
max_length = ast_tellstream(fs);
|
|
|
|
ast_seekstream(fs, sample_offset, SEEK_SET);
|
|
|
|
res = ast_applystream(chan, fs);
|
2011-09-29 09:32:34 +00:00
|
|
|
if (vfs) {
|
2011-05-03 20:45:32 +00:00
|
|
|
ast_applystream(chan, vfs);
|
2011-09-29 09:32:34 +00:00
|
|
|
}
|
2007-06-22 15:03:32 +00:00
|
|
|
ast_playstream(fs);
|
2011-09-29 09:32:34 +00:00
|
|
|
if (vfs) {
|
2007-06-22 15:03:32 +00:00
|
|
|
ast_playstream(vfs);
|
2011-09-29 09:32:34 +00:00
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
|
2003-02-06 22:11:43 +00:00
|
|
|
/* this is to check for if ast_waitstream closed the stream, we probably are at
|
|
|
|
* the end of the stream, return that amount, else check for the amount */
|
2012-02-20 23:43:27 +00:00
|
|
|
sample_offset = (ast_channel_stream(chan)) ? ast_tellstream(fs) : max_length;
|
2002-06-14 15:50:42 +00:00
|
|
|
ast_stopstream(chan);
|
2003-02-23 06:00:11 +00:00
|
|
|
if (res == 1) {
|
|
|
|
/* Stop this command, don't print a result line, as there is a new command */
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
|
2013-01-22 15:16:20 +00:00
|
|
|
pbx_builtin_setvar_helper(chan, "PLAYBACKSTATUS", res ? "FAILED" : "SUCCESS");
|
|
|
|
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 10:19:09 +00:00
|
|
|
/*! \brief get option - really similar to the handle_streamfile, but with a timeout */
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2004-11-16 03:37:07 +00:00
|
|
|
{
|
2011-05-03 20:45:32 +00:00
|
|
|
int res;
|
2007-07-11 21:09:42 +00:00
|
|
|
struct ast_filestream *fs, *vfs;
|
|
|
|
long sample_offset = 0, max_length;
|
2004-11-16 03:37:07 +00:00
|
|
|
int timeout = 0;
|
2009-05-21 21:13:09 +00:00
|
|
|
const char *edigits = "";
|
2004-11-16 03:37:07 +00:00
|
|
|
|
|
|
|
if ( argc < 4 || argc > 5 )
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
if ( argv[3] )
|
2004-11-16 03:37:07 +00:00
|
|
|
edigits = argv[3];
|
|
|
|
|
|
|
|
if ( argc == 5 )
|
|
|
|
timeout = atoi(argv[4]);
|
2012-02-20 23:43:27 +00:00
|
|
|
else if (ast_channel_pbx(chan)->dtimeoutms) {
|
2004-11-16 03:37:07 +00:00
|
|
|
/* by default dtimeout is set to 5sec */
|
2012-02-20 23:43:27 +00:00
|
|
|
timeout = ast_channel_pbx(chan)->dtimeoutms; /* in msec */
|
2004-11-16 03:37:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
if (!(fs = ast_openstream(chan, argv[2], ast_channel_language(chan)))) {
|
2013-07-18 12:54:50 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1 endpos=%ld\n", sample_offset);
|
2006-05-26 17:43:11 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
|
2013-07-18 12:54:50 +00:00
|
|
|
return RESULT_FAILURE;
|
2006-05-26 17:43:11 +00:00
|
|
|
}
|
2007-09-10 13:41:54 +00:00
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
if ((vfs = ast_openvstream(chan, argv[2], ast_channel_language(chan))))
|
2007-09-10 13:41:54 +00:00
|
|
|
ast_debug(1, "Ooh, found a video stream, too\n");
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "Playing '%s' (escape_digits=%s) (timeout %d)\n", argv[2], edigits, timeout);
|
2004-11-16 03:37:07 +00:00
|
|
|
|
2006-05-26 17:43:11 +00:00
|
|
|
ast_seekstream(fs, 0, SEEK_END);
|
|
|
|
max_length = ast_tellstream(fs);
|
|
|
|
ast_seekstream(fs, sample_offset, SEEK_SET);
|
|
|
|
res = ast_applystream(chan, fs);
|
|
|
|
if (vfs)
|
2011-05-03 20:45:32 +00:00
|
|
|
ast_applystream(chan, vfs);
|
2007-06-22 15:03:32 +00:00
|
|
|
ast_playstream(fs);
|
2006-05-26 17:43:11 +00:00
|
|
|
if (vfs)
|
2007-06-22 15:03:32 +00:00
|
|
|
ast_playstream(vfs);
|
|
|
|
|
2006-05-26 17:43:11 +00:00
|
|
|
res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl);
|
|
|
|
/* this is to check for if ast_waitstream closed the stream, we probably are at
|
|
|
|
* the end of the stream, return that amount, else check for the amount */
|
2012-02-20 23:43:27 +00:00
|
|
|
sample_offset = (ast_channel_stream(chan))?ast_tellstream(fs):max_length;
|
2006-05-26 17:43:11 +00:00
|
|
|
ast_stopstream(chan);
|
|
|
|
if (res == 1) {
|
|
|
|
/* Stop this command, don't print a result line, as there is a new command */
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2004-11-16 03:37:07 +00:00
|
|
|
|
|
|
|
/* If the user didnt press a key, wait for digitTimeout*/
|
|
|
|
if (res == 0 ) {
|
|
|
|
res = ast_waitfordigit_full(chan, timeout, agi->audio, agi->ctrl);
|
|
|
|
/* Make sure the new result is in the escape digits of the GET OPTION */
|
|
|
|
if ( !strchr(edigits,res) )
|
2006-05-26 17:43:11 +00:00
|
|
|
res=0;
|
2004-11-16 03:37:07 +00:00
|
|
|
}
|
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d endpos=%ld\n", res, sample_offset);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2004-11-16 03:37:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-14 10:19:09 +00:00
|
|
|
/*! \brief Say number in various language syntaxes */
|
2006-11-04 01:40:49 +00:00
|
|
|
/* While waiting, we're sending a NULL. */
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res, num;
|
|
|
|
|
2007-05-11 16:16:50 +00:00
|
|
|
if (argc < 4 || argc > 5)
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[2], "%30d", &num) != 1)
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_say_number_full(chan, num, argv[3], ast_channel_language(chan), argc > 4 ? argv[4] : NULL, agi->audio, agi->ctrl);
|
2003-02-23 06:00:11 +00:00
|
|
|
if (res == 1)
|
|
|
|
return RESULT_SUCCESS;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_saydigits(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2002-06-14 15:50:42 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res, num;
|
2004-05-03 00:54:16 +00:00
|
|
|
|
2002-06-14 15:50:42 +00:00
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[2], "%30d", &num) != 1)
|
2002-06-14 15:50:42 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2004-05-03 00:54:16 +00:00
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_say_digit_str_full(chan, argv[2], argv[3], ast_channel_language(chan), agi->audio, agi->ctrl);
|
2003-02-23 06:00:11 +00:00
|
|
|
if (res == 1) /* New command */
|
|
|
|
return RESULT_SUCCESS;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2002-06-14 15:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_sayalpha(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2004-12-14 18:39:25 +00:00
|
|
|
{
|
|
|
|
int res;
|
2013-08-22 22:33:48 +00:00
|
|
|
int sensitivity = AST_SAY_CASE_NONE;
|
2004-12-14 18:39:25 +00:00
|
|
|
|
2013-08-22 22:33:48 +00:00
|
|
|
if (argc < 4 || argc > 5) {
|
2004-12-14 18:39:25 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2013-08-22 22:33:48 +00:00
|
|
|
}
|
2004-12-14 18:39:25 +00:00
|
|
|
|
2013-08-22 22:33:48 +00:00
|
|
|
if (argc > 4) {
|
|
|
|
switch (argv[4][0]) {
|
|
|
|
case 'a':
|
|
|
|
case 'A':
|
|
|
|
sensitivity = AST_SAY_CASE_ALL;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
case 'L':
|
|
|
|
sensitivity = AST_SAY_CASE_LOWER;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
|
|
|
sensitivity = AST_SAY_CASE_NONE;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
case 'U':
|
|
|
|
sensitivity = AST_SAY_CASE_UPPER;
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res = ast_say_character_str_full(chan, argv[2], argv[3], ast_channel_language(chan), sensitivity, agi->audio, agi->ctrl);
|
2004-12-14 18:39:25 +00:00
|
|
|
if (res == 1) /* New command */
|
|
|
|
return RESULT_SUCCESS;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2004-12-14 18:39:25 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_saydate(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2005-03-30 07:00:49 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res, num;
|
|
|
|
|
2005-03-30 07:00:49 +00:00
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[2], "%30d", &num) != 1)
|
2005-03-30 07:00:49 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_say_date(chan, num, argv[3], ast_channel_language(chan));
|
2005-03-30 07:00:49 +00:00
|
|
|
if (res == 1)
|
|
|
|
return RESULT_SUCCESS;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2005-03-30 07:00:49 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_saytime(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2004-02-27 08:30:30 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res, num;
|
|
|
|
|
2004-02-27 08:30:30 +00:00
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[2], "%30d", &num) != 1)
|
2004-02-27 08:30:30 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_say_time(chan, num, argv[3], ast_channel_language(chan));
|
2004-02-27 08:30:30 +00:00
|
|
|
if (res == 1)
|
|
|
|
return RESULT_SUCCESS;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-02-15 00:24:24 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2004-02-27 08:30:30 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_saydatetime(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2005-04-11 03:23:54 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res = 0;
|
2006-02-15 00:24:24 +00:00
|
|
|
time_t unixtime;
|
2009-05-21 21:13:09 +00:00
|
|
|
const char *format, *zone = NULL;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2005-04-11 03:23:54 +00:00
|
|
|
if (argc < 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
|
|
|
|
if (argc > 4) {
|
|
|
|
format = argv[4];
|
|
|
|
} else {
|
2006-04-06 16:17:04 +00:00
|
|
|
/* XXX this doesn't belong here, but in the 'say' module */
|
2012-01-24 20:12:09 +00:00
|
|
|
if (!strcasecmp(ast_channel_language(chan), "de")) {
|
2005-04-11 03:23:54 +00:00
|
|
|
format = "A dBY HMS";
|
|
|
|
} else {
|
2008-06-18 00:33:31 +00:00
|
|
|
format = "ABdY 'digits/at' IMp";
|
2005-04-11 03:23:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 5 && !ast_strlen_zero(argv[5]))
|
|
|
|
zone = argv[5];
|
|
|
|
|
2006-02-23 17:13:57 +00:00
|
|
|
if (ast_get_time_t(argv[2], &unixtime, 0, NULL))
|
2005-04-11 03:23:54 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_say_date_with_format(chan, unixtime, argv[3], ast_channel_language(chan), format, zone);
|
2005-04-11 03:23:54 +00:00
|
|
|
if (res == 1)
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-02-15 00:24:24 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2005-04-11 03:23:54 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_sayphonetic(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2004-05-03 00:54:16 +00:00
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_say_phonetic_str_full(chan, argv[2], argv[3], ast_channel_language(chan), agi->audio, agi->ctrl);
|
2004-05-03 00:54:16 +00:00
|
|
|
if (res == 1) /* New command */
|
|
|
|
return RESULT_SUCCESS;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2006-04-06 16:17:04 +00:00
|
|
|
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
|
2004-05-03 00:54:16 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_getdata(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int res, max, timeout;
|
2003-02-14 06:00:11 +00:00
|
|
|
char data[1024];
|
2001-09-28 13:19:43 +00:00
|
|
|
|
|
|
|
if (argc < 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2005-01-08 19:35:20 +00:00
|
|
|
if (argc >= 4)
|
2008-06-18 00:33:31 +00:00
|
|
|
timeout = atoi(argv[3]);
|
2005-01-08 19:35:20 +00:00
|
|
|
else
|
|
|
|
timeout = 0;
|
2008-06-18 00:33:31 +00:00
|
|
|
if (argc >= 5)
|
|
|
|
max = atoi(argv[4]);
|
2005-01-08 19:35:20 +00:00
|
|
|
else
|
|
|
|
max = 1024;
|
2003-02-23 06:00:11 +00:00
|
|
|
res = ast_app_getdata_full(chan, argv[2], data, max, timeout, agi->audio, agi->ctrl);
|
|
|
|
if (res == 2) /* New command */
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
else if (res == 1)
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%s (timeout)\n", data);
|
2004-06-04 19:01:07 +00:00
|
|
|
else if (res < 0 )
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1\n");
|
2001-09-28 13:19:43 +00:00
|
|
|
else
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%s\n", data);
|
2005-03-28 07:08:39 +00:00
|
|
|
return RESULT_SUCCESS;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_setcontext(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2012-02-13 17:27:06 +00:00
|
|
|
ast_channel_context_set(chan, argv[2]);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_setextension(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2012-02-13 17:27:06 +00:00
|
|
|
ast_channel_exten_set(chan, argv[2]);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_setpriority(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
int pri;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
if (argc != 3)
|
2008-06-18 00:33:31 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2005-05-19 02:57:45 +00:00
|
|
|
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[2], "%30d", &pri) != 1) {
|
2012-02-13 17:27:06 +00:00
|
|
|
pri = ast_findlabel_extension(chan, ast_channel_context(chan), ast_channel_exten(chan), argv[2],
|
2012-02-29 16:52:47 +00:00
|
|
|
S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL));
|
2010-07-14 15:48:36 +00:00
|
|
|
if (pri < 1)
|
2005-05-19 02:57:45 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_explicit_goto(chan, NULL, NULL, pri);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_recordfile(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
struct ast_filestream *fs;
|
2002-09-04 16:53:39 +00:00
|
|
|
struct ast_frame *f;
|
2005-07-15 23:00:47 +00:00
|
|
|
struct timeval start;
|
2003-02-06 22:11:43 +00:00
|
|
|
long sample_offset = 0;
|
2002-09-04 16:53:39 +00:00
|
|
|
int res = 0;
|
|
|
|
int ms;
|
2001-09-28 13:19:43 +00:00
|
|
|
|
2007-07-23 22:02:05 +00:00
|
|
|
struct ast_dsp *sildet=NULL; /* silence detector dsp */
|
|
|
|
int totalsilence = 0;
|
|
|
|
int dspsilence = 0;
|
|
|
|
int silence = 0; /* amount of silence to allow */
|
|
|
|
int gotsilence = 0; /* did we timeout for silence? */
|
2008-06-18 00:33:31 +00:00
|
|
|
char *silencestr = NULL;
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
RAII_VAR(struct ast_format *, rfmt, NULL, ao2_cleanup);
|
2003-05-01 03:52:45 +00:00
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
/* XXX EAGI FIXME XXX */
|
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
if (argc < 6)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[5], "%30d", &ms) != 1)
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2003-05-01 03:52:45 +00:00
|
|
|
|
|
|
|
if (argc > 6)
|
|
|
|
silencestr = strchr(argv[6],'s');
|
|
|
|
if ((argc > 7) && (!silencestr))
|
|
|
|
silencestr = strchr(argv[7],'s');
|
|
|
|
if ((argc > 8) && (!silencestr))
|
|
|
|
silencestr = strchr(argv[8],'s');
|
|
|
|
|
|
|
|
if (silencestr) {
|
|
|
|
if (strlen(silencestr) > 2) {
|
|
|
|
if ((silencestr[0] == 's') && (silencestr[1] == '=')) {
|
|
|
|
silencestr++;
|
|
|
|
silencestr++;
|
|
|
|
if (silencestr)
|
2007-07-23 22:02:05 +00:00
|
|
|
silence = atoi(silencestr);
|
|
|
|
if (silence > 0)
|
|
|
|
silence *= 1000;
|
|
|
|
}
|
2003-05-01 03:52:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-23 22:02:05 +00:00
|
|
|
if (silence > 0) {
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
rfmt = ao2_bump(ast_channel_readformat(chan));
|
|
|
|
res = ast_set_read_format(chan, ast_format_slin);
|
2007-07-23 22:02:05 +00:00
|
|
|
if (res < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
|
2011-04-13 16:37:06 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
|
|
|
return RESULT_FAILURE;
|
2007-07-23 22:02:05 +00:00
|
|
|
}
|
|
|
|
sildet = ast_dsp_new();
|
|
|
|
if (!sildet) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
|
2011-04-13 16:37:06 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1\n");
|
|
|
|
return RESULT_FAILURE;
|
2007-07-23 22:02:05 +00:00
|
|
|
}
|
2008-03-05 16:23:44 +00:00
|
|
|
ast_dsp_set_threshold(sildet, ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE));
|
2007-07-23 22:02:05 +00:00
|
|
|
}
|
2013-07-31 23:48:35 +00:00
|
|
|
|
2003-02-06 22:11:43 +00:00
|
|
|
/* backward compatibility, if no offset given, arg[6] would have been
|
|
|
|
* caught below and taken to be a beep, else if it is a digit then it is a
|
|
|
|
* offset */
|
2009-08-10 19:20:57 +00:00
|
|
|
if ((argc >6) && (sscanf(argv[6], "%30ld", &sample_offset) != 1) && (!strchr(argv[6], '=')))
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_streamfile(chan, "beep", ast_channel_language(chan));
|
2001-09-28 13:19:43 +00:00
|
|
|
|
2003-05-01 03:52:45 +00:00
|
|
|
if ((argc > 7) && (!strchr(argv[7], '=')))
|
2012-01-24 20:12:09 +00:00
|
|
|
res = ast_streamfile(chan, "beep", ast_channel_language(chan));
|
2003-05-01 03:52:45 +00:00
|
|
|
|
2002-09-04 16:53:39 +00:00
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(chan, argv[4]);
|
2005-07-15 23:00:47 +00:00
|
|
|
if (res) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (randomerror) endpos=%ld\n", res, sample_offset);
|
2005-07-15 23:00:47 +00:00
|
|
|
} else {
|
2006-12-21 19:44:20 +00:00
|
|
|
fs = ast_writefile(argv[2], argv[3], NULL, O_CREAT | O_WRONLY | (sample_offset ? O_APPEND : 0), 0, AST_FILE_MODE);
|
2002-09-04 16:53:39 +00:00
|
|
|
if (!fs) {
|
|
|
|
res = -1;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (writefile)\n", res);
|
2004-03-10 21:17:13 +00:00
|
|
|
if (sildet)
|
|
|
|
ast_dsp_free(sildet);
|
2002-09-04 16:53:39 +00:00
|
|
|
return RESULT_FAILURE;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2006-05-24 17:02:54 +00:00
|
|
|
/* Request a video update */
|
|
|
|
ast_indicate(chan, AST_CONTROL_VIDUPDATE);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_stream_set(chan, fs);
|
2003-02-06 22:11:43 +00:00
|
|
|
ast_applystream(chan,fs);
|
|
|
|
/* really should have checks */
|
|
|
|
ast_seekstream(fs, sample_offset, SEEK_SET);
|
|
|
|
ast_truncstream(fs);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2005-07-15 23:00:47 +00:00
|
|
|
start = ast_tvnow();
|
|
|
|
while ((ms < 0) || ast_tvdiff_ms(ast_tvnow(), start) < ms) {
|
2008-12-11 16:52:24 +00:00
|
|
|
res = ast_waitfor(chan, ms - ast_tvdiff_ms(ast_tvnow(), start));
|
2002-09-04 16:53:39 +00:00
|
|
|
if (res < 0) {
|
|
|
|
ast_closestream(fs);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (waitfor) endpos=%ld\n", res,sample_offset);
|
2004-03-10 21:17:13 +00:00
|
|
|
if (sildet)
|
|
|
|
ast_dsp_free(sildet);
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_FAILURE;
|
|
|
|
}
|
|
|
|
f = ast_read(chan);
|
|
|
|
if (!f) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);
|
2002-09-04 16:53:39 +00:00
|
|
|
ast_closestream(fs);
|
2004-03-10 21:17:13 +00:00
|
|
|
if (sildet)
|
|
|
|
ast_dsp_free(sildet);
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_FAILURE;
|
|
|
|
}
|
|
|
|
switch(f->frametype) {
|
|
|
|
case AST_FRAME_DTMF:
|
2009-11-04 14:05:12 +00:00
|
|
|
if (strchr(argv[4], f->subclass.integer)) {
|
2005-10-04 22:35:43 +00:00
|
|
|
/* This is an interrupting chracter, so rewind to chop off any small
|
|
|
|
amount of DTMF that may have been recorded
|
|
|
|
*/
|
|
|
|
ast_stream_rewind(fs, 200);
|
|
|
|
ast_truncstream(fs);
|
2003-02-06 22:11:43 +00:00
|
|
|
sample_offset = ast_tellstream(fs);
|
2009-11-04 14:05:12 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (dtmf) endpos=%ld\n", f->subclass.integer, sample_offset);
|
2002-09-04 16:53:39 +00:00
|
|
|
ast_closestream(fs);
|
2001-09-28 13:19:43 +00:00
|
|
|
ast_frfree(f);
|
2004-03-10 21:17:13 +00:00
|
|
|
if (sildet)
|
|
|
|
ast_dsp_free(sildet);
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AST_FRAME_VOICE:
|
2002-09-04 16:53:39 +00:00
|
|
|
ast_writestream(fs, f);
|
2003-02-06 22:11:43 +00:00
|
|
|
/* this is a safe place to check progress since we know that fs
|
|
|
|
* is valid after a write, and it will then have our current
|
|
|
|
* location */
|
|
|
|
sample_offset = ast_tellstream(fs);
|
2007-07-23 22:02:05 +00:00
|
|
|
if (silence > 0) {
|
|
|
|
dspsilence = 0;
|
|
|
|
ast_dsp_silence(sildet, f, &dspsilence);
|
|
|
|
if (dspsilence) {
|
|
|
|
totalsilence = dspsilence;
|
|
|
|
} else {
|
|
|
|
totalsilence = 0;
|
|
|
|
}
|
|
|
|
if (totalsilence > silence) {
|
|
|
|
/* Ended happily with silence */
|
|
|
|
gotsilence = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
break;
|
2006-05-24 17:02:54 +00:00
|
|
|
case AST_FRAME_VIDEO:
|
|
|
|
ast_writestream(fs, f);
|
2006-08-31 01:59:02 +00:00
|
|
|
default:
|
|
|
|
/* Ignore all other frames */
|
2006-05-24 17:02:54 +00:00
|
|
|
break;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
ast_frfree(f);
|
2003-05-01 03:52:45 +00:00
|
|
|
if (gotsilence)
|
|
|
|
break;
|
2007-07-23 22:02:05 +00:00
|
|
|
}
|
2003-05-01 03:52:45 +00:00
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
if (gotsilence) {
|
|
|
|
ast_stream_rewind(fs, silence-1000);
|
|
|
|
ast_truncstream(fs);
|
|
|
|
sample_offset = ast_tellstream(fs);
|
|
|
|
}
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d (timeout) endpos=%ld\n", res, sample_offset);
|
2002-09-04 16:53:39 +00:00
|
|
|
ast_closestream(fs);
|
2005-07-15 23:00:47 +00:00
|
|
|
}
|
2003-05-01 03:52:45 +00:00
|
|
|
|
2007-07-23 22:02:05 +00:00
|
|
|
if (silence > 0) {
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
res = ast_set_read_format(chan, rfmt);
|
2007-07-23 22:02:05 +00:00
|
|
|
if (res)
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", ast_channel_name(chan));
|
2008-06-18 00:33:31 +00:00
|
|
|
ast_dsp_free(sildet);
|
2007-07-23 22:02:05 +00:00
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2002-09-04 16:53:39 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_autohangup(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2002-09-04 16:53:39 +00:00
|
|
|
{
|
2008-05-01 23:06:23 +00:00
|
|
|
double timeout;
|
|
|
|
struct timeval whentohangup = { 0, 0 };
|
2001-09-28 13:19:43 +00:00
|
|
|
|
2002-09-04 16:53:39 +00:00
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(argv[2], "%30lf", &timeout) != 1)
|
2002-09-04 16:53:39 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
if (timeout < 0)
|
|
|
|
timeout = 0;
|
2008-05-01 23:06:23 +00:00
|
|
|
if (timeout) {
|
|
|
|
whentohangup.tv_sec = timeout;
|
|
|
|
whentohangup.tv_usec = (timeout - whentohangup.tv_sec) * 1000000.0;
|
|
|
|
}
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_lock(chan);
|
2008-05-01 23:06:23 +00:00
|
|
|
ast_channel_setwhentohangup_tv(chan, whentohangup);
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(chan);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2002-09-04 16:53:39 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_hangup(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2002-09-04 16:53:39 +00:00
|
|
|
{
|
2005-01-08 19:35:20 +00:00
|
|
|
struct ast_channel *c;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2005-01-08 19:35:20 +00:00
|
|
|
if (argc == 1) {
|
|
|
|
/* no argument: hangup the current channel */
|
2009-06-26 15:28:53 +00:00
|
|
|
ast_set_hangupsource(chan, "dialplan/agi", 0);
|
2005-01-08 19:35:20 +00:00
|
|
|
ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2005-01-08 19:35:20 +00:00
|
|
|
return RESULT_SUCCESS;
|
2005-06-06 02:29:18 +00:00
|
|
|
} else if (argc == 2) {
|
2005-01-08 19:35:20 +00:00
|
|
|
/* one argument: look for info on the specified channel */
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
if ((c = ast_channel_get_by_name(argv[1]))) {
|
2005-06-06 02:29:18 +00:00
|
|
|
/* we have a matching channel */
|
2009-06-26 15:28:53 +00:00
|
|
|
ast_set_hangupsource(c, "dialplan/agi", 0);
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
|
|
|
|
c = ast_channel_unref(c);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2005-06-06 02:29:18 +00:00
|
|
|
return RESULT_SUCCESS;
|
2005-01-08 19:35:20 +00:00
|
|
|
}
|
|
|
|
/* if we get this far no channel name matched the argument given */
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1\n");
|
2005-01-08 19:35:20 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
} else {
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
}
|
2002-09-04 16:53:39 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_exec(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2002-09-04 16:53:39 +00:00
|
|
|
{
|
2010-01-04 18:28:28 +00:00
|
|
|
int res, workaround;
|
2008-08-10 00:47:56 +00:00
|
|
|
struct ast_app *app_to_exec;
|
2002-09-04 16:53:39 +00:00
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
|
2010-01-04 18:28:28 +00:00
|
|
|
ast_verb(3, "AGI Script Executing Application: (%s) Options: (%s)\n", argv[1], argc >= 3 ? argv[2] : "");
|
2002-09-04 16:53:39 +00:00
|
|
|
|
2008-08-10 00:47:56 +00:00
|
|
|
if ((app_to_exec = pbx_findapp(argv[1]))) {
|
2012-03-13 18:20:34 +00:00
|
|
|
if (!(workaround = ast_test_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS))) {
|
|
|
|
ast_set_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS);
|
2010-01-04 18:28:28 +00:00
|
|
|
}
|
Remove many deprecated modules
Billing records are fair,
To get paid is quite bright,
You should really use ODBC;
Good-bye cdr_sqlite.
Microsoft did once push H.323,
Hell, we all remember NetMeeting.
But try to compile chan_h323 now
And you will take quite a beating.
The XMPP and SIP war was fierce,
And in the distant fray
Was birthed res_jabber/chan_jingle;
But neither to stay.
For everyone did care and chase what Google professed.
"Free Internet Calling" was what devotees cried,
But Google did change the specs so often
That the developers were happy the day chan_gtalk died.
And then there was that odd application
Dedicated to the Polish tongue.
app_saycountpl was subsumed by Say;
One could say its bell was rung.
To read and parse a file from the dialplan
You could (I guess) use an application.
app_readfile did fill that purpose, but I think
A function is perhaps better in its creation.
Barging is rude, I'm not sure why we do it.
Inwardly, the caller will probably sigh.
But if you really must do it,
Don't use app_dahdibarge, use ChanSpy.
We all despise the sound of tinny robots
It makes our queues so cold.
To control such an abomination
It's better to not use Wait/SetMusicOnHold.
It's often nice to know properties of a channel
It makes our calls right
We have a nice function called CHANNEL
And so SIPCHANINFO is sent off into the night.
And now things get odd;
Apparently one could delimit with a colon
Properties from the SIPPEER function!
Commas are in; all others are done.
Finally, a word on pipes and commas.
We're sorry. We can't say it enough.
But those compatibility options in asterisk.conf;
To maintain them forever was just too tough.
This patch removes:
* cdr_sqlite
* chan_gtalk
* chan_jingle
* chan_h323
* res_jabber
* app_saycountpl
* app_readfile
* app_dahdibarge
It removes the following applications/functions:
* WaitMusicOnHold
* SetMusicOnHold
* SIPCHANINFO
It removes the colon delimiter from the SIPPEER function.
Finally, it also removes all compatibility options that were configurable from
asterisk.conf, as these all applied to compatibility with Asterisk 1.4 systems.
Review: https://reviewboard.asterisk.org/r/3698/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@418019 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-04 13:26:37 +00:00
|
|
|
res = pbx_exec(chan, app_to_exec, argc == 2 ? "" : argv[2]);
|
2010-01-04 18:28:28 +00:00
|
|
|
if (!workaround) {
|
2012-03-13 18:20:34 +00:00
|
|
|
ast_clear_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS);
|
2010-01-04 18:28:28 +00:00
|
|
|
}
|
2002-09-04 16:53:39 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
|
|
|
|
res = -2;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%d\n", res);
|
2002-09-04 16:53:39 +00:00
|
|
|
|
2007-07-30 18:45:09 +00:00
|
|
|
/* Even though this is wrong, users are depending upon this result. */
|
|
|
|
return res;
|
2002-09-04 16:53:39 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_setcallerid(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2002-09-04 16:53:39 +00:00
|
|
|
{
|
2004-10-02 00:58:31 +00:00
|
|
|
char tmp[256]="";
|
|
|
|
char *l = NULL, *n = NULL;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2004-10-02 00:58:31 +00:00
|
|
|
if (argv[2]) {
|
2005-07-10 23:21:39 +00:00
|
|
|
ast_copy_string(tmp, argv[2], sizeof(tmp));
|
2004-10-02 00:58:31 +00:00
|
|
|
ast_callerid_parse(tmp, &n, &l);
|
|
|
|
if (l)
|
|
|
|
ast_shrink_phone_number(l);
|
|
|
|
else
|
|
|
|
l = "";
|
|
|
|
if (!n)
|
|
|
|
n = "";
|
|
|
|
ast_set_callerid(chan, l, n, NULL);
|
|
|
|
}
|
2002-09-04 16:53:39 +00:00
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2001-09-28 13:19:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_channelstatus(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2002-09-04 16:53:39 +00:00
|
|
|
{
|
2005-01-08 19:35:20 +00:00
|
|
|
if (argc == 2) {
|
2004-06-04 19:01:07 +00:00
|
|
|
/* no argument: supply info on the current channel */
|
2014-05-09 22:49:26 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%u\n", ast_channel_state(chan));
|
2004-06-04 19:01:07 +00:00
|
|
|
return RESULT_SUCCESS;
|
2005-01-08 19:35:20 +00:00
|
|
|
} else if (argc == 3) {
|
2013-07-08 19:19:55 +00:00
|
|
|
RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
|
|
|
|
|
2004-06-04 19:01:07 +00:00
|
|
|
/* one argument: look for info on the specified channel */
|
2013-08-01 13:49:34 +00:00
|
|
|
if ((msg = stasis_cache_get(ast_channel_cache_by_name(), ast_channel_snapshot_type(), argv[2]))) {
|
2013-07-08 19:19:55 +00:00
|
|
|
struct ast_channel_snapshot *snapshot = stasis_message_data(msg);
|
|
|
|
|
2014-05-09 22:49:26 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%u\n", snapshot->state);
|
2005-06-06 02:29:18 +00:00
|
|
|
return RESULT_SUCCESS;
|
2004-06-04 19:01:07 +00:00
|
|
|
}
|
|
|
|
/* if we get this far no channel name matched the argument given */
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1\n");
|
2004-06-04 19:01:07 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
} else {
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
}
|
2003-02-06 22:11:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_setvariable(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
|
|
|
if (argv[3])
|
|
|
|
pbx_builtin_setvar_helper(chan, argv[2], argv[3]);
|
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2003-02-06 22:11:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_getvariable(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
2006-08-23 16:14:18 +00:00
|
|
|
char *ret;
|
2011-04-22 14:08:02 +00:00
|
|
|
char tempstr[1024] = "";
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2004-11-17 04:02:56 +00:00
|
|
|
if (argc != 3)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2005-08-22 23:00:23 +00:00
|
|
|
|
|
|
|
/* check if we want to execute an ast_custom_function */
|
2006-08-23 16:14:18 +00:00
|
|
|
if (!ast_strlen_zero(argv[2]) && (argv[2][strlen(argv[2]) - 1] == ')')) {
|
2006-02-12 04:28:58 +00:00
|
|
|
ret = ast_func_read(chan, argv[2], tempstr, sizeof(tempstr)) ? NULL : tempstr;
|
2006-08-23 16:14:18 +00:00
|
|
|
} else {
|
|
|
|
pbx_retrieve_variable(chan, argv[2], &ret, tempstr, sizeof(tempstr), NULL);
|
|
|
|
}
|
2005-08-22 23:00:23 +00:00
|
|
|
|
2004-12-23 02:47:01 +00:00
|
|
|
if (ret)
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ret);
|
2003-02-06 22:11:43 +00:00
|
|
|
else
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2003-02-06 22:11:43 +00:00
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_getvariablefull(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2004-11-17 04:02:56 +00:00
|
|
|
{
|
2009-04-29 18:53:01 +00:00
|
|
|
struct ast_channel *chan2 = NULL;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
if (argc != 4 && argc != 5) {
|
2004-11-17 04:02:56 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
}
|
|
|
|
|
2004-11-17 04:02:56 +00:00
|
|
|
if (argc == 5) {
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
chan2 = ast_channel_get_by_name(argv[4]);
|
2004-11-17 04:02:56 +00:00
|
|
|
} else {
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
chan2 = ast_channel_ref(chan);
|
2004-11-17 04:02:56 +00:00
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2007-09-12 21:57:30 +00:00
|
|
|
if (chan2) {
|
2009-04-29 18:53:01 +00:00
|
|
|
struct ast_str *str = ast_str_create(16);
|
|
|
|
if (!str) {
|
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
ast_str_substitute_variables(&str, 0, chan2, argv[3]);
|
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ast_str_buffer(str));
|
|
|
|
ast_free(str);
|
2004-11-17 04:02:56 +00:00
|
|
|
} else {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2004-11-17 04:02:56 +00:00
|
|
|
}
|
Convert the ast_channel data structure over to the astobj2 framework.
There is a lot that could be said about this, but the patch is a big
improvement for performance, stability, code maintainability,
and ease of future code development.
The channel list is no longer an unsorted linked list. The main container
for channels is an astobj2 hash table. All of the code related to searching
for channels or iterating active channels has been rewritten. Let n be
the number of active channels. Iterating the channel list has gone from
O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1).
Searching for a channel by extension is still O(n), but uses a new method
for doing so, which is more efficient.
The ast_channel object is now a reference counted object. The benefits
here are plentiful. Some benefits directly related to issues in the
previous code include:
1) When threads other than the channel thread owning a channel wanted
access to a channel, it had to hold the lock on it to ensure that it didn't
go away. This is no longer a requirement. Holding a reference is
sufficient.
2) There are places that now require less dealing with channel locks.
3) There are places where channel locks are held for much shorter periods
of time.
4) There are places where dealing with more than one channel at a time becomes
_MUCH_ easier. ChanSpy is a great example of this. Writing code in the
future that deals with multiple channels will be much easier.
Some additional information regarding channel locking and reference count
handling can be found in channel.h, where a new section has been added that
discusses some of the rules associated with it.
Mark Michelson also assisted with the development of this patch. He did the
conversion of ChanSpy and introduced a new API, ast_autochan, which makes it
much easier to deal with holding on to a channel pointer for an extended period
of time and having it get automatically updated if the channel gets masqueraded.
Mark was also a huge help in the code review process.
Thanks to David Vossel for his assistance with this branch, as well. David
did the conversion of the DAHDIScan application by making it become a wrapper
for ChanSpy internally.
The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch.
Review: http://reviewboard.digium.com/r/203/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
|
|
|
if (chan2) {
|
|
|
|
chan2 = ast_channel_unref(chan2);
|
|
|
|
}
|
|
|
|
|
2004-11-17 04:02:56 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_verbose(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
|
|
|
int level = 0;
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
|
|
|
|
if (argv[2])
|
2009-08-10 19:20:57 +00:00
|
|
|
sscanf(argv[2], "%30d", &level);
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2012-02-13 17:27:06 +00:00
|
|
|
ast_verb(level, "%s: %s\n", ast_channel_data(chan), argv[1]);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2002-09-04 16:53:39 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_dbget(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
|
|
|
int res;
|
2009-01-08 22:37:20 +00:00
|
|
|
struct ast_str *buf;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2003-02-06 22:11:43 +00:00
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2009-01-08 22:37:20 +00:00
|
|
|
|
|
|
|
if (!(buf = ast_str_create(16))) {
|
|
|
|
ast_agi_send(agi->fd, chan, "200 result=-1\n");
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
res = ast_db_get(argv[2], argv[3], ast_str_buffer(buf), ast_str_size(buf));
|
2009-01-09 18:30:55 +00:00
|
|
|
ast_str_update(buf);
|
2009-01-08 22:37:20 +00:00
|
|
|
if (ast_str_strlen(buf) < ast_str_size(buf) - 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ast_str_make_space(&buf, ast_str_size(buf) * 2)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
2013-07-31 23:48:35 +00:00
|
|
|
|
2008-06-18 00:33:31 +00:00
|
|
|
if (res)
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2003-02-06 22:11:43 +00:00
|
|
|
else
|
2009-01-08 22:37:20 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1 (%s)\n", ast_str_buffer(buf));
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2009-01-08 22:37:20 +00:00
|
|
|
ast_free(buf);
|
2003-02-06 22:11:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_dbput(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
|
|
|
int res;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2003-02-06 22:11:43 +00:00
|
|
|
if (argc != 5)
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
res = ast_db_put(argv[2], argv[3], argv[4]);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
|
2003-02-06 22:11:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_dbdel(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
|
|
|
int res;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2003-02-06 22:11:43 +00:00
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
res = ast_db_del(argv[2], argv[3]);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%c\n", res ? '0' : '1');
|
2003-02-06 22:11:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_dbdeltree(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
2012-10-04 15:48:24 +00:00
|
|
|
int num_deleted;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2012-10-04 15:48:24 +00:00
|
|
|
if ((argc < 3) || (argc > 4)) {
|
2003-02-06 22:11:43 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2012-10-04 15:48:24 +00:00
|
|
|
}
|
|
|
|
if (argc == 4) {
|
|
|
|
num_deleted = ast_db_deltree(argv[2], argv[3]);
|
|
|
|
} else {
|
|
|
|
num_deleted = ast_db_deltree(argv[2], NULL);
|
|
|
|
}
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2012-10-04 15:48:24 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=%c\n", num_deleted > 0 ? '0' : '1');
|
2003-02-23 06:00:11 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_agi_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2004-09-25 14:22:27 +00:00
|
|
|
{
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
2008-02-08 21:26:32 +00:00
|
|
|
e->command = "agi set debug [on|off]";
|
2007-09-18 22:43:45 +00:00
|
|
|
e->usage =
|
2008-02-08 21:26:32 +00:00
|
|
|
"Usage: agi set debug [on|off]\n"
|
2007-09-18 22:43:45 +00:00
|
|
|
" Enables/disables dumping of AGI transactions for\n"
|
|
|
|
" debugging purposes.\n";
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-02-08 21:26:32 +00:00
|
|
|
|
|
|
|
if (a->argc != e->args)
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SHOWUSAGE;
|
2008-02-08 21:26:32 +00:00
|
|
|
|
|
|
|
if (strncasecmp(a->argv[3], "off", 3) == 0) {
|
|
|
|
agidebug = 0;
|
|
|
|
} else if (strncasecmp(a->argv[3], "on", 2) == 0) {
|
2007-09-18 22:43:45 +00:00
|
|
|
agidebug = 1;
|
|
|
|
} else {
|
2008-02-08 21:26:32 +00:00
|
|
|
return CLI_SHOWUSAGE;
|
2007-09-18 22:43:45 +00:00
|
|
|
}
|
|
|
|
ast_cli(a->fd, "AGI Debugging %sabled\n", agidebug ? "En" : "Dis");
|
|
|
|
return CLI_SUCCESS;
|
2006-09-18 19:54:18 +00:00
|
|
|
}
|
2004-09-25 14:22:27 +00:00
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, const char * const argv[])
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2003-02-06 22:11:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_setmusic(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2003-06-11 12:17:43 +00:00
|
|
|
{
|
2009-12-15 15:33:49 +00:00
|
|
|
if (argc < 3) {
|
|
|
|
return RESULT_SHOWUSAGE;
|
|
|
|
}
|
2006-04-06 16:17:04 +00:00
|
|
|
if (!strncasecmp(argv[2], "on", 2))
|
2006-07-19 20:44:39 +00:00
|
|
|
ast_moh_start(chan, argc > 3 ? argv[3] : NULL, NULL);
|
2006-04-06 16:17:04 +00:00
|
|
|
else if (!strncasecmp(argv[2], "off", 3))
|
2003-06-11 12:17:43 +00:00
|
|
|
ast_moh_stop(chan);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2003-06-11 12:17:43 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechcreate(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format_cap *cap;
|
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* If a structure already exists, return an error */
|
2011-02-03 16:22:10 +00:00
|
|
|
if (agi->speech) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if (!(cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
|
2011-02-03 16:22:10 +00:00
|
|
|
return RESULT_FAILURE;
|
|
|
|
}
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ast_format_cap_append(cap, ast_format_slin, 0);
|
2011-02-03 16:22:10 +00:00
|
|
|
if ((agi->speech = ast_speech_new(argv[2], cap))) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2011-02-03 16:22:10 +00:00
|
|
|
} else {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2011-02-03 16:22:10 +00:00
|
|
|
}
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_ref(cap, -1);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechset(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
|
|
|
/* Check for minimum arguments */
|
2010-03-25 15:21:26 +00:00
|
|
|
if (argc != 4)
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SHOWUSAGE;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Check to make sure speech structure exists */
|
|
|
|
if (!agi->speech) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
ast_speech_change(agi->speech, argv[2], argv[3]);
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechdestroy(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
|
|
|
if (agi->speech) {
|
|
|
|
ast_speech_destroy(agi->speech);
|
|
|
|
agi->speech = NULL;
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
} else {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechloadgrammar(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
|
|
|
if (argc != 5)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (!agi->speech) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (ast_speech_grammar_load(agi->speech, argv[3], argv[4]))
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
else
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechunloadgrammar(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (!agi->speech) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (ast_speech_grammar_unload(agi->speech, argv[3]))
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
else
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechactivategrammar(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (!agi->speech) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (ast_speech_grammar_activate(agi->speech, argv[3]))
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
else
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechdeactivategrammar(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
|
|
|
if (argc != 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (!agi->speech) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (ast_speech_grammar_deactivate(agi->speech, argv[3]))
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
else
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1\n");
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int speech_streamfile(struct ast_channel *chan, const char *filename, const char *preflang, int offset)
|
|
|
|
{
|
|
|
|
struct ast_filestream *fs = NULL;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (!(fs = ast_openstream(chan, filename, preflang)))
|
|
|
|
return -1;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (offset)
|
|
|
|
ast_seekstream(fs, offset, SEEK_SET);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (ast_applystream(chan, fs))
|
|
|
|
return -1;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (ast_playstream(fs))
|
|
|
|
return -1;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int handle_speechrecognize(struct ast_channel *chan, AGI *agi, int argc, const char * const argv[])
|
2007-12-03 21:03:05 +00:00
|
|
|
{
|
|
|
|
struct ast_speech *speech = agi->speech;
|
2009-05-21 21:13:09 +00:00
|
|
|
const char *prompt;
|
|
|
|
char dtmf = 0, tmp[4096] = "", *buf = tmp;
|
2011-02-03 16:22:10 +00:00
|
|
|
int timeout = 0, offset = 0, res = 0, i = 0;
|
2007-12-03 21:03:05 +00:00
|
|
|
long current_offset = 0;
|
|
|
|
const char *reason = NULL;
|
|
|
|
struct ast_frame *fr = NULL;
|
|
|
|
struct ast_speech_result *result = NULL;
|
|
|
|
size_t left = sizeof(tmp);
|
|
|
|
time_t start = 0, current;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (argc < 4)
|
|
|
|
return RESULT_SHOWUSAGE;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (!speech) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
prompt = argv[2];
|
|
|
|
timeout = atoi(argv[3]);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* If offset is specified then convert from text to integer */
|
|
|
|
if (argc == 5)
|
|
|
|
offset = atoi(argv[4]);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* We want frames coming in signed linear */
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if (ast_set_read_format(chan, ast_format_slin)) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0\n");
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Setup speech structure */
|
|
|
|
if (speech->state == AST_SPEECH_STATE_NOT_READY || speech->state == AST_SPEECH_STATE_DONE) {
|
|
|
|
ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY);
|
|
|
|
ast_speech_start(speech);
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Start playing prompt */
|
2012-01-24 20:12:09 +00:00
|
|
|
speech_streamfile(chan, prompt, ast_channel_language(chan), offset);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Go into loop reading in frames, passing to speech thingy, checking for hangup, all that jazz */
|
|
|
|
while (ast_strlen_zero(reason)) {
|
|
|
|
/* Run scheduled items */
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_sched_runq(ast_channel_sched(chan));
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* See maximum time of waiting */
|
2012-02-20 23:43:27 +00:00
|
|
|
if ((res = ast_sched_wait(ast_channel_sched(chan))) < 0)
|
2007-12-03 21:03:05 +00:00
|
|
|
res = 1000;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Wait for frame */
|
|
|
|
if (ast_waitfor(chan, res) > 0) {
|
|
|
|
if (!(fr = ast_read(chan))) {
|
|
|
|
reason = "hangup";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Perform timeout check */
|
|
|
|
if ((timeout > 0) && (start > 0)) {
|
|
|
|
time(¤t);
|
|
|
|
if ((current - start) >= timeout) {
|
|
|
|
reason = "timeout";
|
|
|
|
if (fr)
|
|
|
|
ast_frfree(fr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Check the speech structure for any changes */
|
|
|
|
ast_mutex_lock(&speech->lock);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* See if we need to quiet the audio stream playback */
|
2012-02-20 23:43:27 +00:00
|
|
|
if (ast_test_flag(speech, AST_SPEECH_QUIET) && ast_channel_stream(chan)) {
|
|
|
|
current_offset = ast_tellstream(ast_channel_stream(chan));
|
2007-12-03 21:03:05 +00:00
|
|
|
ast_stopstream(chan);
|
|
|
|
ast_clear_flag(speech, AST_SPEECH_QUIET);
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Check each state */
|
|
|
|
switch (speech->state) {
|
|
|
|
case AST_SPEECH_STATE_READY:
|
|
|
|
/* If the stream is done, start timeout calculation */
|
2012-03-13 18:20:34 +00:00
|
|
|
if ((timeout > 0) && start == 0 && ((!ast_channel_stream(chan)) || (ast_channel_streamid(chan) == -1 && ast_channel_timingfunc(chan) == NULL))) {
|
2007-12-03 21:03:05 +00:00
|
|
|
ast_stopstream(chan);
|
|
|
|
time(&start);
|
|
|
|
}
|
|
|
|
/* Write audio frame data into speech engine if possible */
|
|
|
|
if (fr && fr->frametype == AST_FRAME_VOICE)
|
2008-05-22 16:29:54 +00:00
|
|
|
ast_speech_write(speech, fr->data.ptr, fr->datalen);
|
2007-12-03 21:03:05 +00:00
|
|
|
break;
|
|
|
|
case AST_SPEECH_STATE_WAIT:
|
|
|
|
/* Cue waiting sound if not already playing */
|
2012-03-13 18:20:34 +00:00
|
|
|
if ((!ast_channel_stream(chan)) || (ast_channel_streamid(chan) == -1 && ast_channel_timingfunc(chan) == NULL)) {
|
2007-12-03 21:03:05 +00:00
|
|
|
ast_stopstream(chan);
|
|
|
|
/* If a processing sound exists, or is not none - play it */
|
|
|
|
if (!ast_strlen_zero(speech->processing_sound) && strcasecmp(speech->processing_sound, "none"))
|
2012-01-24 20:12:09 +00:00
|
|
|
speech_streamfile(chan, speech->processing_sound, ast_channel_language(chan), 0);
|
2007-12-03 21:03:05 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AST_SPEECH_STATE_DONE:
|
|
|
|
/* Get the results */
|
|
|
|
speech->results = ast_speech_results_get(speech);
|
|
|
|
/* Change state to not ready */
|
|
|
|
ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY);
|
|
|
|
reason = "speech";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&speech->lock);
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
/* Check frame for DTMF or hangup */
|
|
|
|
if (fr) {
|
|
|
|
if (fr->frametype == AST_FRAME_DTMF) {
|
|
|
|
reason = "dtmf";
|
2009-11-04 14:05:12 +00:00
|
|
|
dtmf = fr->subclass.integer;
|
|
|
|
} else if (fr->frametype == AST_FRAME_CONTROL && fr->subclass.integer == AST_CONTROL_HANGUP) {
|
2007-12-03 21:03:05 +00:00
|
|
|
reason = "hangup";
|
|
|
|
}
|
|
|
|
ast_frfree(fr);
|
|
|
|
}
|
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
if (!strcasecmp(reason, "speech")) {
|
|
|
|
/* Build string containing speech results */
|
|
|
|
for (result = speech->results; result; result = AST_LIST_NEXT(result, list)) {
|
|
|
|
/* Build result string */
|
|
|
|
ast_build_string(&buf, &left, "%sscore%d=%d text%d=\"%s\" grammar%d=%s", (i > 0 ? " " : ""), i, result->score, i, result->text, i, result->grammar);
|
|
|
|
/* Increment result count */
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
/* Print out */
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1 (speech) endpos=%ld results=%d %s\n", current_offset, i, tmp);
|
2007-12-03 21:03:05 +00:00
|
|
|
} else if (!strcasecmp(reason, "dtmf")) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1 (digit) digit=%c endpos=%ld\n", dtmf, current_offset);
|
2007-12-03 21:03:05 +00:00
|
|
|
} else if (!strcasecmp(reason, "hangup") || !strcasecmp(reason, "timeout")) {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=1 (%s) endpos=%ld\n", reason, current_offset);
|
2007-12-03 21:03:05 +00:00
|
|
|
} else {
|
2008-11-19 12:42:19 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "200 result=0 endpos=%ld\n", current_offset);
|
2007-12-03 21:03:05 +00:00
|
|
|
}
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-02 19:01:16 +00:00
|
|
|
/*!
|
2007-07-23 22:02:05 +00:00
|
|
|
* \brief AGI commands list
|
2007-07-02 19:01:16 +00:00
|
|
|
*/
|
2007-07-30 19:11:28 +00:00
|
|
|
static struct agi_command commands[] = {
|
2008-11-12 00:17:43 +00:00
|
|
|
{ { "answer", NULL }, handle_answer, NULL, NULL, 0 },
|
2009-05-04 19:29:13 +00:00
|
|
|
{ { "asyncagi", "break", NULL }, handle_asyncagi_break, NULL, NULL, 1 },
|
2008-11-12 00:17:43 +00:00
|
|
|
{ { "channel", "status", NULL }, handle_channelstatus, NULL, NULL, 0 },
|
2008-11-12 02:20:05 +00:00
|
|
|
{ { "database", "del", NULL }, handle_dbdel, NULL, NULL, 1 },
|
2008-11-12 13:43:46 +00:00
|
|
|
{ { "database", "deltree", NULL }, handle_dbdeltree, NULL, NULL, 1 },
|
|
|
|
{ { "database", "get", NULL }, handle_dbget, NULL, NULL, 1 },
|
2008-11-12 02:20:05 +00:00
|
|
|
{ { "database", "put", NULL }, handle_dbput, NULL, NULL, 1 },
|
2008-11-12 13:43:46 +00:00
|
|
|
{ { "exec", NULL }, handle_exec, NULL, NULL, 1 },
|
|
|
|
{ { "get", "data", NULL }, handle_getdata, NULL, NULL, 0 },
|
|
|
|
{ { "get", "full", "variable", NULL }, handle_getvariablefull, NULL, NULL, 1 },
|
2008-12-04 13:45:32 +00:00
|
|
|
{ { "get", "option", NULL }, handle_getoption, NULL, NULL, 0 },
|
|
|
|
{ { "get", "variable", NULL }, handle_getvariable, NULL, NULL, 1 },
|
|
|
|
{ { "hangup", NULL }, handle_hangup, NULL, NULL, 0 },
|
|
|
|
{ { "noop", NULL }, handle_noop, NULL, NULL, 1 },
|
2009-05-18 20:18:43 +00:00
|
|
|
{ { "receive", "char", NULL }, handle_recvchar, NULL, NULL, 0 },
|
|
|
|
{ { "receive", "text", NULL }, handle_recvtext, NULL, NULL, 0 },
|
2013-07-31 23:48:35 +00:00
|
|
|
{ { "record", "file", NULL }, handle_recordfile, NULL, NULL, 0 },
|
2009-05-22 19:11:44 +00:00
|
|
|
{ { "say", "alpha", NULL }, handle_sayalpha, NULL, NULL, 0},
|
|
|
|
{ { "say", "digits", NULL }, handle_saydigits, NULL, NULL, 0 },
|
|
|
|
{ { "say", "number", NULL }, handle_saynumber, NULL, NULL, 0 },
|
2013-07-31 23:48:35 +00:00
|
|
|
{ { "say", "phonetic", NULL }, handle_sayphonetic, NULL, NULL, 0},
|
|
|
|
{ { "say", "date", NULL }, handle_saydate, NULL, NULL, 0},
|
|
|
|
{ { "say", "time", NULL }, handle_saytime, NULL, NULL, 0},
|
2009-05-23 21:11:31 +00:00
|
|
|
{ { "say", "datetime", NULL }, handle_saydatetime, NULL, NULL, 0},
|
2013-07-31 23:48:35 +00:00
|
|
|
{ { "send", "image", NULL }, handle_sendimage, NULL, NULL, 0},
|
2009-05-23 21:11:31 +00:00
|
|
|
{ { "send", "text", NULL }, handle_sendtext, NULL, NULL, 0},
|
|
|
|
{ { "set", "autohangup", NULL }, handle_autohangup, NULL, NULL, 0},
|
|
|
|
{ { "set", "callerid", NULL }, handle_setcallerid, NULL, NULL, 0},
|
|
|
|
{ { "set", "context", NULL }, handle_setcontext, NULL, NULL, 0},
|
|
|
|
{ { "set", "extension", NULL }, handle_setextension, NULL, NULL, 0},
|
2008-11-12 02:20:05 +00:00
|
|
|
{ { "set", "music", NULL }, handle_setmusic, NULL, NULL, 0 },
|
2009-05-24 16:17:31 +00:00
|
|
|
{ { "set", "priority", NULL }, handle_setpriority, NULL, NULL, 0 },
|
|
|
|
{ { "set", "variable", NULL }, handle_setvariable, NULL, NULL, 1 },
|
|
|
|
{ { "stream", "file", NULL }, handle_streamfile, NULL, NULL, 0 },
|
|
|
|
{ { "control", "stream", "file", NULL }, handle_controlstreamfile, NULL, NULL, 0 },
|
|
|
|
{ { "tdd", "mode", NULL }, handle_tddmode, NULL, NULL, 0 },
|
|
|
|
{ { "verbose", NULL }, handle_verbose, NULL, NULL, 1 },
|
|
|
|
{ { "wait", "for", "digit", NULL }, handle_waitfordigit, NULL, NULL, 0 },
|
|
|
|
{ { "speech", "create", NULL }, handle_speechcreate, NULL, NULL, 0 },
|
|
|
|
{ { "speech", "set", NULL }, handle_speechset, NULL, NULL, 0 },
|
|
|
|
{ { "speech", "destroy", NULL }, handle_speechdestroy, NULL, NULL, 1 },
|
|
|
|
{ { "speech", "load", "grammar", NULL }, handle_speechloadgrammar, NULL, NULL, 0 },
|
|
|
|
{ { "speech", "unload", "grammar", NULL }, handle_speechunloadgrammar, NULL, NULL, 1 },
|
|
|
|
{ { "speech", "activate", "grammar", NULL }, handle_speechactivategrammar, NULL, NULL, 0 },
|
|
|
|
{ { "speech", "deactivate", "grammar", NULL }, handle_speechdeactivategrammar, NULL, NULL, 0 },
|
|
|
|
{ { "speech", "recognize", NULL }, handle_speechrecognize, NULL, NULL, 0 },
|
2001-09-28 13:19:43 +00:00
|
|
|
};
|
|
|
|
|
2007-07-23 23:14:20 +00:00
|
|
|
static AST_RWLIST_HEAD_STATIC(agi_commands, agi_command);
|
2007-07-23 22:02:05 +00:00
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static char *help_workhorse(int fd, const char * const match[])
|
2003-02-06 22:11:43 +00:00
|
|
|
{
|
2008-11-12 00:17:43 +00:00
|
|
|
char fullcmd[MAX_CMD_LEN], matchstr[MAX_CMD_LEN];
|
2003-02-06 22:11:43 +00:00
|
|
|
struct agi_command *e;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2003-02-06 22:11:43 +00:00
|
|
|
if (match)
|
2005-12-20 20:20:04 +00:00
|
|
|
ast_join(matchstr, sizeof(matchstr), match);
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2007-12-03 21:03:05 +00:00
|
|
|
ast_cli(fd, "%5.5s %30.30s %s\n","Dead","Command","Description");
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_RDLOCK(&agi_commands);
|
|
|
|
AST_RWLIST_TRAVERSE(&agi_commands, e, list) {
|
2005-12-20 20:20:04 +00:00
|
|
|
if (!e->cmda[0])
|
|
|
|
break;
|
2003-02-06 22:11:43 +00:00
|
|
|
/* Hide commands that start with '_' */
|
2005-12-20 20:20:04 +00:00
|
|
|
if ((e->cmda[0])[0] == '_')
|
|
|
|
continue;
|
|
|
|
ast_join(fullcmd, sizeof(fullcmd), e->cmda);
|
|
|
|
if (match && strncasecmp(matchstr, fullcmd, strlen(matchstr)))
|
2003-02-06 22:11:43 +00:00
|
|
|
continue;
|
2010-02-10 16:01:28 +00:00
|
|
|
ast_cli(fd, "%5.5s %30.30s %s\n", e->dead ? "Yes" : "No" , fullcmd, S_OR(e->summary, "Not available"));
|
2003-02-06 22:11:43 +00:00
|
|
|
}
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_UNLOCK(&agi_commands);
|
2007-09-18 22:43:45 +00:00
|
|
|
|
|
|
|
return CLI_SUCCESS;
|
2003-02-06 22:11:43 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 16:07:23 +00:00
|
|
|
int AST_OPTIONAL_API_NAME(ast_agi_register)(struct ast_module *mod, agi_command *cmd)
|
2004-07-17 20:25:39 +00:00
|
|
|
{
|
2008-11-12 00:17:43 +00:00
|
|
|
char fullcmd[MAX_CMD_LEN];
|
2007-07-30 19:11:28 +00:00
|
|
|
|
|
|
|
ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
if (!find_command(cmd->cmda, 1)) {
|
2009-05-22 17:52:35 +00:00
|
|
|
*((enum ast_doc_src *) &cmd->docsrc) = AST_STATIC_DOC;
|
2008-11-12 00:17:43 +00:00
|
|
|
if (ast_strlen_zero(cmd->summary) && ast_strlen_zero(cmd->usage)) {
|
2010-02-10 16:01:28 +00:00
|
|
|
#ifdef AST_XML_DOCS
|
2011-10-10 14:16:27 +00:00
|
|
|
*((char **) &cmd->summary) = ast_xmldoc_build_synopsis("agi", fullcmd, NULL);
|
|
|
|
*((char **) &cmd->usage) = ast_xmldoc_build_description("agi", fullcmd, NULL);
|
|
|
|
*((char **) &cmd->syntax) = ast_xmldoc_build_syntax("agi", fullcmd, NULL);
|
|
|
|
*((char **) &cmd->seealso) = ast_xmldoc_build_seealso("agi", fullcmd, NULL);
|
2009-05-21 21:13:09 +00:00
|
|
|
*((enum ast_doc_src *) &cmd->docsrc) = AST_XML_DOC;
|
2010-09-30 20:40:08 +00:00
|
|
|
#endif
|
|
|
|
#ifndef HAVE_NULLSAFE_PRINTF
|
|
|
|
if (!cmd->summary) {
|
|
|
|
*((char **) &cmd->summary) = ast_strdup("");
|
|
|
|
}
|
|
|
|
if (!cmd->usage) {
|
|
|
|
*((char **) &cmd->usage) = ast_strdup("");
|
|
|
|
}
|
|
|
|
if (!cmd->syntax) {
|
|
|
|
*((char **) &cmd->syntax) = ast_strdup("");
|
|
|
|
}
|
|
|
|
if (!cmd->seealso) {
|
|
|
|
*((char **) &cmd->seealso) = ast_strdup("");
|
|
|
|
}
|
2008-11-12 00:17:43 +00:00
|
|
|
#endif
|
2010-02-10 16:01:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-01 04:36:15 +00:00
|
|
|
cmd->mod = mod;
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_WRLOCK(&agi_commands);
|
2007-07-30 19:11:28 +00:00
|
|
|
AST_LIST_INSERT_TAIL(&agi_commands, cmd, list);
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_UNLOCK(&agi_commands);
|
2007-07-30 19:11:28 +00:00
|
|
|
if (mod != ast_module_info->self)
|
|
|
|
ast_module_ref(ast_module_info->self);
|
|
|
|
ast_verb(2, "AGI Command '%s' registered\n",fullcmd);
|
2007-07-23 22:02:05 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Command already registered!\n");
|
|
|
|
return 0;
|
2004-07-17 20:25:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-15 16:07:23 +00:00
|
|
|
int AST_OPTIONAL_API_NAME(ast_agi_unregister)(struct ast_module *mod, agi_command *cmd)
|
2004-07-17 20:25:39 +00:00
|
|
|
{
|
2007-07-23 22:02:05 +00:00
|
|
|
struct agi_command *e;
|
|
|
|
int unregistered = 0;
|
2008-11-12 00:17:43 +00:00
|
|
|
char fullcmd[MAX_CMD_LEN];
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-07-30 19:11:28 +00:00
|
|
|
ast_join(fullcmd, sizeof(fullcmd), cmd->cmda);
|
2007-07-23 22:02:05 +00:00
|
|
|
|
|
|
|
AST_RWLIST_WRLOCK(&agi_commands);
|
|
|
|
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&agi_commands, e, list) {
|
|
|
|
if (cmd == e) {
|
2007-11-08 05:28:47 +00:00
|
|
|
AST_RWLIST_REMOVE_CURRENT(list);
|
2007-07-30 19:11:28 +00:00
|
|
|
if (mod != ast_module_info->self)
|
|
|
|
ast_module_unref(ast_module_info->self);
|
2008-11-12 00:17:43 +00:00
|
|
|
#ifdef AST_XML_DOCS
|
|
|
|
if (e->docsrc == AST_XML_DOC) {
|
2009-05-21 21:13:09 +00:00
|
|
|
ast_free((char *) e->summary);
|
|
|
|
ast_free((char *) e->usage);
|
|
|
|
ast_free((char *) e->syntax);
|
|
|
|
ast_free((char *) e->seealso);
|
|
|
|
*((char **) &e->summary) = NULL;
|
|
|
|
*((char **) &e->usage) = NULL;
|
|
|
|
*((char **) &e->syntax) = NULL;
|
|
|
|
*((char **) &e->seealso) = NULL;
|
2008-11-12 00:17:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-07-23 22:02:05 +00:00
|
|
|
unregistered=1;
|
|
|
|
break;
|
2004-07-17 20:25:39 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-08 05:28:47 +00:00
|
|
|
AST_RWLIST_TRAVERSE_SAFE_END;
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_UNLOCK(&agi_commands);
|
2013-10-08 15:12:46 +00:00
|
|
|
if (unregistered) {
|
2007-07-30 19:11:28 +00:00
|
|
|
ast_verb(2, "AGI Command '%s' unregistered\n",fullcmd);
|
2013-10-08 15:12:46 +00:00
|
|
|
}
|
2007-07-23 22:02:05 +00:00
|
|
|
return unregistered;
|
2004-07-17 20:25:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 16:07:23 +00:00
|
|
|
int AST_OPTIONAL_API_NAME(ast_agi_register_multiple)(struct ast_module *mod, struct agi_command *cmd, unsigned int len)
|
2007-07-30 19:11:28 +00:00
|
|
|
{
|
2008-11-19 12:42:19 +00:00
|
|
|
unsigned int i, x = 0;
|
2007-07-30 19:11:28 +00:00
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (ast_agi_register(mod, cmd + i) == 1) {
|
|
|
|
x++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* registration failed, unregister everything
|
|
|
|
that had been registered up to that point
|
|
|
|
*/
|
|
|
|
for (; x > 0; x--) {
|
|
|
|
/* we are intentionally ignoring the
|
|
|
|
result of ast_agi_unregister() here,
|
|
|
|
but it should be safe to do so since
|
|
|
|
we just registered these commands and
|
|
|
|
the only possible way for unregistration
|
|
|
|
to fail is if the command is not
|
|
|
|
registered
|
|
|
|
*/
|
|
|
|
(void) ast_agi_unregister(mod, cmd + x - 1);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2007-07-30 19:11:28 +00:00
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
return 0;
|
2007-07-30 19:11:28 +00:00
|
|
|
}
|
|
|
|
|
2009-06-15 16:07:23 +00:00
|
|
|
int AST_OPTIONAL_API_NAME(ast_agi_unregister_multiple)(struct ast_module *mod, struct agi_command *cmd, unsigned int len)
|
2007-07-30 19:11:28 +00:00
|
|
|
{
|
2008-11-19 12:42:19 +00:00
|
|
|
unsigned int i;
|
|
|
|
int res = 0;
|
2007-07-30 19:11:28 +00:00
|
|
|
|
2008-11-19 12:42:19 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
/* remember whether any of the unregistration
|
|
|
|
attempts failed... there is no recourse if
|
|
|
|
any of them do
|
|
|
|
*/
|
|
|
|
res |= ast_agi_unregister(mod, cmd + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2007-07-30 19:11:28 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static agi_command *find_command(const char * const cmds[], int exact)
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2007-07-23 22:02:05 +00:00
|
|
|
int y, match;
|
|
|
|
struct agi_command *e;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_RDLOCK(&agi_commands);
|
|
|
|
AST_RWLIST_TRAVERSE(&agi_commands, e, list) {
|
|
|
|
if (!e->cmda[0])
|
2005-01-08 19:35:20 +00:00
|
|
|
break;
|
2007-08-01 04:36:15 +00:00
|
|
|
/* start optimistic */
|
|
|
|
match = 1;
|
|
|
|
for (y = 0; match && cmds[y]; y++) {
|
|
|
|
/* If there are no more words in the command (and we're looking for
|
|
|
|
an exact match) or there is a difference between the two words,
|
|
|
|
then this is not a match */
|
|
|
|
if (!e->cmda[y] && !exact)
|
|
|
|
break;
|
|
|
|
/* don't segfault if the next part of a command doesn't exist */
|
2008-07-15 18:46:40 +00:00
|
|
|
if (!e->cmda[y]) {
|
|
|
|
AST_RWLIST_UNLOCK(&agi_commands);
|
2007-08-01 04:36:15 +00:00
|
|
|
return NULL;
|
2008-07-15 18:46:40 +00:00
|
|
|
}
|
2007-08-01 04:36:15 +00:00
|
|
|
if (strcasecmp(e->cmda[y], cmds[y]))
|
2001-09-28 13:19:43 +00:00
|
|
|
match = 0;
|
2007-08-01 04:36:15 +00:00
|
|
|
}
|
|
|
|
/* If more words are needed to complete the command then this is not
|
|
|
|
a candidate (unless we're looking for a really inexact answer */
|
|
|
|
if ((exact > -1) && e->cmda[y])
|
|
|
|
match = 0;
|
2008-07-15 18:46:40 +00:00
|
|
|
if (match) {
|
|
|
|
AST_RWLIST_UNLOCK(&agi_commands);
|
2007-08-01 04:36:15 +00:00
|
|
|
return e;
|
2008-07-15 18:46:40 +00:00
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_UNLOCK(&agi_commands);
|
2001-09-28 13:19:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int parse_args(char *s, int *max, const char *argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2007-07-11 21:09:42 +00:00
|
|
|
int x = 0, quoted = 0, escaped = 0, whitespace = 1;
|
2001-09-28 13:19:43 +00:00
|
|
|
char *cur;
|
|
|
|
|
|
|
|
cur = s;
|
|
|
|
while(*s) {
|
|
|
|
switch(*s) {
|
|
|
|
case '"':
|
|
|
|
/* If it's escaped, put a literal quote */
|
2008-06-18 00:33:31 +00:00
|
|
|
if (escaped)
|
2001-09-28 13:19:43 +00:00
|
|
|
goto normal;
|
2008-06-18 00:33:31 +00:00
|
|
|
else
|
2001-09-28 13:19:43 +00:00
|
|
|
quoted = !quoted;
|
|
|
|
if (quoted && whitespace) {
|
|
|
|
/* If we're starting a quote, coming off white space start a new word, too */
|
|
|
|
argv[x++] = cur;
|
|
|
|
whitespace=0;
|
|
|
|
}
|
|
|
|
escaped = 0;
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
case '\t':
|
|
|
|
if (!quoted && !escaped) {
|
|
|
|
/* If we're not quoted, mark this as whitespace, and
|
|
|
|
end the previous argument */
|
|
|
|
whitespace = 1;
|
|
|
|
*(cur++) = '\0';
|
|
|
|
} else
|
2008-06-18 00:33:31 +00:00
|
|
|
/* Otherwise, just treat it as anything else */
|
2001-09-28 13:19:43 +00:00
|
|
|
goto normal;
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
/* If we're escaped, print a literal, otherwise enable escaping */
|
|
|
|
if (escaped) {
|
|
|
|
goto normal;
|
|
|
|
} else {
|
|
|
|
escaped=1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
normal:
|
|
|
|
if (whitespace) {
|
|
|
|
if (x >= MAX_ARGS -1) {
|
|
|
|
ast_log(LOG_WARNING, "Too many arguments, truncating\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Coming off of whitespace, start the next argument */
|
|
|
|
argv[x++] = cur;
|
|
|
|
whitespace=0;
|
|
|
|
}
|
|
|
|
*(cur++) = *s;
|
|
|
|
escaped=0;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
/* Null terminate */
|
|
|
|
*(cur++) = '\0';
|
|
|
|
argv[x] = NULL;
|
|
|
|
*max = x;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-06 19:51:12 +00:00
|
|
|
static void publish_async_exec_end(struct ast_channel *chan, int command_id, const char *command, int result_code, const char *result)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
|
|
|
|
blob = ast_json_pack("{s: i, s: s, s: i, s: s}",
|
|
|
|
"CommandId", command_id,
|
|
|
|
"Command", command,
|
|
|
|
"ResultCode", result_code,
|
|
|
|
"Result", result);
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ast_channel_publish_cached_blob(chan, agi_exec_end_type(), blob);
|
2013-06-06 19:51:12 +00:00
|
|
|
}
|
|
|
|
|
2011-04-13 16:37:06 +00:00
|
|
|
static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead)
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2009-05-21 21:13:09 +00:00
|
|
|
const char *argv[MAX_ARGS];
|
2011-04-13 17:51:14 +00:00
|
|
|
int argc = MAX_ARGS;
|
|
|
|
int res;
|
2001-09-28 13:19:43 +00:00
|
|
|
agi_command *c;
|
2007-12-14 17:29:27 +00:00
|
|
|
char *ami_cmd = ast_strdupa(buf);
|
2013-06-06 19:51:12 +00:00
|
|
|
const char *ami_res;
|
2011-04-13 17:51:14 +00:00
|
|
|
int command_id = ast_random();
|
2013-06-06 19:51:12 +00:00
|
|
|
int resultcode = 0;
|
|
|
|
RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
|
|
|
|
|
|
|
|
startblob = ast_json_pack("{s: i, s: s}",
|
|
|
|
"CommandId", command_id,
|
|
|
|
"Command", ami_cmd);
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
ast_channel_publish_cached_blob(chan, agi_exec_start_type(), startblob);
|
2007-12-14 17:29:27 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
parse_args(buf, &argc, argv);
|
2011-04-13 17:51:14 +00:00
|
|
|
c = find_command(argv, 0);
|
|
|
|
if (c && (!dead || (dead && c->dead))) {
|
|
|
|
/* if this command wasn't registered by res_agi, be sure to usecount
|
2007-07-30 19:11:28 +00:00
|
|
|
the module we are using */
|
|
|
|
if (c->mod != ast_module_info->self)
|
|
|
|
ast_module_ref(c->mod);
|
2003-02-23 06:00:11 +00:00
|
|
|
res = c->handler(chan, agi, argc, argv);
|
2007-07-30 19:11:28 +00:00
|
|
|
if (c->mod != ast_module_info->self)
|
|
|
|
ast_module_unref(c->mod);
|
2007-12-14 17:29:27 +00:00
|
|
|
switch (res) {
|
2011-04-13 17:51:14 +00:00
|
|
|
case RESULT_SHOWUSAGE:
|
|
|
|
ami_res = "Usage";
|
|
|
|
resultcode = 520;
|
2013-06-06 19:51:12 +00:00
|
|
|
|
|
|
|
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
|
|
|
|
|
2010-02-10 16:01:28 +00:00
|
|
|
if (ast_strlen_zero(c->usage)) {
|
|
|
|
ast_agi_send(agi->fd, chan, "520 Invalid command syntax. Proper usage not available.\n");
|
|
|
|
} else {
|
|
|
|
ast_agi_send(agi->fd, chan, "520-Invalid command syntax. Proper usage follows:\n");
|
|
|
|
ast_agi_send(agi->fd, chan, "%s", c->usage);
|
|
|
|
ast_agi_send(agi->fd, chan, "520 End of proper usage.\n");
|
|
|
|
}
|
2013-06-06 19:51:12 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
break;
|
|
|
|
case RESULT_FAILURE:
|
2013-06-06 19:51:12 +00:00
|
|
|
ami_res = "Failure";
|
|
|
|
resultcode = -1;
|
|
|
|
|
|
|
|
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
|
|
|
|
|
2011-04-13 16:37:06 +00:00
|
|
|
/* The RESULT_FAILURE code is usually because the channel hungup. */
|
|
|
|
return AGI_RESULT_FAILURE;
|
2013-06-06 19:51:12 +00:00
|
|
|
case ASYNC_AGI_BREAK:
|
|
|
|
ami_res = "Success";
|
|
|
|
resultcode = 200;
|
|
|
|
|
|
|
|
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
|
|
|
|
|
|
|
|
return AGI_RESULT_SUCCESS_ASYNC;
|
|
|
|
case RESULT_SUCCESS:
|
|
|
|
ami_res = "Success";
|
|
|
|
resultcode = 200;
|
|
|
|
|
|
|
|
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
|
|
|
|
|
|
|
|
break;
|
2011-04-13 16:37:06 +00:00
|
|
|
default:
|
2013-06-06 19:51:12 +00:00
|
|
|
ami_res = "Unknown Result";
|
|
|
|
resultcode = 200;
|
|
|
|
|
|
|
|
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
|
|
|
|
|
2011-04-13 16:37:06 +00:00
|
|
|
break;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2011-04-13 17:51:14 +00:00
|
|
|
} else if (c) {
|
2013-06-06 19:51:12 +00:00
|
|
|
ami_res = "Command Not Permitted on a dead channel";
|
|
|
|
resultcode = 511;
|
|
|
|
|
|
|
|
ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
|
|
|
|
|
|
|
|
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
|
2001-09-28 13:19:43 +00:00
|
|
|
} else {
|
2013-06-06 19:51:12 +00:00
|
|
|
ami_res = "Invalid or unknown command";
|
|
|
|
resultcode = 510;
|
|
|
|
|
|
|
|
ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
|
|
|
|
|
|
|
|
publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2013-06-06 19:51:12 +00:00
|
|
|
|
2011-04-13 16:37:06 +00:00
|
|
|
return AGI_RESULT_SUCCESS;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2006-10-17 23:06:13 +00:00
|
|
|
static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
|
|
|
struct ast_channel *c;
|
2011-04-13 17:51:14 +00:00
|
|
|
int outfd;
|
|
|
|
int ms;
|
|
|
|
int needhup = 0;
|
2006-05-25 16:44:22 +00:00
|
|
|
enum agi_result returnstatus = AGI_RESULT_SUCCESS;
|
2001-09-28 13:19:43 +00:00
|
|
|
struct ast_frame *f;
|
2007-09-11 15:28:46 +00:00
|
|
|
char buf[AGI_BUF_LEN];
|
2007-09-18 22:46:05 +00:00
|
|
|
char *res = NULL;
|
2001-09-28 13:19:43 +00:00
|
|
|
FILE *readf;
|
2008-06-18 00:33:31 +00:00
|
|
|
/* how many times we'll retry if ast_waitfor_nandfs will return without either
|
2004-03-03 18:58:57 +00:00
|
|
|
channel or file descriptor in case select is interrupted by a system call (EINTR) */
|
2007-09-11 15:28:46 +00:00
|
|
|
int retry = AGI_NANDFS_RETRY;
|
2008-12-22 23:25:34 +00:00
|
|
|
int send_sighup;
|
|
|
|
const char *sighup_str;
|
2012-02-14 00:43:50 +00:00
|
|
|
const char *exit_on_hangup_str;
|
|
|
|
int exit_on_hangup;
|
2013-07-31 23:48:35 +00:00
|
|
|
|
2008-12-22 23:25:34 +00:00
|
|
|
ast_channel_lock(chan);
|
|
|
|
sighup_str = pbx_builtin_getvar_helper(chan, "AGISIGHUP");
|
2012-02-14 00:43:50 +00:00
|
|
|
send_sighup = !ast_false(sighup_str);
|
|
|
|
exit_on_hangup_str = pbx_builtin_getvar_helper(chan, "AGIEXITONHANGUP");
|
|
|
|
exit_on_hangup = ast_true(exit_on_hangup_str);
|
2008-12-22 23:25:34 +00:00
|
|
|
ast_channel_unlock(chan);
|
2003-11-05 23:43:31 +00:00
|
|
|
|
2003-02-23 06:00:11 +00:00
|
|
|
if (!(readf = fdopen(agi->ctrl, "r"))) {
|
2001-09-28 13:19:43 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to fdopen file descriptor\n");
|
2008-12-22 23:25:34 +00:00
|
|
|
if (send_sighup && pid > -1)
|
2004-09-22 15:21:36 +00:00
|
|
|
kill(pid, SIGHUP);
|
2004-04-23 04:38:11 +00:00
|
|
|
close(agi->ctrl);
|
2006-05-25 16:44:22 +00:00
|
|
|
return AGI_RESULT_FAILURE;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
2013-07-31 23:48:35 +00:00
|
|
|
|
2001-09-28 13:19:43 +00:00
|
|
|
setlinebuf(readf);
|
2006-10-17 23:06:13 +00:00
|
|
|
setup_env(chan, request, agi->fd, (agi->audio > -1), argc, argv);
|
2001-09-28 13:19:43 +00:00
|
|
|
for (;;) {
|
2007-07-23 22:02:05 +00:00
|
|
|
if (needhup) {
|
|
|
|
needhup = 0;
|
|
|
|
dead = 1;
|
2008-12-22 23:25:34 +00:00
|
|
|
if (send_sighup) {
|
|
|
|
if (pid > -1) {
|
|
|
|
kill(pid, SIGHUP);
|
|
|
|
} else if (agi->fast) {
|
2011-11-15 20:11:06 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "HANGUP\n");
|
2008-12-22 23:25:34 +00:00
|
|
|
}
|
2008-08-09 01:15:38 +00:00
|
|
|
}
|
2012-02-14 00:43:50 +00:00
|
|
|
if (exit_on_hangup) {
|
|
|
|
break;
|
|
|
|
}
|
2007-07-23 22:02:05 +00:00
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
ms = -1;
|
2011-04-13 16:37:06 +00:00
|
|
|
if (dead) {
|
|
|
|
c = ast_waitfor_nandfds(&chan, 0, &agi->ctrl, 1, NULL, &outfd, &ms);
|
|
|
|
} else if (!ast_check_hangup(chan)) {
|
|
|
|
c = ast_waitfor_nandfds(&chan, 1, &agi->ctrl, 1, NULL, &outfd, &ms);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Read the channel control queue until it is dry so we can
|
|
|
|
* switch to dead mode.
|
|
|
|
*/
|
|
|
|
c = chan;
|
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
if (c) {
|
2007-09-11 15:28:46 +00:00
|
|
|
retry = AGI_NANDFS_RETRY;
|
2001-09-28 13:19:43 +00:00
|
|
|
/* Idle the channel until we get a command */
|
|
|
|
f = ast_read(c);
|
|
|
|
if (!f) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_debug(1, "%s hungup\n", ast_channel_name(chan));
|
2007-07-23 22:02:05 +00:00
|
|
|
needhup = 1;
|
2011-04-13 16:37:06 +00:00
|
|
|
if (!returnstatus) {
|
|
|
|
returnstatus = AGI_RESULT_HANGUP;
|
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
} else {
|
2003-02-23 06:00:11 +00:00
|
|
|
/* If it's voice, write it to the audio pipe */
|
|
|
|
if ((agi->audio > -1) && (f->frametype == AST_FRAME_VOICE)) {
|
|
|
|
/* Write, ignoring errors */
|
2008-11-02 18:52:13 +00:00
|
|
|
if (write(agi->audio, f->data.ptr, f->datalen) < 0) {
|
|
|
|
}
|
2003-02-23 06:00:11 +00:00
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
ast_frfree(f);
|
|
|
|
}
|
|
|
|
} else if (outfd > -1) {
|
2007-09-18 22:46:05 +00:00
|
|
|
size_t len = sizeof(buf);
|
|
|
|
size_t buflen = 0;
|
2011-04-13 16:37:06 +00:00
|
|
|
enum agi_result cmd_status;
|
2007-09-18 22:46:05 +00:00
|
|
|
|
2007-09-11 15:28:46 +00:00
|
|
|
retry = AGI_NANDFS_RETRY;
|
2007-08-22 19:54:52 +00:00
|
|
|
buf[0] = '\0';
|
2007-09-11 15:28:46 +00:00
|
|
|
|
2011-01-19 18:45:44 +00:00
|
|
|
while (len > 1) {
|
2007-09-18 22:46:05 +00:00
|
|
|
res = fgets(buf + buflen, len, readf);
|
2008-06-18 00:33:31 +00:00
|
|
|
if (feof(readf))
|
2007-09-18 22:46:05 +00:00
|
|
|
break;
|
2008-06-18 00:33:31 +00:00
|
|
|
if (ferror(readf) && ((errno != EINTR) && (errno != EAGAIN)))
|
2007-09-18 22:46:05 +00:00
|
|
|
break;
|
|
|
|
if (res != NULL && !agi->fast)
|
|
|
|
break;
|
|
|
|
buflen = strlen(buf);
|
2007-10-01 19:58:29 +00:00
|
|
|
if (buflen && buf[buflen - 1] == '\n')
|
|
|
|
break;
|
2011-01-19 18:45:44 +00:00
|
|
|
len = sizeof(buf) - buflen;
|
2007-09-18 22:46:05 +00:00
|
|
|
if (agidebug)
|
2012-07-25 21:22:34 +00:00
|
|
|
ast_verbose("AGI Rx << temp buffer %s - errno %s\nNo \\n received, checking again.\n", buf, strerror(errno));
|
2007-09-18 22:46:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!buf[0]) {
|
2001-09-28 13:19:43 +00:00
|
|
|
/* Program terminated */
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "<%s>AGI Script %s completed, returning %d\n", ast_channel_name(chan), request, returnstatus);
|
2006-10-24 20:22:29 +00:00
|
|
|
if (pid > 0)
|
|
|
|
waitpid(pid, status, 0);
|
2001-09-28 13:19:43 +00:00
|
|
|
/* No need to kill the pid anymore, since they closed us */
|
|
|
|
pid = -1;
|
|
|
|
break;
|
|
|
|
}
|
2007-09-11 15:28:46 +00:00
|
|
|
|
2008-04-17 12:59:04 +00:00
|
|
|
/* Special case for inability to execute child process */
|
|
|
|
if (*buf && strncasecmp(buf, "failure", 7) == 0) {
|
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-08 19:35:20 +00:00
|
|
|
/* get rid of trailing newline, if any */
|
2011-04-13 17:51:14 +00:00
|
|
|
buflen = strlen(buf);
|
|
|
|
if (buflen && buf[buflen - 1] == '\n') {
|
|
|
|
buf[buflen - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2004-09-25 14:22:27 +00:00
|
|
|
if (agidebug)
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verbose("<%s>AGI Rx << %s\n", ast_channel_name(chan), buf);
|
2011-04-13 16:37:06 +00:00
|
|
|
cmd_status = agi_handle_command(chan, agi, buf, dead);
|
|
|
|
switch (cmd_status) {
|
|
|
|
case AGI_RESULT_FAILURE:
|
|
|
|
if (dead || !ast_check_hangup(chan)) {
|
|
|
|
/* The failure was not because of a hangup. */
|
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2003-11-05 23:43:31 +00:00
|
|
|
if (--retry <= 0) {
|
|
|
|
ast_log(LOG_WARNING, "No channel, no fd?\n");
|
2006-05-25 16:44:22 +00:00
|
|
|
returnstatus = AGI_RESULT_FAILURE;
|
2003-11-05 23:43:31 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-27 15:46:46 +00:00
|
|
|
if (agi->speech) {
|
|
|
|
ast_speech_destroy(agi->speech);
|
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
/* Notify process */
|
2008-12-22 23:25:34 +00:00
|
|
|
if (send_sighup) {
|
2008-08-09 01:15:38 +00:00
|
|
|
if (pid > -1) {
|
2008-05-14 21:39:06 +00:00
|
|
|
if (kill(pid, SIGHUP)) {
|
2006-05-25 19:01:26 +00:00
|
|
|
ast_log(LOG_WARNING, "unable to send SIGHUP to AGI process %d: %s\n", pid, strerror(errno));
|
2008-05-14 21:39:06 +00:00
|
|
|
} else { /* Give the process a chance to die */
|
|
|
|
usleep(1);
|
|
|
|
}
|
2008-08-09 01:15:38 +00:00
|
|
|
waitpid(pid, status, WNOHANG);
|
|
|
|
} else if (agi->fast) {
|
2011-11-15 20:11:06 +00:00
|
|
|
ast_agi_send(agi->fd, chan, "HANGUP\n");
|
2006-05-25 19:01:26 +00:00
|
|
|
}
|
2005-08-03 04:17:12 +00:00
|
|
|
}
|
2001-09-28 13:19:43 +00:00
|
|
|
fclose(readf);
|
|
|
|
return returnstatus;
|
|
|
|
}
|
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *handle_cli_agi_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2006-04-06 16:17:04 +00:00
|
|
|
{
|
2007-09-18 22:43:45 +00:00
|
|
|
struct agi_command *command;
|
2008-11-12 00:17:43 +00:00
|
|
|
char fullcmd[MAX_CMD_LEN];
|
|
|
|
int error = 0;
|
2007-07-11 21:09:42 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
2008-09-28 23:32:14 +00:00
|
|
|
e->command = "agi show commands [topic]";
|
2007-09-18 22:43:45 +00:00
|
|
|
e->usage =
|
2010-02-10 16:01:28 +00:00
|
|
|
"Usage: agi show commands [topic] <topic>\n"
|
2007-09-18 22:43:45 +00:00
|
|
|
" When called with a topic as an argument, displays usage\n"
|
|
|
|
" information on the given command. If called without a\n"
|
|
|
|
" topic, it provides a list of AGI commands.\n";
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-10-12 09:19:23 +00:00
|
|
|
if (a->argc < e->args - 1 || (a->argc >= e->args && strcasecmp(a->argv[e->args - 1], "topic")))
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SHOWUSAGE;
|
2008-10-12 09:19:23 +00:00
|
|
|
if (a->argc > e->args - 1) {
|
2007-09-18 22:43:45 +00:00
|
|
|
command = find_command(a->argv + e->args, 1);
|
|
|
|
if (command) {
|
2008-11-12 00:17:43 +00:00
|
|
|
char *synopsis = NULL, *description = NULL, *syntax = NULL, *seealso = NULL;
|
|
|
|
char info[30 + MAX_CMD_LEN]; /* '-= Info about...' */
|
|
|
|
char infotitle[30 + MAX_CMD_LEN + AST_TERM_MAX_ESCAPE_CHARS]; /* '-= Info about...' with colors */
|
|
|
|
char syntitle[11 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Syntax]\n with colors */
|
|
|
|
char desctitle[15 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Description]\n with colors */
|
|
|
|
char deadtitle[13 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Runs Dead]\n with colors */
|
|
|
|
char deadcontent[3 + AST_TERM_MAX_ESCAPE_CHARS]; /* 'Yes' or 'No' with colors */
|
|
|
|
char seealsotitle[12 + AST_TERM_MAX_ESCAPE_CHARS]; /* [See Also]\n with colors */
|
|
|
|
char stxtitle[10 + AST_TERM_MAX_ESCAPE_CHARS]; /* [Syntax]\n with colors */
|
|
|
|
size_t synlen, desclen, seealsolen, stxlen;
|
|
|
|
|
|
|
|
term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, sizeof(syntitle));
|
|
|
|
term_color(desctitle, "[Description]\n", COLOR_MAGENTA, 0, sizeof(desctitle));
|
|
|
|
term_color(deadtitle, "[Runs Dead]\n", COLOR_MAGENTA, 0, sizeof(deadtitle));
|
|
|
|
term_color(seealsotitle, "[See Also]\n", COLOR_MAGENTA, 0, sizeof(seealsotitle));
|
|
|
|
term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, sizeof(stxtitle));
|
|
|
|
term_color(deadcontent, command->dead ? "Yes" : "No", COLOR_CYAN, 0, sizeof(deadcontent));
|
|
|
|
|
|
|
|
ast_join(fullcmd, sizeof(fullcmd), a->argv + e->args);
|
|
|
|
snprintf(info, sizeof(info), "\n -= Info about agi '%s' =- ", fullcmd);
|
|
|
|
term_color(infotitle, info, COLOR_CYAN, 0, sizeof(infotitle));
|
|
|
|
#ifdef AST_XML_DOCS
|
|
|
|
if (command->docsrc == AST_XML_DOC) {
|
|
|
|
synopsis = ast_xmldoc_printable(S_OR(command->summary, "Not available"), 1);
|
|
|
|
description = ast_xmldoc_printable(S_OR(command->usage, "Not available"), 1);
|
|
|
|
seealso = ast_xmldoc_printable(S_OR(command->seealso, "Not available"), 1);
|
|
|
|
if (!seealso || !description || !synopsis) {
|
|
|
|
error = 1;
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
synlen = strlen(S_OR(command->summary, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
|
|
|
|
synopsis = ast_malloc(synlen);
|
|
|
|
|
|
|
|
desclen = strlen(S_OR(command->usage, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
|
|
|
|
description = ast_malloc(desclen);
|
|
|
|
|
|
|
|
seealsolen = strlen(S_OR(command->seealso, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
|
|
|
|
seealso = ast_malloc(seealsolen);
|
|
|
|
|
|
|
|
if (!synopsis || !description || !seealso) {
|
|
|
|
error = 1;
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
term_color(synopsis, S_OR(command->summary, "Not available"), COLOR_CYAN, 0, synlen);
|
|
|
|
term_color(description, S_OR(command->usage, "Not available"), COLOR_CYAN, 0, desclen);
|
|
|
|
term_color(seealso, S_OR(command->seealso, "Not available"), COLOR_CYAN, 0, seealsolen);
|
|
|
|
}
|
|
|
|
|
|
|
|
stxlen = strlen(S_OR(command->syntax, "Not available")) + AST_TERM_MAX_ESCAPE_CHARS;
|
|
|
|
syntax = ast_malloc(stxlen);
|
|
|
|
if (!syntax) {
|
|
|
|
error = 1;
|
|
|
|
goto return_cleanup;
|
|
|
|
}
|
|
|
|
term_color(syntax, S_OR(command->syntax, "Not available"), COLOR_CYAN, 0, stxlen);
|
|
|
|
|
|
|
|
ast_cli(a->fd, "%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n", infotitle, stxtitle, syntax,
|
|
|
|
desctitle, description, syntitle, synopsis, deadtitle, deadcontent,
|
|
|
|
seealsotitle, seealso);
|
|
|
|
return_cleanup:
|
|
|
|
ast_free(synopsis);
|
|
|
|
ast_free(description);
|
|
|
|
ast_free(syntax);
|
|
|
|
ast_free(seealso);
|
2007-07-23 22:02:05 +00:00
|
|
|
} else {
|
2007-09-18 22:43:45 +00:00
|
|
|
if (find_command(a->argv + e->args, -1)) {
|
|
|
|
return help_workhorse(a->fd, a->argv + e->args);
|
2003-02-06 22:11:43 +00:00
|
|
|
} else {
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_join(fullcmd, sizeof(fullcmd), a->argv + e->args);
|
|
|
|
ast_cli(a->fd, "No such command '%s'.\n", fullcmd);
|
2003-02-06 22:11:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-09-18 22:43:45 +00:00
|
|
|
return help_workhorse(a->fd, NULL);
|
2003-02-06 22:11:43 +00:00
|
|
|
}
|
2008-11-12 00:17:43 +00:00
|
|
|
return (error ? CLI_FAILURE : CLI_SUCCESS);
|
2003-02-06 22:11:43 +00:00
|
|
|
}
|
|
|
|
|
2007-02-16 11:47:48 +00:00
|
|
|
/*! \brief Convert string to use HTML escaped characters
|
|
|
|
\note Maybe this should be a generic function?
|
|
|
|
*/
|
|
|
|
static void write_html_escaped(FILE *htmlfile, char *str)
|
|
|
|
{
|
|
|
|
char *cur = str;
|
|
|
|
|
|
|
|
while(*cur) {
|
|
|
|
switch (*cur) {
|
|
|
|
case '<':
|
|
|
|
fprintf(htmlfile, "%s", "<");
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
fprintf(htmlfile, "%s", ">");
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
fprintf(htmlfile, "%s", "&");
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
fprintf(htmlfile, "%s", """);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(htmlfile, "%c", *cur);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cur++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int write_htmldump(const char *filename)
|
2006-04-06 16:17:04 +00:00
|
|
|
{
|
2007-09-18 22:43:45 +00:00
|
|
|
struct agi_command *command;
|
2008-11-12 00:17:43 +00:00
|
|
|
char fullcmd[MAX_CMD_LEN];
|
2003-02-06 22:11:43 +00:00
|
|
|
FILE *htmlfile;
|
|
|
|
|
2008-02-08 21:26:32 +00:00
|
|
|
if (!(htmlfile = fopen(filename, "wt")))
|
|
|
|
return -1;
|
2003-02-06 22:11:43 +00:00
|
|
|
|
|
|
|
fprintf(htmlfile, "<HTML>\n<HEAD>\n<TITLE>AGI Commands</TITLE>\n</HEAD>\n");
|
|
|
|
fprintf(htmlfile, "<BODY>\n<CENTER><B><H1>AGI Commands</H1></B></CENTER>\n\n");
|
|
|
|
fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
|
|
|
|
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_RDLOCK(&agi_commands);
|
2007-09-18 22:43:45 +00:00
|
|
|
AST_RWLIST_TRAVERSE(&agi_commands, command, list) {
|
2008-11-12 00:17:43 +00:00
|
|
|
char *tempstr, *stringp;
|
2008-06-18 00:33:31 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
if (!command->cmda[0]) /* end ? */
|
2005-12-20 20:20:04 +00:00
|
|
|
break;
|
2003-02-06 22:11:43 +00:00
|
|
|
/* Hide commands that start with '_' */
|
2007-09-18 22:43:45 +00:00
|
|
|
if ((command->cmda[0])[0] == '_')
|
2003-02-06 22:11:43 +00:00
|
|
|
continue;
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_join(fullcmd, sizeof(fullcmd), command->cmda);
|
2003-02-06 22:11:43 +00:00
|
|
|
|
|
|
|
fprintf(htmlfile, "<TR><TD><TABLE BORDER=\"1\" CELLPADDING=\"5\" WIDTH=\"100%%\">\n");
|
2007-09-18 22:43:45 +00:00
|
|
|
fprintf(htmlfile, "<TR><TH ALIGN=\"CENTER\"><B>%s - %s</B></TH></TR>\n", fullcmd, command->summary);
|
2008-11-12 00:17:43 +00:00
|
|
|
#ifdef AST_XML_DOCS
|
2013-08-30 17:59:06 +00:00
|
|
|
stringp = ast_xmldoc_printable(command->usage, 0);
|
2008-11-12 00:17:43 +00:00
|
|
|
#else
|
2009-05-22 16:51:22 +00:00
|
|
|
stringp = ast_strdup(command->usage);
|
2008-11-12 00:17:43 +00:00
|
|
|
#endif
|
2003-02-06 22:11:43 +00:00
|
|
|
tempstr = strsep(&stringp, "\n");
|
|
|
|
|
2007-02-16 11:47:48 +00:00
|
|
|
fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">");
|
|
|
|
write_html_escaped(htmlfile, tempstr);
|
|
|
|
fprintf(htmlfile, "</TD></TR>\n");
|
2003-02-06 22:11:43 +00:00
|
|
|
fprintf(htmlfile, "<TR><TD ALIGN=\"CENTER\">\n");
|
2007-09-18 22:43:45 +00:00
|
|
|
|
2007-02-16 11:47:48 +00:00
|
|
|
while ((tempstr = strsep(&stringp, "\n")) != NULL) {
|
|
|
|
write_html_escaped(htmlfile, tempstr);
|
|
|
|
fprintf(htmlfile, "<BR>\n");
|
|
|
|
}
|
2003-02-06 22:11:43 +00:00
|
|
|
fprintf(htmlfile, "</TD></TR>\n");
|
|
|
|
fprintf(htmlfile, "</TABLE></TD></TR>\n\n");
|
2009-05-22 16:51:22 +00:00
|
|
|
ast_free(stringp);
|
2003-02-06 22:11:43 +00:00
|
|
|
}
|
2007-07-23 22:02:05 +00:00
|
|
|
AST_RWLIST_UNLOCK(&agi_commands);
|
2003-02-06 22:11:43 +00:00
|
|
|
fprintf(htmlfile, "</TABLE>\n</BODY>\n</HTML>\n");
|
|
|
|
fclose(htmlfile);
|
2008-02-08 21:26:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *handle_cli_agi_dump_html(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "agi dump html";
|
|
|
|
e->usage =
|
|
|
|
"Usage: agi dump html <filename>\n"
|
|
|
|
" Dumps the AGI command list in HTML format to the given\n"
|
|
|
|
" file.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (a->argc != e->args + 1)
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
|
|
|
|
if (write_htmldump(a->argv[e->args]) < 0) {
|
|
|
|
ast_cli(a->fd, "Could not create file '%s'\n", a->argv[e->args]);
|
|
|
|
return CLI_SHOWUSAGE;
|
|
|
|
}
|
|
|
|
ast_cli(a->fd, "AGI HTML commands dumped to: %s\n", a->argv[e->args]);
|
|
|
|
return CLI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int agi_exec_full(struct ast_channel *chan, const char *data, int enhanced, int dead)
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2006-05-25 16:44:22 +00:00
|
|
|
enum agi_result res;
|
2009-05-21 21:13:09 +00:00
|
|
|
char *buf;
|
2010-01-19 00:28:49 +00:00
|
|
|
int fds[2], efd = -1, pid = -1;
|
2007-07-23 20:27:26 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(arg)[MAX_ARGS];
|
|
|
|
);
|
2003-02-23 06:00:11 +00:00
|
|
|
AGI agi;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2005-11-08 01:55:31 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2001-09-28 13:19:43 +00:00
|
|
|
ast_log(LOG_WARNING, "AGI requires an argument (script)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-02-21 17:44:34 +00:00
|
|
|
if (dead)
|
|
|
|
ast_debug(3, "Hungup channel detected, running agi in dead mode.\n");
|
2003-02-23 06:00:11 +00:00
|
|
|
memset(&agi, 0, sizeof(agi));
|
2009-05-21 21:13:09 +00:00
|
|
|
buf = ast_strdupa(data);
|
|
|
|
AST_STANDARD_APP_ARGS(args, buf);
|
2007-07-23 20:27:26 +00:00
|
|
|
args.argv[args.argc] = NULL;
|
2002-06-14 15:50:42 +00:00
|
|
|
#if 0
|
2001-09-28 13:19:43 +00:00
|
|
|
/* Answer if need be */
|
2007-07-23 22:02:05 +00:00
|
|
|
if (chan->_state != AST_STATE_UP) {
|
2008-02-11 18:29:18 +00:00
|
|
|
if (ast_answer(chan))
|
2001-09-28 13:19:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2002-06-14 15:50:42 +00:00
|
|
|
#endif
|
2013-06-10 16:03:51 +00:00
|
|
|
res = launch_script(chan, args.argv[0], args.argc, args.argv, fds, enhanced ? &efd : NULL, &pid);
|
2008-01-03 06:16:48 +00:00
|
|
|
/* Async AGI do not require run_agi(), so just proceed if normal AGI
|
|
|
|
or Fast AGI are setup with success. */
|
2007-09-18 22:46:05 +00:00
|
|
|
if (res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) {
|
2006-05-25 18:31:19 +00:00
|
|
|
int status = 0;
|
2003-02-23 06:00:11 +00:00
|
|
|
agi.fd = fds[1];
|
|
|
|
agi.ctrl = fds[0];
|
|
|
|
agi.audio = efd;
|
2007-09-18 22:46:05 +00:00
|
|
|
agi.fast = (res == AGI_RESULT_SUCCESS_FAST) ? 1 : 0;
|
2007-07-23 20:27:26 +00:00
|
|
|
res = run_agi(chan, args.argv[0], &agi, pid, &status, dead, args.argc, args.argv);
|
2006-05-25 18:31:19 +00:00
|
|
|
/* If the fork'd process returns non-zero, set AGISTATUS to FAILURE */
|
2007-09-18 22:46:05 +00:00
|
|
|
if ((res == AGI_RESULT_SUCCESS || res == AGI_RESULT_SUCCESS_FAST) && status)
|
2006-05-25 18:31:19 +00:00
|
|
|
res = AGI_RESULT_FAILURE;
|
2006-09-06 20:04:17 +00:00
|
|
|
if (fds[1] != fds[0])
|
|
|
|
close(fds[1]);
|
2003-02-23 06:00:11 +00:00
|
|
|
if (efd > -1)
|
|
|
|
close(efd);
|
2008-06-18 00:33:31 +00:00
|
|
|
}
|
2008-04-16 22:57:54 +00:00
|
|
|
ast_safe_fork_cleanup();
|
2006-05-25 16:44:22 +00:00
|
|
|
|
|
|
|
switch (res) {
|
|
|
|
case AGI_RESULT_SUCCESS:
|
2007-09-18 22:46:05 +00:00
|
|
|
case AGI_RESULT_SUCCESS_FAST:
|
2008-01-03 06:16:48 +00:00
|
|
|
case AGI_RESULT_SUCCESS_ASYNC:
|
2006-05-25 16:44:22 +00:00
|
|
|
pbx_builtin_setvar_helper(chan, "AGISTATUS", "SUCCESS");
|
|
|
|
break;
|
|
|
|
case AGI_RESULT_FAILURE:
|
|
|
|
pbx_builtin_setvar_helper(chan, "AGISTATUS", "FAILURE");
|
|
|
|
break;
|
2007-06-21 15:58:05 +00:00
|
|
|
case AGI_RESULT_NOTFOUND:
|
|
|
|
pbx_builtin_setvar_helper(chan, "AGISTATUS", "NOTFOUND");
|
|
|
|
break;
|
2006-05-25 16:44:22 +00:00
|
|
|
case AGI_RESULT_HANGUP:
|
|
|
|
pbx_builtin_setvar_helper(chan, "AGISTATUS", "HANGUP");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-09-06 15:26:45 +00:00
|
|
|
return 0;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int agi_exec(struct ast_channel *chan, const char *data)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
2007-07-23 22:02:05 +00:00
|
|
|
if (!ast_check_hangup(chan))
|
|
|
|
return agi_exec_full(chan, data, 0, 0);
|
|
|
|
else
|
|
|
|
return agi_exec_full(chan, data, 0, 1);
|
2003-02-23 06:00:11 +00:00
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int eagi_exec(struct ast_channel *chan, const char *data)
|
2003-02-23 06:00:11 +00:00
|
|
|
{
|
2011-02-03 16:22:10 +00:00
|
|
|
int res;
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
struct ast_format *readformat;
|
2005-01-08 19:35:20 +00:00
|
|
|
|
2007-07-19 15:59:19 +00:00
|
|
|
if (ast_check_hangup(chan)) {
|
2008-03-06 19:31:50 +00:00
|
|
|
ast_log(LOG_ERROR, "EAGI cannot be run on a dead/hungup channel, please use AGI.\n");
|
2007-07-19 15:59:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
readformat = ao2_bump(ast_channel_readformat(chan));
|
|
|
|
if (ast_set_read_format(chan, ast_format_slin)) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to set channel '%s' to linear mode\n", ast_channel_name(chan));
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_ref(readformat, -1);
|
2003-02-23 06:00:11 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-03-03 18:58:57 +00:00
|
|
|
res = agi_exec_full(chan, data, 1, 0);
|
2003-02-23 06:00:11 +00:00
|
|
|
if (!res) {
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
if (ast_set_read_format(chan, readformat)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format %s\n", ast_channel_name(chan),
|
|
|
|
ast_format_get_name(readformat));
|
2003-02-23 06:00:11 +00:00
|
|
|
}
|
|
|
|
}
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_ref(readformat, -1);
|
2003-02-23 06:00:11 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int deadagi_exec(struct ast_channel *chan, const char *data)
|
2004-03-03 18:58:57 +00:00
|
|
|
{
|
2007-11-28 15:38:03 +00:00
|
|
|
ast_log(LOG_WARNING, "DeadAGI has been deprecated, please use AGI in all cases!\n");
|
2007-07-23 22:02:05 +00:00
|
|
|
return agi_exec(chan, data);
|
2004-03-03 18:58:57 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
static struct ast_cli_entry cli_agi[] = {
|
2008-01-03 06:16:48 +00:00
|
|
|
AST_CLI_DEFINE(handle_cli_agi_add_cmd, "Add AGI command to a channel in Async AGI"),
|
2008-02-08 21:26:32 +00:00
|
|
|
AST_CLI_DEFINE(handle_cli_agi_debug, "Enable/Disable AGI debugging"),
|
|
|
|
AST_CLI_DEFINE(handle_cli_agi_show, "List AGI commands or specific help"),
|
2008-11-12 06:46:04 +00:00
|
|
|
AST_CLI_DEFINE(handle_cli_agi_dump_html, "Dumps a list of AGI commands in HTML format")
|
2006-09-18 19:54:18 +00:00
|
|
|
};
|
2003-02-06 22:11:43 +00:00
|
|
|
|
2010-02-10 16:01:28 +00:00
|
|
|
#ifdef TEST_FRAMEWORK
|
|
|
|
AST_TEST_DEFINE(test_agi_null_docs)
|
|
|
|
{
|
|
|
|
int res = AST_TEST_PASS;
|
|
|
|
struct agi_command noop_command =
|
|
|
|
{ { "testnoop", NULL }, handle_noop, NULL, NULL, 0 };
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case TEST_INIT:
|
|
|
|
info->name = "null_agi_docs";
|
2010-07-09 17:00:22 +00:00
|
|
|
info->category = "/res/agi/";
|
2010-02-10 16:01:28 +00:00
|
|
|
info->summary = "AGI command with no documentation";
|
|
|
|
info->description = "Test whether an AGI command with no documentation will crash Asterisk";
|
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
case TEST_EXECUTE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_agi_register(ast_module_info->self, &noop_command) == 0) {
|
2010-09-30 20:40:08 +00:00
|
|
|
ast_test_status_update(test, "Unable to register testnoop command, because res_agi is not loaded.\n");
|
2010-02-10 16:01:28 +00:00
|
|
|
return AST_TEST_NOT_RUN;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef HAVE_NULLSAFE_PRINTF
|
|
|
|
/* Test for condition without actually crashing Asterisk */
|
|
|
|
if (noop_command.usage == NULL) {
|
2010-09-30 20:40:08 +00:00
|
|
|
ast_test_status_update(test, "AGI testnoop usage was not updated properly.\n");
|
2010-02-10 16:01:28 +00:00
|
|
|
res = AST_TEST_FAIL;
|
|
|
|
}
|
2010-04-27 22:47:36 +00:00
|
|
|
if (noop_command.syntax == NULL) {
|
2010-09-30 20:40:08 +00:00
|
|
|
ast_test_status_update(test, "AGI testnoop syntax was not updated properly.\n");
|
2010-02-10 16:01:28 +00:00
|
|
|
res = AST_TEST_FAIL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ast_agi_unregister(ast_module_info->self, &noop_command);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2013-06-06 19:51:12 +00:00
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_end_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(agi_async_start_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(agi_async_exec_type);
|
|
|
|
STASIS_MESSAGE_TYPE_CLEANUP(agi_async_end_type);
|
|
|
|
|
2008-12-05 10:31:25 +00:00
|
|
|
ast_cli_unregister_multiple(cli_agi, ARRAY_LEN(cli_agi));
|
2013-10-08 15:12:46 +00:00
|
|
|
ast_agi_unregister_multiple(ast_module_info->self, commands, ARRAY_LEN(commands));
|
2003-02-23 06:00:11 +00:00
|
|
|
ast_unregister_application(eapp);
|
2004-03-03 18:58:57 +00:00
|
|
|
ast_unregister_application(deadapp);
|
2008-01-03 06:16:48 +00:00
|
|
|
ast_manager_unregister("AGI");
|
2013-10-08 15:12:46 +00:00
|
|
|
ast_unregister_application(app);
|
2010-02-10 16:01:28 +00:00
|
|
|
AST_TEST_UNREGISTER(test_agi_null_docs);
|
2013-10-08 15:12:46 +00:00
|
|
|
return 0;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2001-09-28 13:19:43 +00:00
|
|
|
{
|
2013-10-08 15:12:46 +00:00
|
|
|
int err = 0;
|
2013-06-06 19:51:12 +00:00
|
|
|
|
2013-10-08 15:12:46 +00:00
|
|
|
err |= STASIS_MESSAGE_TYPE_INIT(agi_exec_start_type);
|
|
|
|
err |= STASIS_MESSAGE_TYPE_INIT(agi_exec_end_type);
|
|
|
|
err |= STASIS_MESSAGE_TYPE_INIT(agi_async_start_type);
|
|
|
|
err |= STASIS_MESSAGE_TYPE_INIT(agi_async_exec_type);
|
|
|
|
err |= STASIS_MESSAGE_TYPE_INIT(agi_async_end_type);
|
|
|
|
|
|
|
|
err |= ast_cli_register_multiple(cli_agi, ARRAY_LEN(cli_agi));
|
|
|
|
err |= ast_agi_register_multiple(ast_module_info->self, commands, ARRAY_LEN(commands));
|
|
|
|
err |= ast_register_application_xml(deadapp, deadagi_exec);
|
|
|
|
err |= ast_register_application_xml(eapp, eagi_exec);
|
|
|
|
err |= ast_manager_register_xml("AGI", EVENT_FLAG_AGI, action_add_agi_cmd);
|
|
|
|
err |= ast_register_application_xml(app, agi_exec);
|
2013-06-06 19:51:12 +00:00
|
|
|
|
2010-02-10 16:01:28 +00:00
|
|
|
AST_TEST_REGISTER(test_agi_null_docs);
|
2013-10-08 15:12:46 +00:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
unload_module();
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
|
|
|
}
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
2001-09-28 13:19:43 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 19:35:02 +00:00
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Asterisk Gateway Interface (AGI)",
|
2014-07-25 16:47:17 +00:00
|
|
|
.support_level = AST_MODULE_SUPPORT_CORE,
|
2007-07-23 22:02:05 +00:00
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
2010-07-20 19:35:02 +00:00
|
|
|
.load_pri = AST_MODPRI_APP_DEPEND,
|
2007-05-20 18:01:05 +00:00
|
|
|
);
|