From: Sebastian Dröge Date: Fri, 12 Aug 2022 10:16:50 +0000 (+0300) Subject: rtspurl: Use gst_uri_join_strings() in gst_rtsp_url_get_request_uri_with_control... X-Git-Tag: 1.22.0~1113 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edb0e47074ed7b84fe3f33858908392aaaa1818a;p=platform%2Fupstream%2Fgstreamer.git 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: --- diff --git a/subprojects/gst-plugins-base/gst-libs/gst/rtsp/gstrtspurl.c b/subprojects/gst-plugins-base/gst-libs/gst/rtsp/gstrtspurl.c index 2fc95cc..d03e464 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/rtsp/gstrtspurl.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/rtsp/gstrtspurl.c @@ -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, "/"); - - 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 : ""; + /* FIXME: Use GUri here once we can depend on GLib 2.66 */ - 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; } diff --git a/subprojects/gst-plugins-base/tests/check/libs/rtsp.c b/subprojects/gst-plugins-base/tests/check/libs/rtsp.c index e09d776..ceca267 100644 --- a/subprojects/gst-plugins-base/tests/check/libs/rtsp.c +++ b/subprojects/gst-plugins-base/tests/check/libs/rtsp.c @@ -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);