4 years agobridge_softmix.c: Fix crash if channel fails to join mixing tech.
Richard Mudgett [Wed, 13 Apr 2016 18:20:23 +0000 (13:20 -0500)]
bridge_softmix.c: Fix crash if channel fails to join mixing tech.

softmix_bridge_join() failed because of an allocation failure.  To address
this, the softmix bridge technology now checks if the channel failed to
join softmix successfully.  In addition, the bridge now begins the process
of kicking the channel out of the bridge so we don't have channels
partially in the bridge for very long.

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

Change-Id: I97e2ade6a2bcd1214f24fb839fda948825b61a2b

4 years agoMerge "res_pjsip_callerid: Clear out display name if id->name is not valid"
Joshua Colp [Thu, 21 Apr 2016 19:02:09 +0000 (14:02 -0500)]
Merge "res_pjsip_callerid:  Clear out display name if id->name is not valid"

4 years agoMerge "lock.c: Check *lt before dereferencing it"
zuul [Thu, 21 Apr 2016 18:01:56 +0000 (13:01 -0500)]
Merge "lock.c: Check *lt before dereferencing it"

4 years agoMerge "stringfields: Update extended string fields for master only."
zuul [Thu, 21 Apr 2016 17:48:27 +0000 (12:48 -0500)]
Merge "stringfields:  Update extended string fields for master only."

4 years agolock.c: Check *lt before dereferencing it
Diederik de Groot [Thu, 21 Apr 2016 13:26:47 +0000 (15:26 +0200)]
lock.c: Check *lt before dereferencing it

*lt is NULL if t->tracking == 0

ASTERISK-25948 #close

Change-Id: I4a81af28f9c82a74aa82413d772a7dc8fa6f45ba

4 years agoMerge "Dial: Combine frame handling functions."
zuul [Wed, 20 Apr 2016 15:53:17 +0000 (10:53 -0500)]
Merge "Dial: Combine frame handling functions."

4 years agoMerge "pjproject: Add patch for removing strip of '[]' from header params"
Joshua Colp [Wed, 20 Apr 2016 13:17:30 +0000 (08:17 -0500)]
Merge "pjproject:  Add patch for removing strip of '[]' from header params"

4 years agores_pjsip_callerid: Clear out display name if id->name is not valid
George Joseph [Tue, 19 Apr 2016 22:52:15 +0000 (16:52 -0600)]
res_pjsip_callerid:  Clear out display name if id->name is not valid

When create_new_id_hdr creates a new RPID or PAI header, it starts by cloning
the From header, then it overwrites the display name and uri from the channel's  If the wasn't valid, create_new_id_hdr was
leaving the display name from the From header in the new RPID or PAI header.
On an attended transfer where the originator had a caller id number set but not
a display name, the re-INVITE to the final transferee had the number of the
originator but the display name of the transferer.

Added a check to clear out the display name in the new header if was invalid.

ASTERISK-25942 #close

Change-Id: I60b4bf7a7ece9b7425eba74151c0b4969cd2738b

4 years agoMerge "PJSIP: Remove PJSIP parsing functions from uri length validation."
zuul [Tue, 19 Apr 2016 21:53:52 +0000 (16:53 -0500)]
Merge "PJSIP: Remove PJSIP parsing functions from uri length validation."

4 years agoapp_talkdetect: Make the module core supported.
Joshua Colp [Tue, 19 Apr 2016 18:02:18 +0000 (15:02 -0300)]
app_talkdetect: Make the module core supported.

This module is used as part of testsuite tests to confirm
stuff works. I'm accordingly marking it as core as it is
required by those tests.

Change-Id: I558e7af7679b22b8ed641d7dd37ee4ca35b11e88

4 years agoPJSIP: Remove PJSIP parsing functions from uri length validation.
Mark Michelson [Mon, 18 Apr 2016 17:12:37 +0000 (12:12 -0500)]
PJSIP: Remove PJSIP parsing functions from uri length validation.

The PJSIP parsing functions provide a nice concise way to check the
length of a hostname in a SIP URI. The problem is that in order to use
those parsing functions, it's required to use them from a thread that
has registered with PJLib.

On startup, when parsing AOR configuration, the permanent URI handler
may not be run from a PJLib-registered thread. Specifically, this could
happen when Asterisk was started in daemon mode rather than
console-mode. If PJProject were compiled with assertions enabled, then
this would cause Asterisk to crash on startup.

The solution presented here is to do our own parsing of the contact URI
in order to ensure that the hostname in the URI is not too long. The
parsing does not attempt to perform a full SIP URI parse/validation,
since the hostname in the URI is what is important.

ASTERISK-25928 #close
Reported by Joshua Colp

Change-Id: Ic3d6c20ff3502507c17244a8b7e2ca761dc7fb60

4 years agoMerge "app_queue: Frequent segfaults in function can_ring_entry()"
Joshua Colp [Tue, 19 Apr 2016 14:49:17 +0000 (09:49 -0500)]
Merge "app_queue: Frequent segfaults in function can_ring_entry()"

4 years agoMerge "stasis_bridge.c: Update stasis bridge push diagnostic messages."
Joshua Colp [Tue, 19 Apr 2016 14:42:45 +0000 (09:42 -0500)]
Merge "stasis_bridge.c: Update stasis bridge push diagnostic messages."

4 years agoMerge "res_pjsip_transport_management: Allow unload to occur."
Joshua Colp [Tue, 19 Apr 2016 14:40:59 +0000 (09:40 -0500)]
Merge "res_pjsip_transport_management: Allow unload to occur."

4 years agoMerge "bridge_channel.c: Ignore role setup failure in channel push."
Joshua Colp [Tue, 19 Apr 2016 14:37:36 +0000 (09:37 -0500)]
Merge "bridge_channel.c: Ignore role setup failure in channel push."

4 years agores_pjsip_registrar: Fix bad memory-ness with user_agent.
Mark Michelson [Mon, 18 Apr 2016 22:00:42 +0000 (17:00 -0500)]
res_pjsip_registrar: Fix bad memory-ness with user_agent.

Recent changes to the PJSIP registrar resulted in tests failing due to
missing AOR_CONTACT_ADDED test events. The reason for this was that the
user_agent string had junk values in it, resulting in being unable to
generate the event.

I'm going to be honest here, I have no idea why this was happening. Here
are the steps needed for the user_agent variable to get messed up:
* REGISTER is received
* First contact in the REGISTER results in a contact being removed
* Second contact in the REGISTER results in a contact being added
* The contact, AOR, expiration, and user agent all have to be passed as
  format parameters to the creation of a string. Any subset of those
  parameters would not be enough to cause the problem.

Looking into what was happening, the thing that struck me as odd was
that the user_agent variable was meant to be set to the value of the
User-Agent SIP header in the incoming REGISTER. However, when removing a
contact, the user_agent variable would be set (via ast_strdupa inside a
loop) to the stored contact's user_agent. This means that the
user_agent's value would be incorrect when attempting to process further
contacts in the incoming REGISTER.

The fix here is to use a different variable for the stored user agent
when removing a contact. Correcting the behavior to be correct also
means the memory usage is less weird, and the issue no longer occurs.

ASTERISK-25929 #close
Reported by Joshua Colp

Change-Id: I7cd24c86a38dec69ebcc94150614bc25f46b8c08

4 years agores_pjsip_transport_management: Allow unload to occur.
Joshua Colp [Mon, 18 Apr 2016 18:41:34 +0000 (15:41 -0300)]
res_pjsip_transport_management: Allow unload to occur.

At shutdown it is possible for modules to be unloaded that wouldn't
normally be unloaded. This allows the environment to be cleaned up.

The res_pjsip_transport_management module did not have the unload
logic in it to clean itself up causing the res_pjsip module to not
get unloaded. As a result the res_pjsip monitor thread kept going
processing traffic and timers when it shouldn't.

Change-Id: Ic8cadee131e3b2c436a81d3ae8bb5775999ae00a

4 years agobridge_channel.c: Ignore role setup failure in channel push.
Richard Mudgett [Fri, 15 Apr 2016 16:41:49 +0000 (11:41 -0500)]
bridge_channel.c: Ignore role setup failure in channel push.

We have to setup the channel roles after the bridge class push is called
because the bridge class push callback may have set roles on the incoming
channel.  Since we have already partially pushed the channel into the
bridge and reversing what we have already done could be problematic, the
only thing we can do is press on to complete pushing the channel into the

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

Change-Id: I08a97082b729052ee65cdca6bb730cf1289ede00

4 years agochan_sip: Don't verify table if rtupdate=no
Jaco Kroon [Sun, 17 Apr 2016 20:37:53 +0000 (22:37 +0200)]
chan_sip: Don't verify table if rtupdate=no

If rtupdate=no do not verify sipregs/peers table has updatable fields.

ASTERISK-25934 #close

Change-Id: Iaa2c53037b93daccc7e7333c40d61861847b856d

4 years agoMerge "Codecs: strip codec name while parsing allow/disallow options"
Joshua Colp [Mon, 18 Apr 2016 10:31:17 +0000 (05:31 -0500)]
Merge "Codecs: strip codec name while parsing allow/disallow options"

4 years agoapp_queue: Frequent segfaults in function can_ring_entry()
ibercom [Mon, 18 Apr 2016 09:53:14 +0000 (11:53 +0200)]
app_queue: Frequent segfaults in function can_ring_entry()

ASTERISK-25888 #close

Change-Id: I007a2f2dd99823e04fb5be3ff01f02b0a2956117

4 years agostasis_bridge.c: Update stasis bridge push diagnostic messages.
Richard Mudgett [Fri, 15 Apr 2016 21:51:58 +0000 (16:51 -0500)]
stasis_bridge.c: Update stasis bridge push diagnostic messages.

Change-Id: I195b14994c9dcccb9452491ca20a885d2a54605a

4 years agoMerge "app_voicemail/IMAP: function 'save_to_folder' creates wrong folder"
Joshua Colp [Fri, 15 Apr 2016 19:37:28 +0000 (14:37 -0500)]
Merge "app_voicemail/IMAP: function 'save_to_folder' creates wrong folder"

4 years agoDial: Combine frame handling functions.
Mark Michelson [Tue, 12 Apr 2016 19:55:42 +0000 (14:55 -0500)]
Dial: Combine frame handling functions.

There is a good amount of repetition in the two frame handling routines
in the Dial API. This commit combines the two functions into one.

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

Reported by Mark Michelson

Change-Id: Iaae2f174e3058e774cb44e10659fcdfb85345c58

4 years agoCodecs: strip codec name while parsing allow/disallow options
Alexei Gradinari [Mon, 11 Apr 2016 21:20:49 +0000 (17:20 -0400)]
Codecs: strip codec name while parsing allow/disallow options

Failed registration using PJSIP/Realtime if one of the codec name
in allow/disallow option is wrong or contains space.

This patch strip codec name.


Change-Id: Ifdf02de94e5ddbce305640f6f0666084a3b9283d

4 years agotransport management: Register thread with PJProject.
Mark Michelson [Thu, 14 Apr 2016 18:49:35 +0000 (13:49 -0500)]
transport management: Register thread with PJProject.

The scheduler thread that kills idle TCP connections was not registering
with PJProject properly and causing assertions if PJProject was built in
debug mode.

This change registers the thread with PJProject the first time that the
scheduler callback executes.


Change-Id: I5f7a37e2c80726a99afe9dc2a4a69bdedf661283

4 years agoMerge "res_pjsip_transport_management: Kill idle TCP connections."
Joshua Colp [Thu, 14 Apr 2016 18:02:32 +0000 (13:02 -0500)]
Merge "res_pjsip_transport_management: Kill idle TCP connections."

4 years agoMerge "Rename res_pjsip_keepalive res_pjsip_transport_management"
Joshua Colp [Thu, 14 Apr 2016 18:01:00 +0000 (13:01 -0500)]
Merge "Rename res_pjsip_keepalive res_pjsip_transport_management"

4 years agoMerge "AST-2016-004: Fix crash on REGISTER with long URI."
Joshua Colp [Thu, 14 Apr 2016 17:59:31 +0000 (12:59 -0500)]
Merge "AST-2016-004: Fix crash on REGISTER with long URI."

4 years agores_pjsip_transport_management: Kill idle TCP connections.
Mark Michelson [Tue, 8 Mar 2016 18:12:16 +0000 (12:12 -0600)]
res_pjsip_transport_management: Kill idle TCP connections.

"Idle" here means that someone connects to us and does not send a SIP
request. PJProject will not automatically time out such connections, so
it's up to Asterisk to do it instead.

When we receive an incoming TCP connection, we will start a timer
(equivalent to transaction timer D) waiting to receive an incoming
request. If we do not receive a request in that timeframe, then we will
shut down the TCP connection.

ASTERISK-25796 #close
Reported by George Joseph


Change-Id: I7b0d303e5d140d0ccaf2f7af562071e3d1130ac6

4 years agoRename res_pjsip_keepalive res_pjsip_transport_management
Mark Michelson [Tue, 8 Mar 2016 16:52:19 +0000 (10:52 -0600)]
Rename res_pjsip_keepalive res_pjsip_transport_management

Reported by George Joseph


Change-Id: Id322a05f927392293570599730050bc677d99433

4 years agoAST-2016-004: Fix crash on REGISTER with long URI.
Mark Michelson [Thu, 14 Apr 2016 12:23:54 +0000 (07:23 -0500)]
AST-2016-004: Fix crash on REGISTER with long URI.

Due to some ignored return values, Asterisk could crash if processing an
incoming REGISTER whose contact URI was above a certain length.

ASTERISK-25707 #close
Reported by George Joseph



Change-Id: I3ea7cee16f29c8088794de3085ca7523c1c4833d

4 years agobridge_softmix.c: Fix crash if could not allocate the dsp.
Richard Mudgett [Tue, 12 Apr 2016 18:10:47 +0000 (13:10 -0500)]
bridge_softmix.c: Fix crash if could not allocate the dsp.

Fix off nominal crash where we could not setup the channel to process
frames for the softmix bridge technology because of allocation failure.

Change-Id: Ic307a8386e46bf551e48fcd1eb97276714d56372

4 years agostringfields: Update extended string fields for master only.
George Joseph [Wed, 13 Apr 2016 18:38:01 +0000 (12:38 -0600)]
stringfields:  Update extended string fields for master only.

In 13, the new ast_string_field_header structure had to be dynamically
allocated and assigned to a pointer in ast_string_field_mgr to preserve ABI
compatability.  In master, it can be converted to being a structure-in-place in
ast_string_field_mgr to eliminate the extra alloc and free calls.

Change-Id: Ia97c5345eec68717a15dc16fe2e6746ff2a926f4

4 years agoMerge "app_voicemail: Fix test_voicemail_notify_endl test."
Joshua Colp [Wed, 13 Apr 2016 10:21:05 +0000 (05:21 -0500)]
Merge "app_voicemail: Fix test_voicemail_notify_endl test."

4 years agopjproject: Add patch for removing strip of '[]' from header params
George Joseph [Tue, 12 Apr 2016 20:41:43 +0000 (14:41 -0600)]
pjproject:  Add patch for removing strip of '[]' from header params

From the patch submitted to Teluu on 4/12/2016
The wholesale stripping of '[]' from header parameters causes issues if
something (like a port) occurs after the final ']'.

'[2001:a::b]' will correctly parse to '2001:a::b'
'[2001:a::b]:8080' will correctly parse to '2001:a::b' but the scanner is left
with ':8080' and parsing stops with a syntax error.

I can't even find a case where stripping the '[]' is a good thing anyway.  Even
if you continued to parse and resulted in a string that looks like this...
'2001:a::b:8080', it's not valid.

This came up in Asterisk because Kamailio sends us a Contact with an alias
URI parameter that has an IPv6 address in it like this:
Contact: <sip:1171@;alias=[2001:1:2::3]~43691~6>
which should be legal but causes a syntax error because of the characters
after the final ']'.  Even if it didn't, the '[]' should still not be stripped.

I've run the Asterisk Test Suite for PJSIP (252 tests) many of which are IPv6
enabled.  No issues were caused by removing the code that strips the '[]'.

ASTERISK-25123 #close
Reported-by: Anthony Messina

Change-Id: I5cb33f4ebf07ee1f2b26d07caae715e2ec65595a

4 years agoMerge "res_pjsip_dialog_info: Add missing "direction" attribute in NOTIFY event"
Joshua Colp [Tue, 12 Apr 2016 18:29:20 +0000 (13:29 -0500)]
Merge "res_pjsip_dialog_info: Add missing "direction" attribute in NOTIFY event"

4 years agoapp_voicemail: Fix test_voicemail_notify_endl test.
Joshua Colp [Tue, 12 Apr 2016 14:10:45 +0000 (11:10 -0300)]
app_voicemail: Fix test_voicemail_notify_endl test.

The test_voicemail_notify_endl test checks the end-of-line
characters of an email message to confirm that they are consistent.
The test wrongfully assumed that reading from the email message
into a buffer will always result in more than 1 character being
read. This is incorrect. If only 1 character was read the test
would go outside of the buffer and access other memory causing
a crash.

The test now checks to ensure that 2 or more characters are read
in ensuring the test stays within the buffer.

ASTERISK-25874 #close

Change-Id: Ic2c89cea6e90f2c0bc2d8138306ebbffd4f8b710

4 years agoapp_voicemail/IMAP: function 'save_to_folder' creates wrong folder
Alexei Gradinari [Thu, 7 Apr 2016 17:02:19 +0000 (13:02 -0400)]
app_voicemail/IMAP: function 'save_to_folder' creates wrong folder

If try to move message to Cust1 (number 5)
the function 'save_to_folder' tries to create Greeting folder instead of Cust1.

This patch fixed it by setting GREETINGS_FOLDER = -1

ASTERISK-24927 #close

Change-Id: I03d1a761894bcc2d130ec9b003bbcddc28e25c51

4 years agores_pjsip: Add headers to AMI Event ContactStatusDetail
Alexei Gradinari [Thu, 7 Apr 2016 21:18:03 +0000 (17:18 -0400)]
res_pjsip: Add headers to AMI Event ContactStatusDetail

* Added Useragent and RegExpire headers to AMI Event
ContactStatusDetail with associated documentation.

ASTERISK-25903 #close

Change-Id: If3d121e943e588d016ba51d4eb9c6a421a562239

4 years agoMerge "res_pjsip_outbound_publish: Add transport for outbound PUBLISH"
zuul [Tue, 12 Apr 2016 02:26:08 +0000 (21:26 -0500)]
Merge "res_pjsip_outbound_publish: Add transport for outbound PUBLISH"

4 years agoMerge "alembic: Remove batch operations (and sqlite support)"
Joshua Colp [Tue, 12 Apr 2016 00:36:23 +0000 (19:36 -0500)]
Merge "alembic:  Remove batch operations (and sqlite support)"

4 years agoMerge "core_unreal: Fix hangupcauses not getting set on Local channels"
Joshua Colp [Mon, 11 Apr 2016 21:37:34 +0000 (16:37 -0500)]
Merge "core_unreal: Fix hangupcauses not getting set on Local channels"

4 years agoMerge "res_pjsip contact: Lock expiration/addition of contacts"
zuul [Mon, 11 Apr 2016 21:29:34 +0000 (16:29 -0500)]
Merge "res_pjsip contact:  Lock expiration/addition of contacts"

4 years agores_pjsip_outbound_publish: Add transport for outbound PUBLISH
Alexei Gradinari [Tue, 5 Apr 2016 21:56:39 +0000 (17:56 -0400)]
res_pjsip_outbound_publish: Add transport for outbound PUBLISH

The first available transport of the appropriate type is used now.
This patch adds new config option 'transport' for outbound-publish.
If transport is set then outbound PUBLISH requests will use this transport.

ASTERISK-25901 #close

Change-Id: Ib389130489b70e36795b0003fa5fd386e2680151

4 years agocore_unreal: Fix hangupcauses not getting set on Local channels
Jaco Kroon [Mon, 11 Apr 2016 19:26:57 +0000 (21:26 +0200)]
core_unreal: Fix hangupcauses not getting set on Local channels

ASTERISK-25912 #close

Change-Id: I8e72e6894feaf36c9450f2788d205d07baec23aa

4 years agoMerge "app_voicemail/IMAP: IMAP access FATAL error: Out of memory"
zuul [Mon, 11 Apr 2016 19:21:21 +0000 (14:21 -0500)]
Merge "app_voicemail/IMAP: IMAP access FATAL error: Out of memory"

4 years agores_pjsip contact: Lock expiration/addition of contacts
George Joseph [Fri, 1 Apr 2016 18:30:56 +0000 (12:30 -0600)]
res_pjsip contact:  Lock expiration/addition of contacts

Contact expiration can occur in several places:  res_pjsip_registrar,
res_pjsip_registrar_expire, and automatically when anyone calls
ast_sip_location_retrieve_aor_contact.  At the same time, res_pjsip_registrar
may also be attempting to renew or add a contact.  Since none of this was locked
it was possible for one thread to be renewing a contact and another thread to
expire it immediately because it was working off of stale data.  This was the
casue of intermittent registration/inbound/nominal/multiple_contacts test

Now, the new named lock functionality is used to lock the aor during contact
expire and add operations and res_pjsip_registrar_expire now checks the
expiration with the lock held before deleting the contact.

ASTERISK-25885 #close
Reported-by: Josh Colp

Change-Id: I83d413c46a47796f3ab052ca3b349f21cca47059

4 years agoMerge "lock: Add named lock capability"
Joshua Colp [Mon, 11 Apr 2016 17:58:44 +0000 (12:58 -0500)]
Merge "lock:  Add named lock capability"

4 years agopjproject: Add patch to fix Via IPv6 parsing
George Joseph [Sun, 10 Apr 2016 19:16:42 +0000 (13:16 -0600)]
pjproject:  Add patch to fix Via IPv6 parsing

There's a bug in pjproject's sip_parser where the ":" wasn't correctly
interpreted. This is causing IPv6 addresses in the "received" parameter of the
Via header to cause a syntax check failure.

This patch was submitted to Teluu on 4/10/2016.

ASTERISK-25910 #close
Reported-by: Anthony Messina

Change-Id: Ic7e4c4aa14ded61860401ec349f5177568c4d922

4 years agoMerge "pbx.h: Make ast_state_cb_type take more const."
Joshua Colp [Fri, 8 Apr 2016 20:47:50 +0000 (15:47 -0500)]
Merge "pbx.h: Make ast_state_cb_type take more const."

4 years agolock: Add named lock capability
George Joseph [Fri, 1 Apr 2016 01:04:29 +0000 (19:04 -0600)]
lock:  Add named lock capability

Locking some objects like sorcery objects can be tricky because the underlying
ao2 object may not be the same for all callers.  For instance, two threads that
call ast_sorcery_retrieve_by_id on the same aor name might actually get 2
different ao2 objects if the underlying wizard had to rehydrate the aor from a
database. Locking one ao2 object doesn't have any effect on the other even if
those objects had locks in the first place.

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

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

Change-Id: If258c0b7f92b02d07243ce70e535821a1ea7fb45

4 years agoapp_voicemail/IMAP: IMAP access FATAL error: Out of memory
Alexei Gradinari [Thu, 7 Apr 2016 16:37:43 +0000 (12:37 -0400)]
app_voicemail/IMAP: IMAP access FATAL error: Out of memory

Sometimes uw-imap function 'mail_fetchbody' returns huge len
which then pass to uw-imap function 'rfc822_base64'.
uw-imap tries to allocate huge memory and abort() on fail.

This patch check the len.
If the len more than max size (128 Mbytes) log error.
This patch also set variables len, newlen to avoid uninizialezed len.
This patch also check pointer returned by rfc822_base64.

ASTERISK-25899 #close

Change-Id: I4a0e7d655f11abef6a5224e2169df6d5c1f1caca

4 years agoMerge "pbx.c: Minor code rearangements."
Joshua Colp [Fri, 8 Apr 2016 16:59:55 +0000 (11:59 -0500)]
Merge "pbx.c: Minor code rearangements."

4 years agores_pjsip_dialog_info: Add missing "direction" attribute in NOTIFY event
Alexei Gradinari [Thu, 7 Apr 2016 21:39:19 +0000 (17:39 -0400)]
res_pjsip_dialog_info: Add missing "direction" attribute in NOTIFY event

BLF pickup isn't working on Cisco SPA and Snom phones
if the direction="recipient" attribute is missing in 'dialog' tag.

This patch adds direction="recipient" if extension state is

ASTERISK-24601 #close

Change-Id: I5b2c097ca29fd59e92ba237ca5d397cb1b0bcd8c

4 years agopbx.h: Make ast_state_cb_type take more const.
Richard Mudgett [Wed, 6 Apr 2016 22:57:20 +0000 (17:57 -0500)]
pbx.h: Make ast_state_cb_type take more const.

This eliminates some casts that I made a note saying v10 and above
would no longer need them.

Better late than never :)

Change-Id: I346cdb3032b6478ceb40eb6fe732978b54035572

4 years agopbx.c: Minor code rearangements.
Richard Mudgett [Thu, 7 Apr 2016 15:59:13 +0000 (10:59 -0500)]
pbx.c: Minor code rearangements.

* Pull out a loop invariant.

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

Change-Id: I0a95cfa9474a4600b9865f7b444534d275b37e95

4 years agopbx: Update doxygen for extension state watchers.
Richard Mudgett [Thu, 7 Apr 2016 17:26:57 +0000 (12:26 -0500)]
pbx: Update doxygen for extension state watchers.

Change-Id: Id1403b12136de62a272c01bb355aef65fd2c2d1e

4 years agoMerge "pbx: Add support for autohints."
Joshua Colp [Thu, 7 Apr 2016 20:11:17 +0000 (15:11 -0500)]
Merge "pbx: Add support for autohints."

4 years agoalembic: Remove batch operations (and sqlite support)
George Joseph [Thu, 7 Apr 2016 16:49:43 +0000 (10:49 -0600)]
alembic:  Remove batch operations (and sqlite support)

Because SQLite doesn't support full ALTER capabilities, alembic scripts
require batch operations.  However, that capability wasn't available until
0.7.0 which some distributions haven't reached yet.  Therefore, the batch
operations introduced in commit 86d6e44cc (review 2319) have been reverted
and SQLite is unsupported again, for now anyway.

Tested the full upgrade and downgrade on MySQL/Mariadb and Postgresql.

ASTERISK-25890 #close
Reported-by: Harley Peters

Change-Id: I82eba5456736320256f6775f5b0b40133f4d1c80

4 years agores_pjsip_registrar_expire: Fix race condition at shutdown.
Joshua Colp [Thu, 7 Apr 2016 16:05:26 +0000 (13:05 -0300)]
res_pjsip_registrar_expire: Fix race condition at shutdown.

When shutting down, the PJSIP sorcery is destroyed. The registrar
expiration module queries the PJSIP sorcery to determine what
to expire. As there was no synchronization between termination
of the expiration thread and the unloading of the module it was
possible for the thread to try to access the PJSIP sorcery after
it had been destroyed.

This change ensures that the thread is shut down before allowing
the module to be considered unloaded.

Change-Id: I69fd239edbaaf160c2d37ae00d3ac06e5596fe8b

4 years agores_pjsip: Fix configuration setting of "regcontext".
Joshua Colp [Wed, 6 Apr 2016 21:28:49 +0000 (18:28 -0300)]
res_pjsip: Fix configuration setting of "regcontext".

Due to a merge problem two options were swapped causing the
regcontext setting to not get set.

Change-Id: Icb33edc668e7357bacbaec2861a6b5ac64edaff1

4 years agoframe.c: Copy the whole subclass in ast_frdup().
Jacek Konieczny [Wed, 6 Apr 2016 13:01:47 +0000 (15:01 +0200)]
frame.c: Copy the whole subclass in ast_frdup().

The problem is ast_frdup() does not copy whole frame.subclass for voice,
video and image frames, only the format is copied.  For video frames, the
subclass structure contains the .frame_ending flag used to put the RTP
marker where it needs to be.

ASTERISK-25894 #close

Change-Id: I812ca90e84ed5d4f473b997d0dd0d3c5a915fe33

4 years agoMerge "res_pjsip: Handle deferred SDP hold/unhold properly."
Joshua Colp [Wed, 6 Apr 2016 12:52:56 +0000 (07:52 -0500)]
Merge "res_pjsip: Handle deferred SDP hold/unhold properly."

4 years agoMerge "ARI: Add method to Dial a created channel."
Joshua Colp [Wed, 6 Apr 2016 10:43:47 +0000 (05:43 -0500)]
Merge "ARI: Add method to Dial a created channel."

4 years agoMerge "ARI: Add method to create a new channel."
Joshua Colp [Wed, 6 Apr 2016 10:43:36 +0000 (05:43 -0500)]
Merge "ARI: Add method to create a new channel."

4 years agoARI: Add method to Dial a created channel.
Mark Michelson [Wed, 30 Mar 2016 22:18:39 +0000 (17:18 -0500)]
ARI: Add method to Dial a created channel.

This adds a new ARI method that allows for you to dial a channel that
you previously created in ARI.

By combining this with the create method for channels, it allows for a
workflow where a channel can be created, manipulated, and then dialed.
The channel is under control of the ARI application during all stages of
the Dial and can even be manipulated based on channel state changes
observed within an ARI application.

The overarching goal for this is to eventually be able to add a dialed
channel to a Stasis bridge earlier than the "Up" state. However, at the
moment more work is needed in the Dial and Bridge APIs in order to
facilitate that.

ASTERISK-25889 #close

Change-Id: Ic6c399c791e66c4aa52454222fe4f8b02483a205

4 years agoARI: Add method to create a new channel.
Mark Michelson [Wed, 30 Mar 2016 22:01:28 +0000 (17:01 -0500)]
ARI: Add method to create a new channel.

This adds a new ARI method to the channels resource that allows for the
creation of a new channel. The channel is created and then placed into
the specified Stasis application.

This is different from the existing originate method that creates a
channel, dials it, and then places the answered channel into the
dialplan or a Stasis application. This method does not attempt to call
the channel at all. Dialing is left as a later step after channel
creation. This allows for pre-dialing channel manipulation if desired.


Change-Id: I3c96a0aba914b08e39f6256371a5bd4c92cbded8

4 years agoMerge "Dial: Add function to append already-created channel."
Joshua Colp [Tue, 5 Apr 2016 23:12:37 +0000 (18:12 -0500)]
Merge "Dial: Add function to append already-created channel."

4 years agoMerge "config: Allow filters when appending to a category"
Joshua Colp [Tue, 5 Apr 2016 21:38:11 +0000 (16:38 -0500)]
Merge "config:  Allow filters when appending to a category"

4 years agopbx: Add support for autohints.
Joshua Colp [Mon, 28 Mar 2016 16:31:29 +0000 (13:31 -0300)]
pbx: Add support for autohints.

This change introduces the concept of autohints. These are hints
which are created as a result of device state changes occurring within
the core. When this happens a hint will be created (if it does not
exist already) using the device name as the extension.

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

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

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

ASTERISK-25881 #close

Change-Id: I7e444c7da41b7b7d33374420fec658beeb18584e

4 years agores_pjsip: Handle deferred SDP hold/unhold properly.
Mark Michelson [Tue, 5 Apr 2016 19:23:35 +0000 (14:23 -0500)]
res_pjsip: Handle deferred SDP hold/unhold properly.

Some SIP devices indicate hold/unhold using deferred SDP reinvites. In
other words, they provide no SDP in the reinvite.

A typical transaction that starts hold might look something like this:

* Device sends reinvite with no SDP
* Asterisk sends 200 OK with SDP indicating sendrecv on streams.
* Device sends ACK with SDP indicating sendonly on streams.

At this point, PJMedia's SDP negotiator saves Asterisk's local state as
being recvonly.

Now, when the device attempts to unhold, it again uses a deferred SDP
reinvite, so we end up doing the following:

* Device sends reinvite with no SDP
* Asterisk sends 200 OK with SDP indicating recvonly on streams
* Device sends ACK with SDP indicating sendonly on streams

The problem here is that Asterisk offered recvonly, and by RFC 3264's
rules, if an offer is recvonly, the answer has to be sendonly. The
result is that the device is not taken off hold.

What is supposed to happen is that Asterisk should indicate sendrecv in
the 200 OK that it sends. This way, the device has the freedom to
indicate sendrecv if it wants the stream taken off hold, or it can
continue to respond with sendonly if the purpose of the reinvite was
something else (like a session timer refresher).

The fix here is to alter the SDP negotiator's state when we receive a
reinvite with no SDP. If the negotiator's state is currently in the
recvonly or inactive state, then we alter our local state to be
sendrecv. This way, we allow the device to indicate the stream state as

ASTERISK-25854 #close
Reported by Robert McGilvray

Change-Id: I7615737276165eef3a593038413d936247dcc6ed

4 years agoDial: Add function to append already-created channel.
Mark Michelson [Wed, 30 Mar 2016 21:47:15 +0000 (16:47 -0500)]
Dial: Add function to append already-created channel.

The Dial API takes responsiblity for creating an outbound channel when
calling ast_dial_append(). This commit adds a new function,
ast_dial_append_channel(), which allows us to create the channel outside
the Dial API and then to append the channel to the ast_dial structure.

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


Change-Id: Id8179f64f8f99132f80dead8d5db2030fd2c0509

4 years agoMerge "res_http_websocket: Make core supported."
Joshua Colp [Tue, 5 Apr 2016 16:41:01 +0000 (11:41 -0500)]
Merge "res_http_websocket: Make core supported."

4 years agoMerge "stringfields: Refactor to allow fields to be added to the end of structures"
Joshua Colp [Tue, 5 Apr 2016 16:40:40 +0000 (11:40 -0500)]
Merge "stringfields:  Refactor to allow fields to be added to the end of structures"

4 years agoconfig: Allow filters when appending to a category
George Joseph [Mon, 28 Mar 2016 04:33:29 +0000 (22:33 -0600)]
config:  Allow filters when appending to a category

In sorcery based config files where there are multiple categories with the same
name, you can't use the (+) operator to reliably append to a category because
config.c stops looking when it finds the first one with the same name.


type = endpoint

type = aor

authenticate_qualify = yes

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


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

type = endpoint

type = aor

authenticate_qualify = yes

This now works as expected.

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


ASTERISK-25868 #close
Reported-by: Nick Repin

Change-Id: I10773da4c79db36fbf1993961992af63d3441580

4 years agores_http_websocket: Make core supported.
Joshua Colp [Tue, 5 Apr 2016 15:21:32 +0000 (12:21 -0300)]
res_http_websocket: Make core supported.

Websockets are a core part of ARI support and as such this
module should also be core supported.

Change-Id: I8f9283c6a167152761b92984779bb39e3db51a9c

4 years agoMerge "res_rtp_asterisk: Use separate SRTP session for RTCP with DTLS"
Joshua Colp [Tue, 5 Apr 2016 10:37:44 +0000 (05:37 -0500)]
Merge "res_rtp_asterisk: Use separate SRTP session for RTCP with DTLS"

4 years agostringfields: Refactor to allow fields to be added to the end of structures
George Joseph [Sat, 26 Mar 2016 04:22:34 +0000 (22:22 -0600)]
stringfields:  Refactor to allow fields to be added to the end of structures

String fields are great, except that you can't add new ones without breaking
ABI compatibility because it shifts down everything else in the structure.
The only alternative is to add your own char * field to the end of the
structure and manage the memory yourself which isn't ideal, especially since
you then can't use the OPT_STRINGFIELD_T type.


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

Solution: Extended String Fields

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


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

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

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


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

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

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

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


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

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

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

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

Change-Id: I235db338c5b178f5a13b7946afbaa5d4a0f91d61

4 years agores_pjsip_mwi: Fix segv caused by 16c7d8e74a9af13f98c3c22aa9c43ce39965f6b7
George Joseph [Mon, 4 Apr 2016 23:02:09 +0000 (17:02 -0600)]
res_pjsip_mwi:  Fix segv caused by 16c7d8e74a9af13f98c3c22aa9c43ce39965f6b7

I forgot the new voicemail_extension wasn't a stringfield and didn't check
for NULL where I should have.

Change-Id: I029482d5c2ab72474838750461bd46b0809c90fb

4 years agoMerge "install_prereq: Fix check_installed_debs remove subversion"
Joshua Colp [Mon, 4 Apr 2016 22:39:45 +0000 (17:39 -0500)]
Merge "install_prereq:  Fix check_installed_debs remove subversion"

4 years agoMerge "res_pjsip_mwi: Allow subscribe to vm access extension as an alias"
Joshua Colp [Mon, 4 Apr 2016 20:31:31 +0000 (15:31 -0500)]
Merge "res_pjsip_mwi:  Allow subscribe to vm access extension as an alias"

4 years agoMerge "res_pjsip_mwi: Add voicemail extension and mwi_subscribe_replaces_unsolicited"
Joshua Colp [Mon, 4 Apr 2016 20:31:21 +0000 (15:31 -0500)]
Merge "res_pjsip_mwi:  Add voicemail extension and mwi_subscribe_replaces_unsolicited"

4 years agoinstall_prereq: Fix check_installed_debs remove subversion
George Joseph [Sun, 3 Apr 2016 16:47:30 +0000 (10:47 -0600)]
install_prereq:  Fix check_installed_debs remove subversion

check_installed_debs wasn't handling virtual packages like libsrtp-dev and
libresample-dev and on multiarch systems it was accidentally filtering out all
packages if any :i386 packages were found instead of just filtering out the
:i386 packages themselves.

Change-Id: Ifd68da0d1ee30cc84df14de3f9b9079d7c3cecda

4 years agoutils.c: Fix typo in handle_show_locks
George Joseph [Fri, 1 Apr 2016 18:09:50 +0000 (12:09 -0600)]
utils.c:  Fix typo in handle_show_locks

ast_cli_allow_on_shutdown(e) should have been ast_cli_allow_at_shutdown(e).

Change-Id: I4f092495c0b2bfd85c2651e0b5877bf4d05d9faf

4 years agoMerge "chan_sip: Do not send all codecs on INVITE. Do not break on Session-Timers."
zuul [Thu, 31 Mar 2016 22:35:23 +0000 (17:35 -0500)]
Merge "chan_sip: Do not send all codecs on INVITE. Do not break on Session-Timers."

4 years agoMerge "res_stasis: Add control ref to playback and recording structs."
zuul [Thu, 31 Mar 2016 18:20:55 +0000 (13:20 -0500)]
Merge "res_stasis: Add control ref to playback and recording structs."

4 years agoMerge "pjproject_bundled: Fix use of LDCONFIG for shared library link creation"
Joshua Colp [Thu, 31 Mar 2016 16:13:11 +0000 (11:13 -0500)]
Merge "pjproject_bundled:  Fix use of LDCONFIG for shared library link creation"

4 years agoMerge "res_stasis: Fix crash on a hanging up channel."
zuul [Thu, 31 Mar 2016 14:28:48 +0000 (09:28 -0500)]
Merge "res_stasis: Fix crash on a hanging up channel."

4 years agoMerge "res_stasis.c: Protect channel datastore list from stasis end."
Joshua Colp [Thu, 31 Mar 2016 12:05:24 +0000 (07:05 -0500)]
Merge "res_stasis.c: Protect channel datastore list from stasis end."

4 years agoMerge "res_rtp_asterisk: Fix placement of txcount increment"
Joshua Colp [Thu, 31 Mar 2016 12:04:55 +0000 (07:04 -0500)]
Merge "res_rtp_asterisk:  Fix placement of txcount increment"

4 years agoMerge "core_unreal.c: Add clarification comment about channel ref."
zuul [Thu, 31 Mar 2016 05:48:42 +0000 (00:48 -0500)]
Merge "core_unreal.c: Add clarification comment about channel ref."

4 years agoMerge "res_ari: Cannot get control also means channel is unavailable."
Joshua Colp [Thu, 31 Mar 2016 01:59:05 +0000 (20:59 -0500)]
Merge "res_ari: Cannot get control also means channel is unavailable."

4 years agopjproject_bundled: Fix use of LDCONFIG for shared library link creation
George Joseph [Wed, 30 Mar 2016 23:34:42 +0000 (17:34 -0600)]
pjproject_bundled:  Fix use of LDCONFIG for shared library link creation

LDCONFIG apparently isn't set to something sane on all systems so the creation
of the shared library links fails.  Instead of just testing for non-blank,
main/Makefile now checks that LDCONFIG is actually executable and reverts to
LN if it isn't.

This applies to both libasteriskpj and libasteriskssl.

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

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

Change-Id: I25b76379bc637726ec044b2c0e709b56b3701729

4 years agores_stasis: Add control ref to playback and recording structs.
Richard Mudgett [Tue, 29 Mar 2016 18:47:08 +0000 (13:47 -0500)]
res_stasis: Add control ref to playback and recording structs.

The stasis_app_playback and stasis_app_recording structs need to have a
struct stasis_app_control ref.  Other threads can get a reference to the
playback and recording structs from their respective global container.
These other threads can then use the control pointer they contain after
the control struct has gone.

* Add control ref to stasis_app_playback and stasis_app_recording structs.

With the refs added, the control command queue can now have a circular
control reference which will cause the control struct to never get
released if the control's command queue is not flushed when the channel
leaves the Stasis application.  Also the command queue needs better
protection from adding commands if the control->is_done flag is set.

* Flush the control command queue on exit.

ASTERISK-25882 #close

Change-Id: I3cf1fb59cbe6f50f20d9e35a2c07ac07d7f4320d

4 years agores_stasis: Fix crash on a hanging up channel.
Richard Mudgett [Mon, 28 Mar 2016 23:10:40 +0000 (18:10 -0500)]
res_stasis: Fix crash on a hanging up channel.

* Give the struct stasis_app_control ao2 object a ref to the channel held
in the object.  Now the channel will still be around if a thread needs to
post a stasis message instead of crash because the topic was destroyed.

* Moved stopping any lingering silence generator out of the struct
stasis_app_control destructor and made it a part of exiting the Stasis
application.  Who knows which thread the destructor will be called under
so it cannot affect the channel's silence generator.  Not only was the
channel unprotected when the silence generator was stopped, stasis may no
longer even control the channel.


Change-Id: I21728161b5fe638cef7976fa36a605043a7497e4

4 years agores_stasis.c: Protect channel datastore list from stasis end.
Richard Mudgett [Wed, 30 Mar 2016 18:31:44 +0000 (13:31 -0500)]
res_stasis.c: Protect channel datastore list from stasis end.

Change-Id: Ifadc469590bd4d5368e19d3763db3bd1f80fdb95

4 years agores_ari: Cannot get control also means channel is unavailable.
Richard Mudgett [Tue, 29 Mar 2016 23:06:24 +0000 (18:06 -0500)]
res_ari: Cannot get control also means channel is unavailable.

The only caller of ari_bridges_play_found() has this note:

If ari_bridges_play_found fails because the channel is unavailable for
playback, The channel will be removed from the playback list soon.  We can
keep trying to get channels from the list until we either get one that
will work or else there isn't a channel for this bridge anymore, in which
case we'll revert to ari_bridges_play_new.

Change-Id: Ib068141b367ccaa17be0dab4181c98e26c5127d6

4 years agores_stasis_recording.c: Cleanup stasis_app_recording_find_by_name().
Richard Mudgett [Tue, 29 Mar 2016 19:29:53 +0000 (14:29 -0500)]
res_stasis_recording.c: Cleanup stasis_app_recording_find_by_name().

Change-Id: Ic7d93c402c498677a122505558859c853d4e5ac7

4 years agocore_unreal.c: Add clarification comment about channel ref.
Richard Mudgett [Mon, 28 Mar 2016 19:23:59 +0000 (14:23 -0500)]
core_unreal.c: Add clarification comment about channel ref.

Change-Id: I0be0627260cd8d6b6c3cc345949dcfdf32eff1f3