1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/uriloader/exthandler/mac/nsDecodeAppleFile.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsDecodeAppleFile_h__ 1.10 +#define nsDecodeAppleFile_h__ 1.11 + 1.12 +#include "nscore.h" 1.13 +#include "nsCOMPtr.h" 1.14 +#include "nsIFile.h" 1.15 +#include "nsILocalFileMac.h" 1.16 +#include "nsIOutputStream.h" 1.17 + 1.18 +/* 1.19 +** applefile definitions used 1.20 +*/ 1.21 +#if PRAGMA_STRUCT_ALIGN 1.22 + #pragma options align=mac68k 1.23 +#endif 1.24 + 1.25 +#define APPLESINGLE_MAGIC 0x00051600L 1.26 +#define APPLEDOUBLE_MAGIC 0x00051607L 1.27 +#define VERSION 0x00020000 1.28 + 1.29 +#define NUM_ENTRIES 6 1.30 + 1.31 +#define ENT_DFORK 1L 1.32 +#define ENT_RFORK 2L 1.33 +#define ENT_NAME 3L 1.34 +#define ENT_COMMENT 4L 1.35 +#define ENT_DATES 8L 1.36 +#define ENT_FINFO 9L 1.37 + 1.38 +#define CONVERT_TIME 1265437696L 1.39 + 1.40 +/* 1.41 +** data type used in the header decoder. 1.42 +*/ 1.43 +typedef struct ap_header 1.44 +{ 1.45 + int32_t magic; 1.46 + int32_t version; 1.47 + int32_t fill[4]; 1.48 + int16_t entriesCount; 1.49 + 1.50 +} ap_header; 1.51 + 1.52 +typedef struct ap_entry 1.53 +{ 1.54 + int32_t id; 1.55 + int32_t offset; 1.56 + int32_t length; 1.57 + 1.58 +} ap_entry; 1.59 + 1.60 +typedef struct ap_dates 1.61 +{ 1.62 + int32_t create, modify, backup, access; 1.63 + 1.64 +} ap_dates; 1.65 + 1.66 +#if PRAGMA_STRUCT_ALIGN 1.67 + #pragma options align=reset 1.68 +#endif 1.69 + 1.70 +/* 1.71 +**Error codes 1.72 +*/ 1.73 +enum { 1.74 + errADNotEnoughData = -12099, 1.75 + errADNotSupported, 1.76 + errADBadVersion 1.77 +}; 1.78 + 1.79 + 1.80 +class nsDecodeAppleFile : public nsIOutputStream 1.81 +{ 1.82 +public: 1.83 + NS_DECL_THREADSAFE_ISUPPORTS 1.84 + NS_DECL_NSIOUTPUTSTREAM 1.85 + 1.86 + nsDecodeAppleFile(); 1.87 + virtual ~nsDecodeAppleFile(); 1.88 + 1.89 + nsresult Initialize(nsIOutputStream *output, nsIFile *file); 1.90 + 1.91 +private: 1.92 + #define MAX_BUFFERSIZE 1024 1.93 + enum ParserState {parseHeaders, parseEntries, parseLookupPart, parsePart, parseSkipPart, 1.94 + parseDataFork, parseResourceFork, parseWriteThrough}; 1.95 + 1.96 + nsCOMPtr<nsIOutputStream> m_output; 1.97 + FSSpec m_fsFileSpec; 1.98 + SInt16 m_rfRefNum; 1.99 + 1.100 + unsigned char * m_dataBuffer; 1.101 + int32_t m_dataBufferLength; 1.102 + ParserState m_state; 1.103 + ap_header m_headers; 1.104 + ap_entry * m_entries; 1.105 + int32_t m_offset; 1.106 + int32_t m_dataForkOffset; 1.107 + int32_t m_totalDataForkWritten; 1.108 + int32_t m_totalResourceForkWritten; 1.109 + bool m_headerOk; 1.110 + 1.111 + int32_t m_currentPartID; 1.112 + int32_t m_currentPartLength; 1.113 + int32_t m_currentPartCount; 1.114 + 1.115 + Str255 m_comment; 1.116 + ap_dates m_dates; 1.117 + FInfo m_finderInfo; 1.118 + FXInfo m_finderExtraInfo; 1.119 +}; 1.120 + 1.121 +#endif