Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for [[/eggref/4/uri|the CHICKEN 4 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-4.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: eggs]] [[toc:]] == URI === Description Facilities for parsing RFC 1739 Uniform Resource Locators & RFC 3986 Uniform Resource Identifiers. === Author * Kon Lovett * Aubrey Jaffer (Original SLIB implementation) === Download [[http://code.call-cc.org/legacy-eggs/3/uri.egg|uri.egg]] === Usage (require-extension uri) === Documentation ==== uri <procedure>(uri STRING [DEFAULT-URI])</procedure> 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. ==== make-uri <procedure>(make-uri #!key SCHEME SPECIFIC FRAGMENT ...)</procedure> Returns a Uniform Resource Identifier object from '''unencoded''' component arguments. {{SCHEME}} maybe a symbol or string, in which case it is converted to a symbol. {{SPECIFIC}} is scheme specific. The default is {{(AUTHORITY PATH QUERY)}}. {{FRAGMENT}} is a string. {{...}} is scheme specific. The default scheme handler also accepts the keyword arguments {{#:AUTHORITY}}, {{#:PATH}}, and {{#:QUERY}}. {{AUTHORITY}} is a list of {{(USERINFO HOST PORT)}} where {{USERINFO}} is a string {{"<username>:<password>"}}, {{HOST}} is a string, and {{PORT}} is an integer. Any can be {{#f}}, indicating a missing item. Authority can also be a string, in which case it is parsed into a list form. {{PATH}} maybe a list of {{([DIRECTORY ...] BASENAME)}} where {{DIRECTORY}} and {{BASENAME}} are strings, or a string, in which case it is parsed into a path-list (also known as a "split path"). {{QUERY}} is an association list where the key is a string and the value is any object. Query can also be a string, in which case it is parsed into an association list. ==== *make-uri <procedure>(*make-uri SCHEME SPECIFIC FRAGMENT ...)</procedure> Returns a Uniform Resource Identifier object from '''unencoded''' component arguments. {{SCHEME}} is a symbol. {{SPECIFIC}} is scheme specific. {{FRAGMENT}} is a string. {{...}} is scheme specific. ==== Accessor procedures for {{URI}} objects. ==== uri-scheme <procedure>(uri-scheme URI)</procedure> {{SCHEME}} is a symbol. ==== uri-specific <procedure>(uri-specific URI)</procedure> {{SPECIFIC}} is scheme specific. Default is a list - {{((uri-authority uri) (uri-path uri) (uri-query uri))}}. ==== uri-fragment <procedure>(uri-fragment URI)</procedure> {{FRAGMENT}} is a string. ==== uri-authority <procedure>(uri-authority URI)</procedure> {{AUTHORITY}} is a list of {{(USERINFO HOST PORT)}} where {{USERINFO}} is a string {{"<username>:<password>"}}, {{HOST}} is a string, and {{PORT}} is an integer. ==== uri-userinfo <procedure>(uri-userinfo URI)</procedure> {{USERINFO}} is a two value return of {{USERNAME}} and {{PASSWORD}}. ==== uri-username <procedure>(uri-username URI)</procedure> {{USERNAME}} is a string. ==== uri-password <procedure>(uri-password URI)</procedure> {{PASSWORD}} is a string. ==== uri-host <procedure>(uri-host URI)</procedure> {{HOST}} is a string. ==== uri-port <procedure>(uri-port URI)</procedure> {{PORT}} is an integer. ==== uri-path <procedure>(uri-path URI)</procedure> {{PATH}} is a list of ([directory ...] basename) where directory and basename are strings. ==== uri-query <procedure>(uri-query URI)</procedure> {{QUERY}} is an association list where the key is a string and the value is any object. 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". ==== uri? <procedure>(uri? X)</procedure> Returns {{#t}} if {{X}} is an URI object, or {{#f}} otherwise. ==== uri-missing-query-value <parameter>(uri-missing-query-value [X])</parameter> Gets or sets the object used for a query value when none is supplied. Default is {{#t}}. ==== uri-rfc3986-strict <parameter>(uri-rfc3986-strict [X])</parameter> 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. ==== uri-scheme-symbol <procedure>(uri-scheme-symbol STRING [PARSE?])</procedure> Returns the Uniform Resource Identifier (RFC 3986) scheme component from {{STRING}} as a symbol with a lower-case printname, or {{#f}} if none present. {{PARSE?}} is a flag indicating whether the {{STRING}} is an encoded URI, {{#t}}, or should be treated monolithically, {{#f}}. The default is {{#f}}. ==== uri-path-null? <procedure>(uri-path-null? URI)</procedure> Is the path component of the {{URI}} "null"? Null here is defined as a {{PATH-LIST}} equal to either {{#f}}, {{'()}}, or {{'("")}}. ==== uri->string <procedure>(uri->string URI)</procedure> 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. ==== uri->list <procedure>(uri->list STRING [BASIS])</procedure> Returns a decoded list form - {{(scheme specific fragment ...)}}. {{STRING}} is a Uniform Resource Identifier (RFC 3986). {{BASIS}} is either a decoded list form, as above, or a Uniform Resource Identifier string. A URI is converted to a decoded list form. ==== list->uri <procedure>(list->uri LIST)</procedure> Returns a uri object for the decoded list form. {{LIST}} - unencoded {{(scheme specific fragment ...)}}. ==== uri-split-path <procedure>(uri-split-path PATH)</procedure> Returns the "rooted" list form of the string form {{PATH}}. ==== uri-split-path-null? <procedure>(uri-split-path-null? PATH-LIST)</procedure> Is the {{PATH-LIST}} "null"? Null here is defined as a {{PATH-LIST}} equal to either {{#f}}, {{'()}}, or {{'("")}}. ==== uri-encode-split-path <procedure>(uri-encode-split-path PATH-LIST)</procedure> Returns a URI string combining the components of {{PATH-LIST}}. ==== uri-decode-split-path <procedure>(uri-decode-split-path PATH-LIST [BASE-PATH-LIST])</procedure> 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. ==== uri-decode-path <procedure>(uri-decode-path PATH [BASE-PATH-LIST])</procedure> 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. ==== uri-encode-query <procedure>(uri-encode-query QUERY-ALIST [MISSING])</procedure> Converts a {{QUERY-ALIST}} to a ''URI'' encoded query-string. {{MISSING}} is the value for a "valueless" key. Default is {{(uri-missing-query-value)}}. When the value for a key in the {{QUERY-ALIST}} is {{eqv?}} {{MISSING}} then only the key is appended to the result string. ==== uri-decode-query <procedure>(uri-decode-query QUERY-STRING [MISSING])</procedure> Converts a ''URI'' encoded {{QUERY-STRING}} to a query-alist. {{MISSING}} is the value for a "valueless" key. Default is {{(uri-missing-query-value)}}. ==== uri-encode <procedure>(uri-encode URI-COMPONENT [ALLOWED ...])</procedure> 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}}. {{ALLOWED}} is either a procedure of one character parameter, a string, or a character. A match means the character is not encoded. {{ALPHA}} | {{DIGIT}} | {{"-"}} | {{"."}} | {{"_"}} | {{"~"}} are always allowed. Line break (CRLF | LFCR) is mapped to {{"%0D%0A"}}. ==== uri-decode <procedure>(uri-decode URI-COMPONENT)</procedure> 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. ==== absolute-uri? <procedure>(absolute-uri? STRING)</procedure> Returns {{#t}} if {{STRING}} is an absolute URI as indicated by a syntactically valid (per RFC 3986) ''scheme''; otherwise returns {{#f}}. ==== pathname->uri <procedure>(pathname->uri PATHNAME)</procedure> Returns a URI-string for {{PATHNAME}} on the local host. ==== uri-new-scheme-specific <procedure>(uri-new-scheme-specific SCHEME #!key FIELDER PARSER MAKER ENCODER DECODER DATA ASSOCIATIONS)</procedure> Sets the scheme specific handler (class) for {{SCHEME}}. {{SCHEME}} is a Uniform Resource Identifier (RFC 3986) scheme component represented as a symbol. {{FIELDER}} value is a procedure: {{(SYMBOL #!rest -> OBJECT)}}. Taking a uri field component key and optional arguments. Returns the field component value or {{(void)}} when no such field. The field keys {{scheme}}, {{specific}}, and {{fragment}} are builtin. Corresponding to the same named fields of the uri record object. {{MAKER}} value is a procedure: {{(URI SYMBOL OBJECT OBJECT [#!rest ...] -> URI)}}. Taking a URI record object, constructed from the next 3 arguments, the <SCHEME>, <SPECIFIC>, and <FRAGMENT> components of a URI, plus optional arguments. Returns a URI record object. The default is a procedure that just returns its' first argument. {{PARSER}} value is a procedure: {{(#:SCHEME #:SPECIFIC #:FRAGMENT [#!key ...] -> LIST)}}. Taking keyword arguments. Returns a list of the parsed components - {{(<scheme> <specific> <fragment> ...)}}. {{DECODER}} value is a procedure: {{(STRING LIST -> LIST)}}. Taking a encoded string from of a uri, and a parsed components list, known as the {{BASIS}} (which maybe {{#f}}). Returns the parsed components - {{(<scheme> <specific> <fragment> ...)}}. {{ENCODER}} value is a procedure: {{(URI -> STRING)}}. Taking a uri record object. Returns the encoded form of the uri as a string. {{DATA}} value is scheme specific initial data. Default is unspecified. {{ASSOCIATIONS}} value is an association-list of scheme specific operation procedures. Default is {{()}}. The alist must be composed of pairs of the form {{(<symbol> . <procedure>)}}. Any arguments are passed to the procedure. Note that the argument list for the {{make}} procedure has the same components and order as the list of parsed components returned by the {{parse}} and {{decode}} procedures. This is not a coincidence. The uri record object accessors {{uri$scheme-set!}}, {{uri$specific-set!}}, {{uri$fragment-set!}}, {{uri$scheme-class}}, {{uri$scheme-class-set!}}, {{uri$scheme-data}}, and {{uri$scheme-data-set!}} are available for unrestricted access. Use at your own risk. There is a default scheme handler used when a scheme specific handler cannot be found. Please see the source code file "uri.scm" for more information. A scheme specific class is implemented as a dispatcher on its' first argument, which is a symbol. The symbols {{field}}, {{make}}, {{parse}}, {{decode}}, {{encode}}, {{data}}, and {{name}} are reserved. ==== Deprecated ==== uri->tree <procedure>(uri->tree URI-STR [BASE-TREE]) DEPRECATED</procedure> Use <enscript highlight=scheme> (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)) ) </enscript> 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. <enscript highlight=scheme> (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") </enscript> ==== uri-scheme-specific <procedure>(uri-scheme-specific URI) DEPRECATED</procedure> Use {{(uri-specific URI)}}. ==== uri-make-path <procedure>(uri-make-path PATH-LIST) DEPRECATED</procedure> Use {{uri-encode-split-path}}. Returns a URI string combining the components of {{PATH-LIST}}. ==== uri-split-fields <procedure>(uri-split-fields STR CHR) DEPRECATED</procedure> 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. ==== uri-path->keys <procedure>(uri-path->keys PATH-LIST PTYPES) DEPRECATED</procedure> 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}}. ==== path->uri <procedure>(path->uri PATH) DEPRECATED</procedure> Use {{pathname->uri}}. Returns a URI-string for {{PATH}} on the local host. ==== absolute-path? <procedure>(absolute-path? FILE-NAME) DEPRECATED</procedure> 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}}. ==== null-directory? <procedure>(null-directory? STRING) DEPRECATED</procedure> Use utils unit {{directory-null?}}. Returns {{#t}} if changing directory to {{STRING}} would leave the current directory unchanged; otherwise returns {{#f}}. ==== glob-pattern? <procedure>(glob-pattern? STRING) DEPRECATED</procedure> Use regex unit {{glob?}}. Returns {{#t}} if the string {{STRING}} contains characters used for specifying glob patterns, namely {{#\*}}, {{#\?}}, and {{#\[}}. ==== FTP Procedures <pre> (require-extension ftp-parse) </pre> Before RFC 2396, the ''File Transfer Protocol'' (FTP) served a purpose similar to a URL. ==== parse-ftp-address <procedure>(parse-ftp-address URI)</procedure> 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}}: * username * password * remote-site * remote-directory === Requirements * coerce * miscmacros * synch * lookup-table === Bugs Fails a number of URI parsing tests. === Version History * 3.405 Backwards compatible use of Unit files. * 3.402 Optimization to uri-decode. * 3.401 Applied patch by Hans Bulfone - no ':' w/o a valid scheme. * 3.4 Added line-break encoding. Applied patch by Hans Bulfone - '!' is not "unreserved", '+' & '&' are escaped in a query. [Kon Lovett] * 3.307 Renamed 'make-scheme-specific' keywords. Made authority have precedence over path conditional. [Kon Lovett] * 3.306 Bug fix for absolute-uri?. [Kon Lovett] * 3.305 Newer dependencies (lookup-table -> misc-extn). [Kon Lovett] * 3.3.4 Dropped :optional. [Kon Lovett] * 3.3.3 Bugfix for ticket #259. [Kon Lovett] * 3.3.2 Add lookup-table requirement. [Kon Lovett] * 3.3.1 Added '#:associations' to 'uri-new-scheme-specific'. Documentation update. [Kon Lovett] * 3.3 Added 'uri-missing-query-value', MISSING optional argument for 'uri-encode/decode-query', 'uri-scheme-symbol'. Bugfix for query parsing, bare key wasn't accepted. Hid 'exn-uri-query-parse-condition?' since currently not raised. Support for scheme specific implementation - 'uri-new-scheme-specific'. [Kon Lovett] * 3.2 Added {{uri-specific}}, {{*make-uri}}, and {{uri->list}}. Deprecated {{uri-scheme-specific}} and {{uri->tree}}. Internal support for scheme specific implementation. [Kon Lovett] * 3.1 Small bug fix for {{url-encode}}. [Alejandro Forero Cuervo] * 3.0 Added support for string authority & query arguments to {{make-uri}}. Added {{uri-encode-split-path}}, {{uri-split-path-null?}}, {{uri-path-null?}}, {{uri-decode-split-path}}, and {{pathname->uri}}. Deprecated {{uri-make-path}}, {{uri-split-fields}}, {{uri-path->keys}}, {{path->uri}}, {{absolute-path?}}, {{null-directory?}}, {{glob-pattern?}}. Added cached userinfo values. Query string parsing now signals an error condition. Changed query alist key type to string so the symbol table is not needlessly expanded. This change is incompatible, thus the full version number release. [Kon Lovett] * 2.1 Bug fix for null path [Reported by John Janecek], also added reader & printer, bug fix for missing authority [Kon Lovett] * 2.0 Combined uri egg & url egg [Daishi Kato & Kon Lovett] * 1.1 Bug fix for {{uri->url}}, add userinfo accessors * 1.0 Initial Release === License <pre> 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. </pre> <pre> 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. </pre>
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 3 by 4?