Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsDNSService2.cpp File Reference
#include "nsDNSService2.h"
#include "nsIDNSRecord.h"
#include "nsIDNSListener.h"
#include "nsICancelable.h"
#include "nsIProxyObjectManager.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nsAutoLock.h"
#include "nsAutoPtr.h"
#include "nsNetCID.h"
#include "nsNetError.h"
#include "prsystem.h"
#include "prnetdb.h"
#include "prmon.h"
#include "prio.h"
#include "plstr.h"

Go to the source code of this file.


class  nsDNSRecord
class  nsDNSAsyncRequest
class  nsDNSSyncRequest


 NS_IMPL_THREADSAFE_ISUPPORTS3 (nsDNSService, nsIDNSService, nsPIDNSService, nsIObserver) NS_IMETHODIMP nsDNSService


static const char kPrefDnsCacheEntries [] = "network.dnsCacheEntries"
static const char kPrefDnsCacheExpiration [] = "network.dnsCacheExpiration"
static const char kPrefEnableIDN [] = "network.enableIDN"
static const char kPrefIPv4OnlyDomains [] = "network.dns.ipv4OnlyDomains"
static const char kPrefDisableIPv6 [] = "network.dns.disableIPv6"

Function Documentation

Definition at line 291 of file nsDNSService2.cpp.


    PRBool firstTime = (mLock == nsnull);

    // prefs
    PRUint32 maxCacheEntries  = 20;
    PRUint32 maxCacheLifetime = 1; // minutes
    PRBool   enableIDN        = PR_TRUE;
    PRBool   disableIPv6      = PR_FALSE;
    nsAdoptingCString ipv4OnlyDomains;

    // read prefs
    nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
    if (prefs) {
        PRInt32 val;
        if (NS_SUCCEEDED(prefs->GetIntPref(kPrefDnsCacheEntries, &val)))
            maxCacheEntries = (PRUint32) val;
        if (NS_SUCCEEDED(prefs->GetIntPref(kPrefDnsCacheExpiration, &val)))
            maxCacheLifetime = val / 60; // convert from seconds to minutes

        // ASSUMPTION: pref branch does not modify out params on failure
        prefs->GetBoolPref(kPrefEnableIDN, &enableIDN);
        prefs->GetBoolPref(kPrefDisableIPv6, &disableIPv6);
        prefs->GetCharPref(kPrefIPv4OnlyDomains, getter_Copies(ipv4OnlyDomains));

    if (firstTime) {
        mLock = PR_NewLock();
        if (!mLock)
            return NS_ERROR_OUT_OF_MEMORY;

        // register as prefs observer
        prefs->AddObserver(kPrefDnsCacheEntries, this, PR_FALSE);
        prefs->AddObserver(kPrefDnsCacheExpiration, this, PR_FALSE);
        prefs->AddObserver(kPrefEnableIDN, this, PR_FALSE);
        prefs->AddObserver(kPrefIPv4OnlyDomains, this, PR_FALSE);
        prefs->AddObserver(kPrefDisableIPv6, this, PR_FALSE);

    // we have to null out mIDN since we might be getting re-initialized
    // as a result of a pref change.
    nsCOMPtr<nsIIDNService> idn;
    if (enableIDN)
        idn = do_GetService(NS_IDNSERVICE_CONTRACTID);

    nsRefPtr<nsHostResolver> res;
    nsresult rv = nsHostResolver::Create(maxCacheEntries,
    if (NS_SUCCEEDED(rv)) {
        // now, set all of our member variables while holding the lock
        nsAutoLock lock(mLock);
        mResolver = res;
        mIDN = idn;
        mIPv4OnlyDomains = ipv4OnlyDomains; // exchanges buffer ownership
        mDisableIPv6 = disableIPv6;

    return rv;

Here is the call graph for this function:

Variable Documentation

const char kPrefDisableIPv6[] = "network.dns.disableIPv6" [static]

Definition at line 63 of file nsDNSService2.cpp.

const char kPrefDnsCacheEntries[] = "network.dnsCacheEntries" [static]

Definition at line 59 of file nsDNSService2.cpp.

const char kPrefDnsCacheExpiration[] = "network.dnsCacheExpiration" [static]

Definition at line 60 of file nsDNSService2.cpp.

const char kPrefEnableIDN[] = "network.enableIDN" [static]

Definition at line 61 of file nsDNSService2.cpp.

const char kPrefIPv4OnlyDomains[] = "network.dns.ipv4OnlyDomains" [static]

Definition at line 62 of file nsDNSService2.cpp.