Back to index

lightning-sunbird  0.9+nobinonly
nsDecodeAppleFile.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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsDecodeAppleFile_h__
00039 #define nsDecodeAppleFile_h__
00040 
00041 #include "nscore.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsIFile.h"
00044 #include "nsILocalFileMac.h"
00045 #include "nsIOutputStream.h"
00046 
00047 /*
00048 ** applefile definitions used 
00049 */
00050 #if PRAGMA_STRUCT_ALIGN
00051   #pragma options align=mac68k
00052 #endif
00053 
00054 #define APPLESINGLE_MAGIC   0x00051600L
00055 #define APPLEDOUBLE_MAGIC   0x00051607L
00056 #define VERSION             0x00020000
00057 
00058 #define NUM_ENTRIES         6
00059 
00060 #define ENT_DFORK           1L
00061 #define ENT_RFORK           2L
00062 #define ENT_NAME            3L
00063 #define ENT_COMMENT         4L
00064 #define ENT_DATES           8L
00065 #define ENT_FINFO           9L
00066 
00067 #define CONVERT_TIME               1265437696L
00068 
00069 /*
00070 ** data type used in the header decoder.
00071 */
00072 typedef struct ap_header 
00073 {
00074        PRInt32       magic;
00075        PRInt32   version;
00076        PRInt32       fill[4];
00077        PRInt16       entriesCount;
00078 
00079 } ap_header;
00080 
00081 typedef struct ap_entry 
00082 {
00083        PRInt32   id;
00084        PRInt32         offset;
00085        PRInt32         length;
00086        
00087 } ap_entry;
00088 
00089 typedef struct ap_dates 
00090 {
00091        PRInt32 create, modify, backup, access;
00092 
00093 } ap_dates;
00094 
00095 #if PRAGMA_STRUCT_ALIGN
00096   #pragma options align=reset
00097 #endif
00098 
00099 /*
00100 **Error codes
00101 */
00102 enum {
00103   errADNotEnoughData = -12099,
00104   errADNotSupported,
00105   errADBadVersion
00106 };
00107 
00108 
00109 class nsDecodeAppleFile : public nsIOutputStream
00110 {
00111 public:
00112   NS_DECL_ISUPPORTS
00113   NS_DECL_NSIOUTPUTSTREAM
00114   
00115   nsDecodeAppleFile();
00116   virtual ~nsDecodeAppleFile();
00117   
00118   nsresult Initialize(nsIOutputStream *output, nsIFile *file);
00119   
00120 private:
00121   #define MAX_BUFFERSIZE    1024
00122   enum ParserState {parseHeaders, parseEntries, parseLookupPart, parsePart, parseSkipPart,
00123                     parseDataFork, parseResourceFork, parseWriteThrough};
00124   
00125   nsCOMPtr<nsIOutputStream> m_output;
00126   FSSpec            m_fsFileSpec;
00127   SInt16            m_rfRefNum;
00128   
00129   unsigned char *   m_dataBuffer;
00130   PRInt32           m_dataBufferLength;
00131   ParserState       m_state;
00132   ap_header         m_headers;
00133   ap_entry *        m_entries;
00134   PRInt32           m_offset;
00135   PRInt32           m_dataForkOffset;
00136   PRInt32           m_totalDataForkWritten;
00137   PRInt32           m_totalResourceForkWritten;
00138   PRBool            m_headerOk;
00139   
00140   PRInt32           m_currentPartID;
00141   PRInt32           m_currentPartLength;
00142   PRInt32           m_currentPartCount;
00143   
00144   Str255            m_comment;
00145   ap_dates          m_dates;
00146   FInfo             m_finderInfo;
00147   FXInfo            m_finderExtraInfo;
00148 };
00149 
00150 #endif