Back to index

lightning-sunbird  0.9+nobinonly
nsAppleSingleDecoder.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Samir Gehani <sgehani@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 
00041 /*----------------------------------------------------------------------*
00042  *   Implements a simple AppleSingle decoder, as described in RFC1740 
00043  *   http://andrew2.andrew.cmu.edu/rfc/rfc1740.html
00044  *----------------------------------------------------------------------*/
00045 
00046 #pragma options align=mac68k
00047 
00048 #ifndef _NS_APPLESINGLEDECODER_H_
00049 #define _NS_APPLESINGLEDECODER_H_
00050 
00051 #include <stdlib.h>
00052 #include <string.h>
00053 #include <Carbon/Carbon.h>
00054 
00055 
00056 /*----------------------------------------------------------------------*
00057  *   Struct definitions from RFC1740
00058  *----------------------------------------------------------------------*/
00059 #define APPLESINGLE_MAGIC   0x00051600L
00060 #define APPLESINGLE_VERSION 0x00020000L
00061 
00062 typedef struct ASHeader /* header portion of AppleSingle */ 
00063 {
00064   /* AppleSingle = 0x00051600; AppleDouble = 0x00051607 */
00065   UInt32 magicNum;      /* internal file type tag */ 
00066   UInt32 versionNum;    /* format version: 2 = 0x00020000 */ 
00067   UInt8 filler[16];     /* filler, currently all bits 0 */ 
00068   UInt16 numEntries;    /* number of entries which follow */
00069 } ASHeader ; /* ASHeader */ 
00070 
00071 typedef struct ASEntry /* one AppleSingle entry descriptor */ 
00072 {
00073   UInt32 entryID;     /* entry type: see list, 0 invalid */
00074   UInt32 entryOffset; /* offset, in octets, from beginning */
00075                       /* of file to this entry's data */
00076   UInt32 entryLength; /* length of data in octets */
00077 } ASEntry; /* ASEntry */
00078 
00079 typedef struct ASFinderInfo
00080 {
00081   FInfo ioFlFndrInfo;     /* PBGetFileInfo() or PBGetCatInfo() */
00082   FXInfo ioFlXFndrInfo;   /* PBGetCatInfo() (HFS only) */
00083 } ASFinderInfo; /* ASFinderInfo */
00084 
00085 typedef struct ASMacInfo  /* entry ID 10, Macintosh file information */
00086 {
00087        UInt8 filler[3];   /* filler, currently all bits 0 */ 
00088        UInt8 ioFlAttrib;  /* PBGetFileInfo() or PBGetCatInfo() */
00089 } ASMacInfo;
00090 
00091 typedef struct ASFileDates  /* entry ID 8, file dates info */
00092 {
00093   SInt32 create; /* file creation date/time */
00094   SInt32 modify; /* last modification date/time */
00095   SInt32 backup; /* last backup date/time */
00096   SInt32 access; /* last access date/time */
00097 } ASFileDates; /* ASFileDates */
00098 
00099 /* entryID list */
00100 #define AS_DATA         1 /* data fork */
00101 #define AS_RESOURCE     2 /* resource fork */
00102 #define AS_REALNAME     3 /* File's name on home file system */
00103 #define AS_COMMENT      4 /* standard Mac comment */
00104 #define AS_ICONBW       5 /* Mac black & white icon */
00105 #define AS_ICONCOLOR    6 /* Mac color icon */
00106 /*                      7    not used */
00107 #define AS_FILEDATES    8 /* file dates; create, modify, etc */
00108 #define AS_FINDERINFO   9 /* Mac Finder info & extended info */
00109 #define AS_MACINFO      10 /* Mac file info, attributes, etc */
00110 #define AS_PRODOSINFO   11 /* Pro-DOS file info, attrib., etc */
00111 #define AS_MSDOSINFO    12 /* MS-DOS file info, attributes, etc */
00112 #define AS_AFPNAME      13 /* Short name on AFP server */
00113 #define AS_AFPINFO      14 /* AFP file info, attrib., etc */
00114 
00115 #define AS_AFPDIRID     15 /* AFP directory ID */
00116 
00117 
00118 /*----------------------------------------------------------------------*
00119  *   Macros
00120  *----------------------------------------------------------------------*/
00121 #define MAC_ERR_CHECK(_funcCall)   \
00122   err = _funcCall;         \
00123   if (err!=noErr)         \
00124       return err;
00125   
00126   
00127 
00128 class nsAppleSingleDecoder 
00129 {
00130 
00131 public:
00132   nsAppleSingleDecoder(const FSRef *inRef, FSRef *outRef);
00133   nsAppleSingleDecoder();
00134   ~nsAppleSingleDecoder();
00135     
00152   OSErr Decode(const FSRef *inRef, FSRef *outRef);
00153     
00163   OSErr Decode();
00164   
00175   OSErr DecodeFolder(const FSRef *aFolder);
00176      
00187   static Boolean IsAppleSingleFile(const FSRef *inRef);
00188   
00197   static Boolean IsDirectory(const FSRef *inRef);
00198 
00202   static Boolean UCstrcmp(const HFSUniStr255 *str1, const HFSUniStr255 *str2);
00203   
00204 private:
00205   const FSRef *mInRef;
00206   FSRef       *mOutRef;
00207   // cache since it's used through the life of one Decode cycle:
00208   SInt16      mInRefNum;  
00209   Boolean     mRenameReqd;
00210   
00211   OSErr  ProcessASEntry(ASEntry inEntry);  
00212   OSErr  ProcessDataFork(ASEntry inEntry);
00213   OSErr  ProcessResourceFork(ASEntry inEntry);
00214   OSErr  ProcessRealName(ASEntry inEntry);
00215   OSErr  ProcessFileDates(ASEntry inEntry);
00216   OSErr  ProcessFinderInfo(ASEntry inEntry);
00217   OSErr  EntryToMacFile(ASEntry inEntry, UInt16 inTargetSpecRefNum);
00218 
00219   OSErr  FSMakeUnique(const FSRef *inParentRef, FSRef *outRef);
00220 };
00221 
00222 #ifdef __cplusplus
00223 extern "C" {
00224 #endif
00225 
00226 Boolean 
00227 DecodeDirIterateFilter(Boolean containerChanged, ItemCount currentLevel,
00228   const FSCatalogInfo *catalogInfo, const FSRef *ref, 
00229   const FSSpec *spec, const HFSUniStr255 *name, void *yourDataPtr);
00230 
00231 #ifdef __cplusplus
00232 }
00233 #endif
00234 
00235 #pragma options align=reset
00236 
00237 #endif /* _NS_APPLESINGLEDECODER_H_ */