Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
nsHttp Struct Reference

#include <nsHttp.h>

List of all members.

Static Public Member Functions

static nsresult CreateAtomTable ()
static void DestroyAtomTable ()
static nsHttpAtom ResolveAtom (const char *)
static nsHttpAtom ResolveAtom (const nsACString &s)
static PRBool IsValidToken (const char *start, const char *end)
static PRBool IsValidToken (const nsCString &s)
static PRBool ParseInt64 (const char *input, const char **next, PRInt64 *result)
static PRBool ParseInt64 (const char *input, PRInt64 *result)

Detailed Description

Definition at line 135 of file nsHttp.h.


Member Function Documentation

Definition at line 127 of file nsHttp.cpp.

{
    NS_ASSERTION(!sAtomTable.ops, "atom table already initialized");

    if (!sLock) {
        sLock = PR_NewLock();
        if (!sLock)
            return NS_ERROR_OUT_OF_MEMORY;
    }

    // The capacity for this table is initialized to a value greater than the
    // number of known atoms (NUM_HTTP_ATOMS) because we expect to encounter a
    // few random headers right off the bat.
    if (!PL_DHashTableInit(&sAtomTable, &ops, nsnull, sizeof(PLDHashEntryStub),
                           NUM_HTTP_ATOMS + 10)) {
        sAtomTable.ops = nsnull;
        return NS_ERROR_OUT_OF_MEMORY;
    }

    // fill the table with our known atoms
    const char *const atoms[] = {
#define HTTP_ATOM(_name, _value) nsHttp::_name._val,
#include "nsHttpAtomList.h"
#undef HTTP_ATOM
        nsnull
    };

    for (int i = 0; atoms[i]; ++i) {
        PLDHashEntryStub *stub = NS_REINTERPRET_CAST(PLDHashEntryStub *,
                PL_DHashTableOperate(&sAtomTable, atoms[i], PL_DHASH_ADD));
        if (!stub)
            return NS_ERROR_OUT_OF_MEMORY;
        
        NS_ASSERTION(!stub->key, "duplicate static atom");
        stub->key = atoms[i];
    }

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 168 of file nsHttp.cpp.

{
    if (sAtomTable.ops) {
        PL_DHashTableFinish(&sAtomTable);
        sAtomTable.ops = nsnull;
    }

    while (sHeapAtoms) {
        HttpHeapAtom *next = sHeapAtoms->next;
        free(sHeapAtoms);
        sHeapAtoms = next;
    }

    if (sLock) {
        PR_DestroyLock(sLock);
        sLock = nsnull;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsHttp::IsValidToken ( const char *  start,
const char *  end 
) [static]

Definition at line 254 of file nsHttp.cpp.

{
    if (start == end)
        return PR_FALSE;

    for (; start != end; ++start) {
        const unsigned char idx = *start;
        if (idx > 127 || !kValidTokenMap[idx])
            return PR_FALSE;
    }

    return PR_TRUE;
}

Here is the caller graph for this function:

static PRBool nsHttp::IsValidToken ( const nsCString s) [inline, static]

Definition at line 151 of file nsHttp.h.

                                                          {
        const char *start = s.get();
        return IsValidToken(start, start + s.Length());
    }

Here is the call graph for this function:

PRBool nsHttp::ParseInt64 ( const char *  input,
const char **  next,
PRInt64 result 
) [static]

Definition at line 269 of file nsHttp.cpp.

{
    const char *start = input;
    *r = 0;
    while (*input >= '0' && *input <= '9') {
        PRInt64 next = 10 * (*r) + (*input - '0');
        if (next < *r) // overflow?
            return PR_FALSE;
        *r = next;
        ++input;
    }
    if (input == start) // nothing parsed?
        return PR_FALSE;
    if (next)
        *next = input;
    return PR_TRUE;
}

Here is the caller graph for this function:

static PRBool nsHttp::ParseInt64 ( const char *  input,
PRInt64 result 
) [inline, static]

Definition at line 169 of file nsHttp.h.

                                                                        {
        const char *next;
        return ParseInt64(input, &next, result) && *next == '\0';
    }

Here is the call graph for this function:

nsHttpAtom nsHttp::ResolveAtom ( const char *  str) [static]

Definition at line 189 of file nsHttp.cpp.

{
    nsHttpAtom atom = { nsnull };

    if (!str || !sAtomTable.ops)
        return atom;

    nsAutoLock lock(sLock);

    PLDHashEntryStub *stub = NS_REINTERPRET_CAST(PLDHashEntryStub *,
            PL_DHashTableOperate(&sAtomTable, str, PL_DHASH_ADD));
    if (!stub)
        return atom;  // out of memory

    if (stub->key) {
        atom._val = NS_REINTERPRET_CAST(const char *, stub->key);
        return atom;
    }

    // if the atom could not be found in the atom table, then we'll go
    // and allocate a new atom on the heap.
    HttpHeapAtom *heapAtom = NewHeapAtom(str);
    if (!heapAtom)
        return atom;  // out of memory

    stub->key = atom._val = heapAtom->value;
    return atom;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsHttpAtom nsHttp::ResolveAtom ( const nsACString &  s) [inline, static]

Definition at line 142 of file nsHttp.h.

    {
        return ResolveAtom(PromiseFlatCString(s).get());
    }

Here is the call graph for this function:


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