@@ -14,14 +14,13 @@ */ #include "config.h" #import "OFGZIPStream.h" -#import "OFInflateStream.h" +#import "OFCRC32.h" #import "OFDate.h" - -#import "crc32.h" +#import "OFInflateStream.h" #import "OFChecksumMismatchException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" @@ -50,12 +49,11 @@ @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; _stream = [stream retain]; - _operatingSystemMadeOn = - OF_GZIP_STREAM_OPERATING_SYSTEM_UNKNOWN; + _operatingSystemMadeOn = OFGZIPStreamOperatingSystemUnknown; _CRC32 = ~0; } @catch (id e) { [self release]; @throw e; } @@ -82,39 +80,39 @@ for (;;) { uint8_t byte; uint32_t CRC32, uncompressedSize; if (_stream.atEndOfStream) { - if (_state != OF_GZIP_STREAM_ID1) + if (_state != OFGZIPStreamStateID1) @throw [OFTruncatedDataException exception]; return 0; } switch (_state) { - case OF_GZIP_STREAM_ID1: - case OF_GZIP_STREAM_ID2: - case OF_GZIP_STREAM_COMPRESSION_METHOD: + case OFGZIPStreamStateID1: + case OFGZIPStreamStateID2: + case OFGZIPStreamStateCompressionMethod: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; - if ((_state == OF_GZIP_STREAM_ID1 && byte != 0x1F) || - (_state == OF_GZIP_STREAM_ID2 && byte != 0x8B) || - (_state == OF_GZIP_STREAM_COMPRESSION_METHOD && + if ((_state == OFGZIPStreamStateID1 && byte != 0x1F) || + (_state == OFGZIPStreamStateID2 && byte != 0x8B) || + (_state == OFGZIPStreamStateCompressionMethod && byte != 8)) @throw [OFInvalidFormatException exception]; _state++; break; - case OF_GZIP_STREAM_FLAGS: + case OFGZIPStreamStateFlags: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _flags = byte; _state++; break; - case OF_GZIP_STREAM_MODIFICATION_TIME: + case OFGZIPStreamStateModificationDate: _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 4 - _bytesRead]; if (_bytesRead < 4) @@ -129,26 +127,26 @@ (_buffer[1] << 8) | _buffer[0]]; _bytesRead = 0; _state++; break; - case OF_GZIP_STREAM_EXTRA_FLAGS: + case OFGZIPStreamStateExtraFlags: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _extraFlags = byte; _state++; break; - case OF_GZIP_STREAM_OPERATING_SYSTEM: + case OFGZIPStreamStateOperatingSystem: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _operatingSystemMadeOn = byte; _state++; break; - case OF_GZIP_STREAM_EXTRA_LENGTH: - if (!(_flags & OF_GZIP_STREAM_FLAG_EXTRA)) { + case OFGZIPStreamStateExtraLength: + if (!(_flags & OFGZIPStreamFlagExtra)) { _state += 2; break; } _bytesRead += [_stream @@ -160,11 +158,11 @@ _extraLength = (_buffer[1] << 8) | _buffer[0]; _bytesRead = 0; _state++; break; - case OF_GZIP_STREAM_EXTRA: + case OFGZIPStreamStateExtra: { char tmp[512]; size_t toRead = _extraLength - _bytesRead; if (toRead > 512) @@ -178,12 +176,12 @@ return 0; _bytesRead = 0; _state++; break; - case OF_GZIP_STREAM_NAME: - if (!(_flags & OF_GZIP_STREAM_FLAG_NAME)) { + case OFGZIPStreamStateName: + if (!(_flags & OFGZIPStreamFlagName)) { _state++; break; } do { @@ -192,12 +190,12 @@ return 0; } while (byte != 0); _state++; break; - case OF_GZIP_STREAM_COMMENT: - if (!(_flags & OF_GZIP_STREAM_FLAG_COMMENT)) { + case OFGZIPStreamStateComment: + if (!(_flags & OFGZIPStreamFlagComment)) { _state++; break; } do { @@ -206,12 +204,12 @@ return 0; } while (byte != 0); _state++; break; - case OF_GZIP_STREAM_HEADER_CRC16: - if (!(_flags & OF_GZIP_STREAM_FLAG_HEADER_CRC16)) { + case OFGZIPStreamStateHeaderCRC16: + if (!(_flags & OFGZIPStreamFlagHeaderCRC16)) { _state++; break; } _bytesRead += [_stream @@ -228,21 +226,21 @@ */ _bytesRead = 0; _state++; break; - case OF_GZIP_STREAM_DATA: + case OFGZIPStreamStateData: if (_inflateStream == nil) _inflateStream = [[OFInflateStream alloc] initWithStream: _stream]; if (!_inflateStream.atEndOfStream) { size_t bytesRead = [_inflateStream readIntoBuffer: buffer length: length]; - _CRC32 = of_crc32(_CRC32, buffer, bytesRead); + _CRC32 = OFCRC32(_CRC32, buffer, bytesRead); _uncompressedSize += bytesRead; return bytesRead; } @@ -249,11 +247,11 @@ [_inflateStream release]; _inflateStream = nil; _state++; break; - case OF_GZIP_STREAM_CRC32: + case OFGZIPStreamStateCRC32: _bytesRead += [_stream readIntoBuffer: _buffer length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; @@ -273,11 +271,11 @@ _bytesRead = 0; _CRC32 = ~0; _state++; break; - case OF_GZIP_STREAM_UNCOMPRESSED_SIZE: + case OFGZIPStreamStateUncompressedSize: _bytesRead += [_stream readIntoBuffer: _buffer length: 4 - _bytesRead]; uncompressedSize = ((uint32_t)_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]; @@ -292,11 +290,11 @@ expectedChecksum: expected]; } _bytesRead = 0; _uncompressedSize = 0; - _state = OF_GZIP_STREAM_ID1; + _state = OFGZIPStreamStateID1; break; } } } @@ -308,11 +306,11 @@ return _stream.atEndOfStream; } - (bool)hasDataInReadBuffer { - if (_state == OF_GZIP_STREAM_DATA) + if (_state == OFGZIPStreamStateData) return (super.hasDataInReadBuffer || _inflateStream.hasDataInReadBuffer); return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer); }