Bug 452390 Tracemonkey will crash if the compiler doesn't have FASTCALL r=danderson
[wine-gecko.git] / security / manager / ssl / src / nsCertTree.h
blobd2fe5774aab4d357c4bc7f6b8273f37bdd82d7f4
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Ian McGreer <mcgreer@netscape.com>
23 * Kai Engert <kengert@redhat.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef _NS_CERTTREE_H_
40 #define _NS_CERTTREE_H_
42 #include "nsCOMPtr.h"
43 #include "nsAutoPtr.h"
44 #include "nsIServiceManager.h"
45 #include "nsICertTree.h"
46 #include "nsITreeView.h"
47 #include "nsITreeBoxObject.h"
48 #include "nsITreeSelection.h"
49 #include "nsISupportsArray.h"
50 #include "nsIMutableArray.h"
51 #include "nsTArray.h"
52 #include "pldhash.h"
53 #include "nsIX509CertDB.h"
54 #include "nsCertOverrideService.h"
57 typedef struct treeArrayElStr treeArrayEl;
59 struct CompareCacheHashEntry {
60 enum { max_criterions = 3 };
61 CompareCacheHashEntry();
63 void *key; // no ownership
64 PRPackedBool mCritInit[max_criterions];
65 nsXPIDLString mCrit[max_criterions];
68 struct CompareCacheHashEntryPtr : PLDHashEntryHdr {
69 CompareCacheHashEntryPtr();
70 ~CompareCacheHashEntryPtr();
71 CompareCacheHashEntry *entry;
74 class nsCertAddonInfo : public nsISupports
76 public:
77 NS_DECL_ISUPPORTS
79 nsCertAddonInfo() : mUsageCount(0) {}
81 nsRefPtr<nsIX509Cert> mCert;
82 // how many display entries reference this?
83 // (and therefore depend on the underlying cert)
84 PRInt32 mUsageCount;
87 class nsCertTreeDispInfo : public nsICertTreeItem
89 public:
90 NS_DECL_ISUPPORTS
91 NS_DECL_NSICERTTREEITEM
93 nsCertTreeDispInfo();
94 nsCertTreeDispInfo(nsCertTreeDispInfo &other);
95 virtual ~nsCertTreeDispInfo();
97 nsRefPtr<nsCertAddonInfo> mAddonInfo;
98 enum {
99 direct_db, host_port_override
100 } mTypeOfEntry;
101 nsCString mAsciiHost;
102 PRInt32 mPort;
103 nsCertOverride::OverrideBits mOverrideBits;
104 PRBool mIsTemporary;
105 nsCOMPtr<nsIX509Cert> mCert;
108 class nsCertTree : public nsICertTree
110 public:
111 NS_DECL_ISUPPORTS
112 NS_DECL_NSICERTTREE
113 NS_DECL_NSITREEVIEW
115 nsCertTree();
116 virtual ~nsCertTree();
118 enum sortCriterion { sort_IssuerOrg, sort_Org, sort_Token,
119 sort_CommonName, sort_IssuedDateDescending, sort_Email, sort_None };
121 protected:
122 nsresult InitCompareHash();
123 void ClearCompareHash();
124 void RemoveCacheEntry(void *key);
126 typedef int (*nsCertCompareFunc)(void *, nsIX509Cert *a, nsIX509Cert *b);
128 static CompareCacheHashEntry *getCacheEntry(void *cache, void *aCert);
129 static void CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry,
130 sortCriterion crit, PRInt32 level);
131 static PRInt32 CmpByCrit(nsIX509Cert *a, CompareCacheHashEntry *ace,
132 nsIX509Cert *b, CompareCacheHashEntry *bce,
133 sortCriterion crit, PRInt32 level);
134 static PRInt32 CmpBy(void *cache, nsIX509Cert *a, nsIX509Cert *b,
135 sortCriterion c0, sortCriterion c1, sortCriterion c2);
136 static PRInt32 CmpCACert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
137 static PRInt32 CmpWebSiteCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
138 static PRInt32 CmpUserCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
139 static PRInt32 CmpEmailCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
140 nsCertCompareFunc GetCompareFuncFromCertType(PRUint32 aType);
141 PRInt32 CountOrganizations();
143 nsresult GetCertsByType(PRUint32 aType, nsCertCompareFunc aCertCmpFn,
144 void *aCertCmpFnArg);
146 nsresult GetCertsByTypeFromCache(nsINSSCertCache *aCache, PRUint32 aType,
147 nsCertCompareFunc aCertCmpFn, void *aCertCmpFnArg);
148 private:
149 nsTArray< nsRefPtr<nsCertTreeDispInfo> > mDispInfo;
150 nsCOMPtr<nsITreeBoxObject> mTree;
151 nsCOMPtr<nsITreeSelection> mSelection;
152 treeArrayEl *mTreeArray;
153 PRInt32 mNumOrgs;
154 PRInt32 mNumRows;
155 PLDHashTable mCompareCache;
156 nsCOMPtr<nsINSSComponent> mNSSComponent;
157 nsCOMPtr<nsICertOverrideService> mOverrideService;
159 treeArrayEl *GetThreadDescAtIndex(PRInt32 _index);
160 already_AddRefed<nsIX509Cert>
161 GetCertAtIndex(PRInt32 _index, PRInt32 *outAbsoluteCertOffset = nsnull);
162 already_AddRefed<nsCertTreeDispInfo>
163 GetDispInfoAtIndex(PRInt32 index, PRInt32 *outAbsoluteCertOffset = nsnull);
164 void FreeCertArray();
165 nsresult UpdateUIContents();
167 nsresult GetCertsByTypeFromCertList(CERTCertList *aCertList,
168 PRUint32 aType,
169 nsCertCompareFunc aCertCmpFn,
170 void *aCertCmpFnArg);
172 nsCOMPtr<nsIMutableArray> mCellText;
174 #ifdef DEBUG_CERT_TREE
175 /* for debugging purposes */
176 void dumpMap();
177 #endif
180 #endif /* _NS_CERTTREE_H_ */