From 14a79628a732d040402c09990e43ea80c14a681c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 12 Sep 2011 15:10:37 +0100 Subject: [PATCH] playbin2: try to catch malformed URIs Only log in debug log for now, since the check is a bit half-hearted, its purpose is mostly to make sure people use gst_filename_to_uri() or g_filename_to_uri(). https://bugzilla.gnome.org/show_bug.cgi?id=654673 --- gst/playback/gstplaybin2.c | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gst/playback/gstplaybin2.c b/gst/playback/gstplaybin2.c index 20e24c25b2..b057bbe5ad 100644 --- a/gst/playback/gstplaybin2.c +++ b/gst/playback/gstplaybin2.c @@ -1272,6 +1272,34 @@ gst_play_bin_finalize (GObject * object) G_OBJECT_CLASS (parent_class)->finalize (object); } +static gboolean +gst_playbin_uri_is_valid (GstPlayBin * playbin, const gchar * uri) +{ + const gchar *c; + + GST_LOG_OBJECT (playbin, "checking uri '%s'", uri); + + /* this just checks the protocol */ + if (!gst_uri_is_valid (uri)) + return FALSE; + + for (c = uri; *c != '\0'; ++c) { + if (*c >= 128 || !g_ascii_isprint (*c)) + goto invalid; + if (*c == ' ') + goto invalid; + } + + return TRUE; + +invalid: + { + GST_WARNING_OBJECT (playbin, "uri '%s' not valid, character #%u", + uri, (guint) ((guintptr) c - (guintptr) uri)); + return FALSE; + } +} + static void gst_play_bin_set_uri (GstPlayBin * playbin, const gchar * uri) { @@ -1282,6 +1310,17 @@ gst_play_bin_set_uri (GstPlayBin * playbin, const gchar * uri) return; } + if (!gst_playbin_uri_is_valid (playbin, uri)) { + if (g_str_has_prefix (uri, "file:")) { + GST_ERROR_OBJECT (playbin, "malformed file URI '%s' - make sure to " + "escape spaces and non-ASCII characters properly and specify an " + "absolute path. Use gst_filename_to_uri() to convert filenames " + "to URIs", uri); + } else { + GST_ERROR_OBJECT (playbin, "malformed URI '%s'", uri); + } + } + GST_PLAY_BIN_LOCK (playbin); group = playbin->next_group;