From: Patricia Muscalu Date: Tue, 12 Nov 2013 09:55:14 +0000 (+0100) Subject: client: allow absolute path in requests X-Git-Tag: 1.19.3~495^2~933 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=adc02db975d8bf615dda3e33efcb0feb490f5e83;p=platform%2Fupstream%2Fgstreamer.git client: allow absolute path in requests Fixes https://bugzilla.gnome.org/show_bug.cgi?id=711689 --- diff --git a/gst/rtsp-server/rtsp-client.c b/gst/rtsp-server/rtsp-client.c index 3a90f52..a9c7ed1 100644 --- a/gst/rtsp-server/rtsp-client.c +++ b/gst/rtsp-server/rtsp-client.c @@ -1934,8 +1934,34 @@ handle_request (GstRTSPClient * client, GstRTSPMessage * request) /* we always try to parse the url first */ if (strcmp (uristr, "*") == 0) { /* special case where we have * as uri, keep uri = NULL */ - } else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) - goto bad_request; + } else if (gst_rtsp_url_parse (uristr, &uri) != GST_RTSP_OK) { + /* check if the uristr is an absolute path <=> scheme and host information + * is missing */ + gchar *scheme; + + scheme = g_uri_parse_scheme (uristr); + if (scheme == NULL && g_str_has_prefix (uristr, "/")) { + gchar *absolute_uristr = NULL; + + GST_WARNING_OBJECT (client, "request doesn't contain absolute url"); + if (priv->server_ip == NULL) { + GST_WARNING_OBJECT (client, "host information missing"); + goto bad_request; + } + + absolute_uristr = g_strdup_printf ("rtsp://%s%s", priv->server_ip, uristr); + + GST_DEBUG_OBJECT (client, "absolute url: %s", absolute_uristr); + if (gst_rtsp_url_parse (absolute_uristr, &uri) != GST_RTSP_OK) { + g_free (absolute_uristr); + goto bad_request; + } + g_free (absolute_uristr); + } else { + g_free (scheme); + goto bad_request; + } + } /* get the session if there is any */ res = gst_rtsp_message_get_header (request, GST_RTSP_HDR_SESSION, &sessid, 0); diff --git a/tests/check/gst/client.c b/tests/check/gst/client.c index f30056d..da99aa8 100644 --- a/tests/check/gst/client.c +++ b/tests/check/gst/client.c @@ -155,6 +155,9 @@ GST_START_TEST (test_request) GstRTSPClient *client; GstRTSPMessage request = { 0, }; gchar *str; + GstRTSPConnection *conn; + GSocket *sock; + GError *error = NULL; client = gst_rtsp_client_new (); @@ -185,6 +188,41 @@ GST_START_TEST (test_request) gst_rtsp_message_unset (&request); + /* OPTIONS with an absolute path instead of an absolute url */ + /* set host information */ + sock = g_socket_new (G_SOCKET_FAMILY_IPV4, G_SOCKET_TYPE_STREAM, + G_SOCKET_PROTOCOL_TCP, &error); + g_assert_no_error (error); + gst_rtsp_connection_create_from_socket (sock, "localhost", 444, NULL, &conn); + fail_unless (gst_rtsp_client_set_connection (client, conn)); + g_object_unref (sock); + + fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS, + "/test") == GST_RTSP_OK); + str = g_strdup_printf ("%d", cseq); + gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str); + g_free (str); + + gst_rtsp_client_set_send_func (client, test_response_200, NULL, NULL); + fail_unless (gst_rtsp_client_handle_message (client, + &request) == GST_RTSP_OK); + gst_rtsp_message_unset (&request); + + /* OPTIONS with an absolute path instead of an absolute url with invalid + * host information */ + g_object_unref (client); + client = gst_rtsp_client_new (); + fail_unless (gst_rtsp_message_init_request (&request, GST_RTSP_OPTIONS, + "/test") == GST_RTSP_OK); + str = g_strdup_printf ("%d", cseq); + gst_rtsp_message_add_header (&request, GST_RTSP_HDR_CSEQ, str); + g_free (str); + + gst_rtsp_client_set_send_func (client, test_response_400, NULL, NULL); + fail_unless (gst_rtsp_client_handle_message (client, + &request) == GST_RTSP_OK); + gst_rtsp_message_unset (&request); + g_object_unref (client); }