[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:56:59 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit e9af2294d3aa1d7a60da30bbaffc782e507fcb55
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Nov 4 18:58:10 2002 +0000

            * Downloads.subproj/WebMacBinaryDecoder.h: Removed many unneeded fields.
            * Downloads.subproj/WebMacBinaryDecoder.m:
            (+[WebMacBinaryDecoder canDecodeHeaderData:]): Added comments. Changed maximum filename
    	length to 63 as the format supports, rather than the 31 that's based on historical
    	HFS limitations. Fix endian dependency in CRC check.
            (-[WebMacBinaryDecoder decodeData:dataForkData:resourceForkData:]): Simplified this,
    	and removed the state machine and the accumulator. Also added some asserts. Fixed endian
    	dependency in the code to extract the header.
            (-[WebMacBinaryDecoder finishDecoding]): New simpler check now that we don't have a
    	_streamComplete boolean.
            (-[WebMacBinaryDecoder fileAttributes]): Rewrote to take advantage of the above changes,
    	and also to use kCFAbsoluteTimeIntervalSince1904 rather than parsing a date string.
    
            * Downloads.subproj/crc16.h: Tweaks.
            * Downloads.subproj/crc16.m: Tweaks.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2551 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 4afa97f..08cda98 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,5 +1,23 @@
 2002-11-04  Darin Adler  <darin at apple.com>
 
+        * Downloads.subproj/WebMacBinaryDecoder.h: Removed many unneeded fields.
+        * Downloads.subproj/WebMacBinaryDecoder.m:
+        (+[WebMacBinaryDecoder canDecodeHeaderData:]): Added comments. Changed maximum filename
+	length to 63 as the format supports, rather than the 31 that's based on historical
+	HFS limitations. Fix endian dependency in CRC check.
+        (-[WebMacBinaryDecoder decodeData:dataForkData:resourceForkData:]): Simplified this,
+	and removed the state machine and the accumulator. Also added some asserts. Fixed endian
+	dependency in the code to extract the header.
+        (-[WebMacBinaryDecoder finishDecoding]): New simpler check now that we don't have a
+	_streamComplete boolean.
+        (-[WebMacBinaryDecoder fileAttributes]): Rewrote to take advantage of the above changes,
+	and also to use kCFAbsoluteTimeIntervalSince1904 rather than parsing a date string.
+
+        * Downloads.subproj/crc16.h: Tweaks.
+        * Downloads.subproj/crc16.m: Tweaks.
+
+2002-11-04  Darin Adler  <darin at apple.com>
+
         * WebCoreSupport.subproj/WebImageRenderer.m: (-[WebImageRenderer dealloc]):
 	Replaced a useless call to stopAnimation with a couple of asserts.
 
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index 4afa97f..08cda98 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,5 +1,23 @@
 2002-11-04  Darin Adler  <darin at apple.com>
 
+        * Downloads.subproj/WebMacBinaryDecoder.h: Removed many unneeded fields.
+        * Downloads.subproj/WebMacBinaryDecoder.m:
+        (+[WebMacBinaryDecoder canDecodeHeaderData:]): Added comments. Changed maximum filename
+	length to 63 as the format supports, rather than the 31 that's based on historical
+	HFS limitations. Fix endian dependency in CRC check.
+        (-[WebMacBinaryDecoder decodeData:dataForkData:resourceForkData:]): Simplified this,
+	and removed the state machine and the accumulator. Also added some asserts. Fixed endian
+	dependency in the code to extract the header.
+        (-[WebMacBinaryDecoder finishDecoding]): New simpler check now that we don't have a
+	_streamComplete boolean.
+        (-[WebMacBinaryDecoder fileAttributes]): Rewrote to take advantage of the above changes,
+	and also to use kCFAbsoluteTimeIntervalSince1904 rather than parsing a date string.
+
+        * Downloads.subproj/crc16.h: Tweaks.
+        * Downloads.subproj/crc16.m: Tweaks.
+
+2002-11-04  Darin Adler  <darin at apple.com>
+
         * WebCoreSupport.subproj/WebImageRenderer.m: (-[WebImageRenderer dealloc]):
 	Replaced a useless call to stopAnimation with a couple of asserts.
 
diff --git a/WebKit/Downloads.subproj/WebMacBinaryDecoder.h b/WebKit/Downloads.subproj/WebMacBinaryDecoder.h
index 88b99af..f4b851f 100644
--- a/WebKit/Downloads.subproj/WebMacBinaryDecoder.h
+++ b/WebKit/Downloads.subproj/WebMacBinaryDecoder.h
@@ -3,26 +3,24 @@
 //
 //  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
 //
-#import <Foundation/Foundation.h>
 
-#import <WebKit/WebDownloadDecoder.h>
+#import <Foundation/Foundation.h>
 
+ at protocol WebDownloadDecoder;
 
 @interface WebMacBinaryDecoder : NSObject <WebDownloadDecoder>
 {
-    int			_state;
-    long		_dataLen;
-    long		_rsrcLen;
-    long		_rsrcStart;
-    long		_commentStart;
-    long		_curOffset;
-    u_int32_t		_dateBlock[2];
-    u_int32_t		_fInfo[4];
-    char		_comment[256];
-    char		_name[32];
-    NSMutableData	*_accumulator;
-    BOOL		_streamComplete;
-}
-
+    int _offset;
+    
+    char _name[64];
+    int _dataForkLength;
+    int _resourceForkLength;
+    int _commentLength;
+    u_int32_t _creationDate;
+    u_int32_t _modificationDate;
+    OSType _fileType;
+    OSType _fileCreator;
 
+    int _commentEnd;
+}
 @end
diff --git a/WebKit/Downloads.subproj/WebMacBinaryDecoder.m b/WebKit/Downloads.subproj/WebMacBinaryDecoder.m
index a1d63a3..35dcc92 100644
--- a/WebKit/Downloads.subproj/WebMacBinaryDecoder.m
+++ b/WebKit/Downloads.subproj/WebMacBinaryDecoder.m
@@ -4,23 +4,24 @@
 //  Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
 //
 
-#import <string.h>
-#import <sys/types.h>
-#import "crc16.h"
-#import <WebKit/WebMacBinaryDecoder.h>
+// This decoder decodes MacBinary II and might also work for MacBinary III.
+// There's also MacBinary I, which we do not attempt to support.
 
+#import <WebKit/WebMacBinaryDecoder.h>
 
-#define HEADER_ST		0
-#define RESOURCE_ST		1
-#define DATA_ST			2
-#define COMMENT_ST		3
-#define EXTRA_ST		4
-
-#define MB_HDR_SIZE		128
+#import "crc16.h"
+#import <WebFoundation/WebAssertions.h>
+#import <WebKit/WebDownloadDecoder.h>
 
-#undef MIN
-#define MIN(A,B)		((A) < (B) ? (A) : (B))
+#define HEADER_SIZE 128
 
+enum {
+    readingHeader,
+    readingDataFork,
+    skippingToResourceFork,
+    readingResourceFork,
+    finished
+};
 
 @implementation WebMacBinaryDecoder
 
@@ -28,215 +29,113 @@
 // Header data is the first 8KB or larger chunk of received data.
 + (BOOL)canDecodeHeaderData:(NSData *)headerData
 {
-    const u_int8_t	*streamPtr;
-    u_int32_t		crc;
-    
-    if ([headerData length] < MB_HDR_SIZE) return NO;
-    streamPtr = [headerData bytes];
-    if (streamPtr[0] || streamPtr[74] || streamPtr[126] || streamPtr[127]) return NO;
-    if (!streamPtr[1] || streamPtr[1] > 31) return NO;
-    crc = CRC16(streamPtr, 124, 0);
-    if (*(u_int16_t *)(streamPtr + 124) != crc) return NO;
-    return YES;
-}
-
+    if ([headerData length] < HEADER_SIZE) {
+        return NO;
+    }
+    const u_int8_t *header = [headerData bytes];
 
+    // Version must be 0, also the zero fill byte at byte 74,
+    // and the last two bytes of the header.
+    if (header[0] || header[74] || header[126] || header[127]) {
+        return NO;
+    }
 
-- (id)init 
-{
-    self = [super init];
-    if (self) {
-        _accumulator = [[NSMutableData alloc] init];
-        _comment[0] = 0;
-        _state = HEADER_ST;
-        _streamComplete = NO;
+    // Name length must be a reasonable value (between 1 and 63).
+    if (!header[1] || header[1] > 63) {
+        return NO;
     }
-    return self;
-}
 
+    // And the CRC is the most important check.
+    if (((header[124] << 8) | header[125]) != CRC16(header, 124, 0)) {
+        return NO;
+    }
 
+    // FIXME: Specification says we should also check the minimum version at byte 123.
 
-- (void)dealloc
-{
-    [_accumulator release];
-    [super dealloc];
+    return YES;
 }
 
-
-
 // Decodes data and sets dataForkData and resourceForkData with the decoded data.
 // dataForkData and/or resourceForkData and can be set to nil if there is no data to decode.
 // This method will be called repeatedly with every chunk of received data. 
 // Returns YES if no errors have occurred, NO otherwise.
 - (BOOL)decodeData:(NSData *)data dataForkData:(NSData **)dataForkData resourceForkData:(NSData **)resourceForkData
 {
-    BOOL		ret;
-    const u_int8_t	*curP;
-    long		forkEnd;
-    long		writeBytes;
-    long		bytesLeft;
-    int32_t		gap;
-    NSMutableData	*tempData;
-    
-    ret = NO;
-    if (!dataForkData || !resourceForkData) goto exit;
-    ret = YES;
+    ASSERT(data);
+    ASSERT([data length]);
+    ASSERT(dataForkData);
+    ASSERT(resourceForkData);
+    ASSERT(_offset + [data length] >= HEADER_SIZE);
+
     *dataForkData = nil;
     *resourceForkData = nil;
-    [_accumulator appendData:data];
-    while (1) {
-        switch (_state) {
-        case HEADER_ST:
-            // If there's not enough data for the whole header, we'll return
-            // and wait for more to show up.
-            ret = YES;
-            if ([_accumulator length] < MB_HDR_SIZE) goto exit;
+    
+    int dataLength = [data length];
+    
+    // Handle the header by extracting the fields we want, in an endian-independent way.
+    if (_offset == 0) {
+        const u_int8_t *header = [data bytes];
         
-            // Extract the fields we want
-            curP = [_accumulator bytes];
-            curP++;
-            memcpy(_name, curP, *curP + 1);			// Copy the name
-            curP += 64;
-            memcpy(_fInfo, curP, 16);				// Copy the FInfo
-            curP += 16;
-            curP += 2;						// Skip "protect" bit
-            memcpy(&_dataLen, curP, 4);				// Get the data fork length
-            curP += 4;
-            memcpy(&_rsrcLen, curP, 4);				// Get the resource fork length
-            curP += 4;
-            memcpy(_dateBlock, curP, 8);			// Get the dates
-            curP += 8;
-            memcpy(&_comment[0], curP + 1, 1);			// Get the comment length
-            curP += 2;
-            memcpy((char *)_fInfo + 9, curP, 1);		// Get Finder flags
-            curP += 27;
-            _rsrcStart = MB_HDR_SIZE + ((_dataLen + 127) & 0xFFFFFF80);
-            _commentStart = _rsrcStart + ((_rsrcLen + 127) & 0xFFFFFF80);
-            
-            // Purge the header from the accumulator
-            tempData = [[NSMutableData alloc] initWithBytes:curP length:([_accumulator length] - MB_HDR_SIZE)];
-            [_accumulator release];
-            _accumulator = tempData;
-            _curOffset = MB_HDR_SIZE;
-            _state = DATA_ST;
-            break;
-                        
-        case DATA_ST:
-            forkEnd = MB_HDR_SIZE + _dataLen;
-            bytesLeft = forkEnd - _curOffset;
-            writeBytes = MIN((long)[_accumulator length], bytesLeft);
-            *dataForkData = [NSData dataWithBytes:[_accumulator bytes] length:writeBytes];
-            _curOffset += writeBytes;
-            if ((long)[_accumulator length] >= bytesLeft) {
-                tempData = [[NSMutableData alloc] initWithBytes:((char *)[_accumulator bytes] + writeBytes) length:([_accumulator length] - writeBytes)];
-                [_accumulator release];
-                _accumulator = tempData;
-                _state = RESOURCE_ST;
-            } else {
-                [_accumulator setLength:0];
-                goto exit;
-            }
-            break;
-                
-        case RESOURCE_ST:
-            gap = _rsrcStart - _curOffset;
-            if (gap > 0) {
-                if ((int32_t)[_accumulator length] < gap) {
-                    _curOffset += [_accumulator length];
-                    [_accumulator setLength:0];
-                    goto exit;
-                } else {
-                    tempData = [[NSMutableData alloc] initWithBytes:((char *)[_accumulator bytes] + gap) length:([_accumulator length] - gap)];
-                    [_accumulator release];
-                    _accumulator = tempData;
-                    _curOffset += gap;
-                }
-            }
-            forkEnd = _rsrcStart + _rsrcLen;
-            bytesLeft = forkEnd - _curOffset;
-            writeBytes = MIN((long)[_accumulator length], bytesLeft);
-            if (writeBytes) {
-                *resourceForkData = [NSData dataWithBytes:[_accumulator bytes] length:writeBytes];
-            }
-            _curOffset += writeBytes;
-            if ((long)[_accumulator length] >= bytesLeft) {
-                tempData = [[NSMutableData alloc] initWithBytes:((char *)[_accumulator bytes] + writeBytes) length:([_accumulator length] - writeBytes)];
-                [_accumulator release];
-                _accumulator = tempData;
-                _state = COMMENT_ST;
-            } else {
-                [_accumulator setLength:0];
-                goto exit;
-            }
-            break;
-                        
-        case COMMENT_ST:
-            gap = _commentStart - _curOffset;
-            if (gap > 0) {
-                if ((int32_t)[_accumulator length] < gap) {
-                    _curOffset += [_accumulator length];
-                    [_accumulator setLength:0];
-                    goto exit;
-                } else {
-                    tempData = [[NSMutableData alloc] initWithBytes:((char *)[_accumulator bytes] + gap) length:([_accumulator length] - gap)];
-                    [_accumulator release];
-                    _accumulator = tempData;
-                    _curOffset += gap;
-                }
-            }
-            // Wait until we receive the whole comment
-            if ((char)[_accumulator length] < _comment[0]) goto exit;
-            memcpy(_comment + 1, [_accumulator bytes], _comment[0]);
-            _streamComplete = YES;
-            
-            // Now throw out any extra data and set the state so
-            // that we just throw away anything we receive
-            [_accumulator setLength:0];
-            _state = EXTRA_ST;
-            goto exit;
-            break;
-                        
-        case EXTRA_ST:
-            [_accumulator setLength:0];
-            goto exit;
-            break;
-        }
+        ASSERT(header[1] <= sizeof(_name));
+        memcpy(_name, header + 1, header[1]);	// Copy the name
+        _fileType = (((((header[65] << 8) | header[66]) << 8) | header[67]) << 8) | header[68];
+        _fileCreator = (((((header[69] << 8) | header[70]) << 8) | header[71]) << 8) | header[72];
+        _dataForkLength = (((((header[83] << 8) | header[84]) << 8) | header[85]) << 8) | header[86];
+        _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];
+        _commentLength = (header[99] << 8) | header[100];
+    }
+    
+    int dataForkStart = HEADER_SIZE;
+    int dataForkEnd = dataForkStart + _dataForkLength;
+    int resourceForkStart = (dataForkEnd + 0x7F) & ~0x7F;
+    int resourceForkEnd = resourceForkStart + _resourceForkLength;
+    int commentStart = (resourceForkEnd + 0x7F) & ~0x7F;
+    _commentEnd = commentStart + _commentLength;
+
+    // Check for a piece of available data fork.
+    if (_dataForkLength && _offset < dataForkEnd && _offset + dataLength > dataForkStart) {
+        int start = MAX(dataForkStart - _offset, 0);
+        int end = MIN(dataForkEnd - _offset, dataLength);
+        ASSERT(end > start);
+        *dataForkData = [data subdataWithRange:NSMakeRange(start, end - start)];
     }
-	
-exit:
-	return ret;
-}
 
+    // Check for a piece of available resource fork.
+    if (_resourceForkLength && _offset < resourceForkEnd && _offset + dataLength > resourceForkStart) {
+        int start = MAX(resourceForkStart - _offset, 0);
+        int end = MIN(resourceForkEnd - _offset, dataLength);
+        ASSERT(end > start);
+        *resourceForkData = [data subdataWithRange:NSMakeRange(start, end - start)];
+    }
+    
+    _offset += dataLength;
 
+    return YES;
+}
 
 // Returns YES if decoding successfully finished, NO otherwise.
 - (BOOL)finishDecoding
 {
-    return _streamComplete;
+    return _offset >= _commentEnd;
 }
 
-
-
 // Returns a dictionary of 4 file attributes. The attributes (as defined in NSFileManager.h) are:
 // NSFileModificationDate, NSFileHFSCreatorCode, NSFileHFSTypeCode, NSFileCreationDate
 // fileAttributes is called after finishDecoding.
 - (NSDictionary *)fileAttributes
 {
-    NSDate		*crDate;
-    NSDate		*modDate;
-    NSNumber		*type;
-    NSNumber		*creator;
+    ASSERT(_offset >= HEADER_SIZE);
     
-    crDate = [[NSDate dateWithString:@"1904-01-01 00:00:00 +0000"] addTimeInterval:_dateBlock[0]];
-    modDate = [[NSDate dateWithString:@"1904-01-01 00:00:00 +0000"] addTimeInterval:_dateBlock[1]];
-    type = [NSNumber numberWithUnsignedLong:_fInfo[0]];
-    creator = [NSNumber numberWithUnsignedLong:_fInfo[1]];
-    return [NSDictionary dictionaryWithObjectsAndKeys:crDate, NSFileCreationDate,
-                                                      modDate, NSFileModificationDate,
-                                                      type, NSFileHFSTypeCode,
-                                                      creator, NSFileHFSCreatorCode,
-                                                      nil];
+    // FIXME: What about the name?
+    // FIXME: What about other parts of Finder info? Bundle bit, for example.
+    return [NSDictionary dictionaryWithObjectsAndKeys:
+        [NSDate dateWithTimeIntervalSinceReferenceDate:kCFAbsoluteTimeIntervalSince1904 + _creationDate], NSFileCreationDate,
+        [NSDate dateWithTimeIntervalSinceReferenceDate:kCFAbsoluteTimeIntervalSince1904 + _modificationDate], NSFileModificationDate,
+        [NSNumber numberWithUnsignedLong:_fileType], NSFileHFSTypeCode,
+        [NSNumber numberWithUnsignedLong:_fileCreator], NSFileHFSCreatorCode,
+        nil];
 }
 
-
 @end
diff --git a/WebKit/Downloads.subproj/crc16.h b/WebKit/Downloads.subproj/crc16.h
index 1785d04..f4d49a9 100644
--- a/WebKit/Downloads.subproj/crc16.h
+++ b/WebKit/Downloads.subproj/crc16.h
@@ -5,7 +5,4 @@
 
 u_int16_t CRC16(const u_int8_t *p, u_int32_t len, u_int16_t seed);
 
-
-
-
 #endif
diff --git a/WebKit/Downloads.subproj/crc16.m b/WebKit/Downloads.subproj/crc16.m
index 10c6b95..6d861d6 100644
--- a/WebKit/Downloads.subproj/crc16.m
+++ b/WebKit/Downloads.subproj/crc16.m
@@ -1,4 +1,3 @@
-#include <sys/types.h>
 #include "crc16.h"
 
 static const u_int16_t gMagic[] = {
@@ -45,18 +44,11 @@ static const u_int16_t gMagic[] = {
  */
 u_int16_t CRC16(const u_int8_t *p, u_int32_t len, u_int16_t seed)
 {
-	u_int16_t	reg;				/* crc computed so far */
-	u_int32_t	i;
-
-	reg = seed;				/* start with seed */
-//	while (len--) {
-//		reg = (reg << 8) ^ gMagic[(reg >> 8) ^ *p++];
-//	}
-	for (i = 0; i < len; i++, p++)
-	{
-		reg ^= (*p << 8);
-		reg = (reg << 8) ^ gMagic[(u_int8_t)(reg >> 8)];
-  	}
-
-	return (reg);
-} /* CRC16() */
+    u_int16_t crc = seed;
+    u_int32_t i;
+    for (i = 0; i < len; i++, p++) {
+        crc ^= (*p << 8);
+        crc = (crc << 8) ^ gMagic[(u_int8_t)(crc >> 8)];
+    }
+    return crc;
+}

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list