/src/mozilla-central/security/manager/ssl/nsCertTree.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #ifndef _NS_CERTTREE_H_ |
6 | | #define _NS_CERTTREE_H_ |
7 | | |
8 | | #include "nsCOMPtr.h" |
9 | | #include "nsIServiceManager.h" |
10 | | #include "nsICertTree.h" |
11 | | #include "nsITreeView.h" |
12 | | #include "nsITreeBoxObject.h" |
13 | | #include "nsITreeSelection.h" |
14 | | #include "nsIMutableArray.h" |
15 | | #include "nsNSSComponent.h" |
16 | | #include "nsTArray.h" |
17 | | #include "PLDHashTable.h" |
18 | | #include "nsIX509CertDB.h" |
19 | | #include "nsCertOverrideService.h" |
20 | | #include "mozilla/Attributes.h" |
21 | | |
22 | | typedef struct treeArrayElStr treeArrayEl; |
23 | | |
24 | | struct CompareCacheHashEntry { |
25 | | enum { max_criterions = 3 }; |
26 | | CompareCacheHashEntry(); |
27 | | |
28 | | void *key; // no ownership |
29 | | bool mCritInit[max_criterions]; |
30 | | nsString mCrit[max_criterions]; |
31 | | }; |
32 | | |
33 | | struct CompareCacheHashEntryPtr : PLDHashEntryHdr { |
34 | | CompareCacheHashEntryPtr(); |
35 | | ~CompareCacheHashEntryPtr(); |
36 | | CompareCacheHashEntry *entry; |
37 | | }; |
38 | | |
39 | | class nsCertAddonInfo final : public nsISupports |
40 | | { |
41 | | private: |
42 | 0 | ~nsCertAddonInfo() {} |
43 | | |
44 | | public: |
45 | | NS_DECL_ISUPPORTS |
46 | | |
47 | 0 | nsCertAddonInfo() : mUsageCount(0) {} |
48 | | |
49 | | RefPtr<nsIX509Cert> mCert; |
50 | | // how many display entries reference this? |
51 | | // (and therefore depend on the underlying cert) |
52 | | int32_t mUsageCount; |
53 | | }; |
54 | | |
55 | | class nsCertTreeDispInfo : public nsICertTreeItem |
56 | | { |
57 | | protected: |
58 | | virtual ~nsCertTreeDispInfo(); |
59 | | |
60 | | public: |
61 | | NS_DECL_ISUPPORTS |
62 | | NS_DECL_NSICERTTREEITEM |
63 | | |
64 | | nsCertTreeDispInfo(); |
65 | | nsCertTreeDispInfo(nsCertTreeDispInfo &other); |
66 | | |
67 | | RefPtr<nsCertAddonInfo> mAddonInfo; |
68 | | enum { |
69 | | direct_db, host_port_override |
70 | | } mTypeOfEntry; |
71 | | nsCString mAsciiHost; |
72 | | int32_t mPort; |
73 | | nsCertOverride::OverrideBits mOverrideBits; |
74 | | bool mIsTemporary; |
75 | | nsCOMPtr<nsIX509Cert> mCert; |
76 | | }; |
77 | | |
78 | | class nsCertTree : public nsICertTree |
79 | | { |
80 | | public: |
81 | | NS_DECL_ISUPPORTS |
82 | | NS_DECL_NSICERTTREE |
83 | | NS_DECL_NSITREEVIEW |
84 | | |
85 | | nsCertTree(); |
86 | | |
87 | | enum sortCriterion { sort_IssuerOrg, sort_Org, sort_Token, |
88 | | sort_CommonName, sort_IssuedDateDescending, sort_Email, sort_None }; |
89 | | |
90 | | protected: |
91 | | virtual ~nsCertTree(); |
92 | | |
93 | | void ClearCompareHash(); |
94 | | void RemoveCacheEntry(void *key); |
95 | | |
96 | | typedef int (*nsCertCompareFunc)(void *, nsIX509Cert *a, nsIX509Cert *b); |
97 | | |
98 | | static CompareCacheHashEntry *getCacheEntry(void *cache, void *aCert); |
99 | | static void CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry, |
100 | | sortCriterion crit, int32_t level); |
101 | | static int32_t CmpByCrit(nsIX509Cert *a, CompareCacheHashEntry *ace, |
102 | | nsIX509Cert *b, CompareCacheHashEntry *bce, |
103 | | sortCriterion crit, int32_t level); |
104 | | static int32_t CmpBy(void *cache, nsIX509Cert *a, nsIX509Cert *b, |
105 | | sortCriterion c0, sortCriterion c1, sortCriterion c2); |
106 | | static int32_t CmpCACert(void *cache, nsIX509Cert *a, nsIX509Cert *b); |
107 | | static int32_t CmpWebSiteCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); |
108 | | static int32_t CmpUserCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); |
109 | | static int32_t CmpEmailCert(void *cache, nsIX509Cert *a, nsIX509Cert *b); |
110 | | nsCertCompareFunc GetCompareFuncFromCertType(uint32_t aType); |
111 | | int32_t CountOrganizations(); |
112 | | |
113 | | private: |
114 | | static const uint32_t kInitialCacheLength = 64; |
115 | | |
116 | | nsTArray< RefPtr<nsCertTreeDispInfo> > mDispInfo; |
117 | | nsCOMPtr<nsITreeBoxObject> mTree; |
118 | | nsCOMPtr<nsITreeSelection> mSelection; |
119 | | treeArrayEl *mTreeArray; |
120 | | int32_t mNumOrgs; |
121 | | int32_t mNumRows; |
122 | | PLDHashTable mCompareCache; |
123 | | nsCOMPtr<nsICertOverrideService> mOverrideService; |
124 | | RefPtr<nsCertOverrideService> mOriginalOverrideService; |
125 | | |
126 | | treeArrayEl *GetThreadDescAtIndex(int32_t _index); |
127 | | already_AddRefed<nsIX509Cert> |
128 | | GetCertAtIndex(int32_t _index, int32_t *outAbsoluteCertOffset = nullptr); |
129 | | already_AddRefed<nsCertTreeDispInfo> |
130 | | GetDispInfoAtIndex(int32_t index, int32_t *outAbsoluteCertOffset = nullptr); |
131 | | void FreeCertArray(); |
132 | | nsresult UpdateUIContents(); |
133 | | |
134 | | nsresult GetCertsByTypeFromCertList(nsIX509CertList* aCertList, |
135 | | uint32_t aType, |
136 | | nsCertCompareFunc aCertCmpFn, |
137 | | void *aCertCmpFnArg); |
138 | | |
139 | | nsCOMPtr<nsIMutableArray> mCellText; |
140 | | |
141 | | #ifdef DEBUG_CERT_TREE |
142 | | /* for debugging purposes */ |
143 | | void dumpMap(); |
144 | | #endif |
145 | | }; |
146 | | |
147 | | #endif /* _NS_CERTTREE_H_ */ |
148 | | |