asterisk/asterisk.git
7 years agores/res_sorcery_astdb: Add a debugging message for when retrieval by ID fails
Matt Jordan [Wed, 8 Jul 2015 21:38:24 +0000 (16:38 -0500)]
res/res_sorcery_astdb: Add a debugging message for when retrieval by ID fails

Having a debug message tell us that we attempted to look up an item but
failed is nice in circumstances when it isn't clear if the wizard was
queried correctly or not.

Change-Id: I2600c3bbea87f252196358f62e73f4c7da8632f7

7 years agotests/test_devicestate: Add additional tests for the device state API
Matt Jordan [Sat, 27 Jun 2015 22:53:37 +0000 (17:53 -0500)]
tests/test_devicestate: Add additional tests for the device state API

This patch adds more tests that exercise the device state API. This includes:

* Tests that cover adding a device state provider, as well as deleting a
  device state provider. This also verifies that you cannot add an
  already added device state provider, and cannot delete an already
  deleted device state provider.
* A test that covers changing device state and receiving said updates
  from a device state subscriber. This also covers hitting both the
  device state cache as well as a custom device state provider.
* A test that covers converting device state to channel state and device
  state values to a string representation and back.
* A test that covers obtaining device state from an active channel and a
  channel driver that provides its own device state.

Change-Id: I2adca67ffb405cd8625a5d6df1e3f9b3d945c08d

7 years agoMerge "main/devicestate: Prevent duplicate registration of device state providers"
Matt Jordan [Sat, 11 Jul 2015 16:04:26 +0000 (11:04 -0500)]
Merge "main/devicestate: Prevent duplicate registration of device state providers"

7 years agoMerge "bucket: Add clone/staleness operations for ast_bucket/ast_bucket_file"
Matt Jordan [Sat, 11 Jul 2015 15:47:00 +0000 (10:47 -0500)]
Merge "bucket: Add clone/staleness operations for ast_bucket/ast_bucket_file"

7 years agoMerge "sorcery: Add support for object staleness"
Matt Jordan [Sat, 11 Jul 2015 15:46:52 +0000 (10:46 -0500)]
Merge "sorcery: Add support for object staleness"

7 years agomain/devicestate: Prevent duplicate registration of device state providers
Matt Jordan [Sat, 27 Jun 2015 22:51:43 +0000 (17:51 -0500)]
main/devicestate: Prevent duplicate registration of device state providers

Currently, the device state provider API will allow you to register a
device state provider with the same case insensitive name more than
once. This could cause strange issues, as the duplicate device state
providers will not be queried when a device's state has to be polled.
This patch updates the API such that a device state provider with the
same name as one that has already registered will be rejected.

Change-Id: I4a418a12280b7b6e4960bd44f302e27cd036ceb2

7 years agoARI: Added new functionality to get all module information.
Benjamin Ford [Fri, 26 Jun 2015 15:57:15 +0000 (10:57 -0500)]
ARI: Added new functionality to get all module information.

An http request can be sent to retrieve a list of all existing modules,
including the resource name, description, use count, status, and
support level.

The command "curl -v -u user:pass -X GET 'http://localhost:8088/ari/
asterisk/modules" (or something similar, depending on configuration)
can be run in the terminal to access this new functionality.

For more information, see:
https://wiki.asterisk.org/wiki.display/~bford/Asterisk+ARI+Resource

* Added new ARI functionality
* Information on modules can now be retrieved

Change-Id: I63cbbf0ec0c3544cc45ed2a588dceabe91c5e0b0

7 years agobridge_native_rtp.c: Don't start native RTP bridging after attended transfer.
Joshua Colp [Thu, 9 Jul 2015 14:18:11 +0000 (11:18 -0300)]
bridge_native_rtp.c: Don't start native RTP bridging after attended transfer.

The bridge_native_rtp module adds a frame hook to channels which are in
a native RTP bridge. This frame hook is used to intercept when a hold
or unhold frame traverses the bridge so native RTP can be stopped or
started as appropriate. This is expected but exposes a specific bug
when attended transfers are involved.

Upon completion of an attended transfer an unhold frame is queued up
to take one of the channels involved off hold. After this is done
the channel is moved between bridges.

When the frame hook is involved in this case for the unhold it
releases the channel lock and acquires the bridge lock. This
allows the bridge core to step in and move the channel
(potentially changing the bridging techology) from another thread.
Once completed the bridge lock is released by the bridge core.
The frame hook is then able to acquire the bridge lock and
wrongfully starts native RTP again, despite the channel no longer
being in the bridge or needing to start native RTP. In fact at
this point the frame hook is no longer attached to the channel.

This change makes it so the native RTP bridge data is available to
the frame hook when it is invoked. Whether the frame hook has
been detached or not is stored on the native RTP bridge data and
is checked by the frame hook before starting or stopping native
RTP bridging. If the frame hook has been detached it does nothing.

ASTERISK-25240 #close

Change-Id: I13a73186a05f4e5a764f81e5cd0ccec1ed1891d2

7 years agoMerge "DNS: Create a system-level DNS resolver"
Mark Michelson [Wed, 8 Jul 2015 14:00:41 +0000 (09:00 -0500)]
Merge "DNS: Create a system-level DNS resolver"

7 years agores_rtp_asterisk: Ensure DTLS timeout timer is -1 if DTLS is not used.
Joshua Colp [Wed, 8 Jul 2015 09:21:16 +0000 (06:21 -0300)]
res_rtp_asterisk: Ensure DTLS timeout timer is -1 if DTLS is not used.

This change fixes a bug where the DTLS timeout timer would be
initialized to 0 if DTLS was not used for an RTP session.

ASTERISK-25103

Change-Id: If8d26bb054f1d300838850da5b8db9044c2fe2ac

7 years agoDNS: Create a system-level DNS resolver
Ashley Sanders [Tue, 7 Jul 2015 20:03:34 +0000 (15:03 -0500)]
DNS: Create a system-level DNS resolver

Prior to this patch, the DNS core present in master had no default system-level
resolver implementation. Therefore, it was not possible for the DNS core to
perform resolutions unless the libunbound library was installed and the
res_resolver_unbound module was loaded.

This patch introduces a system-level DNS resolver implementation that will
register itself with the lowest consideration priority available (to ensure
that it is to be used only as a last resort). The resolver relies on low-level
DNS search functions to perform a rudimentary DNS search based on a provided
query and then supplies the search results to the DNS core.

ASTERISK-25146 #close
Reported By: Joshua Colp

Change-Id: I3b36ea17b889a98df4f8d80d50bb7ee175afa077

7 years agoMerge "res_pjsip_mwi.c: Use safer loop coding in mwi_subscription_mailboxes_str()."
Matt Jordan [Wed, 8 Jul 2015 01:38:40 +0000 (20:38 -0500)]
Merge "res_pjsip_mwi.c: Use safer loop coding in mwi_subscription_mailboxes_str()."

7 years agoMerge "res_pjsip_mwi.c: Fix MWI subscription memory corruption crash."
Matt Jordan [Wed, 8 Jul 2015 01:38:15 +0000 (20:38 -0500)]
Merge "res_pjsip_mwi.c: Fix MWI subscription memory corruption crash."

7 years agoMerge "PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error."
Joshua Colp [Tue, 7 Jul 2015 22:39:07 +0000 (17:39 -0500)]
Merge "PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error."

7 years agoMerge topic 'res_pjsip_mwi_cleanups'
Joshua Colp [Tue, 7 Jul 2015 22:24:43 +0000 (17:24 -0500)]
Merge topic 'res_pjsip_mwi_cleanups'

* changes:
  res_pjsip_mwi.c: Eliminate a simple RAII_VAR.
  res_pjsip_mwi.c: Fix mid-line log message line breaks.

7 years agoMerge "PJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer dereferences."
Joshua Colp [Tue, 7 Jul 2015 22:20:54 +0000 (17:20 -0500)]
Merge "PJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer dereferences."

7 years agoMerge "res_pjsip_t38.c: Fix always false if test."
Joshua Colp [Tue, 7 Jul 2015 22:12:10 +0000 (17:12 -0500)]
Merge "res_pjsip_t38.c: Fix always false if test."

7 years agoMerge "res/res_http_websocket: Don't send HTTP response fragmented."
Joshua Colp [Tue, 7 Jul 2015 22:01:18 +0000 (17:01 -0500)]
Merge "res/res_http_websocket: Don't send HTTP response fragmented."

7 years agores_rtp_asterisk: Prevent simultaneous access to DTLS SSL context.
Joshua Colp [Wed, 1 Jul 2015 12:55:47 +0000 (09:55 -0300)]
res_rtp_asterisk: Prevent simultaneous access to DTLS SSL context.

This change moves logic for setting up the DTLS SSL contexts to
when the SDP is done being processed instead of when ICE negotiation
completes. It also stops handshakes from being initiated when we
are acting as a server.

Manipulating the SSL context when ICE negotiation has completed
is problematic as the SSL context is not protected and if acting
as a client the remote side may have started DTLS negotiation
already.

The retransmission timeout timer code has also been split up
and simplified some. Both RTP and RTCP now have their own timers
and the points at which the timer is stopped and started is now
more specific. When a packet is sent the timer is started. When
a response is received but before it is processed the timer is
stopped. This provides a guarantee that the timeout is not
occurring while the response is processed.

ASTERISK-22805 #close
ASTERISK-24550 #close
ASTERISK-24651 #close
ASTERISK-24832 #close
ASTERISK-25103 #close
ASTERISK-25127 #close

Change-Id: Ib75ea2546f29d6efc3d2d37c58df6986c7bd9b91

7 years agores_pjsip_mwi.c: Fix MWI subscription memory corruption crash.
Richard Mudgett [Fri, 26 Jun 2015 23:48:35 +0000 (18:48 -0500)]
res_pjsip_mwi.c: Fix MWI subscription memory corruption crash.

MWI subscriptions can crash or corrupt memory when using the subscription
datastore to access the MWI subscription object because the datastore is
not holding a reference to the object.

* Give the subscription datastore a ref to the MWI subscription object.
It is unfortunate that the ref causes a circular ref chain that must be
explicitly broken to allow the memory to get released.  The loop is broken
when the subscription is shutdown and if the subscription setup fails.

ASTERISK-25168 #close
Reported by: Carl Fortin

Change-Id: Ice4fa823f138ff10a6c74d280699c41a82836d4f

7 years agoPJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error.
Richard Mudgett [Thu, 2 Jul 2015 19:51:29 +0000 (14:51 -0500)]
PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error.

When res_pjsip body generator modules were generating XML or XPIDF
response bodies, there was a chance that the generated body would be the
exact size of the supplied buffer.  Adding the nul string terminator would
then write beyond the end of the buffer and potentially corrupt memory.

* Fix MALLOC_DEBUG high fence violations caused by adding a nul string
terminator on the end of a buffer for XML or XPIDF response bodies.

* Made calls to pj_xml_print() safer if the XML prolog is requested.  Due
to a bug in pjproject, the return value could be -1 _or_
AST_PJSIP_XML_PROLOG_LEN if the supplied buffer is not large enough.

* Updated the doxygen comment of AST_PJSIP_XML_PROLOG_LEN to describe the
return value of pj_xml_print() when the supplied buffer is not large
enough.

ASTERISK-25168
Reported by: Carl Fortin

Change-Id: Id70e1d373a6a2b2bd9e678b5cbc5e55b308981de

7 years agoPJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer dereferences.
Richard Mudgett [Fri, 26 Jun 2015 15:36:19 +0000 (10:36 -0500)]
PJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer dereferences.

When a caller calls a FAX number and then hangs up right after the call is
answered then the T.38 re-INVITE automatic reject timer may still be
running after the channel goes away.

* Added session NULL channel checks on the code paths that get executed by
t38_automatic_reject() to prevent a crash when the T.38 re-INVITE
automatic reject timer expires.

ASTERISK-25168
Reported by: Carl Fortin

Change-Id: I07b6cd23815aedce5044f8f32543779e2f7a2403

7 years agores_pjsip_mwi.c: Use safer loop coding in mwi_subscription_mailboxes_str().
Richard Mudgett [Tue, 30 Jun 2015 16:17:25 +0000 (11:17 -0500)]
res_pjsip_mwi.c: Use safer loop coding in mwi_subscription_mailboxes_str().

Change-Id: I6f39d809a6d1b47b35bb32b298f5a12f35d6f907

7 years agores_pjsip_mwi.c: Eliminate a simple RAII_VAR.
Richard Mudgett [Tue, 30 Jun 2015 16:14:57 +0000 (11:14 -0500)]
res_pjsip_mwi.c: Eliminate a simple RAII_VAR.

Change-Id: Ib1843f81e826a6c760c424c88eb70c350d9d61da

7 years agores_pjsip_mwi.c: Fix mid-line log message line breaks.
Richard Mudgett [Tue, 30 Jun 2015 16:11:19 +0000 (11:11 -0500)]
res_pjsip_mwi.c: Fix mid-line log message line breaks.

* Add create_mwi_subscriptions_for_endpoint() doxygen comment.

Change-Id: I3c3f921f4ec749fb65b62d2f6fa0d4d1888b94e2

7 years agores_pjsip_t38.c: Fix always false if test.
Richard Mudgett [Fri, 26 Jun 2015 21:10:26 +0000 (16:10 -0500)]
res_pjsip_t38.c: Fix always false if test.

Calling t38_change_state() sets the t38 state so it makes little sense to
then check the state right after the call for something else.

* Made the code in t38_interpret_parameters() reject or exit T.38 mode as
intended but not implemented.

Change-Id: Ib281263a6ed44da9448132c4e6df1e183b8a3df2

7 years agoMerge "res_pjsip: Failover when server is not available"
Mark Michelson [Mon, 6 Jul 2015 16:52:47 +0000 (11:52 -0500)]
Merge "res_pjsip: Failover when server is not available"

7 years agores_pjsip: Failover when server is not available
Kevin Harwell [Tue, 30 Jun 2015 20:19:31 +0000 (15:19 -0500)]
res_pjsip: Failover when server is not available

Previously Asterisk did not properly failover to the next resolved DNS
address when a endpoint could not be reached. With this patch, and while
using res_pjsip, SIP requests (both in/out of dialog) now attempt to use
the next address in the list of resolved addresses until a proper response
is received or no more addresses are left.

ASTERISK-25076 #close
Reported by: Joshua Colp

Change-Id: Ief14f4ebd82474881f72f4538f4577f30af2a764

7 years agores_sorcery_memory_cache: Execute stale unit test last.
Joshua Colp [Mon, 6 Jul 2015 14:24:43 +0000 (11:24 -0300)]
res_sorcery_memory_cache: Execute stale unit test last.

In Jenkins there is currently a sporadic test failure of a
variable number of sorcery memory cache unit tests. I have not
been able to reproduce this on the build agents themselves or
on my development machine.

My working theory is that the stale unit test is causing a
sorcery instance to persist longer than expected, causing subsequent
tests to fail when setting up and initializing the next
sorcery instance.

To see if this is the case this change moves the stale unit test
to execute last so no subsequent unit tests can have issues
initializing their sorcery instance.

Change-Id: Ifd6550a949613be774b75fa5db12c02110f82c4a

7 years agobucket: Add clone/staleness operations for ast_bucket/ast_bucket_file
Matt Jordan [Sat, 20 Jun 2015 18:54:17 +0000 (13:54 -0500)]
bucket: Add clone/staleness operations for ast_bucket/ast_bucket_file

This patch enhances the bucket API in two ways.

First, since ast_bucket and ast_bucket_file instances are immutable, a 'clone'
operation has been added that provides a 'clone' of an existing
ast_bucket/ast_bucket_file object. Note that this makes use of the
ast_sorcery_copy operation, along with the copy callback handler on the
"bucket" and "file" object types for the bucket sorcery instance.

Second, there is a need for the bucket API to ask a wizard if an object
is stale. This is particularly useful with the upcoming media cache
enhancements, where we want to ask the backing data storage if the
object we are currently operating on has known updates. This patch adds
API calls for ast_bucket and ast_bucket_file objects, which callback
into their respective sorcery wizards via the sorcery API.

Unit tests have also been added to cover the respective
ast_bucket/ast_bucket_file clone and staleness operations.

Change-Id: Ib0240ba915ece313f1678a085a716021d75d6b4a

7 years agosorcery: Add support for object staleness
Matt Jordan [Sat, 4 Jul 2015 15:03:06 +0000 (10:03 -0500)]
sorcery: Add support for object staleness

This patch enhances the sorcery API to allow for sorcery wizards to
determine if an object is stale. This includes the following:

* Sorcery objects now have a timestamp that is set on creation. Since
  sorcery objects are immutable, this can be used by sorcery wizards to
  determine if an object is stale.

* A new API call has been added, ast_sorcery_is_stale. This API call
  queries the wizards associated with the object, calling a new callback
  function 'is_stale'. Note that if a wizard does not support the new
  callback, objects are always assumed to not be stale.

* Unit tests have been added that cover the new API call.

Change-Id: Ica93c6a4e8a06c0376ea43e00cf702920b806064

7 years agoMerge "chan_sip: Fix early call pickup channel leak."
Joshua Colp [Sun, 5 Jul 2015 00:08:59 +0000 (19:08 -0500)]
Merge "chan_sip: Fix early call pickup channel leak."

7 years agores/res_http_websocket: Don't send HTTP response fragmented.
Joshua Colp [Sat, 4 Jul 2015 23:22:01 +0000 (20:22 -0300)]
res/res_http_websocket: Don't send HTTP response fragmented.

This change makes it so that when accepting a WebSocket
connection the HTTP response is sent as one packet instead of
fragmented. Browsers don't like it when you send it fragmented.

ASTERISK-25103

Change-Id: I9b82c4ec2949b0bce692ad0bf6f7cea9709e7f69

7 years agoMakefile: Remove coverage files on 'make clean'
Matt Jordan [Sat, 27 Jun 2015 23:47:19 +0000 (18:47 -0500)]
Makefile: Remove coverage files on 'make clean'

This patch updates a variety of Makefiles in Asterisk's build system to
remove .gcda and .gcno files when 'make clean' is executed. These files
are generated when '--enable-coverage' is passed to the Asterisk
configure script.

Change-Id: Ib70b41eea2ee2908885bff02e80faf9f40c84602

7 years agoMerge "chan_vpb.cc: Fix compiler warning Jenkins found."
Joshua Colp [Thu, 2 Jul 2015 14:47:58 +0000 (09:47 -0500)]
Merge "chan_vpb.cc: Fix compiler warning Jenkins found."

7 years agoMerge "dns: Fix crash when invoking cancel in DNS recurring unit test."
Matt Jordan [Thu, 2 Jul 2015 14:43:09 +0000 (09:43 -0500)]
Merge "dns: Fix crash when invoking cancel in DNS recurring unit test."

7 years agochan_sip: Fix early call pickup channel leak.
Walter Doekes [Thu, 2 Jul 2015 14:08:12 +0000 (16:08 +0200)]
chan_sip: Fix early call pickup channel leak.

When handle_invite_replaces() was called, and either ast_bridge_impart()
failed or there was no bridge (because the channel we're picking up was
still ringing), chan_sip would leak a channel.

Thanks Matt and Corey for checking the bridge path.

ASTERISK-25226 #close

Change-Id: Ie736bb182170a73eef5bcef0ab0376f645c260c8

7 years agoMerge "sorcery/realtime: Add a bit of debug and warning messages for bad configs"
Matt Jordan [Thu, 2 Jul 2015 13:02:08 +0000 (08:02 -0500)]
Merge "sorcery/realtime: Add a bit of debug and warning messages for bad configs"

7 years agoMerge "res_timing: Don't close FD 0 when out of open files."
Joshua Colp [Thu, 2 Jul 2015 12:53:47 +0000 (07:53 -0500)]
Merge "res_timing: Don't close FD 0 when out of open files."

7 years agoMerge "rtp_engine: Skip useless self-assignment in ast_rtp_engine_unload_format."
Joshua Colp [Thu, 2 Jul 2015 12:52:41 +0000 (07:52 -0500)]
Merge "rtp_engine: Skip useless self-assignment in ast_rtp_engine_unload_format."

7 years agoMerge "astfd: Fix buffer overflow in DEBUG_FD_LEAKS."
Joshua Colp [Thu, 2 Jul 2015 12:51:54 +0000 (07:51 -0500)]
Merge "astfd: Fix buffer overflow in DEBUG_FD_LEAKS."

7 years agoMerge "chan_mgcp: Don't call close on fd -1."
Joshua Colp [Thu, 2 Jul 2015 12:50:54 +0000 (07:50 -0500)]
Merge "chan_mgcp: Don't call close on fd -1."

7 years agosorcery/realtime: Add a bit of debug and warning messages for bad configs
Matt Jordan [Wed, 1 Jul 2015 21:04:50 +0000 (16:04 -0500)]
sorcery/realtime: Add a bit of debug and warning messages for bad configs

When a mapping does not exist between a sorcery.conf defined object and
a realtime mapping in extconf, currently, the user will receive a slew
of ERROR messages that don't really tell what is happening. Some ERROR
messages may even be misleading, as they occur after the sorcery API has
already given up on the attempt to load and create the sorcery object.

This patch adds a bit of debug and a useful WARNING message for when a
wizard's open callback fails for a particular object type. In the bad
configurations that resulted in this patch, this provided a 'root cause'
WARNING message that pointed in the right direction of the configuration
problem.

Change-Id: I1cc7344f2b015b8b9c85a7e6ebc8cb4753a8f80b

7 years agodns: Fix crash when invoking cancel in DNS recurring unit test.
Joshua Colp [Thu, 2 Jul 2015 11:54:51 +0000 (08:54 -0300)]
dns: Fix crash when invoking cancel in DNS recurring unit test.

The recurring unit test expects the user data on a DNS query
created as a result of a recurring DNS query to be the recurring
structure itself. This is true, mostly. When invoking the user
provided callback this user data is changed to the user provided
data. This presents a race condition where the data may or may
not point to the recurring data.

This change simplifies the callback of the user provided callback
by creating a new query and populating it with the expected values.
This leaves the recurring DNS query alone and fixes the race
condition. This is more in line with how the API should be used
overall.

ASTERISK-25222 #close

Change-Id: I10fb6deec025dff097157e7ec17e6e4921778478

7 years agochan_mgcp: Don't call close on fd -1.
Walter Doekes [Thu, 2 Jul 2015 11:19:34 +0000 (13:19 +0200)]
chan_mgcp: Don't call close on fd -1.

ASTERISK-25220 #close

Change-Id: Ic48f3a82f51ada87f2fb0e016c9efe0ad56f1ee3

7 years agortp_engine: Skip useless self-assignment in ast_rtp_engine_unload_format.
Walter Doekes [Thu, 2 Jul 2015 11:10:59 +0000 (13:10 +0200)]
rtp_engine: Skip useless self-assignment in ast_rtp_engine_unload_format.

When running valgrind on Asterisk, it complained about:

    ==32423== Source and destination overlap in memcpy(0x85a920, 0x85a920, 304)
    ==32423==    at 0x4C2F71C: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/...)
    ==32423==    by 0x55BA91: ast_rtp_engine_unload_format (rtp_engine.c:2292)
    ==32423==    by 0x4EEFB7: ast_format_attr_unreg_interface (format.c:1437)

The code in question is a struct assignment, which may be performed by
memcpy as a compiler optimization. It is changed to only copy the struct
contents if source and destination are different.

ASTERISK-25219 #close

Change-Id: I6d3546c326b03378ca8e9b8cefd41c16e0088b9a

7 years agoastfd: Fix buffer overflow in DEBUG_FD_LEAKS.
Walter Doekes [Thu, 2 Jul 2015 10:16:26 +0000 (12:16 +0200)]
astfd: Fix buffer overflow in DEBUG_FD_LEAKS.

If DEBUG_FD_LEAKS was used and more file descriptors than the default of
1024 were available, some DEBUG_FD_LEAKS-patched functions would
overwrite memory past the fixed-size (1024) fdleaks buffer.

This change:
- adds bounds checks to __ast_fdleak_fopen and __ast_fdleak_pipe
- consistently uses ARRAY_LEN() instead of sizeof() or 1023 or 1024
- stores pointers to constants instead of copying the contents
- reorders the fdleaks struct for possibly tighter packing
- adds a tiny bit of documentation

ASTERISK-25212 #close

Change-Id: Iacb69e7701c0f0a113786bd946cea5b6335a85e5

7 years agores_timing: Don't close FD 0 when out of open files.
Walter Doekes [Thu, 2 Jul 2015 09:57:44 +0000 (11:57 +0200)]
res_timing: Don't close FD 0 when out of open files.

This fixes so a failure to get a timer file descriptor does not cascade
to closing FD 0.

On error, both res_timing_kqueue and res_timing_timerfd would call the
destructor before setting the file handle. The file handle had been
initialized to 0, causing FD 0 to be closed. This in turn, resulted in
floods of "CLI>" messages and an unusable terminal.

ASTERISK-19277 #close
Reported by: Barry Chern

For the master branch, this was already fixed. This patch only ensures
that we do not attempt to close a negative file descriptor.

Change-Id: I147d7e33726c6e5a2751928d56561494f5800350

7 years agochan_vpb.cc: Fix compiler warning Jenkins found.
Richard Mudgett [Wed, 1 Jul 2015 22:25:31 +0000 (17:25 -0500)]
chan_vpb.cc: Fix compiler warning Jenkins found.

Change-Id: I0ec7fd10d56d90d5a60b12b5a7d6807f265ac5e0

7 years agoChannel alert pipe: improve diagnostic error return
Scott Griepentrog [Wed, 1 Jul 2015 18:34:46 +0000 (13:34 -0500)]
Channel alert pipe: improve diagnostic error return

When a frame is queued on a channel, any failure in
ast_channel_alert_write is logged along with errno.

This change improves the diagnostic message through
aligning the errno value with actual failure cases.

ASTERISK-25224
Reported by: Andrey Biglari

Change-Id: I1bf7b3337ad392789a9f02c650589cd065d20b5b

7 years agoMerge "res_sorcery_realtime: Fix leak of sorcery object type."
Joshua Colp [Tue, 30 Jun 2015 12:32:22 +0000 (07:32 -0500)]
Merge "res_sorcery_realtime: Fix leak of sorcery object type."

7 years agoMerge "channel: Remove ignore of answer on non-outgoing channels."
Matt Jordan [Tue, 30 Jun 2015 12:07:09 +0000 (07:07 -0500)]
Merge "channel: Remove ignore of answer on non-outgoing channels."

7 years agores_sorcery_realtime: Fix leak of sorcery object type.
Mark Michelson [Mon, 29 Jun 2015 17:45:02 +0000 (12:45 -0500)]
res_sorcery_realtime: Fix leak of sorcery object type.

This prevents a leak of a sorcery object type when realtime sorcery
objects are retrieved by fields or when multiple objects are retrieved.

The extent of this leak is that sorcery object types would be leaked.
These are allocated whenever an object type is registered with sorcery,
meaning that on module shutdown, these objects would be leaked. This
could be problematic if many reloads were performed, but it is not as
severe as if every sorcery object retrieved from realtime were being
leaked.

ASTERISK-25165 #close
Reported by Corey Farrell

Change-Id: I625c3b50eee4576670b7eeb013c81ad043b4b4f8

7 years agoMerge "res_pjsip_nat: Adjust when contact should be rewritten."
Matt Jordan [Mon, 29 Jun 2015 16:56:46 +0000 (11:56 -0500)]
Merge "res_pjsip_nat: Adjust when contact should be rewritten."

7 years agoMerge "res/res_corosync: Always decline module load, instead of failing"
Matt Jordan [Mon, 29 Jun 2015 15:39:00 +0000 (10:39 -0500)]
Merge "res/res_corosync: Always decline module load, instead of failing"

7 years agores/res_corosync: Always decline module load, instead of failing
Matt Jordan [Sat, 27 Jun 2015 03:02:42 +0000 (22:02 -0500)]
res/res_corosync: Always decline module load, instead of failing

Returns a 'failure' from the module load routine indicates to Asterisk
that it should abort loading completely. This is rarely - in fact,
really, never - a good option. Aborting load of Asterisk from a dynamic
module implies that the core, and the rest of the dynamic modules, don't
matter: we should abandon all processing.

res_corosync is really not that important.

This patch updates the module such that, if it fails to load, it
politely declines (emitting ERROR messages along the way), and allows
Asterisk to continue to function.

Note that this issue was keeping Asterisk unit tests from running on
certain build agents.

Change-Id: I252249e81fb9b1a68e0da873f54f47e21d648f0f

7 years agomain/pbx: Resolve case sensitivity regression in PBX hints
Matt Jordan [Sat, 27 Jun 2015 01:38:58 +0000 (20:38 -0500)]
main/pbx: Resolve case sensitivity regression in PBX hints

When 8297136f was merged for ASTERISK-25040, a regression was introduced
surrounding the case sensitivity of device names within hints.
Previously, device names - such as 'sip/foo' - were compared in a case
insensitive fashion. Thus, 'sip/foo' was equivalent to 'SIP/foo'. After
that patch, only the case sensitive name would match, i.e., 'SIP/foo'.
As a result, some dialplan hints stopped working.

This patch re-introduces case insensitive matching for device names in
hints.

ASTERISK-25040

ASTERISK-25202 #close

Change-Id: If5046a7d14097e1e3c12b63092b9584bb1e9cb4c
(cherry picked from commit 96bbcf495a1da9e607d9b04a44b5c4f49e83cc03)

7 years agores_pjsip_nat: Adjust when contact should be rewritten.
Mark Michelson [Fri, 26 Jun 2015 21:12:33 +0000 (16:12 -0500)]
res_pjsip_nat: Adjust when contact should be rewritten.

A previous change made the contact only get rewritten if the dialog's
route set was not marked frozen. Unfortunately, while the intent of this
is correct, the dialog's route set actually gets marked as frozen
earlier than expected, especially for UAS dialogs.

Instead, the idea is that the contact needs to not be rewritten if there
is a pre-existing route set on the dialog. This is now accomplished by
checking the dialog's route set list instead of checking if the route
set is frozen.

Doing this causes some broken tests to begin passing again.

ASTERISK-25196
Reported by Mark Michelson

Change-Id: I525ab251fd40a52ede327a52a2810a56deb0529e

7 years agores_pjsip_outbound_registration.c: Add a serializer shutdown group.
Richard Mudgett [Fri, 19 Jun 2015 23:27:24 +0000 (18:27 -0500)]
res_pjsip_outbound_registration.c: Add a serializer shutdown group.

The client_state objects contain a serializer used to send the outbound
REGISTER messages.  Once all those message transactions are complete then
the module can shutdown.

ASTERISK-24907 #close
Reported by: Kevin Harwell

Change-Id: Ibb2fe558f98190f2a06da830e0fadfa25516f547

7 years agoMerge "threadpool, res_pjsip: Add serializer group shutdown API calls."
Matt Jordan [Fri, 26 Jun 2015 18:36:17 +0000 (13:36 -0500)]
Merge "threadpool, res_pjsip: Add serializer group shutdown API calls."

7 years agoMerge "res_pjsip_outbound_registration.c: Fix handle_client_state_destruction() refs"
Matt Jordan [Fri, 26 Jun 2015 18:34:53 +0000 (13:34 -0500)]
Merge "res_pjsip_outbound_registration.c: Fix handle_client_state_destruction() refs"

7 years agoMerge "res_pjsip_outbound_registration.c: Use ast_sorcery_object_unregister() API"
Matt Jordan [Fri, 26 Jun 2015 18:34:47 +0000 (13:34 -0500)]
Merge "res_pjsip_outbound_registration.c: Use ast_sorcery_object_unregister() API"

7 years agoMerge "res_pjsip_refer: Prevent sending duplicate headers."
Matt Jordan [Fri, 26 Jun 2015 16:26:42 +0000 (11:26 -0500)]
Merge "res_pjsip_refer: Prevent sending duplicate headers."

7 years agoMerge "sorcery: Add ast_sorcery_object_unregister() API call."
Matt Jordan [Fri, 26 Jun 2015 16:25:58 +0000 (11:25 -0500)]
Merge "sorcery: Add ast_sorcery_object_unregister() API call."

7 years agoMerge "res_pjsip_outbound_registration.c: Reorder load_module() and unload_module()."
Matt Jordan [Fri, 26 Jun 2015 16:25:49 +0000 (11:25 -0500)]
Merge "res_pjsip_outbound_registration.c: Reorder load_module() and unload_module()."

7 years agoMerge "AMI: Add Linkedid to the standard channel snapshot AMI event headers."
Matt Jordan [Fri, 26 Jun 2015 16:00:29 +0000 (11:00 -0500)]
Merge "AMI: Add Linkedid to the standard channel snapshot AMI event headers."

7 years agoMerge "res_pjsip_nat: Rewrite route set when required."
Matt Jordan [Fri, 26 Jun 2015 15:59:35 +0000 (10:59 -0500)]
Merge "res_pjsip_nat: Rewrite route set when required."

7 years agores_pjsip_refer: Prevent sending duplicate headers.
Mark Michelson [Fri, 26 Jun 2015 15:41:05 +0000 (10:41 -0500)]
res_pjsip_refer: Prevent sending duplicate headers.

res_pjsip_refer will attempt to add Referred-By or Replaces headers to
outbound INVITEs at times. If the INVITE gets challenged for
authentication, then we will resend the INVITE. Prior to this patch, the
Referred-By or Replaces header would be re-added to the outbound INVITE,
resulting in duplicated headers.

ASTERISK-25204 #close
Reported by Mark Michelson

Change-Id: I59fb5c08b4d253c0dba9ee3d3950b5025358222d

7 years agoAMI: Add Linkedid to the standard channel snapshot AMI event headers.
Richard Mudgett [Tue, 23 Jun 2015 19:34:29 +0000 (14:34 -0500)]
AMI: Add Linkedid to the standard channel snapshot AMI event headers.

ASTERISK-25189 #close
Reported by: John Hardin

Change-Id: I2b1778c3fdc1dca0ed55db4e3a639eddfb16c2ac

7 years agores_pjsip_nat: Rewrite route set when required.
Mark Michelson [Tue, 23 Jun 2015 22:43:31 +0000 (17:43 -0500)]
res_pjsip_nat: Rewrite route set when required.

When performing some provider testing, the rewrite_contact option was
interfering with proper construction of a route set when sending an ACK
after receiving a 200 OK response to an INVITE.

The initial INVITE was sent to address sip:foo. The 200 OK had a Contact
header with URI sip:bar. In addition, the 200 OK had Record-Route
headers for sip:baz and sip:foo, in that order. Since the Record-Route
headers had the lr parameter, the result should have been:

* Set R-URI of the ACK to sip:bar.
* Add Route headers for sip:foo and sip:baz, in that order.

However, the rewrite_contact option resulted in our rewriting the
Contact header on the 200 OK to sip:foo. The result was:

* R-URI remained sip:foo.
* We added Route headers for sip:foo and sip:baz, in that order.

The result was that sip:bar was not indicated in the ACK at all, so the
far end never received our ACK. The call eventually dropped.

The intention of rewrite_contact is to rewrite the most immediate
destination of our SIP request to be the same address on which we
received a request or response. In the case of processing a SIP response
with Record-Route headers, this means that instead of rewriting the
Contact header, we should instead rewrite the bottom-most Record-Route
header. In the case of processing a SIP request with Record-Route
headers, this means we rewrite the top-most Record-route header.
Like when we rewrite the Contact header, we also ensure to update
the dialog's route set if it exists.

ASTERISK-25196 #close
Reported by Mark Michelson

Change-Id: I9702157c3603a2d0bd8a8215ac27564d366b666f

7 years agothreadpool, res_pjsip: Add serializer group shutdown API calls.
Richard Mudgett [Fri, 19 Jun 2015 21:16:17 +0000 (16:16 -0500)]
threadpool, res_pjsip: Add serializer group shutdown API calls.

A module trying to unload needs to wait for all serializers it creates and
uses to complete processing before unloading.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: I8c80b90f2f82754e8dbb02ddf3c9121e5e966059

7 years agores_pjsip_outbound_registration.c: Fix handle_client_state_destruction() refs
Richard Mudgett [Tue, 16 Jun 2015 20:06:22 +0000 (15:06 -0500)]
res_pjsip_outbound_registration.c: Fix handle_client_state_destruction() refs

* handle_client_state_destruction() must always be passed a ref to
client_state because it will always unref client_state.
handle_registration_response() was not passing a client_state ref.

* Made the final un-REGISTER message get sent normally using the pjproject
register control structure in handle_client_state_destruction().  The
previous code attempted to short circuit the response handling for the
module to unload.  That doesn't work for a couple reasons.  One,
pjsip_regc_send() may call the registered callback before it returns and
unbalance the client_state ref count.  Two, the registered callback
handles any authentication for the un-REGISTER message.

* Made the distinction between internal registration state and external
registration status with sip_outbound_registration_status_str().  This is
necessary to avoid altering documented AMI messages with internal
changes.

* Removed references to client_state->client outside of the serializer
thread.  When handle_client_state_destruction() destroys the pjproject
register control structure that memory is freed and cannot be referenced
anymore.  These accesses were to provide information for debug and
off-nominal warning messages.

* In sip_outbound_registration_timer_cb() you should not access entry->id
after unrefing client_state because the passed in entry is normally
pointing to the timer entry in the client_state object.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: Ia7b446d8644b6b4550ef5bea49527671de65183f

7 years agores_pjsip_outbound_registration.c: Use ast_sorcery_object_unregister() API
Richard Mudgett [Mon, 15 Jun 2015 20:28:41 +0000 (15:28 -0500)]
res_pjsip_outbound_registration.c: Use ast_sorcery_object_unregister() API

The sorcery pjsip 'registration' config object needs to be destroyed on
module unload.  Otherwise, a reload of res_pjsip could try to use
callbacks for a previously unloaded instance of the module provided by
ast_sorcery_object_register() or one of the variants.  Also, if
res_pjsip_outbound_registration were subsequently reloaded, the sorcery
config field objects would be registered in sorcery twice.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: I304fad13dece2604af48353f6c6d9d5c7b064697

7 years agosorcery: Add ast_sorcery_object_unregister() API call.
Richard Mudgett [Mon, 15 Jun 2015 20:28:00 +0000 (15:28 -0500)]
sorcery: Add ast_sorcery_object_unregister() API call.

Find and unlink the specified sorcery object type to complement
ast_sorcery_object_register().  Without this function you cannot
completely unload individual modules that use sorcery for configuration.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: I1c04634fe9a90921bf676725c7d6bb2aeaab1c88

7 years agores_pjsip_outbound_registration.c: Reorder load_module() and unload_module().
Richard Mudgett [Mon, 15 Jun 2015 18:38:58 +0000 (13:38 -0500)]
res_pjsip_outbound_registration.c: Reorder load_module() and unload_module().

It is best if the loading code creates and initializes the module's
infrastructure before letting the system know of its existence.  The
unloading code needs to reverse the actions of the loading code and in the
reverse order.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: I5d151383e9787b5b60aa5e1627b10f040acdded4

7 years agochannel: Remove ignore of answer on non-outgoing channels.
Joshua Colp [Thu, 25 Jun 2015 11:42:46 +0000 (08:42 -0300)]
channel: Remove ignore of answer on non-outgoing channels.

Due to the way that channels can now be moved around inside of
Asterisk it is possible for the outgoing flag of a channel to get
cleared before it has been answered. This results in the bridge
not receiving notification that the outgoing leg has been answered.

This most easily exhibits itself with DTMF based blond transfers.
Since the answer of the outgoing leg is ignored the other party
continues to receive both a locally generated ringing and the
media stream of the outgoing leg upon its answer. This results
in no media being heard.

This change removes the ignore of the answer and allows it
to pass through.

ASTERISK-25171 #close

Change-Id: I82aedcec4f89f34a2e5472086dfc9a6c775bca8e

7 years agoMerge "res_pjsip_mwi: Set up unsolicited MWI upon registration."
Mark Michelson [Thu, 25 Jun 2015 14:51:48 +0000 (09:51 -0500)]
Merge "res_pjsip_mwi: Set up unsolicited MWI upon registration."

7 years agoMerge "test.c: Add unit test registration checks for summary and description."
Joshua Colp [Thu, 25 Jun 2015 09:52:02 +0000 (04:52 -0500)]
Merge "test.c: Add unit test registration checks for summary and description."

7 years agoMerge "Unit tests: Fix more unit test description strings."
Joshua Colp [Thu, 25 Jun 2015 09:50:54 +0000 (04:50 -0500)]
Merge "Unit tests: Fix more unit test description strings."

7 years agoMerge "Unit tests: Fix unit test description strings."
Joshua Colp [Thu, 25 Jun 2015 09:48:46 +0000 (04:48 -0500)]
Merge "Unit tests: Fix unit test description strings."

7 years agoMerge "DNS unit tests: Fix extraneous description string commas."
Joshua Colp [Thu, 25 Jun 2015 09:48:22 +0000 (04:48 -0500)]
Merge "DNS unit tests: Fix extraneous description string commas."

7 years agotest.c: Add unit test registration checks for summary and description.
Richard Mudgett [Wed, 24 Jun 2015 19:30:15 +0000 (14:30 -0500)]
test.c: Add unit test registration checks for summary and description.

Added checks when a unit test is registered to see that the summary and
description strings do not end with a new-line '\n' for consistency.

The check generates a warning message and will cause the
/main/test/registrations unit test to fail.

* Updated struct ast_test_info member doxygen comments.

Change-Id: I295909b6bc013ed9b6882e85c05287082497534d

7 years agoUnit tests: Fix more unit test description strings.
Richard Mudgett [Wed, 24 Jun 2015 21:39:38 +0000 (16:39 -0500)]
Unit tests: Fix more unit test description strings.

Analyzing the code shows that the unit test summary and description
strings should not end with a new-line character.  Where these strings are
used in the code a new-line is provided for output.

Change-Id: I2f4f37988ec363c8d1c5077a2fc8ca841c5cd30c

7 years agoUnit tests: Fix unit test description strings.
Richard Mudgett [Wed, 24 Jun 2015 19:39:01 +0000 (14:39 -0500)]
Unit tests: Fix unit test description strings.

Analyzing the code shows that the unit test summary and description
strings should not end with a new-line character.  Where these strings are
used in the code a new-line is provided for output.

Change-Id: I129284f5e7ca93d82532334076da4c462d3d9fba

7 years agoDNS unit tests: Fix extraneous description string commas.
Richard Mudgett [Wed, 24 Jun 2015 21:37:04 +0000 (16:37 -0500)]
DNS unit tests: Fix extraneous description string commas.

Change-Id: Icf5f13c8e1c2c92a4473bb573ed2dd856ce1b64e

7 years agoapp_dial: Hold reference to calling channel formats when dialing outbound.
Joshua Colp [Tue, 23 Jun 2015 16:21:41 +0000 (13:21 -0300)]
app_dial: Hold reference to calling channel formats when dialing outbound.

Currently when requesting a channel the native formats of the
calling channel are provided to the core for usage when dialing
the outbound channel. This occurs without holding the channel lock
or keeping a reference to the formats. This is problematic as
the channel driver may end up changing the formats during this time.
In the case of chan_sip this happens when an SDP negotiation
completes.

This change makes it so app_dial keeps a reference to the native
formats of the calling channel which guarantees that they will
remain valid for the period of time needed.

ASTERISK-25172 #close

Change-Id: I2f0a67bd0d5d14c3bdbaae552b4b1613a283f0db

7 years agores_pjsip_outbound_registration.c: Add missing line endings to CLI commands
Richard Mudgett [Wed, 17 Jun 2015 21:23:52 +0000 (16:23 -0500)]
res_pjsip_outbound_registration.c: Add missing line endings to CLI commands

Change-Id: I39ae612746d892d2dbe86f3ff2d7027fa1da57f7

7 years agores_pjsip_outbound_registration.c: Eliminate simple RAII_VAR() usage.
Richard Mudgett [Fri, 12 Jun 2015 19:29:06 +0000 (14:29 -0500)]
res_pjsip_outbound_registration.c: Eliminate simple RAII_VAR() usage.

Change-Id: I399cb9d61bbba706b48c98e0bf75e98984cd9a9e

7 years agores_pjsip_outbound_registration.c: Misc code cleanups.
Richard Mudgett [Fri, 12 Jun 2015 18:33:38 +0000 (13:33 -0500)]
res_pjsip_outbound_registration.c: Misc code cleanups.

* Break some long lines.

* Fix doxygen comment.

Change-Id: I8f12ba6822f84d5e7bb575280270cd7e2fefb305

7 years agoMerge "res_pjsip_outbound_registration.c: Fix whitespace conflict potential."
Joshua Colp [Tue, 23 Jun 2015 17:54:03 +0000 (12:54 -0500)]
Merge "res_pjsip_outbound_registration.c: Fix whitespace conflict potential."

7 years agobridge.c: Hangup attended transfer target if bridged
Kevin Harwell [Mon, 22 Jun 2015 20:11:18 +0000 (15:11 -0500)]
bridge.c: Hangup attended transfer target if bridged

After completing an attended transfer the transfer target channel was not being
hung up after leaving the bridge. Added an explicit softhangup to hangup said
channel, but only if it was previously bridged.

ASTERISK-24782 #close
Reported by: John Bigelow

Change-Id: Idde9543d56842369384a5e8c00d72a22bbc39ada

7 years agores_pjsip_mwi: Set up unsolicited MWI upon registration.
Joshua Colp [Wed, 17 Jun 2015 10:04:39 +0000 (07:04 -0300)]
res_pjsip_mwi: Set up unsolicited MWI upon registration.

The res_pjsip_mwi previously required a reload to set up the proper
subscriptions to allow unsolicited MWI to work. This change
makes it so the act of registering will also cause this to occur.
This is particularly useful if realtime is involved as no reload
needs to occur within Asterisk to cause the MWI information
to get sent.

ASTERISK-25180 #close

Change-Id: Id847b47de4b8b3ab8858455ccc2f07b0f915f252

7 years agores_pjsip_outbound_registration.c: Fix whitespace conflict potential.
Richard Mudgett [Mon, 22 Jun 2015 18:57:21 +0000 (13:57 -0500)]
res_pjsip_outbound_registration.c: Fix whitespace conflict potential.

Change-Id: I82e6e388e3688aebe0783f16c9e0800a747584b5

7 years agochan_sip: Reload peer without its old capabilities.
Alexander Traud [Mon, 22 Jun 2015 14:26:48 +0000 (16:26 +0200)]
chan_sip: Reload peer without its old capabilities.

On reload, previously allowed codecs were not removed. Therefore, it was not
possible to remove codecs while Asterisk was running. Furthermore, newly added
codecs got appended behind the previous codecs. Therefore, it was not possible
to add a codec with a priority of #1. This change removes the old capabilities
before the current ones are added.

ASTERISK-25182 #close
Reported by: Alexander Traud
patches:
 asterisk_13_allow_codec_reload.patch uploaded by Alexander Traud (License 6520)

Change-Id: I62a06bcf15e08e8c54a35612195f97179ebe5802

7 years agochan_sip: Destroy peers without holding peers container lock.
Joshua Colp [Sun, 21 Jun 2015 00:38:02 +0000 (21:38 -0300)]
chan_sip: Destroy peers without holding peers container lock.

Due to the use of stasis_unsubscribe_and_join in the peer destructor
it is possible for a deadlock to occur when an event callback is
occurring at the same time.

This happens because the peer may be destroyed while holding the
peers container lock. If this occurs the event callback will never
be able to acquire the container lock and the unsubscribe will
never complete.

This change makes it so the peers that have been removed from the
peers container are not destroyed with the container lock held.

ASTERISK-25163 #close

Change-Id: Ic6bf1d9da4310142a4d196c45ddefb99317d9a33

7 years agoMerge "Resolve race conditions involving Stasis bridges."
Matt Jordan [Fri, 19 Jun 2015 15:11:36 +0000 (10:11 -0500)]
Merge "Resolve race conditions involving Stasis bridges."

7 years agoResolve race conditions involving Stasis bridges.
Mark Michelson [Thu, 18 Jun 2015 18:16:29 +0000 (13:16 -0500)]
Resolve race conditions involving Stasis bridges.

This resolves two observed race conditions.

First, a bit of background on what the Stasis application does:

1a Creates a stasis_app_control structure. This structure is linked into
   a global container and can be looked up using a channel's unique ID.
2a Puts the channel in an event loop. The event loop can exit either
   because the stasis_app_control structure has been marked done, or
   because of some other factor, such as a hangup. In the event loop, the
   stasis_app_control determines if any specific ARI commands need to be
   run on the channel and will run them from this thread.
3a Checks if the channel is bridged. If the channel is bridged, then
   ast_bridge_depart() is called since channels that are added to Stasis
   bridges are always imparted as departable.
4a Unlink the stasis_app_control from the container.

When an ARI command is received by Asterisk, the following occurs
1b A thread is spawned to handle the HTTP request
2b The stasis_app_control(s) that corresponds to the channel(s) in the
   request is/are retrieved. If the stasis_app_control cannot be
   retrieved, then it is assumed that the channel in question has exited
   the Stasis app or perhaps was never in Stasis in the first place.
3b A command is queued onto the stasis_app_control, and the channel's
   event loop thread is signaled to run the command.
4b While most ARI commands do nothing further, some, such as adding or
   removing channels from a bridge, will block until the command they
   issued has been completed by the channel's event loop.

The first race condition that is solved by this patch involves a crash
that can occur due to faulty detection of the channel's bridged status
in step 3a. What can happen is that in step 2a, the event loop may run
the ast_bridge_impart() function to asynchronously place the channel
into a bridge, then immediately exit the event loop because the channel
has hung up. In step 3a, we would detect that the channel was not
bridged and would not call ast_bridge_depart(). The reason that the
channel did not appear to be bridged was that the depart_thread that is
spawned by ast_bridge_impart() had not yet started. That is the thread
where the channel is marked as being bridged. Since we did not call
ast_bridge_depart(), the Stasis application would exit, and then the
channel would be destroyed Then the depart_thread would start up and
try to manipulate the destroyed channel, causing a crash.

The fix for this is to switch from using ast_channel_is_bridged() to
checking the NULLity of ast_channel_internal_bridge_channel() to
determine if ast_bridge_depart() needs to be called. The channel's
internal bridge_channel is set when ast_bridge_impart() is called and
is NULLed by the call to ast_bridge_depart(). If the channel's internal
bridge_channel is non-NULL, then the channel must have been imparted
into the bridge and needs to be departed, even if the actual bridging
operation has not yet started. By departing the channel when necessary,
the thread that is running the Stasis application will block until the
bridge gives the okay that the depart_thread has exited.

The second race condition that is solved by this patch involves a leak
of HTTP handler threads. The problem was that step 2b would successfully
retrieve a stasis_app_control structure. Then step 2a would exit the
channel from the event loop due to a hangup. Steps 3a and 4a would
execute, and then finally steps 3b and 4b would. The problem is that at
step 4b, when attempting to add a channel to a bridge, the thread would
block forever since the channel would never execute the queued command
since it was finished with the event loop. This meant that the HTTP
handling thread would be leaked, along with any references that thread
may have owned (in my case, I was seeing bridges leaked).

The fix for this is to hone in better on when the channel has exited the
event loop. The stasis_app_control structure has an is_done field that
is now set at each point where the channel may exit the event loop. If
step 2b retrieves a valid stasis_app_control structure but the control
is marked as done, then the attempted operation exits immediately since
there will be nothing to service the attempted command.

ASTERISK-25091 #close
Reported by Ilya Trikoz

Change-Id: If66265b73b4c9f8f58599124d777fedc54576628

7 years agores_sorcery_memory_cache: Remove 'prefetch' option.
Joshua Colp [Wed, 17 Jun 2015 12:00:21 +0000 (09:00 -0300)]
res_sorcery_memory_cache: Remove 'prefetch' option.

To prevent confusion I am removing the prefetch option until such
time as it is implemented. All other functionality, however, has
been implemented.

ASTERISK-25067

Change-Id: I9ce6aa3e5c6c5bc3c5baa8ff90fa036d73939895

7 years agoMerge "Parking: Add documentation for AMI ParkedCallSwap event."
Matt Jordan [Tue, 16 Jun 2015 16:40:34 +0000 (11:40 -0500)]
Merge "Parking: Add documentation for AMI ParkedCallSwap event."

7 years agoParking: Add documentation for AMI ParkedCallSwap event.
Mark Michelson [Tue, 16 Jun 2015 16:13:20 +0000 (11:13 -0500)]
Parking: Add documentation for AMI ParkedCallSwap event.

This event was added some time ago in order to clarify when a channel
took the place of another channel in a parking lot. However, there was
no XML documentation added for the event. This patch adds the XML
documentation.

ASTERISK-24900 #close
Reported by Rusty Newton

Change-Id: I4cfe7777c4b94bbff91c9221c6096a7a02a92eac