URIs vs. half-baked URIs (was Filesel drag and drop)



On Thursday, August 2, 2001, at 02:33  PM, Alex Larsson wrote:

+static gchar *
+uri_extract_filename (const gchar* uri)
+{
+  /* file uri with a hostname */
+  if (strncmp(uri, "file://", strlen("file://"))==0)
+    {
+      const char *hostname = &uri[strlen("file://")];
+      char *p = strchr (hostname,'/');
+
+      /* if we can't find the '/' this uri is bad */
+      if(!p)
+	return NULL;
+
+      return g_strdup (p);
+
+      /* if the file doesn't have the //, we take it containing
+	 a local path */
+    }
+  else if (strncmp (uri, "file:", strlen("file:"))==0)
+    {
+      const char *path = &uri[strlen("file:")];
+      /* if empty bad */
+      if (!*path)
+	return NULL;
+      return g_strdup (path);
+    }
+  return NULL;
+}

I know this kind of code is already in GNOME, but eventually we have to distinguish real URIs from half-baked URIs: paths with "file:" or "file://<hostname>" prefixes but without URI escaping. The code above strips the prefix (ignoring the hostname) and then uses the rest as a path. This won't work for files with "%" characters in their name, it won't work properly if the URIs have "%" escape sequences in them, and it will do the wrong thing for URIs with host names (other than the current host) in them.

I don't mean to pick on Alex, he just happened to be the one who posted the code, but this is a real problem. At some point we have to start distinguishing between places that use real URIs and places that use these kinds of half-baked URIs if we want to be able to drag files that have "%" characters in the file name.

An easy way to do this correctly for code that can have a gnome-vfs dependency is to use gnome_vfs_get_local_path_from_uri or gnome_vfs_get_uri_from_local_path. Maybe we should put these two functions into glib or somewhere in gtk since it's *so* easy and common to get them wrong, and they affect drag and drop.

Relevant functions to look at to see the problem in existing GNOME code are gnome_uri_list_extract_filenames, which extracts paths from URIs in this same half-baked way, and add_one_compatible_uri from eel-dnd.c which goes out of its way to construct half-baked URIs that gnome_uri_list_extract_filenames can deal with.

    -- Darin

_______________________________________________
gnome-hackers mailing list
gnome-hackers gnome org
http://mail.gnome.org/mailman/listinfo/gnome-hackers




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]