Commit Graph

5600 Commits

Author SHA1 Message Date
Corey Farrell 824a4e84d1 Refactor usage pattern of xmldoc info tag.
This updates func_channel.c and main/message.c to use a generic xpointer
include instead of including info from each channel driver.  Now the
name attribute of info is CHANNEL or CHANNEL_EXAMPLES to be included in
documentation for func_channel.  Setting the name attribute of info to
MessageToInfo or MessageFromInfo causes it to be included in the
MessageSend application and AMI action.

Change-Id: I89fd8276a3250824241a618009714267d3a8d1ea
2016-08-16 10:42:46 -05:00
zuul 9fc83f8ffd Merge "core: Entity ID is not set or invalid" 2016-08-16 10:03:20 -05:00
Joshua Colp 8c8fe59f54 Merge "sorcery.c: Minor optimizations." 2016-08-16 08:24:31 -05:00
Joshua Colp 515a598b62 Merge "sorcery.c: Tweak some container declaration formatting." 2016-08-16 08:24:19 -05:00
Joshua Colp 4c9868624e Merge "manager: Add <see-also> tags to relate AoC events and actions" 2016-08-16 05:34:33 -05:00
Joshua Colp 2947127313 Merge "pbx.c: Additional fixes to ast_context_remove_extension_callerid2." 2016-08-16 05:32:30 -05:00
zuul 1fc7faa56e Merge "manager: Add <see-also> links between related events" 2016-08-16 00:26:26 -05:00
zuul 3117d150fa Merge "manager: Add <see-also> tags to relate UserEvent actions/apps/events" 2016-08-15 22:47:32 -05:00
Joshua Colp cb032092d6 Merge "manager: Add <see-also> tags to relate Bridge related events,actions, and apps" 2016-08-15 19:17:46 -05:00
Alexei Gradinari e85adbd947 core: Entity ID is not set or invalid
The Exchanging Device and Mailbox States could not working
if the Entity ID (EID) is not set manually and can't be obtained
from ethernet interface.

This patch replaces debug message to warning
and addes missing description about option 'entityid' to
asterisk.conf.sample.

With this patch the asterisk also:
(1) decline loading the modules which won't work without EID:
    res_corosync and res_pjsip_publish_asterisk.
(2) warn if EID is empty on loading next modules:
    pbx_dundi, res_xmpp

Starting with v197 systemd/udev will automatically assign "predictable"
names for all local Ethernet interfaces.
This patch also addes some new ethernet prefixes "eno" and "ens".

ASTERISK-26164 #close

Change-Id: I72d712f1ad5b6f64571bb179c5cb12461e7c58c6
2016-08-15 13:35:59 -05:00
Richard Mudgett d526aa5cbe sorcery.c: Minor optimizations.
* Remove some unused parameters from internal functions:
sorcery_wizard_create()
sorcery_wizard_update()
sorcery_wizard_delete()

* Created the struct sorcery_observer_invocation ao2 object without a lock
since it is not needed in sorcery_observer_invocation_alloc().

* Cleanup generic ao2 container sorcery object id hash, sort, and cmp
functions.

Change-Id: Iff71d75f52bc1b8cee955456838c149faaa4f92e
2016-08-15 13:15:02 -05:00
Richard Mudgett 45e143576f sorcery.c: Tweak some container declaration formatting.
* Tweak sorcery_object_type_alloc() formatting.
* Tweak ast_sorcery_init() formatting.

Change-Id: Ib02430023f15268cd7a2ea53f2c331213e4d3944
2016-08-15 13:15:02 -05:00
Corey Farrell eca3d2698a pbx.c: Additional fixes to ast_context_remove_extension_callerid2.
Do not check registrar of the first extension head.  We should only check
the registrar when we match the priority.

Additionally fix a couple calls to strcmp which used the input callerid
instead of the clean version ex.cidmatch.

ASTERISK-26233

Change-Id: I17ea6881a18f40840ae9c1f5394aab1fbb3769f1
2016-08-15 11:13:06 -05:00
Matt Jordan e9fe08ea37 manager: Add <see-also> tags to relate interrelated events/actions together
Change-Id: Idbac539205aa732bf786c4f765577d8e9ff28ba4
2016-08-15 07:41:36 -05:00
Matt Jordan a93cd39ac1 manager: Add <see-also> tags to relate Bridge related events,actions, and apps
Change-Id: I67e6b79fa3102e494b5fe6cc7510472249080e85
2016-08-15 07:41:06 -05:00
Matt Jordan d8a7594ffd manager: Add <see-also> tags to relate AoC events and actions
Change-Id: Iea89a36222712148c1775c05ed0ad1049d67a70e
2016-08-15 07:40:50 -05:00
Matt Jordan 243f0cf99a manager: Add <see-also> tags to relate UserEvent actions/apps/events
Change-Id: I80f8a981f62f50e74609c69c49edcaca6c95efa4
2016-08-15 07:40:35 -05:00
Matt Jordan a19f4affe8 manager: Add <see-also> links between related events
This patch adds some see-also references between related AMI events. It
focuses primarily on those events that are guaranteed to come in pairs,
such as DTMFBegin/DTMFEnd, as well as those that occur during the life
cycle of an Asterisk channel, such as Newchannel/Hangup.

Change-Id: Iaab600477052018d0f8c03d0c624c0856e9ff1f3
2016-08-15 07:39:56 -05:00
zuul 531d84a826 Merge "Run mandatory cleanup when startup fails." 2016-08-12 13:34:10 -05:00
Joshua Colp 9e06073e83 Merge "taskprocessor.c: Tweak high water checks." 2016-08-12 04:47:51 -05:00
zuul fb88244957 Merge "res_pjsip: Make aor named lock a mutex." 2016-08-11 23:27:15 -05:00
Corey Farrell 9debe1ca26 Run mandatory cleanup when startup fails.
Errors during startup result in an exit.  These error branches should be
calling ast_run_atexit(0) to ensure mandatory cleanup is run.

ASTERISK-26267 #close

Change-Id: If226f2326ae2df7add20040696132214cf2bb680
2016-08-11 22:41:56 -05:00
Richard Mudgett 4a5da6c9b4 taskprocessor.c: Tweak high water checks.
* The high water check in ast_taskprocessor_alert_set_levels() would
trigger immediately if the new high water level is zero and the queue was
empty.

* The high water check in taskprocessor_push() was off by one.

Change-Id: I687729fb4efa6a0ba38ec9c1c133c4d407bc3d5d
2016-08-11 12:00:08 -05:00
Richard Mudgett 5ba6357be2 res_pjsip: Make aor named lock a mutex.
The named aor lock was always being locked for writes so a rwlock adds no
benefit and may be slower because rwlocks are biased toward read locking.

Change-Id: I8c5c2c780eb30ce5441832257beeb3506fd12b28
2016-08-11 11:58:38 -05:00
David M. Lee ac0454f9fa Fixed compile flags for non-module libs
The non-module libs libasteriskssl.dylib and libasteriskpj.dylib have
long been missing the AST_NOT_MODULE compile flag. This was mostly
okay, until a recent fix to improve compiler warnings when the
AST_MODULE_SELF_SYM is missing broke the build on OS X/macOS/whatever
they are calling it these days.

Change-Id: I2cb51c890824f001280a5114f2e775f97c163516
2016-08-11 10:50:46 -05:00
zuul 74fffe9df2 Merge "res_srtp: Move SDP SRTP code from the core to res_srtp." 2016-08-11 06:19:33 -05:00
Richard Mudgett 41aba83ff6 res_srtp: Move SDP SRTP code from the core to res_srtp.
A patch made to the master branch (Now the 14 branch) inadvertently made
libsrtp a required dependency in order to compile Asterisk.  Rather than
create dummy defines to substitute for the defines supplied by libsrtp
when libsrtp is not available, most of the code in sdp_srtp.c is moved
into res_srtp.c.  This gets more code out of Asterisk's core that isn't
used when SRTP is not available.  This also makes another inadvertent
required dependency on libsrtp by Asterisk's core unlikely.

ASTERISK-26253 #close
Reported by: Ben Merrills

Change-Id: I0a46cde81501c0405399c2588633ae32706d1ee7
2016-08-10 17:43:15 -05:00
Alexei Gradinari 820879415f pjsip: Fix deadlock with suspend taskprocessor on masquerade
If both channels which should be masqueraded
are in the same serializer:
1st channel will be locked waiting condition 'complete'
2nd channel will be locked waiting condition 'suspended'

On heavy load system a chance that both channels will be in
the same serializer 'pjsip/distibutor' is very high.

To reproduce compile res_pjsip/pjsip_distributor.c with
DISTRIBUTOR_POOL_SIZE=1

Steps to reproduce:
1. Party A calls Party B (bridged call 'AB')
2. Party B places Party A on hold
3. Party B calls Voicemail app (non-bridged call 'BV')
4. Party B attended transfers Party A to voicemail using REFER.
5. When asterisk masquerades calls 'AB' and 'BV',
   a deadlock is happened.

This patch adds a suspension indicator to the taskprocessor.
When a session suspends/unsuspends the serializer
it sets the indicator to the appropriate state.
The session checks the suspension indicator before
suspend the serializer.

ASTERISK-26145 #close

Change-Id: Iaaebee60013a58c942ba47b1b4930a63e686663b
2016-08-10 15:14:38 -05:00
Corey Farrell 827457dca0 Produce friendly error when AST_MODULE_SELF_SYM is not defined.
Modules must define AST_MODULE_SELF_SYM to be used as the name of a
generated function.  This produces a friendly error when it's not
defined.

ASTERISK-26278 #close

Change-Id: Ib9d35a08104529c516d636771365e02c6e77a45b
2016-08-08 20:05:34 -05:00
Corey Farrell 29b0f733a0 Add missing checks during startup.
This ensures startup is canceled due to allocation failures from the
following initializations.
* channel.c: ast_channels_init
* config_options.c: aco_init

ASTERISK-26265 #close

Change-Id: I911ed08fa2a3be35de55903e0225957bcdbe9611
2016-08-03 16:11:38 -05:00
Joshua Colp 720a4ff663 Merge "Remove SILK payload mappings from Asterisk core." 2016-08-01 14:52:36 -05:00
Joshua Colp b8fdd3ad79 Merge "pbx.c: Fix handling of '-' in extension name and callerid" 2016-08-01 09:31:27 -05:00
Mark Michelson 1cd79d6ee5 Remove SILK payload mappings from Asterisk core.
SILK is a bit of a hog when it comes to using up our limited number of
dynamic payload types in the RTP engine. By freeing up four slots, it
allows for other codecs to potentially take the place.

Now, codec_silk.so will dynamically use the payload slots in the RTP
engine when it loads.

A better fix would be make RTP dynamic payload types actually
dynamic. However, at this stage of Asterisk 14 development, this is a
risky move that would be imprudent.

Change-Id: I5774e09408f9a203db189529eabdc0d3f4c1e612
2016-07-29 13:18:06 -05:00
Joshua Colp 9cead7c233 Merge "pbx.c: Allow dangerous functions when adding a hint to dialplan." 2016-07-29 07:25:02 -05:00
Corey Farrell 89a0a1eb45 pbx.c: Fix handling of '-' in extension name and callerid
This adds a two strings to ast_exten.  name to go with exten and
cidmatch_display to go with cidmatch.  The new fields contain input used
to add the extension in the first place.  The existing fields now
contain stripped input that excludes insignificant spaces and dashes.
These stripped fields should always be used for comparisons.  The
unstripped fields should normally be used for display, but displaying
stripped values will not cause runtime errors.

Note the actual string is only stored twice if it contains dashes.  If
no dashes are found then both 'char *' fields point to the same memory.
So this change has a minimum effect on memory usage.

The existing functions ast_get_extension_name and
ast_get_extension_cidmatch return unstripped values as they did before
this change.  Other similar bugs likely still exist where unstripped
extensions are saved outside pbx.c then passed back in.

ASTERISK-26233 #close

Change-Id: I6cd61ce57acc1570ca6cc14960c4c3b0a9eb837f
2016-07-28 19:02:39 -05:00
Joshua Colp aa69877049 Merge "dsp.c: Add fax and DTMF detection unit tests." 2016-07-28 17:35:13 -05:00
Joshua Colp 28e61e43d7 Merge "dsp.c: Added descriptive comments to Goertzel calculations." 2016-07-28 17:35:09 -05:00
Joshua Colp 085da4eec0 Merge "dsp.c: Fix incorrect format reference typo." 2016-07-28 17:35:05 -05:00
Richard Mudgett 68ebf86e2f pbx.c: Allow dangerous functions when adding a hint to dialplan.
We can allow dangerous functions when adding a hint since altering
dialplan is itself a privileged activity.  Otherwise, we could never
execute dangerous functions.

ASTERISK-25996 #close
Reported by: Andrew Nagy

Change-Id: I4929ff100ad1200a0198262d069a34f2296e77ba
2016-07-28 15:11:33 -05:00
Kevin Harwell 1d364ac54f rtp_engine: Failed assertion and wrong name given for codec
Fixed an assert check that would trigger when the passed in value was negative.
The negative value was being cast to an unsigned value. This resulted in the
check failing.

Also fixed another problem when loading formats in the engine. When setting the
mime type the format's name was being passed in instead of the codec's name.

Change-Id: I1a201cd419ba4d8e9a40d337e36b6fbe1737192c
2016-07-27 12:36:22 -05:00
Richard Mudgett 737471f131 dsp.c: Add fax and DTMF detection unit tests.
* Add fax amplitude and frequency sweep tests.
* Add DTMF amplitude and twist unit tests.

Change-Id: I8d77c9a1eec89e440d715f998c928687e870c3f7
2016-07-26 17:46:53 -05:00
Richard Mudgett a8cd5d255a dsp.c: Added descriptive comments to Goertzel calculations.
* Added doxygen to describe some struct members and what is going on in
the code.

Change-Id: I2ec706a33b52aee42b16dcc356c2bd916a45190d
2016-07-26 17:46:53 -05:00
Richard Mudgett 6dfb34cf13 dsp.c: Fix incorrect format reference typo.
Change-Id: Ia131da3ec29acf385cb43a586a29ecc975eb3896
2016-07-26 17:46:53 -05:00
Richard Mudgett 49461f37b7 dsp.c: Fix erroneous fax tone detection.
The Goertzel calculations get less accurate the lower the signal level
being worked with becomes because there is less resolution remaining.
If it is too low we can erroneously detect a tone where none really
exists.  The searched for fax frequencies not only need to be so much
stronger than the background noise they must also be a minimum strength.

* Add needed minimum threshold test to tone_detect().

* Set TONE_THRESHOLD to allow low volume frequency spread detection.

ASTERISK-26237 #close
Reported by: Richard Mudgett

Change-Id: I84dbba7f7628fa13720add6a88eae3b129e066fc
2016-07-26 11:48:52 -05:00
zuul e2bfcb3e58 Merge "codecs: Add iLBC 20." 2016-07-26 10:52:35 -05:00
zuul a99d5a6997 Merge "asterisk.c: Add auto generation and persistence of UUID" 2016-07-25 21:14:12 -05:00
George Joseph 8852a4c3db asterisk.c: Add auto generation and persistence of UUID
Upcoming features will require the generation and persistence
of a UUID.

Change-Id: I3ec0062427e133217db6ef496a4216f427c3b92d
2016-07-23 09:05:48 -05:00
Alexander Traud 8fb807009f codecs: Add iLBC 20.
Asterisk already supported iLBC 30. This change adds iLBC 20. Now, Asterisk
defaults to iLBC 20 but falls back to iLBC 30, when the remote party requests
this.

ASTERISK-26218 #close
ASTERISK-26221 #close
Reported by: Aaron Meriwether

Change-Id: I07f523a3aa1338bb5217a1bf69c1eeb92adedffa
2016-07-22 10:09:08 +02:00
Corey Farrell 68de3a9e51 pbx.c: Remove duplicate code.
Merge code found in both branches of a conditional in
ast_add_extension2_lockopt.

The updated code initializes peer_table and peer_label_table of the
extension before linking it to the context.

Change-Id: Ic759e27cdc9906c6877df41d28ee9c5be8f41c20
2016-07-21 23:59:08 -04:00
zuul 9473818659 Merge "res_srtp: Enable AES-256 and AES-GCM." 2016-07-21 21:11:07 -05:00
Joshua Colp 0933f0cf96 Merge "res_pjsip: Add fax_detect_timeout endpoint option." 2016-07-21 18:25:47 -05:00
zuul 194d0f606b Merge "pbx: Create pbx_sw.c for management of 'struct ast_sw'." 2016-07-21 15:55:10 -05:00
zuul fbdeb01edf Merge "Add conditional support for noreturn functions." 2016-07-21 15:29:22 -05:00
Corey Farrell a36a174c4b pbx: Create pbx_sw.c for management of 'struct ast_sw'.
This changes context switches from a linked list to a vector, makes
'struct ast_sw' opaque to pbx.c.

Although ast_walk_context_switches is maintained the procedure is no
longer efficient except for the first call (inc==NULL).  This
functionality is replaced by two new functions implemented by vector
macros.
* ast_context_switches_count (AST_VECTOR_SIZE)
* ast_context_switches_get (AST_VECTOR_GET)

As with ast_walk_context_switches callers of these functions are
expected to have locked contexts.  Only a few places in Asterisk walked
the switches, they have been converted to use the new functions.

Change-Id: I08deb016df22eee8288eb03de62593e45a1f0998
2016-07-21 13:58:26 -04:00
Alexander Traud 1d2173c7ae res_srtp: Enable AES-256 and AES-GCM.
ASTERISK-26190 #close

Change-Id: I11326d80edd656524a51a19450e586c583aa0a0b
2016-07-21 16:25:41 +02:00
zuul b1c45dc815 Merge "pbx: Create pbx_ignorepat.c for management of 'struct ast_ignorepat'." 2016-07-20 10:57:41 -05:00
Corey Farrell 8f6e9ffcc6 Add conditional support for noreturn functions.
This adds support for tagging functions with the noreturn attribute.
If DO_CRASH is enabled then ast_do_crash never returns.  If AST_DEVMODE
and DO_CRASH are enabled then failed assertions never return.  This can
resolve a large number of false positives with static analyzers.

ASTERISK-26220 #close

Change-Id: Icfb61e5fe54574eced4c3e88b317244f467ec753
2016-07-19 22:45:10 -05:00
Richard Mudgett e739888d99 res_pjsip: Add fax_detect_timeout endpoint option.
The new endpoint option allows the PJSIP channel driver's fax_detect
endpoint option to timeout on a call after the specified number of
seconds into a call.  The new feature is disabled if the timeout is set
to zero.  The option is disabled by default.

ASTERISK-26214
Reported by: Richard Mudgett

Change-Id: Id5a87375fb2c4f9dc1d4b44c78ec8735ba65453d
2016-07-19 10:33:45 -05:00
Joshua Colp 943bb48b59 Merge "pbx: Create pbx_include.c for management of 'struct ast_include'." 2016-07-18 07:07:36 -05:00
Corey Farrell e2e8713b84 pbx: Create pbx_ignorepat.c for management of 'struct ast_ignorepat'.
This changes context ignore patterns from a linked list to a vector,
makes 'struct ast_ignorepat' opaque to pbx.c.

Although ast_walk_context_ignorepats is maintained the procedure is no
longer efficient except for the first call (inc==NULL).  This
functionality is replaced by two new functions implemented by vector
macros.
* ast_context_ignorepats_count (AST_VECTOR_SIZE)
* ast_context_ignorepats_get (AST_VECTOR_GET)

As with ast_walk_context_ignorepats callers of these functions are
expected to have locked contexts.  Only a few places in Asterisk walked
the ignorepats, they have been converted to use the new functions.

Change-Id: I78f2157d275ef1b7d624b4ff7d770d38e5d7f20a
2016-07-18 03:21:43 -04:00
Alexander Traud d56fc3b36b translate: Enables native Packet-Loss Concealment (PLC) for supporting codecs.
ASTERISK-25629 #close

Change-Id: I66c0086e6c17764b8141ec60a3e2aaefe088eb78
2016-07-17 14:46:26 +02:00
Corey Farrell be36bd7ca5 pbx: Create pbx_include.c for management of 'struct ast_include'.
This changes context includes from a linked list to a vector, makes
'struct ast_include' opaque to pbx.c.

Although ast_walk_context_includes is maintained the procedure is no
longer efficient except for the first call (inc==NULL).  This
functionality is replaced by two new functions implemented by vector
macros.
* ast_context_includes_count (AST_VECTOR_SIZE)
* ast_context_includes_get (AST_VECTOR_GET)

As with ast_walk_context_includes callers of these functions are
expected to have locked contexts.  Only a few places in Asterisk walked
the includes, they have been converted to use the new functions.

const have been applied where possible to parameters for ast_include
functions.

Change-Id: Ib5c882e27cf96fb2aec67a39c18b4c71c9c83b60
2016-07-15 05:34:29 -04:00
Corey Farrell d3348c51b5 features.c: Remove unneeded adsi.h include.
adsi.h is no longer used by features.c since parking was moved to a
module.

Change-Id: I2248b8a455225a17cb6ddaafd6c20c511a1eaf59
2016-07-14 21:23:47 -05:00
Mark Michelson 273052f404 Update support for SILK format.
This commit adds scaffolding in order to support the SILK audio format
on calls. Roughly, this is what is added:

* Cached silk formats. One for each possible sample rate.
* ast_codec structures for each possible sample rate.
* RTP payload mappings for "SILK".

In addition, this change overhauls the res_format_attr_silk file in the
following ways:

* The "samplerate" attribute is scrapped. That's native to the format.
* There are far more checks to ensure that attributes have been
  allocated before attempting to reference them.
* We do not SDP fmtp lines for attributes set to 0.

These changes make way to be able to install a codec_silk module and
have it actually work. It also should allow for passthrough silk calls
in Asterisk.

Change-Id: Ieeb39c95a9fecc9246bcfd3c45a6c9b51c59380e
2016-07-14 15:59:49 -05:00
zuul 3cf33dd4e7 Merge "translate: explicit format destination not properly set" 2016-07-14 13:40:43 -05:00
zuul afcc519dff Merge "threadpool: Fix leak in ast_threadpool_serializer_group error path." 2016-07-14 13:33:52 -05:00
zuul 707dbcbcd1 Merge "pbx: Fix leak of timezone for time based includes." 2016-07-14 12:14:44 -05:00
zuul f0f137e5bd Merge "stasis_endpoint.c: Fix contactstatus_to_json()." 2016-07-14 09:37:00 -05:00
Corey Farrell f3608b50d7 pbx: Fix leak of timezone for time based includes.
Create include_free to run ast_destroy_timing and ast_free, use that in
all places that freed an ast_include structure.  This fixes a couple of
paths that previously did not run ast_destroy_timing.

ASTERISK-26196 #close

Change-Id: I1671bd111bef0dc113e8bf8f77f89fcfc395d838
2016-07-14 02:59:56 -05:00
Kevin Harwell 63ac4c9487 translate: explicit format destination not properly set
If the destination format's name differed from the codec name then the
translator's explict_dst field would be improperly set. In some circumstances
it would end up setting it to a newly created format that has the same name
as the codec when it actually needed to be the given destination codec.

This could cause the translation path to use the wrong format. For instance,
if an endpoint had specified 'myulaw' as a format the translator could end up
using a 'ulaw' format (with whatever/default settings) instead. If the format
attribute settings differed between the two then there may unexpected results
during processing.

This patch removes the name check when building the translation path. This
should make it always set the translator's explicit_dst to the given destination
format as long as the sample rate and types match.

Change-Id: Iaf8a03831d68e657d89569d54b505074efbefab5
2016-07-13 17:45:27 -05:00
Richard Mudgett 2f26512fd8 stasis_endpoint.c: Fix contactstatus_to_json().
The roundtrip_usec json member is optional.  If it isn't present then
don't put it into the converted json structure where ast_json_pack()
will choke on it.

Change-Id: I39bb2f86154ef54591270c58bfda8635070f9ea0
2016-07-13 15:12:19 -05:00
Corey Farrell fd54d69feb threadpool: Fix leak in ast_threadpool_serializer_group error path.
ast_threadpool_serializer_group leaks a reference to ser when listener
is allocated but tps is not.  Although listener takes the reference to
ser cleanup functions are not run without tps.

ASTERISK-26191 #close

Change-Id: Ie3ccf69a3f1e676c2ef62a77067c0cb57dc9a585
2016-07-13 11:47:56 -05:00
Matt Jordan f12311ee69 res/res_corosync: Raise a Stasis message on node join/leave events
When res_corosync detects that a node leaves or joins, it currently is
informed of this via Corosync callbacks. However, there are a few
limitations with the information presented:
(1) While we have information that Corosync is aware of - such as the
    Corosync nodeid - that information is really only useful inside of
    Corosync or res_corosync. There's no way to translate a Corosync
    nodeid to some other internally useful unique identifier for the
    Asterisk instance that just joined or left the cluster.
(2) While res_corosync is notified of the instance joining or leaving
    the cluster, it has no mechanism to inform the Asterisk core or
    other modules of this event. This limits the usefulness of res_corosync
    as a heartbeat mechanism for other modules.

This patch addresses both issues.

First, it adds the notion of a cluster discovery message both within the
Stasis message bus, as well as the binary event messages that
res_corosync uses to transmit data back and forth within the cluster.
When Asterisk joins the cluster, it sends a discovery message to the other
nodes in the cluster, which correlates the Corosync nodeid along with
the Asterisk EID. res_corosync now maintains a hash of Corosync nodeids
to Asterisk EIDs, such that it can map changes in cluster state with the
Asterisk instance that has that nodeid. Likewise, when an Asterisk
instance receives a discovery message from a node in the cluster, it now
sends its own discovery message back to the originating node with the
local Asterisk EID. This lets Asterisk instances within the cluster
build a complete picture of the other Asterisk instances within the
cluster.

Second, it publishes the discovery messages onto the Stasis message bus.
Said messages are published whenever a node joins or leaves the cluster.
Interested modules can subscribe for the ast_cluster_discovery_type()
message under the ast_system_topic() and be notified when changes in
cluster state occur.

Change-Id: I9015f418d6ae7f47e4994e04e18948df4d49b465
2016-07-13 09:11:37 -05:00
George Joseph 886f2cab23 rest_api/channels: Fix multiple issues with create and dial
* We weren't properly subscribing to the channel and it's originator
  on create.
* We weren't doing a publish_dial after calling ast_call on dial.
* We weren't calling depart_bridge when a channel left the dial bridge.

The first 2 issues were causing events to not be generated and the third
was actually causing channels to not get properly destroyed when hung up.

Together these 3 issues were causing the new
rest_apichannels/create_dial_bridge tests to fail.

As a result of the fixes, the cdr state machine had to be slightly
tweaked to allow bridge leave events without asserting and the tests
themselves had to be updated to account for the channels now cleaning
themselves up.

Change-Id: Ibf23abf5a62de76e82afb4461af5099c961b97d8
2016-07-12 11:16:44 -06:00
Richard Mudgett 44f16af7cc ast_expr2: Fix off-nominal memory leak.
Thanks to ibercom for pointing out a memory leak that was missed
in the earlier patch for the issue.

ASTERISK-26119
Reported by: Alexei Gradinari

Change-Id: I9a151f5c4725d97fb82a9e938bc73dc659532b71
2016-07-11 13:51:29 -05:00
Corey Farrell 7408c51a48 REF_DEBUG: Prevent logging of container node objects.
Using AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE can result in an unref being
recorded to the refs log for the node being replaced.  This prevents
logging of those unrefs since they would produce errors in
refcounter.py.

ASTERISK-26181 #close

Change-Id: Ie4fded84e8a1a58b3a59ce59dfd7eb0da3ddc5d4
2016-07-07 13:44:39 -04:00
Richard Mudgett 4f7b859726 features: Fix channel datastore access.
Found as a result of the testsuite tests/callparking test crashing.

Several calls to ast_get_chan_featuremap_config() and
ast_get_chan_features_xfer_config() did not lock the channel before
calling so the channel's datastore list was accessed without the lock's
protection.  Apparently another thread deleted a datastore on the
channel's list while the crashing thread was walking the list.  Crash at
0xdeaddead due to MALLOC_DEBUG's memory filler value as a result.

* Add missing channel locks to calls that were not already protected
as the doxygen for those calls indicates.

Change-Id: Id273b3d305cc616406c353cbc841b2b7655efaa1
2016-06-30 15:38:11 -05:00
George Joseph 4045e6d8ba codecs: Fix ABI incompatibility created by adding format_name to ast_codec
Adding format_name even to the end of ast_codec caused issued with
binary codec modules because the pointer would be garbage in asterisk
when they registered.  So, the ast_codec structure was reverted and an
internal_ast_codec structure was created just for use in codec.c.  A new
internal-only API was also added (__ast_codec_register_with_format) so
that codec_builtin could register codecs with the format_name in a
separate parameter rather than in the ast_codec structure.

ASTERISK-26144 #close
Reported-by: Alexei Gradinari

Change-Id: I6df1b08f6a6ae089db23adfe1ebc8636330265ba
2016-06-29 09:01:51 -05:00
George Joseph 651290a809 BuildSystem: Fix a few issues hightlighted by gcc 6.x
gcc 6.1.1 caught a few more issues.
Made sure the unit tests still pass for the func_env and stdtime
issues.

ASTERISK-26157 #close

Change-Id: I6664d8f34a45bc1481d2a854481c7878b0c1cf8e
2016-06-28 12:40:49 -05:00
Joshua Colp 8b85b05092 Merge "Fix Alembic upgrades." 2016-06-22 16:06:06 -05:00
Mark Michelson b6bd97eea2 Fix Alembic upgrades.
A non-existent constraint was being referenced in the upgrade script.
This patch corrects the problem by removing the reference.

In addition, the head of the alembic branch referred to a non-existent
revision. This has been fixed by referring to the proper revision.

This patch fixes another realtime problem as well. Our Alembic scripts
store booleans as yes or no values. However, Sorcery tries to insert
"true" or "false" instead. This patch introduces a new boolean type that
translates to "yes" or "no" instead.

ASTERISK-26128 #close

Change-Id: I51574736a881189de695a824883a18d66a52dcef
2016-06-22 12:23:44 -05:00
zuul d22ce6fd3e Merge "fix: memory leaks, resource leaks, out of bounds and bugs" 2016-06-21 07:26:12 -05:00
Alexei Gradinari 820ed3d4b3 fix: memory leaks, resource leaks, out of bounds and bugs
ASTERISK-26119 #close

Change-Id: Iecbf7d0f360a021147344c4e83ab242fd1e7512c
2016-06-20 13:08:18 -04:00
Alexander Traud f72ffc1ff9 http: leverage 'bindaddr' for TLS in http.conf
The internal HTTP/WebSocket server supports both TCP and TLS, which can be
activated separately via the file http.conf. The source code intends to re-use
the TCP parameter 'bindaddr' for TLS, even if 'tlsbindaddr' is not specified
explicitly. This did not work because of a typo. This change resolves this typo.

ASTERISK-26126 #close

Change-Id: I5efb0409ae12044dfb3495b6b97b6d40a8c9c51f
2016-06-20 15:06:22 +02:00
zuul d9b5aea9c3 Merge "core: Not the configured but granted number of possible file descriptors." 2016-06-10 15:50:35 -05:00
Alexander Traud ac683f13c9 core: Not the configured but granted number of possible file descriptors.
With CLI "core show settings", simply the parameter maxfiles of the file
asterisk.conf was shown. If that parameter was not set, nothing was displayed
although the environment might have set a default number itself. Or if maxfiles
were not granted (completely), still maxfiles was shown. Now, the maximum number
of possible file descriptors in the environment is shown.

ASTERISK-26097

Change-Id: I2df5c58863b5007b34b77adbe28b885dfcdf7e0b
2016-06-10 21:04:44 +02:00
Joshua Colp d1006faba9 Merge "astfd: With RLIMIT_NOFILE only the current value is sensible." 2016-06-10 13:46:48 -05:00
Joshua Colp 4eb8cf2684 translate: Enables native Packet-Loss Concealment (PLC) for supporting codecs.
This reverts commit 5bfef2a8b4 as it
caused fax test failures.

ASTERISK-25629

Change-Id: I79de974dc4f63a1cafe0d2509169fd9a6b3cbaf4
2016-06-10 12:40:00 -03:00
Alexander Traud 0bf1a53db3 astfd: With RLIMIT_NOFILE only the current value is sensible.
With menuselect "DEBUG_FD_LEAKS" and CLI "core show fd", both the maximum max
and current max of possible file descriptors were shown. Both show the same
value always. Not to confuse users, just the current maximum is shown now.

ASTERISK-26097

Change-Id: I49cf7952d73aec9e3f6a88942842c39be18380fa
2016-06-10 10:13:20 +02:00
zuul dcb6875428 Merge "cel: Ensure only one dial status per channel exists." 2016-06-09 22:38:52 -05:00
Joshua Colp 914a1502fa Merge "stasis: Add setting subscription congestion levels." 2016-06-09 16:45:54 -05:00
Joshua Colp 67a45e0a38 Merge "sorcery: Add setting object type congestion levels." 2016-06-09 16:45:48 -05:00
Joshua Colp 48c2c3b8da Merge "taskprocessors: Implement high/low water mark alerts." 2016-06-09 16:45:44 -05:00
Joshua Colp d338343dac cel: Ensure only one dial status per channel exists.
CEL wrongly assumed that a channel would only have a single dial
event on it. This is incorrect. Particularly in a queue each
call attempt to a member will result in a dial event, adding
a new dial status in CEL without removing the old one. This
would cause the container to grow with only one dial status
being removed when the channel went away. The other dial status
entries would remain leaking memory.

This change fixes the memory leak by ensuring that only one dial
status will only ever exist for each channel.

The behavior during the scenario where multiple events are received
has also been improved. For failure cases the first failure will
be the dial status. If an answer dial status is received, though,
it will take priority and the dial status for the channel will be
answer.

Memory usage has also been decreased by storing the minimal
amount of information and the code has been cleaned up slightly.

ASTERISK-25262 #close

Change-Id: I5944eb923db17b6a0faa7317ff6abc9307c009fe
2016-06-09 14:46:04 -05:00
George Joseph f0855358a6 cdr.c: Remove assert in base_process_dial_end
Scenario: Caller blonde transfer
Bob calls Charlie who answers.
Bob puts Charlie on hold and calls Alice.
Before Alice answers, Bob transfers Charlie to Alice.

Charlie's channel triggers an assert because he gets an "ANSWERED"
event even though he never dialed anything. With recent changes to dial
events, this is now a valid scenario so the assert needed to be removed.

ASTERISK-26103 #close

Change-Id: I2679b517b696e7952ab7fb29403df9140e7d1de2
2016-06-09 11:03:45 -05:00
Richard Mudgett dcfef53ee2 stasis: Add setting subscription congestion levels.
Stasis subscriptions and message routers create taskprocessors to process
the event messages.  API calls are needed to be able to set the congestion
levels of these taskprocessors for selected subscriptions and message
routers.

* Updated CDR, CEL, and manager's stasis subscription congestion levels
based upon stress testing.  Increased the congestion levels to reduce the
potential for bursty call setup/teardown activity from triggering the
taskprocessor overload alert.  CDRs in particular need an extra high
congestion level because they can take awhile to process the stasis
messages.

ASTERISK-26088
Reported by:  Richard Mudgett

Change-Id: Id0a716394b4eee746dd158acc63d703902450244
2016-06-09 10:32:07 -05:00
Richard Mudgett 4879cd875c sorcery: Add setting object type congestion levels.
Sorcery creates taskprocessors for object types to process object observer
callbacks.  An API call is needed to be able to set the congestion levels
of these taskprocessors for selected object types.

* Updated PJSIP's contact and contact_status sorcery object type observer
default congestion levels based upon stress testing.  Increased the
congestion levels to reduce the potential for bursty register/unregister
and subscribe/unsubscribe activity from triggering the taskprocessor
overload alert.

ASTERISK-26088
Reported by:  Richard Mudgett

Change-Id: I4542e83b556f0714009bfeff89505c801f1218c6
2016-06-09 10:32:07 -05:00
Richard Mudgett 2cd67d5b07 taskprocessors: Implement high/low water mark alerts.
When taskprocessors get backed up, there is a good chance that we are
being overloaded and need to defer adding new work to the system.

* Implemented a high/low water alert mechanism for modules to check if the
system is being overloaded and take appropriate action.  When a
taskprocessor is created it has default congestion levels set.  A
taskprocessor can later have those congestion levels altered for specific
needs if stress testing shows that the taskprocessor is a symptom of
overloading or needs to handle bursty activity without triggering an
overload alert.

* Add CLI "core show taskprocessor" low/high water columns.

* Fixed __allocate_taskprocessor() to not use RAII_VAR().  RAII_VAR() was
never a good thing to use when creating a taskprocessor because of the
nature of how its references needed to be cleaned up on a partial
creation.

* Made res_pjsip's distributor check if the taskprocessor overload alert
is active before placing a message representing brand new work onto a
distributor serializer.

ASTERISK-26088
Reported by:  Richard Mudgett

Change-Id: I182f1be603529cd665958661c4c05ff9901825fa
2016-06-09 10:32:07 -05:00
Joshua Colp fbece11a0c Merge "translate: Enables native Packet-Loss Concealment (PLC) for supporting codecs." 2016-06-09 07:24:46 -05:00
Joshua Colp 7eb3a3357c Merge "BuildSystem: Avoid 'ar cru' and use 'ar cr' instead." 2016-06-09 04:40:37 -05:00
Joshua Colp 20be856b51 Merge "Detect and use proper libraries for musl toolchains" 2016-06-09 04:40:30 -05:00
Joshua Colp 5c949d009e Merge "Fixes to include signal.h" 2016-06-09 04:40:24 -05:00
Joshua Colp 1ead09dcb1 Merge "Fix res_search usage" 2016-06-08 14:43:35 -05:00
Joshua Colp 7bcccd4db3 Merge "Fix #include poll.h and sys/cdefs.h" 2016-06-08 14:43:13 -05:00
Timo Teräs 72d190eb69 Detect and use proper libraries for musl toolchains
Change-Id: I8d9b212f70813404b82918a3f99439e500d4bfcb
2016-06-08 20:37:14 +03:00
Timo Teräs 39b69ab537 Fixes to include signal.h
POSIX defines signal.h. sys/signal.h should not be used as it is
c-library internal header which may or may not exist. Notably with
musl it generates warning of being incorrect.

Change-Id: Ia56b0aa1d84b5c590114867b1b384a624f39a6fc
2016-06-08 20:37:08 +03:00
Joshua Colp 71f70f5a07 Merge "apps/app_voicemail.c and main/say.c: Add support for Icelandic language" 2016-06-08 05:13:52 -05:00
Joshua Colp 643dd462ee Merge "ari/resource_channels: Add 'formats' to channel create/originate" 2016-06-08 05:13:37 -05:00
Örn Arnarson 60caebc738 apps/app_voicemail.c and main/say.c: Add support for Icelandic language
Icelandic has some weird grammar rules when dealing with dates and
numbers. There are different genders used depending on which number
you're dealing with, and only a handful of numbers do change depending
on the gender. There is also an implied gender in several cases.

This patch was originally written for asterisk 1.6, and has been in use
for several years without crashes. I cleaned it up a bit and rewrote
what was necessary for Asterisk 13.

The functions were copied from other similar languages and modified
where appropriate. If i recall correctly, the German and Danish
functions were used as a base.

ASTERISK-26087
Reported by: Örn Arnarson
Tested by: Örn Arnarson

Change-Id: Ib7d8bd7b0fede5767921ed821315b5b508c0e665
2016-06-07 11:36:48 +00:00
Alexander Traud da943ec5c0 BuildSystem: Avoid 'ar cru' and use 'ar cr' instead.
In several internal library projects, the files are archived with the help of
'ar cr'. Only the projects editline and the Objective Open H.323 stack
implementation in C (ooh323c) use 'ar cru' instead. Recently, some platforms
changed the default parameters of AR which creates "/usr/bin/ar: `u' modifier
ignored since `D' is the default (see `U')". For consistency and to avoid this
message all projects use 'ar cr' now.

ASTERISK-26091 #close

Change-Id: I710a9b1c01c1b5a1931a646098c044c8161ead40
2016-06-07 09:32:11 +02:00
Jaco Kroon 5bfef2a8b4 translate: Enables native Packet-Loss Concealment (PLC) for supporting codecs.
ASTERISK-25629 #close

Change-Id: Ibfcf0670e094e9718d82fd9920f1fb2dae122006
2016-06-05 12:02:52 +02:00
Alexei Gradinari 3e8d523d88 core/dial: New channel variable FORWARDERNAME
Added a new channel variable FORWARDERNAME which indicates which
channel was responsible for a forwarding requests received on dial attempt.

Fixed a bug in the app_queue: FORWARD_CONTEXT is not used.

ASTERISK-26059 #close

Change-Id: I34e93e8c1b5e17776a77b319703c48c8ca48e7b2
2016-06-04 11:07:22 -05:00
George Joseph a2f820e8dc ari/resource_channels: Add 'formats' to channel create/originate
If you create a local channel and don't specify an originator channel
to take capabilities from, we automatically add all audio formats to
the new channel's capabilities. When we try to make the channel
compatible with another, the "best format" functions pick the best
format available, which in this case will be slin192.  While this is
great for preserving quality, it's the worst for performance and
overkill for the vast majority of applications.

In the absense of any other information, adding all formats is the
correct thing to do and it's not always possible to supply an
originator so a new parameter 'formats' has been added to the channel
create/originate functions. It's just a comma separated list of formats
to make availalble for the channel. Example: "ulaw,slin,slin16".
'formats' and 'originator' are mutually exclusive.

To facilitate determination of format names, the format name has been
added to "core show codecs".

ASTERISK-26070 #close

Change-Id: I091b23ecd41c1b4128d85028209772ee139f604b
2016-06-03 17:30:40 -05:00
Joshua Colp f7ce0f1832 Merge "core/manager: Add uptime field to FullyBooted" 2016-06-03 08:09:52 -05:00
Timo Teräs 3c1fec8099 Fix res_search usage
Resolver state is not part of res_search API. This fixes
compilation error:

dns.c:261:8: error: too many arguments to function 'res_search'
  ret = res_search(&dns_state,

Change-Id: Ia600a58557040df83f744da3dde23225293845a5
2016-06-02 22:57:49 +03:00
Timo Teräs 9c1d95e873 Fix #include poll.h and sys/cdefs.h
POSIX defines poll.h, sys/poll.h should not be used at is c-library
internal header which may or may not exist. Notable in musl it
generates warning of being incorrect. And add explict include of
sys/cdefs.h where needed.

Change-Id: I142930df53fe7585a06b854b6faddc5301e024be
2016-06-02 22:53:39 +03:00
Niklas Larsson 8a5c2e736c core/manager: Add uptime field to FullyBooted
Add Uptime and LastReload to event FullyBooted.

ASTERISK-26058 #close
Reported by: Niklas Larsson

Change-Id: I909b330801c0990d78df9b272ab0adc95aecb15e
2016-06-02 14:14:20 +02:00
Richard Mudgett 40d19f2e55 logging,cdr,cel: Fix stringfield memory leak.
The stringfields refactor to allow adding stringfields to the end of a
structure (f6f4cf459f) exposed some
incomplete cleanup code by some stringfield users.

The most noticeable leaker is the logging system where there is a leak for
every log message generated.

ASTERISK-26078 #close
Reported by:  Etienne Lessard
Patches:
      jira_asterisk_26078_v13.patch (license #5621) patch uploaded
      by Richard Mudgett

Change-Id: If6a08b31336b492c3de6f9dfd07c447f8d5a8782
2016-06-01 14:09:36 -05:00
Joshua Colp 608e0267e8 Merge "Expand the scope of Dial Events" 2016-05-31 16:36:35 -05:00
Mark Michelson 205a31f86c Expand the scope of Dial Events
Dial events up to this point have come in two flavors
* A Dial event with no status to indicate that dialing has begun
* A Dial event with a status to indicate that dialing has ended

With this change, Dial events have been expanded to also give
intermediate events, such as "RINGING", "PROCEEDING", and "PROGRESS".
This is especially useful for ARI dialing, as it gives the application
writer the opportunity to place a channel into an early bridge when
early media is detected.

AMI handles these in-progress dial events by sending a new event called
"DialState" that simply indicates that dial state has changed but has
not ended. ARI never distinguished between DialBegin and DialEnd, so no
change was made to the event itself.

Another change here relates to dial forwards. A forward-related event
was previously only sent when a channel was successfully able to forward
a call to a new channel. With this set of changes, if forwarding is
blocked, we send a Dial event with a forwarding destination but no
forwarding channel, since we were prevented from creating one. This is
again useful for ARI since application writers can now handle call
forward attempts from within their own application.

ASTERISK-25925 #close
Reported by Mark Michelson

Change-Id: I42cbec7730d84640a434d143a0d172a740995543
2016-05-31 11:43:24 -05:00
Alexei Gradinari 31f17abe44 res_pjsip: add "via_addr", "via_port", "call_id" to contact
As res_pjsip_nat rewrites contact's address, only the last Via header
can contain the source address of registered endpoint.
Also Call-Id header may contain the source address of registered
endpoint.

Added "via_addr", "via_port", "call_id" to contact.
Added new fields ViaAddress, CallID to AMI event ContactStatus.

ASTERISK-26011

Change-Id: I36bcc0bf422b3e0623680152d80486aeafe4c576
2016-05-26 16:18:11 -05:00
Joshua Colp b0e4ea96de Merge "Bridging: introduce "invisible" bridges." 2016-05-25 05:32:55 -05:00
Corey Farrell 80ff2c2540 threadpool: Fix potential data race.
worker_start checked for ZOMBIE status without holding a lock.  All
other read/write of worker status are performed with a lock, so this
check should do the same.

ASTERISK-25777 #close

Change-Id: I5e33685a5c26fdb300851989a3b82be8c4e03781
2016-05-24 15:40:21 -05:00
Mark Michelson f6c33771f6 Bridging: introduce "invisible" bridges.
Invisible bridges function the same as normal bridges, but they have the
following restrictions:

* They never show up in CLI, AMI, or ARI queries.
* They do not have Stasis messages published about them.

Invisible bridges' main use is for when use of the bridging system is
desired, but the bridge should not be known to users of the Asterisk
system.

ASTERISK-25925

Change-Id: I804a209d3181d7c54e3d61a60eb462e7ce0e3670
2016-05-23 13:18:18 -05:00
Joshua Colp acbaa1b0cf Merge "udptl: Don't eat sequence numbers until OK is received" 2016-05-19 05:33:13 -05:00
Joshua Colp 5acb25722c Merge "logger: Support JSON logging with Verbose messages" 2016-05-19 05:31:19 -05:00
George Joseph 6e5e84458f udptl: Don't eat sequence numbers until OK is received
Scenario:
Local fax -> Asterisk w/ firewall -> Provider -> Remote fax

* Local fax starts rtp call to remote fax
* Remote fax starts t38 call back to local fax.
* Local fax sends t38 no-signal to Asterisk before sending an OK.
* udptl processes the frame and increments the expected sequence number.
* chan_sip drops the frame because the call isn't up so nothing goes out
  the external interface to open the port for incoming packets.
* Local fax sends OK and Asterisk sends OK to the remote fax.
* Remote fax sends t38 packets which are dropped by the firewall.
* Local fax re-sends t38 no-signal with the same sequence number.
* udptl drops the frame because it thinks it's a dup.
* Still no outgoing packets to open the firewall.
* t38 negotiation fails.

The patch drops frames t38 received before udptl sequence processing
when the call hasn't been answered yet.  The second no-signal frame
is then seen as new and is relayed out the external interface which
opens the port and allows negotiation to continue.

ASTERISK-26034 #close

Change-Id: I11744b39748bd2ecbbe8ea84cdb4f3c5943c5af9
2016-05-18 14:06:09 -05:00
Matt Jordan 3522376512 logger: Support JSON logging with Verbose messages
When 2d7a4a3357 was merged, it missed the fact that Verbose log messages
are formatted and handled by 'verbosers'. Verbosers are registered
functions that handle verbose messages only; they exist as a separate
class of callbacks. This was done to handle the 'magic' that must be
inserted into Verbose messages sent to remote consoles, so that the
consoles can format the messages correctly, i.e., the leading
tabs/characters.

In reality, verbosers are a weird appendage: they're a separate class of
formatters/message handlers outside of what handles all other log
messages in Asterisk. After some code inspection, it became clear that
simply passing a Verbose message along with its 'sublevel' importance
through the normal logging mechanisms removes the need for verbosers
altogether.

This patch removes the verbosers, and makes the default log formatter
aware that, if the log channel is a console log, it should simply insert
the 'verbose magic' into the log messages itself. This allows the
console handlers to interpret and format the verbose message
themselves.

This simplifies the code quite a lot, and should improve the performance
of printing verbose messages by a reasonable factor:
(1) It removes a number of memory allocations that were done on each
    verobse message
(2) It removes the need to strip the verbose magic out of the verbose
    log messages before passing them to non-console log channels
(3) It now performs fewer iterations over lists when handling verbose
    messages

Since verbose messages are now handled like other log messages (for the
most part), the JSON formatting of the messages works as well.

ASTERISK-25425

Change-Id: I21bf23f0a1e489b5102f8a035fe8871552ce4f96
2016-05-14 22:44:16 -05:00
Joshua Colp acdd0ae993 Merge "logger: Add PID to syslog messages." 2016-05-14 20:37:43 -05:00
Mark Michelson fd3f70598d Use doubles instead of floats for conversions when comparing strings.
In 13.9.0, there was an issue where PJSIP contacts added to an AOR would
be deleted at seemingly random times.

One reason this was happening was because of an operation to retrieve
the contacts whose expiration time was less than or equal to the current
time. When retrieving existing contacts, the contact's expiration time
and the current time were converted from a string to a float, and those
two floats were compared.

On some systems, including mine, this conversion was horribly off. For
instance, I could regularly see the string "1463079214" get converted
into 1463079168.000000. When switching from using a float to using a
double, the conversion was as expected.

Why was the conversion to float off? My best guess is that the
conversion to float was attempting to store the entire value in the 23
bit significand of the IEEE-754 floating point number. In particular, if
you take only the 23 most significant bits of 1463079214, you get the
messed up 1463079168 that we were seeing in the conversion. It likely
was possible to get a more precise value by composing the number using
an exponent, but the conversion did not work that way. With a double,
you have a 52 bit significand, allowing the entire value to fit there,
and thereby allowing an accurate conversion.

ASTERISK-26007 #close
Reported by Greg Siemon

Change-Id: I83ca7944aae8b7cd994b254c78ec02411d321070
2016-05-12 15:24:33 -05:00
Alexei Gradinari 9f996624b0 logger: Add PID to syslog messages.
During refactoring of this support the addition of
the PID to messages was removed. This change adds it
back in.

ASTERISK-25538 #close

Change-Id: Ie2d43b0652e59b7ac319a7dba94501540d70ba36
2016-05-12 05:12:15 -05:00
zuul 53e965a572 Merge "datastore: Add common container based datastores API." 2016-05-09 18:23:44 -05:00
Joshua Colp 94cd351ec4 datastore: Add common container based datastores API.
This change introduces a common container based datastores
management API. This has been done in a few places across
the tree but this consolidates all of the logic into one
place in a generic fashion.

ASTERISK-25999

Change-Id: I72eb15941dcdbc2a37bb00a33ce00f8755bd336a
2016-05-09 10:40:28 -03:00
Joshua Colp bf957e1bf7 Merge "file: Ensure nativeformats remains valid for lifetime of use." 2016-05-09 08:28:16 -05:00
Alexei Gradinari 516f49f316 stasis_endpoints: Add new Status and Headers to ContactStatus
ASTERISK-25903 added a new headers to AMI Event ContactStatusDetail.
ASTERISK-25904 added a new Status to AMI Event ContactStatusDetail.
These additions should be also in stasis_endpoints
to include in command "manager show event ContactStatus"

Change-Id: I7610ad02a998e1f26c20caa27aa50279d0164f6a
2016-05-06 08:23:34 -05:00
Joshua Colp 17b6ba49ef file: Ensure nativeformats remains valid for lifetime of use.
It is possible for the nativeformats of a channel to change
throughout its lifetime. As a result a user of it needs to either
ensure the channel is locked when accessing the formats or keep
a reference to the nativeformats themselves.

This change fixes the file playback support so it keeps a
reference to the nativeformats when accessing things.

ASTERISK-25998 #close

Change-Id: Ie45b65475e1481ddf05b874ee48f63e39fff8915
2016-05-05 11:02:48 -05:00
Chris Trobridge 02f4ca1079 config_options.c: Expand #ifdef to contain whole if statement.
ASTERISK-25956 #close

Change-Id: If6961ec54be276d5ab4f012ee7e7b420cb45de38
2016-05-04 22:19:57 -05:00
George Joseph e61716b774 pjproject_bundled: Various fixes discovered during testing of OSes
For all OSes:
* Disabled third-party codecs in pjproject and added
  '--disable-speex-codec --disable-speex-aec --disable-gsm-codec' to the
  configure options since we don't use the pjsip codec capability.

FreeBSD:
* Added FreeBSD support to install_prereq.
* Changed pjproject/configure.m4 to use $GNU_MAKE instead of hardcoding "make".
* Added __progname and environ to asterisk.exports.in.
* Reverted the use of ldconfig to create shared library symlinks to ln.
* Only enable epoll in pjproject if `uname -s` is Linux.
* Added a patch to pjproject to take the name of the 'make' command from
  an environment variable if supplied.  This is needed for the python bindings.
  (merged by Teluu into pjproject trunk 5/3/2016)
FreeBSD support isn't complete.  Still some general issues regarding
make/gmake having nothing to do with pjproject.  With some handholding it DOES
build successfully.

CentOS:
Added 'patch' and 'bzip2' to install_prereq PACKAGES_RH.
CentOS 6/7 32/64 build and run the pjsip testsuite successfully.

Ubuntu:
No changes required.
Ubuntu 15/16 32/64 build and run the pjsip testsuite successfully.

Debian:
No changes required.
Debian 6/7/8 32/64 build and run the pjsip testsuite successfully.

There will utimately be a follow-up patch to create an install_prereq for
the testsuite as I've discovered a few missing requirements.

ASTERISK-25968 #close

Change-Id: I5756a07facfc63798115a5e73a8709382fe9259c
2016-05-03 07:56:18 -05:00
zuul d53d494f0b Merge "app_chanspy: reduce audio loss on the spying channel." 2016-04-28 17:45:57 -05:00
Joshua Colp f324801763 Merge "config: Fix ast_config_text_file_save2 writability check for missing files" 2016-04-27 14:55:55 -05:00
Jean Aunis 7281770710 app_chanspy: reduce audio loss on the spying channel.
ChanSpy was creating its audiohook with the flags AST_AUDIOHOOK_TRIGGER_SYNC
and AST_AUDIOHOOK_SMALL_QUEUE, which caused audio frames to be lost when
queues grow too large or when read and write queues go out of sync.
Now these flags are set conditionally:
- AST_AUDIOHOOK_TRIGGER_SYNC is not set if the option "o" is set
- a new option "l" is created: if set, AST_AUDIOHOOK_SMALL_QUEUE will not
be set on the audiohook

ASTERISK-25866

Change-Id: I9c7652f41d9fa72c8691e4e70ec4fd16b047a4dd
2016-04-27 15:39:59 +02:00
Joshua Colp 09d588dc2f Merge changes from topic 'system_stress_patches'
* changes:
  test_message.c: Wait longer in case dialplan also processes the test message.
  Manager: Short circuit AMI message processing.
  manager.c: Eliminate most RAII_VAR usage.
2016-04-26 04:57:36 -05:00
zuul 0f29785101 Merge "manager_channels.c: Fix allocation failure crash." 2016-04-25 22:00:51 -05:00
zuul 811e24f595 Merge "Bridge system: Fix memory leaks and double frees on impart failure." 2016-04-25 21:08:16 -05:00
zuul 807a765cfb Merge "bridge_softmix.c: Fix crash if channel fails to join mixing tech." 2016-04-25 21:08:15 -05:00
George Joseph 284bb814ac config: Fix ast_config_text_file_save2 writability check for missing files
A patch I did back in 2014 modified ast_config_text_file_save2 to check the
writability of the main file and include files before truncating and re-writing
them.  An unintended side-effect of this was that if a file doesn't exist,
the check fails and the write is aborted.

This patch causes ast_config_text_file_save2 to check the writability of the
parent directory of missing files instead of checking the file itself.  This
allows missing files to be created again.  A unit test was also added to
test_config to test saving of config files.

The regression was discovered when app_voicemail's passwordlocation=spooldir
feature stopped working.

ASTERISK-25917 #close
Reported-by: Jonathan Rose

Change-Id: Ic4dbe58c277a47b674679e49daed5fc6de349f80
2016-04-25 18:17:28 -05:00
zuul 1df086f821 Merge "bridge: Hold off more than one imparting channel at a time." 2016-04-22 17:08:04 -05:00
Richard Mudgett b3cc74fda9 manager_channels.c: Fix allocation failure crash.
An earlier allocation failure failed to create a channel snapshot for the
AMI HangupRequest/SoftHangupRequest event which resulted in a crash in
channel_hangup_request_cb().  Where the stasis message gets generated
cannot tell if the NULL snapshot returned was because of an allocation
failure or the channel was a dummy channel.

* Made channel_hangup_request_cb() check if the channel blob has a
snapshot and exit if it doesn't.

* Eliminated the RAII_VAR usage in channel_hangup_request_cb().

Change-Id: I0b6a1c4e95cbb7d80b2a7054c6eadecc169dfd24
2016-04-22 15:45:47 -05:00
Richard Mudgett a63656b419 Bridge system: Fix memory leaks and double frees on impart failure.
You cannot reference the passed in features struct after calling
ast_bridge_impart().  Even if the call fails.

Change-Id: I902b88ba0d5d39520e670fb635078a367268ea21
2016-04-22 15:45:47 -05:00
Richard Mudgett 71dfa35540 bridge_softmix.c: Fix crash if channel fails to join mixing tech.
softmix_bridge_join() failed because of an allocation failure.  To address
this, the softmix bridge technology now checks if the channel failed to
join softmix successfully.  In addition, the bridge now begins the process
of kicking the channel out of the bridge so we don't have channels
partially in the bridge for very long.

* Fix the test_channel_feature_hooks.c unit tests.  The test channel must
have a valid codec to join the simple_bridge technology.  This patch makes
joining a bridge more strict by not allowing partially joined channels to
remain in the bridge.

Change-Id: I97e2ade6a2bcd1214f24fb839fda948825b61a2b
2016-04-22 15:45:47 -05:00
Richard Mudgett 06632a0d11 Manager: Short circuit AMI message processing.
Improve AMI message processing performance if there are no consumers
listening for the messages.  We now skip creating the AMI event message
text strings.

Change-Id: I7b22fc5ec4e500d00635c1a467aa8ea68a1bb2b3
2016-04-22 15:45:47 -05:00
Richard Mudgett 6ddd856b86 manager.c: Eliminate most RAII_VAR usage.
* Made ast_manager_event_blob_create() not allocate the ao2 event object
with a lock as it is not needed.

Change-Id: I8e11bfedd22c21316012e0b9dd79f5918f644b7c
2016-04-22 15:45:47 -05:00
zuul 24913e1540 Merge "lock.c: Check *lt before dereferencing it" 2016-04-21 13:01:56 -05:00
zuul b4dd374bc4 Merge "stringfields: Update extended string fields for master only." 2016-04-21 12:48:27 -05:00
Diederik de Groot c991e5472e lock.c: Check *lt before dereferencing it
*lt is NULL if t->tracking == 0

ASTERISK-25948 #close

Change-Id: I4a81af28f9c82a74aa82413d772a7dc8fa6f45ba
2016-04-21 11:07:18 -05:00
Richard Mudgett 1c5248c383 bridge: Hold off more than one imparting channel at a time.
An earlier patch blocked the ast_bridge_impart() call until the channel
either entered the target bridge or it failed.  Unfortuantely, if the
target bridge is stasis and the imprted channel is not a stasis channel,
stasis bounces the channel out of the bridge to come back into the bridge
as a proper stasis channel.  When the channel is bounced out, that
released the block on ast_bridge_impart() to continue.  If the impart was
a result of a transfer, then it became a race to see if the swap channel
would get hung up before the imparted channel could come back into the
stasis bridge.  If the imparted channel won then everything is fine.  If
the swap channel gets hung up first then the transfer will fail because
the swap channel is leaving the bridge.

* Allow a chain of ast_bridge_impart()'s to happen before any are
unblocked to prevent the race condition described above.  When the channel
finally joins the bridge or completely fails to join the bridge then the
ast_bridge_impart() instances are unblocked.

ASTERISK-25947
Reported by: Richard Mudgett

ASTERISK-24649
Reported by: John Bigelow

ASTERISK-24782
Reported by: John Bigelow

Change-Id: I8fef369171f295f580024ab4971e95c799d0dde1
2016-04-20 15:44:21 -05:00
zuul cc9b72208f Merge "Dial: Combine frame handling functions." 2016-04-20 10:53:17 -05:00
Richard Mudgett 6365f0018f bridge_channel.c: Ignore role setup failure in channel push.
We have to setup the channel roles after the bridge class push is called
because the bridge class push callback may have set roles on the incoming
channel.  Since we have already partially pushed the channel into the
bridge and reversing what we have already done could be problematic, the
only thing we can do is press on to complete pushing the channel into the
bridge.

* Ignore any channel role setup errors after pushing the channel into a
bridge.  The channel may behave incorrectly in the bridge but we can no
longer abort the push at this time.

Change-Id: I08a97082b729052ee65cdca6bb730cf1289ede00
2016-04-18 10:52:53 -05:00
Mark Michelson 5e64d7e7a3 Dial: Combine frame handling functions.
There is a good amount of repetition in the two frame handling routines
in the Dial API. This commit combines the two functions into one.

This is in preparation for an upcoming commit that adds the ability to
handle frames for a channel in a bridge.

ASTERISK-25925
Reported by Mark Michelson

Change-Id: Iaae2f174e3058e774cb44e10659fcdfb85345c58
2016-04-14 17:39:41 -05:00
Alexei Gradinari a6e2ba187a Codecs: strip codec name while parsing allow/disallow options
Failed registration using PJSIP/Realtime if one of the codec name
in allow/disallow option is wrong or contains space.

This patch strip codec name.

ASTERISK-25914

Change-Id: Ifdf02de94e5ddbce305640f6f0666084a3b9283d
2016-04-14 16:35:56 -05:00
George Joseph caa416d5f3 stringfields: Update extended string fields for master only.
In 13, the new ast_string_field_header structure had to be dynamically
allocated and assigned to a pointer in ast_string_field_mgr to preserve ABI
compatability.  In master, it can be converted to being a structure-in-place in
ast_string_field_mgr to eliminate the extra alloc and free calls.

Change-Id: Ia97c5345eec68717a15dc16fe2e6746ff2a926f4
2016-04-13 14:01:37 -06:00
Jaco Kroon 2cc56573de core_unreal: Fix hangupcauses not getting set on Local channels
ASTERISK-25912 #close

Change-Id: I8e72e6894feaf36c9450f2788d205d07baec23aa
2016-04-11 14:56:54 -05:00
Joshua Colp 44fba00ca4 Merge "lock: Add named lock capability" 2016-04-11 12:58:44 -05:00
Joshua Colp 8610f4344f Merge "pbx.h: Make ast_state_cb_type take more const." 2016-04-08 15:47:50 -05:00
George Joseph 216abb0ae7 lock: Add named lock capability
Locking some objects like sorcery objects can be tricky because the underlying
ao2 object may not be the same for all callers.  For instance, two threads that
call ast_sorcery_retrieve_by_id on the same aor name might actually get 2
different ao2 objects if the underlying wizard had to rehydrate the aor from a
database. Locking one ao2 object doesn't have any effect on the other even if
those objects had locks in the first place.

Named locks allow access control by keyspace and key strings.  Now an "aor"
named "1000" can be locked and any other thread attempting to lock "aor" "1000"
will wait regardless of whether the underlying ao2 object is the same or not.
Mutex and rwlocks are supported.

This capability will initially be used to lock an aor when multiple threads may
be attempting to prune expired contacts from it.

Change-Id: If258c0b7f92b02d07243ce70e535821a1ea7fb45
2016-04-08 13:52:02 -05:00
Joshua Colp b47dfd1c6e Merge "pbx.c: Minor code rearangements." 2016-04-08 11:59:55 -05:00
Richard Mudgett 6138a75e8e pbx.h: Make ast_state_cb_type take more const.
This eliminates some casts that I made a note saying v10 and above
would no longer need them.

Better late than never :)

Change-Id: I346cdb3032b6478ceb40eb6fe732978b54035572
2016-04-07 17:20:17 -05:00
Richard Mudgett 72c19f7dc5 pbx.c: Minor code rearangements.
* Pull out a loop invariant.

* Convert an else-if ladder to a switch statement.

Change-Id: I0a95cfa9474a4600b9865f7b444534d275b37e95
2016-04-07 17:14:10 -05:00
Richard Mudgett 28cefc3e88 pbx: Update doxygen for extension state watchers.
Change-Id: Id1403b12136de62a272c01bb355aef65fd2c2d1e
2016-04-07 16:18:47 -05:00
Joshua Colp 724c16c543 Merge "pbx: Add support for autohints." 2016-04-07 15:11:17 -05:00
Jacek Konieczny 8ed5f61152 frame.c: Copy the whole subclass in ast_frdup().
The problem is ast_frdup() does not copy whole frame.subclass for voice,
video and image frames, only the format is copied.  For video frames, the
subclass structure contains the .frame_ending flag used to put the RTP
marker where it needs to be.

ASTERISK-25894 #close

Change-Id: I812ca90e84ed5d4f473b997d0dd0d3c5a915fe33
2016-04-06 11:10:49 -05:00
Joshua Colp 4d06a4f366 Merge "Dial: Add function to append already-created channel." 2016-04-05 18:12:37 -05:00
Joshua Colp c49ee63db1 Merge "config: Allow filters when appending to a category" 2016-04-05 16:38:11 -05:00
Joshua Colp 1dc5e28624 pbx: Add support for autohints.
This change introduces the concept of autohints. These are hints
which are created as a result of device state changes occurring within
the core. When this happens a hint will be created (if it does not
exist already) using the device name as the extension.

For example if a device state change is received for "PJSIP/bob"
and autohints are enabled on a context then a hint will exist in
that context for "bob" with a device of "PJSIP/bob".

For virtual or custom device states the name after the type will
be used. For example if the device state of "Custom:bob" changes
then a hint will exist in that context for "bob" with a device of
"Custom:bob".

This functionality can be enabled in extensions.conf by placing
"autohints=yes" in a context.

ASTERISK-25881 #close

Change-Id: I7e444c7da41b7b7d33374420fec658beeb18584e
2016-04-05 18:29:30 -03:00
Mark Michelson ef4d3f1328 Dial: Add function to append already-created channel.
The Dial API takes responsiblity for creating an outbound channel when
calling ast_dial_append(). This commit adds a new function,
ast_dial_append_channel(), which allows us to create the channel outside
the Dial API and then to append the channel to the ast_dial structure.

This is useful for situations where the channel's creation and dialing
are distinct operations. Upcoming ARI early bridge work will illustrate
its usage.

ASTERISK-25889

Change-Id: Id8179f64f8f99132f80dead8d5db2030fd2c0509
2016-04-05 11:55:50 -05:00
Joshua Colp 245c9ca5ce Merge "stringfields: Refactor to allow fields to be added to the end of structures" 2016-04-05 11:40:40 -05:00
George Joseph 984d6fd95c config: Allow filters when appending to a category
In sorcery based config files where there are multiple categories with the same
name, you can't use the (+) operator to reliably append to a category because
config.c stops looking when it finds the first one with the same name.

Example:

[1000]
type = endpoint

[1000]
type = aor

[1000](+)
authenticate_qualify = yes

This config will fail because config.c appends authenticate_qualify to the
first category it finds, the endpoint, and that's not valid for endpoint.

Solution:

The capability to find a category that contains a certain variable already
exists so the only real change was to parse anything after the '+' that's not a
comma, as a filter string.

[1000]
type = endpoint

[1000]
type = aor

[1000](+type=aor)
authenticate_qualify = yes

This now works as expected.

Although the following example doesn't make any sense for pjsip, you can even
specify multiple filters:

[1000](+type=aor&qualify_frequency=10)

ASTERISK-25868 #close
Reported-by: Nick Repin

Change-Id: I10773da4c79db36fbf1993961992af63d3441580
2016-04-05 11:26:31 -05:00
Joshua Colp 051da5c3af Merge "res_rtp_asterisk: Use separate SRTP session for RTCP with DTLS" 2016-04-05 05:37:44 -05:00
George Joseph 4d40b161c3 stringfields: Refactor to allow fields to be added to the end of structures
String fields are great, except that you can't add new ones without breaking
ABI compatibility because it shifts down everything else in the structure.
The only alternative is to add your own char * field to the end of the
structure and manage the memory yourself which isn't ideal, especially since
you then can't use the OPT_STRINGFIELD_T type.

Background:

The reason string fields had to be declared inside the
AST_DECLARE_STRING_FIELDS block was to facilitate iteration over all declared
fields for initialization, compare and copy.  Since AST_DECLARE_STRING_FIELDS
declared the pool, then the fields, then the manager, you could use the offsets
of the pool and manager and iterate over the sequential addresses in between to
access the fields. The actual pool, field allocation and field set operations
don't actually care where the field is.  It's just iteration over the fields
that was the problem.

Solution: Extended String Fields

An extended string field is one that is declared outside the
AST_DECLARE_STRING_FIELDS block but still (anywhere) inside the parent
structure.  Other than using AST_STRING_FIELD_EXTENDED instead of
AST_STRING_FIELD, it looks the same as other string fields.  It's storage comes
from the pool and it participates in string field compare and copy operations
peformed on the parent structure. It's also a valid target for the
OPT_STRINGFIELD_T aco option type.

Implementation:

To keep track of the extended fields and make sure that ABI isn't broken, the
existing embedded_pool pointer in the manager structure was repurposed to be a
pointer to a separate header structure that contains the embedded_pool pointer
plus a vector of fields.  The length of the manager structure didn't change and
the embedded_pool pointer isn't used in the macros, only the stringfields C
code.  A side benefit of this is that changing the header structure in the
future won't break ABI.

ast_string_fields_init initializes the normal string fields and appends them to
the vector, and subsequent calls to ast_string_field_init_extended initialize
and append the extended fields. Cleanup, ast_string_fields_cmp, and
ast_string_fields_copy can now work on the vector instead of sequentially
traversing the addresses between the pool and manager.

The total size of a structure using string fields didn't change, whether using
extended fields or not, nor have the offsets of any structure members, either
inside the original block or outside.  Adding an extended field to the end of a
structure is the same as adding a char *.

Details:

The stringfield C code was pulled out from utils.c and into stringfields.c.
It just made sense.

Additional work was done in ast_string_field_init and
ast_calloc_with_stringfields to handle the allocation of the new header
structure and the vector, and the associated cleanup.  In the process some
additional NULL pointer checking was added.

A lot of work was done in stringfields.h since the logic for compare and copy
is there.  Documentation was added as well as somne additional NULL checking.

The ability to call ast_calloc_with_stringfields with a number of structures
greater than 1 never really worked.  Well, the calloc worked but there was no
way to access the additional structures or clean them up.  It was agreed that
there was no use case for requesting more than 1 structure so an ast_assert
was added to prevent it and the iteration code removed.

Testing:

The stringfield unit tests were updated to test both normal and extended
fields.  Tests for ast_string_field_ptr_set_by_fields and
ast_calloc_with_stringfields were also added.

As an ABI test, 13 was compiled from git and the res_pjsip_* modules, except
res_pjsip itself, saved off.  The patch was then added and a full compile and
install was performed.  Then the older res_pjsip_* moduled were copied over the
installed versions so res_pjsip was new and the rest were old.  No issues.

contact->aor, which is a char * at the end of contact, was then changed to an
extended string field and a recompile and reinstall was performed, again
leaving stock versions of the the res_pjsip_* modules.  Again, no issues with
the res_pjsip_* modules using the old stringfield implementation and with
contact->aor as a char *, and res_pjsip itself using the new stringfield
implementation and contact->aor being an extended string field.

Finally, several existing string fields were converted to extended string
fields to test OPT_STRINGFIELD_T.  Again, no issues.

Change-Id: I235db338c5b178f5a13b7946afbaa5d4a0f91d61
2016-04-04 19:07:53 -05:00
George Joseph 433d2c4bbf utils.c: Fix typo in handle_show_locks
ast_cli_allow_on_shutdown(e) should have been ast_cli_allow_at_shutdown(e).

Change-Id: I4f092495c0b2bfd85c2651e0b5877bf4d05d9faf
2016-04-01 13:11:34 -05:00
Joshua Colp 0ec3299c5f Merge "pjproject_bundled: Fix use of LDCONFIG for shared library link creation" 2016-03-31 11:13:11 -05:00
George Joseph 304f81780d pjproject_bundled: Fix use of LDCONFIG for shared library link creation
LDCONFIG apparently isn't set to something sane on all systems so the creation
of the shared library links fails.  Instead of just testing for non-blank,
main/Makefile now checks that LDCONFIG is actually executable and reverts to
LN if it isn't.

This applies to both libasteriskpj and libasteriskssl.

Thanks to 'abelbeck' for pointing out that the issue was LDCONFIG.

ASTERISK-25873 #close
Reported-by: Hans van Eijsden

Change-Id: I25b76379bc637726ec044b2c0e709b56b3701729
2016-03-30 18:46:15 -05:00
Richard Mudgett 34457dd9db core_unreal.c: Add clarification comment about channel ref.
Change-Id: I0be0627260cd8d6b6c3cc345949dcfdf32eff1f3
2016-03-30 16:27:48 -05:00
Jacek Konieczny 970803efcb res_rtp_asterisk: Use separate SRTP session for RTCP with DTLS
Asterisk uses separate UDP ports for RTP and RTCP traffic and RFC 5764
explicitly states:

  There MUST be a separate DTLS-SRTP session for each distinct pair of
  source and destination ports used by a media session

This means RTP keying material cannot be used for DTLS RTCP, which was
the reason why RTCP encryption would fail.

ASTERISK-25642

Change-Id: I7e8779d8b63e371088081bb113131361b2847e3a
2016-03-29 10:57:55 -05:00
George Joseph c948ce9651 sorcery/res_pjsip: Refactor for realtime performance
There were a number of places in the res_pjsip stack that were getting
all endpoints or all aors, and then filtering them locally.

A good example is pjsip_options which, on startup, retrieves all
endpoints, then the aors for those endpoints, then tests the aors to see
if the qualify_frequency is > 0.  One issue was that it never did
anything with the endpoints other than retrieve the aors so we probably
could have skipped a step and just retrieved all aors. But nevermind.

This worked reasonably well with local config files but with a realtime
backend and thousands of objects, this was a nightmare.  The issue
really boiled down to the fact that while realtime supports predicates
that are passed to the database engine, the non-realtime sorcery
backends didn't.

They do now.

The realtime engines have a scheme for doing simple comparisons. They
take in an ast_variable (or list) for matching, and the name of each
variable can contain an operator.  For instance, a name of
"qualify_frequency >" and a value of "0" would create a SQL predicate
that looks like "where qualify_frequency > '0'".  If there's no operator
after the name, the engines add an '=' so a simple name of
"qualify_frequency" and a value of "10" would return exact matches.

The non-realtime backends decide whether to include an object in a
result set by calling ast_sorcery_changeset_create on every object in
the internal container.  However, ast_sorcery_changeset_create only does
exact string matches though so a name of "qualify_frequency >" and a
value of "0" returns nothing because the literal "qualify_frequency >"
doesn't match any name in the objset set.

So, the real task was to create a generic string matcher that can take a
left value, operator and a right value and perform the match. To that
end, strings.c has a new ast_strings_match(left, operator, right)
function.  Left and right are the strings to operate on and the operator
can be a string containing any of the following: = (or NULL or ""), !=,
>, >=, <, <=, like or regex.  If the operator is like or regex, the
right string should be a %-pattern or a regex expression.  If both left
and right can be converted to float, then a numeric comparison is
performed, otherwise a string comparison is performed.

To use this new function on ast_variables, 2 new functions were added to
config.c.  One that compares 2 ast_variables, and one that compares 2
ast_variable lists.  The former is useful when you want to compare 2
ast_variables that happen to be in a list but don't want to traverse the
list.  The latter will traverse the right list and return true if all
the variables in it match the left list.

Now, the backends' fields_cmp functions call ast_variable_lists_match
instead of ast_sorcery_changeset_create and they can now process the
same syntax as the realtime engines.  The realtime backend just passes
the variable list unaltered to the engine.  The only gotcha is that
there's no common realtime engine support for regex so that's been noted
in the api docs for ast_sorcery_retrieve_by_fields.

Only one more change to sorcery was done...  A new config flag
"allow_unqualified_fetch" was added to reg_sorcery_realtime.
"no": ignore fetches if no predicate fields were supplied.
"error": same as no but emit an error. (good for testing)
"yes": allow (the default);
"warn": allow but emit a warning. (good for testing)

Now on to res_pjsip...

pjsip_options was modified to retrieve aors with qualify_frequency > 0
rather than all endpoints then all aors.  Not only was this a big
improvement in realtime retrieval but even for config files there's an
improvement because we're not going through endpoints anymore.

res_pjsip_mwi was modified to retieve only endpoints with something in
the mailboxes field instead of all endpoints then testing mailboxes.

res_pjsip_registrar_expire was completely refactored.  It was retrieving
all contacts then setting up scheduler entries to check for expiration.
Now, it's a single thread (like keepalive) that periodically retrieves
only contacts whose expiration time is < now and deletes them.  A new
contact_expiration_check_interval was added to global with a default of
30 seconds.

Ross Beer reports that with this patch, his Asterisk startup time dropped
from around an hour to under 30 seconds.

There are still objects that can't be filtered at the database like
identifies, transports, and registrations.  These are not going to be
anywhere near as numerous as endpoints, aors, auths, contacts however.

Back to allow_unqualified_fetch.  If this is set to yes and you have a
very large number of objects in the database, the pjsip CLI commands
will attempt to retrive ALL of them if not qualified with a LIKE.
Worse, if you type "pjsip show endpoint <tab>" guess what's going to
happen? :)  Having a cache helps but all the objects will have to be
retrieved at least once to fill the cache.  Setting
allow_unqualified_fetch=no prevents the mass retrieve and should be used
on endpoints, auths, aors, and contacts.  It should NOT be used for
identifies, registrations and transports since these MUST be
retrieved in bulk.

Example sorcery.conf:

[res_pjsip]
endpoint=config,pjsip.conf,criteria=type=endpoint
endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error

ASTERISK-25826 #close
Reported-by: Ross Beer
Tested-by: Ross Beer

Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-27 22:43:27 -05:00
Richard Mudgett 8e8cf80cea res_parking: Fix blind transfer dynamic lots creation.
Blind transfers to a recognized parking extension need to use the parker's
channel variable values to create the dynamic parking lot.  This is
because there is always only one parker while the parkee may actually be a
multi-party bridge.  A multi-party bridge can never supply the needed
channel variables to create the dynamic parking lot.  In the multi-party
bridge blind transfer scenario, the parker's CHANNEL(parkinglot) value and
channel variables are inherited by the local channel used to park the
bridge.

* In park_common_setup(), make use the parker instead of the parkee to
supply the dynamic parking lot channel variable values.  In all but one
case, the parkee is the same as the parker.  However, in the recognized
parking extension blind transfer scenario for a two party bridge they are
different channels.  For consistency, we need to use the parker channel.

* In park_local_transfer(), pass the CHANNEL(parkinglot) value to the
local channel when blind transferring a multi-party bridge to a recognized
parking extension.

* When a local channel starts a call, the Local;2 side needs to inherit
the CHANNEL(parkinglot) value from Local;1.

The DTMF one-touch parking case wasn't even trying to create dynamic
parking lots before it aborted the attempt.

* In parking_park_call(), add missing code to create a dynamic parking
lot.

A DTMF bridge hook is documented as returning -1 to remove the hook.
Though the hook caller is really coded to accept non-zero.  See the
ast_bridge_hook_callback typedef.

* In feature_park_call(), don't remove the DTMF one-touch parking hook
because of an error.

ASTERISK-24605 #close
Reported by:  Philip Correia
Patches:
      call_park.patch (license #6672) patch uploaded by Philip Correia

Change-Id: I221d3a8fcc181877a1158d17004474d35d8016c9
2016-03-26 02:52:08 -05:00
zuul 4cf7458c2e Merge "core/logging: Fix broken syslog levels on older glibc." 2016-03-25 13:38:39 -05:00
Joshua Colp ffe345cf6e Merge "media_cache: Demote warning to debug as it may occur often." 2016-03-25 12:30:51 -05:00
Joshua Colp 72a897c534 media_cache: Demote warning to debug as it may occur often.
The file playback system will now query the media cache and then
the old file functionality. Under normal conditions this will result
in the cache failing to retrieve a file causing a warning message
to get output each time a file is played back.

This change demotes this warning to a debug message.

Change-Id: Ib72246ba300b5cce32774bfb3c26634bfb708624
2016-03-25 10:22:36 -05:00
Mark Michelson 89e94e886c Restrict CLI/AMI commands on shutdown.
During stress testing, we have frequently seen crashes occur because a
CLI or AMI command attempts to access information that is in the process
of being destroyed.

When addressing how to fix this issue, we initially considered fixing
individual crashes we observed. However, the changes required to fix
those problems would introduce considerable overhead to the nominal
case. This is not reasonable in order to prevent a crash from occurring
while Asterisk is already shutting down.

Instead, this change makes it so AMI and CLI commands cannot be executed
if Asterisk is being shut down. For AMI, this is absolute. For CLI,
though, certain commands can be registered so that they may be run
during Asterisk shutdown.

ASTERISK-25825 #close

Change-Id: I8887e215ac352fadf7f4c1e082da9089b1421990
2016-03-24 16:59:24 -05:00
Gianluca Merlo 894071ea2c config: fix flags in uint option handler
The configuration unsigned integer option handler sets flags for the
parser as if the option should be a signed integer (PARSE_INT32),
leading to errors on "out of range" values. Fix flags (PARSE_UINT32).

A fix to res_pjsip is also present which stops invalid flags from
being passed when registering sorcery object fields for qualify
status.

ASTERISK-25612 #close

Change-Id: I96b539336275e0e72a8e8033487d2c3344debd3e
2016-03-24 11:15:30 -05:00
Walter Doekes 87c9ab97ea core/logging: Fix broken syslog levels on older glibc.
The fix to ASTERISK-25407 introduced the usage of LOG_MAKEPRI. However
this macro is broken in older glibc (< 2.17); it would left-shift the
facility a second time, causing the resultant priority to become
invalid.

The syslog manpage mentions nothing about LOG_MAKEPRI and suggests this:

    The priority argument is formed by ORing the facility and the level
    values [...].

ASTERISK-25510 #close
Reported by: Michael Newton

Change-Id: Ia89debe7fac5ad090c7ef595c0707f31bb1e3d03
2016-03-24 06:34:47 -05:00
Matt Jordan 13efea24f7 main/app: Only look to end of file if ':end' is specified, and not just ':'
There is a little known feature in app_controlplayback that will cause the
specified offset to be used relative to the end of a file if a ':end' is
detected within the filename.

This feature is pretty bad, but okay.

However, a bug exists in this code where a ':' detected in the filename
will cause the end pointer to be non-NULL, even if the full ':end' isn't
specified. This causes us to treat an unspecified offset (0) as being
"start playing from the end of the file", resulting in no file playback
occurring.

This patch fixes this bug by resetting the end pointer if ':end' is not
found in the filename.

Change-Id: Ib4c7b1b45283e4effd622a970055c51146892f35
2016-03-23 13:53:31 -03:00
Matt Jordan ca14b99e6e main/file: Add the ability to play media in the media cache
This patch allows applications/APIs that access media through the core file
APIs to play media in the media cache. Prior to determining if a 'filename'
exists, the filename is passed to the media cache's retrieve API call. If
that call succeeds, the local file specified passed back by the API is
opened for streaming. When used in this fashion, the 'filename' is actually
a URI that the media cache process and understand.

ASTERISK-25654 #close

Change-Id: I73b6e2e90c3e91b8500581c45cdf9c0dc785f5f0
2016-03-23 13:53:31 -03:00
Matt Jordan 791b4c9f81 main/media_cache: Provide an extension on the local file associated with a URI
This patch does the following:

First, it addresses file extension handling in the media cache. The media core
in Asterisk is a bit interesting in that it wants:
 * A file to have an extension on it. That extension is used to associate the
   file with a defined format module.
 * The filename passed to the core to not have an extension on it. This allows
   the core to match the available file formats with the format a channel
   is capable of handling.

Unfortunately, this makes the current implementation a bit lacking in the media
cache. By default, we do not store the extension of a retrieved URI on the
local file that is created. As a result, the media core does not know what
format the file is, and the file is ignored. Modifying the file outside of the
media core is bad, as we would not be able to update the internal
ast_bucket_file's path.

At the same time, we do not want to pass the extension out in the file_path
parameter in ast_media_cache_retrieve. This parameter is intended to be fed
into the media core; if we passed the extension, all callers would have to
strip it off.

Thus, this patch does the following:
* If there is an extension specified in the URL, we append it to the local
  file name (if a preferred file name isn't specified), and we store that
  in the local file path.
* The extension, however, is stripped off of the file_path parameter passed
  back out of ast_media_cache_retrieve.

Second, this patch causes stale items to be completely removed from the system.
Prior to this patch, sound files could be orphaned due to the bucket
referencing the file being deleted, but the file itself not being removed. This
is now addressed by explicitly calling ast_bucket_file_delete on the
bucket_file when it is deemed to be stale. Note that this only happen when we
know we will attempt to retrieve the resource again.

Finally, this patch changes the AO2 container holding media items to just use
a regular mutex. The usage for this container already assumed it was a plain
mutex, and - given that retrieval of an item can cause it to be replaced in
the container - a mutex makes more sense than a read/write lock.

Change-Id: I51667fff86ae8d2e4a663555dfa85b11e935fe0f
2016-03-23 11:46:39 -03:00
Richard Mudgett 9a7cfa2b61 sched.c: Ensure oldest expiring entry runs first.
This patch is part of a series to resolve deadlocks in chan_sip.c.

* Updated sched unit test to check new behavior.

ASTERISK-25023

Change-Id: Ib69437327b3cda5e14c4238d9ff91b2531b34ef3
2016-03-16 14:22:19 -05:00
Walter Doekes dcb25bb057 app_chanspy: Fix occasional deadlock with ChanSpy and Local channels.
Channel masquerading had a conflict with autochannel locking.

When locking autochannel->channel, the channel is fetched from the
autochannel and then locked. During the fetch, the autochannel -- which
has no locks itself -- can be modified by someone who owns the channel
lock. That means that the value of autochan->channel cannot be trusted
until you hold the lock.

In practice, this caused problems with Local channels getting
masqueraded away while the ChanSpy attempted to get info from that
channel. The old channel which was about to get removed got locked, but
the new (replaced) channel got unlocked (no-op). Because the replaced
channel was now locked (and would never get unlocked), it couldn't get
removed from the channel list in a timely manner, and would now cause
deadlocks when iterating over the channel list.

This change checks the autochannel after locking the channel for changes
to the autochannel. If the channel had been changed, the lock is
reobtained on the new channel.

In theory it seems possible that after this fix, the lock attempt on the
old (wrong) channel can be on an already destroyed lock, maybe causing
a crash. But that hasn't been observed in the wild and is harder induce
than the current deadlock.

Thanks go to Filip Frank for suggesting a fix similar to this and
especially to IRC user hexanol for pointing out why this deadlock was
possible and testing this fix. And to Richard for catching my rookie
while loop mistake ;)

ASTERISK-25321 #close

Change-Id: I293ae0014e531cd0e675c3f02d1d118a98683def
2016-03-11 16:05:30 -06:00
Joshua Colp 5cf2226e01 Merge "main/cli.c: Refactor function to print seconds formatted" 2016-03-08 11:29:45 -06:00
Rodrigo Ramírez Norambuena 0ec9fe5421 main/cli.c: Refactor function to print seconds formatted
Refactor and created function ast_cli_print_timestr_fromseconds to print
seconds formatted:  year(s) week(s) day(s) hour(s) second(s)

This function now is used in addons/cdr_mysql.c,cdr_pgsql.c, main/cli.c,
res_config_ldap.c, res_config_pgsql.c.

Change-Id: Ibeb8634102cd11d3f8623398b279cb731bcde36c
2016-03-07 03:42:18 -03:00
zuul 139b0b0b2c Merge "loader: Retry dlopen when loading fails" 2016-03-03 19:57:44 -06:00
George Joseph 195100e770 loader: Retry dlopen when loading fails
Although we use the RTLD_LAZY flag when calling dlopen
the first time on a module, this only defers resolution
for function calls.  Pointer references to functions are
determined at link time so dlopen expects them to be there.
Since we don't cross-module link, pointers to functions
in other modules won't be available and dlopen will fail.

Doing a "hardened" build also causes problems because it
typically sets "-z now" on the ld command line which
overrides RTLD_LAZY at run time.

If the failing module isn't a GLOBAL_SYMBOLS module, then
dlopen will be called again after all the GLOBAL_SYMBOLS
modules have been loaded and they'll eventually resolve.

If the calling module IS a GLOBAL_SYMBOLS module itself
and a third module depends on it, then there's an issue
because the second time through the dlopen loop,
GLOBAL_SYMBOLS modules aren't given any special treatment
and since the order in which dlopen is called isn't
deterministic, the dependent may again be tried before the
module it needs is loaded.

Simple solution:  Save modules that fail load_resource
because of a dlopen error in a list and retry them
immediately after the first pass. Keep retrying until
the failed list is empty or we reach a #defined max
retries. Error messages are suppressed until the final
pass which also gets rid of those confusing error messages
about module failures that are later corrected.

Change-Id: Iddae1d97cd2f00b94e61662447432765755f64bb
2016-03-03 15:38:01 -06:00
Kevin Harwell 15c5743ac1 bridge.c: Crash during attended transfer when missing a local channel half
It's possible for the transferer channel to get hung up early during the
attended transfer process. For instance, a phone may send a "bye" immediately
upon receiving a sip notify that contains a sip frag 100 (I'm looking at you
Jitsi). When this occurs a race begins between the transferer being hung up
and completion of the transfer code.

If the channel hangs up too early during a transfer involving stasis bridging
for instance, then when the created local channel goes to look up its swap
channel (and associated datastore) it can't find it (since it is no longer in
the bridge) thus it fails to enter the stasis application. Consequently, the
created local channel(s) hang up as well. If the timing is just right then the
bridging code attempts to add the message link with missing local channel(s).
Hence the crash.

Unfortunately, there is no great way to solve the problem of the unexpected
"bye". While we can't guarantee we won't receive an early hangup, and in this
case still fail to enter the stasis application, we can make it so asterisk
does not crash.

This patch does just that by locking the local channel structure, checking
that the local channel's peer has not been lost, and then continuing. This
keeps the local channel's peer from being ripped out from underneath it by
the local/unreal hangup code while attempting to set the stasis message link.

ASTERISK-25771

Change-Id: Ie6d6061e34c7c95f07116fffac9a09e5d225c880
2016-03-03 14:03:14 -06:00
zuul 7023055def Merge "build-system: Allow building with static pjproject" 2016-03-03 11:30:42 -06:00
Joshua Colp d7fe2becdd Merge "SIP diversion: Fix REDIRECTING(reason) value inconsistencies." 2016-03-03 07:40:41 -06:00
Scott Griepentrog 0a3f0e85ac CHAOS: cleanup possible null vars on msg alloc failure
In message.c, if msg_alloc fails to init the string field,
vars may be null, so use a null tolerant cleanup.

In res_pjsip_messaging.c, if msg_data_create fails, mdata
will be null, so use a null tolerant cleanup.

ASTERISK-25323

Change-Id: Ic2d55c2c3750d5616e2a05ea92a19c717507ff56
2016-03-02 11:56:51 -06:00
Richard Mudgett 25de01f301 SIP diversion: Fix REDIRECTING(reason) value inconsistencies.
Previous chan_sip behavior:

Before this patch chan_sip would always strip any quotes from an incoming
reason and pass that value up as the REDIRECTING(reason).  For an outgoing
reason value, chan_sip would check the value against known values and
quote any it didn't recognize.  Incoming 480 response message reason text
was just assigned to the REDIRECTING(reason).

Previous chan_pjsip behavior:

Before this patch chan_pjsip would always pass the incoming reason value
up as the REDIRECTING(reason).  For an outgoing reason value, chan_pjsip
would send the reason value as passed down.

With this patch:

Both channel drivers match incoming reason values with values documented
by REDIRECTING(reason) and values documented by RFC5806 regardless of
whether they are quoted or not.  RFC5806 values are mapped to the
equivalent REDIRECTING(reason) documented value and is set in
REDIRECTING(reason).  e.g., an incoming RFC5806 'unconditional' value or a
quoted string version ('"unconditional"') is converted to
REDIRECTING(reason)'s 'cfu' value.  The user's dialplan only needs to deal
with 'cfu' instead of any of the aliases.

The incoming 480 response reason text supported by chan_sip checks for
known reason values and if not matched then puts quotes around the reason
string and assigns that to REDIRECTING(reason).

Both channel drivers send outgoing known REDIRECTING(reason) values as the
unquoted RFC5806 equivalent.  User custom values are either sent as is or
with added quotes if SIP doesn't allow a character within the value as
part of a RFC3261 Section 25.1 token.  Note that there are still
limitations on what characters can be put in a custom user value.  e.g.,
embedding quotes in the middle of the reason string is silly and just
going to cause you grief.

* Setting a REDIRECTING(reason) value now recognizes RFC5806 aliases.
e.g., Setting REDIRECTING(reason) to 'unconditional' is converted to the
'cfu' value.

* Added missing malloc() NULL return check in res_pjsip_diversion.c
set_redirecting_reason().

* Fixed potential read from a stale pointer in res_pjsip_diversion.c
add_diversion_header().  The reason string needed to be copied into the
tdata memory pool to ensure that the string would always be available.
Otherwise, if the reason string returned by reason_code_to_str() was a
user's reason string then the string could be freed later by another
thread.

Change-Id: Ifba83d23a195a9f64d55b9c681d2e62476b68a87
2016-03-01 20:21:58 -06:00
George Joseph 3173e91bab build-system: Allow building with static pjproject
Background here:
http://lists.digium.com/pipermail/asterisk-dev/2016-January/075266.html

From CHANGES:
 * To help insure that Asterisk is compiled and run with the same known
   version of pjproject, a new option (--with-pjproject-bundled) has been
   added to ./configure.  When specified, the version of pjproject specified
   in third-party/versions.mak will be downloaded and configured.  When you
   make Asterisk, the build process will also automatically build pjproject
   and Asterisk will be statically linked to it.  Once a particular version
   of pjproject is configured and built, it won't be configured or built
   again unless you run a 'make distclean'.

   To facilitate testing, when 'make install' is run, the pjsua and pjsystest
   utilities and the pjproject python bindings will be installed in
   ASTDATADIR/third-party/pjproject.

   The default behavior remains building with the shared pjproject
   installation, if any.

Building:

   All you have to do is include the --with-pjproject-bundled option on
   the ./configure command line (and remove any existing --with-pjproject
   option if specified).  Everything else is automatic.

Behind the scenes:

   The top-level Makefile was modified to include 'third-party' in the
   list of MOD_SUBDIRS.

   The third-party directory was created to contain any third party
   packages that may be needed in the future.  Its Makefile automatically
   iterates over any subdirectories passing on targets.

   The third-party/pjproject directory was created to house the pjproject
   source distribution.  Its Makefile contains targets to download, patch
   configure, generate dependencies, compile libs, apps and python bindings,
   sanitized build.mak and generate a symbols list.

   When bootstrap.sh is run, it automatically includes the configure.m4
   file in third-party/pjproject.  This file has a macro to download and
   conifgure pjproject and get and set PJPROJECT_INCLUDE, PJPROJECT_DIR
   and PJPROJECT_BUNDLED.  It also tests for the capabilities like
   PJ_TRANSACTION_GRP_LOCK by parsing preprocessor output as opposed to
   trying to compile.  Of course, bootstrap.sh is only run once and the
   configure file is incldued in the patch.

   When configure is run with the new options, the macro in configure.m4
   triggers the download, patch, conifgure and tests.  No compilation is
   performed at this time.  The downloaded tarball is cached in /tmp so
   it doesn't get downloaded again on a distclean.

   When make is run in the top-level Asterisk source directory, it will
   automatically descend all the subdirectories in third_party just as it
   does for addons, apps, etc.  The top-level Makefile makes sure that
   the 'third-party' is built before 'main' so that dependencies from the
   other directories are built first.

   When main does build, a new shared library (libasteriskpj) is created that
   links statically to the pjproject .a files and exports all their symbols.
   The asterisk binary links to that, just as it does with libasteriskssl.

   When Asterisk is installed, the pjsua and pjsystest apps, and the pjproject
   python bindings are installed in ASTDATADIR/third-party/pjproject.  This
   will facilitate testing, including running the testsuite which will be
   updated to check that directory for the pjsua module ahead of the system
   python library.

Modules should continue to depend on pjproject if they use pjproject APIs
directly.  They should not care about the implementation.  No changes to any
res_pjsip modules were made.

Change-Id: Ia7a60c28c2e9ba9537c5570f933c1ebcb20a3103
2016-03-01 09:30:43 -07:00
Joshua Colp b075549286 Merge "bridge core: Add owed T.38 terminate when channel leaves a bridge." 2016-03-01 06:00:28 -06:00
Joshua Colp aadc58a1e7 Merge "channel api: Create is_t38_active accessor functions." 2016-03-01 06:00:18 -06:00
Joshua Colp 916cc68585 Merge "bridge_channel: Don't settle owed events on an optimization." 2016-03-01 06:00:04 -06:00
Joshua Colp 806e4a664f Merge "channel.c: Route all control frames to a channel through the same code." 2016-03-01 05:59:54 -06:00
Richard Mudgett c7d45b84f9 bridge core: Add owed T.38 terminate when channel leaves a bridge.
The channel is now going to get T.38 terminated when it leaves the
bridging system and the bridged peers are going to get T.38 terminated as
well.

ASTERISK-25582

Change-Id: I77a9205979910210e3068e1ddff400dbf35c4ca7
2016-02-29 12:50:43 -06:00
Richard Mudgett 0e296563d7 channel api: Create is_t38_active accessor functions.
ASTERISK-25582

Change-Id: I69451920b122de7ee18d15bb231c80ea7067a22b
2016-02-29 12:50:43 -06:00
Richard Mudgett 86f7336c91 bridge_channel: Don't settle owed events on an optimization.
Local channel optimization could cause DTMF digits to be duplicated.
Pending DTMF end events would be posted to a bridge when the local channel
optimizes out and is replaced by the channel further down the chain.  When
the real digit ends, the channel would get another DTMF end posted to the
bridge.

A -- LocalA;1/n -- LocalA;2/n -- LocalB;1 -- LocalB;2 -- B

1) LocalA has the /n flag to prevent optimization.
2) B is sending DTMF to A through the local channel chain.
3) When LocalB optimizes out it can move B to the position of LocalB;1
4) Without this patch, when B swaps with LocalB;1 then LocalB;1 would
settle an owed DTMF end to the bridge toward LocalA;2.
5) When B finally ends its DTMF it sends the DTMF end down the chain.
6) Without this patch, A would hear the DTMF digit end when LocalB
optimizes out and when B ends the original digit.

ASTERISK-25582

Change-Id: I1bbd28b8b399c0fb54985a5747f330a4cd2aa251
2016-02-29 12:50:43 -06:00
Richard Mudgett 128c96456c channel.c: Route all control frames to a channel through the same code.
Frame hooks can conceivably return a control frame in exchange for an
audio frame inside ast_write().  Those returned control frames were not
handled quite the same as if they were sent to ast_indicate().  Now it
doesn't matter if you use ast_write() to send an AST_FRAME_CONTROL to a
channel or ast_indicate().

ASTERISK-25582

Change-Id: I5775f41421aca2b510128198e9b827bf9169629b
2016-02-29 12:50:43 -06:00
George Joseph 4422905218 sorcery: Refactor create, update and delete to better deal with caches
The ast_sorcery_create, update and delete function have been refactored
to better deal with caches and errors.

The action is now called on all non-caching wizards first. If ANY succeed,
the action is called on all caching wizards and the observers are notified.
This way we don't put something in the cache (or update or delete) before
knowing the action was performed in at least 1 backend and we only call the
observers once even if there were multiple writable backends.

ast_sorcery_create was never adding to caches in the first place which
was preventing contacts from getting added to a memory_cache when they
were created.  In turn this was causing memory_cache to emit errors if
the contact was deleted before being retrieved (which would have
populated the cache).

ASTERISK-25811 #close
Reported-by: Ross Beer

Change-Id: Id5596ce691685a79886e57b0865888458d6e7b46
2016-02-29 11:31:42 -06:00
Richard Mudgett 30a49b8a6a cel.c: Fix mismatch in ast_cel_track_event() return type.
The return type of ast_cel_track_event() is not large enough to return all
64 potential bits of the event enable mask.  Fortunately, the defined CEL
events do not really need all 64 bits and the return value is only used to
determine if the requested CEL event is enabled.

* Made the ast_cel_track_event() return 0 or 1 only so the return value
can fit inside an int type instead of zero or a truncated 64 bit non-zero
value.

Change-Id: I783d932320db11a95c7bf7636a72b6fe2566904c
2016-02-17 14:06:58 -06:00
Mark Michelson 3b426a8b09 Check for OpenSSL defines before trying to use them.
The SSL_OP_NO_TLSv1_1 and SSL_OP_NO_TLSv1_2 defines did not exist prior
to OpenSSL version 1.0.1. A recent commit attempts to, by default, set
these options, which can cause problems on systems with older OpenSSL
installations.

This commit adds a configure script check for those defines and will not
attempt to make use of those if they do not exist. We will print a
warning urging the user to upgrade their OpenSSL installation if those
defines are not present.

Change-Id: I6a2eb9a43fd0738b404d8f6f2cf4b5c22d9d752d
2016-02-04 16:57:46 -06:00
Kevin Harwell e89114c1be Merge "AST-2016-003 udptl.c: Fix uninitialized values." 2016-02-03 15:17:22 -06:00
Joshua Colp 0de74fad55 AST-2016-001 http: Provide greater control of TLS and set modern defaults.
This change exposes the configuration of various aspects of the TLS
support and sets the default to the modern standards.

The TLS cipher is now set to the best values according to the
Mozilla OpSec team, different TLS versions can now be disabled, and
the cipher order can be forced to be that of the server instead of
the client.

ASTERISK-24972 #close

Change-Id: I0a10f2883f7559af5e48dee0901251dbf30d45b8
2016-02-03 15:10:16 -06:00
Richard Mudgett e67b445e8d AST-2016-003 udptl.c: Fix uninitialized values.
Sending UDPTL packets to Asterisk with the right amount of missing
sequence numbers and enough redundant 0-length IFP packets, can make
Asterisk crash.

ASTERISK-25603 #close
Reported by: Walter Doekes

ASTERISK-25742 #close
Reported by: Torrey Searle

Change-Id: I97df8375041be986f3f266ac1946a538023a5255
2016-02-03 15:07:04 -06:00
George Joseph 40da6434c1 build_system: Fix some warnings highlighted by clang
Fix some warnings found with clang.

Change-Id: I5195b6189b148c2ee3ed4a19d015a6d4ef3e77bd
2016-02-01 19:22:40 -06:00
Mark Michelson 51547175c0 Merge "config: Allow options to register when documentation is unavailable." 2016-01-28 15:56:30 -06:00
Richard Mudgett d2397f028f config_options.c: Fix warning message wording.
Change-Id: I915ea437936320393afde0e7552cf0a980a6b2e4
2016-01-28 12:49:29 -06:00
Joshua Colp 1dfd104a27 config: Allow options to register when documentation is unavailable.
The config options framework is strict in that configuration options must
be documented unless XML documentation support is not available. In
practice this is useful as it ensures documentation exists however in
off-nominal cases this can cause strange problems.

If it is expected that a config option has a non-zero or non-empty
default value but the config option documentation is unavailable
this reasonable expectation will not be met. This can cause obscure
crashes and weirdness depending on how the code handles it.

This change tweaks the behavior to ensure that the config option
is still allowed to register, apply default values, and be set when
devmode is not enabled. If devmode is enabled then the option can
NOT be set.

This also does not remove the initial documentation error message that
is output on load when registering the configuration option.

ASTERISK-25725 #close

Change-Id: Iec42fca6b35f31326c33fcdc25473f6fd7bc8af8
2016-01-26 11:16:55 -06:00
Richard Mudgett 7866806fc3 logger.c: Fix buffer overrun found by address sanitizer.
The null terminator of the tail struct member was not being allocated
when no logger.conf config file is installed.

ASTERISK-25714 #close
Reported by: Badalian Vyacheslav

Change-Id: I45770fdd08af39506a3bc33ba279c4f16e047a30
2016-01-22 12:35:56 -06:00
Matt Jordan 1943561691 Merge "main/asterisk.c: ast_el_read_char" 2016-01-21 17:25:03 -06:00
Mark Michelson e66021d2ca Merge "taskprocessor.c: Increase CLI "core ping taskprocessor" timeout." 2016-01-20 14:19:02 -06:00
Mark Michelson 8adb8e3e1a Merge "taskprocessor.c: Fix some taskprocessor unrefs." 2016-01-20 14:18:57 -06:00
Diederik de Groot b259ac95ac main/asterisk.c: ast_el_read_char
Make sure buf[res] is not accessed at res=-1 (buffer underrun).
Address Sanitizer will complain about this quite loudly.

ASTERISK-24801 #close

Change-Id: Ifcd7f691310815a31756b76067c56fba299d3ae9
2016-01-20 18:37:56 +01:00
Richard Mudgett c9f7269b2e taskprocessor.c: Increase CLI "core ping taskprocessor" timeout.
Change-Id: I4892d6acbb580d6c207d006341eaf5e0f8f2a029
2016-01-19 16:48:59 -06:00
Richard Mudgett 6e2a867716 taskprocessor.c: Fix some taskprocessor unrefs.
You have to call ast_taskprocessor_unref() outside of the taskprocessor
implementation code.  Taskprocessor use since v12 has become more
transient than just the singleton uses in earlier versions.

Change-Id: If7675299924c0cc65f2a43a85254e6f06f2d61bb
2016-01-19 16:48:14 -06:00
Corey Farrell 35a3e8cc7f Refactor init_logger_chain locking.
This removes logchannels locking from init_logger_chain, puts the
responsibility on the caller.  Adds locking around the one call that was
missing it.

ASTERISK-24833

Change-Id: I6cc42117338bf9575650a67bcb78ab1a33d7bad8
2016-01-19 14:21:25 -05:00
Joshua Colp 82938d0507 Merge "main/config: Clean config maps on shutdown." 2016-01-17 11:44:38 -06:00
Joshua Colp 34dbed9619 Merge "bridge_basic: don't play an attended transfer fail sound after target hangs up" 2016-01-16 08:29:58 -06:00
Joshua Colp a19a513714 Merge "bridge_basic: don't cache xferfailsound during an attended transfer" 2016-01-16 08:29:17 -06:00
Joshua Colp 644a9d0e99 Merge "taskprocessor.c: Simplify ast_taskprocessor_get() return code." 2016-01-16 08:28:17 -06:00
Corey Farrell 480ccfcc97 main/config: Clean config maps on shutdown.
ASTERISK-25700 #close

Change-Id: I096da84f9c62c6095f68bcf98eac4b7c7868e808
2016-01-15 20:00:08 -06:00
Kevin Harwell a5b38b604c bridge_basic: don't cache xferfailsound during an attended transfer
The xferfailsound was read from the channel at the beginning of the transfer,
and that value is "cached" for the duration of the transfer. Therefore, changing
the xferfailsound on the channel using the FEATURE() dialplan function does
nothing once the transfer is under way.

This makes it so the transfer code instead gets the xferfailsound configuration
options from the channel when it is actually going to be used.

This patch also fixes a potential memory leak of the props object as well as
making sure the condition variable gets initialized before being destroyed.

ASTERISK-25696 #close

Change-Id: Ic726b0f54ef588bd9c9c67f4b0e4d787934f85e4
2016-01-15 17:51:18 -06:00
Richard Mudgett d36c4d0b01 taskprocessor.c: Simplify ast_taskprocessor_get() return code.
Change-Id: Id5bd18ef1f60ef8be453e677e98478298358a9d1
2016-01-15 12:44:33 -06:00
Richard Mudgett 0a878020dc astmm.c: Add more stats to CLI "memory show" commands.
* Add freed regions totals to allocations and summary.

* Add totals for all allocations and not just the selected allocations.

Change-Id: I61d5a5112617b0733097f2545a3006a344b4032a
2016-01-14 19:57:29 -06:00
Kevin Harwell 84b30c5e18 bridge_basic: don't play an attended transfer fail sound after target hangs up
If the attended transfer destination answers (picks call up or goes to
voicemail) and then hangs up on the transferer then transferer hears the
fail sound.

This patch makes it so the fail sound is not played when the transfer
destination/target hangs up after answering.

ASTERISK-25697 #close

Change-Id: I97f142fe4fc2805d1a24b7c16143069dc03d9ded
2016-01-14 16:06:03 -06:00
Joshua Colp 022423b98b app: Queue hangup if channel is hung up during sub or macro execution.
This issue was exposed when executing a connected line subroutine.
When connected or redirected subroutines or macros are executed it is
expected that the underlying applications and logic invoked are fast
and do not consume frames. In practice this constraint is not enforced
and if not adhered to will cause channels to continue when they shouldn't.
This is because each caller of the connected or redirected logic does not
check whether the channel has been hung up on return. As a result the
the hung up channel continues.

This change makes it so when the API to execute a subroutine or
macro is invoked the channel is checked to determine if it has hung up.
If it has then a hangup is queued again so the caller will see it
and stop.

ASTERISK-25690 #close

Change-Id: I1f9a8ceb1487df0389f0d346ce0f6dcbcaf476ea
2016-01-13 11:01:18 -06:00
Joshua Colp 9e6ea2ba72 Merge topic 'update_taskprocessor_commands'
* changes:
  Sorcery: Create human friendly serializer names.
  Stasis: Create human friendly taskprocessor/serializer names.
  taskprocessor.c: New API for human friendly taskprocessor names.
  taskprocessor.c: Sort CLI "core show taskprocessors" output.
2016-01-12 13:25:49 -06:00
Joshua Colp 7e418b1ab5 Merge "taskprocessor.c: Fix CLI "core show taskprocessors" output format." 2016-01-12 13:18:58 -06:00
Joshua Colp e89d2691e9 Merge topic 'update_taskprocessor_commands'
* changes:
  taskprocessor.c: Fix CLI "core show taskprocessors" unref.
  taskprocessor.c: Add CLI "core ping taskprocessor" missing unlock.
2016-01-12 13:18:35 -06:00
Joshua Colp e57defa8dd Merge "ccss.c: Replace space in taskprocessor name." 2016-01-12 13:17:54 -06:00
Joshua Colp fb8bdcce01 Merge "pbx: Deadlock between contexts container and context_merge locks" 2016-01-11 17:37:19 -06:00
Joshua Colp 3a2d91c282 Merge "manager: Cleanup manager_channelvars during shutdown." 2016-01-11 14:35:14 -06:00
Kevin Harwell 7760029f19 pbx: Deadlock between contexts container and context_merge locks
Recent changes (ASTERISK-25394 commit 2bd27d1222)
introduced the possibility of a deadlock. Due to the mentioned modifications
ast_change_hints now needs to keep both merge/delete and state callbacks from
occurring while it executes. Unfortunately, sometimes ast_change_hints can be
called with the contexts container locked. When this happens it's possible for
another thread to grab the context_merge_lock before the thread calling into
ast_change_hints does and then try to obtain the contexts container lock. This
of course causes a deadlock between the two threads. The thread calling into
ast_change_hints waits for the other thread to release context_merge_lock and
the other thread is waiting on that one to release the contexts container lock.

Unfortunately, there is not a great way to fix this problem. When hints change,
the subsequent state callbacks cannot run at the same time as a merge/delete,
nor when the usual state callbacks do. This patch alleviates the problem by
having those particular callbacks (the ones run after a hint change) occur in a
serialized task. By moving the context_merge_lock to a task it can now safely be
attempted or held without a deadlock occurring.

ASTERISK-25640 #close
Reported by: Krzysztof Trempala

Change-Id: If2210ea241afd1585dc2594c16faff84579bf302
2016-01-11 13:46:25 -06:00