netwerk/dns/nsEffectiveTLDService.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef EffectiveTLDService_h
michael@0 7 #define EffectiveTLDService_h
michael@0 8
michael@0 9 #include "nsIEffectiveTLDService.h"
michael@0 10
michael@0 11 #include "nsIMemoryReporter.h"
michael@0 12 #include "nsTHashtable.h"
michael@0 13 #include "nsString.h"
michael@0 14 #include "nsCOMPtr.h"
michael@0 15 #include "mozilla/Attributes.h"
michael@0 16 #include "mozilla/MemoryReporting.h"
michael@0 17
michael@0 18 class nsIIDNService;
michael@0 19
michael@0 20 #define ETLD_ENTRY_N_INDEX_BITS 30
michael@0 21
michael@0 22 // struct for static data generated from effective_tld_names.dat
michael@0 23 struct ETLDEntry {
michael@0 24 uint32_t strtab_index : ETLD_ENTRY_N_INDEX_BITS;
michael@0 25 uint32_t exception : 1;
michael@0 26 uint32_t wild : 1;
michael@0 27 };
michael@0 28
michael@0 29
michael@0 30 // hash entry class
michael@0 31 class nsDomainEntry : public PLDHashEntryHdr
michael@0 32 {
michael@0 33 friend class nsEffectiveTLDService;
michael@0 34 public:
michael@0 35 // Hash methods
michael@0 36 typedef const char* KeyType;
michael@0 37 typedef const char* KeyTypePointer;
michael@0 38
michael@0 39 nsDomainEntry(KeyTypePointer aEntry)
michael@0 40 {
michael@0 41 }
michael@0 42
michael@0 43 nsDomainEntry(const nsDomainEntry& toCopy)
michael@0 44 {
michael@0 45 // if we end up here, things will break. nsTHashtable shouldn't
michael@0 46 // allow this, since we set ALLOW_MEMMOVE to true.
michael@0 47 NS_NOTREACHED("nsDomainEntry copy constructor is forbidden!");
michael@0 48 }
michael@0 49
michael@0 50 ~nsDomainEntry()
michael@0 51 {
michael@0 52 }
michael@0 53
michael@0 54 KeyType GetKey() const
michael@0 55 {
michael@0 56 return GetEffectiveTLDName(mData->strtab_index);
michael@0 57 }
michael@0 58
michael@0 59 bool KeyEquals(KeyTypePointer aKey) const
michael@0 60 {
michael@0 61 return !strcmp(GetKey(), aKey);
michael@0 62 }
michael@0 63
michael@0 64 static KeyTypePointer KeyToPointer(KeyType aKey)
michael@0 65 {
michael@0 66 return aKey;
michael@0 67 }
michael@0 68
michael@0 69 static PLDHashNumber HashKey(KeyTypePointer aKey)
michael@0 70 {
michael@0 71 // PL_DHashStringKey doesn't use the table parameter, so we can safely
michael@0 72 // pass nullptr
michael@0 73 return PL_DHashStringKey(nullptr, aKey);
michael@0 74 }
michael@0 75
michael@0 76 enum { ALLOW_MEMMOVE = true };
michael@0 77
michael@0 78 void SetData(const ETLDEntry* entry) { mData = entry; }
michael@0 79
michael@0 80 bool IsNormal() { return mData->wild || !mData->exception; }
michael@0 81 bool IsException() { return mData->exception; }
michael@0 82 bool IsWild() { return mData->wild; }
michael@0 83
michael@0 84 static const char *GetEffectiveTLDName(size_t idx)
michael@0 85 {
michael@0 86 return strings.strtab + idx;
michael@0 87 }
michael@0 88
michael@0 89 private:
michael@0 90 const ETLDEntry* mData;
michael@0 91 #define ETLD_STR_NUM_1(line) str##line
michael@0 92 #define ETLD_STR_NUM(line) ETLD_STR_NUM_1(line)
michael@0 93 struct etld_string_list {
michael@0 94 #define ETLD_ENTRY(name, ex, wild) char ETLD_STR_NUM(__LINE__)[sizeof(name)];
michael@0 95 #include "etld_data.inc"
michael@0 96 #undef ETLD_ENTRY
michael@0 97 };
michael@0 98 static const union etld_strings {
michael@0 99 struct etld_string_list list;
michael@0 100 char strtab[1];
michael@0 101 } strings;
michael@0 102 static const ETLDEntry entries[];
michael@0 103 void FuncForStaticAsserts(void);
michael@0 104 #undef ETLD_STR_NUM
michael@0 105 #undef ETLD_STR_NUM1
michael@0 106 };
michael@0 107
michael@0 108 class nsEffectiveTLDService MOZ_FINAL
michael@0 109 : public nsIEffectiveTLDService
michael@0 110 , public nsIMemoryReporter
michael@0 111 {
michael@0 112 public:
michael@0 113 NS_DECL_ISUPPORTS
michael@0 114 NS_DECL_NSIEFFECTIVETLDSERVICE
michael@0 115 NS_DECL_NSIMEMORYREPORTER
michael@0 116
michael@0 117 nsEffectiveTLDService();
michael@0 118 nsresult Init();
michael@0 119
michael@0 120 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
michael@0 121
michael@0 122 private:
michael@0 123 nsresult GetBaseDomainInternal(nsCString &aHostname, int32_t aAdditionalParts, nsACString &aBaseDomain);
michael@0 124 nsresult NormalizeHostname(nsCString &aHostname);
michael@0 125 ~nsEffectiveTLDService();
michael@0 126
michael@0 127 nsTHashtable<nsDomainEntry> mHash;
michael@0 128 nsCOMPtr<nsIIDNService> mIDNService;
michael@0 129 };
michael@0 130
michael@0 131 #endif // EffectiveTLDService_h

mercurial