comp.lang.ada
 help / color / mirror / Atom feed
* Open URLs
@ 2010-01-03 18:17 vlc
  2010-01-03 18:36 ` Gautier write-only
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: vlc @ 2010-01-03 18:17 UTC (permalink / raw)


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!



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open URLs
  2010-01-03 18:17 Open URLs vlc
@ 2010-01-03 18:36 ` Gautier write-only
  2010-01-03 18:36 ` Pascal Obry
  2010-01-03 20:05 ` Dmitry A. Kazakov
  2 siblings, 0 replies; 6+ messages in thread
From: Gautier write-only @ 2010-01-03 18:36 UTC (permalink / raw)


> 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?

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/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open URLs
  2010-01-03 18:17 Open URLs vlc
  2010-01-03 18:36 ` Gautier write-only
@ 2010-01-03 18:36 ` Pascal Obry
  2010-01-03 18:53   ` vlc
  2010-01-03 20:05 ` Dmitry A. Kazakov
  2 siblings, 1 reply; 6+ messages in thread
From: Pascal Obry @ 2010-01-03 18:36 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open URLs
  2010-01-03 18:36 ` Pascal Obry
@ 2010-01-03 18:53   ` vlc
  0 siblings, 0 replies; 6+ messages in thread
From: vlc @ 2010-01-03 18:53 UTC (permalink / raw)


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!



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open URLs
  2010-01-03 18:17 Open URLs vlc
  2010-01-03 18:36 ` Gautier write-only
  2010-01-03 18:36 ` Pascal Obry
@ 2010-01-03 20:05 ` Dmitry A. Kazakov
  2010-01-14  8:32   ` David Thompson
  2 siblings, 1 reply; 6+ messages in thread
From: Dmitry A. Kazakov @ 2010-01-03 20:05 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open URLs
  2010-01-03 20:05 ` Dmitry A. Kazakov
@ 2010-01-14  8:32   ` David Thompson
  0 siblings, 0 replies; 6+ messages in thread
From: David Thompson @ 2010-01-14  8:32 UTC (permalink / raw)


On Sun, 3 Jan 2010 21:05:46 +0100, "Dmitry A. Kazakov"
<mailbox@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>




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-01-14  8:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-03 18:17 Open URLs vlc
2010-01-03 18:36 ` Gautier write-only
2010-01-03 18:36 ` Pascal Obry
2010-01-03 18:53   ` vlc
2010-01-03 20:05 ` Dmitry A. Kazakov
2010-01-14  8:32   ` David Thompson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox