ObjFW  Diff

Differences From Artifact [7aef38f501]:

To Artifact [a31da3127a]:


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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#import "OFArray.h"
#import "OFNumber.h"
#import "OFString.h"
#import "OFXMLElement.h"

#ifdef OF_HAVE_FILES
# import "OFFileManager.h"
# import "OFURLHandler_file.h"
#endif

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

static OFCharacterSet *URLAllowedCharacterSet = nil;
static OFCharacterSet *URLSchemeAllowedCharacterSet = nil;
static OFCharacterSet *URLPathAllowedCharacterSet = nil;
static OFCharacterSet *URLQueryOrFragmentAllowedCharacterSet = nil;

@interface OFCharacterSet_URLAllowedBase: OFCharacterSet
- (instancetype)of_init OF_METHOD_FAMILY(init);
@end

@interface OFCharacterSet_URLAllowed: OFCharacterSet_URLAllowedBase
+ (OFCharacterSet *)URLAllowedCharacterSet;
@end

@interface OFCharacterSet_URLSchemeAllowed: OFCharacterSet_URLAllowedBase
+ (OFCharacterSet *)URLSchemeAllowedCharacterSet;
@end

@interface OFCharacterSet_URLPathAllowed: OFCharacterSet_URLAllowedBase
+ (OFCharacterSet *)URLPathAllowedCharacterSet;
@end

@interface OFCharacterSet_URLQueryOrFragmentAllowed:
    OFCharacterSet_URLAllowedBase
+ (OFCharacterSet *)URLQueryOrFragmentAllowedCharacterSet;
@end

#ifdef OF_HAVE_FILES
static OFString *
pathToURLPath(OFString *path)
{







|











|



|



|



|



|
<







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
54
55
56
57
58
59

60
61
62
63
64
65
66
#import "OFArray.h"
#import "OFNumber.h"
#import "OFString.h"
#import "OFXMLElement.h"

#ifdef OF_HAVE_FILES
# import "OFFileManager.h"
# import "OFFileURLHandler.h"
#endif

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

static OFCharacterSet *URLAllowedCharacterSet = nil;
static OFCharacterSet *URLSchemeAllowedCharacterSet = nil;
static OFCharacterSet *URLPathAllowedCharacterSet = nil;
static OFCharacterSet *URLQueryOrFragmentAllowedCharacterSet = nil;

@interface OFURLAllowedCharacterSetBase: OFCharacterSet
- (instancetype)of_init OF_METHOD_FAMILY(init);
@end

@interface OFURLAllowedCharacterSet: OFURLAllowedCharacterSetBase
+ (OFCharacterSet *)URLAllowedCharacterSet;
@end

@interface OFURLSchemeAllowedCharacterSet: OFURLAllowedCharacterSetBase
+ (OFCharacterSet *)URLSchemeAllowedCharacterSet;
@end

@interface OFURLPathAllowedCharacterSet: OFURLAllowedCharacterSetBase
+ (OFCharacterSet *)URLPathAllowedCharacterSet;
@end

@interface OFURLQueryOrFragmentAllowedCharacterSet: OFURLAllowedCharacterSetBase

+ (OFCharacterSet *)URLQueryOrFragmentAllowedCharacterSet;
@end

#ifdef OF_HAVE_FILES
static OFString *
pathToURLPath(OFString *path)
{
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
	return [path substringWithRange: of_range(1, path.length - 1)];
# else
	return path;
# endif
}
#endif

@interface OFCharacterSet_invertedSetWithPercent: OFCharacterSet
{
	OFCharacterSet *_characterSet;
	bool (*_characterIsMember)(id, SEL, of_unichar_t);
}

- (instancetype)of_initWithCharacterSet: (OFCharacterSet *)characterSet
    OF_METHOD_FAMILY(init);
@end

@implementation OFCharacterSet_URLAllowedBase
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_init
{







|









|







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
	return [path substringWithRange: of_range(1, path.length - 1)];
# else
	return path;
# endif
}
#endif

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

- (instancetype)of_initWithCharacterSet: (OFCharacterSet *)characterSet
    OF_METHOD_FAMILY(init);
@end

@implementation OFURLAllowedCharacterSetBase
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_init
{
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}
@end

@implementation OFCharacterSet_URLAllowed
+ (void)initialize
{
	if (self != [OFCharacterSet_URLAllowed class])
		return;

	URLAllowedCharacterSet = [[OFCharacterSet_URLAllowed alloc] of_init];
}

+ (OFCharacterSet *)URLAllowedCharacterSet
{
	return URLAllowedCharacterSet;
}








|


|


|







176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

- (unsigned int)retainCount
{
	return OF_RETAIN_COUNT_MAX;
}
@end

@implementation OFURLAllowedCharacterSet
+ (void)initialize
{
	if (self != [OFURLAllowedCharacterSet class])
		return;

	URLAllowedCharacterSet = [[OFURLAllowedCharacterSet alloc] of_init];
}

+ (OFCharacterSet *)URLAllowedCharacterSet
{
	return URLAllowedCharacterSet;
}

219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
		return true;
	default:
		return false;
	}
}
@end

@implementation OFCharacterSet_URLSchemeAllowed
+ (void)initialize
{
	if (self != [OFCharacterSet_URLSchemeAllowed class])
		return;

	URLSchemeAllowedCharacterSet =
	    [[OFCharacterSet_URLSchemeAllowed alloc] of_init];
}

+ (OFCharacterSet *)URLSchemeAllowedCharacterSet
{
	return URLSchemeAllowedCharacterSet;
}








|


|



|







218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
		return true;
	default:
		return false;
	}
}
@end

@implementation OFURLSchemeAllowedCharacterSet
+ (void)initialize
{
	if (self != [OFURLSchemeAllowedCharacterSet class])
		return;

	URLSchemeAllowedCharacterSet =
	    [[OFURLSchemeAllowedCharacterSet alloc] of_init];
}

+ (OFCharacterSet *)URLSchemeAllowedCharacterSet
{
	return URLSchemeAllowedCharacterSet;
}

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
		return true;
	default:
		return false;
	}
}
@end

@implementation OFCharacterSet_URLPathAllowed
+ (void)initialize
{
	if (self != [OFCharacterSet_URLPathAllowed class])
		return;

	URLPathAllowedCharacterSet =
	    [[OFCharacterSet_URLPathAllowed alloc] of_init];
}

+ (OFCharacterSet *)URLPathAllowedCharacterSet
{
	return URLPathAllowedCharacterSet;
}








|


|



|







249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
		return true;
	default:
		return false;
	}
}
@end

@implementation OFURLPathAllowedCharacterSet
+ (void)initialize
{
	if (self != [OFURLPathAllowedCharacterSet class])
		return;

	URLPathAllowedCharacterSet =
	    [[OFURLPathAllowedCharacterSet alloc] of_init];
}

+ (OFCharacterSet *)URLPathAllowedCharacterSet
{
	return URLPathAllowedCharacterSet;
}

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
		return true;
	default:
		return false;
	}
}
@end

@implementation OFCharacterSet_URLQueryOrFragmentAllowed
+ (void)initialize
{
	if (self != [OFCharacterSet_URLQueryOrFragmentAllowed class])
		return;

	URLQueryOrFragmentAllowedCharacterSet =
	    [[OFCharacterSet_URLQueryOrFragmentAllowed alloc] of_init];
}

+ (OFCharacterSet *)URLQueryOrFragmentAllowedCharacterSet
{
	return URLQueryOrFragmentAllowedCharacterSet;
}








|


|



|







295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
		return true;
	default:
		return false;
	}
}
@end

@implementation OFURLQueryOrFragmentAllowedCharacterSet
+ (void)initialize
{
	if (self != [OFURLQueryOrFragmentAllowedCharacterSet class])
		return;

	URLQueryOrFragmentAllowedCharacterSet =
	    [[OFURLQueryOrFragmentAllowedCharacterSet alloc] of_init];
}

+ (OFCharacterSet *)URLQueryOrFragmentAllowedCharacterSet
{
	return URLQueryOrFragmentAllowedCharacterSet;
}

343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
		return true;
	default:
		return false;
	}
}
@end

@implementation OFCharacterSet_invertedSetWithPercent
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_initWithCharacterSet: (OFCharacterSet *)characterSet
{







|







342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
		return true;
	default:
		return false;
	}
}
@end

@implementation OFInvertedCharacterSetWithoutPercent
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)of_initWithCharacterSet: (OFCharacterSet *)characterSet
{
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
@end

void
of_url_verify_escaped(OFString *string, OFCharacterSet *characterSet)
{
	void *pool = objc_autoreleasePoolPush();

	characterSet = [[[OFCharacterSet_invertedSetWithPercent alloc]
	    of_initWithCharacterSet: characterSet] autorelease];

	if ([string indexOfCharacterFromSet: characterSet] != OF_NOT_FOUND)
		@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);
}

@implementation OFCharacterSet (URLCharacterSets)
+ (OFCharacterSet *)URLSchemeAllowedCharacterSet
{
	return [OFCharacterSet_URLSchemeAllowed URLSchemeAllowedCharacterSet];
}

+ (OFCharacterSet *)URLHostAllowedCharacterSet
{
	return [OFCharacterSet_URLAllowed URLAllowedCharacterSet];
}

+ (OFCharacterSet *)URLUserAllowedCharacterSet
{
	return [OFCharacterSet_URLAllowed URLAllowedCharacterSet];
}

+ (OFCharacterSet *)URLPasswordAllowedCharacterSet
{
	return [OFCharacterSet_URLAllowed URLAllowedCharacterSet];
}

+ (OFCharacterSet *)URLPathAllowedCharacterSet
{
	return [OFCharacterSet_URLPathAllowed URLPathAllowedCharacterSet];
}

+ (OFCharacterSet *)URLQueryAllowedCharacterSet
{
	return [OFCharacterSet_URLQueryOrFragmentAllowed
	    URLQueryOrFragmentAllowedCharacterSet];
}

+ (OFCharacterSet *)URLFragmentAllowedCharacterSet
{
	return [OFCharacterSet_URLQueryOrFragmentAllowed
	    URLQueryOrFragmentAllowedCharacterSet];
}
@end

@implementation OFURL
+ (instancetype)URL
{







|











|




|




|




|




|




|





|







378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
@end

void
of_url_verify_escaped(OFString *string, OFCharacterSet *characterSet)
{
	void *pool = objc_autoreleasePoolPush();

	characterSet = [[[OFInvertedCharacterSetWithoutPercent alloc]
	    of_initWithCharacterSet: characterSet] autorelease];

	if ([string indexOfCharacterFromSet: characterSet] != OF_NOT_FOUND)
		@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);
}

@implementation OFCharacterSet (URLCharacterSets)
+ (OFCharacterSet *)URLSchemeAllowedCharacterSet
{
	return [OFURLSchemeAllowedCharacterSet URLSchemeAllowedCharacterSet];
}

+ (OFCharacterSet *)URLHostAllowedCharacterSet
{
	return [OFURLAllowedCharacterSet URLAllowedCharacterSet];
}

+ (OFCharacterSet *)URLUserAllowedCharacterSet
{
	return [OFURLAllowedCharacterSet URLAllowedCharacterSet];
}

+ (OFCharacterSet *)URLPasswordAllowedCharacterSet
{
	return [OFURLAllowedCharacterSet URLAllowedCharacterSet];
}

+ (OFCharacterSet *)URLPathAllowedCharacterSet
{
	return [OFURLPathAllowedCharacterSet URLPathAllowedCharacterSet];
}

+ (OFCharacterSet *)URLQueryAllowedCharacterSet
{
	return [OFURLQueryOrFragmentAllowedCharacterSet
	    URLQueryOrFragmentAllowedCharacterSet];
}

+ (OFCharacterSet *)URLFragmentAllowedCharacterSet
{
	return [OFURLQueryOrFragmentAllowedCharacterSet
	    URLQueryOrFragmentAllowedCharacterSet];
}
@end

@implementation OFURL
+ (instancetype)URL
{
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721

	@try {
		void *pool = objc_autoreleasePoolPush();

#if defined(OF_WINDOWS) || defined(OF_MSDOS)
		isDirectory = ([path hasSuffix: @"\\"] ||
		    [path hasSuffix: @"/"] ||
		    [OFURLHandler_file of_directoryExistsAtPath: path]);
#elif defined(OF_AMIGAOS)
		isDirectory = ([path hasSuffix: @"/"] ||
		    [path hasSuffix: @":"] ||
		    [OFURLHandler_file of_directoryExistsAtPath: path]);
#else
		isDirectory = ([path hasSuffix: @"/"] ||
		    [OFURLHandler_file of_directoryExistsAtPath: path]);
#endif

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}







|



|


|







699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720

	@try {
		void *pool = objc_autoreleasePoolPush();

#if defined(OF_WINDOWS) || defined(OF_MSDOS)
		isDirectory = ([path hasSuffix: @"\\"] ||
		    [path hasSuffix: @"/"] ||
		    [OFFileURLHandler of_directoryExistsAtPath: path]);
#elif defined(OF_AMIGAOS)
		isDirectory = ([path hasSuffix: @"/"] ||
		    [path hasSuffix: @":"] ||
		    [OFFileURLHandler of_directoryExistsAtPath: path]);
#else
		isDirectory = ([path hasSuffix: @"/"] ||
		    [OFFileURLHandler of_directoryExistsAtPath: path]);
#endif

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}