Commit Graph

3245 Commits

Author SHA1 Message Date
Matt Jordan b99a705262 ARI: Add the ability to subscribe to all events
This patch adds the ability to subscribe to all events. There are two possible
ways to accomplish this:
(1) On initial WebSocket connection. This patch adds a new query parameter,
    'subscribeAll'. If present and True, Asterisk will subscribe the
    applications to all ARI events.
(2) Via the applications resource. When subscribing in this manner, an ARI
    client should merely specify a blank resource name, i.e., 'channels:'
    instead of 'channels:12354'. This will subscribe the application to all
    resources of the 'channels' type.

ASTERISK-24870 #close

Change-Id: I4a943b4db24442cf28bc64b24bfd541249790ad6
2015-09-22 09:59:47 -05:00
Matt Jordan 47813cc51c res/res_stasis_device_state: Allow for subscribing to 'all' device state
This patch adds support for subscribing to all device state changes. This is
done either by subscribing to an empty device, e.g., 'eventSource=deviceState:',
or by the WebSocket connection specifying that it wants all state in the
system.

ASTERISK-24870

Change-Id: I9cfeca1c9e2231bd7ea73e45919111d44d2eda32
2015-09-21 08:22:11 -05:00
Matt Jordan 5206aa9d30 ARI: Add events for Contact and Peer Status changes
This patch adds support for receiving events regarding Peer status changes
and Contact status changes. This is particularly useful in scenarios where
we are subscribed to all endpoints and channels, where we often want to know
more about the state of channel technology specific items than a single
endpoint's state.

ASTERISK-24870

Change-Id: I6137459cdc25ce27efc134ad58abf065653da4e9
2015-09-21 08:21:58 -05:00
Matt Jordan d856f89012 Merge "CHAOS: res_pjsip_diversion avoid crash if allocation fails" 2015-09-19 09:15:22 -05:00
Scott Griepentrog d9723d242a CHAOS: avoid crash if string create fails
Validate string buffer allocation before using them.

ASTERISK-25323

Change-Id: Ib9c338bdc1e53fb8b81366f0b39482b83ef56ce0
2015-09-18 13:49:55 -05:00
Richard Mudgett e1927915bc CHAOS: res_pjsip_diversion avoid crash if allocation fails
Validate ast_malloc buffer returned before using it in
set_redirecting_value().

ASTERISK-25323

Change-Id: I15d2ed7cb0546818264c0bf251aa40adeae83253
2015-09-17 17:04:16 -05:00
Mark Michelson e47396721f 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
2015-09-17 11:12:22 -05:00
Matt Jordan 6097a1fc05 Merge "res/res_pjsip_nat: Ignore REGISTER requests when looking for a Record-Route" 2015-09-11 16:13:53 -05:00
Richard Mudgett 69824fdfbf res_pjsip_pubsub.c: Mark ast_sip_create_subscription() as not used.
Change-Id: I2b8db18eac36c01a5c7eb9467699124e203fd093
2015-09-10 13:16:12 -05:00
Richard Mudgett 2526659432 res_pjsip_pubsub.c: Add some notification comments.
Change-Id: Ie62ff1f4b7adc1a12fa0303f53926af249b25e20
2015-09-10 13:16:12 -05:00
Richard Mudgett 9b290dfe2f res_pjsip_pubsub.c: Set dlg_status code instead of sending SIP response.
We should not try to send a SIP response message because we may be
restoring a persistent subscription where we are not responding to a SIP
request.

Change-Id: Id89167ef90320c5563f37e632db0dda6cb9e7dec
2015-09-10 13:16:12 -05:00
Richard Mudgett 73eb132012 res_pjsip_pubsub.c: Fix off-nominal memory leak.
Fix off-nominal visited vector leak in build_resource_tree().

Change-Id: If0399c7941c9c0b1038bcfb7b9a371760977831c
2015-09-10 13:16:12 -05:00
Richard Mudgett 2b30fc2b2d res_pjsip_pubsub.c: Fix one byte buffer overrun error.
ast_sip_pubsub_register_body_generator() did not account for the null
terminator set by sprintf() in the allocated output buffer.

Change-Id: I388688a132e479bca6ad1c19275eae0070969ae2
2015-09-10 13:16:12 -05:00
Richard Mudgett 08a182c8e6 res_pjsip_pubsub.c: Use ast_alloca() instead of alloca().
Change-Id: Ia396096b4fedc2874649ca11137612c3f55e83e3
2015-09-10 13:16:12 -05:00
Richard Mudgett 61f30db877 res_pjsip_pubsub.c: Add missing error return in load_module().
Change-Id: I15debd0f717f16ee2f78e7f56151c3b3b97b72fc
2015-09-10 13:16:12 -05:00
Richard Mudgett b8f07527b2 res_pjsip/location.c: Use the builtin ao2_callback() match function instead.
Change-Id: I364906d6d2bad3472929986704a0286b9a2cbe3f
2015-09-10 13:16:12 -05:00
Mark Michelson f1a2e82d49 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
2015-09-10 09:55:00 -05:00
Matt Jordan bd71dcd1da res/res_pjsip_nat: Ignore REGISTER requests when looking for a Record-Route
We will only rewrite the Contact header if there is no Record-Route header in
the received request. If a malfunctioning proxy places a Record-Route header
into a REGISTER request, we will decide that we shouldn't update the IP/port
in the Contact header, and we will end up storing a contact with an AoR that
contains the NAT'd IP address.

While it is nice to have the proxy *not* send a Record-Route in a REGISTER
request, it's also a good idea to not process the header in a non-dialog
message. This patch updates the code to explicitly ignore the Record-Route
header in REGISTER requests.

ASTERISK-25387 #close

Change-Id: I4bd3bcccc4003d460cc354d986b0dea2e433ef3f
2015-09-10 08:43:54 -05:00
Joshua Colp be3f52a122 Merge "ParkAndAnnounce: Add variable inheritance" 2015-09-10 07:25:02 -05:00
Joshua Colp 8e269a467d Merge "pjsip: avoid possible crash req_caps allocation failure" 2015-09-09 17:22:22 -05:00
Scott Griepentrog fcea6910f6 pjsip: avoid possible crash req_caps allocation failure
Make certain that the pjsip session has not failed to
allocate the format capabilities structure, which can
otherwise cause a crash when referenced.

ASTERISK-25323

Change-Id: I602790ba12714741165e441cc64a3ecde4cb5750
2015-09-09 13:09:42 -05:00
Joshua Colp 647cdcd6a8 Merge "res_pjsip: Use hash for contact object identity instead of Contact URI." 2015-09-09 05:53:02 -05:00
Matt Jordan 0b63c2969f Merge "res_rtp_asterisk: Add more ICE debugging" 2015-09-08 16:33:29 -05:00
David M. Lee 8e5ed27a16 res_rtp_asterisk: Add more ICE debugging
In working through a recent ICE negotiation bug, I found the debug
logging in res_rtp_asterisk to be lacking. This patch adds a number of
debug and warning statements that were helpful.

Change-Id: I950c6d8f13a41f14b3d6334b4cafe7d4e997be80
2015-09-08 15:50:26 -05:00
Joshua Colp 3628e380b8 res_pjsip: Use hash for contact object identity instead of Contact URI.
In the wild it is possible for Contact URIs to be quite long as
parameters can exist on them. This can present a problem when storing
them in the AstDB as the URI is used as part of the object name and
there is a fixed length limit for the AstDB. This will cause
the contact to not get stored.

This change uses the MD5 hash of the Contact URI as part of the
object name instead. This has a fixed length which is guaranteed
to not exceed the AstDB length limit.

ASTERISK-25295 #close

Change-Id: Ie8252a75331ca00b41b9f308f42cc1fbdf701a02
2015-09-08 07:44:52 -05:00
Matt Jordan ef3358d0c0 res/res_pjsip: Purge contacts when an AoR is deleted
When an AoR is deleted by an external mechanism, such as through ARI, we
currently do not remove dynamic contacts that were created for that AoR as a
result of a received REGISTER request. As a result, re-creating the AoR will
cause the dynamic contact to be interpreted as a persistent contact, leading
to some rather strange state being created for the contacts/endpoints.

This patch adds a sorcery observer for the 'aor' object. When a delete is
issued on the underlying sorcery object, the observer is called, and all
contacts created and persisted in sorcery for that AoR are also removed. Note
that we don't want to perform this action when an AO2 object that is an AoR is
destroyed, as the AoR can still exist in the backing storage (and we would
thus be removing valid contacts from an AoR that still "exists".)

ASTERISK-25381 #close

Change-Id: I6697e51ef6b2858b5d63401f35dc378bb0f90328
2015-09-07 11:37:54 -05:00
Joshua Colp e1c43223ab Merge "res_pjsip: Change default from user value." 2015-09-05 15:56:59 -05:00
Joshua Colp bf74956371 Merge "Fix when remote candidates exceed PJ_ICE_MAX_CAND" 2015-09-05 15:42:37 -05:00
David M. Lee 27c89053b0 Fix when remote candidates exceed PJ_ICE_MAX_CAND
We were passing the wrong count into pj_ice_sess_create_check_list(),
causing the create to fail if we ever received more than PJ_ICE_MAX_CAND
candidates.

Change-Id: I0303d8e1ecb20a8de9fe629a3209d216c4028378
2015-09-04 16:13:52 -05:00
Mark Michelson 993ae9a669 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
2015-09-04 14:48:20 -05:00
Jonathan Rose 7d981b787c 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
2015-09-04 11:22:26 -05:00
Martin Tomec be31747db8 res/pjsip: Mark WSS transport as secure
Pjsip is refusing to use unsecure transport with "sips" in url.
WSS should be considered as secure transport.

ASTERISK-24602 #comment Partially fixed by setting WSS as secure

Change-Id: Iddac406c6deba6240c41a603b8859dfefe1a5353
2015-09-04 12:46:14 +02:00
Mark Michelson c15d8cc0ed 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
2015-09-02 17:28:18 -05:00
Mark Michelson beb568e51c 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
2015-09-01 09:41:10 -05:00
Joshua Colp bb38010c67 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
2015-08-28 20:49:35 -05:00
Joshua Colp 229b95d253 res_pjsip_session: Don't invoke session supplements twice for BYE requests.
When a BYE request is received the PJSIP invite session implementation
creates and sends a 200 OK response before we are aware of it. This
causes the INVITE session state callback to be called into and ultimately
the session supplements run on the BYE request. Once this response has
been sent the normal transaction state callback is invoked which
invokes the session supplements on the BYE request again. This can
be problematic in particular with res_pjsip_rfc3326 as it may
attempt to update the hangup cause code on the channel while it is
in the process of being hung up.

This change makes it so the session supplements are only invoked
once by the INVITE session state callback.

ASTERISK-25318 #close

Change-Id: I69c17df55ccbb61ef779ac38cc8c6b411376c19a
2015-08-28 06:44:21 -05:00
Joshua Colp 388e628120 Merge "res_pjsip: Add common ast_sip_get_host_ip API." 2015-08-27 15:41:54 -05:00
Scott Griepentrog 6bfa14bdad Chaos: handle failed allocation in get_media_encryption_type
If the ast_strndup() call fails to allocate a copy of the
transport string for parsing, fail gracefully.

ASTERISK-25323
Reported by: Scott Griepentrog

Change-Id: Ia4b905ce6d03da53fea526224455c1044b1a5a28
2015-08-26 15:26:00 -05:00
Joshua Colp d013ecf748 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
2015-08-25 13:55:33 -03:00
Mark Michelson 6b8734fe68 Merge "res_pjsip_pubsub: On recreated notify fail deleted sub_tree is referenced" 2015-08-24 17:16:48 -05:00
Joshua Colp a408369bac 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
2015-08-24 11:09:05 -05:00
Matt Jordan 3af34441eb res_pjsip/pjsip_configuration: Disregard empty auth values
When an endpoint is backed by a non-static conf file backend (such as
the AstDB or Realtime), the 'auth' object may be returned as being an
empty string. Currently, res_pjsip will interpret that as being a valid
auth object, and will attempt to authenticate inbound requests. This
isn't desired; is an auth value is empty (which the name of an auth
object cannot be), we should instead interpret that as being an invalid
auth object and skip it.

ASTERISK-25339 #close

Change-Id: Ic32b0c6eb5575107d5164a8c40099e687cd722c7
2015-08-23 18:43:55 -05:00
Richard Mudgett d643b206c6 res_pjsip_sdp_rtp.c: Set preferred rx payload type mapping on incoming offers.
ASTERISK-25166
Reported by: Kevin Harwell

ASTERISK-17410
Reported by: Boris Fox

Change-Id: I97ecebc1ab9b5654fb918bf1f4c98c956b852369
2015-08-20 11:56:14 -05:00
Richard Mudgett 1a549ed134 rtp_engine.c: Initial split of payload types into rx and tx mappings.
There are numerous problems with the current implementation of the RTP
payload type mapping in Asterisk.  It uses only one mapping structure to
associate payload types to codecs.  The single mapping is overkill if all
of the payload type values are well known values.  Dynamic payload type
mappings do not work as well with the single mapping because RFC3264
allows each side of the link to negotiate different dynamic mappings for
what they want to receive.  Not only could you have the same codec mapped
for sending and receiving on different payload types you could wind up
with the same payload type mapped to different codecs for each direction.

1) An independent payload type mapping is needed for sending and
receiving.

2) The receive mapping needs to keep track of previous mappings because of
the slack to when negotiation happens and current packets in flight using
the old mapping arrive.

3) The transmit mapping only needs to keep track of the current negotiated
values since we are sending the packets and know when the switchover takes
place.

* Needed to create ast_rtp_codecs_payload_code_tx() and make some callers
use the new function because ast_rtp_codecs_payload_code() was used for
mappings in both directions.

* Needed to create ast_rtp_codecs_payloads_xover() for cases where we need
to pass preferred codec mappings to the peer channel for early media
bridging or when we need to prefer the offered mapping that RFC3264 says
we SHOULD use.

* ast_rtp_codecs_payloads_xover() and ast_rtp_codecs_payload_code_tx() are
the only new public functions created.  All the others were only used for
the tx or rx mapping direction so the function doxygen now reflects which
direction the function operates.

* chan_mgcp.c: Removed call to ast_rtp_codecs_payloads_clear() as doing
that makes no sense when processing an incoming SDP.  We would be wiping
out any mappings that we set for the possible outgoing SDP we sent
earlier.

ASTERISK-25166
Reported by: Kevin Harwell

ASTERISK-17410
Reported by: Boris Fox

Change-Id: Iaf6c227bca68cb7c414cf2fd4108a8ac98bd45ac
2015-08-19 17:09:58 -05:00
Mark Michelson aacb46b56a Merge "res_ari_events: Fix shutdown ref leak." 2015-08-19 17:06:51 -05:00
Mark Michelson 192693c2c1 Merge "res_http_websocket.c: Add missing unref on an off nominal path." 2015-08-19 16:56:35 -05:00
Richard Mudgett 21d419e4fc ari/ari_websockets.c: Fix ast_debug parameter type mismatch.
This is a type mismatch fix of the debugging commit
c63316eec1 made to find out why
a testsuite test was failing only on one of the continuous
integration build agents.

Change-Id: Iba34f6e87cec331f6ac80e4daff6476ea6f00a75
2015-08-19 12:10:18 -05:00
Richard Mudgett 03eb6cbc10 res_ari_events: Fix shutdown ref leak.
ASTERISK-25308 #close
Reported by: Joshua Colp

Change-Id: I592785bf70ff4b63d00e535b482f40da8e82a082
2015-08-18 16:44:06 -05:00
Richard Mudgett e1e7e205bc res_http_websocket.c: Add missing unref on an off nominal path.
Change-Id: I228df6adecd4cb450d03e09e9a38c86bb566e811
2015-08-18 16:40:04 -05:00
Richard Mudgett 59253a2262 res_http_websocket.c: Fix some off nominal path cleanup.
* Remove extraneous unlock on off-nominal path.
* Add missing HTTP error reply.

Change-Id: I1f402bfe448fba8696b507477cab5f060ccd9b2b
2015-08-18 16:38:19 -05:00
Richard Mudgett 1f0a9f8a76 res_ari.c: Add missing off nominal unlock and remove a RAII_VAR().
Change-Id: I0c5e7b34057f26dadb39489c4dac3015c52f5dbf
2015-08-18 16:38:19 -05:00
Mark Michelson 5a85711568 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
2015-08-14 15:48:53 -05:00
Joshua Colp 495dfb24b7 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
2015-08-13 05:36:32 -05:00
Joshua Colp e1e37e47fd Merge "res_http_websocket: Forcefully terminate on write errors." 2015-08-12 13:43:16 -05:00
Mark Michelson cf45868984 Merge "res_pjsip.c: Fix crash from corrupt saved SUBSCRIBE message." 2015-08-12 13:08:02 -05:00
Joshua Colp 7e65be4ecd 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
2015-08-12 05:14:55 -05:00
Matt Jordan a87e2dd254 res/res_format_attr_silk: Expose format attributes to other modules
This patch adds the .get callback to the format attribute module, such
that the Asterisk core or other third party modules can query for the
negotiated format attributes.

Change-Id: Ia24f55cf9b661d651ce89b4f4b023d921380f19c
2015-08-11 18:24:29 -05:00
Richard Mudgett f3f5b45d57 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
2015-08-11 16:57:36 -05:00
David M. Lee d5f0c27122 Replace htobe64 with htonll
We don't have a compatability function to fill in a missing htobe64; but
we already have one for the identical htonll.

Change-Id: Ic0a95db1c5b0041e14e6b127432fb533b97e4cac
2015-08-07 23:40:56 -05:00
Scott Emidy 12e6f5ac01 ARI: Retrieve existing log channels
An http request can be sent to get the existing Asterisk logs.

The command "curl -v -u user:pass -X GET 'http://localhost:8088
/ari/asterisk/logging'" can be run in the terminal to access the
newly implemented functionality.

* Retrieve all existing log channels

ASTERISK-25252

Change-Id: I7bb08b93e3b938c991f3f56cc5d188654768a808
2015-08-07 14:57:45 -05:00
Scott Emidy b91ca7ba49 ARI: Creating log channels
An http request can be sent to create a log channel
in Asterisk.

The command "curl -v -u user:pass -X POST
'http://localhost:088/ari/asterisk/logging/mylog?
configuration=notice,warning'" can be run in the terminal
to access the newly implemented functionality for ARI.

* Ability to create log channels using ARI

ASTERISK-25252

Change-Id: I9a20e5c75716dfbb6b62fd3474faf55be20bd782
2015-08-07 11:18:13 -05:00
Joshua Colp ecd4cde521 Merge "ARI: Deleting log channels" 2015-08-07 10:41:12 -05:00
Joshua Colp 1b89cbb3b0 Merge "res_pjsip: Ensure sanitized XML is NULL terminated." 2015-08-07 10:23:49 -05:00
Joshua Colp 12d7c8a740 Merge "res_pjsip_pubsub: More accurately persist packet." 2015-08-07 05:17:13 -05:00
Joshua Colp 58effbc3f6 Merge "res_rtp_asterisk.c: Fix off-nominal crash potential." 2015-08-07 05:18:06 -05:00
Scott Emidy f19c4930c2 ARI: Deleting log channels
An http request can be sent to delete a log channel
in Asterisk.

The command "curl -v -u user:pass -X DELETE 'http://localhost:8088
/ari/asterisk/logging/mylog'" can be run in the terminal
to access the newly implemented functionally for ARI.

* Able to delete log channels using ARI

ASTERISK-25252

Change-Id: Id6eeb54ebcc511595f0418d586ff55914bc3aae6
2015-08-06 17:43:49 -05:00
Mark Michelson 382334cc06 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
2015-08-06 13:15:59 -05:00
Joshua Colp 7ebca6795b Merge "res_pjsip_sdp_rtp.c: Fixup some whitespace." 2015-08-06 11:53:20 -05:00
Joshua Colp 4b6c657a82 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
2015-08-06 05:20:47 -05:00
Joshua Colp 3d4db97253 Merge "res_pjsip_sdp_rtp.c: Fix processing wrong SDP media list." 2015-08-06 04:52:49 -05:00
Joshua Colp 8a48c9e6cb Merge "res_http_websocket: Debug write lengths." 2015-08-06 04:52:10 -05:00
Joshua Colp 7351d33a1f res_rtp_asterisk: Don't leak temporary key when enabling PFS.
A change recently went in which enabled perfect forward secrecy for
DTLS in res_rtp_asterisk. This was accomplished two different ways
depending on the availability of a feature in OpenSSL. The fallback
method created a temporary instance of a key but did not free it.
This change fixes that.

ASTERISK-25265

Change-Id: Iadc031b67a91410bbefb17ffb4218d615d051396
2015-08-05 10:25:53 -05:00
Mark Michelson c63316eec1 res_http_websocket: Debug write lengths.
Commit 39cc28f6ea attempted to fix a
test failure observed on 32 bit test agents by ensuring that a cast from
a 32 bit unsigned integer to a 64 bit unsigned integer was happening in
a predictable place. As it turns out, this did not cause test runs to
succeed.

This commit adds several redundant debug messages that print the payload
lengths of websocket frames. The idea here is that this commit will not
cause tests to succeed for the faulty test agent, but we might deduce
where the fault lies more easily this way by observing at what point the
expected value (537) changes to some ungangly huge number.

If you are wondering why something like this is being committed to the
branch, keep in mind that in commit
39cc28f6ea I noted that the observed test
failures only happen when automated tests are run. Attempts to run the
tests by hand manually on the test agent result in the tests passing.

Change-Id: I14a65c19d8af40dadcdbd52348de3b0016e1ae8d
2015-08-04 10:19:36 -05:00
Matt Jordan 3ba6099a9e Merge "res_http_websocket: Avoid passing strlen() to ast_websocket_write()." 2015-08-03 11:52:01 -05:00
Matt Jordan 8672f0bbbd Merge "res/res_rtp_asterisk: Add ECDH support" 2015-08-03 11:49:43 -05:00
Mark Michelson 35a98161df res_http_websocket: Avoid passing strlen() to ast_websocket_write().
We have seen a rash of test failures on a 32-bit build agent. Commit
48698a5e21 solved an obvious problem where
we were not encoding a 64-bit value correctly over the wire. This
commit, however, did not solve the test failures.

In the failing tests, ARI is attempting to send a 537 byte text frame
over a websocket. When sending a frame this small, 16 bits are all that
is required in order to encode the payload length on the websocket
frame. However, ast_websocket_write() thinks that the payload length is
greater than 65535 and therefore writes out a 64 bit payload length.
Inspecting this payload length, the lower 32 bits are exactly what we
would expect it to be, 537 in hex. The upper 32 bits, are junk values
that are not expected to be there.

In the failure, we are passing the result of strlen() to a function that
expects a uint64_t parameter to be passed in. strlen() returns a size_t,
which on this 32-bit machine is 32 bits wide. Normally, passing a 32-bit
unsigned value to somewhere where a 64-bit unsigned value is expected
would cause no problems. In fact, in manual runs of failing tests, this
works just fine. However, ast_websocket_write() uses the Asterisk
optional API, which means that rather than a simple function call, there
are a series of macros that are used for its declaration and
implementation. These macros may be causing some sort of error to occur
when converting from a 32 bit quantity to a 64 bit quantity.

This commit changes the logic by making existing ast_websocket_write()
calls use ast_websocket_write_string() instead. Within
ast_websocket_write_string(), the 64-bit converted strlen is saved in a
local variable, and that variable is passed to ast_websocket_write()
instead.

Note that this commit message is full of speculation rather than
certainty. This is because the observed test failures, while always
present in automated test runs, never occur when tests are manually
attempted on the same test agent. The idea behind this commit is to fix
a theoretical issue by performing changes that should, at the least,
cause no harm. If it turns out that this change does not fix the failing
tests, then this commit should be reverted.

Change-Id: I4458dd87d785ca322b89c152b223a540a3d23e67
2015-08-03 11:23:29 -05:00
Mark Michelson b002e09214 Merge "ARI: Channels added to Stasis application during WebSocket creation ..." 2015-07-31 11:58:30 -05:00
Mark Michelson 92ddda68aa Merge "ARI: Rotate log channels." 2015-07-31 11:58:12 -05:00
Joshua Colp 94f7427b17 Merge "res_pjsip_session.c: Fix crashes seen when call cancelled." 2015-07-31 11:54:42 -05:00
Benjamin Ford 1f02d20da4 ARI: Rotate log channels.
An http request can be sent to rotate a specified log channel.
If the channel does not exist, an error response will be
returned.

The command "curl -v -u user:pass -X PUT 'http://localhost:8088
/ari/asterisk/logging/logChannelName/rotate'" can be run in the
terminal to access this new functionality.

* Added the ability to rotate log files through ARI

ASTERISK-25252

Change-Id: Iaefa21cbbc1b29effb33004ee3d89c977e76ab01
2015-07-31 11:46:08 -05:00
Ashley Sanders fe804b09b3 ARI: Channels added to Stasis application during WebSocket creation ...
Prior to ASTERISK-24988, the WebSocket handshake was resolved before Stasis
applications were registered. This was done such that the WebSocket would be
ready when an application is registered. However, by creating the WebSocket
first, the client had the ability to make requests for the Stasis application
it thought had been created with the initial handshake request. The inevitable
conclusion of this scenario was the cart being put before the horse.

ASTERISK-24988 resolved half of the problem by ensuring that the applications
were created and registered with Stasis prior to completing the handshake
with the client. While this meant that Stasis was ready when the client
received the green-light from Asterisk, it also meant that the WebSocket was
not yet ready for Stasis to dispatch messages.

This patch introduces a message queuing mechanism for delaying messages from
Stasis applications while the WebSocket is being constructed. When the ARI
event processor receives the message from the WebSocket that it is being
created, the event processor instantiates an event session which contains a
message queue. It then tries to create and register the requested applications
with Stasis. Messages that are dispatched from Stasis between this point and
the point at which the event processor is notified the WebSocket is ready, are
stashed in the queue. Once the WebSocket has been built, the queue's messages
are dispatched in the order in which they were originally received and the
queue is concurrently cleared.

ASTERISK-25181 #close
Reported By: Matt Jordan

Change-Id: Iafef7b85a2e0bf78c114db4c87ffc3d16d671a17
2015-07-31 11:28:10 -05:00
Richard Mudgett 33a465249b res_rtp_asterisk.c: Fix off-nominal crash potential.
ASTERISK-25296
Reported by: Richard Mudgett

Change-Id: I08549fb7c3ab40a559f41a3940f3732a4059b55b
2015-07-30 17:11:58 -05:00
Richard Mudgett ba7dd38470 res_pjsip_sdp_rtp.c: Fixup some whitespace.
Change-Id: Ib4eb7ef7dcaf93ddc26538f0a498aaf110d7a973
2015-07-30 17:11:58 -05:00
Richard Mudgett 3751bf0971 res_pjsip_sdp_rtp.c: Fix processing wrong SDP media list.
Change-Id: I7c076826c2d3c6ae8c923ca73b7a71980cca11f2
2015-07-30 17:11:58 -05:00
Richard Mudgett 077c58cd5c res_pjsip_session.c: Fix crashes seen when call cancelled.
Two testsuite tests crashed in the same place as a result of an INVITE
being CANCELed.

tests/channels/pjsip/resolver/srv/failover/in_dialog/transport_unspecified
tests/channels/pjsip/resolver/srv/failover/in_dialog/transport_tcp

The session pointer is no longer in the inv->mod_data[session_module.id]
location because the INVITE transaction has reached the terminated state.

ASTERISK-25297 #close
Reported by: Richard Mudgett

Change-Id: Idb75fdca0321f5447d5dac737a632a5f03614427
2015-07-30 17:05:57 -05:00
Mark Michelson 5fcd1bc556 res_http_websocket: Properly encode 64 bit payload
A test agent was continuously failing all ARI tests when run against
Asterisk 13. As it turns out, the reason for this is that on those test
runs, for some reason we decided to use the super extended 64 bit
payload length for websocket text frames instead of the extended 16 bit
payload length. For 64-bit payloads, the expected byte order over the
network is

7, 6, 5, 4, 3, 2, 1, 0

However, we were sending the payload as

3, 2, 1, 0, 7, 6, 5, 4

This meant that we were saying to expect an absolutely MASSIVE payload
to arrive. Since we did not follow through on this expected payload
size, the client would sit patiently waiting for the rest of the payload
to arrive until the test would time out.

With this change, we use the htobe64() function instead of htonl() so
that a 64-bit byte-swap is performed instead of a 32 bit byte-swap.

Change-Id: Ibcd8552392845fbcdd017a8c8c1043b7fe35964a
2015-07-29 14:47:39 -05:00
Mark Duncan 1d081ec970 res/res_rtp_asterisk: Add ECDH support
This will add ECDH support to Asterisk. It will
detect auto ECDH support in OpenSSL
(1.0.2b and above) during ./configure. If this is
available, it will use it,
otherwise it will fall back to prime256v1 (this
behavior is consistent with
other projects such as Apache and nginx).

This fixes WebRTC being broken in Firefox 38+ due
to Firefox now only supporting
ciphers with perfect forward secrecy.

ASTERISK-25265 #close

Change-Id: I8c13b33a2a79c0bde2e69e4ba6afa5ab9351465b
2015-07-29 11:24:49 +09:00
Joshua Colp 309dd2a409 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
2015-07-24 12:43:43 -03:00
Joshua Colp f7f3ae1815 Merge "res_pjsip: Add rtp_keepalive endpoint option." 2015-07-20 15:52:38 -05:00
Mark Michelson 2b42264e66 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: I3b9903d99e35fe5d0b53ecc46df82c750776bc8d
2015-07-20 12:37:01 -05:00
Matt Jordan 0047ca8c84 Merge "res/res_musiconhold: Add a warning when MOH does not exist" 2015-07-19 10:58:00 -05:00
Michael Cargile 8b503f2a10 res/res_musiconhold: Add a warning when MOH does not exist
Change-Id: Ifdfbd0b97cf31478d29923ec30aabce28d01740b
2015-07-19 09:52:31 -05:00
Matt Jordan 9475dc9492 res/res_sorcery_config: Prevent crash from misconfigured sorcery.conf
Misconfiguring sorcery.conf with a 'config' wizard with no extra data
will currently crash Asterisk on startup, as the wizard requires a comma
delineated list to parse. This patch updates res_sorcery_config to check
for the presence of the data before it starts manipulating it.

Change-Id: I4c97512e8258bc82abe190627a9206c28f5d3847
2015-07-19 09:11:18 -05:00
Matt Jordan 254d07b15b ARI: Add support for push configuration of dynamic object
This patch adds support for push configuration of dynamic, i.e.,
sorcery, objects in Asterisk. It adds three new REST API calls to the
'asterisk' resource:
 * GET /asterisk/{configClass}/{objectType}/{id}: retrieve the current
   object given its ID. This returns back a list of ConfigTuples, which
   define the fields and their present values that make up the object.
 * PUT /asterisk/{configClass}/{objectType}/{id}: create or update an
   object. A body may be passed with the request that contains fields to
   populate in the object. The same format as what is retrieved using
   the GET operation is used for the body, save that we specify that the
   list of fields to update are contained in the "fields" attribute.
 * DELETE /asterisk/{configClass}/{objectType}/{id}: remove a dynamic
   object from its backing storage.

Note that the success/failure of these operations is somewhat
configuration dependent, i.e., you must be using a sorcery wizard that
supports the operation in question. If a sorcery wizard does not support
the create or delete mechanisms, then the REST API call will fail with a
403 forbidden.

ASTERISK-25238 #close

Change-Id: I28cd5c7bf6f67f8e9e437ff097f8fd171d30ff5c
2015-07-16 20:38:57 -05:00
Matt Jordan af9ee2910d Merge "parking_applications.c: Fix ast_verb() line terminator." 2015-07-16 20:34:05 -05:00
Matt Jordan f99322ab21 Merge "res_pjsip_session.c: Extract sip_session_defer_termination_stop_timer()." 2015-07-16 20:33:24 -05:00
Matt Jordan 3613babd99 Merge "res_pjsip_session.c: Add some helpful comments and minor tweaks." 2015-07-16 20:33:15 -05:00
Matt Jordan f25660c99d Merge "res_pjsip_session.c: Fix off nominal crash potential in debug message." 2015-07-16 20:33:11 -05:00
Richard Mudgett 097c15ac51 parking_applications.c: Fix ast_verb() line terminator.
Change-Id: I8797238c71563e243c48c6145b4f1ae58f91f775
2015-07-16 12:25:57 -05:00
Richard Mudgett 8b620c555b 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
2015-07-16 12:24:51 -05:00