Bug 574454 - Remove widget level disabling code for chrome margins on non-aero deksto...
[mozilla-central.git] / modules / libjar / nsJAR.h
blob38fb589cb1ecf37dd3ef7f848cd71f9eb7ac6c1f
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-2000
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Don Bragg <dbragg@netscape.com>
25 * Samir Gehani <sgehani@netscape.com>
26 * Mitch Stoltz <mstoltz@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
43 #ifndef nsJAR_h__
44 #define nsJAR_h__
46 #include "nscore.h"
47 #include "pratom.h"
48 #include "prmem.h"
49 #include "prio.h"
50 #include "plstr.h"
51 #include "prlog.h"
52 #include "prtypes.h"
53 #include "prinrval.h"
55 #include "nsIComponentManager.h"
56 #include "nsCOMPtr.h"
57 #include "nsString.h"
58 #include "nsIFile.h"
59 #include "nsStringEnumerator.h"
60 #include "nsHashtable.h"
61 #include "nsAutoLock.h"
62 #include "nsIZipReader.h"
63 #include "nsZipArchive.h"
64 #include "nsIPrincipal.h"
65 #include "nsISignatureVerifier.h"
66 #include "nsIObserverService.h"
67 #include "nsWeakReference.h"
68 #include "nsIObserver.h"
70 class nsIInputStream;
71 class nsJARManifestItem;
72 class nsZipReaderCache;
74 /* For mManifestStatus */
75 typedef enum
77 JAR_MANIFEST_NOT_PARSED = 0,
78 JAR_VALID_MANIFEST = 1,
79 JAR_INVALID_SIG = 2,
80 JAR_INVALID_UNKNOWN_CA = 3,
81 JAR_INVALID_MANIFEST = 4,
82 JAR_INVALID_ENTRY = 5,
83 JAR_NO_MANIFEST = 6,
84 JAR_NOT_SIGNED = 7
85 } JARManifestStatusType;
87 /*-------------------------------------------------------------------------
88 * Class nsJAR declaration.
89 * nsJAR serves as an XPCOM wrapper for nsZipArchive with the addition of
90 * JAR manifest file parsing.
91 *------------------------------------------------------------------------*/
92 class nsJAR : public nsIZipReader
94 // Allows nsJARInputStream to call the verification functions
95 friend class nsJARInputStream;
97 public:
99 nsJAR();
100 virtual ~nsJAR();
102 NS_DEFINE_STATIC_CID_ACCESSOR( NS_ZIPREADER_CID )
104 NS_DECL_ISUPPORTS
106 NS_DECL_NSIZIPREADER
108 nsresult GetJarPath(nsACString& aResult);
110 PRIntervalTime GetReleaseTime() {
111 return mReleaseTime;
114 PRBool IsReleased() {
115 return mReleaseTime != PR_INTERVAL_NO_TIMEOUT;
118 void SetReleaseTime() {
119 mReleaseTime = PR_IntervalNow();
122 void ClearReleaseTime() {
123 mReleaseTime = PR_INTERVAL_NO_TIMEOUT;
126 void SetZipReaderCache(nsZipReaderCache* cache) {
127 mCache = cache;
130 protected:
131 //-- Private data members
132 nsCOMPtr<nsIFile> mZipFile; // The zip/jar file on disk
133 nsZipArchive mZip; // The underlying zip archive
134 nsObjectHashtable mManifestData; // Stores metadata for each entry
135 PRBool mParsedManifest; // True if manifest has been parsed
136 nsCOMPtr<nsIPrincipal> mPrincipal; // The entity which signed this file
137 PRInt16 mGlobalStatus; // Global signature verification status
138 PRIntervalTime mReleaseTime; // used by nsZipReaderCache for flushing entries
139 nsZipReaderCache* mCache; // if cached, this points to the cache it's contained in
140 PRLock* mLock;
141 PRInt64 mMtime;
142 PRInt32 mTotalItemsInManifest;
144 nsresult ParseManifest();
145 void ReportError(const char* aFilename, PRInt16 errorCode);
146 nsresult LoadEntry(const char* aFilename, char** aBuf,
147 PRUint32* aBufLen = nsnull);
148 PRInt32 ReadLine(const char** src);
149 nsresult ParseOneFile(const char* filebuf, PRInt16 aFileType);
150 nsresult VerifyEntry(nsJARManifestItem* aEntry, const char* aEntryData,
151 PRUint32 aLen);
153 nsresult CalculateDigest(const char* aInBuf, PRUint32 aInBufLen,
154 nsCString& digest);
156 //-- Debugging
157 void DumpMetadata(const char* aMessage);
161 * nsJARItem
163 * An individual JAR entry. A set of nsJARItems macthing a
164 * supplied pattern are returned in a nsJAREnumerator.
166 class nsJARItem : public nsIZipEntry
168 public:
169 NS_DECL_ISUPPORTS
170 NS_DECL_NSIZIPENTRY
172 nsJARItem(nsZipItem* aZipItem);
173 virtual ~nsJARItem() {}
175 private:
176 PRUint32 mSize; /* size in original file */
177 PRUint32 mRealsize; /* inflated size */
178 PRUint32 mCrc32;
179 PRTime mLastModTime;
180 PRUint16 mCompression;
181 PRPackedBool mIsDirectory;
182 PRPackedBool mIsSynthetic;
186 * nsJAREnumerator
188 * Enumerates a list of files in a zip archive
189 * (based on a pattern match in its member nsZipFind).
191 class nsJAREnumerator : public nsIUTF8StringEnumerator
193 public:
194 NS_DECL_ISUPPORTS
195 NS_DECL_NSIUTF8STRINGENUMERATOR
197 nsJAREnumerator(nsZipFind *aFind) : mFind(aFind), mName(nsnull) {
198 NS_ASSERTION(mFind, "nsJAREnumerator: Missing zipFind.");
201 private:
202 nsZipFind *mFind;
203 const char* mName; // pointer to an name owned by mArchive -- DON'T delete
204 PRUint16 mNameLen;
206 ~nsJAREnumerator() { delete mFind; }
209 ////////////////////////////////////////////////////////////////////////////////
211 #if defined(DEBUG_warren) || defined(DEBUG_jband)
212 #define ZIP_CACHE_HIT_RATE
213 #endif
215 class nsZipReaderCache : public nsIZipReaderCache, public nsIObserver,
216 public nsSupportsWeakReference
218 public:
219 NS_DECL_ISUPPORTS
220 NS_DECL_NSIZIPREADERCACHE
221 NS_DECL_NSIOBSERVER
223 nsZipReaderCache();
224 virtual ~nsZipReaderCache();
226 nsresult ReleaseZip(nsJAR* reader);
228 protected:
229 PRLock* mLock;
230 PRInt32 mCacheSize;
231 nsSupportsHashtable mZips;
233 #ifdef ZIP_CACHE_HIT_RATE
234 PRUint32 mZipCacheLookups;
235 PRUint32 mZipCacheHits;
236 PRUint32 mZipCacheFlushes;
237 PRUint32 mZipSyncMisses;
238 #endif
242 ////////////////////////////////////////////////////////////////////////////////
244 #endif /* nsJAR_h__ */