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.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #include "nsNSSCertCache.h"
38 #include "nsNSSCertificate.h"
39 #include "nsAutoLock.h"
42 #include "nsIInterfaceRequestor.h"
43 #include "nsNSSHelper.h"
45 NS_IMPL_THREADSAFE_ISUPPORTS1(nsNSSCertCache
, nsINSSCertCache
)
47 nsNSSCertCache::nsNSSCertCache()
53 nsNSSCertCache::~nsNSSCertCache()
55 nsNSSShutDownPreventionLock locker
;
56 if (isAlreadyShutDown())
59 destructorSafeDestroyNSSReference();
60 shutdown(calledFromObject
);
63 void nsNSSCertCache::virtualDestroyNSSReference()
65 destructorSafeDestroyNSSReference();
68 void nsNSSCertCache::destructorSafeDestroyNSSReference()
70 if (isAlreadyShutDown())
74 PR_DestroyLock(mutex
);
80 nsNSSCertCache::CacheAllCerts()
82 nsNSSShutDownPreventionLock locker
;
83 if (isAlreadyShutDown())
84 return NS_ERROR_NOT_AVAILABLE
;
86 nsCOMPtr
<nsIInterfaceRequestor
> cxt
= new PipUIContext();
88 CERTCertList
*newList
= PK11_ListCerts(PK11CertListUnique
, cxt
);
91 nsAutoLock
lock(mutex
);
92 mCertList
= new nsNSSCertList(newList
, PR_TRUE
); // adopt
99 nsNSSCertCache::CacheCertList(nsIX509CertList
*list
)
101 nsNSSShutDownPreventionLock locker
;
102 if (isAlreadyShutDown())
103 return NS_ERROR_NOT_AVAILABLE
;
106 nsAutoLock
lock(mutex
);
108 //NS_ADDREF(mCertList);
115 nsNSSCertCache::GetX509CachedCerts(nsIX509CertList
**list
)
117 nsNSSShutDownPreventionLock locker
;
118 if (isAlreadyShutDown())
119 return NS_ERROR_NOT_AVAILABLE
;
122 nsAutoLock
lock(mutex
);
124 return NS_ERROR_NOT_AVAILABLE
;
135 void* nsNSSCertCache::GetCachedCerts()
137 if (isAlreadyShutDown())
140 nsAutoLock
lock(mutex
);
141 return mCertList
->GetRawCertList();