modules/libjar/nsIZipReader.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "nsISupports.idl"
michael@0 8
michael@0 9 interface nsIUTF8StringEnumerator;
michael@0 10 interface nsIInputStream;
michael@0 11 interface nsIFile;
michael@0 12 interface nsICertificatePrincipal;
michael@0 13
michael@0 14 [scriptable, uuid(fad6f72f-13d8-4e26-9173-53007a4afe71)]
michael@0 15 interface nsIZipEntry : nsISupports
michael@0 16 {
michael@0 17 /**
michael@0 18 * The type of compression used for the item. The possible values and
michael@0 19 * their meanings are defined in the zip file specification at
michael@0 20 * http://www.pkware.com/business_and_developers/developer/appnote/
michael@0 21 */
michael@0 22 readonly attribute unsigned short compression;
michael@0 23 /**
michael@0 24 * The compressed size of the data in the item.
michael@0 25 */
michael@0 26 readonly attribute unsigned long size;
michael@0 27 /**
michael@0 28 * The uncompressed size of the data in the item.
michael@0 29 */
michael@0 30 readonly attribute unsigned long realSize;
michael@0 31 /**
michael@0 32 * The CRC-32 hash of the file in the entry.
michael@0 33 */
michael@0 34 readonly attribute unsigned long CRC32;
michael@0 35 /**
michael@0 36 * True if the name of the entry ends with '/' and false otherwise.
michael@0 37 */
michael@0 38 readonly attribute boolean isDirectory;
michael@0 39 /**
michael@0 40 * The time at which this item was last modified.
michael@0 41 */
michael@0 42 readonly attribute PRTime lastModifiedTime;
michael@0 43 /**
michael@0 44 * Use this attribute to determine whether this item is an actual zip entry
michael@0 45 * or is one synthesized for part of a real entry's path. A synthesized
michael@0 46 * entry represents a directory within the zip file which has no
michael@0 47 * corresponding entry within the zip file. For example, the entry for the
michael@0 48 * directory foo/ in a zip containing exactly one entry for foo/bar.txt
michael@0 49 * is synthetic. If the zip file contains an actual entry for a directory,
michael@0 50 * this attribute will be false for the nsIZipEntry for that directory.
michael@0 51 * It is impossible for a file to be synthetic.
michael@0 52 */
michael@0 53 readonly attribute boolean isSynthetic;
michael@0 54 /**
michael@0 55 * The UNIX style file permissions of this item.
michael@0 56 */
michael@0 57 readonly attribute unsigned long permissions;
michael@0 58 };
michael@0 59
michael@0 60 [scriptable, uuid(38d6d07a-8a58-4fe7-be8b-ef6472fa83ff)]
michael@0 61 interface nsIZipReader : nsISupports
michael@0 62 {
michael@0 63 /**
michael@0 64 * Opens a zip file for reading.
michael@0 65 * It is allowed to open with another file,
michael@0 66 * but it needs to be closed first with close().
michael@0 67 */
michael@0 68 void open(in nsIFile zipFile);
michael@0 69
michael@0 70 /**
michael@0 71 * Opens a zip file inside a zip file for reading.
michael@0 72 */
michael@0 73 void openInner(in nsIZipReader zipReader, in AUTF8String zipEntry);
michael@0 74
michael@0 75 /**
michael@0 76 * The file that represents the zip with which this zip reader was
michael@0 77 * initialized.
michael@0 78 */
michael@0 79 readonly attribute nsIFile file;
michael@0 80
michael@0 81 /**
michael@0 82 * Closes a zip reader. Subsequent attempts to extract files or read from
michael@0 83 * its input stream will result in an error.
michael@0 84 *
michael@0 85 * Subsequent attempts to access a nsIZipEntry obtained from this zip
michael@0 86 * reader will cause unspecified behavior.
michael@0 87 */
michael@0 88 void close();
michael@0 89
michael@0 90 /**
michael@0 91 * Tests the integrity of the archive by performing a CRC check
michael@0 92 * on each item expanded into memory. If an entry is specified
michael@0 93 * the integrity of only that item is tested. If null (javascript)
michael@0 94 * or EmptyCString() (c++) is passed in the integrity of all items
michael@0 95 * in the archive are tested.
michael@0 96 */
michael@0 97 void test(in AUTF8String aEntryName);
michael@0 98
michael@0 99 /**
michael@0 100 * Extracts a zip entry into a local file specified by outFile.
michael@0 101 * The entry must be stored in the zip in either uncompressed or
michael@0 102 * DEFLATE-compressed format for the extraction to be successful.
michael@0 103 * If the entry is a directory, the directory will be extracted
michael@0 104 * non-recursively.
michael@0 105 */
michael@0 106 void extract(in AUTF8String zipEntry, in nsIFile outFile);
michael@0 107
michael@0 108 /**
michael@0 109 * Returns a nsIZipEntry describing a specified zip entry.
michael@0 110 */
michael@0 111 nsIZipEntry getEntry(in AUTF8String zipEntry);
michael@0 112
michael@0 113 /**
michael@0 114 * Checks whether the zipfile contains an entry specified by entryName.
michael@0 115 */
michael@0 116 boolean hasEntry(in AUTF8String zipEntry);
michael@0 117
michael@0 118 /**
michael@0 119 * Returns a string enumerator containing the matching entry names.
michael@0 120 *
michael@0 121 * @param aPattern
michael@0 122 * A regular expression used to find matching entries in the zip file.
michael@0 123 * Set this parameter to null (javascript) or EmptyCString() (c++) or "*"
michael@0 124 * to get all entries; otherwise, use the
michael@0 125 * following syntax:
michael@0 126 *
michael@0 127 * o * matches anything
michael@0 128 * o ? matches one character
michael@0 129 * o $ matches the end of the string
michael@0 130 * o [abc] matches one occurrence of a, b, or c. The only character that
michael@0 131 * must be escaped inside the brackets is ]. ^ and - must never
michael@0 132 * appear in the first and second positions within the brackets,
michael@0 133 * respectively. (In the former case, the behavior specified for
michael@0 134 * '[^az]' will happen.)
michael@0 135 * o [a-z] matches any character between a and z. The characters a and z
michael@0 136 * must either both be letters or both be numbers, with the
michael@0 137 * character represented by 'a' having a lower ASCII value than
michael@0 138 * the character represented by 'z'.
michael@0 139 * o [^az] matches any character except a or z. If ] is to appear inside
michael@0 140 * the brackets as a character to not match, it must be escaped.
michael@0 141 * o pat~pat2 returns matches to the pattern 'pat' which do not also match
michael@0 142 * the pattern 'pat2'. This may be used to perform filtering
michael@0 143 * upon the results of one pattern to remove all matches which
michael@0 144 * also match another pattern. For example, because '*'
michael@0 145 * matches any string and '*z*' matches any string containing a
michael@0 146 * 'z', '*~*z*' will match all strings except those containing
michael@0 147 * a 'z'. Note that a pattern may not use '~' multiple times,
michael@0 148 * so a string such as '*~*z*~*y*' is not a valid pattern.
michael@0 149 * o (foo|bar) will match either the pattern foo or the pattern bar.
michael@0 150 * Neither of the patterns foo or bar may use the 'pat~pat2'
michael@0 151 * syntax described immediately above.
michael@0 152 * o \ will escape a special character. Escaping is required for all
michael@0 153 * special characters unless otherwise specified.
michael@0 154 * o All other characters match case-sensitively.
michael@0 155 *
michael@0 156 * An aPattern not conforming to this syntax has undefined behavior.
michael@0 157 *
michael@0 158 * @throws NS_ERROR_ILLEGAL_VALUE on many but not all invalid aPattern
michael@0 159 * values.
michael@0 160 */
michael@0 161 nsIUTF8StringEnumerator findEntries(in AUTF8String aPattern);
michael@0 162
michael@0 163 /**
michael@0 164 * Returns an input stream containing the contents of the specified zip
michael@0 165 * entry.
michael@0 166 * @param zipEntry the name of the entry to open the stream from
michael@0 167 */
michael@0 168 nsIInputStream getInputStream(in AUTF8String zipEntry);
michael@0 169
michael@0 170 /**
michael@0 171 * Returns an input stream containing the contents of the specified zip
michael@0 172 * entry. If the entry refers to a directory (ends with '/'), a directory stream
michael@0 173 * is opened, otherwise the contents of the file entry is returned.
michael@0 174 * @param aJarSpec the Spec of the URI for the JAR (only used for directory streams)
michael@0 175 * @param zipEntry the name of the entry to open the stream from
michael@0 176 */
michael@0 177 nsIInputStream getInputStreamWithSpec(in AUTF8String aJarSpec, in AUTF8String zipEntry);
michael@0 178
michael@0 179 /**
michael@0 180 * Returns an object describing the entity which signed
michael@0 181 * an entry. parseManifest must be called first. If aEntryName is an
michael@0 182 * entry in the jar, getInputStream must be called after parseManifest.
michael@0 183 * If aEntryName is an external file which has meta-information
michael@0 184 * stored in the jar, verifyExternalFile (not yet implemented) must
michael@0 185 * be called before getPrincipal.
michael@0 186 */
michael@0 187 nsICertificatePrincipal getCertificatePrincipal(in AUTF8String aEntryName);
michael@0 188
michael@0 189 readonly attribute uint32_t manifestEntriesCount;
michael@0 190 };
michael@0 191
michael@0 192 ////////////////////////////////////////////////////////////////////////////////
michael@0 193 // nsIZipReaderCache
michael@0 194
michael@0 195 [scriptable, uuid(748050ac-3ab6-4472-bc2a-cb1564ac6a81)]
michael@0 196 interface nsIZipReaderCache : nsISupports
michael@0 197 {
michael@0 198 /**
michael@0 199 * Initializes a new zip reader cache.
michael@0 200 * @param cacheSize - the number of released entries to maintain before
michael@0 201 * beginning to throw some out (note that the number of outstanding
michael@0 202 * entries can be much greater than this number -- this is the count
michael@0 203 * for those otherwise unused entries)
michael@0 204 */
michael@0 205 void init(in unsigned long cacheSize);
michael@0 206
michael@0 207 /**
michael@0 208 * Returns a (possibly shared) nsIZipReader for an nsIFile.
michael@0 209 *
michael@0 210 * If the zip reader for given file is not in the cache, a new zip reader
michael@0 211 * is created, initialized, and opened (see nsIZipReader::init and
michael@0 212 * nsIZipReader::open). Otherwise the previously created zip reader is
michael@0 213 * returned.
michael@0 214 *
michael@0 215 * @note If someone called close() on the shared nsIZipReader, this method
michael@0 216 * will return the closed zip reader.
michael@0 217 */
michael@0 218 nsIZipReader getZip(in nsIFile zipFile);
michael@0 219
michael@0 220 /**
michael@0 221 * returns true if this zipreader already has this file cached
michael@0 222 */
michael@0 223 bool isCached(in nsIFile zipFile);
michael@0 224
michael@0 225 /**
michael@0 226 * Returns a (possibly shared) nsIZipReader for a zip inside another zip
michael@0 227 *
michael@0 228 * See getZip
michael@0 229 */
michael@0 230 nsIZipReader getInnerZip(in nsIFile zipFile, in AUTF8String zipEntry);
michael@0 231 };
michael@0 232
michael@0 233 ////////////////////////////////////////////////////////////////////////////////
michael@0 234
michael@0 235 %{C++
michael@0 236
michael@0 237 #define NS_ZIPREADER_CID \
michael@0 238 { /* 88e2fd0b-f7f4-480c-9483-7846b00e8dad */ \
michael@0 239 0x88e2fd0b, 0xf7f4, 0x480c, \
michael@0 240 { 0x94, 0x83, 0x78, 0x46, 0xb0, 0x0e, 0x8d, 0xad } \
michael@0 241 }
michael@0 242
michael@0 243 #define NS_ZIPREADERCACHE_CID \
michael@0 244 { /* 608b7f6f-4b60-40d6-87ed-d933bf53d8c1 */ \
michael@0 245 0x608b7f6f, 0x4b60, 0x40d6, \
michael@0 246 { 0x87, 0xed, 0xd9, 0x33, 0xbf, 0x53, 0xd8, 0xc1 } \
michael@0 247 }
michael@0 248
michael@0 249 %}
michael@0 250
michael@0 251 ////////////////////////////////////////////////////////////////////////////////

mercurial