LCOV - code coverage report
Current view: top level - netwerk/dns - nsEffectiveTLDService.h (source / functions) Hit Total Coverage
Test: output.info Lines: 5 8 62.5 %
Date: 2017-07-14 16:53:18 Functions: 3 6 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef EffectiveTLDService_h
       7             : #define EffectiveTLDService_h
       8             : 
       9             : #include "nsIEffectiveTLDService.h"
      10             : 
      11             : #include "nsIMemoryReporter.h"
      12             : #include "nsString.h"
      13             : #include "nsCOMPtr.h"
      14             : #include "mozilla/Attributes.h"
      15             : #include "mozilla/BinarySearch.h"
      16             : #include "mozilla/MemoryReporting.h"
      17             : 
      18             : class nsIIDNService;
      19             : 
      20             : // struct for static data generated from effective_tld_names.dat
      21             : struct ETLDEntry {
      22             :   friend class nsEffectiveTLDService;
      23             : 
      24             : public:
      25           0 :   bool IsNormal()    const { return wild || !exception; }
      26           0 :   bool IsException() const { return exception; }
      27           0 :   bool IsWild()      const { return wild; }
      28             : 
      29       25845 :   const char* GetEffectiveTLDName() const
      30             :   {
      31       25845 :     return strings.strtab + strtab_index;
      32             :   }
      33             : 
      34             :   static const ETLDEntry* GetEntry(const char* aDomain);
      35             : 
      36             :   static const size_t ETLD_ENTRY_N_INDEX_BITS = 30;
      37             : 
      38             :   // These fields must be public to allow static construction.
      39             :   uint32_t strtab_index : ETLD_ENTRY_N_INDEX_BITS;
      40             :   uint32_t exception : 1;
      41             :   uint32_t wild : 1;
      42             : 
      43             : private:
      44             :   struct Cmp {
      45         763 :     int operator()(const ETLDEntry aEntry) const
      46             :     {
      47         763 :       return strcmp(mName, aEntry.GetEffectiveTLDName());
      48             :     }
      49          59 :     explicit Cmp(const char* aName) : mName(aName) {}
      50             :     const char* mName;
      51             :   };
      52             : 
      53             : #define ETLD_STR_NUM_1(line) str##line
      54             : #define ETLD_STR_NUM(line) ETLD_STR_NUM_1(line)
      55             :   struct etld_string_list {
      56             : #define ETLD_ENTRY(name, ex, wild) char ETLD_STR_NUM(__LINE__)[sizeof(name)];
      57             : #include "etld_data.inc"
      58             : #undef ETLD_ENTRY
      59             :   };
      60             : 
      61             :   // This static string table is all the eTLD domain names packed together.
      62             :   static const union etld_strings {
      63             :     struct etld_string_list list;
      64             :     char strtab[1];
      65             :   } strings;
      66             : 
      67             :   // This is the static entries table. Each entry has an index into the string
      68             :   // table. The entries are in sorted order so that binary search can be used.
      69             :   static const ETLDEntry entries[];
      70             : 
      71             :   void FuncForStaticAsserts(void);
      72             : #undef ETLD_STR_NUM
      73             : #undef ETLD_STR_NUM1
      74             : };
      75             : 
      76             : class nsEffectiveTLDService final
      77             :   : public nsIEffectiveTLDService
      78             :   , public nsIMemoryReporter
      79             : {
      80             : public:
      81             :   NS_DECL_ISUPPORTS
      82             :   NS_DECL_NSIEFFECTIVETLDSERVICE
      83             :   NS_DECL_NSIMEMORYREPORTER
      84             : 
      85             :   nsEffectiveTLDService();
      86             :   nsresult Init();
      87             : 
      88             :   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
      89             : 
      90             : private:
      91             :   nsresult GetBaseDomainInternal(nsCString &aHostname, int32_t aAdditionalParts, nsACString &aBaseDomain);
      92             :   nsresult NormalizeHostname(nsCString &aHostname);
      93             :   ~nsEffectiveTLDService();
      94             : 
      95             :   nsCOMPtr<nsIIDNService>     mIDNService;
      96             : };
      97             : 
      98             : #endif // EffectiveTLDService_h

Generated by: LCOV version 1.13