Bug 452390 Tracemonkey will crash if the compiler doesn't have FASTCALL r=danderson
[wine-gecko.git] / security / manager / ssl / src / nsNSSCertCache.cpp
blobcd8888d6860df2684251a99a0d288eda1870d75a
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):
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"
40 #include "cert.h"
41 #include "nsCOMPtr.h"
42 #include "nsIInterfaceRequestor.h"
43 #include "nsNSSHelper.h"
45 NS_IMPL_THREADSAFE_ISUPPORTS1(nsNSSCertCache, nsINSSCertCache)
47 nsNSSCertCache::nsNSSCertCache()
48 :mCertList(nsnull)
50 mutex = PR_NewLock();
53 nsNSSCertCache::~nsNSSCertCache()
55 nsNSSShutDownPreventionLock locker;
56 if (isAlreadyShutDown())
57 return;
59 destructorSafeDestroyNSSReference();
60 shutdown(calledFromObject);
63 void nsNSSCertCache::virtualDestroyNSSReference()
65 destructorSafeDestroyNSSReference();
68 void nsNSSCertCache::destructorSafeDestroyNSSReference()
70 if (isAlreadyShutDown())
71 return;
73 if (mutex) {
74 PR_DestroyLock(mutex);
75 mutex = nsnull;
79 NS_IMETHODIMP
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);
90 if (newList) {
91 nsAutoLock lock(mutex);
92 mCertList = new nsNSSCertList(newList, PR_TRUE); // adopt
95 return NS_OK;
98 NS_IMETHODIMP
99 nsNSSCertCache::CacheCertList(nsIX509CertList *list)
101 nsNSSShutDownPreventionLock locker;
102 if (isAlreadyShutDown())
103 return NS_ERROR_NOT_AVAILABLE;
106 nsAutoLock lock(mutex);
107 mCertList = list;
108 //NS_ADDREF(mCertList);
111 return NS_OK;
114 NS_IMETHODIMP
115 nsNSSCertCache::GetX509CachedCerts(nsIX509CertList **list)
117 nsNSSShutDownPreventionLock locker;
118 if (isAlreadyShutDown())
119 return NS_ERROR_NOT_AVAILABLE;
122 nsAutoLock lock(mutex);
123 if (!mCertList) {
124 return NS_ERROR_NOT_AVAILABLE;
126 *list = mCertList;
127 NS_ADDREF(*list);
130 return NS_OK;
135 void* nsNSSCertCache::GetCachedCerts()
137 if (isAlreadyShutDown())
138 return nsnull;
140 nsAutoLock lock(mutex);
141 return mCertList->GetRawCertList();