Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsHttpHandler.cpp File Reference
#include "nsHttp.h"
#include "nsHttpHandler.h"
#include "nsHttpChannel.h"
#include "nsHttpConnection.h"
#include "nsHttpResponseHead.h"
#include "nsHttpTransaction.h"
#include "nsHttpAuthCache.h"
#include "nsStandardURL.h"
#include "nsIHttpChannel.h"
#include "nsIURL.h"
#include "nsIStandardURL.h"
#include "nsICacheService.h"
#include "nsICategoryManager.h"
#include "nsCategoryManagerUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsIPrefLocalizedString.h"
#include "nsISocketProviderService.h"
#include "nsISocketProvider.h"
#include "nsPrintfCString.h"
#include "nsCOMPtr.h"
#include "nsNetCID.h"
#include "nsAutoLock.h"
#include "prprf.h"
#include "nsReadableUtils.h"
#include "nsQuickSort.h"
#include "nsNetUtil.h"
#include "nsIOService.h"

Go to the source code of this file.

Defines

#define UA_PREF_PREFIX   "general.useragent."
#define UA_APPNAME   "Mozilla"
#define UA_APPVERSION   "5.0"
#define UA_APPSECURITY_FALLBACK   "N"
#define HTTP_PREF_PREFIX   "network.http."
#define INTL_ACCEPT_LANGUAGES   "intl.accept_languages"
#define INTL_ACCEPT_CHARSET   "intl.charset.default"
#define NETWORK_ENABLEIDN   "network.enableIDN"
#define BROWSER_PREF_PREFIX   "browser.cache."
#define UA_PREF(_pref)   UA_PREF_PREFIX _pref
#define HTTP_PREF(_pref)   HTTP_PREF_PREFIX _pref
#define BROWSER_PREF(_pref)   BROWSER_PREF_PREFIX _pref
#define PREF_CHANGED(p)   ((pref == nsnull) || !PL_strcmp(pref, p))
#define MULTI_PREF_CHANGED(p)   ((pref == nsnull) || !PL_strncmp(pref, p, sizeof(p) - 1))

Functions

static NS_DEFINE_CID (kIOServiceCID, NS_IOSERVICE_CID)
static NS_DEFINE_CID (kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID)
static NS_DEFINE_CID (kCookieServiceCID, NS_COOKIESERVICE_CID)
static NS_DEFINE_CID (kCacheServiceCID, NS_CACHESERVICE_CID)
static NS_DEFINE_CID (kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID)
static NS_DEFINE_CID (kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID)
static nsresult NewURI (const nsACString &aSpec, const char *aCharset, nsIURI *aBaseURI, PRInt32 aDefaultPort, nsIURI **aURI)
static int StringCompare (const void *s1, const void *s2, void *)
static nsresult PrepareAcceptLanguages (const char *i_AcceptLanguages, nsACString &o_AcceptLanguages)
 Allocates a C string into that contains a ISO 639 language list notated with HTTP "q" values for output with a HTTP Accept-Language header.
static nsresult PrepareAcceptCharsets (const char *i_AcceptCharset, nsACString &o_AcceptCharset)
 Allocates a C string into that contains a character set/encoding list notated with HTTP "q" values for output with a HTTP Accept-Charset header.
 NS_IMPL_THREADSAFE_ISUPPORTS5 (nsHttpHandler, nsIHttpProtocolHandler, nsIProxiedProtocolHandler, nsIProtocolHandler, nsIObserver, nsISupportsWeakReference) NS_IMETHODIMP nsHttpHandler
 NS_IMPL_THREADSAFE_ISUPPORTS4 (nsHttpsHandler, nsIHttpProtocolHandler, nsIProxiedProtocolHandler, nsIProtocolHandler, nsISupportsWeakReference) nsresult nsHttpsHandler

Variables

nsHttpHandlergHttpHandler = nsnull

Define Documentation

#define BROWSER_PREF (   _pref)    BROWSER_PREF_PREFIX _pref

Definition at line 111 of file nsHttpHandler.cpp.

#define BROWSER_PREF_PREFIX   "browser.cache."

Definition at line 107 of file nsHttpHandler.cpp.

#define HTTP_PREF (   _pref)    HTTP_PREF_PREFIX _pref

Definition at line 110 of file nsHttpHandler.cpp.

#define HTTP_PREF_PREFIX   "network.http."

Definition at line 103 of file nsHttpHandler.cpp.

#define INTL_ACCEPT_CHARSET   "intl.charset.default"

Definition at line 105 of file nsHttpHandler.cpp.

#define INTL_ACCEPT_LANGUAGES   "intl.accept_languages"

Definition at line 104 of file nsHttpHandler.cpp.

#define MULTI_PREF_CHANGED (   p)    ((pref == nsnull) || !PL_strncmp(pref, p, sizeof(p) - 1))
#define NETWORK_ENABLEIDN   "network.enableIDN"

Definition at line 106 of file nsHttpHandler.cpp.

#define PREF_CHANGED (   p)    ((pref == nsnull) || !PL_strcmp(pref, p))
#define UA_APPNAME   "Mozilla"

Definition at line 99 of file nsHttpHandler.cpp.

Definition at line 101 of file nsHttpHandler.cpp.

#define UA_APPVERSION   "5.0"

Definition at line 100 of file nsHttpHandler.cpp.

#define UA_PREF (   _pref)    UA_PREF_PREFIX _pref

Definition at line 109 of file nsHttpHandler.cpp.

#define UA_PREF_PREFIX   "general.useragent."

Definition at line 98 of file nsHttpHandler.cpp.


Function Documentation

static nsresult NewURI ( const nsACString &  aSpec,
const char *  aCharset,
nsIURI aBaseURI,
PRInt32  aDefaultPort,
nsIURI **  aURI 
) [static]

Definition at line 116 of file nsHttpHandler.cpp.

{
    nsStandardURL *url = new nsStandardURL();
    if (!url)
        return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(url);

    nsresult rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY,
                            aDefaultPort, aSpec, aCharset, aBaseURI);
    if (NS_FAILED(rv)) {
        NS_RELEASE(url);
        return rv;
    }

    *aURI = url; // no QI needed
    return NS_OK;
}

Here is the call graph for this function:

static NS_DEFINE_CID ( kIOServiceCID  ,
NS_IOSERVICE_CID   
) [static]
static NS_DEFINE_CID ( kStreamConverterServiceCID  ,
NS_STREAMCONVERTERSERVICE_CID   
) [static]
static NS_DEFINE_CID ( kCookieServiceCID  ,
NS_COOKIESERVICE_CID   
) [static]
static NS_DEFINE_CID ( kCacheServiceCID  ,
NS_CACHESERVICE_CID   
) [static]
static NS_DEFINE_CID ( kSocketProviderServiceCID  ,
NS_SOCKETPROVIDERSERVICE_CID   
) [static]

Definition at line 1742 of file nsHttpHandler.cpp.

{
    nsCOMPtr<nsIProtocolHandler> httpHandler(
            do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http"));
    NS_ASSERTION(httpHandler.get() != nsnull, "no http handler?");
    return NS_OK;
}

Here is the call graph for this function:

Definition at line 1392 of file nsHttpHandler.cpp.

{
    aScheme.AssignLiteral("http");
    return NS_OK;
}
static nsresult PrepareAcceptCharsets ( const char *  i_AcceptCharset,
nsACString &  o_AcceptCharset 
) [static]

Allocates a C string into that contains a character set/encoding list notated with HTTP "q" values for output with a HTTP Accept-Charset header.

If the UTF-8 character set is not present, it will be added. If a wildcard catch-all is not present, it will be added. If more than one charset is set (as of 2001-02-07, only one is used), they will be comma delimited and with q values set for each charset in decending order.

Ex: passing: "euc-jp" returns: "euc-jp,utf-8;q=0.6,*;q=0.6"

passing: "UTF-8" returns: "UTF-8, *"

Definition at line 1259 of file nsHttpHandler.cpp.

{
    PRUint32 n, size, wrote, u;
    PRInt32 available;
    double q, dec;
    char *p, *p2, *token, *q_Accept, *o_Accept;
    const char *acceptable, *comma;
    PRBool add_utf = PR_FALSE;
    PRBool add_asterisk = PR_FALSE;

    if (!i_AcceptCharset)
        acceptable = "";
    else
        acceptable = i_AcceptCharset;
    o_Accept = nsCRT::strdup(acceptable);
    if (nsnull == o_Accept)
        return NS_ERROR_OUT_OF_MEMORY;
    for (p = o_Accept, n = size = 0; '\0' != *p; p++) {
        if (*p == ',') n++;
            size++;
    }

    // only add "utf-8" and "*" to the list if they aren't
    // already specified.

    if (PL_strcasestr(acceptable, "utf-8") == NULL) {
        n++;
        add_utf = PR_TRUE;
    }
    if (PL_strstr(acceptable, "*") == NULL) {
        n++;
        add_asterisk = PR_TRUE;
    }

    available = size + ++n * 11 + 1;
    q_Accept = new char[available];
    if ((char *) 0 == q_Accept)
        return NS_ERROR_OUT_OF_MEMORY;
    *q_Accept = '\0';
    q = 1.0;
    dec = q / (double) n;
    n = 0;
    p2 = q_Accept;
    for (token = nsCRT::strtok(o_Accept, ",", &p);
         token != (char *) 0;
         token = nsCRT::strtok(p, ",", &p)) {
        token = net_FindCharNotInSet(token, HTTP_LWS);
        char* trim;
        trim = net_FindCharInSet(token, ";" HTTP_LWS);
        if (trim != (char*)0)  // remove "; q=..." if present
            *trim = '\0';

        if (*token != '\0') {
            comma = n++ != 0 ? "," : ""; // delimiter if not first item
            u = QVAL_TO_UINT(q);
            if (u < 10)
                wrote = PR_snprintf(p2, available, "%s%s;q=0.%u", comma, token, u);
            else
                wrote = PR_snprintf(p2, available, "%s%s", comma, token);
            q -= dec;
            p2 += wrote;
            available -= wrote;
            NS_ASSERTION(available > 0, "allocated string not long enough");
        }
    }
    if (add_utf) {
        comma = n++ != 0 ? "," : ""; // delimiter if not first item
        u = QVAL_TO_UINT(q);
        if (u < 10)
            wrote = PR_snprintf(p2, available, "%sutf-8;q=0.%u", comma, u);
        else
            wrote = PR_snprintf(p2, available, "%sutf-8", comma);
        q -= dec;
        p2 += wrote;
        available -= wrote;
        NS_ASSERTION(available > 0, "allocated string not long enough");
    }
    if (add_asterisk) {
        comma = n++ != 0 ? "," : ""; // delimiter if not first item

        // keep q of "*" equal to the lowest q value
        // in the event of a tie between the q of "*" and a non-wildcard
        // the non-wildcard always receives preference.

        q += dec;
        u = QVAL_TO_UINT(q);
        if (u < 10)
            wrote = PR_snprintf(p2, available, "%s*;q=0.%u", comma, u);
        else
            wrote = PR_snprintf(p2, available, "%s*", comma);
        available -= wrote;
        p2 += wrote;
        NS_ASSERTION(available > 0, "allocated string not long enough");
    }
    nsCRT::free(o_Accept);

    // change alloc from C++ new/delete to nsCRT::strdup's way
    o_AcceptCharset.Assign(q_Accept);
#if defined DEBUG_havill
    printf("Accept-Charset: %s\n", q_Accept);
#endif
    delete [] q_Accept;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult PrepareAcceptLanguages ( const char *  i_AcceptLanguages,
nsACString &  o_AcceptLanguages 
) [static]

Allocates a C string into that contains a ISO 639 language list notated with HTTP "q" values for output with a HTTP Accept-Language header.

Previous q values will be stripped because the order of the langs imply the q value. The q values are calculated by dividing 1.0 amongst the number of languages present.

Ex: passing: "en, ja" returns: "en,ja;q=0.5"

passing: "en, ja, fr_CA" returns: "en,ja;q=0.7,fr_CA;q=0.3"

Definition at line 1173 of file nsHttpHandler.cpp.

{
    if (!i_AcceptLanguages)
        return NS_OK;

    PRUint32 n, size, wrote;
    double q, dec;
    char *p, *p2, *token, *q_Accept, *o_Accept;
    const char *comma;
    PRInt32 available;

    o_Accept = nsCRT::strdup(i_AcceptLanguages);
    if (!o_Accept)
        return NS_ERROR_OUT_OF_MEMORY;
    for (p = o_Accept, n = size = 0; '\0' != *p; p++) {
        if (*p == ',') n++;
            size++;
    }

    available = size + ++n * 11 + 1;
    q_Accept = new char[available];
    if (!q_Accept) {
        nsCRT::free(o_Accept);
        return NS_ERROR_OUT_OF_MEMORY;
    }
    *q_Accept = '\0';
    q = 1.0;
    dec = q / (double) n;
    n = 0;
    p2 = q_Accept;
    for (token = nsCRT::strtok(o_Accept, ",", &p);
         token != (char *) 0;
         token = nsCRT::strtok(p, ",", &p))
    {
        token = net_FindCharNotInSet(token, HTTP_LWS);
        char* trim;
        trim = net_FindCharInSet(token, ";" HTTP_LWS);
        if (trim != (char*)0)  // remove "; q=..." if present
            *trim = '\0';

        if (*token != '\0') {
            comma = n++ != 0 ? "," : ""; // delimiter if not first item
            PRUint32 u = QVAL_TO_UINT(q);
            if (u < 10)
                wrote = PR_snprintf(p2, available, "%s%s;q=0.%u", comma, token, u);
            else
                wrote = PR_snprintf(p2, available, "%s%s", comma, token);
            q -= dec;
            p2 += wrote;
            available -= wrote;
            NS_ASSERTION(available > 0, "allocated string not long enough");
        }
    }
    nsCRT::free(o_Accept);

    o_AcceptLanguages.Assign((const char *) q_Accept);
    delete [] q_Accept;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int StringCompare ( const void s1,
const void s2,
void  
) [static]

Definition at line 739 of file nsHttpHandler.cpp.

{
    return nsCRT::strcmp(*NS_STATIC_CAST(const char *const *, s1),
                         *NS_STATIC_CAST(const char *const *, s2));
}

Variable Documentation

Definition at line 142 of file nsHttpHandler.cpp.