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
This commit is contained in:
Tim-Philipp Müller 2011-09-12 15:10:37 +01:00
parent 454c554b11
commit 14a79628a7

View file

@ -1272,6 +1272,34 @@ gst_play_bin_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (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 static void
gst_play_bin_set_uri (GstPlayBin * playbin, const gchar * uri) 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; 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); GST_PLAY_BIN_LOCK (playbin);
group = playbin->next_group; group = playbin->next_group;