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>
This commit is contained in:
Per Förlin 2021-06-01 15:27:31 +02:00 committed by Nirbheek Chauhan
parent 3ced923da5
commit 535c02c73b
2 changed files with 48 additions and 1 deletions

View file

@ -173,6 +173,7 @@ struct _GstRTSPConnection
gchar tunnelid[TUNNELID_LEN];
gboolean tunneled;
gboolean ignore_x_server_reply;
GstRTSPTunnelState tstate;
/* the remote and local ip */
@ -878,7 +879,8 @@ setup_tunneling (GstRTSPConnection * conn, gint64 timeout, gchar * uri,
response->type_data.response.code != GST_RTSP_STS_OK)
goto wrong_result;
if (gst_rtsp_message_get_header (response, GST_RTSP_HDR_X_SERVER_IP_ADDRESS,
if (!conn->ignore_x_server_reply &&
gst_rtsp_message_get_header (response, GST_RTSP_HDR_X_SERVER_IP_ADDRESS,
&value, 0) == GST_RTSP_OK) {
g_free (url->host);
url->host = g_strdup (value);
@ -3463,6 +3465,45 @@ gst_rtsp_connection_get_tunnelid (const GstRTSPConnection * conn)
return conn->tunnelid;
}
/**
* gst_rtsp_connection_set_ignore_x_server_reply:
* @conn: a #GstRTSPConnection
* @ignore: %TRUE to ignore the x-server-ip-address header reply or %FALSE to
* comply with it (%FALSE is the default).
*
* Set whether to ignore the x-server-ip-address header reply or not. If the
* header is ignored, the original address will be used instead.
*
* Since: 1.20
*/
void
gst_rtsp_connection_set_ignore_x_server_reply (GstRTSPConnection * conn,
gboolean ignore)
{
g_return_if_fail (conn != NULL);
conn->ignore_x_server_reply = ignore;
}
/**
* gst_rtsp_connection_get_ignore_x_server_reply:
* @conn: a #GstRTSPConnection
*
* Get the ignore_x_server_reply value.
*
* Returns: returns %TRUE if the x-server-ip-address header reply will be
* ignored, else returns %FALSE
*
* Since: 1.20
*/
gboolean
gst_rtsp_connection_get_ignore_x_server_reply (const GstRTSPConnection * conn)
{
g_return_val_if_fail (conn != NULL, FALSE);
return conn->ignore_x_server_reply;
}
/**
* gst_rtsp_connection_do_tunnel:
* @conn: a #GstRTSPConnection

View file

@ -235,6 +235,12 @@ void gst_rtsp_connection_set_remember_session_id (GstRTSPConnectio
GST_RTSP_API
gboolean gst_rtsp_connection_get_remember_session_id (GstRTSPConnection *conn);
GST_RTSP_API
void gst_rtsp_connection_set_ignore_x_server_reply (GstRTSPConnection *conn, gboolean ignore);
GST_RTSP_API
gboolean gst_rtsp_connection_get_ignore_x_server_reply (const GstRTSPConnection *conn);
/* async IO */
/**