ObjFW  Check-in [519c277156]

Overview
Comment:OF*Archive: Share +[URIForFile:inArchive:] code
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 519c277156b271461b5841e32e386cecc1ee006759d7b498fc6bc0e0af8132e9
User & Date: js on 2022-10-04 22:22:25
Other Links: manifest | tags
Context
2022-10-04
22:27
Add of-lha: URI handler check-in: f3bdf29f07 user: js tags: trunk
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
Changes

Modified src/OFTarArchive.m from [0dbf94ce58] to [e6e921bda1].

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	OFMutableURI *URI = [OFMutableURI URI];
	void *pool = objc_autoreleasePoolPush();
	OFCharacterSet *characterSet = [OFCharacterSet
	    of_URIPathAllowedCharacterSetWithoutExclamationMark];
	OFString *archiveURI;

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

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

	[URI makeImmutable];

	objc_autoreleasePoolPop(pool);

	return URI;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}








<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<







70
71
72
73
74
75
76





77














78
79
80
81
82
83
84
+ (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
}

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

14
15
16
17
18
19
20

21
22
23
24
25
26
27
 */

#include "config.h"

#include <errno.h>

#import "OFTarURIHandler.h"

#import "OFTarArchive.h"
#import "OFURI.h"

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

@implementation OFTarURIHandler







>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 */

#include "config.h"

#include <errno.h>

#import "OFTarURIHandler.h"
#import "OFStream.h"
#import "OFTarArchive.h"
#import "OFURI.h"

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

@implementation OFTarURIHandler

Modified src/OFURI.h from [0e7faecce0] to [80857913fd].

371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386

387
388
389
390
391
392
393

/**
 * @brief Returns the characters allowed in the fragment part of a URI.
 *
 * @return The characters allowed in the fragment part of a URI.
 */
+ (OFCharacterSet *)URIFragmentAllowedCharacterSet;

+ (OFCharacterSet *)of_URIPathAllowedCharacterSetWithoutExclamationMark;
@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"







<
<







>







371
372
373
374
375
376
377


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

/**
 * @brief Returns the characters allowed in the fragment part of a URI.
 *
 * @return The characters allowed in the fragment part of a URI.
 */
+ (OFCharacterSet *)URIFragmentAllowedCharacterSet;


@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"

Modified src/OFURI.m from [a82a35d7aa] to [e7dba343a1].

139
140
141
142
143
144
145




























146
147
148
149
150
151
152
			hasColon = true;

		UTF8String++;
	}

	return hasColon;
}





























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








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







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
			hasColon = true;

		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;
}

443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
+ (OFCharacterSet *)URIFragmentAllowedCharacterSet
{
	OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce,
	    initURIQueryOrFragmentAllowedCharacterSet);

	return URIQueryOrFragmentAllowedCharacterSet;
}

+ (OFCharacterSet *)of_URIPathAllowedCharacterSetWithoutExclamationMark
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl,
	    initURIPathAllowedCharacterSetWithoutExclamationMark);

	return URIPathAllowedCharacterSetWithoutExclamationMark;
}
@end

@implementation OFURI
+ (instancetype)URI
{
	return [[[self alloc] init] autorelease];
}







<
<
<
<
<
<
<
<
<







471
472
473
474
475
476
477









478
479
480
481
482
483
484
+ (OFCharacterSet *)URIFragmentAllowedCharacterSet
{
	OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce,
	    initURIQueryOrFragmentAllowedCharacterSet);

	return URIQueryOrFragmentAllowedCharacterSet;
}









@end

@implementation OFURI
+ (instancetype)URI
{
	return [[[self alloc] init] autorelease];
}

Modified src/OFZIPArchive.m from [d0b4f286d3] to [ed7fc3801b].

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
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}

+ (OFURI *)URIForFile: (OFString *)path inArchive: (OFURI *)archive
{
	OFMutableURI *URI = [OFMutableURI URI];
	void *pool = objc_autoreleasePoolPush();
	OFCharacterSet *characterSet = [OFCharacterSet
	    of_URIPathAllowedCharacterSetWithoutExclamationMark];
	OFString *archiveURI;

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

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

	[URI makeImmutable];

	objc_autoreleasePoolPop(pool);

	return URI;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}








<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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
}