ObjFW  Check-in [2481bede45]

Overview
Comment:Add of-gzip: URI handler
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2481bede459ead0d58bed6c673c6b3063a8a5264316d9548a8373decb2f336c1
User & Date: js on 2022-10-04 22:12:08
Other Links: manifest | tags
Context
2022-10-04
22:22
OF*Archive: Share +[URIForFile:inArchive:] code check-in: 519c277156 user: js tags: trunk
22:12
Add of-gzip: URI handler check-in: 2481bede45 user: js tags: trunk
21:49
Add of-tar: URI handler check-in: 4f56311b57 user: js tags: trunk
Changes

Modified src/Makefile from [d59b367af0] to [6f0c9c9452].

180
181
182
183
184
185
186

187
188
189
190
191
192
193
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194







+







	OFBase64.m			\
	OFBitSetCharacterSet.m		\
	OFBytesValue.m			\
	OFCRC16.m			\
	OFCRC32.m			\
	OFCountedMapTableSet.m		\
	OFEmbeddedURIHandler.m		\
	OFGZIPURIHandler.m		\
	OFHuffmanTree.m			\
	OFINIFileSettings.m		\
	OFInvertedCharacterSet.m	\
	OFLHADecompressingStream.m	\
	OFMapTableDictionary.m		\
	OFMapTableSet.m			\
	OFMutableAdjacentArray.m	\

Added src/OFGZIPURIHandler.h version [f833858668].
























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * 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 "OFURIHandler.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFGZIPURIHandler: OFURIHandler
@end

OF_ASSUME_NONNULL_END

Added src/OFGZIPURIHandler.m version [96c40ab197].

















































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * 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.
 */

#include "config.h"

#import "OFGZIPURIHandler.h"
#import "OFURI.h"
#import "OFGZIPStream.h"

#import "OFInvalidArgumentException.h"

@implementation OFGZIPURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFStream *stream;

	if (![URI.scheme isEqual: @"of-gzip"] || URI.host != nil ||
	    URI.port != nil || URI.user != nil || URI.password != nil ||
	    URI.query != nil || URI.fragment != nil)
		@throw [OFInvalidArgumentException exception];

	if (![mode isEqual: @"r"])
		@throw [OFInvalidArgumentException exception];

	stream = [OFURIHandler openItemAtURI: [OFURI URIWithString: URI.path]
					mode: @"r"];
	stream = [OFGZIPStream streamWithStream: stream mode: @"r"];

	[stream retain];

	objc_autoreleasePoolPop(pool);

	return [stream autorelease];
}
@end

Modified src/OFTarArchive.h from [748cfc3b0d] to [fceb35b7be].

81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
81
82
83
84
85
86
87

88
89
90
91
92
93
94
95







-
+








/**
 * @brief Creates a URI for accessing a the specified file within the specified
 *	  tar archive.
 *
 * @param path The path of the file within the archive
 * @param archive The URI of the archive
 * @return A URI for accessing the specified file within the specified Tar
 * @return A URI for accessing the specified file within the specified tar
 *	   archive
 */
+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive;

- (instancetype)init OF_UNAVAILABLE;

/**

Modified src/OFTarURIHandler.m from [b5232b0f3e] to [6ffaae458d].

23
24
25
26
27
28
29

30
31
32
33
34
35
36
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37







+








#import "OFInvalidArgumentException.h"
#import "OFOpenItemFailedException.h"

@implementation OFTarURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFString *percentEncodedPath, *archiveURI, *path;
	size_t pos;
	OFTarArchive *archive;
	OFTarArchiveEntry *entry;

	if (![URI.scheme isEqual: @"of-tar"] || URI.host != nil ||
	    URI.port != nil || URI.user != nil || URI.password != nil ||
57
58
59
60
61
62
63
64
65
66










67
68
69
70
71
72
58
59
60
61
62
63
64



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80







-
-
-
+
+
+
+
+
+
+
+
+
+






	    OFMakeRange(pos + 1, percentEncodedPath.length - pos - 1)]
	    .stringByRemovingPercentEncoding;

	archive = [OFTarArchive
	    archiveWithURI: [OFURI URIWithString: archiveURI]
		      mode: @"r"];

	while ((entry = [archive nextEntry]) != nil)
		if ([entry.fileName isEqual: path])
			return [archive streamForReadingCurrentEntry];
	while ((entry = [archive nextEntry]) != nil) {
		if ([entry.fileName isEqual: path]) {
			OFStream *stream =
			    [[archive streamForReadingCurrentEntry] retain];

			objc_autoreleasePoolPop(pool);

			return [stream autorelease];
		}
	}

	@throw [OFOpenItemFailedException exceptionWithURI: URI
						      mode: mode
						     errNo: ENOENT];
}
@end

Modified src/OFURIHandler.m from [98204d10fd] to [cf412745fd].

24
25
26
27
28
29
30

31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+







# import "OFMutex.h"
#endif

#import "OFEmbeddedURIHandler.h"
#ifdef OF_HAVE_FILES
# import "OFFileURIHandler.h"
#endif
#import "OFGZIPURIHandler.h"
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
# import "OFHTTPURIHandler.h"
#endif
#import "OFTarURIHandler.h"
#import "OFZIPURIHandler.h"

#import "OFUnsupportedProtocolException.h"
62
63
64
65
66
67
68

69
70
71
72
73
74
75
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77







+







#endif

	[self registerClass: [OFEmbeddedURIHandler class]
		  forScheme: @"of-embedded"];
#ifdef OF_HAVE_FILES
	[self registerClass: [OFFileURIHandler class] forScheme: @"file"];
#endif
	[self registerClass: [OFGZIPURIHandler class] forScheme: @"of-gzip"];
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
	[self registerClass: [OFHTTPURIHandler class] forScheme: @"http"];
	[self registerClass: [OFHTTPURIHandler class] forScheme: @"https"];
#endif
	[self registerClass: [OFTarURIHandler class] forScheme: @"of-tar"];
	[self registerClass: [OFZIPURIHandler class] forScheme: @"of-zip"];
}

Modified src/OFZIPURIHandler.m from [ac757b6022] to [ed7da6bb04].

20
21
22
23
24
25
26

27
28
29

30
31
32
33
34
35
36
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38







+



+







#import "OFZIPArchive.h"

#import "OFInvalidArgumentException.h"

@implementation OFZIPURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFString *percentEncodedPath, *archiveURI, *path;
	size_t pos;
	OFZIPArchive *archive;
	OFStream *stream;

	if (![URI.scheme isEqual: @"of-zip"] || URI.host != nil ||
	    URI.port != nil || URI.user != nil || URI.password != nil ||
	    URI.query != nil || URI.fragment != nil)
		@throw [OFInvalidArgumentException exception];

	if (![mode isEqual: @"r"])
52
53
54
55
56
57
58

59

60
61





62
54
55
56
57
58
59
60
61
62
63


64
65
66
67
68
69







+

+
-
-
+
+
+
+
+

	path = [percentEncodedPath substringWithRange:
	    OFMakeRange(pos + 1, percentEncodedPath.length - pos - 1)]
	    .stringByRemovingPercentEncoding;

	archive = [OFZIPArchive
	    archiveWithURI: [OFURI URIWithString: archiveURI]
		      mode: @"r"];
	stream = [archive streamForReadingFile: path];

	[stream retain];
	return [archive streamForReadingFile: path];
}

	objc_autoreleasePoolPop(pool);

	return [stream autorelease];
}
@end