rtspsrc: Don't replace 404 errors with "no auth protocol found"

When getting a "404 Not Found" response from the DESCRIBE request, the
source produced a "No supported authentication protocol was found" error
instead of passing on the 404, which was confusing.

Only produce this error message when we're handling a response of "401
Unauthorized" without a compatible WWW-Authenticate header.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3493>
This commit is contained in:
Jan Alexander Steffens (heftig) 2022-11-15 11:56:35 +01:00 committed by Tim-Philipp Müller
parent 0881870219
commit f4bf977719

View file

@ -6270,21 +6270,21 @@ gst_rtsp_auth_method_to_string (GstRTSPAuthMethod method)
* *
* At the moment, for Basic auth, we just do a minimal check and don't * At the moment, for Basic auth, we just do a minimal check and don't
* even parse out the realm */ * even parse out the realm */
static void static gboolean
gst_rtspsrc_parse_auth_hdr (GstRTSPMessage * response, gst_rtspsrc_parse_auth_hdr (GstRTSPMessage * response,
GstRTSPAuthMethod * methods, GstRTSPConnection * conn, gboolean * stale) GstRTSPAuthMethod * methods, GstRTSPConnection * conn, gboolean * stale)
{ {
GstRTSPAuthCredential **credentials, **credential; GstRTSPAuthCredential **credentials, **credential;
g_return_if_fail (response != NULL); g_return_val_if_fail (response != NULL, FALSE);
g_return_if_fail (methods != NULL); g_return_val_if_fail (methods != NULL, FALSE);
g_return_if_fail (stale != NULL); g_return_val_if_fail (stale != NULL, FALSE);
credentials = credentials =
gst_rtsp_message_parse_auth_credentials (response, gst_rtsp_message_parse_auth_credentials (response,
GST_RTSP_HDR_WWW_AUTHENTICATE); GST_RTSP_HDR_WWW_AUTHENTICATE);
if (!credentials) if (!credentials)
return; return FALSE;
credential = credentials; credential = credentials;
while (*credential) { while (*credential) {
@ -6312,6 +6312,8 @@ gst_rtspsrc_parse_auth_hdr (GstRTSPMessage * response,
} }
gst_rtsp_auth_credentials_free (credentials); gst_rtsp_auth_credentials_free (credentials);
return TRUE;
} }
/** /**
@ -6340,10 +6342,14 @@ gst_rtspsrc_setup_auth (GstRTSPSrc * src, GstRTSPMessage * response)
GstRTSPConnection *conn; GstRTSPConnection *conn;
gboolean stale = FALSE; gboolean stale = FALSE;
g_return_val_if_fail (response != NULL, FALSE);
conn = src->conninfo.connection; conn = src->conninfo.connection;
/* Identify the available auth methods and see if any are supported */ /* Identify the available auth methods and see if any are supported. If no
gst_rtspsrc_parse_auth_hdr (response, &avail_methods, conn, &stale); * headers were found, propagate the HTTP error. */
if (!gst_rtspsrc_parse_auth_hdr (response, &avail_methods, conn, &stale))
goto propagate_error;
if (avail_methods == GST_RTSP_AUTH_NONE) if (avail_methods == GST_RTSP_AUTH_NONE)
goto no_auth_available; goto no_auth_available;
@ -6375,9 +6381,10 @@ gst_rtspsrc_setup_auth (GstRTSPSrc * src, GstRTSPMessage * response)
* already, request a username and passwd from the application via some kind * already, request a username and passwd from the application via some kind
* of credentials request message */ * of credentials request message */
/* If we don't have a username and passwd at this point, bail out. */ /* If we don't have a username and passwd at this point, bail out and
* propagate the normal NOT_AUTHORIZED error. */
if (user == NULL || pass == NULL) if (user == NULL || pass == NULL)
goto no_user_pass; goto propagate_error;
/* Try to configure for each available authentication method, strongest to /* Try to configure for each available authentication method, strongest to
* weakest */ * weakest */
@ -6410,10 +6417,11 @@ no_auth_available:
("No supported authentication protocol was found")); ("No supported authentication protocol was found"));
return FALSE; return FALSE;
} }
no_user_pass:
propagate_error:
{ {
/* We don't fire an error message, we just return FALSE and let the /* We don't fire an error message, we just return FALSE and let the
* normal NOT_AUTHORIZED error be propagated */ * normal error be propagated */
return FALSE; return FALSE;
} }
} }