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

version» Context lines:

pike.git/lib/modules/Standards.pmod/URI.pike:195:   //! Set the new base URI to this.   //! @throws   //! An exception is thrown if the @[uri] is a relative URI or only a   //! fragment, and missing a @[base_uri].   void reparse_uri(this_program|string|void base_uri)   {    string uri = raw_uri;    if(stringp(base_uri))    {    DEBUG("cloning base URI %O", base_uri); -  this_program::base_uri = this_program(base_uri); // create a new URI object +  this::base_uri = this_program(base_uri); // create a new URI object    }    else -  this_program::base_uri = [object(this_program)]base_uri; +  this::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) +  if((!uri || uri == "") && this::base_uri)    {    DEBUG("Path is empty -- Inherit entire base URI "    "as per RFC 2396, §5.2 step 2. Done!"); -  inherit_properties(this_program::base_uri); +  inherit_properties(this::base_uri);    return;    }       // Parse fragment identifier    // fragment = *( pchar / "/" / "?" )    // pchar = unreserved / pct-encoded / sub-delims / ":" / "@"    if( sscanf(uri, "%s#%s", uri, fragment)==2 )    {    DEBUG("Found fragment %O", fragment);    if( !sizeof(uri) )    {    DEBUG("Fragment only. Using entire base URI, except fragment."); -  if( !this_program::base_uri ) +  if( !this::base_uri )    error("fragment only URI lacking base URI.\n");    string f = fragment; -  inherit_properties(this_program::base_uri); +  inherit_properties(this::base_uri);    fragment = f;    return;    }    }       // Parse scheme    // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )    if(sscanf(uri, "%[A-Za-z0-9+.-]:%s", scheme, uri) < 2)    {    scheme = 0; -  if(!this_program::base_uri) +  if(!this::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);       // DWIM for "www.cnn.com" style input, when parsed in the context of    // base "http://". -  if( !scheme && this_program::base_uri?->scheme && -  !sizeof(this_program::base_uri->authority) ) +  if( !scheme && this::base_uri?->scheme && +  !sizeof(this::base_uri->authority) )    {    uri = "//"+uri;    }       // Parse authority/login    //    // hier-part = "//" authority path-abempty / path-absolute    // / path-rootless / path-empty    if(sscanf(uri, "//%[^/]%s", authority, uri))    {
pike.git/lib/modules/Standards.pmod/URI.pike:291:    }       // 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)) { +  if ((uri == "") && !scheme && !authority && (this::base_uri)) {    // Empty path. -  path = this_program::base_uri->path; +  path = this::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    // absolute URI and we are done. Otherwise, the reference URI's    // scheme is inherited from the base URI's scheme component.    if(scheme)    {    if(authority)    parse_authority();       DEBUG("Scheme found! RFC 2396, §5.2, step 3 "    "says we're absolute. Done!");    sprintf_cache['s'] = raw_uri;    return;    } -  scheme = this_program::base_uri->scheme; +  scheme = this::base_uri->scheme;    DEBUG("Inherited scheme %O from base URI", scheme);       if(authority)    parse_authority();          // 4) If the authority component is defined, then the reference is a    // network-path and we skip to step 7. Otherwise, the reference    // URI's authority is inherited from the base URI's authority    // component, which will also be undefined if the URI scheme does not    // use an authority component.    if(!authority || !sizeof(authority))    { -  authority = this_program::base_uri->authority; +  authority = this::base_uri->authority;    DEBUG("Inherited authority %O from base URI", authority);    if (authority)    parse_authority();       // 5) If the path component begins with a slash character ("/"), then    // the reference is an absolute-path and we skip to step 7.    if(!has_prefix(path, "/"))    {       // 6) If this step is reached, then we are resolving a relative-path    // reference. The relative path needs to be merged with the base    // URI's path. Although there are many ways to do this, we will    // describe a simple method using a separate string buffer.       DEBUG("Combining base path %O with path %O => %O", -  this_program::base_uri->path, path, -  combine_uri_path(this_program::base_uri->path, path)); -  path = combine_uri_path(this_program::base_uri->path, path); +  this::base_uri->path, path, +  combine_uri_path(this::base_uri->path, path)); +  path = combine_uri_path(this::base_uri->path, path);       }    }       // 7) The resulting URI components, including any inherited from the    // base URI, are recombined to give the absolute form of the URI reference.    // (Reassembly is done at cast-to-string/sprintf() time)   }