2003-02-04 15:48:42 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2003-02-04 15:48:42 +00:00
|
|
|
*
|
2010-03-27 06:09:26 +00:00
|
|
|
* Copyright (C) 1999 - 2010, Digium, Inc.
|
2003-02-04 15:48:42 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
|
|
|
*
|
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.
|
|
|
|
*
|
2003-02-04 15:48:42 +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 Full-featured outgoing call spool support
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2003-02-04 15:48:42 +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"
|
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <utime.h>
|
|
|
|
#include <dirent.h>
|
2010-03-27 06:09:26 +00:00
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
#include <sys/inotify.h>
|
2010-05-13 15:33:49 +00:00
|
|
|
#elif defined(HAVE_KQUEUE)
|
2010-05-13 05:37:31 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/event.h>
|
|
|
|
#include <fcntl.h>
|
2010-03-27 06:09:26 +00:00
|
|
|
#endif
|
2005-06-06 22:12:19 +00:00
|
|
|
|
2007-11-20 23:16:15 +00:00
|
|
|
#include "asterisk/paths.h" /* use ast_config_AST_SPOOL_DIR */
|
2005-06-06 22:12:19 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/callerid.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/utils.h"
|
2008-12-03 17:01:03 +00:00
|
|
|
#include "asterisk/options.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.h"
|
|
|
|
#include "asterisk/format_cache.h"
|
2005-06-06 22:12:19 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
/*
|
|
|
|
* pbx_spool is similar in spirit to qcall, but with substantially enhanced functionality...
|
|
|
|
* The spool file contains a header
|
|
|
|
*/
|
|
|
|
|
2006-05-19 22:51:44 +00:00
|
|
|
enum {
|
|
|
|
/*! Always delete the call file after a call succeeds or the
|
|
|
|
* maximum number of retries is exceeded, even if the
|
|
|
|
* modification time of the call file is in the future.
|
|
|
|
*/
|
2006-05-25 17:58:55 +00:00
|
|
|
SPOOL_FLAG_ALWAYS_DELETE = (1 << 0),
|
|
|
|
/* Don't unlink the call file after processing, move in qdonedir */
|
2010-11-10 23:14:45 +00:00
|
|
|
SPOOL_FLAG_ARCHIVE = (1 << 1),
|
2012-08-08 22:39:40 +00:00
|
|
|
/* Connect the channel with the outgoing extension once early media is received */
|
|
|
|
SPOOL_FLAG_EARLY_MEDIA = (1 << 2),
|
2006-05-19 22:51:44 +00:00
|
|
|
};
|
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
static char qdir[255];
|
2006-05-25 17:58:55 +00:00
|
|
|
static char qdonedir[255];
|
2003-02-04 15:48:42 +00:00
|
|
|
|
|
|
|
struct outgoing {
|
2008-05-14 08:16:25 +00:00
|
|
|
int retries; /*!< Current number of retries */
|
|
|
|
int maxretries; /*!< Maximum number of retries permitted */
|
|
|
|
int retrytime; /*!< How long to wait between retries (in seconds) */
|
|
|
|
int waittime; /*!< How long to wait for an answer */
|
|
|
|
long callingpid; /*!< PID which is currently calling */
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format_cap *capabilities; /*!< Formats (codecs) for this call */
|
2009-03-03 17:03:47 +00:00
|
|
|
AST_DECLARE_STRING_FIELDS (
|
|
|
|
AST_STRING_FIELD(fn); /*!< File name of call file */
|
|
|
|
AST_STRING_FIELD(tech); /*!< Which channel technology to use for outgoing call */
|
|
|
|
AST_STRING_FIELD(dest); /*!< Which device/line to use for outgoing call */
|
|
|
|
AST_STRING_FIELD(app); /*!< If application: Application name */
|
|
|
|
AST_STRING_FIELD(data); /*!< If application: Application data */
|
|
|
|
AST_STRING_FIELD(exten); /*!< If extension/context/priority: Extension in dialplan */
|
|
|
|
AST_STRING_FIELD(context); /*!< If extension/context/priority: Dialplan context */
|
|
|
|
AST_STRING_FIELD(cid_num); /*!< CallerID Information: Number/extension */
|
|
|
|
AST_STRING_FIELD(cid_name); /*!< CallerID Information: Name */
|
|
|
|
AST_STRING_FIELD(account); /*!< account code */
|
|
|
|
);
|
2008-05-14 08:16:25 +00:00
|
|
|
int priority; /*!< If extension/context/priority: Dialplan priority */
|
|
|
|
struct ast_variable *vars; /*!< Variables and Functions */
|
|
|
|
int maxlen; /*!< Maximum length of call */
|
|
|
|
struct ast_flags options; /*!< options */
|
2003-02-04 15:48:42 +00:00
|
|
|
};
|
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
2015-05-11 12:07:31 +00:00
|
|
|
struct direntry {
|
|
|
|
AST_LIST_ENTRY(direntry) list;
|
|
|
|
time_t mtime;
|
|
|
|
char name[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
static AST_LIST_HEAD_STATIC(dirlist, direntry);
|
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
static void queue_file(const char *filename, time_t when);
|
|
|
|
#endif
|
|
|
|
|
2012-10-08 21:24:11 +00:00
|
|
|
static void free_outgoing(struct outgoing *o)
|
|
|
|
{
|
|
|
|
if (o->vars) {
|
|
|
|
ast_variables_destroy(o->vars);
|
|
|
|
}
|
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_cleanup(o->capabilities);
|
2012-10-08 21:24:11 +00:00
|
|
|
ast_string_field_free_memory(o);
|
|
|
|
ast_free(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct outgoing *new_outgoing(const char *fn)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2012-10-08 21:24:11 +00:00
|
|
|
struct outgoing *o;
|
2011-02-03 16:22:10 +00:00
|
|
|
|
2012-10-08 21:24:11 +00:00
|
|
|
o = ast_calloc(1, sizeof(*o));
|
|
|
|
if (!o) {
|
|
|
|
return NULL;
|
2011-02-03 16:22:10 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 21:24:11 +00:00
|
|
|
/* Initialize the new object. */
|
|
|
|
o->priority = 1;
|
|
|
|
o->retrytime = 300;
|
|
|
|
o->waittime = 45;
|
2006-05-19 22:51:44 +00:00
|
|
|
ast_set_flag(&o->options, SPOOL_FLAG_ALWAYS_DELETE);
|
2009-03-03 17:03:47 +00:00
|
|
|
if (ast_string_field_init(o, 128)) {
|
2012-10-08 21:24:11 +00:00
|
|
|
/*
|
|
|
|
* No need to call free_outgoing here since the failure was to
|
|
|
|
* allocate string fields and no variables have been allocated
|
|
|
|
* yet.
|
|
|
|
*/
|
|
|
|
ast_free(o);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ast_string_field_set(o, fn, fn);
|
|
|
|
if (ast_strlen_zero(o->fn)) {
|
|
|
|
/* String field set failed. Since this string is important we must fail. */
|
|
|
|
free_outgoing(o);
|
|
|
|
return NULL;
|
2009-03-03 17:03:47 +00:00
|
|
|
}
|
2003-02-04 15:48:42 +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
|
|
|
o->capabilities = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
2012-10-08 21:24:11 +00:00
|
|
|
if (!o->capabilities) {
|
|
|
|
free_outgoing(o);
|
|
|
|
return NULL;
|
2008-10-14 22:38:06 +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
|
|
|
ast_format_cap_append(o->capabilities, ast_format_slin, 0);
|
2012-10-08 21:24:11 +00:00
|
|
|
|
|
|
|
return o;
|
2005-10-11 20:44:23 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 21:24:11 +00:00
|
|
|
static int apply_outgoing(struct outgoing *o, FILE *f)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
char *c, *c2;
|
|
|
|
int lineno = 0;
|
2008-06-18 20:23:58 +00:00
|
|
|
struct ast_variable *var, *last = o->vars;
|
|
|
|
|
|
|
|
while (last && last->next) {
|
|
|
|
last = last->next;
|
|
|
|
}
|
2005-07-15 23:24:51 +00:00
|
|
|
|
2005-04-01 21:31:12 +00:00
|
|
|
while(fgets(buf, sizeof(buf), f)) {
|
2003-02-04 15:48:42 +00:00
|
|
|
lineno++;
|
2005-07-15 00:15:14 +00:00
|
|
|
/* Trim comments */
|
|
|
|
c = buf;
|
|
|
|
while ((c = strchr(c, '#'))) {
|
|
|
|
if ((c == buf) || (*(c-1) == ' ') || (*(c-1) == '\t'))
|
|
|
|
*c = '\0';
|
|
|
|
else
|
|
|
|
c++;
|
|
|
|
}
|
2005-10-11 20:52:37 +00:00
|
|
|
|
|
|
|
c = buf;
|
|
|
|
while ((c = strchr(c, ';'))) {
|
|
|
|
if ((c > buf) && (c[-1] == '\\')) {
|
|
|
|
memmove(c - 1, c, strlen(c) + 1);
|
|
|
|
c++;
|
|
|
|
} else {
|
|
|
|
*c = '\0';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2005-07-15 00:15:14 +00:00
|
|
|
/* Trim trailing white space */
|
2012-10-08 21:24:11 +00:00
|
|
|
ast_trim_blanks(buf);
|
|
|
|
if (ast_strlen_zero(buf)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
c = strchr(buf, ':');
|
|
|
|
if (!c) {
|
|
|
|
ast_log(LOG_NOTICE, "Syntax error at line %d of %s\n", lineno, o->fn);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*c = '\0';
|
|
|
|
c = ast_skip_blanks(c + 1);
|
2003-02-04 15:48:42 +00:00
|
|
|
#if 0
|
2012-10-08 21:24:11 +00:00
|
|
|
printf("'%s' is '%s' at line %d\n", buf, c, lineno);
|
2005-07-15 00:15:14 +00:00
|
|
|
#endif
|
2012-10-08 21:24:11 +00:00
|
|
|
if (!strcasecmp(buf, "channel")) {
|
|
|
|
if ((c2 = strchr(c, '/'))) {
|
|
|
|
*c2 = '\0';
|
|
|
|
c2++;
|
|
|
|
ast_string_field_set(o, tech, c);
|
|
|
|
ast_string_field_set(o, dest, c2);
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_NOTICE, "Channel should be in form Tech/Dest at line %d of %s\n", lineno, o->fn);
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(buf, "callerid")) {
|
|
|
|
char cid_name[80] = {0}, cid_num[80] = {0};
|
|
|
|
ast_callerid_split(c, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num));
|
|
|
|
ast_string_field_set(o, cid_num, cid_num);
|
|
|
|
ast_string_field_set(o, cid_name, cid_name);
|
|
|
|
} else if (!strcasecmp(buf, "application")) {
|
|
|
|
ast_string_field_set(o, app, c);
|
|
|
|
} else if (!strcasecmp(buf, "data")) {
|
|
|
|
ast_string_field_set(o, data, c);
|
|
|
|
} else if (!strcasecmp(buf, "maxretries")) {
|
|
|
|
if (sscanf(c, "%30d", &o->maxretries) != 1) {
|
|
|
|
ast_log(LOG_WARNING, "Invalid max retries at line %d of %s\n", lineno, o->fn);
|
|
|
|
o->maxretries = 0;
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(buf, "codecs")) {
|
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_update_by_allow_disallow(o->capabilities, c, 1);
|
2012-10-08 21:24:11 +00:00
|
|
|
} else if (!strcasecmp(buf, "context")) {
|
|
|
|
ast_string_field_set(o, context, c);
|
|
|
|
} else if (!strcasecmp(buf, "extension")) {
|
|
|
|
ast_string_field_set(o, exten, c);
|
|
|
|
} else if (!strcasecmp(buf, "priority")) {
|
|
|
|
if ((sscanf(c, "%30d", &o->priority) != 1) || (o->priority < 1)) {
|
|
|
|
ast_log(LOG_WARNING, "Invalid priority at line %d of %s\n", lineno, o->fn);
|
|
|
|
o->priority = 1;
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(buf, "retrytime")) {
|
|
|
|
if ((sscanf(c, "%30d", &o->retrytime) != 1) || (o->retrytime < 1)) {
|
|
|
|
ast_log(LOG_WARNING, "Invalid retrytime at line %d of %s\n", lineno, o->fn);
|
|
|
|
o->retrytime = 300;
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(buf, "waittime")) {
|
|
|
|
if ((sscanf(c, "%30d", &o->waittime) != 1) || (o->waittime < 1)) {
|
|
|
|
ast_log(LOG_WARNING, "Invalid waittime at line %d of %s\n", lineno, o->fn);
|
|
|
|
o->waittime = 45;
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(buf, "retry")) {
|
|
|
|
o->retries++;
|
|
|
|
} else if (!strcasecmp(buf, "startretry")) {
|
|
|
|
if (sscanf(c, "%30ld", &o->callingpid) != 1) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to retrieve calling PID!\n");
|
|
|
|
o->callingpid = 0;
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(buf, "endretry") || !strcasecmp(buf, "abortretry")) {
|
|
|
|
o->callingpid = 0;
|
|
|
|
o->retries++;
|
|
|
|
} else if (!strcasecmp(buf, "delayedretry")) {
|
|
|
|
} else if (!strcasecmp(buf, "setvar") || !strcasecmp(buf, "set")) {
|
|
|
|
c2 = c;
|
|
|
|
strsep(&c2, "=");
|
|
|
|
if (c2) {
|
|
|
|
var = ast_variable_new(c, c2, o->fn);
|
|
|
|
if (var) {
|
|
|
|
/* Always insert at the end, because some people want to treat the spool file as a script */
|
|
|
|
if (last) {
|
|
|
|
last->next = var;
|
2003-02-04 15:48:42 +00:00
|
|
|
} else {
|
2012-10-08 21:24:11 +00:00
|
|
|
o->vars = var;
|
2005-07-15 00:15:14 +00:00
|
|
|
}
|
2012-10-08 21:24:11 +00:00
|
|
|
last = var;
|
2005-07-15 00:15:14 +00:00
|
|
|
}
|
|
|
|
} else
|
2012-10-08 21:24:11 +00:00
|
|
|
ast_log(LOG_WARNING, "Malformed \"%s\" argument. Should be \"%s: variable=value\"\n", buf, buf);
|
|
|
|
} else if (!strcasecmp(buf, "account")) {
|
|
|
|
ast_string_field_set(o, account, c);
|
|
|
|
} else if (!strcasecmp(buf, "alwaysdelete")) {
|
|
|
|
ast_set2_flag(&o->options, ast_true(c), SPOOL_FLAG_ALWAYS_DELETE);
|
|
|
|
} else if (!strcasecmp(buf, "archive")) {
|
|
|
|
ast_set2_flag(&o->options, ast_true(c), SPOOL_FLAG_ARCHIVE);
|
|
|
|
} else if (!strcasecmp(buf, "early_media")) {
|
|
|
|
ast_set2_flag(&o->options, ast_true(c), SPOOL_FLAG_EARLY_MEDIA);
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Unknown keyword '%s' at line %d of %s\n", buf, lineno, o->fn);
|
2005-07-15 00:15:14 +00:00
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2004-05-08 08:07:47 +00:00
|
|
|
if (ast_strlen_zero(o->tech) || ast_strlen_zero(o->dest) || (ast_strlen_zero(o->app) && ast_strlen_zero(o->exten))) {
|
2012-10-08 21:24:11 +00:00
|
|
|
ast_log(LOG_WARNING, "At least one of app or extension must be specified, along with tech and dest in file %s\n", o->fn);
|
2003-02-04 15:48:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-03-20 21:13:12 +00:00
|
|
|
static void safe_append(struct outgoing *o, time_t now, char *s)
|
|
|
|
{
|
|
|
|
FILE *f;
|
2010-11-10 23:14:45 +00:00
|
|
|
struct utimbuf tbuf = { .actime = now, .modtime = now + o->retrytime };
|
2007-07-11 20:40:33 +00:00
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
ast_debug(1, "Outgoing %s/%s: %s\n", o->tech, o->dest, s);
|
2007-07-11 20:40:33 +00:00
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
if ((f = fopen(o->fn, "a"))) {
|
2007-07-11 20:40:33 +00:00
|
|
|
fprintf(f, "\n%s: %ld %d (%ld)\n", s, (long)ast_mainpid, o->retries, (long) now);
|
|
|
|
fclose(f);
|
2010-11-10 23:14:45 +00:00
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
|
|
|
|
/* Update the file time */
|
2010-11-10 23:14:45 +00:00
|
|
|
if (utime(o->fn, &tbuf)) {
|
2007-07-11 20:40:33 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", o->fn, strerror(errno));
|
2010-11-10 23:14:45 +00:00
|
|
|
}
|
2004-03-20 21:13:12 +00:00
|
|
|
}
|
|
|
|
|
2006-05-25 17:58:55 +00:00
|
|
|
/*!
|
|
|
|
* \brief Remove a call file from the outgoing queue optionally moving it in the archive dir
|
|
|
|
*
|
|
|
|
* \param o the pointer to outgoing struct
|
|
|
|
* \param status the exit status of the call. Can be "Completed", "Failed" or "Expired"
|
|
|
|
*/
|
|
|
|
static int remove_from_queue(struct outgoing *o, const char *status)
|
2006-05-19 22:51:44 +00:00
|
|
|
{
|
2006-05-25 17:58:55 +00:00
|
|
|
FILE *f;
|
|
|
|
char newfn[256];
|
|
|
|
const char *bname;
|
|
|
|
|
2015-05-11 12:07:31 +00:00
|
|
|
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
|
|
|
struct direntry *cur;
|
|
|
|
#endif
|
|
|
|
|
2006-05-25 17:58:55 +00:00
|
|
|
if (!ast_test_flag(&o->options, SPOOL_FLAG_ALWAYS_DELETE)) {
|
2006-05-19 22:51:44 +00:00
|
|
|
struct stat current_file_status;
|
2006-05-25 17:58:55 +00:00
|
|
|
|
2007-07-11 20:40:33 +00:00
|
|
|
if (!stat(o->fn, ¤t_file_status)) {
|
2010-11-10 23:14:45 +00:00
|
|
|
if (time(NULL) < current_file_status.st_mtime) {
|
2006-05-25 17:58:55 +00:00
|
|
|
return 0;
|
2010-11-10 23:14:45 +00:00
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
}
|
2006-05-25 17:58:55 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 12:07:31 +00:00
|
|
|
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
|
|
|
AST_LIST_LOCK(&dirlist);
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&dirlist, cur, list) {
|
|
|
|
if (!strcmp(cur->name, o->fn)) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
|
|
|
ast_free(cur);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
AST_LIST_UNLOCK(&dirlist);
|
|
|
|
#endif
|
|
|
|
|
2006-05-25 17:58:55 +00:00
|
|
|
if (!ast_test_flag(&o->options, SPOOL_FLAG_ARCHIVE)) {
|
|
|
|
unlink(o->fn);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
|
2007-06-22 04:35:12 +00:00
|
|
|
if (ast_mkdir(qdonedir, 0777)) {
|
2006-05-25 17:58:55 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool archiving disabled\n", qdonedir);
|
|
|
|
unlink(o->fn);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
if (!(bname = strrchr(o->fn, '/'))) {
|
|
|
|
bname = o->fn;
|
|
|
|
} else {
|
|
|
|
bname++;
|
2006-05-19 22:51:44 +00:00
|
|
|
}
|
2006-05-25 17:58:55 +00:00
|
|
|
|
|
|
|
snprintf(newfn, sizeof(newfn), "%s/%s", qdonedir, bname);
|
2012-10-08 21:24:11 +00:00
|
|
|
/* If there is already a call file with the name in the archive dir, it will be overwritten. */
|
2006-05-25 17:58:55 +00:00
|
|
|
unlink(newfn);
|
|
|
|
if (rename(o->fn, newfn) != 0) {
|
|
|
|
unlink(o->fn);
|
|
|
|
return -1;
|
2010-11-10 23:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Only append to the file AFTER we move it out of the watched directory,
|
|
|
|
* otherwise the fclose() causes another event for inotify(7) */
|
|
|
|
if ((f = fopen(newfn, "a"))) {
|
|
|
|
fprintf(f, "Status: %s\n", status);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2006-05-19 22:51:44 +00:00
|
|
|
}
|
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
static void *attempt_thread(void *data)
|
|
|
|
{
|
|
|
|
struct outgoing *o = data;
|
|
|
|
int res, reason;
|
2004-05-08 08:07:47 +00:00
|
|
|
if (!ast_strlen_zero(o->app)) {
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "Attempting call on %s/%s for application %s(%s) (Retry %d)\n", o->tech, o->dest, o->app, o->data, o->retries);
|
2012-02-01 19:53:38 +00:00
|
|
|
res = ast_pbx_outgoing_app(o->tech, o->capabilities, o->dest, o->waittime * 1000,
|
|
|
|
o->app, o->data, &reason, 2 /* wait to finish */, o->cid_num, o->cid_name,
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
o->vars, o->account, NULL, NULL);
|
2003-02-04 15:48:42 +00:00
|
|
|
} else {
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "Attempting call on %s/%s for %s@%s:%d (Retry %d)\n", o->tech, o->dest, o->exten, o->context,o->priority, o->retries);
|
2012-02-01 19:53:38 +00:00
|
|
|
res = ast_pbx_outgoing_exten(o->tech, o->capabilities, o->dest,
|
|
|
|
o->waittime * 1000, o->context, o->exten, o->priority, &reason,
|
2012-08-08 22:39:40 +00:00
|
|
|
2 /* wait to finish */, o->cid_num, o->cid_name, o->vars, o->account, NULL,
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
ast_test_flag(&o->options, SPOOL_FLAG_EARLY_MEDIA), NULL);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
if (res) {
|
2007-08-10 21:03:06 +00:00
|
|
|
ast_log(LOG_NOTICE, "Call failed to go through, reason (%d) %s\n", reason, ast_channel_reason2str(reason));
|
2003-02-04 15:48:42 +00:00
|
|
|
if (o->retries >= o->maxretries + 1) {
|
|
|
|
/* Max retries exceeded */
|
2009-05-02 19:02:22 +00:00
|
|
|
ast_log(LOG_NOTICE, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
|
2006-05-25 17:58:55 +00:00
|
|
|
remove_from_queue(o, "Expired");
|
2004-03-20 21:13:12 +00:00
|
|
|
} else {
|
|
|
|
/* Notate that the call is still active */
|
|
|
|
safe_append(o, time(NULL), "EndRetry");
|
2010-11-10 23:14:45 +00:00
|
|
|
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
|
|
|
queue_file(o->fn, time(NULL) + o->retrytime);
|
|
|
|
#endif
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_NOTICE, "Call completed to %s/%s\n", o->tech, o->dest);
|
2006-05-25 17:58:55 +00:00
|
|
|
remove_from_queue(o, "Completed");
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2005-10-11 20:44:23 +00:00
|
|
|
free_outgoing(o);
|
2003-02-04 15:48:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void launch_service(struct outgoing *o)
|
|
|
|
{
|
|
|
|
pthread_t t;
|
2006-01-07 07:31:08 +00:00
|
|
|
int ret;
|
2007-05-24 18:30:19 +00:00
|
|
|
|
|
|
|
if ((ret = ast_pthread_create_detached(&t, NULL, attempt_thread, o))) {
|
2006-01-07 07:31:08 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
|
2005-10-11 20:44:23 +00:00
|
|
|
free_outgoing(o);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-07 21:21:00 +00:00
|
|
|
/* Called from scan_thread or queue_file */
|
2010-03-27 06:09:26 +00:00
|
|
|
static int scan_service(const char *fn, time_t now)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
2012-10-08 21:24:11 +00:00
|
|
|
struct outgoing *o;
|
2003-02-04 15:48:42 +00:00
|
|
|
FILE *f;
|
2012-10-08 21:24:11 +00:00
|
|
|
int res;
|
2010-11-10 23:14:45 +00:00
|
|
|
|
2012-10-08 21:24:11 +00:00
|
|
|
o = new_outgoing(fn);
|
|
|
|
if (!o) {
|
2009-03-03 17:03:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
|
|
|
|
/* Attempt to open the file */
|
2012-10-08 21:24:11 +00:00
|
|
|
f = fopen(o->fn, "r");
|
|
|
|
if (!f) {
|
|
|
|
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
|
|
|
/*!
|
|
|
|
* \todo XXX There is some odd delayed duplicate servicing of
|
|
|
|
* call files going on. We need to suppress the error message
|
|
|
|
* if the file does not exist as a result.
|
|
|
|
*/
|
|
|
|
if (errno != ENOENT)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to open %s: '%s'(%d), deleting\n",
|
|
|
|
o->fn, strerror(errno), (int) errno);
|
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
remove_from_queue(o, "Failed");
|
|
|
|
free_outgoing(o);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in and verify the contents */
|
2012-10-08 21:24:11 +00:00
|
|
|
res = apply_outgoing(o, f);
|
|
|
|
fclose(f);
|
|
|
|
if (res) {
|
|
|
|
ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", o->fn);
|
2007-07-11 20:40:33 +00:00
|
|
|
remove_from_queue(o, "Failed");
|
|
|
|
free_outgoing(o);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-11-10 23:14:45 +00:00
|
|
|
|
2012-10-08 21:24:11 +00:00
|
|
|
ast_debug(1, "Filename: %s, Retries: %d, max: %d\n", o->fn, o->retries, o->maxretries);
|
2007-07-11 20:40:33 +00:00
|
|
|
if (o->retries <= o->maxretries) {
|
|
|
|
now += o->retrytime;
|
|
|
|
if (o->callingpid && (o->callingpid == ast_mainpid)) {
|
|
|
|
safe_append(o, time(NULL), "DelayedRetry");
|
2011-02-04 16:55:39 +00:00
|
|
|
ast_debug(1, "Delaying retry since we're currently running '%s'\n", o->fn);
|
2005-10-11 20:44:23 +00:00
|
|
|
free_outgoing(o);
|
2007-07-11 20:40:33 +00:00
|
|
|
} else {
|
|
|
|
/* Increment retries */
|
|
|
|
o->retries++;
|
|
|
|
/* If someone else was calling, they're presumably gone now
|
|
|
|
so abort their retry and continue as we were... */
|
|
|
|
if (o->callingpid)
|
|
|
|
safe_append(o, time(NULL), "AbortRetry");
|
2010-11-10 23:14:45 +00:00
|
|
|
|
2007-07-11 20:40:33 +00:00
|
|
|
safe_append(o, now, "StartRetry");
|
|
|
|
launch_service(o);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2012-10-08 21:24:11 +00:00
|
|
|
return now;
|
2007-07-11 20:40:33 +00:00
|
|
|
}
|
|
|
|
|
2012-10-08 21:24:11 +00:00
|
|
|
ast_log(LOG_NOTICE, "Queued call to %s/%s expired without completion after %d attempt%s\n",
|
|
|
|
o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
|
|
|
|
remove_from_queue(o, "Expired");
|
|
|
|
free_outgoing(o);
|
|
|
|
return 0;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 23:27:33 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_INOTIFY)
|
2010-03-27 06:09:26 +00:00
|
|
|
/* Only one thread is accessing this list, so no lock is necessary */
|
2010-11-10 23:14:45 +00:00
|
|
|
static AST_LIST_HEAD_NOLOCK_STATIC(createlist, direntry);
|
2011-10-25 16:08:52 +00:00
|
|
|
static AST_LIST_HEAD_NOLOCK_STATIC(openlist, direntry);
|
2010-11-10 23:27:33 +00:00
|
|
|
#endif
|
2010-03-27 06:09:26 +00:00
|
|
|
|
2015-05-11 12:07:31 +00:00
|
|
|
#if defined(HAVE_INOTIFY) || defined(HAVE_KQUEUE)
|
|
|
|
|
2010-03-27 06:09:26 +00:00
|
|
|
static void queue_file(const char *filename, time_t when)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
struct direntry *cur, *new;
|
|
|
|
int res;
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
2012-11-14 19:55:39 +00:00
|
|
|
if (!strchr(filename, '/')) {
|
2012-07-31 20:21:43 +00:00
|
|
|
char *fn = ast_alloca(strlen(qdir) + strlen(filename) + 2);
|
2010-03-27 06:09:26 +00:00
|
|
|
sprintf(fn, "%s/%s", qdir, filename); /* SAFE */
|
|
|
|
filename = fn;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (when == 0) {
|
|
|
|
if (stat(filename, &st)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to stat %s: %s\n", filename, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!S_ISREG(st.st_mode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
when = st.st_mtime;
|
|
|
|
}
|
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
/* Need to check the existing list in order to avoid duplicates. */
|
|
|
|
AST_LIST_LOCK(&dirlist);
|
2010-05-13 05:37:31 +00:00
|
|
|
AST_LIST_TRAVERSE(&dirlist, cur, list) {
|
|
|
|
if (cur->mtime == when && !strcmp(filename, cur->name)) {
|
2010-11-10 23:14:45 +00:00
|
|
|
AST_LIST_UNLOCK(&dirlist);
|
2010-05-13 05:37:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-27 06:09:26 +00:00
|
|
|
if ((res = when) > now || (res = scan_service(filename, now)) > 0) {
|
|
|
|
if (!(new = ast_calloc(1, sizeof(*new) + strlen(filename) + 1))) {
|
2010-11-10 23:14:45 +00:00
|
|
|
AST_LIST_UNLOCK(&dirlist);
|
2010-03-27 06:09:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
new->mtime = res;
|
|
|
|
strcpy(new->name, filename);
|
|
|
|
/* List is ordered by mtime */
|
|
|
|
if (AST_LIST_EMPTY(&dirlist)) {
|
|
|
|
AST_LIST_INSERT_HEAD(&dirlist, new, list);
|
|
|
|
} else {
|
|
|
|
int found = 0;
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&dirlist, cur, list) {
|
|
|
|
if (cur->mtime > new->mtime) {
|
|
|
|
AST_LIST_INSERT_BEFORE_CURRENT(new, list);
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END
|
|
|
|
if (!found) {
|
|
|
|
AST_LIST_INSERT_TAIL(&dirlist, new, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-10 23:14:45 +00:00
|
|
|
AST_LIST_UNLOCK(&dirlist);
|
2010-03-27 06:09:26 +00:00
|
|
|
}
|
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
static void queue_file_create(const char *filename)
|
|
|
|
{
|
|
|
|
struct direntry *cur;
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE(&createlist, cur, list) {
|
|
|
|
if (!strcmp(cur->name, filename)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cur = ast_calloc(1, sizeof(*cur) + strlen(filename) + 1))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcpy(cur->name, filename);
|
2011-10-25 16:08:52 +00:00
|
|
|
/* We'll handle this file unless an IN_OPEN event occurs within 2 seconds */
|
|
|
|
cur->mtime = time(NULL) + 2;
|
2010-11-10 23:14:45 +00:00
|
|
|
AST_LIST_INSERT_TAIL(&createlist, cur, list);
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:08:52 +00:00
|
|
|
static void queue_file_open(const char *filename)
|
|
|
|
{
|
|
|
|
struct direntry *cur;
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&createlist, cur, list) {
|
|
|
|
if (!strcmp(cur->name, filename)) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
|
|
|
AST_LIST_INSERT_TAIL(&openlist, cur, list);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END
|
|
|
|
}
|
|
|
|
|
|
|
|
static void queue_created_files(void)
|
|
|
|
{
|
|
|
|
struct direntry *cur;
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&createlist, cur, list) {
|
|
|
|
if (cur->mtime > now) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
|
|
|
queue_file(cur->name, 0);
|
|
|
|
ast_free(cur);
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END
|
|
|
|
}
|
|
|
|
|
2010-11-10 23:14:45 +00:00
|
|
|
static void queue_file_write(const char *filename)
|
|
|
|
{
|
|
|
|
struct direntry *cur;
|
|
|
|
/* Only queue entries where an IN_CREATE preceded the IN_CLOSE_WRITE */
|
2011-10-25 16:08:52 +00:00
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&openlist, cur, list) {
|
2010-11-10 23:14:45 +00:00
|
|
|
if (!strcmp(cur->name, filename)) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
|
|
|
ast_free(cur);
|
|
|
|
queue_file(filename, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-27 06:09:26 +00:00
|
|
|
static void *scan_thread(void *unused)
|
|
|
|
{
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
|
|
|
time_t now;
|
|
|
|
struct timespec ts = { .tv_sec = 1 };
|
2010-05-13 05:37:31 +00:00
|
|
|
#ifdef HAVE_INOTIFY
|
2010-11-10 23:14:45 +00:00
|
|
|
ssize_t res;
|
2010-03-27 06:09:26 +00:00
|
|
|
int inotify_fd = inotify_init();
|
2010-11-10 23:14:45 +00:00
|
|
|
struct inotify_event *iev;
|
|
|
|
char buf[8192] __attribute__((aligned (sizeof(int))));
|
2010-03-27 06:09:26 +00:00
|
|
|
struct pollfd pfd = { .fd = inotify_fd, .events = POLLIN };
|
2010-05-13 05:37:31 +00:00
|
|
|
#else
|
2013-03-15 01:24:23 +00:00
|
|
|
struct timespec nowait = { .tv_sec = 0, .tv_nsec = 1 };
|
2010-05-13 05:37:31 +00:00
|
|
|
int inotify_fd = kqueue();
|
|
|
|
struct kevent kev;
|
2013-03-15 01:24:23 +00:00
|
|
|
struct kevent event;
|
2010-05-13 05:37:31 +00:00
|
|
|
#endif
|
|
|
|
struct direntry *cur;
|
2010-03-27 06:09:26 +00:00
|
|
|
|
|
|
|
while (!ast_fully_booted) {
|
|
|
|
nanosleep(&ts, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inotify_fd < 0) {
|
2010-05-13 05:37:31 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to initialize "
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
"inotify(7)"
|
|
|
|
#else
|
|
|
|
"kqueue(2)"
|
|
|
|
#endif
|
|
|
|
"\n");
|
2010-03-27 06:09:26 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-13 05:37:31 +00:00
|
|
|
#ifdef HAVE_INOTIFY
|
2011-10-25 16:08:52 +00:00
|
|
|
inotify_add_watch(inotify_fd, qdir, IN_CREATE | IN_OPEN | IN_CLOSE_WRITE | IN_MOVED_TO);
|
2010-05-13 05:37:31 +00:00
|
|
|
#endif
|
2010-03-27 06:09:26 +00:00
|
|
|
|
|
|
|
/* First, run through the directory and clear existing entries */
|
|
|
|
if (!(dir = opendir(qdir))) {
|
|
|
|
ast_log(LOG_ERROR, "Unable to open directory %s: %s\n", qdir, strerror(errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-13 05:37:31 +00:00
|
|
|
#ifndef HAVE_INOTIFY
|
2010-11-10 23:14:45 +00:00
|
|
|
EV_SET(&kev, dirfd(dir), EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, NOTE_WRITE, 0, NULL);
|
2013-03-15 01:24:23 +00:00
|
|
|
if (kevent(inotify_fd, &kev, 1, &event, 1, &nowait) < 0 && errno != 0) {
|
2010-05-13 05:37:31 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to watch directory %s: %s\n", qdir, strerror(errno));
|
|
|
|
}
|
|
|
|
#endif
|
2010-03-27 06:09:26 +00:00
|
|
|
now = time(NULL);
|
|
|
|
while ((de = readdir(dir))) {
|
|
|
|
queue_file(de->d_name, 0);
|
|
|
|
}
|
2010-05-13 05:37:31 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_INOTIFY
|
|
|
|
/* Directory needs to remain open for kqueue(2) */
|
2010-03-27 06:09:26 +00:00
|
|
|
closedir(dir);
|
2010-05-13 05:37:31 +00:00
|
|
|
#endif
|
2010-03-27 06:09:26 +00:00
|
|
|
|
|
|
|
/* Wait for either a) next timestamp to occur, or b) a change to happen */
|
|
|
|
for (;/* ever */;) {
|
|
|
|
time_t next = AST_LIST_EMPTY(&dirlist) ? INT_MAX : AST_LIST_FIRST(&dirlist)->mtime;
|
|
|
|
|
|
|
|
time(&now);
|
|
|
|
if (next > now) {
|
2010-05-13 05:37:31 +00:00
|
|
|
#ifdef HAVE_INOTIFY
|
2010-03-27 06:09:26 +00:00
|
|
|
int stage = 0;
|
|
|
|
/* Convert from seconds to milliseconds, unless there's nothing
|
|
|
|
* in the queue already, in which case, we wait forever. */
|
|
|
|
int waittime = next == INT_MAX ? -1 : (next - now) * 1000;
|
2011-10-25 16:08:52 +00:00
|
|
|
if (!AST_LIST_EMPTY(&createlist)) {
|
|
|
|
waittime = 1000;
|
|
|
|
}
|
2010-03-27 06:09:26 +00:00
|
|
|
/* When a file arrives, add it to the queue, in mtime order. */
|
|
|
|
if ((res = poll(&pfd, 1, waittime)) > 0 && (stage = 1) &&
|
2010-11-10 23:14:45 +00:00
|
|
|
(res = read(inotify_fd, &buf, sizeof(buf))) >= sizeof(*iev)) {
|
|
|
|
ssize_t len = 0;
|
2010-09-07 21:21:00 +00:00
|
|
|
/* File(s) added to directory, add them to my list */
|
2010-11-10 23:14:45 +00:00
|
|
|
for (iev = (void *) buf; res >= sizeof(*iev); iev = (struct inotify_event *) (((char *) iev) + len)) {
|
2011-10-25 16:08:52 +00:00
|
|
|
/* For an IN_MOVED_TO event, simply process the file. However, if
|
|
|
|
* we get an IN_CREATE event it *might* be an open(O_CREAT) or it
|
|
|
|
* might be a hardlink (like smsq does, since rename() might
|
|
|
|
* overwrite an existing file). So we have to see if we get a
|
|
|
|
* subsequent IN_OPEN event on the same file. If we do, keep it
|
|
|
|
* on the openlist and wait for the corresponding IN_CLOSE_WRITE.
|
|
|
|
* If we *don't* see an IN_OPEN event, then it was a hard link so
|
|
|
|
* it can be processed immediately.
|
|
|
|
*
|
|
|
|
* Unfortunately, although open(O_CREAT) is an atomic file system
|
|
|
|
* operation, the inotify subsystem doesn't give it to us in a
|
|
|
|
* single event with both IN_CREATE|IN_OPEN set. It's two separate
|
|
|
|
* events, and the kernel doesn't even give them to us at the same
|
|
|
|
* time. We can read() from inotify_fd after the IN_CREATE event,
|
|
|
|
* and get *nothing* from it. The IN_OPEN arrives only later! So
|
|
|
|
* we have a very short timeout of 2 seconds. */
|
2010-11-10 23:14:45 +00:00
|
|
|
if (iev->mask & IN_CREATE) {
|
|
|
|
queue_file_create(iev->name);
|
2011-10-25 16:08:52 +00:00
|
|
|
} else if (iev->mask & IN_OPEN) {
|
|
|
|
queue_file_open(iev->name);
|
2010-11-10 23:14:45 +00:00
|
|
|
} else if (iev->mask & IN_CLOSE_WRITE) {
|
|
|
|
queue_file_write(iev->name);
|
|
|
|
} else if (iev->mask & IN_MOVED_TO) {
|
|
|
|
queue_file(iev->name, 0);
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_ERROR, "Unexpected event %d for file '%s'\n", (int) iev->mask, iev->name);
|
2010-09-07 21:21:00 +00:00
|
|
|
}
|
2010-11-10 23:14:45 +00:00
|
|
|
|
|
|
|
len = sizeof(*iev) + iev->len;
|
|
|
|
res -= len;
|
|
|
|
}
|
2010-03-27 06:09:26 +00:00
|
|
|
} else if (res < 0 && errno != EINTR && errno != EAGAIN) {
|
|
|
|
ast_debug(1, "Got an error back from %s(2): %s\n", stage ? "read" : "poll", strerror(errno));
|
|
|
|
}
|
2011-10-25 19:09:32 +00:00
|
|
|
time(&now);
|
|
|
|
}
|
|
|
|
queue_created_files();
|
2010-05-13 05:37:31 +00:00
|
|
|
#else
|
2013-03-15 01:24:23 +00:00
|
|
|
int num_events;
|
|
|
|
/* If queue empty then wait forever */
|
|
|
|
if (next == INT_MAX) {
|
|
|
|
num_events = kevent(inotify_fd, &kev, 1, &event, 1, NULL);
|
|
|
|
} else {
|
|
|
|
struct timespec ts2 = { .tv_sec = (unsigned long int)(next - now), .tv_nsec = 0 };
|
|
|
|
num_events = kevent(inotify_fd, &kev, 1, &event, 1, &ts2);
|
|
|
|
}
|
|
|
|
if ((num_events < 0) || (event.flags == EV_ERROR)) {
|
|
|
|
ast_debug(10, "KEvent error %s\n", strerror(errno));
|
|
|
|
continue;
|
|
|
|
} else if (num_events == 0) {
|
2010-05-13 05:37:31 +00:00
|
|
|
/* Interrupt or timeout, restart calculations */
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
/* Directory changed, rescan */
|
|
|
|
rewinddir(dir);
|
|
|
|
while ((de = readdir(dir))) {
|
|
|
|
queue_file(de->d_name, 0);
|
|
|
|
}
|
|
|
|
}
|
2010-03-27 06:09:26 +00:00
|
|
|
time(&now);
|
|
|
|
}
|
2011-10-25 19:09:32 +00:00
|
|
|
#endif
|
2010-03-27 06:09:26 +00:00
|
|
|
|
|
|
|
/* Empty the list of all entries ready to be processed */
|
2010-11-10 23:14:45 +00:00
|
|
|
AST_LIST_LOCK(&dirlist);
|
2010-03-27 06:09:26 +00:00
|
|
|
while (!AST_LIST_EMPTY(&dirlist) && AST_LIST_FIRST(&dirlist)->mtime <= now) {
|
|
|
|
cur = AST_LIST_REMOVE_HEAD(&dirlist, list);
|
|
|
|
queue_file(cur->name, cur->mtime);
|
|
|
|
ast_free(cur);
|
|
|
|
}
|
2010-11-10 23:14:45 +00:00
|
|
|
AST_LIST_UNLOCK(&dirlist);
|
2010-03-27 06:09:26 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2003-02-04 15:48:42 +00:00
|
|
|
static void *scan_thread(void *unused)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
DIR *dir;
|
|
|
|
struct dirent *de;
|
2006-02-24 10:50:43 +00:00
|
|
|
char fn[256];
|
2003-02-04 15:48:42 +00:00
|
|
|
int res;
|
2012-02-13 22:04:46 +00:00
|
|
|
int force_poll = 1;
|
|
|
|
time_t last = 0;
|
|
|
|
time_t next = 0;
|
|
|
|
time_t now;
|
2008-12-03 17:01:03 +00:00
|
|
|
struct timespec ts = { .tv_sec = 1 };
|
2010-11-10 23:14:45 +00:00
|
|
|
|
2008-12-03 17:01:03 +00:00
|
|
|
while (!ast_fully_booted) {
|
|
|
|
nanosleep(&ts, NULL);
|
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
|
2012-02-13 22:04:46 +00:00
|
|
|
for (;;) {
|
2003-02-04 15:48:42 +00:00
|
|
|
/* Wait a sec */
|
2008-12-03 17:01:03 +00:00
|
|
|
nanosleep(&ts, NULL);
|
2003-02-04 15:48:42 +00:00
|
|
|
time(&now);
|
2007-07-11 20:40:33 +00:00
|
|
|
|
|
|
|
if (stat(qdir, &st)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to stat %s\n", qdir);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure it is time for us to execute our check */
|
2012-02-13 22:04:46 +00:00
|
|
|
if (!force_poll && st.st_mtime == last && (!next || now < next)) {
|
|
|
|
/*
|
|
|
|
* The directory timestamp did not change and any delayed
|
|
|
|
* call-file is not ready to be executed.
|
|
|
|
*/
|
2007-07-11 20:40:33 +00:00
|
|
|
continue;
|
2012-02-13 22:04:46 +00:00
|
|
|
}
|
2010-11-10 23:14:45 +00:00
|
|
|
|
2003-02-04 15:48:42 +00:00
|
|
|
#if 0
|
2007-07-11 20:40:33 +00:00
|
|
|
printf("atime: %ld, mtime: %ld, ctime: %ld\n", st.st_atime, st.st_mtime, st.st_ctime);
|
|
|
|
printf("Ooh, something changed / timeout\n");
|
2008-12-03 17:38:59 +00:00
|
|
|
#endif
|
2007-07-11 20:40:33 +00:00
|
|
|
|
|
|
|
if (!(dir = opendir(qdir))) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to open directory %s: %s\n", qdir, strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-02-13 22:04:46 +00:00
|
|
|
/*
|
|
|
|
* Since the dir timestamp is available at one second
|
|
|
|
* resolution, we cannot know if it was updated within the same
|
|
|
|
* second after we scanned it. Therefore, we will force another
|
|
|
|
* scan if the dir was just modified.
|
|
|
|
*/
|
|
|
|
force_poll = (st.st_mtime == now);
|
|
|
|
|
|
|
|
next = 0;
|
|
|
|
last = st.st_mtime;
|
2007-07-11 20:40:33 +00:00
|
|
|
while ((de = readdir(dir))) {
|
|
|
|
snprintf(fn, sizeof(fn), "%s/%s", qdir, de->d_name);
|
|
|
|
if (stat(fn, &st)) {
|
|
|
|
ast_log(LOG_WARNING, "Unable to stat %s: %s\n", fn, strerror(errno));
|
|
|
|
continue;
|
|
|
|
}
|
2012-02-13 22:04:46 +00:00
|
|
|
if (!S_ISREG(st.st_mode)) {
|
|
|
|
/* Not a regular file. */
|
2007-07-11 20:40:33 +00:00
|
|
|
continue;
|
2012-02-13 22:04:46 +00:00
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
if (st.st_mtime <= now) {
|
2010-03-27 06:09:26 +00:00
|
|
|
res = scan_service(fn, now);
|
2007-07-11 20:40:33 +00:00
|
|
|
if (res > 0) {
|
2012-02-13 22:04:46 +00:00
|
|
|
/* The call-file is delayed or to be retried later. */
|
|
|
|
if (!next || res < next) {
|
|
|
|
/* This delayed call file expires earlier. */
|
2007-07-11 20:40:33 +00:00
|
|
|
next = res;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2008-12-03 17:38:59 +00:00
|
|
|
} else if (res) {
|
2007-07-11 20:40:33 +00:00
|
|
|
ast_log(LOG_WARNING, "Failed to scan service '%s'\n", fn);
|
2008-12-03 17:38:59 +00:00
|
|
|
} else if (!next) {
|
|
|
|
/* Expired entry: must recheck on the next go-around */
|
|
|
|
next = st.st_mtime;
|
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
} else {
|
2012-02-13 22:04:46 +00:00
|
|
|
/* The file's timestamp is in the future. */
|
|
|
|
if (!next || st.st_mtime < next) {
|
|
|
|
/* This call-file's timestamp expires earlier. */
|
2007-07-11 20:40:33 +00:00
|
|
|
next = st.st_mtime;
|
2012-02-13 22:04:46 +00:00
|
|
|
}
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2007-07-11 20:40:33 +00:00
|
|
|
}
|
|
|
|
closedir(dir);
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-27 06:09:26 +00:00
|
|
|
#endif
|
2003-02-04 15:48:42 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2003-02-04 15:48:42 +00:00
|
|
|
{
|
|
|
|
pthread_t thread;
|
2006-01-07 07:31:08 +00:00
|
|
|
int ret;
|
2004-07-14 13:57:15 +00:00
|
|
|
snprintf(qdir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing");
|
2007-06-22 04:35:12 +00:00
|
|
|
if (ast_mkdir(qdir, 0777)) {
|
2003-02-04 15:48:42 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool disabled\n", qdir);
|
2007-12-26 20:02:27 +00:00
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2006-05-25 17:58:55 +00:00
|
|
|
snprintf(qdonedir, sizeof(qdir), "%s/%s", ast_config_AST_SPOOL_DIR, "outgoing_done");
|
2007-05-24 18:30:19 +00:00
|
|
|
|
|
|
|
if ((ret = ast_pthread_create_detached_background(&thread, NULL, scan_thread, NULL))) {
|
2006-01-07 07:31:08 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to create thread :( (returned error: %d)\n", ret);
|
2007-12-26 20:02:27 +00:00
|
|
|
return AST_MODULE_LOAD_FAILURE;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
2007-05-24 18:30:19 +00:00
|
|
|
|
2007-12-26 20:02:27 +00:00
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
2003-02-04 15:48:42 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Outgoing Spool Support");
|