ObjFW  Diff

Differences From Artifact [fd812a6a57]:

To Artifact [55c91c5cfd]:


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
68
69

70

71
72
73
74
75
76
77
78
79
80
81
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
68
69
70
71

72
73
74
75
76


77
78
79
80
81
82
83







-
+




+
+
+














-
+

+


-
-








@interface OFURISchemeAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURIPathAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURIQueryOrFragmentAllowedCharacterSet: OFURIAllowedCharacterSetBase
@interface OFURIQueryAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURIQueryKeyValueAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURIFragmentAllowedCharacterSet: 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 *URIQueryAllowedCharacterSet = nil;
static OFCharacterSet *URIQueryKeyValueAllowedCharacterSet = nil;
static OFCharacterSet *URIFragmentAllowedCharacterSet = nil;

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

static void
initURIAllowedCharacterSet(void)
{
	URIAllowedCharacterSet = [[OFURIAllowedCharacterSet alloc] init];
}

90
91
92
93
94
95
96
97

98
99
100


101
102
103
104
105
106
107
108







109
110
111
112
113
114
115
92
93
94
95
96
97
98

99
100


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124







-
+

-
-
+
+








+
+
+
+
+
+
+







initURIPathAllowedCharacterSet(void)
{
	URIPathAllowedCharacterSet =
	    [[OFURIPathAllowedCharacterSet alloc] init];
}

static void
initURIQueryOrFragmentAllowedCharacterSet(void)
initURIQueryAllowedCharacterSet(void)
{
	URIQueryOrFragmentAllowedCharacterSet =
	    [[OFURIQueryOrFragmentAllowedCharacterSet alloc] init];
	URIQueryAllowedCharacterSet =
	    [[OFURIQueryAllowedCharacterSet alloc] init];
}

static void
initURIQueryKeyValueAllowedCharacterSet(void)
{
	URIQueryKeyValueAllowedCharacterSet =
	    [[OFURIQueryKeyValueAllowedCharacterSet alloc] init];
}

static void
initURIFragmentAllowedCharacterSet(void)
{
	URIFragmentAllowedCharacterSet =
	    [[OFURIFragmentAllowedCharacterSet alloc] init];
}

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

123
124
125
126
127
128
129













130
131
132
133
134
135
136
132
133
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







+
+
+
+
+
+
+
+
+
+
+
+
+







			hasColon = true;

		UTF8String++;
	}

	return hasColon;
}

static bool
isUnicodePrivate(OFUnichar character)
{
	if (character >= 0xE00 && character <= 0xF8FF)
		return true;
	if (character >= 0xF0000 && character <= 0xFFFFD)
		return true;
	if (character >= 0x100000 && character <= 0x10FFFD)
		return true;

	return false;
}

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

151
152
153
154
155
156
157



158
159
160
161
162
163
164
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189







+
+
+








@implementation OFURIAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	if (character > 0x7F)
		return !isUnicodePrivate(character);

	switch (character) {
	case '-':
	case '.':
	case '_':
	case '~':
	case '!':
	case '$':
197
198
199
200
201
202
203



204
205
206
207
208
209
210
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238







+
+
+








@implementation OFURIPathAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	if (character > 0x7F)
		return !isUnicodePrivate(character);

	switch (character) {
	case '-':
	case '.':
	case '_':
	case '~':
	case '!':
	case '$':
223
224
225
226
227
228
229
230

231
232
233
234



235
236
237
238
239
240
241
251
252
253
254
255
256
257

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272







-
+




+
+
+







		return true;
	default:
		return false;
	}
}
@end

@implementation OFURIQueryOrFragmentAllowedCharacterSet
@implementation OFURIQueryAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	if (character > 0x7F)
		return true;

	switch (character) {
	case '-':
	case '.':
	case '_':
	case '~':
	case '!':
262
263
264
265
266
267
268





































269
270
271
272
273
274
275

276
277
278
279
280
281
282

283
284
285
286
287
288
289
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







+







+








@implementation OFURIQueryKeyValueAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	if (character > 0x7F)
		return true;

	switch (character) {
	case '-':
	case '.':
	case '_':
	case '~':
	case '!':
	case '$':
	case '\'':
	case '(':
	case ')':
	case '*':
	case '+':
	case ',':
	case ';':
	case ':':
	case '@':
	case '/':
	case '?':
		return true;
	default:
		return false;
	}
}
@end

@implementation OFURIFragmentAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	if (character > 0x7F)
		return !isUnicodePrivate(character);

	switch (character) {
	case '-':
	case '.':
	case '_':
	case '~':
	case '!':
	case '$':
	case '&':
	case '\'':
	case '(':
	case ')':
	case '*':
	case '+':
	case ',':
	case ';':
	case '=':
	case ':':
	case '@':
	case '/':
	case '?':
		return true;
	default:
		return false;
377
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
447
448
449
450
451
452
453


454
455
456

457
458
459
460
461
462
463
464
465
466
467
468
469


470
471
472

473
474
475
476
477
478
479
480







-
-
+
+

-
+












-
-
+
+

-
+







	OFOnce(&onceControl, initURIPathAllowedCharacterSet);

	return URIPathAllowedCharacterSet;
}

+ (OFCharacterSet *)URIQueryAllowedCharacterSet
{
	OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce,
	    initURIQueryOrFragmentAllowedCharacterSet);
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initURIQueryAllowedCharacterSet);

	return URIQueryOrFragmentAllowedCharacterSet;
	return URIQueryAllowedCharacterSet;
}

+ (OFCharacterSet *)URIQueryKeyValueAllowedCharacterSet
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initURIQueryKeyValueAllowedCharacterSet);

	return URIQueryKeyValueAllowedCharacterSet;
}

+ (OFCharacterSet *)URIFragmentAllowedCharacterSet
{
	OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce,
	    initURIQueryOrFragmentAllowedCharacterSet);
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initURIFragmentAllowedCharacterSet);

	return URIQueryOrFragmentAllowedCharacterSet;
	return URIFragmentAllowedCharacterSet;
}
@end

@implementation OFURI
+ (instancetype)URI
{
	return [[[self alloc] init] autorelease];
579
580
581
582
583
584
585
586

587
588
589
590
591
592
593
649
650
651
652
653
654
655

656
657
658
659
660
661
662
663







-
+







		length = query - UTF8String;
	}

	*pathString = [OFString stringWithUTF8String: UTF8String
					      length: length];

	OFURIVerifyIsEscaped(*pathString,
	    [OFCharacterSet URIQueryAllowedCharacterSet], true);
	    [OFCharacterSet URIPathAllowedCharacterSet], true);
}

- (instancetype)initWithString: (OFString *)string
{
	self = [super init];

	@try {