Commit graph

3459 commits

Author SHA1 Message Date
zuul
ac50fdecdb Merge "res_stasis: Handle re-enter stasis bridge with swap channel." 2016-04-22 17:08:06 -05:00
Richard Mudgett
6b1a632290 res_stasis: Handle re-enter stasis bridge with swap channel.
We lose the fact that there is a swap channel if there is one.  We
currently wind up rejoining the stasis bridge as a normal join after the
swap channel has already been kicked from the bridge.

This patch preserves the swap channel so the AMI/ARI events can note that
the channel joining the bridge is swapping with another channel.  Another
benefit to swaqpping in one operation is if there are any channels that
get lonely (MOH, bridge playback, and bridge record channels).  The lonely
channels won't leave before the joining channel has a chance to come back
in under stasis if the swap channel is the only reason the lonely channels
are staying in the bridge.

ASTERISK-25947 #close
Reported by: Richard Mudgett

ASTERISK-24649
Reported by: John Bigelow

ASTERISK-24782
Reported by: John Bigelow

Change-Id: If37ea508831d1fed6dbfac2f191c638fc0a850ee
2016-04-20 15:44:30 -05:00
George Joseph
70e860ec49 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
connected.id.  If the connected.id.name 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
connected.id.name was invalid.

ASTERISK-25942 #close

Change-Id: I60b4bf7a7ece9b7425eba74151c0b4969cd2738b
2016-04-19 18:16:35 -05:00
Mark Michelson
0235a66532 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
2016-04-19 10:47:18 -05:00
Joshua Colp
d268fe527d Merge "stasis_bridge.c: Update stasis bridge push diagnostic messages." 2016-04-19 09:42:45 -05:00
Joshua Colp
2b6764d8b9 Merge "res_pjsip_transport_management: Allow unload to occur." 2016-04-19 09:40:59 -05:00
Mark Michelson
b8b60135ec 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
2016-04-19 08:22:23 -05:00
Joshua Colp
6cfa02394f 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
2016-04-18 13:49:45 -05:00
Richard Mudgett
af114edb8b stasis_bridge.c: Update stasis bridge push diagnostic messages.
Change-Id: I195b14994c9dcccb9452491ca20a885d2a54605a
2016-04-15 20:26:14 -05:00
Mark Michelson
be4333ddad 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.

AST-2016-005

Change-Id: I5f7a37e2c80726a99afe9dc2a4a69bdedf661283
2016-04-14 14:28:06 -05:00
Joshua Colp
d3e4d10f04 Merge "res_pjsip_transport_management: Kill idle TCP connections." 2016-04-14 13:02:32 -05:00
Joshua Colp
0c239112bb Merge "Rename res_pjsip_keepalive res_pjsip_transport_management" 2016-04-14 13:01:00 -05:00
Mark Michelson
216f22fd0f 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

AST-2016-005

Change-Id: I7b0d303e5d140d0ccaf2f7af562071e3d1130ac6
2016-04-14 12:02:30 -05:00
Mark Michelson
d9fba46016 Rename res_pjsip_keepalive res_pjsip_transport_management
ASTERISK-25796
Reported by George Joseph

AST-2016-005

Change-Id: Id322a05f927392293570599730050bc677d99433
2016-04-14 07:36:23 -05:00
Mark Michelson
7b8b6e2e4f 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

Patches:
    0001-res_pjsip-Validate-that-URIs-don-t-exceed-pjproject-.patch

AST-2016-004

Change-Id: I3ea7cee16f29c8088794de3085ca7523c1c4833d
2016-04-14 07:23:54 -05:00
Joshua Colp
c714d0006b Merge "res_pjsip_dialog_info: Add missing "direction" attribute in NOTIFY event" 2016-04-12 13:29:20 -05:00
Alexei Gradinari
49813bc9e5 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
2016-04-11 22:26:37 -05:00
zuul
74951bd591 Merge "res_pjsip_outbound_publish: Add transport for outbound PUBLISH" 2016-04-11 21:26:08 -05:00
Alexei Gradinari
4e00e31ef1 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
2016-04-11 16:05:59 -05:00
George Joseph
a621dd5e96 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
failures.

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
2016-04-11 13:00:27 -05:00
Alexei Gradinari
b3be945415 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
Ringing.

ASTERISK-24601 #close

Change-Id: I5b2c097ca29fd59e92ba237ca5d397cb1b0bcd8c
2016-04-08 05:49:02 -05:00
Richard Mudgett
6138a75e8e pbx.h: Make ast_state_cb_type take more const.
This eliminates some casts that I made a note saying v10 and above
would no longer need them.

Better late than never :)

Change-Id: I346cdb3032b6478ceb40eb6fe732978b54035572
2016-04-07 17:20:17 -05:00
Joshua Colp
2eaeea690d 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
2016-04-07 11:42:32 -05:00
Joshua Colp
3e5672d843 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
2016-04-06 16:29:58 -05:00
Joshua Colp
97db0ca884 Merge "res_pjsip: Handle deferred SDP hold/unhold properly." 2016-04-06 07:52:56 -05:00
Joshua Colp
72ef79dc2d Merge "ARI: Add method to Dial a created channel." 2016-04-06 05:43:47 -05:00
Joshua Colp
3b71f09bb7 Merge "ARI: Add method to create a new channel." 2016-04-06 05:43:36 -05:00
Mark Michelson
abbb2edd4c 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
2016-04-05 18:14:17 -05:00
Mark Michelson
dd48d60c5b 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.

ASTERISK-25889

Change-Id: I3c96a0aba914b08e39f6256371a5bd4c92cbded8
2016-04-05 18:14:05 -05:00
Mark Michelson
a098251e7e 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
desired.

ASTERISK-25854 #close
Reported by Robert McGilvray

Change-Id: I7615737276165eef3a593038413d936247dcc6ed
2016-04-05 16:13:38 -05:00
Joshua Colp
784fb43f43 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
2016-04-05 10:22:20 -05:00
Joshua Colp
051da5c3af Merge "res_rtp_asterisk: Use separate SRTP session for RTCP with DTLS" 2016-04-05 05:37:44 -05:00
George Joseph
c07e1190ec res_pjsip_mwi: Fix segv caused by 16c7d8e74a
I forgot the new voicemail_extension wasn't a stringfield and didn't check
for NULL where I should have.

Change-Id: I029482d5c2ab72474838750461bd46b0809c90fb
2016-04-04 18:05:45 -05:00
Joshua Colp
abf241b94f Merge "res_pjsip_mwi: Allow subscribe to vm access extension as an alias" 2016-04-04 15:31:31 -05:00
Joshua Colp
96dcd81110 Merge "res_pjsip_mwi: Add voicemail extension and mwi_subscribe_replaces_unsolicited" 2016-04-04 15:31:21 -05:00
zuul
e2a8033d09 Merge "res_stasis: Add control ref to playback and recording structs." 2016-03-31 13:20:55 -05:00
zuul
cd6d478d3f Merge "res_stasis: Fix crash on a hanging up channel." 2016-03-31 09:28:48 -05:00
Joshua Colp
7372925a5b Merge "res_stasis.c: Protect channel datastore list from stasis end." 2016-03-31 07:05:24 -05:00
Joshua Colp
99c749cf26 Merge "res_rtp_asterisk: Fix placement of txcount increment" 2016-03-31 07:04:55 -05:00
Joshua Colp
41cedd9896 Merge "res_ari: Cannot get control also means channel is unavailable." 2016-03-30 20:59:05 -05:00
Richard Mudgett
0ea742d33a 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
2016-03-30 16:36:20 -05:00
Richard Mudgett
53f63ad770 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.

ASTERISK-25882

Change-Id: I21728161b5fe638cef7976fa36a605043a7497e4
2016-03-30 16:36:20 -05:00
Richard Mudgett
2fab4d7da8 res_stasis.c: Protect channel datastore list from stasis end.
Change-Id: Ifadc469590bd4d5368e19d3763db3bd1f80fdb95
2016-03-30 16:33:56 -05:00
Richard Mudgett
ece2edaa04 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
2016-03-30 16:31:59 -05:00
Richard Mudgett
2f36cba4b5 res_stasis_recording.c: Cleanup stasis_app_recording_find_by_name().
Change-Id: Ic7d93c402c498677a122505558859c853d4e5ac7
2016-03-30 16:29:59 -05:00
George Joseph
2b3261cd36 res_pjsip_mwi: Allow subscribe to vm access extension as an alias
Background:

If your extension is 1000 and the voicemail access extension is 1571 and you
dial 1571, usually a dialplan rule calls voicemailmain with your extension and
you are placed directly in your mailbox.  Therefore most admins program the
voicemail (or other speed dial) button on their phones to the access extension.
Some phones (Snom at least) use whatever is programmed there to also subscribe
for MWI and so can't dial one number and subscribe to another.  This works fine
in chan_sip because chan_sip completely ignores the user portion of the
SUBSCRIBE message request URI.  If it can match the peer, is subscribes to the
peer's mailbox.  The user could be set to anything or nothing and you'd still
get subscribed to your mailbox.

Issue:

chan_pjsip actually uses the user portion of the URI to find an aor and its
mailboxes.  Therefore a subscribe to 1571 results in a 404.  Sure, you can
create an aor for 1571 but you certainly can't add your entire voicemail
system's mailboxes to it and everyone would get notified of every MWI.

Solution:

When an MWI subscribe comes in and an aor can't be found that matches the
resource directly, check the resource against the endpoint's aors.  If an aor
is found that has a voicemail_extension that matches the resource, use it.

ASTERISK-25865
Reported-by: Ross Beer

Change-Id: I770ea185f751f1ada888fafb4b452115f1c06e9e
2016-03-30 13:34:09 -06:00
George Joseph
e2524fcee3 res_pjsip_mwi: Add voicemail extension and mwi_subscribe_replaces_unsolicited
res_pjsip_mwi was missing the chan_sip "vmexten" functionality which adds
the Message-Account header to the MWI NOTIFY.  Also, specifying mailboxes
on endpoints for unsolicited mwi and on aors for subscriptions required
that the admin know in advance which the client wanted.  If you specified
mailboxes on the endpoint, subscriptions were rejected even if you also
specified mailboxes on the aor.

Voicemail extension:
* Added a global default_voicemail_extension which defaults to "".
* Added voicemail_extension to both endpoint and aor.
* Added ast_sip_subscription_get_dialog for support.
* Added ast_sip_subscription_get_sip_uri for support.

When an unsolicited NOTIFY is constructed, the From header is parsed, the
voicemail extension from the endpoint is substituted for the user, and the
result placed in the Message-Account field in the body.

When a subscribed NOTIFY is constructed, the subscription dialog local uri
is parsed, the voicemail_extension from the aor (looked up from the
subscription resource name) is substituted for the user, and the result
placed in the Message-Account field in the body.

If no voicemail extension was defined, the Message-Account field is not added
to the NOTIFY body.

mwi_subscribe_replaces_unsolicited:
* Added mwi_subscribe_replaces_unsolicited to endpoint.

The previous behavior was to reject a subscribe if a previous internal
subscription for unsolicited MWI was found for the mailbox.  That remains the
default.  However, if there are mailboxes also set on the aor and the client
subscribes and mwi_subscribe_replaces_unsolicited is set, the existing internal
subscription is removed and replaced with the external subscription.  This
allows an admin to configure mailboxes on both the endpoint and aor and allows
the client to select which to use.

ASTERISK-25865 #close
Reported-by: Ross Beer

Change-Id: Ic15a9415091760539c7134a5ba3dc4a6a1217cea
2016-03-30 13:23:54 -05:00
zuul
23d2a561d5 Merge "res_pjsip/pjsip_options: Fix From generation on outgoing OPTIONS" 2016-03-30 10:51:42 -05:00
George Joseph
724b9ab28f res_rtp_asterisk: Fix placement of txcount increment
Commit 1bce690ccb was incrementing txcount
for rtcp packets as well as rtp packets and that was causing sender reports
to be generated instead of receiver reports in cases where no rtp was actually
being sent.

Moved the txcount increment from __rtp_sento, which handles both rtp and rtcp,
to rtp_sento which only handles rtp packets.

Discovered by the hep/rtcp-receiver test.

Change-Id: Ie442e4bb947a68847a676497021ba10ffaf376d5
2016-03-30 09:52:47 -05:00
George Joseph
c4064727d2 chan_pjsip: Add 'pjsip show channelstats'
Added the ability to show channel statistics to chan_pjsip (cli_functions.c)

Moved the existing 'pjsip show channel(s)' functionality from
pjsip_configuration to cli_functions.c.  The stats needed chan_pjsip's
private header so it made sense to move the existing channel commands as well.

Now using stasis_cache_dump to get the channel snapshots rather than retrieving
all endpoints, then getting each one's channel snapshots.  Much more efficient.

Change-Id: I03b114522126d27434030b285bf6d531ddd79869
2016-03-29 14:35:31 -05:00