Bug 452390 Tracemonkey will crash if the compiler doesn't have FASTCALL r=danderson
[wine-gecko.git] / security / manager / ssl / src / nsCRLInfo.cpp
blob4d031d928e4b1819f41dcdaa1ca6e6e25883ffc4
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 "prmem.h"
38 #include "prerror.h"
39 #include "prprf.h"
41 #include "nsCRLInfo.h"
42 #include "nsIDateTimeFormat.h"
43 #include "nsDateTimeFormatCID.h"
44 #include "nsCOMPtr.h"
45 #include "nsComponentManagerUtils.h"
46 #include "nsReadableUtils.h"
47 #include "nsNSSShutDown.h"
49 #include "nspr.h"
50 extern "C" {
51 #include "pk11func.h"
52 #include "certdb.h"
53 #include "cert.h"
54 #include "secerr.h"
55 #include "nssb64.h"
56 #include "secasn1.h"
57 #include "secder.h"
60 NS_IMPL_ISUPPORTS1(nsCRLInfo, nsICRLInfo)
62 nsCRLInfo::nsCRLInfo()
64 /* member initializers and constructor code */
67 nsCRLInfo::nsCRLInfo(CERTSignedCrl *signedCrl)
69 nsNSSShutDownPreventionLock locker;
70 CERTCrl *crl = &(signedCrl->crl);
71 nsAutoString org;
72 nsAutoString orgUnit;
73 nsAutoString nameInDb;
74 nsAutoString nextUpdateLocale;
75 nsAutoString lastUpdateLocale;
76 nsCAutoString lastFetchURL;
77 PRTime lastUpdate = 0;
78 PRTime nextUpdate = 0;
79 SECStatus sec_rv;
81 // Get the information we need here //
82 char * o = CERT_GetOrgName(&(crl->name));
83 if (o) {
84 org = NS_ConvertASCIItoUTF16(o);
85 PORT_Free(o);
88 char * ou = CERT_GetOrgUnitName(&(crl->name));
89 if (ou) {
90 orgUnit = NS_ConvertASCIItoUTF16(ou);
91 //At present, the ou is being used as the unique key - but this
92 //would change, one support for delta crls come in.
93 nameInDb = orgUnit;
94 PORT_Free(ou);
97 nsCOMPtr<nsIDateTimeFormat> dateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID);
99 // Last Update time
100 if (crl->lastUpdate.len) {
101 sec_rv = DER_UTCTimeToTime(&lastUpdate, &(crl->lastUpdate));
102 if (sec_rv == SECSuccess && dateFormatter) {
103 dateFormatter->FormatPRTime(nsnull, kDateFormatShort, kTimeFormatNone,
104 lastUpdate, lastUpdateLocale);
108 if (crl->nextUpdate.len) {
109 // Next update time
110 sec_rv = DER_UTCTimeToTime(&nextUpdate, &(crl->nextUpdate));
111 if (sec_rv == SECSuccess && dateFormatter) {
112 dateFormatter->FormatPRTime(nsnull, kDateFormatShort, kTimeFormatNone,
113 nextUpdate, nextUpdateLocale);
117 char * url = signedCrl->url;
118 if(url) {
119 lastFetchURL = url;
122 mOrg.Assign(org.get());
123 mOrgUnit.Assign(orgUnit.get());
124 mLastUpdateLocale.Assign(lastUpdateLocale.get());
125 mNextUpdateLocale.Assign(nextUpdateLocale.get());
126 mLastUpdate = lastUpdate;
127 mNextUpdate = nextUpdate;
128 mNameInDb.Assign(nameInDb.get());
129 mLastFetchURL = lastFetchURL;
132 nsCRLInfo::~nsCRLInfo()
134 /* destructor code */
137 /* readonly attribute */
138 NS_IMETHODIMP nsCRLInfo::GetOrganization(nsAString & aOrg)
140 aOrg = mOrg;
141 return NS_OK;
144 /* readonly attribute */
145 NS_IMETHODIMP nsCRLInfo::GetOrganizationalUnit(nsAString & aOrgUnit)
147 aOrgUnit = mOrgUnit;
148 return NS_OK;
151 NS_IMETHODIMP nsCRLInfo::GetLastUpdateLocale(nsAString & aLastUpdateLocale)
153 aLastUpdateLocale = mLastUpdateLocale;
154 return NS_OK;
157 NS_IMETHODIMP nsCRLInfo::GetNextUpdateLocale(nsAString & aNextUpdateLocale)
159 aNextUpdateLocale = mNextUpdateLocale;
160 return NS_OK;
163 NS_IMETHODIMP nsCRLInfo::GetLastUpdate(PRTime* aLastUpdate)
165 NS_ENSURE_ARG(aLastUpdate);
166 *aLastUpdate = mLastUpdate;
167 return NS_OK;
170 NS_IMETHODIMP nsCRLInfo::GetNextUpdate(PRTime* aNextUpdate)
172 NS_ENSURE_ARG(aNextUpdate);
173 *aNextUpdate = mNextUpdate;
174 return NS_OK;
177 NS_IMETHODIMP nsCRLInfo::GetNameInDb(nsAString & aNameInDb)
179 aNameInDb = mNameInDb;
180 return NS_OK;
183 NS_IMETHODIMP nsCRLInfo::GetLastFetchURL(nsACString & aLastFetchURL)
185 aLastFetchURL = mLastFetchURL;
186 return NS_OK;