︙ | | |
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
|
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 "OFURLHandler_file.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 OFCharacterSet_URLAllowedBase: OFCharacterSet
@interface OFURLAllowedCharacterSetBase: OFCharacterSet
- (instancetype)of_init OF_METHOD_FAMILY(init);
@end
@interface OFCharacterSet_URLAllowed: OFCharacterSet_URLAllowedBase
@interface OFURLAllowedCharacterSet: OFURLAllowedCharacterSetBase
+ (OFCharacterSet *)URLAllowedCharacterSet;
@end
@interface OFCharacterSet_URLSchemeAllowed: OFCharacterSet_URLAllowedBase
@interface OFURLSchemeAllowedCharacterSet: OFURLAllowedCharacterSetBase
+ (OFCharacterSet *)URLSchemeAllowedCharacterSet;
@end
@interface OFCharacterSet_URLPathAllowed: OFCharacterSet_URLAllowedBase
@interface OFURLPathAllowedCharacterSet: OFURLAllowedCharacterSetBase
+ (OFCharacterSet *)URLPathAllowedCharacterSet;
@end
@interface OFCharacterSet_URLQueryOrFragmentAllowed:
@interface OFURLQueryOrFragmentAllowedCharacterSet: OFURLAllowedCharacterSetBase
OFCharacterSet_URLAllowedBase
+ (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
|
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 OFCharacterSet_invertedSetWithPercent: OFCharacterSet
@interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet
{
OFCharacterSet *_characterSet;
bool (*_characterIsMember)(id, SEL, of_unichar_t);
}
- (instancetype)of_initWithCharacterSet: (OFCharacterSet *)characterSet
OF_METHOD_FAMILY(init);
@end
@implementation OFCharacterSet_URLAllowedBase
@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
|
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 OFCharacterSet_URLAllowed
@implementation OFURLAllowedCharacterSet
+ (void)initialize
{
if (self != [OFCharacterSet_URLAllowed class])
if (self != [OFURLAllowedCharacterSet class])
return;
URLAllowedCharacterSet = [[OFCharacterSet_URLAllowed alloc] of_init];
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
|
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 OFCharacterSet_URLSchemeAllowed
@implementation OFURLSchemeAllowedCharacterSet
+ (void)initialize
{
if (self != [OFCharacterSet_URLSchemeAllowed class])
if (self != [OFURLSchemeAllowedCharacterSet class])
return;
URLSchemeAllowedCharacterSet =
[[OFCharacterSet_URLSchemeAllowed alloc] of_init];
[[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
|
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 OFCharacterSet_URLPathAllowed
@implementation OFURLPathAllowedCharacterSet
+ (void)initialize
{
if (self != [OFCharacterSet_URLPathAllowed class])
if (self != [OFURLPathAllowedCharacterSet class])
return;
URLPathAllowedCharacterSet =
[[OFCharacterSet_URLPathAllowed alloc] of_init];
[[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
|
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 OFCharacterSet_URLQueryOrFragmentAllowed
@implementation OFURLQueryOrFragmentAllowedCharacterSet
+ (void)initialize
{
if (self != [OFCharacterSet_URLQueryOrFragmentAllowed class])
if (self != [OFURLQueryOrFragmentAllowedCharacterSet class])
return;
URLQueryOrFragmentAllowedCharacterSet =
[[OFCharacterSet_URLQueryOrFragmentAllowed alloc] of_init];
[[OFURLQueryOrFragmentAllowedCharacterSet alloc] of_init];
}
+ (OFCharacterSet *)URLQueryOrFragmentAllowedCharacterSet
{
return URLQueryOrFragmentAllowedCharacterSet;
}
|
︙ | | |
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
|
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
-
+
|
return true;
default:
return false;
}
}
@end
@implementation OFCharacterSet_invertedSetWithPercent
@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
|
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 = [[[OFCharacterSet_invertedSetWithPercent alloc]
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 [OFCharacterSet_URLSchemeAllowed URLSchemeAllowedCharacterSet];
return [OFURLSchemeAllowedCharacterSet URLSchemeAllowedCharacterSet];
}
+ (OFCharacterSet *)URLHostAllowedCharacterSet
{
return [OFCharacterSet_URLAllowed URLAllowedCharacterSet];
return [OFURLAllowedCharacterSet URLAllowedCharacterSet];
}
+ (OFCharacterSet *)URLUserAllowedCharacterSet
{
return [OFCharacterSet_URLAllowed URLAllowedCharacterSet];
return [OFURLAllowedCharacterSet URLAllowedCharacterSet];
}
+ (OFCharacterSet *)URLPasswordAllowedCharacterSet
{
return [OFCharacterSet_URLAllowed URLAllowedCharacterSet];
return [OFURLAllowedCharacterSet URLAllowedCharacterSet];
}
+ (OFCharacterSet *)URLPathAllowedCharacterSet
{
return [OFCharacterSet_URLPathAllowed URLPathAllowedCharacterSet];
return [OFURLPathAllowedCharacterSet URLPathAllowedCharacterSet];
}
+ (OFCharacterSet *)URLQueryAllowedCharacterSet
{
return [OFCharacterSet_URLQueryOrFragmentAllowed
return [OFURLQueryOrFragmentAllowedCharacterSet
URLQueryOrFragmentAllowedCharacterSet];
}
+ (OFCharacterSet *)URLFragmentAllowedCharacterSet
{
return [OFCharacterSet_URLQueryOrFragmentAllowed
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
|
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: @"/"] ||
[OFURLHandler_file of_directoryExistsAtPath: path]);
[OFFileURLHandler of_directoryExistsAtPath: path]);
#elif defined(OF_AMIGAOS)
isDirectory = ([path hasSuffix: @"/"] ||
[path hasSuffix: @":"] ||
[OFURLHandler_file of_directoryExistsAtPath: path]);
[OFFileURLHandler of_directoryExistsAtPath: path]);
#else
isDirectory = ([path hasSuffix: @"/"] ||
[OFURLHandler_file of_directoryExistsAtPath: path]);
[OFFileURLHandler of_directoryExistsAtPath: path]);
#endif
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
|
︙ | | |