You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Paul Marculescu <pa...@p16.pub.ro> on 2002/06/03 03:15:19 UTC

[PATCH] apr_uri

I made a little patch for apr-util's apr_uri.c to handle win32 absolute
paths under file:// schema.




Index: uri/apr_uri.c
===================================================================
RCS file: /home/cvspublic/apr-util/uri/apr_uri.c,v
retrieving revision 1.12
diff -u -r1.12 apr_uri.c
--- uri/apr_uri.c	13 Mar 2002 20:40:49 -0000	1.12
+++ uri/apr_uri.c	2 Jun 2002 23:25:08 -0000
@@ -127,6 +127,7 @@
                                                unsigned flags)
 {
     char *ret = "";
+	char *slsh = "";
 
     /* If suppressing the site part, omit both user name &
scheme://hostname */
     if (!(flags & APR_URI_UNP_OMITSITEPART)) {
@@ -163,9 +164,23 @@
 
     /* Should we suppress all path info? */
     if (!(flags & APR_URI_UNP_OMITPATHINFO)) {
+		/* If this is a WIN32 platform and the uri schema is file://,
+		 * we should add the '/' starting the path if there is an absolute
WIN32 path
+		 * (including the drive letter)
+		 */
+#ifdef WIN32
+		if (uptr->scheme && strcasecmp("file", uptr->scheme) == 0) {
+			/* see if there is enough room to chech for a drive letter and a ':'
*/
+			if ( uptr->path && strlen(uptr->path) > 1) {
+				if (uptr->path[1] == ':')
+					slsh = apr_pstrcat (p, slsh, "/", NULL ) ;
+			}
+		}
+#endif
 	/* Append path, query and fragment strings: */
 	ret = apr_pstrcat (p,
 		ret,
+		slsh,
 		uptr->path ? uptr->path : "",
 		(uptr->query    && !(flags & APR_URI_UNP_OMITQUERY)) ? "?" : "",
 		(uptr->query    && !(flags & APR_URI_UNP_OMITQUERY)) ? uptr->query :
"",
@@ -246,6 +261,19 @@
 	    ++s;
 	}
 	if (s != uri) {
+		/* If this is a WIN32 platform and the uri schema is file://,
+		 * we skip the '/' starting the path if there is an absolute WIN32
path
+		 * (including the drive letter)
+		 */
+#ifdef WIN32
+		if (uptr->scheme && strcasecmp("file", uptr->scheme) == 0) {
+			/* see if there is enough room to chech for a drive letter and a ':'
*/
+			if (s - uri > 2) {
+				if (uri_delims[*(unsigned char*)(uri + 2)] & T_COLON)
+					uri++;
+			}
+		}
+#endif
 	    uptr->path = apr_pstrmemdup(p, uri, s - uri);
 	}
 	if (*s == 0) {

Re: [PATCH] apr_uri

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 02:51 AM 6/3/2002, Paul replied:

>Cliff Woolley wrote:
> >
> > On Mon, 3 Jun 2002, Paul Marculescu wrote:
> >
> > > I made a little patch for apr-util's apr_uri.c to handle win32 absolute
> > > paths under file:// schema.
> >
> > I'll admit it strikes me as a bit odd to be supporting platform-specific
> > forms of _uniform_ resource identifiers.  :-)  Is this a
> > standards-recognized form or is it just one that Microsoft made up?  If
> > it's valid under the standard, then I suppose it makes sense to support
> > it.
>
>:)
>I think you are right, but suppose you're on a Win32 platform and you
>want to specify
>this path: D:/test in a file url. According to the standards, it will be
>file:///D:/test
>Right?
>
>The apr_uri_parse() function generates the path /D:/test from this URI.
>This is where I got a little confused, since rfc's said:
>
>  A file URL takes the form:
>   file://<host>/<path>
>  where <host> is the fully qualified domain name of the system on
>  which the <path> is accessible, and <path> is a hierarchical
>  directory path of the form <directory>/<directory>/.../<name>.
>
>so why is the '/' after the host included in the path?

It is... ever used Netscape?  They choose to follow the rfc (while encoding
the d: as d|... e.g. file:///d|/foo ... and unless that second colon is 
ambigious,
I'd suggest we support either : or | for consistency [the "|" is entirely 
invalid in
win32 paths, as are ">" and "<"].



Re: [PATCH] apr_uri

Posted by Cliff Woolley <jw...@virginia.edu>.
On Mon, 3 Jun 2002, Paul Marculescu wrote:

> > PS: Please be sure to follow our styleguide when submitting patches...
> > namely, no tabs.  :)
>
> There were some tabs in the apr_uri.c as I "cvs co" it a few minutes ago
> (again, to make sure).
>
> so I got a little confused. Anyway, I'll keep that in mind.

Hmmm... so they did.  Best I can tell you is do as we say, not as we do.
:-/  Anyway, the style police just came along and cleaned up apr_uri.c and
apr_uri.h.  :)

Thanks,
Cliff


Re: [PATCH] apr_uri

Posted by Paul Marculescu <pa...@p16.pub.ro>.

Cliff Woolley wrote:
> 
> On Mon, 3 Jun 2002, Paul Marculescu wrote:
> 
> > I made a little patch for apr-util's apr_uri.c to handle win32 absolute
> > paths under file:// schema.
> 
> I'll admit it strikes me as a bit odd to be supporting platform-specific
> forms of _uniform_ resource identifiers.  :-)  Is this a
> standards-recognized form or is it just one that Microsoft made up?  If
> it's valid under the standard, then I suppose it makes sense to support
> it.

:)
I think you are right, but suppose you're on a Win32 platform and you
want to specify 
this path: D:/test in a file url. According to the standards, it will be
file:///D:/test 
Right?

The apr_uri_parse() function generates the path /D:/test from this URI.
This is where I got a little confused, since rfc's said:

 A file URL takes the form:
  file://<host>/<path>
 where <host> is the fully qualified domain name of the system on
 which the <path> is accessible, and <path> is a hierarchical 
 directory path of the form <directory>/<directory>/.../<name>. 

so why is the '/' after the host included in the path?
On Unix platforms, this is quite ok, as the fs there has a single root:
'/'.
On Win32, there is no single root, so not all paths can be expressed as
relative path from any other path.
Getting back to my problem, I end up with this: /D:/test, which is not
good.

If the URL was file:///test, the path will be /test, which on Win32
means: the "test" directory in the root of the current partition. What
if the current partition is not "D:" ?

That's why I thought of this patch.

> 
> Then there is also the issue that things in APR-util are supposed to be
> platform-neutral... we'll have to figure out how to deal with that.  That
> doesn't mean that I think we should move this stuff to APR, of course.
> We need to find a middle ground.
> 
> --Cliff
> 
> PS: Please be sure to follow our styleguide when submitting patches...
> namely, no tabs.  :)

There were some tabs in the apr_uri.c as I "cvs co" it a few minutes ago
(again, to make sure).
...
000014E0:  20 28 70 2C 0D 0A 09 09
...

so I got a little confused. Anyway, I'll keep that in mind.


Paul

Re: [PATCH] apr_uri

Posted by Cliff Woolley <jw...@virginia.edu>.
On Mon, 3 Jun 2002, Paul Marculescu wrote:

> I made a little patch for apr-util's apr_uri.c to handle win32 absolute
> paths under file:// schema.

I'll admit it strikes me as a bit odd to be supporting platform-specific
forms of _uniform_ resource identifiers.  :-)  Is this a
standards-recognized form or is it just one that Microsoft made up?  If
it's valid under the standard, then I suppose it makes sense to support
it.

Then there is also the issue that things in APR-util are supposed to be
platform-neutral... we'll have to figure out how to deal with that.  That
doesn't mean that I think we should move this stuff to APR, of course.
We need to find a middle ground.

--Cliff

PS: Please be sure to follow our styleguide when submitting patches...
namely, no tabs.  :)