Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
RCHostLookup Class Reference

#include <rcnetdb.h>

List of all members.

Public Member Functions

virtual ~RCHostLookup ()
 RCHostLookup ()
virtual PRStatus ByName (const char *name)
virtual PRStatus ByAddress (const RCNetAddr &)
virtual const RCNetAddr * operator[] (PRUintn)

Private Member Functions

 RCHostLookup (const RCHostLookup &)
RCHostLookupoperator= (const RCHostLookup &)

Private Attributes

RCLock ml
PRIntn max_index
RCNetAddr * address

Detailed Description

Definition at line 100 of file rcnetdb.h.


Constructor & Destructor Documentation

Definition at line 133 of file rcnetdb.cpp.

{
    if (NULL != address) delete [] address;
}  /* RCHostLookup::~RCHostLookup */

Definition at line 138 of file rcnetdb.cpp.

                          : RCBase()
{
    address = NULL;
    max_index = 0;
}  /* RCHostLookup::RCHostLookup */

Member Function Documentation

PRStatus RCHostLookup::ByAddress ( const RCNetAddr &  host_addr) [virtual]

Definition at line 184 of file rcnetdb.cpp.

{
    PRStatus rv;
    PRNetAddr addr;
    PRHostEnt hostentry;
    PRIntn index = 0, max;
    RCNetAddr* vector = NULL;
    RCNetAddr* old_vector = NULL;
    char *buffer = (char*)PR_Malloc(PR_NETDB_BUF_SIZE);
    if (NULL == buffer) return PR_FAILURE;
    rv = PR_GetHostByAddr(host_addr, buffer, PR_NETDB_BUF_SIZE, &hostentry);
    if (PR_SUCCESS == rv)
    {
        for (max = 0, index = 0;; ++max)
        {
            index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
            if (0 == index) break;
        }
        if (max > 0)
        {
            vector = new RCNetAddr[max];
            while (--max > 0)
            {
                index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
                if (0 == index) break;
                vector[index] = &addr;
            }
            {
                RCEnter entry(&ml);
                old_vector = address;
                address = vector;
                max_index = max;
            }
            if (NULL != old_vector) delete [] old_vector;
        }
    }
    if (NULL != buffer) PR_DELETE(buffer);
    return PR_SUCCESS;
}  /* RCHostLookup::ByAddress */
PRStatus RCHostLookup::ByName ( const char *  name) [virtual]

Definition at line 144 of file rcnetdb.cpp.

{
    PRStatus rv;
    PRNetAddr addr;
    PRHostEnt hostentry;
    PRIntn index = 0, max;
    RCNetAddr* vector = NULL;
    RCNetAddr* old_vector = NULL;
    void* buffer = PR_Malloc(PR_NETDB_BUF_SIZE);
    if (NULL == buffer) return PR_FAILURE;
    rv = PR_GetHostByName(name, (char*)buffer, PR_NETDB_BUF_SIZE, &hostentry);
    if (PR_SUCCESS == rv)
    {
        for (max = 0, index = 0;; ++max)
        {
            index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
            if (0 == index) break;
        }
        if (max > 0)
        {
            vector = new RCNetAddr[max];
            while (--max > 0)
            {
                index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
                if (0 == index) break;
                vector[index] = &addr;
            }
            {
                RCEnter entry(&ml);
                old_vector = address;
                address = vector;
                max_index = max;
            }
            if (NULL != old_vector) delete [] old_vector;
        }
    }
    if (NULL != buffer) PR_DELETE(buffer);
    return PR_SUCCESS;
}  /* RCHostLookup::ByName */
RCHostLookup& RCHostLookup::operator= ( const RCHostLookup ) [private]
const RCNetAddr * RCHostLookup::operator[] ( PRUintn  which) [virtual]

Definition at line 224 of file rcnetdb.cpp.

{
    RCNetAddr* addr = NULL;
    if (which < max_index)
        addr = &address[which];
    return addr;
}  /* RCHostLookup::operator[] */

Member Data Documentation

RCNetAddr* RCHostLookup::address [private]

Definition at line 115 of file rcnetdb.h.

PRIntn RCHostLookup::max_index [private]

Definition at line 114 of file rcnetdb.h.

RCLock RCHostLookup::ml [private]

Definition at line 113 of file rcnetdb.h.


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