back

uri

Description:

Facilities for parsing RFC 1739 Uniform Resource Locators & RFC 3986 Uniform Resource Identifiers

Author:

Kon Lovett
Aubrey Jaffer

Usage:

(require-extension uri)

Download:

uri.egg

Requires:

coerce miscmacros synch lookup-table

Documentation:

[procedure] (uri STRING [DEFAULT-URI])

Parses the Uniform Resource Identifier (RFC 3986) STRING and returns a Uniform Resource Identifier object. Returns the DEFAULT-URI, if provided, when the parse fails, otherwise signals an error.

[procedure] (make-uri #!key scheme specific fragment ...)

Returns a Uniform Resource Identifier object from unencoded component arguments.

[procedure] (*make-uri scheme specific fragment ...)

Returns a Uniform Resource Identifier object from unencoded component arguments.

[procedure] (uri-scheme URI)
[procedure] (uri-specific URI)
[procedure] (uri-fragment URI)
[procedure] (uri-authority URI)
[procedure] (uri-userinfo URI)
[procedure] (uri-username URI)
[procedure] (uri-password URI)
[procedure] (uri-host URI)
[procedure] (uri-port URI)
[procedure] (uri-path URI)
[procedure] (uri-query URI)

Accessor procedures for URI objects.

Any can be #f, indicating a missing item.

A null string, "", indicates a root element.

Example: An authority of (#f "" #f) means missing userinfo, missing port, and the "root" host or "localhost". In this case the actual host was missing from the source URI string, as in "file:///usr/local/share/chicken/doc/chicken.html#Index".

[procedure] (uri? X)

Returns #t if X is an URI object, or #f otherwise.

[parameter] (uri-missing-query-value [X])

Gets or sets the object used for a query value when none is supplied. Default is #t.

[parameter] (uri-rfc3986-strict [X])

Gets or sets the strict standard parsing flag. Default is #t.

Currently this only effects the precedence of authority over path with an ambiguous uri. When #t the path component has precedence.

[procedure] (uri-scheme-symbol STRING [PARSE?])

Returns the Uniform Resource Identifier (RFC 3986) scheme component from STRING as a symbol with a lower-case printname, or #f if none present.

[procedure] (uri-path-null? URI)

Is the path component of the "null"?

[procedure] (uri->string URI)

Returns the URI encoded string form of the URI object.

Any query component values are converted to a string before the query component string form is built.

[procedure] (uri->list STRING [BASIS])

Returns a decoded list form - (scheme specific fragment ...).

[procedure] (list->uri LIST)

Returns a uri object for the decoded list form.

[procedure] (uri-split-path PATH)

Returns the "rooted" list form of the string form PATH.

[procedure] (uri-split-path-null? PATH-LIST)

Is the PATH-LIST "null"?

[procedure] (uri-encode-split-path PATH-LIST)

Returns a URI string combining the components of PATH-LIST.

[procedure] (uri-decode-split-path PATH-LIST [BASE-PATH-LIST])

Returns a path-list from the encoded PATH-LIST, with optional BASE-PATH-LIST.

The optional BASE-PATH-LIST is used as the base address for relative paths.

[procedure] (uri-decode-path PATH [BASE-PATH-LIST])

Returns a list path from the string PATH, with optional BASE-PATH-LIST.

The optional BASE-PATH-LIST is used as the base address for relative paths.

[procedure] (uri-encode-query QUERY-ALIST [MISSING])

Converts a QUERY-ALIST to a URI encoded query-string.

[procedure] (uri-decode-query QUERY-STRING [MISSING])

Converts a URI encoded QUERY-STRING to a query-alist.

[procedure] (uri-encode URI-COMPONENT [ALLOWED ...])

Returns a copy of the string URI-COMPONENT in which all unsafe octets (as defined in RFC 3986) have been `%' escaped. uri-decode decodes strings encoded by uri-encode.

[procedure] (uri-decode URI-COMPONENT)

Returns a copy of the string URI-COMPONENT in which each `%' escaped characters in URI-component is replaced with the character it encodes. This routine is useful for showing URI contents on error pages.

[procedure] (absolute-uri? STRING)

Returns #t if STRING is an absolute URI as indicated by a syntactically valid (per RFC 3986) scheme; otherwise returns #f.

[procedure] (pathname->uri PATHNAME)

Returns a URI-string for PATHNAME on the local host.

[procedure] (uri-new-scheme-specific SCHEME #:fielder #:parser #:maker #:encoder #:decoder #:data #:associations)

Sets the scheme specific handler (class) for SCHEME.

[procedure] (uri->tree URI-STR [BASE-TREE]) DEPRECATED

Use

(let ([lst (uri->list uri-str
                      (and base-tree
                           `(,(first base-tree)
                             (,(second base-tree) ,(third base-tree) ,(fourth base-tree))
                             ,(fifth base-tree))))])
  `(,(first lst) ,@(second lst) ,(third lst)) )

Returns a list of 5 elements corresponding to the parts (scheme authority path query fragment) of string URI-STR. Elements corresponding to absent parts are #f.

The path is a list of strings. If the first string is empty, then the path is absolute; otherwise relative. The optional BASE-TREE is a tree as returned by uri->tree; and is used as the base address for relative URIs.

If the authority component is a Server-based Naming Authority, then it is a list of the userinfo, host, and port strings (or #f). For other types of authority components the authority will be a string.

  (uri->tree "http://www.ics.uci.edu:80/pub/ietf/uri/#Related")
  =>
  (http (#f "www.ics.uci.edu" 80) ("" "pub" "ietf" "uri" "") #f #f "Related")
[procedure] (uri-scheme-specific URI) DEPRECATED

Use (uri-specific URI).

[procedure] (uri-make-path PATH-LIST) DEPRECATED

Use uri-encode-split-path.

Returns a URI string combining the components of PATH-LIST.

[procedure] (uri-split-fields STR CHR) DEPRECATED

Use unit extras string-split.

Returns a list of STR split at each occurrence of CHR. CHR does not appear in the returned list of strings.

[procedure] (uri-path->keys PATH-LIST PTYPES) DEPRECATED

Use uri-decode-split-path and coerce egg coerce-all.

PATH-LIST is a path-list as returned by uri-split-fields. uri-path->keys returns a list of items coerced to types PTYPES.

[procedure] (path->uri PATH) DEPRECATED

Use pathname->uri.

Returns a URI-string for PATH on the local host.

[procedure] (absolute-path? FILE-NAME) DEPRECATED

Use utils unit absolute-pathname?.

Returns #t if FILE-NAME is a fully specified pathname (does not depend on the current working directory); otherwise returns #f.

[procedure] (null-directory? STRING) DEPRECATED

Use utils unit directory-null?.

Returns #t if changing directory to STRING would leave the current directory unchanged; otherwise returns #f.

[procedure] (glob-pattern? STRING) DEPRECATED

Use regex unit glob?.

Returns #t if the string STRING contains characters used for specifying glob patterns, namely #\*, #\?, and #\[.

FTP Procedures

(require-extension ftp-parse)

Before RFC 2396, the File Transfer Protocol (FTP) served a purpose similar to a URL.

[procedure] (parse-ftp-address URI)

Returns a list of the decoded FTP URI; or #f if indecipherable. FTP Uniform Resource Locator, ange-ftp, and getit formats are handled. The returned list has four elements which are strings or #f:

  1. username
  2. password
  3. remote-site
  4. remote-directory

Bugs:

Version:

License:

Portions Copyright 2007 Kon Lovett
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
conditions are met:

  Redistributions of source code must retain the above copyright notice, this list of conditions and the following
    disclaimer.
  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
    disclaimer in the documentation and/or other materials provided with the distribution.
  Neither the name of the author nor the names of its contributors may be used to endorse or promote
    products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Portions Copyright 1997, 1998, 2000, 2001 Aubrey Jaffer

Permission to copy this software, to modify it, to redistribute it,
to distribute modified versions, and to use it for any purpose is
granted, subject to the following restrictions and understandings.

1. Any copy made of this software must include this copyright notice
in full.

2. I have made no warranty or representation that the operation of
this software will be error-free, and I am under no obligation to
provide any services, by way of maintenance, update, or otherwise.

3. In conjunction with products arising from the use of this
material, there shall be no use of my name in any advertising,
promotional, or sales literature without prior written consent in
each case.

back