]> git.ipfire.org Git - thirdparty/asterisk.git/log
thirdparty/asterisk.git
9 years agochan_pjsip: Fix crash on reINVITE before initial INVITE completes. 93/1393/1
Richard Mudgett [Mon, 5 Oct 2015 21:53:44 +0000 (16:53 -0500)] 
chan_pjsip: Fix crash on reINVITE before initial INVITE completes.

Apparently some endpoints attempt to send a reINVITE before completing the
initial INVITE transaction.  In this case PJSIP responds appropriately to
the reINVITE with a 491 INVITE request pending.  Unfortunately chan_pjsip
is using the initial INVITE transaction state to determine if an INVITE is
the initial INVITE or a reINVITE.  Since the initial INVITE transaction
has not been confirmed yet chan_pjsip thinks the reINVITE is an initial
INVITE and starts another PBX thread on the channel.  The extra PBX thread
ensures that hilarity ensues.

* Fix checks for a reINVITE on incoming requests to look for the presence
of a to-tag instead of the initial INVITE transaction state.

* Made caller_id_incoming_request() determine what to do if there is a
channel on the session or not.  After a channel is created it is too late
to just store the new party id on the session because the session's party
id has already been copied to the channel's caller id.

ASTERISK-25404 #close
Reported by: Chet Stevens

Change-Id: Ie78201c304a2b13226f3a4ce59908beecc2c68be

9 years agoFix improper usage of scheduler exposed by 5c713fdf18f 82/1382/2
Matt Jordan [Tue, 6 Oct 2015 02:34:41 +0000 (21:34 -0500)] 
Fix improper usage of scheduler exposed by 5c713fdf18f

When 5c713fdf18f was merged, it allowed for scheduled items to have an ID of
'0' returned. While this was valid per the documentation for the API, it was
apparently never returned previously. As a result, several users of the
scheduler API viewed the result as being invalid, causing them to reschedule
already scheduled items or otherwise fail in interesting ways.

This patch corrects the users such that they view '0' as valid, and a returned
ID of -1 as being invalid.

Note that the failing HEP RTCP tests now pass with this patch. These tests
failed due to a duplicate scheduling of the RTCP transmissions.

ASTERISK-25449 #close

Change-Id: I019a9aa8b6997584f66876331675981ac9e07e39

9 years agores_sorcery_memory_cache.c: Fix deadlock with scheduler. 65/1365/1
Richard Mudgett [Wed, 30 Sep 2015 22:28:19 +0000 (17:28 -0500)] 
res_sorcery_memory_cache.c: Fix deadlock with scheduler.

A deadlock can happen when a sorcery object is being expired from the
memory cache when at the same time another object is being placed into the
memory cache.  There are a couple other variations on this theme that
could cause the deadlock.  Basically if an object is being expired from
the sorcery memory cache at the same time as another thread tries to
update the next object expiration timer the deadlock can happen.

* Add a deadlock avoidance loop in expire_objects_from_cache() to check if
someone is trying to remove the scheduler callback from the scheduler.

ASTERISK-25441 #close

Change-Id: Iec7b0bdb81a72b39477727b1535b2539ad0cf4dc

9 years agores_sorcery_memory_cache.c: Replace inline code with function. 64/1364/1
Richard Mudgett [Thu, 1 Oct 2015 19:30:06 +0000 (14:30 -0500)] 
res_sorcery_memory_cache.c: Replace inline code with function.

Make sorcery_memory_cache_close() call remove_all_from_cache() instead of
partially inlining it.

ASTERISK-25441

Change-Id: I1aa6cb425b1a4307096f3f914d17af8ec179a74c

9 years agores_sorcery_memory_cache.c: Shutdown in a less crash potential order. 63/1363/1
Richard Mudgett [Thu, 1 Oct 2015 19:27:34 +0000 (14:27 -0500)] 
res_sorcery_memory_cache.c: Shutdown in a less crash potential order.

Basically you should shutdown in the opposite order of how you setup since
later setup pieces likely depend on earlier setup pieces.  e.g.,
Registering your external API with the rest of the system should be the
last thing setup and the first thing unregistered during shutdown.

Change-Id: I5715765b723100c8d3c2642e9e72cc7ad5ad115e

9 years agores_sorcery_memory_cache.c: Misc tweaks. 62/1362/1
Richard Mudgett [Wed, 30 Sep 2015 22:27:54 +0000 (17:27 -0500)] 
res_sorcery_memory_cache.c: Misc tweaks.

Change-Id: I8cd32dffbb4f33bb0c39518d6e4c991e73573160

9 years agores_sorcery_memory_cache.c: Made use OBJ_SEARCH_MASK. 61/1361/1
Richard Mudgett [Wed, 30 Sep 2015 22:27:23 +0000 (17:27 -0500)] 
res_sorcery_memory_cache.c: Made use OBJ_SEARCH_MASK.

Change-Id: Ibca6574dc3c213b29cc93486e01ccd51f5caa46c

9 years agores/res_pjsip_dlg_options: Add a module to handle in-dialog OPTIONS requests 50/1350/1
Matthew Jordan [Thu, 9 Apr 2015 15:42:16 +0000 (15:42 +0000)] 
res/res_pjsip_dlg_options: Add a module to handle in-dialog OPTIONS requests

This patch adds a new session supplement that handles in-dialog OPTIONS
requests. Said OPTIONS requests are sent a 200 OK, as an endpoint lookup
for the OPTIONS request would already have been done by the time the
session supplement receives the inbound request.

ASTERISK-24862 #close
Reported by: yaron nahum
patches:
  res_pjsip_dlg_options.c submitted by yaron nahum (License 6676)

Change-Id: Iefc901a7c5c88d9d4b853188f85092d9eb7b6ada

9 years agoapp_queue.c: Force COLP update if outgoing channel name changed. 29/1329/1
Richard Mudgett [Thu, 24 Sep 2015 19:56:24 +0000 (14:56 -0500)] 
app_queue.c: Force COLP update if outgoing channel name changed.

* When a call is answered and the outgoing channel name has changed then
force a connected line update because the channel is no longer the same.
The channel was masqueraded into by another channel.  This is usually
because of a call pickup.

Note: Forwarded calls are handled in a controlled manner so the original
channel name is replaced with the forwarded channel.

ASTERISK-25423 #close
Reported by: John Hardin

Change-Id: Ie275ea9e99c092ad369db23e0feb08c44498c172

9 years agoapp_queue.c: Factor out a connected line update routine. 28/1328/1
Richard Mudgett [Thu, 24 Sep 2015 19:20:24 +0000 (14:20 -0500)] 
app_queue.c: Factor out a connected line update routine.

Replace inlined code with update_connected_line_from_peer().

ASTERISK-25423
Reported by: John Hardin

Change-Id: I33bbd033596fcb0208d41d8970369b4e87b806f3

9 years agoapp_dial.c: Make 'A' option pass COLP updates. 27/1327/1
Richard Mudgett [Thu, 24 Sep 2015 18:27:44 +0000 (13:27 -0500)] 
app_dial.c: Make 'A' option pass COLP updates.

While the 'A' option is playing the announcement file allow the caller and
peer to exchange COLP update frames.

ASTERISK-25423
Reported by: John Hardin

Change-Id: Iac6cf89b56d26452c6bb88e9363622bbf23895f9

9 years agoapp_dial.c: Force COLP update if outgoing channel name changed. 26/1326/1
Richard Mudgett [Thu, 24 Sep 2015 17:59:08 +0000 (12:59 -0500)] 
app_dial.c: Force COLP update if outgoing channel name changed.

* When a call is answered and the outgoing channel name has changed then
force a connected line update because the channel is no longer the same.
The channel was masqueraded into by another channel.  This is usually
because of a call pickup.

Note: Forwarded calls are handled in a controlled manner so the original
channel name is replaced with the forwarded channel.

ASTERISK-25423
Reported by: John Hardin

Change-Id: I2e01f7a698fbbc8c26344a59c2be40c6cd98b00c

9 years agoapp_dial.c: Factor out a connected line update routine. 25/1325/1
Richard Mudgett [Thu, 24 Sep 2015 17:37:07 +0000 (12:37 -0500)] 
app_dial.c: Factor out a connected line update routine.

Replace inlined code with update_connected_line_from_peer().

ASTERISK-25423
Reported by: John Hardin

Change-Id: Ia14f18def417645cd7fb453e1bdac682630a5091

9 years agoDo not swallow frames on channels leaving bridges. 07/1307/1
Mark Michelson [Thu, 24 Sep 2015 19:49:46 +0000 (14:49 -0500)] 
Do not swallow frames on channels leaving bridges.

When leaving a bridge, indications on a channel could be swallowed by
the internal indication logic because it appears that the channel is on
its way to be hung up anyway. One such situation where this is
detrimental is when channels on hold are redirected out of a bridge. The
AST_CONTROL_UNHOLD indication from the bridging code is swallowed,
leaving the channel in question to still appear to be on hold.

The fix here is to modify the logic inside ast_indicate_data() to not
drop the indication if the channel is simply leaving a bridge. This way,
channels on hold redirected out of a bridge revert to their expected "in
use" state after the redirection.

ASTERISK-25418 #close
Reported by Mark Michelson

Change-Id: If6115204dfa0551c050974ee138fabd15f978949

9 years agoapp_page.c: Fix crash when forwarding with a predial handler. 01/1301/1
Richard Mudgett [Tue, 22 Sep 2015 22:08:49 +0000 (17:08 -0500)] 
app_page.c: Fix crash when forwarding with a predial handler.

Page uses the async method of dialing with the dial API.  When a call gets
forwarded there is no calling channel available.  If the predial handler
was set then the calling channel could not be put into auto-service
for the forwarded call because it doesn't exist.  A crash is the result.

* Moved the callee predial parameter string processing to before the
string is passed to the dial API rather than having the dial API do it.
There are a few benefits do doing this.  The first is the predial
parameter string processing doesn't need to be done for each channel
called by the dial API.  The second is in async mode and the forwarded
channel is to have the predial handler executed on it then the
non-existent calling channel does not need to be present to process the
predial parameter string.

* Don't start auto-service on a non-existent calling channel to execute
the predial handler when the dial API is in async mode and forwarding a
call.

ASTERISK-25384 #close
Reported by: Chet Stevens

Change-Id: If53892b286d29f6cf955e2545b03dcffa2610981

9 years agoResolve race conditions involving Stasis bridges. 98/1298/1
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

9 years agoMerge "app_record: RECORDED_FILE variable not being populated" into certified/13.1
Matt Jordan [Tue, 22 Sep 2015 12:40:25 +0000 (07:40 -0500)] 
Merge "app_record: RECORDED_FILE variable not being populated" into certified/13.1

9 years agoapp_record: RECORDED_FILE variable not being populated 92/1292/1
Kevin Harwell [Mon, 21 Sep 2015 23:06:15 +0000 (18:06 -0500)] 
app_record: RECORDED_FILE variable not being populated

The RECORDED_FILE variable is empty unless a '%d' is specified in the filename.
This patch makes it so the variable is always set to the filename.

ASTERISK-25410 #close

Change-Id: I4ec826d8eb582ae2ad184e717be8668b74d37653

9 years agopbx: Update device and presence state when changing a hint extension. 65/1265/3
Joshua Colp [Wed, 16 Sep 2015 13:22:35 +0000 (10:22 -0300)] 
pbx: Update device and presence state when changing a hint extension.

When changing a hint extension without removing the hint first the
device state and presence state is not updated. This causes the state
of the hint to be that of the previous extension and not the current
one. This state is kept until a state change occurs as a result of
something (presence state change, device state change).

This change updates the hint with the current device and presence
state of the new extension when it is changed. Any state callbacks
which may have been added before the hint extension is changed are
also informed of the new device and presence state if either have
changed.

ASTERISK-25394 #close

Change-Id: If268f1110290e502c73dd289c9e7e7b27bc8432f

9 years agores_pjsip_pubsub: Eliminate race during initial NOTIFY. 67/1267/2
Mark Michelson [Wed, 16 Sep 2015 22:36:32 +0000 (17:36 -0500)] 
res_pjsip_pubsub: Eliminate race during initial NOTIFY.

There is a slim chance of a race condition occurring where two threads
can both attempt to manipulate the same area.

Thread A can be handling an incoming initial SUBSCRIBE request. Thread A
lets the specific subscription handler know that the subscription has
been established.

At this point, Thread B may detect a state change on the subscribed
resource and queue up a notification task on Thread C, the subscription
serializer thread.

Now Thread A attempts to generate the initial NOTIFY request to send to
the subscriber at the same time that Thread C attempts to generate a
state change NOTIFY request to send to the subscriber.

The result is that Threads A and C can step on the same memory area,
resulting in a crash. The crash has been observed as happening when
attempting to allocate more space to hold the body for the NOTIFY.

The solution presented here is to queue the subscription establishment
and initial NOTIFY generation onto the subscription serializer thread
(Thread C in the above scenario). This way, there is no way that a state
change notification can occur before the initial NOTIFY is sent, and if
there is a quick succession of NOTIFYs, we can guarantee that the two
NOTIFY requests will be sent in succession.

Change-Id: I5a89a77b5f2717928c54d6efb9955e5f6f5cf815

9 years agoscheduler: Use queue for allocating sched IDs. 57/1257/4
Mark Michelson [Thu, 10 Sep 2015 22:19:26 +0000 (17:19 -0500)] 
scheduler: Use queue for allocating sched IDs.

It has been observed that on long-running busy systems, a scheduler
context can eventually hit INT_MAX for its assigned IDs and end up
overflowing into a very low negative number. When this occurs, this can
result in odd behaviors, because a negative return is interpreted by
callers as being a failure. However, the item actually was successfully
scheduled. The result may be that a freed item remains in the scheduler,
resulting in a crash at some point in the future.

The scheduler can overflow because every time that an item is added to
the scheduler, a counter is bumped and that counter's current value is
assigned as the new item's ID.

This patch introduces a new method for assigning scheduler IDs. Instead
of assigning from a counter, a queue of available IDs is maintained.
When assigning a new ID, an ID is pulled from the queue. When a
scheduler item is released, its ID is pushed back onto the queue. This
way, IDs may be reused when they become available, and the growth of ID
numbers is directly related to concurrent activity within a scheduler
context rather than the uptime of the system.

Change-Id: I532708eef8f669d823457d7fefdad9a6078b99b2

9 years agores_pjsip: Copy default_from_user to avoid crash. 37/1237/1
Mark Michelson [Thu, 10 Sep 2015 14:49:45 +0000 (09:49 -0500)] 
res_pjsip: Copy default_from_user to avoid crash.

The default_from_user retrieval function was pulling the
default_from_user from the global configuration struct in an unsafe way.
If using a database as a backend configuration store, the global
configuration struct is short-lived, so grabbing a pointer from it
results in referencing freed memory.

The fix here is to copy the default_from_user value out of the global
configuration struct.

Thanks go to John Hardin for discovering this problem and proposing the
patch on which this fix is based.

ASTERISK-25390 #close
Reported by Mark Michelson

Change-Id: I6b96067a495c1259da768f4012d44e03e7c6148c

9 years agores_pjsip: Validate that contact uris start with sip: or sips: 32/1232/1
George Joseph [Thu, 23 Apr 2015 14:16:45 +0000 (08:16 -0600)] 
res_pjsip:  Validate that contact uris start with sip: or sips:

Currently we use pjsip_parse_hdr to validate contact uris but it
appears that it allows uris without a scheme if there's a port
supplied.  I.E myexample.com will fail but myexample.com:5060 will
pass even though it has no scheme.  This causes SEGVs later on
whenever the uri is used.

To prevent this, permanent_contact_validate has been updated to check
that the scheme is either 'sip' or 'sips'.

2 uses of possibly-null endpoint have also been fixed in
create_out_of_dialog_request.

ASTERISK-24999

Change-Id: Ifc17d16a4923e1045d37fe51e43bbe29fa556ca2
Reported-by: Brad Latus
(cherry picked from commit 75666ad7c608ad9968a216a8f0a5832bf85b785c)

9 years agoParkAndAnnounce: Add variable inheritance 27/1227/1
Jonathan Rose [Thu, 3 Sep 2015 19:07:35 +0000 (14:07 -0500)] 
ParkAndAnnounce: Add variable inheritance

In Asterisk 11, the announcer channel would receive channel variables
from the channel being parked by means of normal channel inheritance.
This functionality was lost during the big res_parking project in
Asterisk 12. This patch restores that functionality.

ASTERISK-25369 #close
Review: https://gerrit.asterisk.org/#/c/1180/

Change-Id: Ie47e618330114ad2ea91e2edcef1cb6f341eed6e

9 years agotaskprocessor: Fix race condition between unreferencing and finding. 26/1226/1
Joshua Colp [Sat, 29 Aug 2015 15:36:35 +0000 (12:36 -0300)] 
taskprocessor: Fix race condition between unreferencing and finding.

When unreferencing a taskprocessor its reference count is checked
to determine if it should be unlinked from the taskprocessors
container and its listener shut down. In between the time when the
reference count is checked and unlinking it is possible for
another thread to jump in, find it, and get a reference to it. If
the thread then uses the taskprocessor it may find that it is not
in the state it expects.

This change locks the taskprocessors container during almost the
entire unreference operation to ensure that any other thread which
may attempt to find the taskprocessor has to wait.

ASTERISK-25295

Change-Id: Icb842db82fe1cf238da55df92e95938a4419377c
(cherry picked from commit a676ba2aad5525926ae31b8317b95ae52cbbabbb)

9 years agoMerge "res_pjsip: Change default from user value." into certified/13.1
Matt Jordan [Mon, 7 Sep 2015 16:37:17 +0000 (11:37 -0500)] 
Merge "res_pjsip: Change default from user value." into certified/13.1

9 years agores_pjsip: Change default from user value. 00/1200/3
Mark Michelson [Fri, 4 Sep 2015 19:40:38 +0000 (14:40 -0500)] 
res_pjsip: Change default from user value.

When Asterisk sends an outbound SIP request, if there is no direct
reason to place a specific value for the username in the From header,
Asterisk would generate a UUID. For example, this would happen when
sending outbound OPTIONS requests when qualifying or when sending
outbound INVITE requests when originating (if no explicit caller ID were
provided). The issue is that some SIP providers reject these sorts of
requests with a "Name too long" error response.

This patch aims to fix this by changing the default outbound username in
From headers to "asterisk". This value can be overridden by changing the
default_from_user option in the global options if desired.

ASTERISK-25377 #close
Reported by Mark Michelson

Change-Id: I6a4d34a56ff73ff4f661b0075aeba5461b7f3190

9 years agoMessage.c: Clear message channel frames on cleanup 86/1186/1
Jonathan Rose [Wed, 13 May 2015 20:41:07 +0000 (15:41 -0500)] 
Message.c: Clear message channel frames on cleanup

The message channel is a special channel that doesn't actually process frames.
However, certain actions can cause frames to be placed in the channel's read
queue including the Hangup application which is called on the channel after
each message is processed. Since the channel will continually be reused for
many messages, it's necessary to flush these frames at some point.

ASTERISK-25083 #close
Reported by: Jonathan Rose

Change-Id: Idf18df73ccd8c220be38743335b5c79c2a4c0d0f
(cherry picked from commit 02c513058905dae19f28393ea840a47ae4a9e66d)

9 years agores_pjsip: Fix contact refleak on stateful responses. 79/1179/1
Mark Michelson [Wed, 2 Sep 2015 22:26:14 +0000 (17:26 -0500)] 
res_pjsip: Fix contact refleak on stateful responses.

When sending a stateful response, creation of the transaction can fail,
most commonly because we are trying to create a transaction from a
retransmitted request. When creation of the transaction fails, we end up
leaking a reference to a contact that was bumped when the response was
created.

This patch adds the missing deref and fixes the reference leak.

Change-Id: I2f97ad512aeb1b17e87ca29ae0abacb4d6395f07

9 years agopbx: Fix crash when issuing "core show hints" with long pattern match. 75/1175/1
Joshua Colp [Wed, 2 Sep 2015 17:41:10 +0000 (14:41 -0300)] 
pbx: Fix crash when issuing "core show hints" with long pattern match.

When issuing the "core show hints" CLI command a combination of both
the hint extension and context is created. This uses a fixed size
buffer expecting that the extension will not exceed maximum extension
length. When the extension is actually a pattern match this constraint
does not hold true, and the extension may exceed the maximum extension
length. In this case extra characters are written past the end of the
fixed size buffer.

This change makes it so the construction of the combined hint extension
and context can not exceed the size of the buffer.

ASTERISK-25367 #close

Change-Id: Idfa1b95d0d4dc38e675be7c1de8900b3f981f499

9 years agoPJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error. 72/1172/1
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

9 years agores_pjsip_pubsub: re-re-fix persistent subscription storage. 69/1169/2
Mark Michelson [Tue, 1 Sep 2015 14:05:34 +0000 (09:05 -0500)] 
res_pjsip_pubsub: re-re-fix persistent subscription storage.

A recent change to res_pjsip_pubsub switched to using pjsip_msg_print as
a means of writing an appropriate packet to persistent storage. While
this partially solved the issue, it had its own problems.
pjsip_msg_print will always add a Content-Length header to the message
it prints. Frequent restarts of Asterisk can result in persistent
subscriptions being written with five or more Content-Length headers. In
addition, sometimes some apparent corruption of individual headers could
be seen.

This aims to fix the problem by not running a parsed message through an
interpreter but rather by taking the raw message and saving it. The
logic for what to save is going to be different depending on whether a
SUBSCRIBE was received from the wire or if it was pulled from
persistence. When receiving a packet from the wire, when using a
streaming transport, the rdata->pkt_info.packet may contain multiple SIP
messages or fragments. However, the rdata->msg_info.msg_buf will always
contain the current SIP message to be processed. When pulling from
persistence, though, the rdata->msg_info.msg_buf will be NULL since no
transport actually handled the packet. However, since we know that we
will always ever pull one SIP message from persistence, we are free to
save directly from rdata->pkt_info.packet instead.

ASTERISK-25365 #close
Reported by Mark Michelson

Change-Id: I33153b10d0b4dc8e3801aaaee2f48173b867855b

9 years agoFix deadlock on presence state changes. 67/1167/1
Mark Michelson [Mon, 31 Aug 2015 20:24:17 +0000 (15:24 -0500)] 
Fix deadlock on presence state changes.

A deadlock was observed where three threads were competing for different
locks:

* One thread held the hints lock and was attempting to lock a specific
  hint.
* One thread was holding the specific hint's lock and was attempting to
  lock the contexts lock
* One thread was holding the contexts lock and attempting to lock the
  hints lock.

Clearly the second thread was doing the wrong thing here. The fix for
this is to make sure that the hint's lock is not held on presence state
changes. Something similar is already done (and commented about) for
device state changes.

ASTERISK-25362 #close
Reported by Mark Michelson

Change-Id: I15ec2416b92978a4c0c08273b2d46cb21aff97e2

9 years agoMerge "res_pjsip_sdp_rtp: Fix multiple keepalive scheduled items." into certified...
Matt Jordan [Sat, 29 Aug 2015 17:30:54 +0000 (12:30 -0500)] 
Merge "res_pjsip_sdp_rtp: Fix multiple keepalive scheduled items." into certified/13.1

9 years agores_pjsip_sdp_rtp: Fix multiple keepalive scheduled items. 61/1161/1
Joshua Colp [Sat, 29 Aug 2015 01:22:45 +0000 (22:22 -0300)] 
res_pjsip_sdp_rtp: Fix multiple keepalive scheduled items.

The keepalive support in res_pjsip_sdp_rtp currently assumes
that a stream will only be negotiated once. This is false.
If the stream is replaced and later added back it can be
negotiated again causing multiple keepalive scheduled items
to exist. This change explicitly deletes the existing
keepalive scheduled item before adding the new one.

The res_pjsip_sdp_rtp module also does not stop RTP
keepalives or timeout timer if the stream has been
replaced. This change adds a callback to the session media
interface to allow a media stream to be stopped without
the resources being destroyed. This allows the scheduled
items and RTP to be stopped when the stream no longer
exists.

ASTERISK-25356 #close

Change-Id: Ibe6a7cc0927c87326fd5f1c0d4ad889dbfbea1de

9 years agosched: ast_sched_del may return prematurely due to spurious wakeup 58/1158/1
Joshua Colp [Sat, 29 Aug 2015 00:57:14 +0000 (21:57 -0300)] 
sched: ast_sched_del may return prematurely due to spurious wakeup

When deleting a scheduled item if the item in question is currently
executing the ast_sched_del function waits until it has completed.
This is accomplished using ast_cond_wait. Unfortunately the
ast_cond_wait function can suffer from spurious wakeups so the
predicate needs to be checked after it returns to make sure it has
really woken up as a result of being signaled.

This change adds a loop around the ast_cond_wait to make sure that
it only exits when the executing task has really completed.

ASTERISK-25355 #close

Change-Id: I51198270eb0b637c956c61aa409f46283432be61

9 years agoMerge "Local channels: Alternate solution to ringback problem." into certified/13.1
Joshua Colp [Fri, 28 Aug 2015 11:30:55 +0000 (06:30 -0500)] 
Merge "Local channels: Alternate solution to ringback problem." into certified/13.1

9 years agoMerge "res_pjsip: Add common ast_sip_get_host_ip API." into certified/13.1
Joshua Colp [Thu, 27 Aug 2015 20:42:05 +0000 (15:42 -0500)] 
Merge "res_pjsip: Add common ast_sip_get_host_ip API." into certified/13.1

9 years agoLocal channels: Alternate solution to ringback problem. 50/1150/1
Mark Michelson [Thu, 23 Jul 2015 18:11:42 +0000 (13:11 -0500)] 
Local channels: Alternate solution to ringback problem.

Commit 54b25c80c8387aea9eb20f9f4f077486cbdf3e5d solved an issue where a
specific scenario involving local channels and a native local RTP bridge
could result in ringback still being heard on a calling channel even
after the call is bridged.

That commit caused many tests in the testsuite to fail with alarming
consequences, such as not sending DialBegin and DialEnd events, and
giving incorrect hangup causes during calls.

This commit reverts the previous commit and implements and alternate
solution. This new solution involves only passing AST_CONTROL_RINGING
frames across local channels if the local channel is in AST_STATE_RING.
Otherwise, the frame does not traverse the local channels. By doing
this, we can ensure that a playtones generator does not get started on
the calling channel but rather is started on the local channel on which
the ringing frame was initially indicated.

ASTERISK-25250 #close
Reported by Etienne Lessard

Change-Id: I3bc87a18a38eb2b68064f732d098edceb5c19f39

9 years agochan_sip: Allow call pickup to set the hangup cause. 43/1143/1
Joshua Colp [Wed, 26 Aug 2015 10:40:32 +0000 (07:40 -0300)] 
chan_sip: Allow call pickup to set the hangup cause.

The call pickup implementation in chan_sip currently sets the channel
hangup cause to "normal clearing" if call pickup is successfully
performed. This action overwrites the "answered elsewhere" hangup cause
set by the call pickup code and can result in the SIP device in
question showing a missed call when it should not.

This change sets the hangup cause to "normal clearing" as a
default initially but allows the call pickup to change it as
needed.

ASTERISK-25346 #close

Change-Id: I00ac2c269cee9e29586ee2c65e83c70e52a02cff

9 years agores_pjsip: Add common ast_sip_get_host_ip API. 38/1138/2
Joshua Colp [Tue, 25 Aug 2015 12:17:34 +0000 (09:17 -0300)] 
res_pjsip: Add common ast_sip_get_host_ip API.

Modules commonly used the pj_gethostip function for retrieving the
IP address of the host. This function does not cache the result and may
result in a DNS lookup occurring, or additional work. If the DNS
server is unreachable or network issues arise this can cause the
pj_gethostip function to block for a period of time.

This change adds an ast_sip_get_host_ip and ast_sip_get_host_ip_string
function which does the same thing but caches the host IP address at
module load time. This results in no additional work being done each
time the local host IP address is needed.

ASTERISK-25342 #close

Change-Id: I3205deb679b01fa5ac05a94b623bfd620a2abe1e

9 years agoMerge "bridge: Kick channel from bridge if hung up during action." into certified...
Mark Michelson [Mon, 24 Aug 2015 22:16:33 +0000 (17:16 -0500)] 
Merge "bridge: Kick channel from bridge if hung up during action." into certified/13.1

9 years agobridge: Kick channel from bridge if hung up during action. 35/1135/1
Joshua Colp [Mon, 24 Aug 2015 11:21:37 +0000 (08:21 -0300)] 
bridge: Kick channel from bridge if hung up during action.

When executing an action in a bridge it is possible for the
channel to be hung up without the bridge becoming aware of it.
This is most easily reproducible by hanging up when the bridge
is streaming DTMF due to a feature timeout. This change makes
it so after action execution the channel is checked to determine
if it has been hung up and if it has it is kicked from the bridge.

ASTERISK-25341 #close

Change-Id: I6dd8b0c3f5888da1c57afed9e8a802ae0a053062

9 years agores_pjsip_pubsub: On recreated notify fail deleted sub_tree is referenced 31/1131/1
Joshua Colp [Mon, 24 Aug 2015 16:04:57 +0000 (13:04 -0300)] 
res_pjsip_pubsub: On recreated notify fail deleted sub_tree is referenced

When recreating a subscription it is possible for a freed sub_tree
to be referenced when the initial NOTIFY fails to be created.

Change-Id: I681c215309aad01b21d611c2de47b3b0a6022788

9 years agores_pjsip_pubsub: On notify fail deleted sub_tree is then referenced 25/1125/2
Scott Griepentrog [Thu, 16 Apr 2015 18:20:29 +0000 (13:20 -0500)] 
res_pjsip_pubsub: On notify fail deleted sub_tree is then referenced

This change makes the send_notify of the sub_tree
not happen when the sub_tree has been deleted due
to the notify call failing, which avoids a crash.

ASTERISK-24970 #close

Change-Id: I1f20ffc08b192f59c457293b218025a693992cbf
(cherry picked from commit 8d4ce7cc2b87317005588e700b278a8cca7005c8)

9 years agores_pjsip_sdp_rtp: Restore removed NULL check. 99/1099/1
Mark Michelson [Fri, 14 Aug 2015 20:46:05 +0000 (15:46 -0500)] 
res_pjsip_sdp_rtp: Restore removed NULL check.

When sending an RTP keepalive, we need to be sure we're not dealing with
a NULL RTP instance. There had been a NULL check, but the commit that
added the rtp_timeout and rtp_hold_timeout options removed the NULL
check.

Change-Id: I2d7dcd5022697cfc6bf3d9e19245419078e79b64

9 years agoaudiohook.c: Fix MixMonitor crash when using the r() or t() options. 90/1090/2
Richard Mudgett [Thu, 13 Aug 2015 17:22:14 +0000 (12:22 -0500)] 
audiohook.c: Fix MixMonitor crash when using the r() or t() options.

The built frame format in audiohook_read_frame_both() is now set to a
signed linear format before the rx and tx frames are duplicated instead of
only for the mixed audio frame duplication.

ASTERISK-25322 #close
Reported by Sean Pimental

Change-Id: I86f85b5c48c49e4e2d3b770797b9d484250a1538

9 years agoMerge "chan_sip.c: wrong peer searched in sip_report_security_event" into certified...
Mark Michelson [Thu, 13 Aug 2015 21:12:11 +0000 (16:12 -0500)] 
Merge "chan_sip.c: wrong peer searched in sip_report_security_event" into certified/13.1

9 years agochan_sip.c: wrong peer searched in sip_report_security_event 84/1084/2
Kevin Harwell [Wed, 12 Aug 2015 17:59:53 +0000 (12:59 -0500)] 
chan_sip.c: wrong peer searched in sip_report_security_event

In chan_sip, after handling an incoming invite a security event is raised
describing authorization (success, failure, etc...). However, it was doing
a lookup of the peer by extension. This is fine for register messages, but
in the case of an invite it may search and find the wrong peer, or a non
existent one (for instance, in the case of call pickup). Also, if the peers
are configured through realtime this may cause an unnecessary database lookup
when caching is enabled.

This patch makes it so that sip_report_security_event searches by IP address
when looking for a peer instead of by extension after an invite is processed.

ASTERISK-25320 #close

Change-Id: I9b3f11549efb475b6561c64f0e6da1a481d98bc4

9 years agores_http_websocket: When shutting down a session don't close closed socket 80/1080/2
Joshua Colp [Thu, 13 Aug 2015 10:26:51 +0000 (07:26 -0300)] 
res_http_websocket: When shutting down a session don't close closed socket

Due to the use of ast_websocket_close in session termination it is
possible for the underlying socket to already be closed when the
session is terminated. This occurs when the close frame is attempted
to be written out but fails.

Change-Id: I7572583529a42a7dc911ea77a974d8307d5c0c8b

9 years agoMerge "res_http_websocket: Forcefully terminate on write errors." into certified...
Joshua Colp [Wed, 12 Aug 2015 18:43:05 +0000 (13:43 -0500)] 
Merge "res_http_websocket: Forcefully terminate on write errors." into certified/13.1

9 years agores_http_websocket: Forcefully terminate on write errors. 75/1075/1
Joshua Colp [Tue, 11 Aug 2015 10:24:30 +0000 (07:24 -0300)] 
res_http_websocket: Forcefully terminate on write errors.

The res_http_websocket module will currently attempt to close
the WebSocket connection if fatal cases occur, such as when
attempting to write out data and being unable to. When the
fatal cases occur the code attempts to write a WebSocket close
frame out to have the remote side close the connection. If
writing this fails then the connection is not terminated.

This change forcefully terminates the connection if the
WebSocket is to be closed but is unable to send the close frame.

ASTERISK-25312 #close

Change-Id: I10973086671cc192a76424060d9ec8e688602845

9 years agochan_dahdi.c: Flush the DAHDI write buffer after starting DTMF. 68/1068/1
Richard Mudgett [Mon, 10 Aug 2015 18:43:19 +0000 (13:43 -0500)] 
chan_dahdi.c: Flush the DAHDI write buffer after starting DTMF.

Pressing DTMF digits on a phone to go out on a DAHDI channel can result in
the digit not being recognized or even heard by the peer.

Phone -> Asterisk -> DAHDI/channel

Turns out the DAHDI behavior with DTMF generation (and any other generated
tones) is exposed by the "buffers=" setting in chan_dahdi.conf.  When
Asterisk requests to start sending DTMF then DAHDI waits until its write
buffer is empty before generating any samples for the DTMF tones.  When
Asterisk subsequently requests DAHDI to stop sending DTMF then DAHDI
immediately stops generating the DTMF samples.  As a result, the more
samples there are in the DAHDI write buffer the shorter the time DTMF
actually gets sent on the wire.  If there are more samples in the write
buffer than the time DTMF is supposed to be sent then no DTMF gets sent on
the wire.  With the "buffers=12,half" setting and each buffer representing
20 ms of samples then the DAHDI write buffer is going to contain around
120 ms of samples.  For DTMF to be recognized by the peer the actual sent
DTMF duration needs to be a minimum of 40 ms.  Therefore, the intended
duration needs to be a minimum of 160 ms for the peer to receive the
minimum DTMF digit duration to recognize it.

A simple and effective solution to work around the DAHDI behavior is for
Asterisk to flush the DAHDI write buffer when sending DTMF so the full
duration of DTMF is actually sent on the wire.  When someone is going to
send DTMF they are not likely to be talking before sending the tones so
the flushed write samples are expected to just contain silence.

* Made dahdi_digit_begin() flush the DAHDI write buffer after requesting
to send a DTMF digit.

ASTERISK-25315 #close
Reported by John Hardin

Change-Id: Ib56262c708cb7858082156bfc70ebd0a220efa6a

9 years agochan_dahdi.c: Lock private struct for ast_write(). 67/1067/1
Richard Mudgett [Wed, 5 Aug 2015 19:21:50 +0000 (14:21 -0500)] 
chan_dahdi.c: Lock private struct for ast_write().

There is a window of opportunity for DTMF to not go out if an audio frame
is in the process of being written to DAHDI while another thread starts
sending DTMF.  The thread sending the audio frame could be past the
currently dialing check before being preempted by another thread starting
a DTMF generation request.  When the thread sending the audio frame
resumes it will then cause DAHDI to stop the DTMF tone generation.  The
result is no DTMF goes out.

* Made dahdi_write() lock the private struct before writing to the DAHDI
file descriptor.

ASTERISK-25315
Reported by John Hardin

Change-Id: Ib4e0264cf63305ed5da701188447668e72ec9abb

9 years agores_pjsip.c: Fix crash from corrupt saved SUBSCRIBE message. 66/1066/1
Richard Mudgett [Mon, 10 Aug 2015 23:23:02 +0000 (18:23 -0500)] 
res_pjsip.c: Fix crash from corrupt saved SUBSCRIBE message.

If the saved SUBSCRIBE message is not parseable for whatever reason then
Asterisk could crash when libpjsip tries to parse the message and adds an
error message to the parse error list.

* Made ast_sip_create_rdata() initialize the parse error rdata list.  The
list is checked after parsing to see that it remains empty for the
function to return successful.

ASTERISK-25306
Reported by Mark Michelson

Change-Id: Ie0677f69f707503b1a37df18723bd59418085256

10 years agoMerge "res_pjsip: Ensure sanitized XML is NULL terminated." into certified/13.1
Joshua Colp [Fri, 7 Aug 2015 15:23:45 +0000 (10:23 -0500)] 
Merge "res_pjsip: Ensure sanitized XML is NULL terminated." into certified/13.1

10 years agores_pjsip_pubsub: More accurately persist packet. 45/1045/2
Mark Michelson [Thu, 6 Aug 2015 17:48:07 +0000 (12:48 -0500)] 
res_pjsip_pubsub: More accurately persist packet.

The pjsip_rx_data structure has a pkt_info.packet field on it that is
the packet that was read from the transport. For datagram transports,
the packet read from the transport will correspond to the SIP message
that arrived. For streamed transports, however, it is possible to read
multiple SIP messages in one packet.

In a recent case, Asterisk crashed on a system where TCP was being used.
This is because at some point, a read from the TCP socket resulted in a
200 OK response as well as an incoming SUBSCRIBE request being stored in
rdata->pkt_info.packet. When the SUBSCRIBE was processed, the
combination 200 OK and SUBSCRIBE was saved in persistent storage. Later,
a restart of Asterisk resulted in the crash because the persistent
subscription recreation code ended up building the 200 OK response
instead of a SUBSCRIBE request, and we attempted to access
request-specific data.

The fix here is to use the pjsip_msg_print() function in order to
persist SUBSCRIBE requests. This way, rather than using the raw socket
data, we use the parsed SIP message that PJSIP has given us. If we
receive multiple SIP messages from a single read, we will be sure only
to save off the relevant SIP message. There also is a safeguard put in
place to make sure that if we do end up reconstructing a SIP response,
it will not cause a crash.

ASTERISK-25306 #close
Reported by Mark Michelson

Change-Id: I4bf16f7b76a2541d10b55de82bcd14c6e542afb2

10 years agores_pjsip: Ensure sanitized XML is NULL terminated. 39/1039/2
Joshua Colp [Tue, 4 Aug 2015 21:12:59 +0000 (18:12 -0300)] 
res_pjsip: Ensure sanitized XML is NULL terminated.

The ast_sip_sanitize_xml function is used to sanitize
a string for placement into XML. This is done by examining
an input string and then appending values to an output
buffer. The function used by its implementation, strncat,
has specific behavior that was not taken into account.
If the size of the input string exceeded the available
output buffer size it was possible for the sanitization
function to write past the output buffer itself causing
a crash. The crash would either occur because it was
writing into memory it shouldn't be or because the resulting
string was not NULL terminated.

This change keeps count of how much remaining space is
available in the output buffer for text and only allows
strncat to use that amount.

Since this was exposed by the res_pjsip_pidf_digium_body_supplement
module attempting to send a large message the maximum allowed
message size has also been increased in it.

A unit test has also been added which confirms that the
ast_sip_sanitize_xml function is providing NULL terminated
output even when the input length exceeds the output
buffer size.

ASTERISK-25304 #close

Change-Id: I743dd9809d3e13d722df1b0509dfe34621398302

10 years agores_pjsip_session: Fix double re-INVITE collision crash. 41/1041/1
Richard Mudgett [Fri, 13 Feb 2015 17:21:28 +0000 (17:21 +0000)] 
res_pjsip_session: Fix double re-INVITE collision crash.

A multi-asterisk box setup with direct media enabled would occasionally
crash when two re-INVITE collisions on a call leg happen in a row.

The re-INVITE logic only had one timer struct to defer the re-INVITE.
When the second collision happens the timer struct is overwritten and put
into the timer heap again.  Resources for the first timer are leaked and
the heap has two positions occupied by the same timer struct.  Now the
heap ordering is potentially corrupted, the timer will fire twice, and any
resources allocated for the second timer will be released twice.

* The solution is to put the collided re-INVITE into the delayed requests
queue with all the other delayed requests and cherry pick the next request
that can come off the queue when an event happens.

* Changed to put delayed BYE requests at the head of the delayed queue.
There is no sense in processing delayed UPDATEs and re-INVITEs when a BYE
has been requested.

* Made the start of a BYE request flush the delayed requests queue to
prevent a delayed request from overlapping the BYE transaction.  I saw a
few cases where a delayed re-INVITE got started after the BYE transaction
started.

* Changed the delayed_request struct to use an enum instead of a string
for the request method.  Cherry picking the queue is easier with an enum
than string comparisons and the compiler can warn if a switch statement
does not cover all defined enum values.

* Improved the debug output to give more information.  It helps to know
which channel is involved with an endpoint.  Trunks can have many channels
associated with the endpoint at the same time.

ASTERISK-24727 #close
Reported by: Mark Michelson

Review: https://reviewboard.asterisk.org/r/4414/

Change-Id: Ib05700c3a13ceac53b17d66099ef0d296a5e1863

10 years agoFix problem where a hung channel could occur on a failed blind transfer. 76/976/1
Mark Michelson [Fri, 16 Jan 2015 22:12:25 +0000 (22:12 +0000)] 
Fix problem where a hung channel could occur on a failed blind transfer.

Different clients react differently to being told that a blind transfer
has failed. Some will simply send a BYE and be done with it. Others will
attempt to reinvite themselves back onto the call.

In the latter case, we were creating a new channel and then leaving it to
sit forever doing nothing. With this code change, that new channel will
not be created and the dialog with the transferring channel will be cleaned
up properly.

ASTERISK-24624 #close
Reported by Zane Conkle

Review: https://reviewboard.asterisk.org/r/4339

Change-Id: I76e440e08e603c1eea40a14951e7b171c0472a55

10 years agopjsip: Add rtp_timeout and rtp_timeout_hold endpoint options. 40/940/2
Joshua Colp [Sat, 18 Jul 2015 16:16:10 +0000 (13:16 -0300)] 
pjsip: Add rtp_timeout and rtp_timeout_hold endpoint options.

This change adds support for the 'rtp_timeout' and 'rtp_timeout_hold'
endpoint options. These allow the channel to be hung up if RTP
is not received from the remote endpoint for a specified number of
seconds.

ASTERISK-25259 #close

Change-Id: I3f39daaa7da2596b5022737b77799d16204175b9

10 years agoMerge "res_pjsip: Add rtp_keepalive endpoint option." into certified/13.1
Joshua Colp [Mon, 20 Jul 2015 20:52:09 +0000 (15:52 -0500)] 
Merge "res_pjsip: Add rtp_keepalive endpoint option." into certified/13.1

10 years agores_pjsip: Add rtp_keepalive endpoint option. 65/865/5
Mark Michelson [Thu, 9 Jul 2015 19:17:53 +0000 (14:17 -0500)] 
res_pjsip: Add rtp_keepalive endpoint option.

This adds an "rtp_keepalive" option for PJSIP endpoints. Similar to the
chan_sip option, this specifies an interval, in seconds, at which we
will send RTP comfort noise frames. This can be useful for keeping RTP
sessions alive as well as keeping NAT associations alive during lulls.

ASTERISK-25242 #close
Reported by Mark Michelson

Change-Id: I683bdc206c8c7def586ecaa64dcf2b86550be3bf

10 years agoMerge "chan_pjsip: Don't change formats when frame of unsupported format is received...
Matt Jordan [Mon, 20 Jul 2015 12:31:40 +0000 (07:31 -0500)] 
Merge "chan_pjsip: Don't change formats when frame of unsupported format is received." into certified/13.1

10 years agochan_pjsip: Don't change formats when frame of unsupported format is received. 04/904/3
Joshua Colp [Thu, 16 Jul 2015 14:46:14 +0000 (11:46 -0300)] 
chan_pjsip: Don't change formats when frame of unsupported format is received.

Receipt of an RTP packet currently causes the formats on an PJSIP channel to
change to the format of the RTP packet. In some off-nominal cases it's possible
for this to be a format that has not been configured or negotiated. This change
makes it so only formats explicitly configured on the endpoint are allowed.

ASTERISK-25258 #close

Change-Id: If93d641fb6418a285928839300d7854cab8c1020

10 years agoMerge "strings.h: Fix issues with escape string functions." into certified/13.1
Matt Jordan [Fri, 17 Jul 2015 13:50:37 +0000 (08:50 -0500)] 
Merge "strings.h: Fix issues with escape string functions." into certified/13.1

10 years agostrings.h: Fix issues with escape string functions. 19/919/1
Richard Mudgett [Wed, 15 Jul 2015 20:40:32 +0000 (15:40 -0500)] 
strings.h: Fix issues with escape string functions.

Fixes for issues with the ASTERISK-24934 patch.

* Fixed ast_escape_alloc() and ast_escape_c_alloc() if the s parameter is
an empty string.  If it were an empty string the functions returned NULL
as if there were a memory allocation failure.  This failure caused the AMI
VarSet event to not get posted if the new value was an empty string.

* Fixed dest buffer overwrite potential in ast_escape() and
ast_escape_c().  If the dest buffer size is smaller than the space needed
by the escaped s parameter string then the dest buffer would be written
beyond the end by the nul string terminator.  The num parameter was really
the dest buffer size parameter so I renamed it to size.

* Made nul terminate the dest buffer if the source string parameter s was
an empty string in ast_escape() and ast_escape_c().

* Updated ast_escape() and ast_escape_c() doxygen function description
comments to reflect reality.

* Added some more unit test cases to /main/strings/escape to cover the
empty source string issues.

ASTERISK-25255 #close
Reported by: Richard Mudgett

Change-Id: Id77fc704600ebcce81615c1200296f74de254104

10 years agores_parking: Fix crash if ATTENDEDTRANSFER set empty before Park. 16/916/1
Richard Mudgett [Tue, 14 Jul 2015 19:36:42 +0000 (14:36 -0500)] 
res_parking: Fix crash if ATTENDEDTRANSFER set empty before Park.

setup_park_common_datastore() was assuming that a non-NULL string returned
for the ATTENDEDTRANSFER and BLINDTRANSFER channel variables are not empty
strings.  Things got crashy as a result.

* Made setup_park_common_datastore() treat the channel variable values the
same whether they are NULL or empty for ATTENDEDTRANSFER and
BLINDTRANSFER.

ASTERISK-25254 #close
Reported by: Richard Mudgett

Change-Id: I9a9c174b33f354f35f82cc6b7cea8303adbaf9c2

10 years agobridge_native_rtp.c: Don't start native RTP bridging after attended transfer. 57/857/2
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

10 years agosorcery: Fix cache creation callback. 41/841/1
Joshua Colp [Tue, 26 May 2015 12:44:18 +0000 (09:44 -0300)] 
sorcery: Fix cache creation callback.

The cache creation callback function expects to receive a sorcery_details
structure and not just a standalone object.

Change-Id: Id2a9e5f271c466686e6d0def461fa50c8b2cae53

10 years agores_sorcery_memory_cache: Remove ASTERISK_REGISTER_FILE() macro. 37/837/2
Mark Michelson [Wed, 8 Jul 2015 19:39:40 +0000 (14:39 -0500)] 
res_sorcery_memory_cache: Remove ASTERISK_REGISTER_FILE() macro.

This was part of the backport of res_sorcery_memory_cache from master
but will not compile in 13.

Change-Id: I27b3d833acda9dd1770fdbe594964197b93779b0

10 years agores_sorcery_memory_cache: Execute stale unit test last. 35/835/1
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

10 years agores_sorcery_memory_cache: Remove 'prefetch' option. 34/834/1
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

10 years agotest_sorcery_memory_cache_thrash: Add unit tests for thrashing the memory cache. 33/833/1
Joshua Colp [Tue, 2 Jun 2015 15:20:00 +0000 (12:20 -0300)] 
test_sorcery_memory_cache_thrash: Add unit tests for thrashing the memory cache.

This change adds a CLI command which can perform memory cache thrashing as well
as unit tests which perform thrashing under the following configurations:

1. Low number of unique objects that go stale after 1 second
2. Low number of unique objects that expire after 1 second
3. Low number of unique objects which are constantly updated
4. Large number of unique objects which exceed a defined cache size
5. Large number of unique objects which exceed a defined cache size
   that also expire and go stale rapidly
6. Large number of unique objects which expire and go stale rapidly
7. Large number of unique objects

For all of the above there are a large number of threads constantly
attempting to retrieve random objects and each test runs for a few
seconds.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: I8c8ceff977332c80ed4a31f10d694d48552b2f78

10 years agores_sorcery_memory_cache: Implement expire_on_reload option. 32/832/1
Joshua Colp [Thu, 4 Jun 2015 18:11:44 +0000 (15:11 -0300)] 
res_sorcery_memory_cache: Implement expire_on_reload option.

This change implements the expire_on_reload option for memory caches.
If enabled and a reload is performed all objects within the cache
will be expired and the cache emptied.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: Id46aa1957d660556700e689e195eed57c989b85e

10 years agores_sorcery_memory_cache: Add test event when a refresh occurs. 31/831/1
Joshua Colp [Thu, 4 Jun 2015 10:33:30 +0000 (07:33 -0300)] 
res_sorcery_memory_cache: Add test event when a refresh occurs.

This change adds a testsuite event for when a refresh occurs.
This is useful as it provides a guaranteed mechanism of knowing when
it has occurred instead of waiting an arbitrary amount of time.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: Iaa6b8d2d6bab7f99ee08e1c8908b8272a8987e65

10 years agores_sorcery_memory_cache: Add CLI commands and AMI actions. 30/830/1
Joshua Colp [Tue, 26 May 2015 12:34:47 +0000 (09:34 -0300)] 
res_sorcery_memory_cache: Add CLI commands and AMI actions.

This change adds the following CLI commands and AMI actions:

sorcery memory cache show
sorcery memory cache dump
sorcery memory cache expire
sorcery memory cache stale

SorceryMemoryCacheExpire
SorceryMemoryCacheExpireObject
SorceryMemoryCacheStale
SorceryMemoryCacheStaleObject

These allow both examination and manipulation of sorcery memory
caches from external sources.

Cached objects can be explicitly expired from a cache or marked
as stale. If expired they are immediately removed. If marked as
stale they will be background refreshed when next retrieved.

ASTERISK-25067
Reported by Matt Jordan

Change-Id: I68e03cfd8c34b5e07f4b6ee4fd93a3f4a00a3d9e

10 years agores_sorcery_memory_cache: Add support for refreshing stale objects. 29/829/1
Mark Michelson [Tue, 26 May 2015 18:01:24 +0000 (13:01 -0500)] 
res_sorcery_memory_cache: Add support for refreshing stale objects.

This change introduces a check of object_lifetime_stale when retrieving
cached objects. If the amount of time the object has been in the cache
exceeds the lifetime, then a task is scheduled to update the cached
object based on an object retrieved from other sorcery wizards instead.

To prevent the cached object from being retrieved during a refresh,
thread-local storage is used to mark the thread as being a stale object
update. This results in the cache returning no object, leading to
sorcery querying other wizards for the object instead.

A test has been added for stale objects as well. This test ensures that
stale objects are retrieved the same as freshly-cached objects. The test
also ensures that after an object is stale, changes in the backend are
reflected in the cache, to include if the object has been deleted from
the backend.

ASTERISK-25067
Reported by Matt Jordan

Change-Id: I9bd7c049adf6939bfe2899f393c2bfbbf412d217

10 years agores_sorcery_memory_cache: Add support for object_lifetime_maximum. 28/828/1
Joshua Colp [Wed, 20 May 2015 22:35:54 +0000 (19:35 -0300)] 
res_sorcery_memory_cache: Add support for object_lifetime_maximum.

This makes the "object_lifetime_maximum" option operational.

On the addition of an object to an empty memory cache a scheduled
task is created which, when invoked, expires objects from the cache
which have exceeded their lifetime. If more objects have been added
the remaining life of the oldest object is used to schedule the
next invocation of the scheduled task.

If the oldest object is removed from the cache before it can be
expired automatically the scheduled task is cancelled, if possible,
and the lifetime of the next oldest is used to schedule the task.

If during these two operations no additional objects exist in the
cache then no task is scheduled.

An additional unit test has been added which verifies this
functionality.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: I87409674674a508e7717ee20739ca15cec6ba7b6

10 years agores_sorcery_memory_cache: Add support for maximum_objects. 27/827/1
Mark Michelson [Wed, 20 May 2015 20:19:27 +0000 (15:19 -0500)] 
res_sorcery_memory_cache: Add support for maximum_objects.

This makes the "maximum_objects" option operational.

A heap has been added alongside the hash table in the cache. When
objects are added to the cache, they are also added to the heap.
Similarly, when objects are removed from the cache, they are removed
from the heap.

The heap's use comes into play when an item is to be added to a "full"
cache. When the cache is full, the oldest item is removed from the
cache, using the heap to determine the oldest item.

A unit test has been added that verifies that the maximum_objects option
works as expected and that the oldest object is removed from the cache
when an object beyond the maximum is added.

ASTERISK-25067 #close
Reported by Matt Jordan

Change-Id: I490658830e9c4cbf0b3051e4cdc4913cf9f1b73a

10 years agores_sorcery_memory_cache: Add basic module implementation. 17/817/2
Joshua Colp [Sat, 16 May 2015 22:02:50 +0000 (19:02 -0300)] 
res_sorcery_memory_cache: Add basic module implementation.

This change adds a basic res_sorcery_memory_cache module which implements
configuration option parsing, configuration file parsing for threading,
sorcery interface implementation, and unit tests.

Objects can be added, updated, deleted, and retrieved from the memory
cache. Automatic expiration and stale handling will be added in the
future.

Note that unit tests exist within the module itself in case the
threading done as a result of expiration results in asynchronous
actions (which it likely will). Providing access and a notification
mechanism for an external test module would be complicated and
not worth it.

ASTERISK-25067 #close
Reported by: Matt Jordan

Change-Id: Id8a6a357ef5a83d466f81eee56a67d13eeb118b9

10 years agoapp: Add functions to swap vm function table 76/776/2
Jonathan Rose [Thu, 2 Jul 2015 22:03:51 +0000 (17:03 -0500)] 
app: Add functions to swap vm function table

This patch adds function-mocking methods for testing voicemail
features in external modules. It is being pulled over from r432556
on SVN because DPMA won't presently compile with TEST_FRAMEWORK
set in Asterisk 13.1 certified.

Change-Id: I1c2cf6d5a8589104154a86538ecd3f62a2694681

10 years agoMerge "res/res_corosync: Always decline module load, instead of failing" into certifi...
Joshua Colp [Tue, 30 Jun 2015 12:35:25 +0000 (07:35 -0500)] 
Merge "res/res_corosync: Always decline module load, instead of failing" into certified/13.1

10 years agores/res_corosync: Always decline module load, instead of failing 48/748/1
George Joseph [Wed, 22 Apr 2015 21:22:10 +0000 (15:22 -0600)] 
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

10 years agores_sorcery_realtime: Fix leak of sorcery object type. 46/746/2
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

10 years agores_pjsip_nat: Adjust when contact should be rewritten. 37/737/1
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

10 years agoMerge "res_pjsip_mwi: Set up unsolicited MWI upon registration." into certified/13.1
Mark Michelson [Fri, 26 Jun 2015 16:27:43 +0000 (11:27 -0500)] 
Merge "res_pjsip_mwi: Set up unsolicited MWI upon registration." into certified/13.1

10 years agores_pjsip_refer: Prevent sending duplicate headers. 31/731/1
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

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

10 years agores_pjsip_nat: Rewrite route set when required. 24/724/2
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

10 years agoAMI: Add Linkedid to the standard channel snapshot AMI event headers. 28/728/1
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

10 years agores_pjsip_mwi: Set up unsolicited MWI upon registration. 20/720/1
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

10 years agoMerge "bridge: When performing a blonde transfer update connected line information...
Matt Jordan [Sat, 13 Jun 2015 13:36:49 +0000 (08:36 -0500)] 
Merge "bridge: When performing a blonde transfer update connected line information." into certified/13.1

10 years agobridge: When performing a blonde transfer update connected line information. 43/643/2
Joshua Colp [Wed, 10 Jun 2015 23:28:26 +0000 (20:28 -0300)] 
bridge: When performing a blonde transfer update connected line information.

When performing a blonde transfer the code uses the old masquerade
mechanism to move a channel around. As a result of this certain information,
such as connected line, is moved between the channels involved. Upon
completion of the move a frame is queued which is supposed to update the
connected line information on the channel. This does not occur as the
code considers it a redundant update since the masquerade operation
updated the channel (but did not inform it of the new connected line
information). The code also does not queue a connected line update
to be handled by the thread handling the channel. Without this any
other channel that may be loosely involved does not know it is
talking to a different caller.

This change does the following to resolve this:

1. The indicated connected line information is cleared upon
completion of the masquerade operation when doing a blonde transfer.
This prevents the connected line update from being considered
redundant.

2. A connected line update frame is now queued upon the completion
of the masquerade operation so any other channel loosely involved
knows that there is a different caller.

ASTERISK-25157 #close
Reported by: Joshua Colp

Change-Id: Ibb8798184a1dab3ecd35299faecc420034adbf20

10 years agoapp_directory: Fix crash when using the alias option 'a'. 40/640/1
Richard Mudgett [Thu, 11 Jun 2015 19:39:45 +0000 (14:39 -0500)] 
app_directory: Fix crash when using the alias option 'a'.

The voicemail.conf mailbox key/value pair is defined as:
<mailbox>=[<password>[,<full-name>[,<email>[,<pager>[,<options>]]]]]
Where all fields in the value including the field values are optional.

Since the parsing code for the mailbox key/value pair is sloppy, this
patch tightens the parsing for the directory information.

* Renamed the 'pos' and 'bufptr' variables to 'name' and 'options'
respectively in search_directory_sub().  Those names make more sense.

* Made sure that search_directory_sub() is dealing with the voicemail.conf
mailbox options field if it even exists when looking for the 'hidefromdir'
and 'alias' options.

* Fix crash if a voicemail.conf mailbox is just
<mailbox>=<password>,<name> when the 'a' option is used.  If there were no
fields after the name then the 'options' pointer was not checked for NULL.

* Fix users.conf alias processing if the 'a' option is used.  The wrong
variable was used.

ASTERISK-25087 #close
Reported by: Chet Stevens

Change-Id: I86052ea77307beddddba5279824d39dc0d593374

10 years agoMerge "AMI: Escape string values." into certified/13.1
Joshua Colp [Mon, 8 Jun 2015 18:16:35 +0000 (13:16 -0500)] 
Merge "AMI: Escape string values." into certified/13.1

10 years ago.version: Update for certified/13.1-cert3-rc1
Matt Jordan [Mon, 8 Jun 2015 17:28:41 +0000 (12:28 -0500)] 
.version: Update for certified/13.1-cert3-rc1

10 years ago.lastclean: Update for certified/13.1-cert3-rc1
Matt Jordan [Mon, 8 Jun 2015 17:28:41 +0000 (12:28 -0500)] 
.lastclean: Update for certified/13.1-cert3-rc1

10 years agorealtime: Add database scripts for certified/13.1-cert3-rc1
Matt Jordan [Mon, 8 Jun 2015 17:28:41 +0000 (12:28 -0500)] 
realtime: Add database scripts for certified/13.1-cert3-rc1

10 years agoAMI: Escape string values. 02/602/1
Kevin Harwell [Mon, 8 Jun 2015 14:43:53 +0000 (09:43 -0500)] 
AMI: Escape string values.

So this issue is a bit complicated. Since it is possible to pass values to AMI
that contain a '\r\n' (or other similar sequences) these values need to be
escaped. One way to solve this is to escape the values and then pass the escaped
values to the AMI variable parameter string building function. However, this
puts the onus on the pre-build function to escape all string values. This
potentially requires a fair amount of changes along with a lot of string
allocations/freeing for all values.

Surely there is a way to push this complexity down a level into the string
building function itself? This of course is possible, but ends up requiring a
way to distinguish between strings that need to be escaped and those that don't.
The best way to handle this is by introducing a new format specifier in the
format string. For instance a %s (no escape) and %S (escape). However, that is
a bit weird and unexpected.

So faced with those possibilities this patch implements a limited version of the
first option. Instead of attempting to escape all string values this patch only
escapes those values that make sense. This approach limits the number of changes
and doesn't suffer from the odd format specifier problem.

ASTERISK-24934 #close
Reported by: warren smith

Change-Id: Ib55a5b84fe0481b0f2caaaab68c566f392c0aac0