After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 555490 - need decoding URI utility
need decoding URI utility
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
: 546182 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-10-08 03:05 UTC by David Zeuthen (not reading bugmail)
Modified: 2018-05-24 11:33 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description David Zeuthen (not reading bugmail) 2008-10-08 03:05:28 UTC
In order to implement the "connect to server" feature in Nautilus, some API is needed to decode URIs.

Specifically this is needed for the "edit connected server" property page; for example given the URI sftp://user@server.local:22222/path/to/files we want to present this as

 General
  Server: [server.local              ]
  Name:   [My share at server.local  ]
  Icon:   [some-icon-name            ]

 Optional
  User:   [user                      ]
  Port:   [22222                     ]
  Folder: [/path/to/files            ]

It turns out code for decoding URIs is already in gvfs

 http://svn.gnome.org/viewvc/gvfs/trunk/client/gvfsuriutils.h?revision=1034&view=markup
 http://svn.gnome.org/viewvc/gvfs/trunk/client/gvfsuriutils.c?revision=1558&view=markup

since it's needed for the mount daemons itself. As discussed with alexl on IRC, there's a couple of things about this code

 1. Getting it wrong when decoding an URI may result in security issues
    so correctness is really important

 2. URIs may sometimes be gvfs specific (see bug 530654 and bug 528670 for
    lots of discussion about this). It's not impossible that some other set
    of gio extensions than those found in gvfs may one day be used. Such
    extensions may have a different way of decoding e.g. http URIs.

 3. Win32 got a http gio backend that may use different URIs than in gvfs

Point 1. and the fact that the mount daemons itself using the code, is actually a reason we want this low in the stack. E.g. we want the same behavior (including bug-by-bug compatibility) in the mount daemon (implementing the mount) as well as dialogs for configuring the URI.

Point 2. and point 3. suggests we need to use an extension based system that allows e.g. gvfs to provide one set of decoding functions and e.g. another set of gio extensions to provide another.

For the API, the existing stuff in utils/gvfsuriutils.[ch] seems OK from a high-level point of view. We probably want it to be a bit more GObject'ified but that's more a detail than anything.

To support adding new URI types without having to patch the UI tools, we probably also want a way to enumerate the different supported URI types, so one can write something like

 GList *supported_uri_types, *l;
 supported_uri_types = g_decoded_uri_get_provider ();
 for (l = supported_uri_types; l != NULL; l = l->next) {
   GDecodedUriProvider *provider = G_DECODED_URI_PROVIDER (l->data);
   GDecodedUriFlags flags;
   char *display_name;

   flags = g_decoded_uri_provider_get_flags (provider);
   display_name = g_decoded_uri_provider_get_display_name (provider);

   /* Use display_name to build a GtkComboBox for the user to
    * select the type of the URI. 
    *
    * Use flags to choose what goes into the dialog.
    */

   g_free (display_name);
   g_free (scheme);
 }
 g_list_foreach (supported_uri_types, (GFunc) g_object_unref, NULL);
 g_list_free (supported_uri_types);
 
with GDecodedUriFlags including

 G_DECODED_URI_FLAGS_SHARE
 G_DECODED_URI_FLAGS_PORT
 G_DECODED_URI_FLAGS_USER
 G_DECODED_URI_FLAGS_DOMAIN

This is pretty similar to what's going on in Nautilus's connect to server dialog, e.g. this code

 http://svn.gnome.org/viewvc/nautilus/trunk/src/nautilus-connect-server-dialog.c?revision=14685&view=markup

Implementation-wise I suspect that the gio bits simply just instantiates all sub-types of, say, GUriDecoder. That way, gvfs can provide this through it's gio extension. Or something to that effect.

I'm willing to write the code if something like this will be accepted in gio. Thanks for considering.

     David
Comment 1 Alexander Larsson 2008-10-10 17:25:00 UTC
So, here is the problem. You want something that specifically handles the uris that gvfs handles. However, you want said functions in a very lowlevel generic library that has no direct requirement on gvfs, might not be using it, or might even be using another backend for its i/o (such as the http backend for win32).

I understand this wish, and I see what you want it for. However, I still think having uri decoders like this in glib is a bad idea. If you see a function with g_uri_something you expect them to work on any random uri. For instance, you will want to use these functions when implementing e.g. a web browser or a http library. But that would eventually lead to all sorts of problems, because real world uris are not only like gvfs uris, and there are all sorts of issues you need to take care of in the general case. 

You can't even in general rely on a uri having the hostname, port, filename format (mailto: uris, sip: uris, etc). There are also issues like http uris that contain escaped slashes for servers with filesystem that allow slashes in filenames, meaning you can't ever unescape a uri and re-escape and not modify what you are refering too (ftp does something similar). We ignore all these kind of issues in gvfs because we're not handling "uris", we're handling "gvfs uris" a different kind of entity (but similar and confusingly named).

So, a set of utilities that are actually useful for uris in general is much more limited than what you expect, and it certainly can't make the kind of assumptions that gvfsuriutils.c does. We already have some of them in guriutils.h, perhaps we could add some more, but they won't really be what you want.
Comment 2 Alexander Larsson 2008-10-10 17:49:16 UTC
At a fundamental level, URIs are just not designed for expressing navigable hierarchies of files that you can (at the client side) decode and understand. Instead they are string-based unique identifiers that reference a specific object. In some cases you can sort of ad-hoc map back to a hierarchy and go from one uri to a related one, but in general its just not possible.

Its no accident that the reference to a file on a gvfs share internally is nothing like a URI at all. All we use URIs for is as a marshalling format when passing such a reference via a user visible string.
Comment 3 Matthias Clasen 2009-01-03 04:40:45 UTC
*** Bug 546182 has been marked as a duplicate of this bug. ***
Comment 4 GNOME Infrastructure Team 2018-05-24 11:33:43 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/163.