Back to index

lightning-sunbird  0.9+nobinonly
nsAppleFileDecoder.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Jean-Francois Ducarroz <ducarroz@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsAppleFileDecoder_h__
00040 #define nsAppleFileDecoder_h__
00041 
00042 #include "nsIAppleFileDecoder.h"
00043 #include "nsILocalFileMac.h"
00044 
00045 /*
00046 ** applefile definitions used 
00047 */
00048 #if PRAGMA_STRUCT_ALIGN
00049   #pragma options align=mac68k
00050 #endif
00051 
00052 #define APPLESINGLE_MAGIC   0x00051600L
00053 #define APPLEDOUBLE_MAGIC   0x00051607L
00054 #define VERSION             0x00020000
00055 
00056 #define NUM_ENTRIES         6
00057 
00058 #define ENT_DFORK           1L
00059 #define ENT_RFORK           2L
00060 #define ENT_NAME            3L
00061 #define ENT_COMMENT         4L
00062 #define ENT_DATES           8L
00063 #define ENT_FINFO           9L
00064 
00065 #define CONVERT_TIME               1265437696L
00066 
00067 /*
00068 ** data type used in the header decoder.
00069 */
00070 typedef struct ap_header 
00071 {
00072        PRInt32       magic;
00073        PRInt32   version;
00074        PRInt32       fill[4];
00075        PRInt16       entriesCount;
00076 
00077 } ap_header;
00078 
00079 typedef struct ap_entry 
00080 {
00081        PRInt32   id;
00082        PRInt32         offset;
00083        PRInt32         length;
00084        
00085 } ap_entry;
00086 
00087 typedef struct ap_dates 
00088 {
00089        PRInt32 create, modify, backup, access;
00090 
00091 } ap_dates;
00092 
00093 #if PRAGMA_STRUCT_ALIGN
00094   #pragma options align=reset
00095 #endif
00096 
00097 /*
00098 **Error codes
00099 */
00100 enum {
00101   errADNotEnoughData = -12099,
00102   errADNotSupported,
00103   errADBadVersion
00104 };
00105 
00106 
00107 class nsAppleFileDecoder : public nsIAppleFileDecoder
00108 {
00109 public:
00110   NS_DECL_ISUPPORTS
00111   NS_DECL_NSIOUTPUTSTREAM
00112   NS_DECL_NSIAPPLEFILEDECODER 
00113    
00114   nsAppleFileDecoder();
00115   virtual ~nsAppleFileDecoder();
00116   
00117 private:
00118   #define MAX_BUFFERSIZE    1024
00119   enum ParserState {parseHeaders, parseEntries, parseLookupPart, parsePart, parseSkipPart,
00120                     parseDataFork, parseResourceFork, parseWriteThrough};
00121   
00122   nsCOMPtr<nsIOutputStream> m_output;
00123   FSSpec            m_fsFileSpec;
00124   SInt16            m_rfRefNum;
00125   
00126   unsigned char *   m_dataBuffer;
00127   PRInt32           m_dataBufferLength;
00128   ParserState       m_state;
00129   ap_header         m_headers;
00130   ap_entry *        m_entries;
00131   PRInt32           m_offset;
00132   PRInt32           m_dataForkOffset;
00133   PRInt32           m_totalDataForkWritten;
00134   PRInt32           m_totalResourceForkWritten;
00135   PRBool            m_headerOk;
00136   
00137   PRInt32           m_currentPartID;
00138   PRInt32           m_currentPartLength;
00139   PRInt32           m_currentPartCount;
00140   
00141   Str255            m_comment;
00142   ap_dates          m_dates;
00143   FInfo             m_finderInfo;
00144   FXInfo            m_finderExtraInfo;
00145 };
00146 
00147 #endif