Commit graph

244 commits

Author SHA1 Message Date
Thibault Saunier
2fd28195ca Move files from gst-plugins-base into the "subprojects/gst-plugins-base/" subdir 2021-09-24 16:13:26 -03:00
Tobias Ronge
3ec9795a28 rtspconnection: Only reset timeout when socket is unused
After sending or retrieving data, gstrtspconnection resets the socket's
timeout to 0 (infinite). This could cause problems if sending and
receiving at the same time. For example, if RTCP data is sent from the
streaming thread while gstrtspsrc is already retrieving data.

With this patch, timeout is only reset to 0 if there is no other
thread using the socket.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1260>
2021-09-09 06:45:04 +00:00
Per Förlin
535c02c73b gstrtspconnection: Add support to ignore x-server header reply
When connecting to an RTSP server in tunnled mode (HTTP) the server
usually replies with a x-server header. This contains the address
of the intended streaming server. However some servers return an
"invalid" address. Here follows two examples when it might happen.

1. A server use Apache combined with a separate RTSP process to handle
   Https request on port 443. In this case Apache handle TLS and
   connects to the local RTSP server, which results in a local
   address 127.0.0.1 or ::1 in the x-server reply. This address is
   returned to the actual RTSP client in the x-server header.
   The client will receive this address and try to  connect to it
   and fail.

2. The client use a ipv6 link local address with a specified scope id
   fe80::aaaa:bbbb:cccc:dddd%eth0 and connects via Http on port 80.
   The RTSP server receives the connection and returns the address
   in the x-server header. The client will receive this address and
   try to connect to it "as is" without the scope id and fail.

In the case of streaming data from RTSP servers like 1. and 2. it's
useful to have the option to simply ignore the x-server header reply
and continue using the original address.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1192>
2021-08-16 09:06:37 +00:00
Per Förlin
30f88aa7c8 gstrtspconnection: Add IPv6 support for tunneled mode
An IPv6 address must be specified within [] brackets.
Add brackets for IPv6 address used for tunneled mode,
for non-tunneled this is already supported.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1145>
2021-06-24 06:10:19 +00:00
Tim-Philipp Müller
577dabf7b1 Use g_memdup2() where available and add fallback for older GLib versions
g_memdup() is deprecated since GLib 2.68 and we want to avoid
deprecation warnings with recent versions of GLib.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1171>
2021-06-02 14:21:02 +00:00
Nirbheek Chauhan
9b01036664 rtspconnection: Consistently translate GIOError to GstRTSPResult
The users of this API need to be able to differentiate between EINTR
and ERROR. For example, in rtspsrc, gst_rtsp_conninfo_connect()
behaves differently when gst_rtsp_connection_connect_with_response_usec()
returns an ERROR or EINTR. The former is an element error while the
latter is simple a GST_ERROR since it was a user cancellation of the
connection attempt.

Due to this, rtspsrc was incorrectly emitting element errors while
going to NULL, which would or would not reach the application in
a racy manner.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1069>
2021-03-16 08:18:11 +00:00
Kristofer Björkström
11b5ebd058 gstrtspconnection: correct data_size when tunneled mode
gst_rtsp_connection_send_messages_usec in tunneled mode does base64
encode messages. When calculating data_size 1 bytes is added, which
results in ending the base64 with a NULL.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/1051>
2021-02-25 12:21:53 +01:00
Guillaume Desmottes
e8f5777c92 rtsp: remove documentation link on GTimeVal
Looks like it's been removed from glib.devhelp2 on Fedora 31.

Fix #508
2020-03-12 13:44:10 +05:30
Olivier Crête
61aeb4bbc3 rtspconnection: Add functions without GTimeVal deprecate existing
GTimeVal is now deprecated in GLib, so let's deprecate it here too
2019-12-18 18:20:25 +00:00
Joakim Johansson
f2b3e9b4a1 gstrtspconnection: messages_bytes not decreased
The watch->messages_bytes is not decreased when the write operation
from the backlog is only partly successfull.

This commit decreases the watch->messages_bytes for the successfully
sent messages.

Fixes #679
2019-10-21 09:58:27 +00:00
Thibault Saunier
909baa2360 Pass the code through codespell 2019-08-30 13:05:36 +00:00
Göran Jönsson
dcfa999e89 rtspconnection: data-offset increase not set 2019-06-28 07:22:17 +02:00
Göran Jönsson
35f2ea21e6 rtpsconnection: Fix number of n_vectors
Body_offset mean that so much data have been written.

Without this patch n_vectors somtimes  becomes one more than it should
and then there will be an vector that have a random size causing
writev_bytes to cause a "Bad address" error.
2019-06-27 13:18:06 +02:00
Eike Hein
303f927d70 rtspconnection: Start CSeq at 1
RFC 7826 recommends (but does not require) starting at 0,
but at least one known server implementation fails to copy
request sequence numbers <1 into responses due to an
incorrect null check.

The server known to exhibit this behavior is the Parrot
Streaming Server, serving video from their UAV devices.
A fix has been submitted upstream as well:
https://github.com/Parrot-Developers/librtsp/pull/2

The Parrot developers are known to have tested with LibVLC.
In WireShark debugging, LibVLC appears to start with a CSeq
of 2, which is likely why this bug went unnoticed.

This reverts 487595a7d6, which set this to 0 citing the
RFC. The switch to 0 was thus a recent one; it's therefore
possible server implementors relied on the previous
GStreamer client behavior in their tests as well.

Fixes #624.
2019-06-12 16:21:41 +09:00
Sebastian Dröge
03a85de734 libs: Fix various Since markers 2019-04-23 12:28:26 +00:00
Kristofer Bjorkstrom
1dea6d52ce rtspconnection: add Content-Length limit
Add the possible to limit the Content-Length
Define an appropriate request size limit and reject requests exceeding
the limit (413 Request Entity Too Large)
2019-04-22 09:01:32 +00:00
Kristofer Bjorkstrom
487595a7d6 rtspconnection: CSeq initial value set to 0
RFC 7826: "it is RECOMMENDED to start at 0.
2019-04-10 09:09:58 +02:00
Kristofer Bjorkstrom
06b600901c rtspconnection: CSeq validation
Make rtspconnection a little more strict to RFC2326.
Make sure that CSeq is in every RTSP message and that CSeq is valid.

Also break the build_next loop if any parsing fails, By acting on
the builder->status code.
2019-04-10 09:09:58 +02:00
Sebastian Dröge
2ad6b0b432 rtspconnection: Remove unneeded bytes_written >= 0 conditions
It's unsigned and always >= 0.

Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/569
2019-03-22 10:28:16 +02:00
Tobias Ronge
f672277509 gstrtspconnection: Security loophole making heap overflow
The former code allowed an attacker to create a heap overflow by
sending a longer than allowed session id in a response and including a
semicolon to change the maximum length. With this change, the parser
will never go beyond 512 bytes.
2019-03-14 10:24:30 +01:00
Kristofer Bjorkstrom
4bc906e87e rtspconnection: Fix GError set over the top of a previous GError
The function fill_bytes could sometimes return a value greater than zero
and in the same time set the GError.

Function read_bytes calls fill_bytes in a while loop. In the special
case above it would call fill_bytes with error already set.
Thus resulting in "GError set over the top of a previous GError".

Solved this by clearing GError when return value is greater than zero.
Actions are taken depending on error type by caller of read_bytes. Eg.
with EWOULDBLOCK gst_rtsp_source_dispatch_read will try to read the
missing bytes again (GST_RTSP_EINTR )

https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/445
2019-02-18 16:12:58 +00:00
Sebastian Dröge
05f0fe79a2 rtspconnection: Fix uninitialized variable warning when compiling with pre-2.59.1 GLib
gstrtspconnection.c: In function ‘writev_bytes’:
gstrtspconnection.c:1348:10: error: ‘res’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
   return res;
          ^
2019-01-30 13:04:12 +00:00
Seungha Yang
a86fc3da46 rtspconnection: Fix broken build on GLib 2.59.0
GPollableReturn enum was introduced after GLib 2.59.0 release.
2019-01-30 12:29:01 +00:00
Sebastian Dröge
3a0e7fb8f4 rtspconnection: Update to merged GOutputStream::writev() API 2019-01-29 14:17:29 +02:00
Sebastian Dröge
8a54cc3b16 rtspconnection: Handle EOF on writev() after checking for all other error conditions
Otherwise we would return EOF if nothing was written in any case, even
if this was actually a case of TIMEOUT or EWOULDBLOCK for example.

Thanks to Edward Hervey for debugging and finding this issue.
2019-01-29 14:17:23 +02:00
Ognyan Tonchev
87a9f2b92c rtspconnection: Fixes for corrupt RTP packets in dispatch_write()
Fixes 2 problems:

1) Number of unmapped memories does not always match number of mmaped ones in
dispatch_write().
2) When dispatch_write() is dispatched second time after an incomplete write,
already set offsets will not be taken into account, thus corrupt RTP data will
be sent.
2019-01-29 14:17:23 +02:00
Sebastian Dröge
f90dac8d48 rtsp-connection: Make use of new GstRTSPMessage API for directly storing a body buffer and add API for writing multiple messages
By doing so we can send a whole GstBufferList and each memory in the
contained buffers without copying into a single memory area and with a
single writev() call. This improves performance considerably for
high-packet-rate streams.

This depends on https://gitlab.gnome.org/GNOME/glib/merge_requests/333
to be efficient, otherwise each chunk of memory is a separate write()
call.

https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/370
2019-01-29 14:17:23 +02:00
Edward Hervey
962df52fef rtspconnection: Properly exit infinite loop
In the unlikeliness the builder state is invalid, exit the
top-level while(TRUE) loop.
2018-12-17 12:21:01 +01:00
Per Forlin
76aa92be51 rtspconnection: Replace Auth header instead of append
gst_rtsp_connection_send() adds the Authorization header to the request.
If this function is being called multiple times with the same request
it will add one more Authorization header every time.

To fix to this issue do not append a new Authorization header on
top of an existing ones. Remove any existing Authorization headers first
and then add the new one.

Fixes gst-plugins-good#425
2018-12-07 11:36:11 +00:00
Mathieu Duponchelle
aa6daaafc6 rtspconnection: do not duplicate authentication headers
rtsp_connection_send takes care of adding those already,
and some reverse proxies such as nginx will reject the request
altogether if the Authorization header is present twice,
even with the same value.

https://bugzilla.gnome.org/show_bug.cgi?id=797272
2018-10-11 15:35:56 +02:00
Sebastian Dröge
d4f607ef40 rtspconnection: Use GstQueueArray instead of GQueue for the queued messages 2018-06-29 07:38:20 +02:00
Sebastian Cote
9e77d9cacf rtspconnection: also add Content-Type to HTTP POST request when tunnelling
When the GstRTSPConnection class sends a RTSP over HTTP tunnelling
request, the HTTP Content-Type header is missing from the HTTP POST
request.

This isn't a problem with most servers, but there are servers that
rejects the request without there also being a Content-Type header.

RFC 1945:
Any HTTP/1.0 message containing an entity body should include a
Content-Type header field defining the media type of that body.

Apple Dispatch 28:
QuickTime Streaming uses the "application/x-rtsp-tunnelled" MIME
type in both the Content-Type and Accept headers. This reflects
the data type that is expected and delivered by the client and server.

https://bugzilla.gnome.org/show_bug.cgi?id=793110
2018-02-08 16:08:03 +00:00
Sebastian Dröge
9c2d5e863e rtspconnection: Allow setting a custom accept-certificate function for manually checking a TLS certificate for validity
https://bugzilla.gnome.org/show_bug.cgi?id=785024
2017-11-01 13:41:42 +02:00
Thibault Saunier
20fae3f1e0 rtsp: Start implementing support for RTSP 2.0
Properly handle protocol version in the connection

Add the following headers types:
  * Pipelined-Request
  * Media-Properties
  * Seek-Style
  * Accept-Ranges

https://bugzilla.gnome.org/show_bug.cgi?id=781446
2017-10-05 13:16:03 -03:00
Reynaldo H. Verdejo Pinochet
e81c334ca9 Use proper GtkDoc notation for NULL/FALSE/TRUE 2017-10-03 14:31:18 -07:00
Thibault Saunier
099ac9faf2 docs: Convert gtkdoc comments to markdown
Modernizing the documentation, making it simpler to read an
modify and allowing us to possibly switch to hotdoc in the
future.
2017-03-10 18:19:17 -03:00
Sebastian Dröge
828c8604dd rtsp: Add gst_rtsp_generate_digest_auth_response() to calculate digest auth response
https://bugzilla.gnome.org/show_bug.cgi?id=774416
2016-11-21 09:39:21 +02:00
Sergio Torres Soldado
7960bc0380 rtspconnection: Fix potential deadlock caused by blocking read forever
Reset the connection "may_cancel" property to avoid a potential deadlock
if there is no data to read and the socket stays blocked forever.

https://bugzilla.gnome.org/show_bug.cgi?id=768249
2016-07-07 19:15:18 +03:00
Sebastian Dröge
b0c834df1b rtspconnection: Properly initialize stack-allocated RTSP message to all-zeroes 2015-12-14 19:03:33 +01:00
Evan Callaway
5ac65d9e3a rtspconnection: Use relative URI for non-proxy tunneled requests
Match the section 5.1.2 of the HTTP/1.0 spec by using relative URIs unless we
are using a proxy server. Also, send Host header for compatability with
HTTP/1.1 and some HTTP/1.0 servers.

https://bugzilla.gnome.org/show_bug.cgi?id=758922
2015-12-14 18:21:10 +01:00
Evan Callaway
65c7bd7a2c rtspconnection: Support authentication during tunneling setup
gst_rtsp_connection_connect_with_response accepts a response pointer
which it fills with the response from setup_tunneling if the
connection is configured to be tunneled.  The motivation for this is to
allow the caller to inspect the response header to determine if
additional authentication is required so that the connection can be
retried with the appropriate authentication headers.

The function prototype of gst_rtsp_connection_connect has been
preserved for compatability with existing code and wraps
gst_rtsp_connection_connect_with_response.

https://bugzilla.gnome.org/show_bug.cgi?id=749596
2015-12-14 16:00:45 +01:00
Ognyan Tonchev
7a702df863 rtspconnection: Add support for parsing custom headers
https://bugzilla.gnome.org/show_bug.cgi?id=758235
2015-11-18 00:15:32 +00:00
Sebastian Dröge
4115814f36 Update GLib dependency to 2.40.0 2015-10-02 22:19:52 +03:00
Sebastian Dröge
18c610edda rtspconnection: Only drop everything after the ; of a session header in requests
For responses it is actually allowed and used to signal the timeout to the
client!

https://bugzilla.gnome.org/show_bug.cgi?id=736267
2015-06-22 19:51:32 +02:00
Nicolas Dufresne
c9a536af47 gi: Fix warnings in GstRtsp
* The custom GSource is not boxed (skip for now)
* The comment block has wrong name for _read_socket()
2015-06-16 15:50:13 -04:00
Arun Raghavan
37684b35b6 rtsp: Add a FIXME 2.0 for gst_rtsp_connection_create_from_socket()
There's a couple of redundant arguments from the pre-GIO days.
2015-06-12 12:51:22 +05:30
Xavier Claessens
74a4347614 GstRTSPConnection: Add GTlsInteraction support
https://bugzilla.gnome.org/show_bug.cgi?id=750471
2015-06-09 19:47:51 -04:00
Tim-Philipp Müller
853951b646 rtsp: don't use soon-to-be-deprecated g_cancellable_reset()
From the API documentation: "Note that it is generally not
a good idea to reuse an existing cancellable for more
operations after it has been cancelled once, as this
function might tempt you to do. The recommended practice
is to drop the reference to a cancellable after cancelling
it, and let it die with the outstanding async operations.
You should create a fresh cancellable for further async
operations."

https://bugzilla.gnome.org/show_bug.cgi?id=739132
2015-05-19 18:53:01 +01:00
Göran Jönsson
e3a212e0d4 rtspconnection: No remove child if destroyed.
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=740730
2014-12-09 10:32:00 +01:00
Sebastian Dröge
90eb93c2ef Don't compare booleans for equality to TRUE and FALSE
TRUE is 1, but every other non-zero value is also considered true. Comparing
for equality with TRUE would only consider 1 but not the others.
2014-12-01 09:51:12 +01:00