mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-05 09:00:54 +00:00
rtspurl: Use gst_uri_join_strings() in gst_rtsp_url_get_request_uri_with_control() instead of a hand-crafted, wrong version
For example the query string of the base must not be taken over to the request URL unless there is no control path, and control paths can be absolute and must not be considered relative if they start with a /. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/971 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2877>
This commit is contained in:
parent
7d7c608c2c
commit
54e29f0244
2 changed files with 27 additions and 49 deletions
|
@ -319,8 +319,27 @@ gst_rtsp_url_get_port (const GstRTSPUrl * url, guint16 * port)
|
|||
gchar *
|
||||
gst_rtsp_url_get_request_uri (const GstRTSPUrl * url)
|
||||
{
|
||||
gchar *uri;
|
||||
const gchar *pre_host;
|
||||
const gchar *post_host;
|
||||
const gchar *pre_query;
|
||||
const gchar *query;
|
||||
|
||||
return gst_rtsp_url_get_request_uri_with_control (url, NULL);
|
||||
g_return_val_if_fail (url != NULL, NULL);
|
||||
|
||||
pre_host = url->family == GST_RTSP_FAM_INET6 ? "[" : "";
|
||||
post_host = url->family == GST_RTSP_FAM_INET6 ? "]" : "";
|
||||
pre_query = url->query ? "?" : "";
|
||||
query = url->query ? url->query : "";
|
||||
|
||||
if (url->port != 0) {
|
||||
uri = g_strdup_printf ("rtsp://%s%s%s:%u%s%s%s", pre_host, url->host,
|
||||
post_host, url->port, url->abspath, pre_query, query);
|
||||
} else {
|
||||
uri = g_strdup_printf ("rtsp://%s%s%s%s%s%s", pre_host, url->host,
|
||||
post_host, url->abspath, pre_query, query);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -340,57 +359,16 @@ gchar *
|
|||
gst_rtsp_url_get_request_uri_with_control (const GstRTSPUrl * url,
|
||||
const gchar * control_path)
|
||||
{
|
||||
|
||||
gchar *url_string;
|
||||
gchar *uri;
|
||||
const gchar *pre_host;
|
||||
const gchar *post_host;
|
||||
const gchar *pre_query;
|
||||
const gchar *query;
|
||||
gboolean has_slash;
|
||||
const gchar *slash;
|
||||
const gchar *actual_control_path = NULL;
|
||||
|
||||
g_return_val_if_fail (url != NULL, NULL);
|
||||
|
||||
has_slash = g_str_has_suffix (url->abspath, "/");
|
||||
/* FIXME: Use GUri here once we can depend on GLib 2.66 */
|
||||
|
||||
if (control_path && strlen (control_path) > 0) {
|
||||
gboolean control_has_slash;
|
||||
|
||||
/* treat wild card as empty control path */
|
||||
if (g_strcmp0 (control_path, "*") == 0)
|
||||
control_path = "";
|
||||
control_has_slash = g_str_has_prefix (control_path, "/");
|
||||
actual_control_path = control_path;
|
||||
if (has_slash && control_has_slash) {
|
||||
if (strlen (control_path) == 1) {
|
||||
actual_control_path = NULL;
|
||||
} else {
|
||||
actual_control_path = control_path + 1;
|
||||
}
|
||||
} else {
|
||||
has_slash = has_slash || control_has_slash;
|
||||
}
|
||||
}
|
||||
slash = (!has_slash && (actual_control_path != NULL)) ? "/" : "";
|
||||
if (!actual_control_path)
|
||||
actual_control_path = "";
|
||||
|
||||
pre_host = url->family == GST_RTSP_FAM_INET6 ? "[" : "";
|
||||
post_host = url->family == GST_RTSP_FAM_INET6 ? "]" : "";
|
||||
pre_query = url->query ? "?" : "";
|
||||
query = url->query ? url->query : "";
|
||||
|
||||
if (url->port != 0) {
|
||||
uri =
|
||||
g_strdup_printf ("rtsp://%s%s%s:%u%s%s%s%s%s", pre_host,
|
||||
url->host, post_host, url->port, url->abspath,
|
||||
slash, actual_control_path, pre_query, query);
|
||||
} else {
|
||||
uri =
|
||||
g_strdup_printf ("rtsp://%s%s%s%s%s%s%s%s", pre_host, url->host,
|
||||
post_host, url->abspath, slash, actual_control_path, pre_query, query);
|
||||
}
|
||||
url_string = gst_rtsp_url_get_request_uri (url);
|
||||
uri = gst_uri_join_strings (url_string, control_path);
|
||||
g_clear_pointer (&url_string, g_free);
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ GST_START_TEST (test_rtsp_url_query)
|
|||
gchar *uri;
|
||||
const gchar *original_uri = "rtsp://localhost/foo/bar/?baz=fooo";
|
||||
const gchar *original_uri_with_control =
|
||||
"rtsp://localhost/foo/bar/video/stream1?baz=fooo";
|
||||
"rtsp://localhost/foo/bar/video/stream1";
|
||||
|
||||
res = gst_rtsp_url_parse (original_uri, &url);
|
||||
fail_unless (res == GST_RTSP_OK);
|
||||
|
@ -75,7 +75,7 @@ GST_START_TEST (test_rtsp_url_query)
|
|||
uri = gst_rtsp_url_get_request_uri (url);
|
||||
fail_unless_equals_string (uri, original_uri);
|
||||
g_free (uri);
|
||||
uri = gst_rtsp_url_get_request_uri_with_control (url, "/video/stream1");
|
||||
uri = gst_rtsp_url_get_request_uri_with_control (url, "video/stream1");
|
||||
fail_unless_equals_string (uri, original_uri_with_control);
|
||||
g_free (uri);
|
||||
|
||||
|
|
Loading…
Reference in a new issue