Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Open URLs

10 views
Skip to first unread message

vlc

unread,
Jan 3, 2010, 1:17:58 PM1/3/10
to
Hi *,

I am looking for a way to open URLs (like "file:///home/vlc/file") as
files - as you would do with "Open (Handle, In_File, "/home/vlc/
file")".

I could surely just remove the heading "file://", but this would still
leave me with the problem of special characters like "file:///home/vlc/
name%20with%20spaces".

Does anybody know of a way to translate URLs to paths?

Thanks a lot in advance!

Gautier write-only

unread,
Jan 3, 2010, 1:36:04 PM1/3/10
to

What about doing successive string replacements:
"file://" -> ""
"%20" -> " "
etc.
?
Probably you need to make a "Replace_all" function using
Ada.Strings.Fixed's routines (unless it's already there), then it
should be straightforward.
______________________________________________________________
Gautier's Ada programming -- http://gautiersblog.blogspot.com/

Pascal Obry

unread,
Jan 3, 2010, 1:36:30 PM1/3/10
to
Le 03/01/2010 19:17, vlc a �crit :

> Does anybody know of a way to translate URLs to paths?
>
> Thanks a lot in advance!

Not directly. After removing the file:// prefix, you can use AWS.URL.Decode.

Pascal.

--

--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.net - http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B

vlc

unread,
Jan 3, 2010, 1:53:04 PM1/3/10
to
On Jan 3, 7:36 pm, Pascal Obry <pas...@obry.net> wrote:
>
> Not directly. After removing the file:// prefix, you can use AWS.URL.Decode.
>
> Pascal.

Thanks. This looks quite promising!

Dmitry A. Kazakov

unread,
Jan 3, 2010, 3:05:46 PM1/3/10
to
On Sun, 3 Jan 2010 10:17:58 -0800 (PST), vlc wrote:

> I am looking for a way to open URLs (like "file:///home/vlc/file") as
> files - as you would do with "Open (Handle, In_File, "/home/vlc/
> file")".
>
> I could surely just remove the heading "file://", but this would still
> leave me with the problem of special characters like "file:///home/vlc/
> name%20with%20spaces".

The third / is a delimiter, theoretically there could be something between
file:// and /. The path might be followed by queries and fragments, see
here:

http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax



> Does anybody know of a way to translate URLs to paths?

You just parse it. What is the problem, except that the number of URI
schemes is huge.

Regarding replacing %20 with SP, I am not sure if this has to be done. You
have to dig the documents (RFC) to verify if %<number> is indeed a defined
escape sequence, if there are any in the URI, I do not remember. Otherwise
it is a part of the file name to be passed further as is.

In any case, when you write a parser, you could make it recognize escape
sequences, delimiters etc as it moves the cursor left to right. Something
like:

Pointer := URI'First;
... -- Get scheme, advance pointer
case Scheme is
when File_Schema =>
declare
Path : Unbounded_String;
Code_Point : Integer;
begin
loop
if URI (Pointer) = '%' then
Get (URI, Pointer, Code_Point);
Append (Path, Character'Val (Code_Point));
elsif Is_In (Delimiters, URI (Pointer)) then
exit;
else
Append (Path, URI (Pointer));
Pointer := Pointer + 1;
end if;
exit when Pointer > URI'Last;
end loop;
...
etc

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

David Thompson

unread,
Jan 14, 2010, 3:32:43 AM1/14/10
to
On Sun, 3 Jan 2010 21:05:46 +0100, "Dmitry A. Kazakov"
<mai...@dmitry-kazakov.de> wrote:

> On Sun, 3 Jan 2010 10:17:58 -0800 (PST), vlc wrote:
>
> > I am looking for a way to open URLs (like "file:///home/vlc/file") as
> > files - as you would do with "Open (Handle, In_File, "/home/vlc/
> > file")".
> >
> > I could surely just remove the heading "file://", but this would still
> > leave me with the problem of special characters like "file:///home/vlc/
> > name%20with%20spaces".
>
> The third / is a delimiter, theoretically there could be something between
> file:// and /. The path might be followed by queries and fragments, see
> here:
>
> http://en.wikipedia.org/wiki/URI_scheme#Generic_syntax
>

Although one can just say queries aren't supported for resources that
are actually files, since they don't make sense. (Although they might
for something like a cryptographic FS where you must supply a password
-- but then whether you should allow a password to be supplied by a
potentially untrusted path is another issue.)

Fragments are supposed to be implemented by the user agent (for the
web, normally a browser); it's not clear to me whether the OP does or
anyone else would want this below or above the proposed API.

> > Does anybody know of a way to translate URLs to paths?
>
> You just parse it. What is the problem, except that the number of URI
> schemes is huge.
>

Nontrivial but I wouldn't say huge -- and the number that make sense
for files is pretty small. And the OP apparently only needs one.

> Regarding replacing %20 with SP, I am not sure if this has to be done. You
> have to dig the documents (RFC) to verify if %<number> is indeed a defined
> escape sequence, if there are any in the URI, I do not remember. Otherwise
> it is a part of the file name to be passed further as is.
>

Yes % two-hex is in STD66=RFC3986 2, and %20=SP is even the example.

Of course if there are codepoints not allowed in a pathname, like NUL
on Unix, you can't support the corresponding escape %00 in a URI.
And you need to decide some things like whether %2F is treated as a
branch-character / which is similarly unsupportable, or as a branch
delimiter in violation of the nominal URI semantics.

<snip code>

0 new messages