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
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.
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_
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"
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
79 nsCertAddonInfo() : mUsageCount(0) {}
81 nsRefPtr
<nsIX509Cert
> mCert
;
82 // how many display entries reference this?
83 // (and therefore depend on the underlying cert)
87 class nsCertTreeDispInfo
: public nsICertTreeItem
91 NS_DECL_NSICERTTREEITEM
94 nsCertTreeDispInfo(nsCertTreeDispInfo
&other
);
95 virtual ~nsCertTreeDispInfo();
97 nsRefPtr
<nsCertAddonInfo
> mAddonInfo
;
99 direct_db
, host_port_override
101 nsCString mAsciiHost
;
103 nsCertOverride::OverrideBits mOverrideBits
;
105 nsCOMPtr
<nsIX509Cert
> mCert
;
108 class nsCertTree
: public nsICertTree
116 virtual ~nsCertTree();
118 enum sortCriterion
{ sort_IssuerOrg
, sort_Org
, sort_Token
,
119 sort_CommonName
, sort_IssuedDateDescending
, sort_Email
, sort_None
};
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
);
149 nsTArray
< nsRefPtr
<nsCertTreeDispInfo
> > mDispInfo
;
150 nsCOMPtr
<nsITreeBoxObject
> mTree
;
151 nsCOMPtr
<nsITreeSelection
> mSelection
;
152 treeArrayEl
*mTreeArray
;
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
,
169 nsCertCompareFunc aCertCmpFn
,
170 void *aCertCmpFnArg
);
172 nsCOMPtr
<nsIMutableArray
> mCellText
;
174 #ifdef DEBUG_CERT_TREE
175 /* for debugging purposes */
180 #endif /* _NS_CERTTREE_H_ */