new function, fixed and factored out of file_utils_filename_to_uri().

2007-05-14  Michael Natterer  <mitch@gimp.org>

	* app/file/file-utils.[ch] (file_utils_filename_is_uri): new function,
	fixed and factored out of file_utils_filename_to_uri().

	* app/main.c (gimp_dbus_open): use it here instead of a simple
	strstr(filename, "://").


svn path=/trunk/; revision=22484
This commit is contained in:
Michael Natterer 2007-05-13 23:15:34 +00:00 committed by Michael Natterer
parent e0719dfd82
commit 88ac187c84
4 changed files with 62 additions and 24 deletions

View File

@ -1,3 +1,11 @@
2007-05-14 Michael Natterer <mitch@gimp.org>
* app/file/file-utils.[ch] (file_utils_filename_is_uri): new function,
fixed and factored out of file_utils_filename_to_uri().
* app/main.c (gimp_dbus_open): use it here instead of a simple
strstr(filename, "://").
2007-05-14 Tor Lillqvist <tml@novell.com>
* libgimpbase/gimpenv.c: Undef DATADIR before including <shlobj.h>

View File

@ -51,6 +51,50 @@ static gchar * file_utils_unescape_uri (const gchar *escaped,
gboolean ascii_must_not_be_escaped);
gboolean
file_utils_filename_is_uri (const gchar *filename,
GError **error)
{
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (strstr (filename, "://"))
{
gchar *scheme;
gchar *canon;
scheme = g_strndup (filename, (strstr (filename, "://") - filename));
canon = g_strdup (scheme);
g_strcanon (canon, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.", '-');
if (strcmp (scheme, canon) || ! g_ascii_isgraph (canon[0]))
{
g_set_error (error, G_FILE_ERROR, 0,
_("'%s:' is not a valid URI scheme"), scheme);
g_free (scheme);
g_free (canon);
return FALSE;
}
g_free (scheme);
g_free (canon);
if (! g_utf8_validate (filename, -1, NULL))
{
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
_("Invalid character sequence in URI"));
return FALSE;
}
return TRUE;
}
return FALSE;
}
gchar *
file_utils_filename_to_uri (Gimp *gimp,
const gchar *filename,
@ -78,29 +122,13 @@ file_utils_filename_to_uri (Gimp *gimp,
return NULL;
}
}
else if (strstr (filename, "://"))
else if (file_utils_filename_is_uri (filename, error))
{
gchar *scheme;
gchar *canon;
scheme = g_strndup (filename, (strstr (filename, "://") - filename));
canon = g_strdup (scheme);
g_strcanon (canon, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "+-.", '-');
if (! strcmp (scheme, canon) && g_ascii_isgraph (canon[0]))
{
g_set_error (error, G_FILE_ERROR, 0,
_("URI scheme '%s:' is not supported"), scheme);
g_free (scheme);
g_free (canon);
return NULL;
return g_strdup (filename);
}
g_free (scheme);
g_free (canon);
else if (error)
{
return NULL;
}
if (! g_path_is_absolute (filename))

View File

@ -25,6 +25,8 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
gboolean file_utils_filename_is_uri (const gchar *filename,
GError **error);
gchar * file_utils_filename_to_uri (Gimp *gimp,
const gchar *filename,
GError **error);

View File

@ -718,11 +718,11 @@ gimp_dbus_open (const gchar **filenames,
const gchar *filename = filenames[i];
gchar *uri;
if (strstr (filename, "://"))
if (file_utils_filename_is_uri (filename, &error))
{
uri = g_strdup (filename);
}
else
else if (! error)
{
if (! g_path_is_absolute (filename))
{