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
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/
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
15 * The Original Code is Mozilla TLD Service
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
23 * Pamela Greene <pamg.bugs@gmail.com> (original author)
24 * Daniel Witte <dwitte@stanford.edu>
25 * Jeff Walden <jwalden+code@mit.edu>
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.
39 * ***** END LICENSE BLOCK ***** */
41 #include "nsIEffectiveTLDService.h"
43 #include "nsTHashtable.h"
49 // struct for static data generated from effective_tld_names.dat
52 PRPackedBool exception
;
58 class nsDomainEntry
: public PLDHashEntryHdr
62 typedef const char* KeyType
;
63 typedef const char* KeyTypePointer
;
65 nsDomainEntry(KeyTypePointer aEntry
)
69 nsDomainEntry(const nsDomainEntry
& toCopy
)
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!");
80 KeyType
GetKey() const
85 PRBool
KeyEquals(KeyTypePointer aKey
) const
87 return !strcmp(mData
->domain
, aKey
);
90 static KeyTypePointer
KeyToPointer(KeyType aKey
)
95 static PLDHashNumber
HashKey(KeyTypePointer aKey
)
97 // PL_DHashStringKey doesn't use the table parameter, so we can safely
99 return PL_DHashStringKey(nsnull
, aKey
);
102 enum { ALLOW_MEMMOVE
= PR_TRUE
};
104 void SetData(const ETLDEntry
* entry
) { mData
= entry
; }
106 PRPackedBool
IsNormal() { return mData
->wild
|| !mData
->exception
; }
107 PRPackedBool
IsException() { return mData
->exception
; }
108 PRPackedBool
IsWild() { return mData
->wild
; }
111 const ETLDEntry
* mData
;
114 class nsEffectiveTLDService
: public nsIEffectiveTLDService
118 NS_DECL_NSIEFFECTIVETLDSERVICE
120 nsEffectiveTLDService() { }
124 nsresult
GetBaseDomainInternal(nsCString
&aHostname
, PRUint32 aAdditionalParts
, nsACString
&aBaseDomain
);
125 nsresult
NormalizeHostname(nsCString
&aHostname
);
126 ~nsEffectiveTLDService() { }
128 nsTHashtable
<nsDomainEntry
> mHash
;
129 nsCOMPtr
<nsIIDNService
> mIDNService
;