ObjFW  Check-in [55858a10bb]

Overview
Comment:Move all archive URI handling to a single file
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 55858a10bbbc5cf4b387f50e428765b022d6fe7853bdc4a7698dfac11841667d
User & Date: js on 2022-10-08 23:47:33
Other Links: manifest | tags
Context
2022-10-09
16:19
OFZIPArchive: Make returned streams retain archive check-in: 6527c97d03 user: js tags: trunk
2022-10-08
23:47
Move all archive URI handling to a single file check-in: 55858a10bb user: js tags: trunk
2022-10-06
23:33
OFTarArchive: Make returned streams retain archive check-in: 6c08b57605 user: js tags: trunk
Changes

Modified src/OFArchiveURIHandler.h from [b4b1b87298] to [7c81cf8db2].

15
16
17
18
19
20
21









22
23

#import "OFURIHandler.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFArchiveURIHandler: OFURIHandler
@end










OF_ASSUME_NONNULL_END







>
>
>
>
>
>
>
>
>


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

#import "OFURIHandler.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFArchiveURIHandler: OFURIHandler
@end

#ifdef __cplusplus
extern "C" {
#endif
extern OFURI *OFArchiveURIHandlerURIForFileInArchive(OFString *, OFString *,
    OFURI *);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/OFArchiveURIHandler.m from [8522ccf377] to [688b91a007].

14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
















30
31
32
33
34
35
36
 */

#include "config.h"

#include <errno.h>

#import "OFArchiveURIHandler.h"

#import "OFGZIPStream.h"
#import "OFLHAArchive.h"
#import "OFStream.h"
#import "OFTarArchive.h"
#import "OFURI.h"
#import "OFZIPArchive.h"

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

















@implementation OFArchiveURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFString *scheme = URI.scheme;
	OFString *percentEncodedPath, *path;







>









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







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
49
50
51
52
53
 */

#include "config.h"

#include <errno.h>

#import "OFArchiveURIHandler.h"
#import "OFCharacterSet.h"
#import "OFGZIPStream.h"
#import "OFLHAArchive.h"
#import "OFStream.h"
#import "OFTarArchive.h"
#import "OFURI.h"
#import "OFZIPArchive.h"

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

@interface OFArchiveURIHandlerPathAllowedCharacterSet: OFCharacterSet
{
	OFCharacterSet *_characterSet;
	bool (*_characterIsMember)(id, SEL, OFUnichar);
}
@end

static OFCharacterSet *pathAllowedCharacters;

static void
initPathAllowedCharacters(void)
{
	pathAllowedCharacters =
	    [[OFArchiveURIHandlerPathAllowedCharacterSet alloc] init];
}

@implementation OFArchiveURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFString *scheme = URI.scheme;
	OFString *percentEncodedPath, *path;
117
118
119
120
121
122
123





























































	stream = [stream retain];

	objc_autoreleasePoolPop(pool);

	return [stream autorelease];
}
@end




































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
	stream = [stream retain];

	objc_autoreleasePoolPop(pool);

	return [stream autorelease];
}
@end

@implementation OFArchiveURIHandlerPathAllowedCharacterSet
- (instancetype)init
{
	self = [super init];

	@try {
		_characterSet =
		    [[OFCharacterSet URIPathAllowedCharacterSet] retain];
		_characterIsMember = (bool (*)(id, SEL, OFUnichar))
		    [_characterSet methodForSelector:
		    @selector(characterIsMember:)];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_characterSet release];

	[super dealloc];
}

- (bool)characterIsMember: (OFUnichar)character
{
	return (character != '!' && _characterIsMember(_characterSet,
	    @selector(characterIsMember:), character));
}
@end

OFURI *
OFArchiveURIHandlerURIForFileInArchive(OFString *scheme,
    OFString *pathInArchive, OFURI *archiveURI)
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFMutableURI *ret = [OFMutableURI URI];
	void *pool = objc_autoreleasePoolPush();
	OFString *archiveURIString;

	OFOnce(&onceControl, initPathAllowedCharacters);

	pathInArchive = [pathInArchive
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    pathAllowedCharacters];
	archiveURIString = [archiveURI.string
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    pathAllowedCharacters];

	ret.scheme = scheme;
	ret.percentEncodedPath = [OFString
	    stringWithFormat: @"%@!%@", archiveURIString, pathInArchive];
	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

Modified src/OFLHAArchive.m from [7d50694f14] to [3876237eb4].

18
19
20
21
22
23
24

25
26
27
28
29
30
31
#include "config.h"

#include <errno.h>

#import "OFLHAArchive.h"
#import "OFLHAArchiveEntry.h"
#import "OFLHAArchiveEntry+Private.h"

#import "OFCRC16.h"
#import "OFLHADecompressingStream.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFString.h"
#import "OFURI.h"
#import "OFURIHandler.h"







>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "config.h"

#include <errno.h>

#import "OFLHAArchive.h"
#import "OFLHAArchiveEntry.h"
#import "OFLHAArchiveEntry+Private.h"
#import "OFArchiveURIHandler.h"
#import "OFCRC16.h"
#import "OFLHADecompressingStream.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFString.h"
#import "OFURI.h"
#import "OFURIHandler.h"
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	return OFURIForFileInArchive(@"of-lha", path, archive);
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}








|







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	return OFArchiveURIHandlerURIForFileInArchive(@"of-lha", path, archive);
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

Modified src/OFTarArchive.m from [d33bd24f84] to [4c749d1fe6].

18
19
20
21
22
23
24

25
26
27
28
29
30
31
#include "config.h"

#include <errno.h>

#import "OFTarArchive.h"
#import "OFTarArchiveEntry.h"
#import "OFTarArchiveEntry+Private.h"

#import "OFDate.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFURI.h"
#import "OFURIHandler.h"

#import "OFInvalidArgumentException.h"







>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "config.h"

#include <errno.h>

#import "OFTarArchive.h"
#import "OFTarArchiveEntry.h"
#import "OFTarArchiveEntry+Private.h"
#import "OFArchiveURIHandler.h"
#import "OFDate.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFURI.h"
#import "OFURIHandler.h"

#import "OFInvalidArgumentException.h"
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	return OFURIForFileInArchive(@"of-tar", path, archive);
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}








|







77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	return OFArchiveURIHandlerURIForFileInArchive(@"of-tar", path, archive);
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

Modified src/OFURI.h from [80857913fd] to [63067c2093].

378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
@end

#ifdef __cplusplus
extern "C" {
#endif
extern bool OFURIIsIPv6Host(OFString *host);
extern void OFURIVerifyIsEscaped(OFString *, OFCharacterSet *);
extern OFURI *OFURIForFileInArchive(OFString *, OFString *, OFURI *);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

#import "OFMutableURI.h"







<







378
379
380
381
382
383
384

385
386
387
388
389
390
391
@end

#ifdef __cplusplus
extern "C" {
#endif
extern bool OFURIIsIPv6Host(OFString *host);
extern void OFURIVerifyIsEscaped(OFString *, OFCharacterSet *);

#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

#import "OFMutableURI.h"

Modified src/OFURI.m from [e7dba343a1] to [213596bf3e].

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
76
77
78
79
80
81
82
83
84
85
86

@interface OFURIQueryOrFragmentAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURIQueryKeyValueAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURIPathAllowedCharacterSetWithoutExclamationMark:
    OFURIPathAllowedCharacterSet
{
	OFCharacterSet *_characterSet;
	bool (*_characterIsMember)(id, SEL, OFUnichar);
}
@end

OF_DIRECT_MEMBERS
@interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet
{
	OFCharacterSet *_characterSet;
	bool (*_characterIsMember)(id, SEL, OFUnichar);
}

- (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet;
@end

static OFCharacterSet *URIAllowedCharacterSet = nil;
static OFCharacterSet *URISchemeAllowedCharacterSet = nil;
static OFCharacterSet *URIPathAllowedCharacterSet = nil;
static OFCharacterSet *URIQueryOrFragmentAllowedCharacterSet = nil;
static OFCharacterSet *URIQueryKeyValueAllowedCharacterSet = nil;
static OFCharacterSet *URIPathAllowedCharacterSetWithoutExclamationMark = nil;

static OFOnceControl URIAllowedCharacterSetOnce = OFOnceControlInitValue;
static OFOnceControl URIQueryOrFragmentAllowedCharacterSetOnce =
    OFOnceControlInitValue;

static void
initURIAllowedCharacterSet(void)







<
<
<
<
<
<
<
<















<







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
76
77

@interface OFURIQueryOrFragmentAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURIQueryKeyValueAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end









OF_DIRECT_MEMBERS
@interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet
{
	OFCharacterSet *_characterSet;
	bool (*_characterIsMember)(id, SEL, OFUnichar);
}

- (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet;
@end

static OFCharacterSet *URIAllowedCharacterSet = nil;
static OFCharacterSet *URISchemeAllowedCharacterSet = nil;
static OFCharacterSet *URIPathAllowedCharacterSet = nil;
static OFCharacterSet *URIQueryOrFragmentAllowedCharacterSet = nil;
static OFCharacterSet *URIQueryKeyValueAllowedCharacterSet = nil;


static OFOnceControl URIAllowedCharacterSetOnce = OFOnceControlInitValue;
static OFOnceControl URIQueryOrFragmentAllowedCharacterSetOnce =
    OFOnceControlInitValue;

static void
initURIAllowedCharacterSet(void)
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
static void
initURIQueryKeyValueAllowedCharacterSet(void)
{
	URIQueryKeyValueAllowedCharacterSet =
	    [[OFURIQueryKeyValueAllowedCharacterSet alloc] init];
}

static void
initURIPathAllowedCharacterSetWithoutExclamationMark(void)
{
	URIPathAllowedCharacterSetWithoutExclamationMark =
	    [[OFURIPathAllowedCharacterSetWithoutExclamationMark alloc] init];
}

bool
OFURIIsIPv6Host(OFString *host)
{
	const char *UTF8String = host.UTF8String;
	bool hasColon = false;

	while (*UTF8String != '\0') {







<
<
<
<
<
<
<







103
104
105
106
107
108
109







110
111
112
113
114
115
116
static void
initURIQueryKeyValueAllowedCharacterSet(void)
{
	URIQueryKeyValueAllowedCharacterSet =
	    [[OFURIQueryKeyValueAllowedCharacterSet alloc] init];
}








bool
OFURIIsIPv6Host(OFString *host)
{
	const char *UTF8String = host.UTF8String;
	bool hasColon = false;

	while (*UTF8String != '\0') {
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

		UTF8String++;
	}

	return hasColon;
}

OFURI *
OFURIForFileInArchive(OFString *scheme, OFString *path, OFURI *archive)
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFMutableURI *URI = [OFMutableURI URI];
	void *pool = objc_autoreleasePoolPush();
	OFString *archiveURI;

	OFOnce(&onceControl,
	    initURIPathAllowedCharacterSetWithoutExclamationMark);

	path = [path stringByAddingPercentEncodingWithAllowedCharacters:
	    URIPathAllowedCharacterSetWithoutExclamationMark];
	archiveURI = [archive.string
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    URIPathAllowedCharacterSetWithoutExclamationMark];

	URI.scheme = scheme;
	URI.percentEncodedPath = [OFString stringWithFormat: @"%@!%@",
							     archiveURI, path];

	[URI makeImmutable];

	objc_autoreleasePoolPop(pool);

	return URI;
}

@implementation OFURIAllowedCharacterSetBase
- (instancetype)autorelease
{
	return self;
}

- (instancetype)retain







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







124
125
126
127
128
129
130




























131
132
133
134
135
136
137

		UTF8String++;
	}

	return hasColon;
}





























@implementation OFURIAllowedCharacterSetBase
- (instancetype)autorelease
{
	return self;
}

- (instancetype)retain
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
	case '/':
	case '?':
		return true;
	default:
		return false;
	}
}
@end

@implementation OFURIPathAllowedCharacterSetWithoutExclamationMark
- (instancetype)init
{
	self = [super init];

	@try {
		_characterSet = [[OFCharacterSet URIPathAllowedCharacterSet]
		    retain];
		_characterIsMember = (bool (*)(id, SEL, OFUnichar))
		    [_characterSet methodForSelector:
		    @selector(characterIsMember:)];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_characterSet release];

	[super dealloc];
}

- (bool)characterIsMember: (OFUnichar)character
{
	return (character != '!' && _characterIsMember(_characterSet,
	    @selector(characterIsMember:), character));
}
@end

@implementation OFInvertedCharacterSetWithoutPercent
- (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet
{
	self = [super init];








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







285
286
287
288
289
290
291

































292
293
294
295
296
297
298
	case '/':
	case '?':
		return true;
	default:
		return false;
	}
}

































@end

@implementation OFInvertedCharacterSetWithoutPercent
- (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet
{
	self = [super init];

Modified src/OFZIPArchive.m from [ed7fc3801b] to [4d14cd8ba2].

16
17
18
19
20
21
22

23
24
25
26
27
28
29
#include "config.h"

#include <errno.h>

#import "OFZIPArchive.h"
#import "OFZIPArchiveEntry.h"
#import "OFZIPArchiveEntry+Private.h"

#import "OFArray.h"
#import "OFCRC32.h"
#import "OFData.h"
#import "OFDictionary.h"
#import "OFInflate64Stream.h"
#import "OFInflateStream.h"
#import "OFSeekableStream.h"







>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "config.h"

#include <errno.h>

#import "OFZIPArchive.h"
#import "OFZIPArchiveEntry.h"
#import "OFZIPArchiveEntry+Private.h"
#import "OFArchiveURIHandler.h"
#import "OFArray.h"
#import "OFCRC32.h"
#import "OFData.h"
#import "OFDictionary.h"
#import "OFInflate64Stream.h"
#import "OFInflateStream.h"
#import "OFSeekableStream.h"
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	return OFURIForFileInArchive(@"of-zip", path, archive);
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}








|







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	return OFArchiveURIHandlerURIForFileInArchive(@"of-zip", path, archive);
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}