Back to index

lightning-sunbird  0.9+nobinonly
nsCertTree.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Ian McGreer <mcgreer@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef _NS_CERTTREE_H_
00039 #define _NS_CERTTREE_H_
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsIServiceManager.h"
00043 #include "nsICertTree.h"
00044 #include "nsITreeView.h"
00045 #include "nsITreeBoxObject.h"
00046 #include "nsITreeSelection.h"
00047 #include "nsISupportsArray.h"
00048 #include "pldhash.h"
00049 #include "nsIX509CertDB.h"
00050 
00051 typedef struct treeArrayElStr treeArrayEl;
00052 
00053 struct CompareCacheHashEntry {
00054   enum { max_criterions = 3 };
00055   CompareCacheHashEntry();
00056 
00057   void *key; // no ownership
00058   PRPackedBool mCritInit[max_criterions];
00059   nsXPIDLString mCrit[max_criterions];
00060 };
00061 
00062 struct CompareCacheHashEntryPtr : PLDHashEntryHdr {
00063   CompareCacheHashEntryPtr();
00064   ~CompareCacheHashEntryPtr();
00065   CompareCacheHashEntry *entry;
00066 };
00067 
00068 
00069 class nsCertTree : public nsICertTree
00070 {
00071 public:
00072   NS_DECL_ISUPPORTS
00073   NS_DECL_NSICERTTREE
00074   NS_DECL_NSITREEVIEW
00075 
00076   nsCertTree();
00077   virtual ~nsCertTree();
00078 
00079   enum sortCriterion { sort_IssuerOrg, sort_Org, sort_Token, 
00080     sort_CommonName, sort_IssuedDateDescending, sort_Email, sort_None };
00081 
00082 protected:
00083   nsresult InitCompareHash();
00084   void ClearCompareHash();
00085   void RemoveCacheEntry(void *key);
00086 
00087   typedef int (*nsCertCompareFunc)(void *, nsIX509Cert *a, nsIX509Cert *b);
00088 
00089   static CompareCacheHashEntry *getCacheEntry(void *cache, void *aCert);
00090   static void CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry,
00091                                sortCriterion crit, PRInt32 level);
00092   static PRInt32 CmpByCrit(nsIX509Cert *a, CompareCacheHashEntry *ace, 
00093                            nsIX509Cert *b, CompareCacheHashEntry *bce, 
00094                            sortCriterion crit, PRInt32 level);
00095   static PRInt32 CmpBy(void *cache, nsIX509Cert *a, nsIX509Cert *b, 
00096                        sortCriterion c0, sortCriterion c1, sortCriterion c2);
00097   static PRInt32 CmpCACert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
00098   static PRInt32 CmpWebSiteCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
00099   static PRInt32 CmpUserCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
00100   static PRInt32 CmpEmailCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
00101   nsCertCompareFunc GetCompareFuncFromCertType(PRUint32 aType);
00102   PRInt32 CountOrganizations();
00103 
00104   PRBool GetCertsByType(PRUint32 aType, nsCertCompareFunc aCertCmpFn,
00105                         void *aCertCmpFnArg, nsISupportsArray **_certs);
00106 
00107   PRBool GetCertsByTypeFromCache(nsINSSCertCache *aCache, PRUint32 aType,
00108                                  nsCertCompareFunc aCertCmpFn, void *aCertCmpFnArg,
00109                                  nsISupportsArray **_certs);
00110 private:
00111   nsCOMPtr<nsISupportsArray>      mCertArray;
00112   nsCOMPtr<nsITreeBoxObject>  mTree;
00113   nsCOMPtr<nsITreeSelection>  mSelection;
00114   treeArrayEl                *mTreeArray;
00115   PRInt32                         mNumOrgs;
00116   PRInt32                         mNumRows;
00117   PLDHashTable mCompareCache;
00118   nsCOMPtr<nsINSSComponent> mNSSComponent;
00119 
00120   treeArrayEl *GetThreadDescAtIndex(PRInt32 _index);
00121   nsIX509Cert *GetCertAtIndex(PRInt32 _index);
00122 
00123   void FreeCertArray();
00124   nsresult UpdateUIContents();
00125 
00126   PRBool GetCertsByTypeFromCertList(CERTCertList *aCertList,
00127                                     PRUint32 aType,
00128                                     nsCertCompareFunc  aCertCmpFn,
00129                                     void              *aCertCmpFnArg,
00130                                     nsISupportsArray **_certs);
00131 
00132 #ifdef DEBUG_CERT_TREE
00133   /* for debugging purposes */
00134   void dumpMap();
00135 #endif
00136 };
00137 
00138 #endif /* _NS_CERTTREE_H_ */
00139