michael@0: /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: interface nsIUTF8StringEnumerator; michael@0: interface nsIInputStream; michael@0: interface nsIFile; michael@0: interface nsICertificatePrincipal; michael@0: michael@0: [scriptable, uuid(fad6f72f-13d8-4e26-9173-53007a4afe71)] michael@0: interface nsIZipEntry : nsISupports michael@0: { michael@0: /** michael@0: * The type of compression used for the item. The possible values and michael@0: * their meanings are defined in the zip file specification at michael@0: * http://www.pkware.com/business_and_developers/developer/appnote/ michael@0: */ michael@0: readonly attribute unsigned short compression; michael@0: /** michael@0: * The compressed size of the data in the item. michael@0: */ michael@0: readonly attribute unsigned long size; michael@0: /** michael@0: * The uncompressed size of the data in the item. michael@0: */ michael@0: readonly attribute unsigned long realSize; michael@0: /** michael@0: * The CRC-32 hash of the file in the entry. michael@0: */ michael@0: readonly attribute unsigned long CRC32; michael@0: /** michael@0: * True if the name of the entry ends with '/' and false otherwise. michael@0: */ michael@0: readonly attribute boolean isDirectory; michael@0: /** michael@0: * The time at which this item was last modified. michael@0: */ michael@0: readonly attribute PRTime lastModifiedTime; michael@0: /** michael@0: * Use this attribute to determine whether this item is an actual zip entry michael@0: * or is one synthesized for part of a real entry's path. A synthesized michael@0: * entry represents a directory within the zip file which has no michael@0: * corresponding entry within the zip file. For example, the entry for the michael@0: * directory foo/ in a zip containing exactly one entry for foo/bar.txt michael@0: * is synthetic. If the zip file contains an actual entry for a directory, michael@0: * this attribute will be false for the nsIZipEntry for that directory. michael@0: * It is impossible for a file to be synthetic. michael@0: */ michael@0: readonly attribute boolean isSynthetic; michael@0: /** michael@0: * The UNIX style file permissions of this item. michael@0: */ michael@0: readonly attribute unsigned long permissions; michael@0: }; michael@0: michael@0: [scriptable, uuid(38d6d07a-8a58-4fe7-be8b-ef6472fa83ff)] michael@0: interface nsIZipReader : nsISupports michael@0: { michael@0: /** michael@0: * Opens a zip file for reading. michael@0: * It is allowed to open with another file, michael@0: * but it needs to be closed first with close(). michael@0: */ michael@0: void open(in nsIFile zipFile); michael@0: michael@0: /** michael@0: * Opens a zip file inside a zip file for reading. michael@0: */ michael@0: void openInner(in nsIZipReader zipReader, in AUTF8String zipEntry); michael@0: michael@0: /** michael@0: * The file that represents the zip with which this zip reader was michael@0: * initialized. michael@0: */ michael@0: readonly attribute nsIFile file; michael@0: michael@0: /** michael@0: * Closes a zip reader. Subsequent attempts to extract files or read from michael@0: * its input stream will result in an error. michael@0: * michael@0: * Subsequent attempts to access a nsIZipEntry obtained from this zip michael@0: * reader will cause unspecified behavior. michael@0: */ michael@0: void close(); michael@0: michael@0: /** michael@0: * Tests the integrity of the archive by performing a CRC check michael@0: * on each item expanded into memory. If an entry is specified michael@0: * the integrity of only that item is tested. If null (javascript) michael@0: * or EmptyCString() (c++) is passed in the integrity of all items michael@0: * in the archive are tested. michael@0: */ michael@0: void test(in AUTF8String aEntryName); michael@0: michael@0: /** michael@0: * Extracts a zip entry into a local file specified by outFile. michael@0: * The entry must be stored in the zip in either uncompressed or michael@0: * DEFLATE-compressed format for the extraction to be successful. michael@0: * If the entry is a directory, the directory will be extracted michael@0: * non-recursively. michael@0: */ michael@0: void extract(in AUTF8String zipEntry, in nsIFile outFile); michael@0: michael@0: /** michael@0: * Returns a nsIZipEntry describing a specified zip entry. michael@0: */ michael@0: nsIZipEntry getEntry(in AUTF8String zipEntry); michael@0: michael@0: /** michael@0: * Checks whether the zipfile contains an entry specified by entryName. michael@0: */ michael@0: boolean hasEntry(in AUTF8String zipEntry); michael@0: michael@0: /** michael@0: * Returns a string enumerator containing the matching entry names. michael@0: * michael@0: * @param aPattern michael@0: * A regular expression used to find matching entries in the zip file. michael@0: * Set this parameter to null (javascript) or EmptyCString() (c++) or "*" michael@0: * to get all entries; otherwise, use the michael@0: * following syntax: michael@0: * michael@0: * o * matches anything michael@0: * o ? matches one character michael@0: * o $ matches the end of the string michael@0: * o [abc] matches one occurrence of a, b, or c. The only character that michael@0: * must be escaped inside the brackets is ]. ^ and - must never michael@0: * appear in the first and second positions within the brackets, michael@0: * respectively. (In the former case, the behavior specified for michael@0: * '[^az]' will happen.) michael@0: * o [a-z] matches any character between a and z. The characters a and z michael@0: * must either both be letters or both be numbers, with the michael@0: * character represented by 'a' having a lower ASCII value than michael@0: * the character represented by 'z'. michael@0: * o [^az] matches any character except a or z. If ] is to appear inside michael@0: * the brackets as a character to not match, it must be escaped. michael@0: * o pat~pat2 returns matches to the pattern 'pat' which do not also match michael@0: * the pattern 'pat2'. This may be used to perform filtering michael@0: * upon the results of one pattern to remove all matches which michael@0: * also match another pattern. For example, because '*' michael@0: * matches any string and '*z*' matches any string containing a michael@0: * 'z', '*~*z*' will match all strings except those containing michael@0: * a 'z'. Note that a pattern may not use '~' multiple times, michael@0: * so a string such as '*~*z*~*y*' is not a valid pattern. michael@0: * o (foo|bar) will match either the pattern foo or the pattern bar. michael@0: * Neither of the patterns foo or bar may use the 'pat~pat2' michael@0: * syntax described immediately above. michael@0: * o \ will escape a special character. Escaping is required for all michael@0: * special characters unless otherwise specified. michael@0: * o All other characters match case-sensitively. michael@0: * michael@0: * An aPattern not conforming to this syntax has undefined behavior. michael@0: * michael@0: * @throws NS_ERROR_ILLEGAL_VALUE on many but not all invalid aPattern michael@0: * values. michael@0: */ michael@0: nsIUTF8StringEnumerator findEntries(in AUTF8String aPattern); michael@0: michael@0: /** michael@0: * Returns an input stream containing the contents of the specified zip michael@0: * entry. michael@0: * @param zipEntry the name of the entry to open the stream from michael@0: */ michael@0: nsIInputStream getInputStream(in AUTF8String zipEntry); michael@0: michael@0: /** michael@0: * Returns an input stream containing the contents of the specified zip michael@0: * entry. If the entry refers to a directory (ends with '/'), a directory stream michael@0: * is opened, otherwise the contents of the file entry is returned. michael@0: * @param aJarSpec the Spec of the URI for the JAR (only used for directory streams) michael@0: * @param zipEntry the name of the entry to open the stream from michael@0: */ michael@0: nsIInputStream getInputStreamWithSpec(in AUTF8String aJarSpec, in AUTF8String zipEntry); michael@0: michael@0: /** michael@0: * Returns an object describing the entity which signed michael@0: * an entry. parseManifest must be called first. If aEntryName is an michael@0: * entry in the jar, getInputStream must be called after parseManifest. michael@0: * If aEntryName is an external file which has meta-information michael@0: * stored in the jar, verifyExternalFile (not yet implemented) must michael@0: * be called before getPrincipal. michael@0: */ michael@0: nsICertificatePrincipal getCertificatePrincipal(in AUTF8String aEntryName); michael@0: michael@0: readonly attribute uint32_t manifestEntriesCount; michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // nsIZipReaderCache michael@0: michael@0: [scriptable, uuid(748050ac-3ab6-4472-bc2a-cb1564ac6a81)] michael@0: interface nsIZipReaderCache : nsISupports michael@0: { michael@0: /** michael@0: * Initializes a new zip reader cache. michael@0: * @param cacheSize - the number of released entries to maintain before michael@0: * beginning to throw some out (note that the number of outstanding michael@0: * entries can be much greater than this number -- this is the count michael@0: * for those otherwise unused entries) michael@0: */ michael@0: void init(in unsigned long cacheSize); michael@0: michael@0: /** michael@0: * Returns a (possibly shared) nsIZipReader for an nsIFile. michael@0: * michael@0: * If the zip reader for given file is not in the cache, a new zip reader michael@0: * is created, initialized, and opened (see nsIZipReader::init and michael@0: * nsIZipReader::open). Otherwise the previously created zip reader is michael@0: * returned. michael@0: * michael@0: * @note If someone called close() on the shared nsIZipReader, this method michael@0: * will return the closed zip reader. michael@0: */ michael@0: nsIZipReader getZip(in nsIFile zipFile); michael@0: michael@0: /** michael@0: * returns true if this zipreader already has this file cached michael@0: */ michael@0: bool isCached(in nsIFile zipFile); michael@0: michael@0: /** michael@0: * Returns a (possibly shared) nsIZipReader for a zip inside another zip michael@0: * michael@0: * See getZip michael@0: */ michael@0: nsIZipReader getInnerZip(in nsIFile zipFile, in AUTF8String zipEntry); michael@0: }; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: %{C++ michael@0: michael@0: #define NS_ZIPREADER_CID \ michael@0: { /* 88e2fd0b-f7f4-480c-9483-7846b00e8dad */ \ michael@0: 0x88e2fd0b, 0xf7f4, 0x480c, \ michael@0: { 0x94, 0x83, 0x78, 0x46, 0xb0, 0x0e, 0x8d, 0xad } \ michael@0: } michael@0: michael@0: #define NS_ZIPREADERCACHE_CID \ michael@0: { /* 608b7f6f-4b60-40d6-87ed-d933bf53d8c1 */ \ michael@0: 0x608b7f6f, 0x4b60, 0x40d6, \ michael@0: { 0x87, 0xed, 0xd9, 0x33, 0xbf, 0x53, 0xd8, 0xc1 } \ michael@0: } michael@0: michael@0: %} michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////////