[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:57:34 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 3d3ff66194a9db7e9e2eeda0dafe0df9ea6e619d
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Nov 6 23:11:00 2002 +0000

    	- added a BinHex decoder and did a little work on the MacBinary decoder
    
            I'm not supposed to be working on this, but I didn't feel like doing "real" work.
    
            * Downloads.subproj/WebBinHexDecoder.h: Added.
            * Downloads.subproj/WebBinHexDecoder.m: Added.
            * WebKit.pbproj/project.pbxproj: Added WebBinHexDecoder.
    
            * Downloads.subproj/WebDownloadDecoder.h: Added WEB_DOWNLOAD_DECODER_MINIMUM_HEADER_LENGTH.
            * Downloads.subproj/WebDownloadHandler.m:
            (-[WebDownloadHandler closeFile]): Check to be sure we don't close the same file twice.
    
            * Downloads.subproj/WebMacBinaryDecoder.h: Added _scriptCode.
            * Downloads.subproj/WebMacBinaryDecoder.m:
            (+[WebMacBinaryDecoder canDecodeHeaderData:]): Added check of MacBinary version field.
            (-[WebMacBinaryDecoder decodeData:dataForkData:resourceForkData:]): Added MacBinary III
    	part that gets the script code.
            (-[WebMacBinaryDecoder filename]): Use the script code.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2577 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 6f8425b..89b7e80 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,24 @@
+2002-11-06  Darin Adler  <darin at apple.com>
+
+	- added a BinHex decoder and did a little work on the MacBinary decoder
+        
+        I'm not supposed to be working on this, but I didn't feel like doing "real" work.
+
+        * Downloads.subproj/WebBinHexDecoder.h: Added.
+        * Downloads.subproj/WebBinHexDecoder.m: Added.
+        * WebKit.pbproj/project.pbxproj: Added WebBinHexDecoder.
+
+        * Downloads.subproj/WebDownloadDecoder.h: Added WEB_DOWNLOAD_DECODER_MINIMUM_HEADER_LENGTH.
+        * Downloads.subproj/WebDownloadHandler.m:
+        (-[WebDownloadHandler closeFile]): Check to be sure we don't close the same file twice.
+
+        * Downloads.subproj/WebMacBinaryDecoder.h: Added _scriptCode.
+        * Downloads.subproj/WebMacBinaryDecoder.m:
+        (+[WebMacBinaryDecoder canDecodeHeaderData:]): Added check of MacBinary version field.
+        (-[WebMacBinaryDecoder decodeData:dataForkData:resourceForkData:]): Added MacBinary III
+	part that gets the script code.
+        (-[WebMacBinaryDecoder filename]): Use the script code.
+
 2002-11-06  Maciej Stachowiak  <mjs at apple.com>
 
 	Took URL field out of click policy - open in new window policy
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index 6f8425b..89b7e80 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,24 @@
+2002-11-06  Darin Adler  <darin at apple.com>
+
+	- added a BinHex decoder and did a little work on the MacBinary decoder
+        
+        I'm not supposed to be working on this, but I didn't feel like doing "real" work.
+
+        * Downloads.subproj/WebBinHexDecoder.h: Added.
+        * Downloads.subproj/WebBinHexDecoder.m: Added.
+        * WebKit.pbproj/project.pbxproj: Added WebBinHexDecoder.
+
+        * Downloads.subproj/WebDownloadDecoder.h: Added WEB_DOWNLOAD_DECODER_MINIMUM_HEADER_LENGTH.
+        * Downloads.subproj/WebDownloadHandler.m:
+        (-[WebDownloadHandler closeFile]): Check to be sure we don't close the same file twice.
+
+        * Downloads.subproj/WebMacBinaryDecoder.h: Added _scriptCode.
+        * Downloads.subproj/WebMacBinaryDecoder.m:
+        (+[WebMacBinaryDecoder canDecodeHeaderData:]): Added check of MacBinary version field.
+        (-[WebMacBinaryDecoder decodeData:dataForkData:resourceForkData:]): Added MacBinary III
+	part that gets the script code.
+        (-[WebMacBinaryDecoder filename]): Use the script code.
+
 2002-11-06  Maciej Stachowiak  <mjs at apple.com>
 
 	Took URL field out of click policy - open in new window policy
diff --git a/WebKit/Downloads.subproj/WebBinHexDecoder.h b/WebKit/Downloads.subproj/WebBinHexDecoder.h
new file mode 100644
index 0000000..72b6a0d
--- /dev/null
+++ b/WebKit/Downloads.subproj/WebBinHexDecoder.h
@@ -0,0 +1,51 @@
+//
+//  WebBinHexDecoder.h
+//  WebKit
+//
+//  Created by Darin Adler on Wed Nov 06 2002.
+//  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+ at protocol WebDownloadDecoder;
+
+ at interface WebBinHexDecoder : NSObject <WebDownloadDecoder>
+{
+    BOOL _sawError;
+
+    BOOL _atEnd;
+    
+    unsigned char _sixBitBuffer[4];
+    int _sixBitBufferLength;
+    
+    unsigned char _byteBuffer[3];
+    int _byteBufferLength;
+    int _byteBufferOffset;
+    
+    unsigned char _repeatCharacter;
+    int _repeatCount;
+    
+    BOOL _sawRepeatCharacter;
+    
+    int _CRC;
+    
+    const unsigned char *_source;
+    const unsigned char *_sourceEnd;
+    
+    unsigned char _name[64];
+    OSType _fileType;
+    OSType _fileCreator;
+    int _dataForkLengthRemaining;
+    int _resourceForkLengthRemaining;
+    
+    int _computedCRC;
+    BOOL _haveComputedCRC;
+    
+    unsigned char _fileCRC[2];
+    int _fileCRCLength;
+    
+    BOOL _dataForkCRCChecked;
+    BOOL _resourceForkCRCChecked;
+}
+ at end
diff --git a/WebKit/Downloads.subproj/WebBinHexDecoder.m b/WebKit/Downloads.subproj/WebBinHexDecoder.m
new file mode 100644
index 0000000..87462e3
--- /dev/null
+++ b/WebKit/Downloads.subproj/WebBinHexDecoder.m
@@ -0,0 +1,365 @@
+//
+//  WebBinHexDecoder.m
+//  WebKit
+//
+//  Created by Darin Adler on Wed Nov 06 2002.
+//  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+//
+
+// This decoder decodes a particular variant of the BinHex format.
+// Specifically, it's the 7-bit format known as Hqx7.
+
+#import "WebBinHexDecoder.h"
+
+#import <WebFoundation/WebAssertions.h>
+
+#define SKIP_CHARACTER 0x40
+#define END_CHARACTER 0x41
+#define BAD_CHARACTER 0x42
+
+static const unsigned char sixBitTable[256] = {   
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x40, 0x42, 0x42, 0x40, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x42, 0x42,
+      0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x42, 0x14, 0x15, 0x41, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x42,
+      0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x42, 0x2C, 0x2D, 0x2E, 0x2F, 0x42, 0x42, 0x42, 0x42,
+      0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x42, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x42, 0x42,
+      0x3D, 0x3E, 0x3F, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42,
+      0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42
+};
+
+#define RUN_LENGTH_CODE 0x90
+
+#define BEFORE_HEADER_LINE "(This file must be converted with BinHex 4.0)"
+
+typedef struct {
+    unsigned char name[64];
+    unsigned char remainder[19];
+} Header;
+
+ at implementation WebBinHexDecoder
+
+- (int)decodeIntoBuffer:(void *)buffer size:(int)bufferSize
+{
+    ASSERT(buffer);
+    ASSERT(bufferSize);
+    
+    if (_sawError || _atEnd) {
+        return 0;
+    }
+    
+    unsigned char *bufferStart = buffer;
+    unsigned char *bufferP = bufferStart;
+    unsigned char *bufferEnd = bufferStart + bufferSize;
+    
+    int sixBitBufferLength = _sixBitBufferLength;
+    int byteBufferLength = _byteBufferLength;
+    int byteBufferOffset = _byteBufferOffset;
+    unsigned char repeatCharacter = _repeatCharacter;
+    int repeatCount = _repeatCount;
+    BOOL sawRepeatCharacter = _sawRepeatCharacter;
+    int CRC = _CRC;
+    const unsigned char *source = _source;
+    const unsigned char *sourceEnd = _sourceEnd;
+    
+    for (;;) {
+        for (;;) {
+            // Empty the repeat count.
+            while (repeatCount) {
+                unsigned int c = repeatCharacter;
+                *bufferP++ = c;
+                
+                int i;
+                for (i = 0; i < 8; i++) {
+                    c <<= 1;
+                    if ((CRC <<= 1) & 0x10000) {
+                        CRC = (CRC & 0xFFFF) ^ 0x1021;
+                    }
+                    CRC ^= (c >> 8);
+                    c &= 0xFF;
+                }
+                
+                //printf("added the character %X to the CRC, CRC is now %X\n", repeatCharacter, CRC);
+                
+                repeatCount -= 1;
+                if (bufferP == bufferEnd) {
+                    goto done;
+                }
+            }
+            
+            // Empty the byte buffer.
+            if (byteBufferOffset == byteBufferLength) {
+                break;
+            }
+            unsigned char byte = _byteBuffer[byteBufferOffset++];
+            if (sawRepeatCharacter) {
+                if (byte == 0) {
+                    repeatCount = 1;
+                    repeatCharacter = RUN_LENGTH_CODE;
+                } else {
+                    repeatCount = byte;
+                }
+                sawRepeatCharacter = NO;
+            } else {
+                if (byte == RUN_LENGTH_CODE) {
+                    sawRepeatCharacter = YES;
+                } else {
+                    repeatCount = 1;
+                    repeatCharacter = byte;
+                }
+            }
+        }
+        
+        // Extract six-bit characters, then bytes.
+        for (;;) {
+            if (source == sourceEnd) {
+                goto done;
+            }
+        
+            char sixBits = sixBitTable[*source++];
+            switch (sixBits) {
+                case SKIP_CHARACTER:
+                    continue;
+                case END_CHARACTER:
+                    _atEnd = YES;
+                    break;
+                case BAD_CHARACTER:
+                    _sawError = YES;
+                    return 0;
+                default:
+                    _sixBitBuffer[sixBitBufferLength++] = sixBits;
+            }
+            
+            // Fill the byte buffer.
+            if (sixBitBufferLength == 4 || _atEnd) {
+                ASSERT(byteBufferOffset == byteBufferLength);
+                _byteBuffer[0] = (_sixBitBuffer[0] << 2 | _sixBitBuffer[1] >> 4);
+                _byteBuffer[1] = (_sixBitBuffer[1] << 4 | _sixBitBuffer[2] >> 2);
+                _byteBuffer[2] = (_sixBitBuffer[2] << 6 | _sixBitBuffer[3]);
+                byteBufferOffset = 0;
+                byteBufferLength = (sixBitBufferLength * 6) / 8;
+                sixBitBufferLength = 0;
+                break;
+            }
+        }
+    }
+
+done:    
+    _sixBitBufferLength = sixBitBufferLength;
+    _byteBufferLength = byteBufferLength;
+    _byteBufferOffset = byteBufferOffset;
+    _repeatCharacter = repeatCharacter;
+    _repeatCount = repeatCount;
+    _sawRepeatCharacter = sawRepeatCharacter;
+    _CRC = CRC;
+    
+    _source = source;
+    
+    return bufferP - bufferStart;
+}
+
+- (void)pumpCRCTwice
+{
+    int i;
+    for (i = 0; i < 16; i++) {
+        if ((_CRC <<= 1) & 0x10000) {
+            _CRC = (_CRC & 0xFFFF) ^ 0x1021;
+        }
+    }
+}
+
+- (void)decodeAllIntoBuffer:(void *)buffer size:(int)size
+{
+    int decodedByteCount = [self decodeIntoBuffer:buffer size:size];
+    if (decodedByteCount != size) {
+        _sawError = YES;
+    }
+}
+
+- (void)decodeHeader
+{
+    ASSERT(_CRC == 0);
+    
+    // Find the header line.
+    int beforeHeaderLineLength = strlen(BEFORE_HEADER_LINE);
+    for (;;) {
+        _source = memchr(_source, '(', _sourceEnd - _source);
+        if (!_source) {
+            _sawError = YES;
+            return;
+        }
+        if (_sourceEnd - _source < beforeHeaderLineLength) {
+            _sawError = YES;
+            return;
+        }
+        if (memcmp(_source, BEFORE_HEADER_LINE, beforeHeaderLineLength) == 0) {
+            _source += beforeHeaderLineLength;
+            break;
+        }
+        _source += 1;
+    }
+    
+    // Find the colon after it.
+    for (;;) {
+        if (_source == _sourceEnd) {
+            _sawError = YES;
+            return;
+        }
+        unsigned char c = *_source++;
+        if (c == ':') {
+            break;
+        }
+        if (c != '\n' && c != '\r') {
+            _sawError = YES;
+            return;
+        }
+    }
+
+    // Decode.
+    Header header;
+    [self decodeAllIntoBuffer:&header.name[0] size:1];
+    if (header.name[0] == 0 || header.name[0] >= sizeof(header.name)) {
+        _sawError = YES;
+        return;
+    }
+    [self decodeAllIntoBuffer:&header.name[1] size:header.name[0]];
+    [self decodeAllIntoBuffer:&header.remainder size:sizeof(header.remainder)];
+    if (header.remainder[0] != 0) { // version
+        _sawError = YES;
+        return;
+    }
+
+    // Compute the CRC.
+    [self pumpCRCTwice];
+    int computedCRC = _CRC & 0xFFFF;
+    
+    // Read the CRC from the file.
+    unsigned char CRC[2];
+    [self decodeAllIntoBuffer:CRC size:2];
+    if (computedCRC != ((CRC[0] << 8) | CRC[1])) {
+        _sawError = YES;
+        return;
+    }
+    
+    // Extract the header fields we care about.
+    memcpy(_name, header.name, header.name[0] + 1);
+    _fileType = (((((header.remainder[1] << 8) | header.remainder[2]) << 8) | header.remainder[3]) << 8) | header.remainder[4];
+    _fileCreator = (((((header.remainder[5] << 8) | header.remainder[6]) << 8) | header.remainder[7]) << 8) | header.remainder[8];
+    _dataForkLengthRemaining = (((((header.remainder[11] << 8) | header.remainder[12]) << 8) | header.remainder[13]) << 8) | header.remainder[14];
+    _resourceForkLengthRemaining = (((((header.remainder[15] << 8) | header.remainder[16]) << 8) | header.remainder[17]) << 8) | header.remainder[18];
+    
+    // Reset the CRC so it's ready to compute a fork CRC.
+    _CRC = 0;
+}
+
+- (void)setUpSourceForData:(NSData *)data
+{
+    _source = [data bytes];
+    _sourceEnd = _source + [data length];
+}
+
+- (void)decodeForkWithData:(NSData **)data count:(int *)count CRCCheckFlag:(BOOL *)CRCCheckFlag
+{
+    *data = nil;
+    
+    while (*count) {
+        char buffer[8192];
+        int maxBytes = MIN(*count, (int)sizeof(buffer));
+        int numBytesDecoded = [self decodeIntoBuffer:buffer size:maxBytes];
+        if (numBytesDecoded == 0) {
+            return;
+        }
+        ASSERT(!_sawError);
+        if (*data == nil) {
+            *data = [NSMutableData dataWithBytes:buffer length:numBytesDecoded];
+        } else {
+            [(NSMutableData *)*data appendBytes:buffer length:numBytesDecoded];
+        }
+        *count -= numBytesDecoded;
+    }
+    
+    if (!*CRCCheckFlag) {
+        // Done reading the fork, now compute the CRC.
+        if (!_haveComputedCRC) {
+            [self pumpCRCTwice];
+            _computedCRC = _CRC & 0xFFFF;
+            _haveComputedCRC = YES;
+        }
+        
+        // Done reading the fork, now read the CRC.
+        if (_fileCRCLength != 2) {
+            int numBytesDecoded = [self decodeIntoBuffer:&_fileCRC[_fileCRCLength] size:(2 - _fileCRCLength)];
+            _fileCRCLength += numBytesDecoded;
+            
+            if (_fileCRCLength == 2) {
+                // Check the CRC.
+                if (_computedCRC != ((_fileCRC[0] << 8) | _fileCRC[1])) {
+                    _sawError = YES;
+                }
+                
+                // Set the flag so we know we already checked.
+                *CRCCheckFlag = YES;
+                
+                // Reset the CRC variables so the next fork can use them.
+                _CRC = 0;
+                _haveComputedCRC = NO;
+                _fileCRCLength = 0;
+            }
+        }
+    }
+}
+
++ (BOOL)canDecodeHeaderData:(NSData *)data
+{
+    WebBinHexDecoder *decoder = [[self alloc] init];
+    [decoder setUpSourceForData:data];
+    [decoder decodeHeader];
+    BOOL sawError = decoder->_sawError;
+    [decoder release];
+    return !sawError;
+}
+
+- (BOOL)decodeData:(NSData *)data dataForkData:(NSData **)dataForkData resourceForkData:(NSData **)resourceForkData
+{
+    [self setUpSourceForData:data];
+    
+    if (_name[0] == 0) {
+        [self decodeHeader];
+    }
+    ASSERT(_sawError || _name[0]);
+    
+    [self decodeForkWithData:dataForkData count:&_dataForkLengthRemaining CRCCheckFlag:&_dataForkCRCChecked];
+    [self decodeForkWithData:resourceForkData count:&_resourceForkLengthRemaining CRCCheckFlag:&_resourceForkCRCChecked];
+
+    return !_sawError;
+}
+
+- (BOOL)finishDecoding
+{
+    ASSERT(!_sawError);
+    return _resourceForkCRCChecked;
+}
+
+- (NSDictionary *)fileAttributes
+{
+    // FIXME: What about other parts of Finder info? Bundle bit, for example.
+    return [NSDictionary dictionaryWithObjectsAndKeys:
+        [NSNumber numberWithUnsignedLong:_fileType], NSFileHFSTypeCode,
+        [NSNumber numberWithUnsignedLong:_fileCreator], NSFileHFSCreatorCode,
+        nil];
+}
+
+- (NSString *)filename
+{
+    return [(NSString *)CFStringCreateWithPascalString(NULL, _name, kCFStringEncodingMacRoman) autorelease];
+}
+
+ at end
diff --git a/WebKit/Downloads.subproj/WebDownload.m b/WebKit/Downloads.subproj/WebDownload.m
index eb110bf..79232de 100644
--- a/WebKit/Downloads.subproj/WebDownload.m
+++ b/WebKit/Downloads.subproj/WebDownload.m
@@ -6,10 +6,12 @@
 //  Copyright (c) 2002 Apple Computer, Inc.
 //
 
+#import <WebKit/WebDownloadHandler.h>
+
+#import <WebKit/WebBinHexDecoder.h>
 #import <WebKit/WebControllerPolicyDelegatePrivate.h>
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDownloadDecoder.h>
-#import <WebKit/WebDownloadHandler.h>
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebMacBinaryDecoder.h>
@@ -17,8 +19,6 @@
 #import <WebFoundation/WebError.h>
 #import <WebFoundation/WebResourceRequest.h>
 
-#define MinimumHeaderLength 8192
-
 @implementation WebDownloadHandler
 
 - initWithDataSource:(WebDataSource *)dSource
@@ -27,7 +27,10 @@
     
     dataSource = [dSource retain];
 
-    decoderClasses = [[NSArray arrayWithObjects:[WebMacBinaryDecoder class], nil] retain];
+    decoderClasses = [[NSArray arrayWithObjects:
+        [WebBinHexDecoder class],
+        [WebMacBinaryDecoder class],
+        nil] retain];
     
     LOG(Download, "Download started for: %s", [[[[dSource request] URL] absoluteString] cString]);
     return self;
@@ -53,21 +56,18 @@
         resourceForkData:(NSData **)resourceForkData
 {
     ASSERT(headerData);
+    ASSERT([headerData length]);
     ASSERT(dataForkData);
     ASSERT(resourceForkData);
     
-    NSObject <WebDownloadDecoder> *decoder;
-    BOOL didDecode;
     unsigned i;
+    for (i = 0; i < [decoderClasses count]; i++) {
+        Class decoderClass = [decoderClasses objectAtIndex:i];
 
-    for(i=0; i<[decoderClasses count]; i++){
-        Class DecoderClass = [decoderClasses objectAtIndex:i];
-
-        if([DecoderClass canDecodeHeaderData:headerData]){
-            decoder = [[[DecoderClass alloc] init] autorelease];
-            didDecode = [decoder decodeData:headerData dataForkData:dataForkData resourceForkData:resourceForkData];
-
-            if(!didDecode){
+        if ([decoderClass canDecodeHeaderData:headerData]) {
+            NSObject <WebDownloadDecoder> *decoder = [[[decoderClass alloc] init] autorelease];
+            BOOL didDecode = [decoder decodeData:headerData dataForkData:dataForkData resourceForkData:resourceForkData];
+            if (!didDecode) {
                 // Though the decoder said it could decode the header, actual decoding failed. Shouldn't happen.
                 ERROR("Download decoder \"%s\" failed to decode header even though it claimed to handle it.",
                       [[decoder className] lossyCString]);
@@ -91,21 +91,16 @@
     ASSERT(dataForkData);
     ASSERT(resourceForkData);
     
-    if(!decoderSequence){
+    if (!decoderSequence) {
         decoderSequence = [[NSMutableArray array] retain];
         [self decodeHeaderData:data dataForkData:dataForkData resourceForkData:resourceForkData];
-    }
-    else{
-
-        NSObject <WebDownloadDecoder> *decoder;
-        BOOL didDecode;
+    } else {
         unsigned i;
-        
-        for(i=0; i<[decoderSequence count]; i++){
-            decoder = [decoderSequence objectAtIndex:i];            
-            didDecode = [decoder decodeData:data dataForkData:dataForkData resourceForkData:resourceForkData];
+        for (i = 0; i< [decoderSequence count]; i++) {
+            NSObject <WebDownloadDecoder> *decoder = [decoderSequence objectAtIndex:i];            
+            BOOL didDecode = [decoder decodeData:data dataForkData:dataForkData resourceForkData:resourceForkData];
     
-            if(!didDecode){
+            if (!didDecode) {
                 return NO;
             }
             
@@ -113,7 +108,7 @@
         }
     }
 
-    if([decoderSequence count] == 0){
+    if ([decoderSequence count] == 0) {
         *dataForkData = data;
         *resourceForkData = nil;
     }
@@ -123,8 +118,14 @@
 
 - (void)closeFile
 {
-    FSCloseFork(dataForkRefNum);
-    FSCloseFork(resourceForkRefNum);
+    if (dataForkRefNum) {
+        FSCloseFork(dataForkRefNum);
+        dataForkRefNum = 0;
+    }
+    if (resourceForkRefNum) {
+        FSCloseFork(resourceForkRefNum);
+        resourceForkRefNum = 0;
+    }
 }
 
 - (void)cleanUpAfterFailure
@@ -140,7 +141,7 @@
 
 - (WebError *)createFileIfNecessary
 {
-    if(fileRefPtr){
+    if (fileRefPtr) {
         return nil;
     }
     
@@ -150,20 +151,20 @@
         
     NSString *filename = [lastDecoder filename];
 
-    if(filename){
+    if (filename) {
         path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename];
     }
 
-    if([fileManager fileExistsAtPath:path]){
+    if ([fileManager fileExistsAtPath:path]) {
         NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
         NSString *extension = [path pathExtension];
         NSString *pathWithAppendedNumber;
         unsigned i;
 
-        for(i=1; 1; i++){
+        for (i = 1; 1; i++) {
             pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtension, i];
             path = [pathWithAppendedNumber stringByAppendingPathExtension:extension];
-            if(![fileManager fileExistsAtPath:path]){
+            if (![fileManager fileExistsAtPath:path]) {
                 break;
             }
         }
@@ -171,7 +172,7 @@
 
     [[dataSource contentPolicy] _setPath:path];
 
-    if(![fileManager createFileAtPath:path contents:nil attributes:[lastDecoder fileAttributes]]){
+    if (![fileManager createFileAtPath:path contents:nil attributes:[lastDecoder fileAttributes]]) {
         ERROR("-[NSFileManager createFileAtPath:contents:attributes:] failed.");
         return [self errorWithCode:WebErrorCannotCreateFile];
     }
@@ -179,9 +180,9 @@
     [[NSWorkspace sharedWorkspace] noteFileSystemChanged:path];
 
     OSErr result = FSPathMakeRef([path UTF8String], &fileRef, nil);
-    if(result == noErr){
+    if (result == noErr) {
         fileRefPtr = &fileRef;
-    }else{
+    } else {
         ERROR("FSPathMakeRef failed.");
         [self cleanUpAfterFailure];
         return [self errorWithCode:WebErrorCannotCreateFile];
@@ -194,28 +195,28 @@
 {
     OSErr result;
     
-    if(*forkRefNum == 0){
+    if (*forkRefNum == 0) {
         HFSUniStr255 forkName;
-        if(forkRefNum == &dataForkRefNum){
+        if (forkRefNum == &dataForkRefNum) {
             result = FSGetDataForkName(&forkName);
-        }else{
+        } else {
             result = FSGetResourceForkName(&forkName);
         }
                 
-        if(result != noErr){
+        if (result != noErr) {
             ERROR("Couldn't get fork name of download file.");
             return NO;
         }
 
         result = FSOpenFork(fileRefPtr, forkName.length, forkName.unicode, fsWrPerm, forkRefNum);
-        if(result != noErr){
+        if (result != noErr) {
             ERROR("Couldn't open fork of download file.");
             return NO;
         }
     }
 
     result = FSWriteFork(*forkRefNum, fsAtMark, 0, [data length], [data bytes], NULL);
-    if(result != noErr){
+    if (result != noErr) {
         ERROR("Couldn't write to fork of download file.");
         return NO;
     }
@@ -226,21 +227,21 @@
 - (WebError *)writeDataForkData:(NSData *)dataForkData resourceForkData:(NSData *)resourceForkData
 {
     WebError *error = [self createFileIfNecessary];
-    if(error){
+    if (error) {
         return error;
     }
     
     BOOL didWrite = YES;
     
-    if(dataForkData && [dataForkData length]){
+    if ([dataForkData length]) {
         didWrite = [self writeData:dataForkData toFork:&dataForkRefNum];
     }
 
-    if(didWrite && resourceForkData && [resourceForkData length]){
+    if (didWrite && [resourceForkData length]) {
         didWrite = [self writeData:resourceForkData toFork:&resourceForkRefNum];
     }
 
-    if(!didWrite){
+    if (!didWrite) {
         ERROR("Writing to download file failed.");
         [self cleanUpAfterFailure];
         return [self errorWithCode:WebErrorCannotWriteToFile];
@@ -251,23 +252,23 @@
 
 - (NSData *)dataIfDoneBufferingData:(NSData *)data
 {
-    if(!bufferedData){
-        bufferedData = [[NSMutableData dataWithData:data] retain];
-    }else if([bufferedData length] == 0){
+    if (!bufferedData) {
+        bufferedData = [data mutableCopy];
+    } else if([bufferedData length] == 0) {
         // When bufferedData's length is 0, we're done buffering.
         return data;
-    }else{
+    } else {
         // Append new data. 
         [bufferedData appendData:data];
     }
 
-    if([bufferedData length] >= MinimumHeaderLength){
+    if ([bufferedData length] >= WEB_DOWNLOAD_DECODER_MINIMUM_HEADER_LENGTH) {
         // We've have enough now. Make a copy so we can set bufferedData's length to 0,
         // so we're know we're done buffering.
-        data = [NSData dataWithData:bufferedData];
+        data = [[bufferedData copy] autorelease];
         [bufferedData setLength:0];
         return data;
-    }else{
+    } else {
         // Keep buffering. The header is not big enough to determine the encoding sequence.
         return nil;
     }
@@ -277,26 +278,26 @@
 {
     ASSERT(data);
 
-    if([data length] == 0){
+    if ([data length] == 0) {
         // Workaround for 3093170.
         return nil;
     }
     
     data = [self dataIfDoneBufferingData:data];
-    if(!data){
+    if (!data) {
         return nil;
     }	
     
     NSData *dataForkData, *resourceForkData;
     
-    if(![self decodeData:data dataForkData:&dataForkData resourceForkData:&resourceForkData]){
+    if (![self decodeData:data dataForkData:&dataForkData resourceForkData:&resourceForkData]) {
         ERROR("Download decoding failed.");
         [self cleanUpAfterFailure];
         return [self errorWithCode:WebErrorDownloadDecodingFailedMidStream];
     }
 
     WebError *error = [self writeDataForkData:dataForkData resourceForkData:resourceForkData];
-    if(error){
+    if (error) {
         return error;
     }
 
@@ -308,9 +309,9 @@
     NSObject <WebDownloadDecoder> *decoder;
     unsigned i;
     
-    for(i=0; i<[decoderSequence count]; i++){
+    for (i = 0; i < [decoderSequence count]; i++) {
         decoder = [decoderSequence objectAtIndex:i];
-        if(![decoder finishDecoding]){
+        if (![decoder finishDecoding]) {
             return NO;
         }
     }
@@ -326,11 +327,11 @@
         return [self errorWithCode:WebErrorDownloadDecodingFailedToComplete];
     }
 
-    if([bufferedData length] > 0){
-        // All data has been buffered because we never received MinimumHeaderLength or more.
+    if ([bufferedData length]) {
+        // All data has been buffered because we never received the minimum header length.
         // Write it out now.
         WebError *error = [self writeDataForkData:bufferedData resourceForkData:nil];
-        if(error){
+        if (error) {
             return error;
         }
     }
@@ -341,8 +342,8 @@
     
     LOG(Download, "Download complete. Saved to: %s", [path cString]);
     
-    if([[dataSource contentPolicy] policyAction] == WebContentPolicySaveAndOpenExternally){
-        if(![[NSWorkspace sharedWorkspace] openFile:path]){
+    if ([[dataSource contentPolicy] policyAction] == WebContentPolicySaveAndOpenExternally) {
+        if (![[NSWorkspace sharedWorkspace] openFile:path]) {
             return [self errorWithCode:WebErrorCannotFindApplicationForFile];
         }
     }
@@ -355,5 +356,4 @@
     [self cleanUpAfterFailure];
 }
 
-
 @end
diff --git a/WebKit/Downloads.subproj/WebDownloadDecoder.h b/WebKit/Downloads.subproj/WebDownloadDecoder.h
index a35fc2a..875af21 100644
--- a/WebKit/Downloads.subproj/WebDownloadDecoder.h
+++ b/WebKit/Downloads.subproj/WebDownloadDecoder.h
@@ -9,6 +9,8 @@
 
 #include <Foundation/Foundation.h>
 
+#define WEB_DOWNLOAD_DECODER_MINIMUM_HEADER_LENGTH 8192
+
 @protocol WebDownloadDecoder <NSObject>
 
 // Returns YES if the decoder can decode headerData, NO otherwise.
@@ -29,6 +31,7 @@
 // fileAttributes is called after finishDecoding.
 - (NSDictionary *)fileAttributes;
 
+// Returns the decoded filename.
 - (NSString *)filename;
 
 @end
diff --git a/WebKit/Downloads.subproj/WebDownloadHandler.m b/WebKit/Downloads.subproj/WebDownloadHandler.m
index eb110bf..79232de 100644
--- a/WebKit/Downloads.subproj/WebDownloadHandler.m
+++ b/WebKit/Downloads.subproj/WebDownloadHandler.m
@@ -6,10 +6,12 @@
 //  Copyright (c) 2002 Apple Computer, Inc.
 //
 
+#import <WebKit/WebDownloadHandler.h>
+
+#import <WebKit/WebBinHexDecoder.h>
 #import <WebKit/WebControllerPolicyDelegatePrivate.h>
 #import <WebKit/WebDataSourcePrivate.h>
 #import <WebKit/WebDownloadDecoder.h>
-#import <WebKit/WebDownloadHandler.h>
 #import <WebKit/WebKitErrors.h>
 #import <WebKit/WebKitLogging.h>
 #import <WebKit/WebMacBinaryDecoder.h>
@@ -17,8 +19,6 @@
 #import <WebFoundation/WebError.h>
 #import <WebFoundation/WebResourceRequest.h>
 
-#define MinimumHeaderLength 8192
-
 @implementation WebDownloadHandler
 
 - initWithDataSource:(WebDataSource *)dSource
@@ -27,7 +27,10 @@
     
     dataSource = [dSource retain];
 
-    decoderClasses = [[NSArray arrayWithObjects:[WebMacBinaryDecoder class], nil] retain];
+    decoderClasses = [[NSArray arrayWithObjects:
+        [WebBinHexDecoder class],
+        [WebMacBinaryDecoder class],
+        nil] retain];
     
     LOG(Download, "Download started for: %s", [[[[dSource request] URL] absoluteString] cString]);
     return self;
@@ -53,21 +56,18 @@
         resourceForkData:(NSData **)resourceForkData
 {
     ASSERT(headerData);
+    ASSERT([headerData length]);
     ASSERT(dataForkData);
     ASSERT(resourceForkData);
     
-    NSObject <WebDownloadDecoder> *decoder;
-    BOOL didDecode;
     unsigned i;
+    for (i = 0; i < [decoderClasses count]; i++) {
+        Class decoderClass = [decoderClasses objectAtIndex:i];
 
-    for(i=0; i<[decoderClasses count]; i++){
-        Class DecoderClass = [decoderClasses objectAtIndex:i];
-
-        if([DecoderClass canDecodeHeaderData:headerData]){
-            decoder = [[[DecoderClass alloc] init] autorelease];
-            didDecode = [decoder decodeData:headerData dataForkData:dataForkData resourceForkData:resourceForkData];
-
-            if(!didDecode){
+        if ([decoderClass canDecodeHeaderData:headerData]) {
+            NSObject <WebDownloadDecoder> *decoder = [[[decoderClass alloc] init] autorelease];
+            BOOL didDecode = [decoder decodeData:headerData dataForkData:dataForkData resourceForkData:resourceForkData];
+            if (!didDecode) {
                 // Though the decoder said it could decode the header, actual decoding failed. Shouldn't happen.
                 ERROR("Download decoder \"%s\" failed to decode header even though it claimed to handle it.",
                       [[decoder className] lossyCString]);
@@ -91,21 +91,16 @@
     ASSERT(dataForkData);
     ASSERT(resourceForkData);
     
-    if(!decoderSequence){
+    if (!decoderSequence) {
         decoderSequence = [[NSMutableArray array] retain];
         [self decodeHeaderData:data dataForkData:dataForkData resourceForkData:resourceForkData];
-    }
-    else{
-
-        NSObject <WebDownloadDecoder> *decoder;
-        BOOL didDecode;
+    } else {
         unsigned i;
-        
-        for(i=0; i<[decoderSequence count]; i++){
-            decoder = [decoderSequence objectAtIndex:i];            
-            didDecode = [decoder decodeData:data dataForkData:dataForkData resourceForkData:resourceForkData];
+        for (i = 0; i< [decoderSequence count]; i++) {
+            NSObject <WebDownloadDecoder> *decoder = [decoderSequence objectAtIndex:i];            
+            BOOL didDecode = [decoder decodeData:data dataForkData:dataForkData resourceForkData:resourceForkData];
     
-            if(!didDecode){
+            if (!didDecode) {
                 return NO;
             }
             
@@ -113,7 +108,7 @@
         }
     }
 
-    if([decoderSequence count] == 0){
+    if ([decoderSequence count] == 0) {
         *dataForkData = data;
         *resourceForkData = nil;
     }
@@ -123,8 +118,14 @@
 
 - (void)closeFile
 {
-    FSCloseFork(dataForkRefNum);
-    FSCloseFork(resourceForkRefNum);
+    if (dataForkRefNum) {
+        FSCloseFork(dataForkRefNum);
+        dataForkRefNum = 0;
+    }
+    if (resourceForkRefNum) {
+        FSCloseFork(resourceForkRefNum);
+        resourceForkRefNum = 0;
+    }
 }
 
 - (void)cleanUpAfterFailure
@@ -140,7 +141,7 @@
 
 - (WebError *)createFileIfNecessary
 {
-    if(fileRefPtr){
+    if (fileRefPtr) {
         return nil;
     }
     
@@ -150,20 +151,20 @@
         
     NSString *filename = [lastDecoder filename];
 
-    if(filename){
+    if (filename) {
         path = [[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:filename];
     }
 
-    if([fileManager fileExistsAtPath:path]){
+    if ([fileManager fileExistsAtPath:path]) {
         NSString *pathWithoutExtension = [path stringByDeletingPathExtension];
         NSString *extension = [path pathExtension];
         NSString *pathWithAppendedNumber;
         unsigned i;
 
-        for(i=1; 1; i++){
+        for (i = 1; 1; i++) {
             pathWithAppendedNumber = [NSString stringWithFormat:@"%@-%d", pathWithoutExtension, i];
             path = [pathWithAppendedNumber stringByAppendingPathExtension:extension];
-            if(![fileManager fileExistsAtPath:path]){
+            if (![fileManager fileExistsAtPath:path]) {
                 break;
             }
         }
@@ -171,7 +172,7 @@
 
     [[dataSource contentPolicy] _setPath:path];
 
-    if(![fileManager createFileAtPath:path contents:nil attributes:[lastDecoder fileAttributes]]){
+    if (![fileManager createFileAtPath:path contents:nil attributes:[lastDecoder fileAttributes]]) {
         ERROR("-[NSFileManager createFileAtPath:contents:attributes:] failed.");
         return [self errorWithCode:WebErrorCannotCreateFile];
     }
@@ -179,9 +180,9 @@
     [[NSWorkspace sharedWorkspace] noteFileSystemChanged:path];
 
     OSErr result = FSPathMakeRef([path UTF8String], &fileRef, nil);
-    if(result == noErr){
+    if (result == noErr) {
         fileRefPtr = &fileRef;
-    }else{
+    } else {
         ERROR("FSPathMakeRef failed.");
         [self cleanUpAfterFailure];
         return [self errorWithCode:WebErrorCannotCreateFile];
@@ -194,28 +195,28 @@
 {
     OSErr result;
     
-    if(*forkRefNum == 0){
+    if (*forkRefNum == 0) {
         HFSUniStr255 forkName;
-        if(forkRefNum == &dataForkRefNum){
+        if (forkRefNum == &dataForkRefNum) {
             result = FSGetDataForkName(&forkName);
-        }else{
+        } else {
             result = FSGetResourceForkName(&forkName);
         }
                 
-        if(result != noErr){
+        if (result != noErr) {
             ERROR("Couldn't get fork name of download file.");
             return NO;
         }
 
         result = FSOpenFork(fileRefPtr, forkName.length, forkName.unicode, fsWrPerm, forkRefNum);
-        if(result != noErr){
+        if (result != noErr) {
             ERROR("Couldn't open fork of download file.");
             return NO;
         }
     }
 
     result = FSWriteFork(*forkRefNum, fsAtMark, 0, [data length], [data bytes], NULL);
-    if(result != noErr){
+    if (result != noErr) {
         ERROR("Couldn't write to fork of download file.");
         return NO;
     }
@@ -226,21 +227,21 @@
 - (WebError *)writeDataForkData:(NSData *)dataForkData resourceForkData:(NSData *)resourceForkData
 {
     WebError *error = [self createFileIfNecessary];
-    if(error){
+    if (error) {
         return error;
     }
     
     BOOL didWrite = YES;
     
-    if(dataForkData && [dataForkData length]){
+    if ([dataForkData length]) {
         didWrite = [self writeData:dataForkData toFork:&dataForkRefNum];
     }
 
-    if(didWrite && resourceForkData && [resourceForkData length]){
+    if (didWrite && [resourceForkData length]) {
         didWrite = [self writeData:resourceForkData toFork:&resourceForkRefNum];
     }
 
-    if(!didWrite){
+    if (!didWrite) {
         ERROR("Writing to download file failed.");
         [self cleanUpAfterFailure];
         return [self errorWithCode:WebErrorCannotWriteToFile];
@@ -251,23 +252,23 @@
 
 - (NSData *)dataIfDoneBufferingData:(NSData *)data
 {
-    if(!bufferedData){
-        bufferedData = [[NSMutableData dataWithData:data] retain];
-    }else if([bufferedData length] == 0){
+    if (!bufferedData) {
+        bufferedData = [data mutableCopy];
+    } else if([bufferedData length] == 0) {
         // When bufferedData's length is 0, we're done buffering.
         return data;
-    }else{
+    } else {
         // Append new data. 
         [bufferedData appendData:data];
     }
 
-    if([bufferedData length] >= MinimumHeaderLength){
+    if ([bufferedData length] >= WEB_DOWNLOAD_DECODER_MINIMUM_HEADER_LENGTH) {
         // We've have enough now. Make a copy so we can set bufferedData's length to 0,
         // so we're know we're done buffering.
-        data = [NSData dataWithData:bufferedData];
+        data = [[bufferedData copy] autorelease];
         [bufferedData setLength:0];
         return data;
-    }else{
+    } else {
         // Keep buffering. The header is not big enough to determine the encoding sequence.
         return nil;
     }
@@ -277,26 +278,26 @@
 {
     ASSERT(data);
 
-    if([data length] == 0){
+    if ([data length] == 0) {
         // Workaround for 3093170.
         return nil;
     }
     
     data = [self dataIfDoneBufferingData:data];
-    if(!data){
+    if (!data) {
         return nil;
     }	
     
     NSData *dataForkData, *resourceForkData;
     
-    if(![self decodeData:data dataForkData:&dataForkData resourceForkData:&resourceForkData]){
+    if (![self decodeData:data dataForkData:&dataForkData resourceForkData:&resourceForkData]) {
         ERROR("Download decoding failed.");
         [self cleanUpAfterFailure];
         return [self errorWithCode:WebErrorDownloadDecodingFailedMidStream];
     }
 
     WebError *error = [self writeDataForkData:dataForkData resourceForkData:resourceForkData];
-    if(error){
+    if (error) {
         return error;
     }
 
@@ -308,9 +309,9 @@
     NSObject <WebDownloadDecoder> *decoder;
     unsigned i;
     
-    for(i=0; i<[decoderSequence count]; i++){
+    for (i = 0; i < [decoderSequence count]; i++) {
         decoder = [decoderSequence objectAtIndex:i];
-        if(![decoder finishDecoding]){
+        if (![decoder finishDecoding]) {
             return NO;
         }
     }
@@ -326,11 +327,11 @@
         return [self errorWithCode:WebErrorDownloadDecodingFailedToComplete];
     }
 
-    if([bufferedData length] > 0){
-        // All data has been buffered because we never received MinimumHeaderLength or more.
+    if ([bufferedData length]) {
+        // All data has been buffered because we never received the minimum header length.
         // Write it out now.
         WebError *error = [self writeDataForkData:bufferedData resourceForkData:nil];
-        if(error){
+        if (error) {
             return error;
         }
     }
@@ -341,8 +342,8 @@
     
     LOG(Download, "Download complete. Saved to: %s", [path cString]);
     
-    if([[dataSource contentPolicy] policyAction] == WebContentPolicySaveAndOpenExternally){
-        if(![[NSWorkspace sharedWorkspace] openFile:path]){
+    if ([[dataSource contentPolicy] policyAction] == WebContentPolicySaveAndOpenExternally) {
+        if (![[NSWorkspace sharedWorkspace] openFile:path]) {
             return [self errorWithCode:WebErrorCannotFindApplicationForFile];
         }
     }
@@ -355,5 +356,4 @@
     [self cleanUpAfterFailure];
 }
 
-
 @end
diff --git a/WebKit/Downloads.subproj/WebMacBinaryDecoder.h b/WebKit/Downloads.subproj/WebMacBinaryDecoder.h
index b2dd751..dda8e6c 100644
--- a/WebKit/Downloads.subproj/WebMacBinaryDecoder.h
+++ b/WebKit/Downloads.subproj/WebMacBinaryDecoder.h
@@ -13,6 +13,8 @@
     int _offset;
     
     unsigned char _name[64];
+    ScriptCode _scriptCode;
+    
     int _dataForkLength;
     int _resourceForkLength;
     u_int32_t _creationDate;
diff --git a/WebKit/Downloads.subproj/WebMacBinaryDecoder.m b/WebKit/Downloads.subproj/WebMacBinaryDecoder.m
index b6140c7..1da5bf3 100644
--- a/WebKit/Downloads.subproj/WebMacBinaryDecoder.m
+++ b/WebKit/Downloads.subproj/WebMacBinaryDecoder.m
@@ -26,7 +26,7 @@
     }
     const u_int8_t *header = [headerData bytes];
 
-    // Version must be 0, also the zero fill byte at byte 74,
+    // Version must be 0, also the zero fill bytes at 74 and 82,
     // and the last two bytes of the header.
     if (header[0] || header[74] || header[82] || header[126] || header[127]) {
         return NO;
@@ -38,19 +38,29 @@
     }
 
     // And the CRC is the most important check.
-    if (((header[124] << 8) | header[125]) != CRC16(header, 124, 0)) {
-        // MacBinary I doesn't have a CRC. Make MacBinary I specific checks.
-
-        // 99-127 is 0 in MacBinary I
-        int i;
-        for(i=99; i<=127; i++){
-            if(header[i]){
-                return NO;
-            }
+    if (((header[124] << 8) | header[125]) == CRC16(header, 124, 0)) {
+        // CRC matches, so we have MacBinary II or III.
+        
+        // Version 129 is MacBinary II, and MacBinary III is compatible.
+        // If we see any other value here, it's something newer that we can't handle.
+        if (header[123] != 129) {
+            return NO;
         }
+        
+        return YES;
     }
+    
+    // MacBinary I doesn't have a CRC. So now we have to see if we have a MacBinary I file.
 
-    // FIXME: Specification says we should also check the minimum version at byte 123.
+    // Bytes 99-127 must be 0 in MacBinary I (already checked 126 and 127 above).
+    int i;
+    for (i = 99; i <= 125; i++) {
+        if (header[i]) {
+            return NO;
+        }
+    }
+    
+    // FIXME: The specification recommends also reality-checking the file lengths.
 
     return YES;
 }
@@ -85,6 +95,11 @@
         _resourceForkLength = (((((header[87] << 8) | header[88]) << 8) | header[89]) << 8) | header[90];
         _creationDate = (((((header[91] << 8) | header[92]) << 8) | header[93]) << 8) | header[94];
         _modificationDate = (((((header[95] << 8) | header[96]) << 8) | header[97]) << 8) | header[98];
+        
+        // MacBinary III.
+        if (header[102] == 'm' && header[103] == 'B' && header[104] == 'I' && header[105] == 'N') {
+            _scriptCode = header[106];
+        }
     }
     
     int dataForkStart = HEADER_SIZE;
@@ -141,9 +156,9 @@
 
 - (NSString *)filename
 {
-    // FIXME: We should use the encoding specified in the header if one is present.
-    return [(NSString *)CFStringCreateWithPascalString(NULL, _name, kCFStringEncodingMacRoman) autorelease];
+    // FIXME: We pass _scriptCode in here, but does CFString know how to handle all the script
+    // codes? What about when we have a bad script code? Is it OK to just return nil here?
+    return [(NSString *)CFStringCreateWithPascalString(NULL, _name, _scriptCode) autorelease];
 }
 
-
 @end
diff --git a/WebKit/WebKit.pbproj/project.pbxproj b/WebKit/WebKit.pbproj/project.pbxproj
index bb0d980..48c4b11 100644
--- a/WebKit/WebKit.pbproj/project.pbxproj
+++ b/WebKit/WebKit.pbproj/project.pbxproj
@@ -301,6 +301,7 @@
 				830A567403731461000C720C,
 				83413E8E0375BCD3004719BE,
 				83413E8F0375BCD3004719BE,
+				9316400E0379832D008635CE,
 			);
 			isa = PBXHeadersBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -411,6 +412,7 @@
 				830A567503731461000C720C,
 				83413E8A0375BCBE004719BE,
 				83413E900375BCD3004719BE,
+				9316400F0379832D008635CE,
 			);
 			isa = PBXSourcesBuildPhase;
 			runOnlyForDeploymentPostprocessing = 0;
@@ -1526,6 +1528,8 @@
 			children = (
 				83413E8B0375BCD3004719BE,
 				83413E890375BCBE004719BE,
+				9316400C0379832D008635CE,
+				9316400D0379832D008635CE,
 				832E26A1036F95CA005E2B4F,
 				832E26A3036F9614005E2B4F,
 				832E26A4036F9614005E2B4F,
@@ -1533,14 +1537,13 @@
 				83413E8D0375BCD3004719BE,
 			);
 			isa = PBXGroup;
-			name = Downloads;
+			path = Downloads.subproj;
 			refType = 4;
 		};
 		832E26A1036F95CA005E2B4F = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
-			name = WebDownloadDecoder.h;
-			path = Downloads.subproj/WebDownloadDecoder.h;
+			path = WebDownloadDecoder.h;
 			refType = 4;
 		};
 		832E26A2036F95CA005E2B4F = {
@@ -1552,15 +1555,13 @@
 		832E26A3036F9614005E2B4F = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
-			name = WebDownloadHandler.h;
-			path = Downloads.subproj/WebDownloadHandler.h;
+			path = WebDownloadHandler.h;
 			refType = 4;
 		};
 		832E26A4036F9614005E2B4F = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
-			name = WebDownloadHandler.m;
-			path = Downloads.subproj/WebDownloadHandler.m;
+			path = WebDownloadHandler.m;
 			refType = 4;
 		};
 		832E26A5036F9614005E2B4F = {
@@ -1614,8 +1615,7 @@
 		83413E890375BCBE004719BE = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
-			name = crc16.m;
-			path = Downloads.subproj/crc16.m;
+			path = crc16.m;
 			refType = 4;
 		};
 		83413E8A0375BCBE004719BE = {
@@ -1627,22 +1627,19 @@
 		83413E8B0375BCD3004719BE = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
-			name = crc16.h;
-			path = Downloads.subproj/crc16.h;
+			path = crc16.h;
 			refType = 4;
 		};
 		83413E8C0375BCD3004719BE = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
-			name = WebMacBinaryDecoder.h;
-			path = Downloads.subproj/WebMacBinaryDecoder.h;
+			path = WebMacBinaryDecoder.h;
 			refType = 4;
 		};
 		83413E8D0375BCD3004719BE = {
 			fileEncoding = 30;
 			isa = PBXFileReference;
-			name = WebMacBinaryDecoder.m;
-			path = Downloads.subproj/WebMacBinaryDecoder.m;
+			path = WebMacBinaryDecoder.m;
 			refType = 4;
 		};
 		83413E8E0375BCD3004719BE = {
@@ -1879,6 +1876,30 @@
 			settings = {
 			};
 		};
+		9316400C0379832D008635CE = {
+			fileEncoding = 4;
+			isa = PBXFileReference;
+			path = WebBinHexDecoder.h;
+			refType = 4;
+		};
+		9316400D0379832D008635CE = {
+			fileEncoding = 4;
+			isa = PBXFileReference;
+			path = WebBinHexDecoder.m;
+			refType = 4;
+		};
+		9316400E0379832D008635CE = {
+			fileRef = 9316400C0379832D008635CE;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
+		9316400F0379832D008635CE = {
+			fileRef = 9316400D0379832D008635CE;
+			isa = PBXBuildFile;
+			settings = {
+			};
+		};
 		931A72D203265920008635CE = {
 			fileEncoding = 4;
 			isa = PBXFileReference;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list