/src/mozilla-central/modules/libjar/zipwriter/nsZipHeader.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
4 | | */ |
5 | | |
6 | | #ifndef _nsZipHeader_h_ |
7 | | #define _nsZipHeader_h_ |
8 | | |
9 | | #include "nsString.h" |
10 | | #include "nsIOutputStream.h" |
11 | | #include "nsIInputStream.h" |
12 | | #include "nsIZipReader.h" |
13 | | #include "mozilla/Attributes.h" |
14 | | #include "mozilla/UniquePtr.h" |
15 | | |
16 | | // High word is S_IFREG, low word is DOS file attribute |
17 | | #define ZIP_ATTRS_FILE 0x80000000 |
18 | | // High word is S_IFDIR, low word is DOS dir attribute |
19 | | #define ZIP_ATTRS_DIRECTORY 0x40000010 |
20 | 0 | #define PERMISSIONS_FILE 0644 |
21 | 0 | #define PERMISSIONS_DIR 0755 |
22 | | |
23 | | // Combine file type attributes with unix style permissions |
24 | 0 | #define ZIP_ATTRS(p, a) ((p & 0xfff) << 16) | a |
25 | | |
26 | | class nsZipHeader final : public nsIZipEntry |
27 | | { |
28 | | ~nsZipHeader() |
29 | 0 | { |
30 | 0 | mExtraField = nullptr; |
31 | 0 | mLocalExtraField = nullptr; |
32 | 0 | } |
33 | | |
34 | | public: |
35 | | NS_DECL_ISUPPORTS |
36 | | NS_DECL_NSIZIPENTRY |
37 | | |
38 | | nsZipHeader() : |
39 | | mCRC(0), |
40 | | mCSize(0), |
41 | | mUSize(0), |
42 | | mEAttr(0), |
43 | | mOffset(0), |
44 | | mFieldLength(0), |
45 | | mLocalFieldLength(0), |
46 | | mVersionMade(0x0300 + 23), // Generated on Unix by v2.3 (matches infozip) |
47 | | mVersionNeeded(20), // Requires v2.0 to extract |
48 | | mFlags(0), |
49 | | mMethod(0), |
50 | | mTime(0), |
51 | | mDate(0), |
52 | | mDisk(0), |
53 | | mIAttr(0), |
54 | | mInited(false), |
55 | | mWriteOnClose(false), |
56 | | mExtraField(nullptr), |
57 | | mLocalExtraField(nullptr) |
58 | 0 | { |
59 | 0 | } |
60 | | |
61 | | uint32_t mCRC; |
62 | | uint32_t mCSize; |
63 | | uint32_t mUSize; |
64 | | uint32_t mEAttr; |
65 | | uint32_t mOffset; |
66 | | uint32_t mFieldLength; |
67 | | uint32_t mLocalFieldLength; |
68 | | uint16_t mVersionMade; |
69 | | uint16_t mVersionNeeded; |
70 | | uint16_t mFlags; |
71 | | uint16_t mMethod; |
72 | | uint16_t mTime; |
73 | | uint16_t mDate; |
74 | | uint16_t mDisk; |
75 | | uint16_t mIAttr; |
76 | | bool mInited; |
77 | | bool mWriteOnClose; |
78 | | nsCString mName; |
79 | | nsCString mComment; |
80 | | mozilla::UniquePtr<uint8_t[]> mExtraField; |
81 | | mozilla::UniquePtr<uint8_t[]> mLocalExtraField; |
82 | | |
83 | | void Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr, |
84 | | uint32_t aOffset); |
85 | | uint32_t GetFileHeaderLength(); |
86 | | nsresult WriteFileHeader(nsIOutputStream *aStream); |
87 | | uint32_t GetCDSHeaderLength(); |
88 | | nsresult WriteCDSHeader(nsIOutputStream *aStream); |
89 | | nsresult ReadCDSHeader(nsIInputStream *aStream); |
90 | | const uint8_t * GetExtraField(uint16_t aTag, bool aLocal, uint16_t *aBlockSize); |
91 | | nsresult PadExtraField(uint32_t aOffset, uint16_t aAlignSize); |
92 | | }; |
93 | | |
94 | | #endif |