2004-07-07 09:34:01 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-07-07 09:34:01 +00:00
|
|
|
*
|
2006-03-28 03:36:17 +00:00
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
2004-07-07 09:34:01 +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.
|
|
|
|
*
|
2004-07-07 09:34:01 +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-26 13:03:17 +00:00
|
|
|
/*! \file
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2005-10-26 13:03:17 +00:00
|
|
|
* \brief IAX Provisioning Protocol
|
2004-07-07 09:34:01 +00:00
|
|
|
*
|
2005-12-30 21:18:06 +00:00
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2004-07-07 09:34:01 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.
Specifically, it does the following:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-12 02:38:22 +00:00
|
|
|
ASTERISK_REGISTER_FILE()
|
2006-06-07 18:54:56 +00:00
|
|
|
|
2005-11-10 23:42:45 +00:00
|
|
|
#include <netdb.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/config.h"
|
|
|
|
#include "asterisk/cli.h"
|
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/frame.h"
|
|
|
|
#include "asterisk/md5.h"
|
|
|
|
#include "asterisk/astdb.h"
|
|
|
|
#include "asterisk/utils.h"
|
2006-03-28 03:28:52 +00:00
|
|
|
#include "asterisk/acl.h"
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
#include "asterisk/format_cache.h"
|
|
|
|
#include "asterisk/format_compatibility.h"
|
2013-01-29 22:58:33 +00:00
|
|
|
|
|
|
|
#include "include/iax2.h"
|
|
|
|
#include "include/provision.h"
|
|
|
|
#include "include/parser.h"
|
2004-07-07 09:34:01 +00:00
|
|
|
|
|
|
|
static int provinit = 0;
|
|
|
|
|
|
|
|
struct iax_template {
|
|
|
|
int dead;
|
|
|
|
char name[80];
|
|
|
|
char src[80];
|
|
|
|
char user[20];
|
|
|
|
char pass[20];
|
|
|
|
char lang[10];
|
|
|
|
unsigned short port;
|
|
|
|
unsigned int server;
|
|
|
|
unsigned short serverport;
|
|
|
|
unsigned int altserver;
|
After some study, thought, comparing, etc. I've backed out the previous universal mod to make ast_flags a 64 bit thing. Instead, I added a 64-bit version of ast_flags (ast_flags64), and 64-bit versions of the test-flag, set-flag, etc. macros, and an app_parse_options64 routine, and I use these in app_dial alone, to eliminate the 30-option limit it had grown to meet. There is room now for 32 more options and flags. I was heavily tempted to implement some of the other ideas that were presented, but this solution does not intro any new versions of dial, doesn't have a different API, has a minimal/zero impact on code outside of dial, and doesn't seriously (I hope) affect the code structure of dial. It's the best I can think of right now. My goal was NOT to rewrite dial. I leave that to a future, coordinated effort.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75983 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-19 23:24:27 +00:00
|
|
|
unsigned int flags;
|
2011-02-03 16:22:10 +00:00
|
|
|
iax2_format format;
|
2008-12-03 19:25:30 +00:00
|
|
|
unsigned int tos;
|
|
|
|
AST_LIST_ENTRY(iax_template) list;
|
|
|
|
};
|
|
|
|
|
|
|
|
static AST_LIST_HEAD_NOLOCK_STATIC(templates, iax_template);
|
|
|
|
|
|
|
|
AST_MUTEX_DEFINE_STATIC(provlock);
|
2004-07-07 09:34:01 +00:00
|
|
|
|
|
|
|
static struct iax_flag {
|
|
|
|
char *name;
|
|
|
|
int value;
|
|
|
|
} iax_flags[] = {
|
|
|
|
{ "register", PROV_FLAG_REGISTER },
|
|
|
|
{ "secure", PROV_FLAG_SECURE },
|
|
|
|
{ "heartbeat", PROV_FLAG_HEARTBEAT },
|
|
|
|
{ "debug", PROV_FLAG_DEBUG },
|
2004-11-09 21:19:35 +00:00
|
|
|
{ "disablecid", PROV_FLAG_DIS_CALLERID },
|
|
|
|
{ "disablecw", PROV_FLAG_DIS_CALLWAIT },
|
|
|
|
{ "disablecidcw", PROV_FLAG_DIS_CIDCW },
|
|
|
|
{ "disable3way", PROV_FLAG_DIS_THREEWAY },
|
2004-07-07 09:34:01 +00:00
|
|
|
};
|
|
|
|
|
After some study, thought, comparing, etc. I've backed out the previous universal mod to make ast_flags a 64 bit thing. Instead, I added a 64-bit version of ast_flags (ast_flags64), and 64-bit versions of the test-flag, set-flag, etc. macros, and an app_parse_options64 routine, and I use these in app_dial alone, to eliminate the 30-option limit it had grown to meet. There is room now for 32 more options and flags. I was heavily tempted to implement some of the other ideas that were presented, but this solution does not intro any new versions of dial, doesn't have a different API, has a minimal/zero impact on code outside of dial, and doesn't seriously (I hope) affect the code structure of dial. It's the best I can think of right now. My goal was NOT to rewrite dial. I leave that to a future, coordinated effort.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75983 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-19 23:24:27 +00:00
|
|
|
char *iax_provflags2str(char *buf, int buflen, unsigned int flags)
|
2004-07-07 09:34:01 +00:00
|
|
|
{
|
|
|
|
int x;
|
2006-07-21 17:31:28 +00:00
|
|
|
|
|
|
|
if (!buf || buflen < 1)
|
|
|
|
return NULL;
|
|
|
|
|
2004-07-16 04:40:54 +00:00
|
|
|
buf[0] = '\0';
|
2006-07-21 17:31:28 +00:00
|
|
|
|
2008-07-08 16:40:28 +00:00
|
|
|
for (x = 0; x < ARRAY_LEN(iax_flags); x++) {
|
2004-07-07 09:34:01 +00:00
|
|
|
if (flags & iax_flags[x].value){
|
2004-07-16 04:40:54 +00:00
|
|
|
strncat(buf, iax_flags[x].name, buflen - strlen(buf) - 1);
|
|
|
|
strncat(buf, ",", buflen - strlen(buf) - 1);
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-21 17:31:28 +00:00
|
|
|
|
|
|
|
if (!ast_strlen_zero(buf))
|
2004-07-07 09:34:01 +00:00
|
|
|
buf[strlen(buf) - 1] = '\0';
|
|
|
|
else
|
2004-07-16 04:40:54 +00:00
|
|
|
strncpy(buf, "none", buflen - 1);
|
2006-07-21 17:31:28 +00:00
|
|
|
|
2004-07-07 09:34:01 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int iax_str2flags(const char *buf)
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int len;
|
After some study, thought, comparing, etc. I've backed out the previous universal mod to make ast_flags a 64 bit thing. Instead, I added a 64-bit version of ast_flags (ast_flags64), and 64-bit versions of the test-flag, set-flag, etc. macros, and an app_parse_options64 routine, and I use these in app_dial alone, to eliminate the 30-option limit it had grown to meet. There is room now for 32 more options and flags. I was heavily tempted to implement some of the other ideas that were presented, but this solution does not intro any new versions of dial, doesn't have a different API, has a minimal/zero impact on code outside of dial, and doesn't seriously (I hope) affect the code structure of dial. It's the best I can think of right now. My goal was NOT to rewrite dial. I leave that to a future, coordinated effort.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75983 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-19 23:24:27 +00:00
|
|
|
unsigned int flags = 0;
|
2004-07-07 09:34:01 +00:00
|
|
|
char *e;
|
|
|
|
while(buf && *buf) {
|
|
|
|
e = strchr(buf, ',');
|
|
|
|
if (e)
|
|
|
|
len = e - buf;
|
|
|
|
else
|
|
|
|
len = 0;
|
2008-07-08 16:40:28 +00:00
|
|
|
for (x = 0; x < ARRAY_LEN(iax_flags); x++) {
|
2004-07-07 09:34:01 +00:00
|
|
|
if ((len && !strncasecmp(iax_flags[x].name, buf, len)) ||
|
|
|
|
(!len && !strcasecmp(iax_flags[x].name, buf))) {
|
|
|
|
flags |= iax_flags[x].value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e) {
|
|
|
|
buf = e + 1;
|
|
|
|
while(*buf && (*buf < 33))
|
|
|
|
buf++;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
2008-12-03 19:25:30 +00:00
|
|
|
|
|
|
|
static void iax_template_copy(struct iax_template *dst, struct iax_template *src)
|
|
|
|
{
|
|
|
|
if (!dst || !src) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst->dead = src->dead;
|
|
|
|
ast_copy_string(dst->name, src->name, sizeof(dst->name));
|
|
|
|
ast_copy_string(dst->src, src->src, sizeof(dst->src));
|
|
|
|
ast_copy_string(dst->user, src->user, sizeof(dst->user));
|
|
|
|
ast_copy_string(dst->pass, src->pass, sizeof(dst->pass));
|
|
|
|
ast_copy_string(dst->lang, src->lang, sizeof(dst->lang));
|
|
|
|
dst->port = src->port;
|
|
|
|
dst->server = src->server;
|
|
|
|
dst->altserver = src->altserver;
|
|
|
|
dst->flags = src->flags;
|
|
|
|
dst->format = src->format;
|
|
|
|
dst->tos = src->tos;
|
|
|
|
}
|
2004-07-07 09:34:01 +00:00
|
|
|
|
|
|
|
static struct iax_template *iax_template_find(const char *s, int allowdead)
|
|
|
|
{
|
|
|
|
struct iax_template *cur;
|
2008-12-03 19:25:30 +00:00
|
|
|
|
|
|
|
AST_LIST_TRAVERSE(&templates, cur, list) {
|
2004-07-07 09:34:01 +00:00
|
|
|
if (!strcasecmp(s, cur->name)) {
|
2008-12-03 19:25:30 +00:00
|
|
|
if (!allowdead && cur->dead) {
|
2004-07-07 09:34:01 +00:00
|
|
|
cur = NULL;
|
2008-12-03 19:25:30 +00:00
|
|
|
}
|
2004-07-07 09:34:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-03 19:25:30 +00:00
|
|
|
|
2004-07-07 09:34:01 +00:00
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
2006-01-18 22:17:31 +00:00
|
|
|
char *iax_prov_complete_template(const char *line, const char *word, int pos, int state)
|
2004-07-07 09:34:01 +00:00
|
|
|
{
|
|
|
|
struct iax_template *c;
|
|
|
|
int which=0;
|
2005-12-27 19:48:44 +00:00
|
|
|
char *ret = NULL;
|
|
|
|
int wordlen = strlen(word);
|
|
|
|
|
2007-10-11 19:03:06 +00:00
|
|
|
if (pos == 3) {
|
|
|
|
ast_mutex_lock(&provlock);
|
2008-12-03 19:25:30 +00:00
|
|
|
AST_LIST_TRAVERSE(&templates, c, list) {
|
2007-10-11 19:03:06 +00:00
|
|
|
if (!strncasecmp(word, c->name, wordlen) && ++which > state) {
|
|
|
|
ret = ast_strdup(c->name);
|
|
|
|
break;
|
|
|
|
}
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
2007-10-11 19:03:06 +00:00
|
|
|
ast_mutex_unlock(&provlock);
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
|
|
|
|
{
|
|
|
|
struct MD5Context md5;
|
|
|
|
unsigned int tmp[4];
|
|
|
|
MD5Init(&md5);
|
|
|
|
MD5Update(&md5, provdata->buf, provdata->pos);
|
|
|
|
MD5Final((unsigned char *)tmp, &md5);
|
|
|
|
return tmp[0] ^ tmp[1] ^ tmp[2] ^ tmp[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
|
|
|
|
{
|
|
|
|
struct iax_template *cur;
|
|
|
|
unsigned int sig;
|
|
|
|
char tmp[40];
|
|
|
|
memset(provdata, 0, sizeof(*provdata));
|
|
|
|
ast_mutex_lock(&provlock);
|
|
|
|
cur = iax_template_find(template, 1);
|
|
|
|
/* If no match, try searching for '*' */
|
|
|
|
if (!cur)
|
|
|
|
cur = iax_template_find("*", 1);
|
|
|
|
if (cur) {
|
|
|
|
/* found it -- add information elements as appropriate */
|
|
|
|
if (force || strlen(cur->user))
|
|
|
|
iax_ie_append_str(provdata, PROV_IE_USER, cur->user);
|
|
|
|
if (force || strlen(cur->pass))
|
|
|
|
iax_ie_append_str(provdata, PROV_IE_PASS, cur->pass);
|
|
|
|
if (force || strlen(cur->lang))
|
|
|
|
iax_ie_append_str(provdata, PROV_IE_LANG, cur->lang);
|
|
|
|
if (force || cur->port)
|
|
|
|
iax_ie_append_short(provdata, PROV_IE_PORTNO, cur->port);
|
|
|
|
if (force || cur->server)
|
|
|
|
iax_ie_append_int(provdata, PROV_IE_SERVERIP, cur->server);
|
|
|
|
if (force || cur->serverport)
|
|
|
|
iax_ie_append_short(provdata, PROV_IE_SERVERPORT, cur->serverport);
|
|
|
|
if (force || cur->altserver)
|
|
|
|
iax_ie_append_int(provdata, PROV_IE_ALTSERVER, cur->altserver);
|
|
|
|
if (force || cur->flags)
|
|
|
|
iax_ie_append_int(provdata, PROV_IE_FLAGS, cur->flags);
|
|
|
|
if (force || cur->format)
|
|
|
|
iax_ie_append_int(provdata, PROV_IE_FORMAT, cur->format);
|
|
|
|
if (force || cur->tos)
|
|
|
|
iax_ie_append_byte(provdata, PROV_IE_TOS, cur->tos);
|
|
|
|
|
|
|
|
/* Calculate checksum of message so far */
|
|
|
|
sig = prov_ver_calc(provdata);
|
|
|
|
if (signature)
|
|
|
|
*signature = sig;
|
|
|
|
/* Store signature */
|
|
|
|
iax_ie_append_int(provdata, PROV_IE_PROVVER, sig);
|
|
|
|
/* Cache signature for later verification so we need not recalculate all this */
|
|
|
|
snprintf(tmp, sizeof(tmp), "v0x%08x", sig);
|
|
|
|
ast_db_put("iax/provisioning/cache", template, tmp);
|
|
|
|
} else
|
|
|
|
ast_db_put("iax/provisioning/cache", template, "u");
|
|
|
|
ast_mutex_unlock(&provlock);
|
|
|
|
return cur ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int iax_provision_version(unsigned int *version, const char *template, int force)
|
|
|
|
{
|
|
|
|
char tmp[80] = "";
|
|
|
|
struct iax_ie_data ied;
|
|
|
|
int ret=0;
|
|
|
|
memset(&ied, 0, sizeof(ied));
|
|
|
|
|
|
|
|
ast_mutex_lock(&provlock);
|
2012-09-21 19:35:37 +00:00
|
|
|
if (ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp))) {
|
|
|
|
ast_log(LOG_ERROR, "ast_db_get failed to retrieve iax/provisioning/cache/%s\n", template);
|
2012-05-10 18:35:14 +00:00
|
|
|
}
|
2009-08-10 19:20:57 +00:00
|
|
|
if (sscanf(tmp, "v%30x", version) != 1) {
|
2004-07-07 09:34:01 +00:00
|
|
|
if (strcmp(tmp, "u")) {
|
|
|
|
ret = iax_provision_build(&ied, version, template, force);
|
2007-06-14 19:39:12 +00:00
|
|
|
if (ret)
|
|
|
|
ast_debug(1, "Unable to create provisioning packet for '%s'\n", template);
|
2004-07-07 09:34:01 +00:00
|
|
|
} else
|
|
|
|
ret = -1;
|
2007-06-14 19:39:12 +00:00
|
|
|
} else
|
|
|
|
ast_debug(1, "Retrieved cached version '%s' = '%08x'\n", tmp, *version);
|
2004-07-07 09:34:01 +00:00
|
|
|
ast_mutex_unlock(&provlock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-09-20 20:40:39 +00:00
|
|
|
static int iax_template_parse(struct iax_template *cur, struct ast_config *cfg, const char *s, const char *def)
|
2004-07-07 09:34:01 +00:00
|
|
|
{
|
|
|
|
struct ast_variable *v;
|
|
|
|
int foundportno = 0;
|
|
|
|
int foundserverportno = 0;
|
|
|
|
int x;
|
|
|
|
struct in_addr ia;
|
|
|
|
struct hostent *hp;
|
|
|
|
struct ast_hostent h;
|
|
|
|
struct iax_template *src, tmp;
|
2006-09-20 20:40:39 +00:00
|
|
|
const char *t;
|
2004-07-07 09:34:01 +00:00
|
|
|
if (def) {
|
|
|
|
t = ast_variable_retrieve(cfg, s ,"template");
|
|
|
|
src = NULL;
|
|
|
|
if (t && strlen(t)) {
|
|
|
|
src = iax_template_find(t, 0);
|
|
|
|
if (!src)
|
|
|
|
ast_log(LOG_WARNING, "Unable to find base template '%s' for creating '%s'. Trying '%s'\n", t, s, def);
|
|
|
|
else
|
|
|
|
def = t;
|
|
|
|
}
|
|
|
|
if (!src) {
|
|
|
|
src = iax_template_find(def, 0);
|
|
|
|
if (!src)
|
2006-09-28 18:09:01 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to locate default base template '%s' for creating '%s', omitting.\n", def, s);
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
if (!src)
|
|
|
|
return -1;
|
2008-12-03 19:25:30 +00:00
|
|
|
ast_mutex_lock(&provlock);
|
2004-07-07 09:34:01 +00:00
|
|
|
/* Backup old data */
|
2008-12-03 19:25:30 +00:00
|
|
|
iax_template_copy(&tmp, cur);
|
2004-07-07 09:34:01 +00:00
|
|
|
/* Restore from src */
|
2008-12-03 19:25:30 +00:00
|
|
|
iax_template_copy(cur, src);
|
2004-07-07 09:34:01 +00:00
|
|
|
/* Restore important headers */
|
|
|
|
memcpy(cur->name, tmp.name, sizeof(cur->name));
|
|
|
|
cur->dead = tmp.dead;
|
2008-12-03 19:25:30 +00:00
|
|
|
ast_mutex_unlock(&provlock);
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
if (def)
|
2012-04-19 19:05:17 +00:00
|
|
|
ast_copy_string(cur->src, def, sizeof(cur->src));
|
2004-07-07 09:34:01 +00:00
|
|
|
else
|
2004-07-16 04:40:54 +00:00
|
|
|
cur->src[0] = '\0';
|
2004-07-07 09:34:01 +00:00
|
|
|
v = ast_variable_browse(cfg, s);
|
|
|
|
while(v) {
|
|
|
|
if (!strcasecmp(v->name, "port") || !strcasecmp(v->name, "serverport")) {
|
2009-08-10 19:20:57 +00:00
|
|
|
if ((sscanf(v->value, "%5d", &x) == 1) && (x > 0) && (x < 65535)) {
|
2004-07-07 09:34:01 +00:00
|
|
|
if (!strcasecmp(v->name, "port")) {
|
|
|
|
cur->port = x;
|
|
|
|
foundportno = 1;
|
|
|
|
} else {
|
|
|
|
cur->serverport = x;
|
2004-08-17 23:57:36 +00:00
|
|
|
foundserverportno = 1;
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);
|
|
|
|
} else if (!strcasecmp(v->name, "server") || !strcasecmp(v->name, "altserver")) {
|
|
|
|
hp = ast_gethostbyname(v->value, &h);
|
|
|
|
if (hp) {
|
|
|
|
memcpy(&ia, hp->h_addr, sizeof(ia));
|
|
|
|
if (!strcasecmp(v->name, "server"))
|
|
|
|
cur->server = ntohl(ia.s_addr);
|
|
|
|
else
|
|
|
|
cur->altserver = ntohl(ia.s_addr);
|
|
|
|
} else
|
|
|
|
ast_log(LOG_WARNING, "Ignoring invalid %s '%s' for '%s' at line %d\n", v->name, v->value, s, v->lineno);
|
|
|
|
} else if (!strcasecmp(v->name, "codec")) {
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
struct ast_format *tmpfmt;
|
|
|
|
if ((tmpfmt = ast_format_cache_get(v->value))) {
|
|
|
|
cur->format = ast_format_compatibility_format2bitfield(tmpfmt);
|
|
|
|
ao2_ref(tmpfmt, -1);
|
2004-07-07 09:34:01 +00:00
|
|
|
} else
|
|
|
|
ast_log(LOG_WARNING, "Ignoring invalid codec '%s' for '%s' at line %d\n", v->value, s, v->lineno);
|
|
|
|
} else if (!strcasecmp(v->name, "tos")) {
|
2006-03-28 03:28:52 +00:00
|
|
|
if (ast_str2tos(v->value, &cur->tos))
|
2007-12-16 10:51:53 +00:00
|
|
|
ast_log(LOG_WARNING, "Invalid tos value at line %d, refer to QoS documentation\n", v->lineno);
|
2004-07-07 09:34:01 +00:00
|
|
|
} else if (!strcasecmp(v->name, "user")) {
|
2012-04-19 19:05:17 +00:00
|
|
|
ast_copy_string(cur->user, v->value, sizeof(cur->user));
|
2004-07-07 09:34:01 +00:00
|
|
|
if (strcmp(cur->user, v->value))
|
|
|
|
ast_log(LOG_WARNING, "Truncating username from '%s' to '%s' for '%s' at line %d\n", v->value, cur->user, s, v->lineno);
|
|
|
|
} else if (!strcasecmp(v->name, "pass")) {
|
2012-04-19 19:05:17 +00:00
|
|
|
ast_copy_string(cur->pass, v->value, sizeof(cur->pass));
|
2004-07-07 09:34:01 +00:00
|
|
|
if (strcmp(cur->pass, v->value))
|
|
|
|
ast_log(LOG_WARNING, "Truncating password from '%s' to '%s' for '%s' at line %d\n", v->value, cur->pass, s, v->lineno);
|
|
|
|
} else if (!strcasecmp(v->name, "language")) {
|
2012-04-19 19:05:17 +00:00
|
|
|
ast_copy_string(cur->lang, v->value, sizeof(cur->lang));
|
2004-07-07 09:34:01 +00:00
|
|
|
if (strcmp(cur->lang, v->value))
|
|
|
|
ast_log(LOG_WARNING, "Truncating language from '%s' to '%s' for '%s' at line %d\n", v->value, cur->lang, s, v->lineno);
|
|
|
|
} else if (!strcasecmp(v->name, "flags")) {
|
|
|
|
cur->flags = iax_str2flags(v->value);
|
|
|
|
} else if (!strncasecmp(v->name, "flags", 5) && strchr(v->name, '+')) {
|
|
|
|
cur->flags |= iax_str2flags(v->value);
|
|
|
|
} else if (!strncasecmp(v->name, "flags", 5) && strchr(v->name, '-')) {
|
|
|
|
cur->flags &= ~iax_str2flags(v->value);
|
|
|
|
} else if (strcasecmp(v->name, "template")) {
|
|
|
|
ast_log(LOG_WARNING, "Unknown keyword '%s' in definition of '%s' at line %d\n", v->name, s, v->lineno);
|
|
|
|
}
|
|
|
|
v = v->next;
|
|
|
|
}
|
|
|
|
if (!foundportno)
|
|
|
|
cur->port = IAX_DEFAULT_PORTNO;
|
|
|
|
if (!foundserverportno)
|
|
|
|
cur->serverport = IAX_DEFAULT_PORTNO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iax_process_template(struct ast_config *cfg, char *s, char *def)
|
|
|
|
{
|
|
|
|
/* Find an already existing one if there */
|
|
|
|
struct iax_template *cur;
|
|
|
|
int mallocd = 0;
|
2008-12-03 19:25:30 +00:00
|
|
|
|
|
|
|
cur = iax_template_find(s, 1 /* allow dead */);
|
2004-07-07 09:34:01 +00:00
|
|
|
if (!cur) {
|
|
|
|
mallocd = 1;
|
2007-06-06 21:20:11 +00:00
|
|
|
cur = ast_calloc(1, sizeof(*cur));
|
2004-07-07 09:34:01 +00:00
|
|
|
if (!cur) {
|
|
|
|
ast_log(LOG_WARNING, "Out of memory!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* Initialize entry */
|
2012-04-19 19:05:17 +00:00
|
|
|
ast_copy_string(cur->name, s, sizeof(cur->name));
|
2004-07-07 09:34:01 +00:00
|
|
|
cur->dead = 1;
|
|
|
|
}
|
|
|
|
if (!iax_template_parse(cur, cfg, s, def))
|
|
|
|
cur->dead = 0;
|
|
|
|
|
|
|
|
/* Link if we're mallocd */
|
|
|
|
if (mallocd) {
|
|
|
|
ast_mutex_lock(&provlock);
|
2008-12-03 19:25:30 +00:00
|
|
|
AST_LIST_INSERT_HEAD(&templates, cur, list);
|
2004-07-07 09:34:01 +00:00
|
|
|
ast_mutex_unlock(&provlock);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *ifthere(const char *s)
|
|
|
|
{
|
|
|
|
if (strlen(s))
|
|
|
|
return s;
|
|
|
|
else
|
|
|
|
return "<unspecified>";
|
|
|
|
}
|
|
|
|
|
2006-07-21 17:31:28 +00:00
|
|
|
static const char *iax_server(unsigned int addr)
|
2004-07-07 09:34:01 +00:00
|
|
|
{
|
|
|
|
struct in_addr ia;
|
2006-07-21 17:31:28 +00:00
|
|
|
|
2004-07-07 09:34:01 +00:00
|
|
|
if (!addr)
|
|
|
|
return "<unspecified>";
|
2006-07-21 17:31:28 +00:00
|
|
|
|
2004-07-07 09:34:01 +00:00
|
|
|
ia.s_addr = htonl(addr);
|
2006-07-21 17:31:28 +00:00
|
|
|
|
|
|
|
return ast_inet_ntoa(ia);
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 19:03:06 +00:00
|
|
|
static char *iax_show_provisioning(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2004-07-07 09:34:01 +00:00
|
|
|
{
|
|
|
|
struct iax_template *cur;
|
2006-07-21 17:31:28 +00:00
|
|
|
char server[INET_ADDRSTRLEN];
|
|
|
|
char alternate[INET_ADDRSTRLEN];
|
|
|
|
char flags[80]; /* Has to be big enough for 'flags' too */
|
2004-07-07 09:34:01 +00:00
|
|
|
int found = 0;
|
2007-10-11 19:03:06 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "iax2 show provisioning";
|
|
|
|
e->usage =
|
|
|
|
"Usage: iax2 show provisioning [template]\n"
|
|
|
|
" Lists all known IAX provisioning templates or a\n"
|
|
|
|
" specific one if specified.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return iax_prov_complete_template(a->line, a->word, a->pos, a->n);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((a->argc != 3) && (a->argc != 4))
|
|
|
|
return CLI_SHOWUSAGE;
|
2008-12-03 19:25:30 +00:00
|
|
|
|
2004-07-07 09:34:01 +00:00
|
|
|
ast_mutex_lock(&provlock);
|
2008-12-03 19:25:30 +00:00
|
|
|
AST_LIST_TRAVERSE(&templates, cur, list) {
|
2007-10-11 19:03:06 +00:00
|
|
|
if ((a->argc == 3) || (!strcasecmp(a->argv[3], cur->name))) {
|
2006-07-21 17:31:28 +00:00
|
|
|
if (found)
|
2007-10-11 19:03:06 +00:00
|
|
|
ast_cli(a->fd, "\n");
|
2006-07-21 17:31:28 +00:00
|
|
|
ast_copy_string(server, iax_server(cur->server), sizeof(server));
|
|
|
|
ast_copy_string(alternate, iax_server(cur->altserver), sizeof(alternate));
|
2007-10-11 19:03:06 +00:00
|
|
|
ast_cli(a->fd, "== %s ==\n", cur->name);
|
|
|
|
ast_cli(a->fd, "Base Templ: %s\n", strlen(cur->src) ? cur->src : "<none>");
|
|
|
|
ast_cli(a->fd, "Username: %s\n", ifthere(cur->user));
|
|
|
|
ast_cli(a->fd, "Secret: %s\n", ifthere(cur->pass));
|
|
|
|
ast_cli(a->fd, "Language: %s\n", ifthere(cur->lang));
|
|
|
|
ast_cli(a->fd, "Bind Port: %d\n", cur->port);
|
|
|
|
ast_cli(a->fd, "Server: %s\n", server);
|
|
|
|
ast_cli(a->fd, "Server Port: %d\n", cur->serverport);
|
|
|
|
ast_cli(a->fd, "Alternate: %s\n", alternate);
|
|
|
|
ast_cli(a->fd, "Flags: %s\n", iax_provflags2str(flags, sizeof(flags), cur->flags));
|
2011-02-03 16:22:10 +00:00
|
|
|
ast_cli(a->fd, "Format: %s\n", iax2_getformatname(cur->format));
|
2007-10-11 19:03:06 +00:00
|
|
|
ast_cli(a->fd, "TOS: 0x%x\n", cur->tos);
|
2004-07-07 09:34:01 +00:00
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&provlock);
|
|
|
|
if (!found) {
|
2007-10-11 19:03:06 +00:00
|
|
|
if (a->argc == 3)
|
|
|
|
ast_cli(a->fd, "No provisioning templates found\n");
|
2004-07-07 09:34:01 +00:00
|
|
|
else
|
2007-10-11 19:03:06 +00:00
|
|
|
ast_cli(a->fd, "No provisioning template matching '%s' found\n", a->argv[3]);
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
2007-10-11 19:03:06 +00:00
|
|
|
return CLI_SUCCESS;
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
static struct ast_cli_entry cli_iax2_provision[] = {
|
2007-10-22 20:05:18 +00:00
|
|
|
AST_CLI_DEFINE(iax_show_provisioning, "Display iax provisioning"),
|
2006-09-18 19:54:18 +00:00
|
|
|
};
|
2004-07-07 09:34:01 +00:00
|
|
|
|
|
|
|
static int iax_provision_init(void)
|
|
|
|
{
|
2006-09-18 19:54:18 +00:00
|
|
|
ast_cli_register_multiple(cli_iax2_provision, sizeof(cli_iax2_provision) / sizeof(struct ast_cli_entry));
|
2004-07-07 09:34:01 +00:00
|
|
|
provinit = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-03 19:25:30 +00:00
|
|
|
static void iax_provision_free_templates(int dead)
|
|
|
|
{
|
|
|
|
struct iax_template *cur;
|
|
|
|
|
|
|
|
/* Drop dead or not (depending on dead) entries while locked */
|
|
|
|
ast_mutex_lock(&provlock);
|
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&templates, cur, list) {
|
|
|
|
if ((dead && cur->dead) || !dead) {
|
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
|
|
|
ast_free(cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
|
|
|
ast_mutex_unlock(&provlock);
|
|
|
|
}
|
|
|
|
|
2004-07-09 07:37:44 +00:00
|
|
|
int iax_provision_unload(void)
|
|
|
|
{
|
|
|
|
provinit = 0;
|
2006-09-18 19:54:18 +00:00
|
|
|
ast_cli_unregister_multiple(cli_iax2_provision, sizeof(cli_iax2_provision) / sizeof(struct ast_cli_entry));
|
2008-12-03 19:25:30 +00:00
|
|
|
iax_provision_free_templates(0 /* Remove all templates. */);
|
|
|
|
|
2004-07-09 07:37:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-16 21:09:46 +00:00
|
|
|
int iax_provision_reload(int reload)
|
2004-07-07 09:34:01 +00:00
|
|
|
{
|
|
|
|
struct ast_config *cfg;
|
2008-12-03 19:25:30 +00:00
|
|
|
struct iax_template *cur;
|
2004-07-07 09:34:01 +00:00
|
|
|
char *cat;
|
|
|
|
int found = 0;
|
2007-08-16 21:09:46 +00:00
|
|
|
struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
|
2004-07-07 09:34:01 +00:00
|
|
|
if (!provinit)
|
|
|
|
iax_provision_init();
|
2008-04-29 22:54:14 +00:00
|
|
|
|
2008-03-26 18:39:06 +00:00
|
|
|
cfg = ast_config_load2("iaxprov.conf", "chan_iax2", config_flags);
|
2008-11-19 19:25:14 +00:00
|
|
|
if (cfg != NULL && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) {
|
2008-04-29 22:54:14 +00:00
|
|
|
/* Mark all as dead. No need for locking */
|
2008-12-03 19:25:30 +00:00
|
|
|
AST_LIST_TRAVERSE(&templates, cur, list) {
|
2008-04-29 22:54:14 +00:00
|
|
|
cur->dead = 1;
|
|
|
|
}
|
|
|
|
|
2004-07-07 09:34:01 +00:00
|
|
|
/* Load as appropriate */
|
|
|
|
cat = ast_category_browse(cfg, NULL);
|
|
|
|
while(cat) {
|
|
|
|
if (strcasecmp(cat, "general")) {
|
|
|
|
iax_process_template(cfg, cat, found ? "default" : NULL);
|
|
|
|
found++;
|
2007-07-26 15:49:18 +00:00
|
|
|
ast_verb(3, "Loaded provisioning template '%s'\n", cat);
|
2004-07-07 09:34:01 +00:00
|
|
|
}
|
|
|
|
cat = ast_category_browse(cfg, cat);
|
|
|
|
}
|
2005-11-10 23:31:10 +00:00
|
|
|
ast_config_destroy(cfg);
|
2007-08-16 21:09:46 +00:00
|
|
|
} else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
|
|
|
|
return 0;
|
|
|
|
else
|
2004-07-07 09:34:01 +00:00
|
|
|
ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");
|
2008-12-03 19:25:30 +00:00
|
|
|
|
|
|
|
iax_provision_free_templates(1 /* remove only marked as dead */);
|
|
|
|
|
2004-07-07 09:34:01 +00:00
|
|
|
/* Purge cached signature DB entries */
|
|
|
|
ast_db_deltree("iax/provisioning/cache", NULL);
|
|
|
|
return 0;
|
|
|
|
}
|