pike.git / lib / modules / Standards.pmod / URI.pike

version» Context lines:

pike.git/lib/modules/Standards.pmod/URI.pike:1:   #pike __REAL_VERSION__      //! This class implements URI parsing and resolving of relative references to   //! absolute form, as defined in RFC 2396 and RFC 3986.      // Implemented by Johan Sundström and Johan Schön. - // $Id: URI.pike,v 1.31 2009/08/15 07:21:46 nilsson Exp $ + // $Id: URI.pike,v 1.32 2009/09/17 17:25:11 grubba Exp $      #pragma strict_types      //! Scheme component of URI   string scheme;      //! Authority component of URI (formerly called net_loc, from RFC 2396   //! known as authority)   string authority;   
pike.git/lib/modules/Standards.pmod/URI.pike:40:   // replace the base URI, hence also needing to reresolve all of our   // properties with respect to that change.   string raw_uri;      #ifdef STANDARDS_URI_DEBUG   #define DEBUG(X, Y ...) werror("Standards.URI: "+X+"\n", Y)   #else   #define DEBUG(X, Y ...)   #endif    + // FIXME: What about decoding of Percent-Encoding (RFC3986 2.1)? + // cf pct-encoded in the functions below. +    // Parse authority component (according to RFC 1738, § 3.1)   // Updated to RFC 3986 $ 3.2.   protected void parse_authority()   {    // authority = [ userinfo "@" ] host [ ":" port ]    if(sscanf(authority, "%[^@]@%s", string userinfo, authority) == 2)    {    // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )    sscanf(userinfo, "%[^:]:%s", user, password); // user info present    DEBUG("parse_authority(): user=%O, password=%O", user, password);    }    if(scheme)    port = Protocols.Ports.tcp[scheme]; // Set a good default á la RFC 1700    // host = IP-literal / IPv4address / reg-name    if (has_prefix(authority, "[")) {    // IP-literal = "[" ( IPv6address / IPvFuture ) "]"    // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )    sscanf(authority, "[%s]%*[:]%d", host, port);    } else { -  +  // IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet +  // reg-name = *( unreserved / pct-encoded / sub-delims )    sscanf(authority, "%[^:]%*[:]%d", host, port);    }    DEBUG("parse_authority(): host=%O, port=%O", host, port);   }      // Inherit all properties except raw_uri and base_uri from the URI uri. :-)   protected void inherit_properties(this_program uri)   {    authority = uri->authority;    scheme = uri->scheme;
pike.git/lib/modules/Standards.pmod/URI.pike:181:    {    DEBUG("cloning base URI %O", base_uri);    this_program::base_uri = this_program(base_uri); // create a new URI object    }    else    this_program::base_uri = [object(this_program)]base_uri;       // RFC 2396, §5.2:    // 1) The URI reference is parsed into the potential four components and    // fragment identifier, as described in Section 4.3. +  // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]       // 2) If the path component is empty and the scheme, authority, and    // query components are undefined, then it is a reference to the    // current document and we are done. Otherwise, the reference URI's    // query and fragment components are defined as found (or not found)    // within the URI reference and not inherited from the base URI.    // (Doing this at once saves us some useless parsing efforts.)    if((!uri || uri == "") && this_program::base_uri)    {    DEBUG("Path is empty -- Inherit entire base URI "
pike.git/lib/modules/Standards.pmod/URI.pike:205:       if(has_prefix (uri, "#") && this_program::base_uri)    {    DEBUG("Fragment only. Using entire base URI, except fragment.");    inherit_properties(this_program::base_uri);    fragment = uri[1..];    return;    }       // Parse fragment identifier +  // fragment = *( pchar / "/" / "?" ) +  // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"    sscanf(uri, "%s#%s", uri, fragment);    DEBUG("Found fragment %O", fragment);       // Parse scheme -  +  // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )    if(sscanf(uri, "%[A-Za-z0-9+.-]:%s", scheme, uri) < 2)    {    scheme = 0;    if(!this_program::base_uri)    error("Standards.URI: got a relative URI (no scheme) lacking a base_uri!\n");    } else {    /* RFC 3986 §3.1    *    * An implementation should accept uppercase letters as equivalent    * to lowercase in scheme names (e.g., allow "HTTP" as well as    * "http") for the sake of robustness but should only produce    * lowercase scheme names for consistency.    */    scheme = lower_case(scheme);    }    DEBUG("Found scheme %O", scheme);       // Parse authority/login -  +  // +  // hier-part = "//" authority path-abempty / path-absolute +  // / path-rootless / path-empty    if(sscanf(uri, "//%[^/]%s", authority, uri))    {    DEBUG("Found authority %O", authority);    }       // Parse query information -  +  // query = *( pchar / "/" / "?" ) +  // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"    sscanf(uri, "%s?%s", uri, query);    DEBUG("Found query %O", query);       // Parse path: -  +  // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"    if ((uri == "") && !scheme && !authority && (this_program::base_uri)) {    // Empty path.    path = this_program::base_uri->path;    } else {    path = uri;    }    DEBUG("Found path %O", path);       // 3) If the scheme component is defined, indicating that the reference    // starts with a scheme name, then the reference is interpreted as an