LCOV - code coverage report
Current view: directory - netwerk/dns - nsEffectiveTLDService.h (source / functions) Found Hit Coverage
Test: app.info Lines: 17 17 100.0 %
Date: 2012-06-02 Functions: 11 11 100.0 %

       1                 : //* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla TLD Service
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Google Inc.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2006
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Pamela Greene <pamg.bugs@gmail.com> (original author)
      24                 :  *   Daniel Witte <dwitte@stanford.edu>
      25                 :  *   Jeff Walden <jwalden+code@mit.edu>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      29                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #include "nsIEffectiveTLDService.h"
      42                 : 
      43                 : #include "nsTHashtable.h"
      44                 : #include "nsString.h"
      45                 : #include "nsCOMPtr.h"
      46                 : 
      47                 : class nsIIDNService;
      48                 : 
      49                 : // struct for static data generated from effective_tld_names.dat
      50                 : struct ETLDEntry {
      51                 :   const char* domain;
      52                 :   bool exception;
      53                 :   bool wild;
      54                 : };
      55                 : 
      56                 : 
      57                 : // hash entry class
      58                 : class nsDomainEntry : public PLDHashEntryHdr
      59                 : {
      60                 : public:
      61                 :   // Hash methods
      62                 :   typedef const char* KeyType;
      63                 :   typedef const char* KeyTypePointer;
      64                 : 
      65         1223704 :   nsDomainEntry(KeyTypePointer aEntry)
      66         1223704 :   {
      67         1223704 :   }
      68                 : 
      69                 :   nsDomainEntry(const nsDomainEntry& toCopy)
      70                 :   {
      71                 :     // if we end up here, things will break. nsTHashtable shouldn't
      72                 :     // allow this, since we set ALLOW_MEMMOVE to true.
      73                 :     NS_NOTREACHED("nsDomainEntry copy constructor is forbidden!");
      74                 :   }
      75                 : 
      76         1215600 :   ~nsDomainEntry()
      77                 :   {
      78         1215600 :   }
      79                 : 
      80                 :   KeyType GetKey() const
      81                 :   {
      82                 :     return mData->domain;
      83                 :   }
      84                 : 
      85            4073 :   bool KeyEquals(KeyTypePointer aKey) const
      86                 :   {
      87            4073 :     return !strcmp(mData->domain, aKey);
      88                 :   }
      89                 : 
      90         1282926 :   static KeyTypePointer KeyToPointer(KeyType aKey)
      91                 :   {
      92         1282926 :     return aKey;
      93                 :   }
      94                 : 
      95         1282926 :   static PLDHashNumber HashKey(KeyTypePointer aKey)
      96                 :   {
      97                 :     // PL_DHashStringKey doesn't use the table parameter, so we can safely
      98                 :     // pass nsnull
      99         1282926 :     return PL_DHashStringKey(nsnull, aKey);
     100                 :   }
     101                 : 
     102                 :   enum { ALLOW_MEMMOVE = true };
     103                 : 
     104         1223704 :   void SetData(const ETLDEntry* entry) { mData = entry; }
     105                 : 
     106            3963 :   bool IsNormal() { return mData->wild || !mData->exception; }
     107              97 :   bool IsException() { return mData->exception; }
     108            4073 :   bool IsWild() { return mData->wild; }
     109                 : 
     110                 : private:
     111                 :   const ETLDEntry* mData;
     112                 : };
     113                 : 
     114                 : class nsEffectiveTLDService : public nsIEffectiveTLDService
     115                 : {
     116                 : public:
     117                 :   NS_DECL_ISUPPORTS
     118                 :   NS_DECL_NSIEFFECTIVETLDSERVICE
     119                 : 
     120             302 :   nsEffectiveTLDService() { }
     121                 :   nsresult Init();
     122                 : 
     123                 : private:
     124                 :   nsresult GetBaseDomainInternal(nsCString &aHostname, PRUint32 aAdditionalParts, nsACString &aBaseDomain);
     125                 :   nsresult NormalizeHostname(nsCString &aHostname);
     126             300 :   ~nsEffectiveTLDService() { }
     127                 : 
     128                 :   nsTHashtable<nsDomainEntry> mHash;
     129                 :   nsCOMPtr<nsIIDNService>     mIDNService;
     130                 : };

Generated by: LCOV version 1.7