ObjFW  Check-in [adf754d5fc]

Overview
Comment:Move of_zip_archive_find_extra_field()

This belongs to OFZIPArchiveEntry. Consequently, it has been renamed to
of_zip_archive_entry_find_extra_field() and made public, so that it can
be used by applications that got the extra field from the
OFZIPArchiveEntry.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: adf754d5fc291945c4c23c3b3916e9e229c2b4ce44a317bf5f99a40d9be3a72d
User & Date: js on 2014-05-25 22:58:08
Other Links: manifest | tags
Context
2014-05-25
23:10
OFZIP: Fix q missing in first line of help check-in: 03db213022 user: js tags: trunk
22:58
Move of_zip_archive_find_extra_field() check-in: adf754d5fc user: js tags: trunk
12:05
Update buildsys check-in: eeaa49c11a user: js tags: trunk
Changes

Modified src/OFZIPArchive.m from [85d6f8f249] to [3ed67d1bc6].

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
}

- initWithArchiveFile: (OFString*)path
	       offset: (off_t)offset
      localFileHeader: (OFZIPArchive_LocalFileHeader*)localFileHeader;
@end

void
of_zip_archive_find_extra_field(OFDataArray *extraField, uint16_t tag,
    uint8_t **data, uint16_t *size)
{
	uint8_t *bytes;
	size_t i, count;

	bytes = [extraField items];
	count = [extraField count];

	for (i = 0; i < count;) {
		uint16_t currentTag, currentSize;

		if (i + 3 >= count)
			@throw [OFInvalidFormatException exception];

		currentTag = (bytes[i + 1] << 8) | bytes[i];
		currentSize = (bytes[i + 3] << 8) | bytes[i + 2];

		if (i + 3 + currentSize >= count)
			@throw [OFInvalidFormatException exception];

		if (currentTag == tag) {
			*data = bytes + i + 4;
			*size = currentSize;
			return;
		}

		i += 4 + currentSize;
	}

	*data = NULL;
	*size = 0;
}

uint32_t
of_zip_archive_read_field32(uint8_t **data, uint16_t *size)
{
	uint32_t field = 0;
	uint_fast8_t i;

	if (*size < 4)







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







81
82
83
84
85
86
87



































88
89
90
91
92
93
94
}

- initWithArchiveFile: (OFString*)path
	       offset: (off_t)offset
      localFileHeader: (OFZIPArchive_LocalFileHeader*)localFileHeader;
@end




































uint32_t
of_zip_archive_read_field32(uint8_t **data, uint16_t *size)
{
	uint32_t field = 0;
	uint_fast8_t i;

	if (*size < 4)
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
		    : OF_STRING_ENCODING_CODEPAGE_437);

		_fileName = [[file readStringWithLength: fileNameLength
					       encoding: encoding] copy];
		_extraField = [[file
		    readDataArrayWithCount: extraFieldLength] retain];

		of_zip_archive_find_extra_field(_extraField, 0x0001,
		    &ZIP64, &ZIP64Size);

		if (ZIP64 != NULL) {
			if (_uncompressedSize == 0xFFFFFFFF)
				_uncompressedSize = of_zip_archive_read_field64(
				    &ZIP64, &ZIP64Size);
			if (_compressedSize == 0xFFFFFFFF)







|







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
		    : OF_STRING_ENCODING_CODEPAGE_437);

		_fileName = [[file readStringWithLength: fileNameLength
					       encoding: encoding] copy];
		_extraField = [[file
		    readDataArrayWithCount: extraFieldLength] retain];

		of_zip_archive_entry_find_extra_field(_extraField, 0x0001,
		    &ZIP64, &ZIP64Size);

		if (ZIP64 != NULL) {
			if (_uncompressedSize == 0xFFFFFFFF)
				_uncompressedSize = of_zip_archive_read_field64(
				    &ZIP64, &ZIP64Size);
			if (_compressedSize == 0xFFFFFFFF)

Modified src/OFZIPArchiveEntry.h from [0557ab49b8] to [5c2f6096e1].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"

#include <stdio.h>

@class OFString;
@class OFDataArray;
@class OFFile;
@class OFDate;

/*!







|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"

/*! @file */

@class OFString;
@class OFDataArray;
@class OFFile;
@class OFDate;

/*!
98
99
100
101
102
103
104

















/*!
 * @brief Returns the extra field of the entry.
 *
 * @return The extra field of the entry
 */
- (OFDataArray*)extraField;
@end
























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*!
 * @brief Returns the extra field of the entry.
 *
 * @return The extra field of the entry
 */
- (OFDataArray*)extraField;
@end

#ifdef __cplusplus
extern "C" {
#endif
/*!
 * @brief Gets a pointer to and the size of the extra field with the specified
 *	  tag.
 *
 * @param data A pointer to a pointer that should be set to the start of the
 *	       extra field with the specified tag
 * @param size A pointer to an uint16_t that should be set to the size
 */
extern void of_zip_archive_entry_find_extra_field(OFDataArray *extraField,
    uint16_t tag, uint8_t **data, uint16_t *size);
#ifdef __cplusplus
}
#endif

Modified src/OFZIPArchiveEntry.m from [fabe910a28] to [0a34c90b44].

25
26
27
28
29
30
31
32
33
34
35



































36
37
38
39
40
41
42

#import "autorelease.h"
#import "macros.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"

extern void of_zip_archive_find_extra_field(OFDataArray*, uint16_t, uint8_t**,
    uint16_t*);
extern uint32_t of_zip_archive_read_field32(uint8_t**, uint16_t*);
extern uint64_t of_zip_archive_read_field64(uint8_t**, uint16_t*);




































@implementation OFZIPArchiveEntry
- (instancetype)OF_initWithFile: (OFFile*)file
{
	self = [super init];

	@try {







<
<


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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

#import "autorelease.h"
#import "macros.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"



extern uint32_t of_zip_archive_read_field32(uint8_t**, uint16_t*);
extern uint64_t of_zip_archive_read_field64(uint8_t**, uint16_t*);

void
of_zip_archive_entry_find_extra_field(OFDataArray *extraField, uint16_t tag,
    uint8_t **data, uint16_t *size)
{
	uint8_t *bytes;
	size_t i, count;

	bytes = [extraField items];
	count = [extraField count];

	for (i = 0; i < count;) {
		uint16_t currentTag, currentSize;

		if (i + 3 >= count)
			@throw [OFInvalidFormatException exception];

		currentTag = (bytes[i + 1] << 8) | bytes[i];
		currentSize = (bytes[i + 3] << 8) | bytes[i + 2];

		if (i + 3 + currentSize >= count)
			@throw [OFInvalidFormatException exception];

		if (currentTag == tag) {
			*data = bytes + i + 4;
			*size = currentSize;
			return;
		}

		i += 4 + currentSize;
	}

	*data = NULL;
	*size = 0;
}

@implementation OFZIPArchiveEntry
- (instancetype)OF_initWithFile: (OFFile*)file
{
	self = [super init];

	@try {
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
		_fileName = [[file readStringWithLength: fileNameLength
					       encoding: encoding] copy];
		_extraField = [[file
		    readDataArrayWithCount: extraFieldLength] retain];
		_fileComment = [[file readStringWithLength: fileCommentLength
						  encoding: encoding] copy];

		of_zip_archive_find_extra_field(_extraField, 0x0001,
		    &ZIP64, &ZIP64Size);

		if (ZIP64 != NULL) {
			if (_uncompressedSize == 0xFFFFFFFF)
				_uncompressedSize = of_zip_archive_read_field64(
				    &ZIP64, &ZIP64Size);
			if (_compressedSize == 0xFFFFFFFF)







|







106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
		_fileName = [[file readStringWithLength: fileNameLength
					       encoding: encoding] copy];
		_extraField = [[file
		    readDataArrayWithCount: extraFieldLength] retain];
		_fileComment = [[file readStringWithLength: fileCommentLength
						  encoding: encoding] copy];

		of_zip_archive_entry_find_extra_field(_extraField, 0x0001,
		    &ZIP64, &ZIP64Size);

		if (ZIP64 != NULL) {
			if (_uncompressedSize == 0xFFFFFFFF)
				_uncompressedSize = of_zip_archive_read_field64(
				    &ZIP64, &ZIP64Size);
			if (_compressedSize == 0xFFFFFFFF)