~ubuntu-branches/ubuntu/trusty/xulrunner/trusty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Mozilla Communicator client code, released
 * March 31, 1998.
 *
 * The Initial Developer of the Original Code is
 * Netscape Communications Corporation.
 * Portions created by the Initial Developer are Copyright (C) 1999
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Samir Gehani <sgehani@netscape.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either of the GNU General Public License Version 2 or later (the "GPL"),
 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */


/*----------------------------------------------------------------------*
 *   Implements a simple AppleSingle decoder, as described in RFC1740 
 *   http://andrew2.andrew.cmu.edu/rfc/rfc1740.html
 *----------------------------------------------------------------------*/

#pragma options align=mac68k

#ifndef _NS_APPLESINGLEDECODER_H_
#define _NS_APPLESINGLEDECODER_H_

#include <stdlib.h>
#include <string.h>
#include <Carbon/Carbon.h>


/*----------------------------------------------------------------------*
 *   Struct definitions from RFC1740
 *----------------------------------------------------------------------*/
#define APPLESINGLE_MAGIC   0x00051600L
#define APPLESINGLE_VERSION 0x00020000L

typedef struct ASHeader /* header portion of AppleSingle */ 
{
  /* AppleSingle = 0x00051600; AppleDouble = 0x00051607 */
  UInt32 magicNum;      /* internal file type tag */ 
  UInt32 versionNum;    /* format version: 2 = 0x00020000 */ 
  UInt8 filler[16];     /* filler, currently all bits 0 */ 
  UInt16 numEntries;    /* number of entries which follow */
} ASHeader ; /* ASHeader */ 

typedef struct ASEntry /* one AppleSingle entry descriptor */ 
{
  UInt32 entryID;     /* entry type: see list, 0 invalid */
  UInt32 entryOffset; /* offset, in octets, from beginning */
                      /* of file to this entry's data */
  UInt32 entryLength; /* length of data in octets */
} ASEntry; /* ASEntry */

typedef struct ASFinderInfo
{
  FInfo ioFlFndrInfo;     /* PBGetFileInfo() or PBGetCatInfo() */
  FXInfo ioFlXFndrInfo;   /* PBGetCatInfo() (HFS only) */
} ASFinderInfo; /* ASFinderInfo */

typedef struct ASMacInfo  /* entry ID 10, Macintosh file information */
{
       UInt8 filler[3];   /* filler, currently all bits 0 */ 
       UInt8 ioFlAttrib;  /* PBGetFileInfo() or PBGetCatInfo() */
} ASMacInfo;

typedef struct ASFileDates  /* entry ID 8, file dates info */
{
  SInt32 create; /* file creation date/time */
  SInt32 modify; /* last modification date/time */
  SInt32 backup; /* last backup date/time */
  SInt32 access; /* last access date/time */
} ASFileDates; /* ASFileDates */

/* entryID list */
#define AS_DATA         1 /* data fork */
#define AS_RESOURCE     2 /* resource fork */
#define AS_REALNAME     3 /* File's name on home file system */
#define AS_COMMENT      4 /* standard Mac comment */
#define AS_ICONBW       5 /* Mac black & white icon */
#define AS_ICONCOLOR    6 /* Mac color icon */
/*                      7    not used */
#define AS_FILEDATES    8 /* file dates; create, modify, etc */
#define AS_FINDERINFO   9 /* Mac Finder info & extended info */
#define AS_MACINFO      10 /* Mac file info, attributes, etc */
#define AS_PRODOSINFO   11 /* Pro-DOS file info, attrib., etc */
#define AS_MSDOSINFO    12 /* MS-DOS file info, attributes, etc */
#define AS_AFPNAME      13 /* Short name on AFP server */
#define AS_AFPINFO      14 /* AFP file info, attrib., etc */

#define AS_AFPDIRID     15 /* AFP directory ID */


/*----------------------------------------------------------------------*
 *   Macros
 *----------------------------------------------------------------------*/
#define MAC_ERR_CHECK(_funcCall)   \
  err = _funcCall;         \
  if (err!=noErr)         \
      return err;
  
  

class nsAppleSingleDecoder 
{

public:
  nsAppleSingleDecoder(const FSRef *inRef, FSRef *outRef);
  nsAppleSingleDecoder();
  ~nsAppleSingleDecoder();
    
  /** 
   * Decode
   *
   * Takes an "in" FSSpec for the source file in AppleSingle
   * format to decode and write out to an "out" FSSpec.
   * This form is used when the Decode(void) method has already
   * been invoked once and this object is reused to decode 
   * another AppleSingled file: useful in iteration to avoid
   * nsAppleSingleDecoder object instantiation per file.
   *
   * @param  inRef    the AppleSingled file to decode
   * @param  outRef   the destination file in which the decoded
   *                  data was written out (empty when passed in
   *                  and filled on return)
   * @return err      a standard MacOS OSErr where noErr means OK
   */
  OSErr Decode(const FSRef *inRef, FSRef *outRef);
    
  /**
   * Decode
   *
   * Decodes the AppleSingled file passed in to the constructor
   * and writes out the decoded data to the outSpec passed to the 
   * constructor.
   *
   * @return err      a standard MacOS OSErr where noErr = OK
   */
  OSErr Decode();
  
  /**
   * DecodeFolder
   *
   * Traverses arbitrarily nested subdirs decoding any files
   * in AppleSingle format and leaving other files alone.
   *
   * @param  aFolder the folder whose contents to decode
   * @return err     a standard MacOS err 
   *                 (dirNFErr if invalid dir, noErr = OK)
   */
  OSErr DecodeFolder(const FSRef *aFolder);
     
  /**
   * IsAppleSingleFile
   *
   * Checks the file header to see whether this is an AppleSingle
   * version 2 file by matching the magicNum field in the header.
   *
   * @param  inRef        the file to check
   * @return bAppleSingle a Boolean where true indicates this is
   *                      in fact an AppleSingle file
   */
  static Boolean IsAppleSingleFile(const FSRef *inRef);
  
  /**
   * IsDirectory
   *
   * Check whether the supplied FSSpec points to a directory.
   *
   * @param  inRef  the file/directory spec
   * @return bDir   true iff this spec is a valid directory
   */
  static Boolean IsDirectory(const FSRef *inRef);

  /**
   * String utility wrapper to compare to Unicode filenames.
   */
  static Boolean UCstrcmp(const HFSUniStr255 *str1, const HFSUniStr255 *str2);
  
private:
  const FSRef *mInRef;
  FSRef       *mOutRef;
  // cache since it's used through the life of one Decode cycle:
  SInt16      mInRefNum;  
  Boolean     mRenameReqd;
  
  OSErr  ProcessASEntry(ASEntry inEntry);  
  OSErr  ProcessDataFork(ASEntry inEntry);
  OSErr  ProcessResourceFork(ASEntry inEntry);
  OSErr  ProcessRealName(ASEntry inEntry);
  OSErr  ProcessFileDates(ASEntry inEntry);
  OSErr  ProcessFinderInfo(ASEntry inEntry);
  OSErr  EntryToMacFile(ASEntry inEntry, UInt16 inTargetSpecRefNum);

  OSErr  FSMakeUnique(const FSRef *inParentRef, FSRef *outRef);
};

#ifdef __cplusplus
extern "C" {
#endif

Boolean 
DecodeDirIterateFilter(Boolean containerChanged, ItemCount currentLevel,
  const FSCatalogInfo *catalogInfo, const FSRef *ref, 
  const FSSpec *spec, const HFSUniStr255 *name, void *yourDataPtr);

#ifdef __cplusplus
}
#endif

#pragma options align=reset

#endif /* _NS_APPLESINGLEDECODER_H_ */