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

version» Context lines:

pike.git/lib/modules/Standards.pmod/URI.pike:1:   //! This class implements URI parsing and resolving of relative references to   //! absolute form, as defined in RFC 2396      // Implemented by Johan Sundström and Johan Schön.   // Copyright (c) Roxen Internet Software 2001 - // $Id: URI.pike,v 1.7 2001/01/26 14:54:31 jhs Exp $ + // $Id: URI.pike,v 1.8 2001/01/30 22:04:40 jhs 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;      //! Path component of URI. May be empty, but not undefined.
pike.git/lib/modules/Standards.pmod/URI.pike:25:   //! Certain classes of URI (e.g. URL) may have these defined   string host, user, password;      //! If no port number is present in URI, but the scheme used has a default port number,   //! this number is put here.   int port;      //! The base URI object, if present   object(this_program) base_uri;    + // URI hacker docs: + // This string is the raw uri the object was instantiated from in the + // first place. We save it here for the sole purpose of being able to + // replace the base URI, hence also needing to reresolve all of our + // properties with respect to that change.   string raw_uri;      #define error(S) throw( ({ (S), backtrace() }) )   #ifdef STANDARDS_URI_DEBUG   #define DEBUG(X, Y ...) werror("Standards.URI: "+X+"\n", Y)   #else   #define DEBUG(X, Y ...)   #endif      // Parse authority component (according to RFC 1738, § 3.1)
pike.git/lib/modules/Standards.pmod/URI.pike:48:    {    sscanf(auth, "%[^:]:%s", user, password); // auth info present    DEBUG("parse_authority(): user=%O, password=%O", user, password);    }    if(scheme)    port = [int]Protocols.Ports.tcp[scheme]; // Set a good default á la RFC 1700    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. :-)   static void inherit_properties(object(this_program) uri)   {    authority = uri->authority;    scheme = uri->scheme;    user = uri->user; password = uri->password;    host = uri->host; query = uri->query;    port = uri->port;    path = uri->path; fragment = uri->fragment;   }
pike.git/lib/modules/Standards.pmod/URI.pike:94:    // b) The reference's path component is appended to the buffer string.    buf+=rel;    segments = buf / "/";       // c) All occurrences of "./", where "." is a complete path segment,    // are removed from the buffer string.    for(int i=0; i<sizeof(segments)-1; i++)    if(segments[i]==".")    segments[i]=0;    -  segments -= ({0}); +  segments -= ({ 0 });       // d) If the buffer string ends with "." as a complete path segment,    // that "." is removed.    if(segments[-1]==".")    segments=segments[..sizeof(segments)-2]+({""});       // e) All occurrences of "<segment>/../", where <segment> is a    // complete path segment not equal to "..", are removed from the    // buffer string. Removal of these path segments is performed    // iteratively, removing the leftmost matching pattern on each
pike.git/lib/modules/Standards.pmod/URI.pike:167:    DEBUG("cloning base URI %O", base_uri);    local::base_uri = object_program(this_object())(base_uri); // create a new URI object    }    else    local::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.    -  +     // 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(!raw_uri || raw_uri == "") +  if(!uri || uri == "")    {    DEBUG("Path is empty -- Inherit entire base URI "    "as per RFC 2396, §5.2 step 2. Done!");    inherit_properties(local::base_uri);    return;    }    -  if(raw_uri[0] == '#') +  if(uri[0] == '#')    {    DEBUG("Fragment only. Using entire base URI, except fragment.");    inherit_properties(local::base_uri); -  fragment=raw_uri[1..]; +  fragment = uri[1..];    return;    }       // Parse fragment identifier    sscanf(uri, "%s#%s", uri, fragment);    DEBUG("Found fragment %O", fragment);       // Parse scheme    if(sscanf(uri, "%[A-Za-z0-9+.-]:%s", scheme, uri) < 2)    {