Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions
nsStdURLParser Class Reference

#include <nsURLParsers.h>

Inheritance diagram for nsStdURLParser:
Inheritance graph
[legend]
Collaboration diagram for nsStdURLParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void ParseAfterScheme (const char *spec, PRInt32 specLen, PRUint32 *authPos, PRInt32 *authLen, PRUint32 *pathPos, PRInt32 *pathLen)
NS_IMETHOD ParseAuthority (const char *auth, PRInt32 authLen, PRUint32 *usernamePos, PRInt32 *usernameLen, PRUint32 *passwordPos, PRInt32 *passwordLen, PRUint32 *hostnamePos, PRInt32 *hostnameLen, PRInt32 *port)
NS_IMETHOD ParseUserInfo (const char *userinfo, PRInt32 userinfoLen, PRUint32 *usernamePos, PRInt32 *usernameLen, PRUint32 *passwordPos, PRInt32 *passwordLen)
NS_IMETHOD ParseServerInfo (const char *serverinfo, PRInt32 serverinfoLen, PRUint32 *hostnamePos, PRInt32 *hostnameLen, PRInt32 *port)
void parseURL (in string spec, in long specLen, out unsigned long schemePos, out long schemeLen, out unsigned long authorityPos, out long authorityLen, out unsigned long pathPos, out long pathLen)
 The string to parse in the following methods may be given as a null terminated string, in which case the length argument should be -1.
void parseAuthority (in string authority, in long authorityLen, out unsigned long usernamePos, out long usernameLen, out unsigned long passwordPos, out long passwordLen, out unsigned long hostnamePos, out long hostnameLen, out long port)
 ParseAuthority breaks the authority string up into its 4 components: username, password, hostname, and hostport.
void parseUserInfo (in string userinfo, in long userinfoLen, out unsigned long usernamePos, out long usernameLen, out unsigned long passwordPos, out long passwordLen)
 userinfo = <username>:<password>
void parseServerInfo (in string serverinfo, in long serverinfoLen, out unsigned long hostnamePos, out long hostnameLen, out long port)
 serverinfo = <hostname>:<port>
void parsePath (in string path, in long pathLen, out unsigned long filepathPos, out long filepathLen, out unsigned long paramPos, out long paramLen, out unsigned long queryPos, out long queryLen, out unsigned long refPos, out long refLen)
 ParsePath breaks the path string up into its 4 major components: a file path, a param string, a query string, and a reference string.
void parseFilePath (in string filepath, in long filepathLen, out unsigned long directoryPos, out long directoryLen, out unsigned long basenamePos, out long basenameLen, out unsigned long extensionPos, out long extensionLen)
 ParseFilePath breaks the file path string up into: the directory portion, file base name, and file extension.
void parseFileName (in string filename, in long filenameLen, out unsigned long basenamePos, out long basenameLen, out unsigned long extensionPos, out long extensionLen)
 filename = <basename>.

Detailed Description

Definition at line 132 of file nsURLParsers.h.


Member Function Documentation

void nsStdURLParser::ParseAfterScheme ( const char *  spec,
PRInt32  specLen,
PRUint32 authPos,
PRInt32 authLen,
PRUint32 pathPos,
PRInt32 pathLen 
) [virtual]

Reimplemented from nsAuthURLParser.

Definition at line 649 of file nsURLParsers.cpp.

{
    NS_PRECONDITION(specLen >= 0, "unexpected");

    PRUint32 nslash = CountConsecutiveSlashes(spec, specLen);

    // search for the end of the authority section
    const char *end = spec + specLen;
    const char *p;
    for (p = spec + nslash; p < end; ++p) {
        if (strchr("/?#;", *p))
            break;
    }
    switch (nslash) {
    case 0:
    case 2:
        if (p < end) {
            // spec = (//)<auth><path>
            SET_RESULT(auth, nslash, p - (spec + nslash));
            SET_RESULT(path, p - spec, specLen - (p - spec));
        }
        else {
            // spec = (//)<auth>
            SET_RESULT(auth, nslash, specLen - nslash);
            SET_RESULT(path, 0, -1);
        }
        break;
    case 1:
        // spec = /<path>
        SET_RESULT(auth, 0, -1);
        SET_RESULT(path, 0, specLen);
        break;
    default:
        // spec = ///[/]<path>
        SET_RESULT(auth, 2, 0);
        SET_RESULT(path, 2, specLen - 2);
    }
}

Here is the call graph for this function:

void nsIURLParser::parseAuthority ( in string  authority,
in long  authorityLen,
out unsigned long  usernamePos,
out long  usernameLen,
out unsigned long  passwordPos,
out long  passwordLen,
out unsigned long  hostnamePos,
out long  hostnameLen,
out long  port 
) [inherited]

ParseAuthority breaks the authority string up into its 4 components: username, password, hostname, and hostport.

auth = <username>:<password><hostname>:<port>

NS_IMETHODIMP nsAuthURLParser::ParseAuthority ( const char *  auth,
PRInt32  authLen,
PRUint32 usernamePos,
PRInt32 usernameLen,
PRUint32 passwordPos,
PRInt32 passwordLen,
PRUint32 hostnamePos,
PRInt32 hostnameLen,
PRInt32 port 
) [inherited]

Definition at line 475 of file nsURLParsers.cpp.

{
    nsresult rv;

    NS_PRECONDITION(auth, "null pointer");

    if (authLen < 0)
        authLen = strlen(auth);

    if (authLen == 0) {
        SET_RESULT(username, 0, -1);
        SET_RESULT(password, 0, -1);
        SET_RESULT(hostname, 0, 0);
        if (port)
            *port = -1;
        return NS_OK;
    }

    // search backwards for @
    const char *p = auth + authLen - 1;
    for (; (*p != '@') && (p > auth); --p);
    if ( *p == '@' ) {
        // auth = <user-info@server-info>
        rv = ParseUserInfo(auth, p - auth,
                           usernamePos, usernameLen,
                           passwordPos, passwordLen);
        if (NS_FAILED(rv)) return rv;
        rv = ParseServerInfo(p + 1, authLen - (p - auth + 1),
                             hostnamePos, hostnameLen,
                             port);
        if (NS_FAILED(rv)) return rv;
        OFFSET_RESULT(hostname, p + 1 - auth);
    }
    else {
        // auth = <server-info>
        SET_RESULT(username, 0, -1);
        SET_RESULT(password, 0, -1);
        rv = ParseServerInfo(auth, authLen,
                             hostnamePos, hostnameLen,
                             port);
        if (NS_FAILED(rv)) return rv;
    }
    return NS_OK;
}

Here is the call graph for this function:

void nsIURLParser::parseFileName ( in string  filename,
in long  filenameLen,
out unsigned long  basenamePos,
out long  basenameLen,
out unsigned long  extensionPos,
out long  extensionLen 
) [inherited]

filename = <basename>.

<extension>

void nsIURLParser::parseFilePath ( in string  filepath,
in long  filepathLen,
out unsigned long  directoryPos,
out long  directoryLen,
out unsigned long  basenamePos,
out long  basenameLen,
out unsigned long  extensionPos,
out long  extensionLen 
) [inherited]

ParseFilePath breaks the file path string up into: the directory portion, file base name, and file extension.

filepath = <directory><basename>.<extension>

void nsIURLParser::parsePath ( in string  path,
in long  pathLen,
out unsigned long  filepathPos,
out long  filepathLen,
out unsigned long  paramPos,
out long  paramLen,
out unsigned long  queryPos,
out long  queryLen,
out unsigned long  refPos,
out long  refLen 
) [inherited]

ParsePath breaks the path string up into its 4 major components: a file path, a param string, a query string, and a reference string.

path = <filepath>;?<query>#<ref>

void nsIURLParser::parseServerInfo ( in string  serverinfo,
in long  serverinfoLen,
out unsigned long  hostnamePos,
out long  hostnameLen,
out long  port 
) [inherited]

serverinfo = <hostname>:<port>

NS_IMETHODIMP nsAuthURLParser::ParseServerInfo ( const char *  serverinfo,
PRInt32  serverinfoLen,
PRUint32 hostnamePos,
PRInt32 hostnameLen,
PRInt32 port 
) [inherited]

Definition at line 559 of file nsURLParsers.cpp.

{
    NS_PRECONDITION(serverinfo, "null pointer");

    if (serverinfoLen < 0)
        serverinfoLen = strlen(serverinfo);

    if (serverinfoLen == 0) {
        SET_RESULT(hostname, 0, 0);
        if (port)
            *port = -1;
        return NS_OK;
    }

    // search backwards for a ':' but stop on ']' (IPv6 address literal
    // delimiter).  check for illegal characters in the hostname.
    const char *p = serverinfo + serverinfoLen - 1;
    const char *colon = nsnull, *bracket = nsnull;
    for (; p > serverinfo; --p) {
        switch (*p) {
            case ']':
                bracket = p;
                break;
            case ':':
                if (bracket == nsnull)
                    colon = p;
                break;
            case ' ':
                // hostname must not contain a space
                NS_WARNING("malformed hostname");
                return NS_ERROR_MALFORMED_URI;
        }
    }

    if (colon) {
        // serverinfo = <hostname:port>
        SET_RESULT(hostname, 0, colon - serverinfo);
        if (port) {
            // XXX unfortunately ToInteger is not defined for substrings
            nsCAutoString buf(colon+1, serverinfoLen - (colon + 1 - serverinfo));
            PRInt32 err;
           *port = buf.ToInteger(&err);
            if (NS_FAILED(err))
               *port = -1;
        }
    }
    else {
        // serverinfo = <hostname>
        SET_RESULT(hostname, 0, serverinfoLen);
        if (port)
           *port = -1;
    }
    return NS_OK;
}

Here is the caller graph for this function:

void nsIURLParser::parseURL ( in string  spec,
in long  specLen,
out unsigned long  schemePos,
out long  schemeLen,
out unsigned long  authorityPos,
out long  authorityLen,
out unsigned long  pathPos,
out long  pathLen 
) [inherited]

The string to parse in the following methods may be given as a null terminated string, in which case the length argument should be -1.

Out parameters of the following methods are all optional (ie. the caller may pass-in a NULL value if the corresponding results are not needed). Signed out parameters may hold a value of -1 if the corresponding result is not part of the string being parsed.

The parsing routines attempt to be as forgiving as possible. ParseSpec breaks the URL string up into its 3 major components: a scheme, an authority section (hostname, etc.), and a path.

spec = <scheme>://<authority><path>

void nsIURLParser::parseUserInfo ( in string  userinfo,
in long  userinfoLen,
out unsigned long  usernamePos,
out long  usernameLen,
out unsigned long  passwordPos,
out long  passwordLen 
) [inherited]

userinfo = <username>:<password>

NS_IMETHODIMP nsAuthURLParser::ParseUserInfo ( const char *  userinfo,
PRInt32  userinfoLen,
PRUint32 usernamePos,
PRInt32 usernameLen,
PRUint32 passwordPos,
PRInt32 passwordLen 
) [inherited]

Definition at line 525 of file nsURLParsers.cpp.

{
    NS_PRECONDITION(userinfo, "null pointer");

    if (userinfoLen < 0)
        userinfoLen = strlen(userinfo);

    if (userinfoLen == 0) {
        SET_RESULT(username, 0, -1);
        SET_RESULT(password, 0, -1);
        return NS_OK;
    }

    const char *p = (const char *) memchr(userinfo, ':', userinfoLen);
    if (p) {
        // userinfo = <username:password>
        if (p == userinfo) {
            // must have a username!
            return NS_ERROR_MALFORMED_URI;
        }
        SET_RESULT(username, 0, p - userinfo);
        SET_RESULT(password, p - userinfo + 1, userinfoLen - (p - userinfo + 1));
    }
    else {
        // userinfo = <username>
        SET_RESULT(username, 0, userinfoLen);
        SET_RESULT(password, 0, -1);
    }
    return NS_OK;
}

Here is the caller graph for this function:


The documentation for this class was generated from the following files: