ObjFW  Diff

Differences From Artifact [bc22950fc0]:

To Artifact [6274573b21]:


17
18
19
20
21
22
23
24
25



26
27
28
29
30
31
32
17
18
19
20
21
22
23


24
25
26
27
28
29
30
31
32
33







-
-
+
+
+







#include "config.h"

#include <stdlib.h>
#include <string.h>

#import "OFURL.h"
#import "OFURL+Private.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFString.h"
#import "OFXMLElement.h"

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

@implementation OFURL
85
86
87
88
89
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
116
117
118
86
87
88
89
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







+
+
-
+
+











-
-
-
-
-
-
-
-







		if ((UTF8String2 = of_strdup([string UTF8String])) == NULL)
			@throw [OFOutOfMemoryException
			     exceptionWithRequestedSize:
			     [string UTF8StringLength]];

		UTF8String = UTF8String2;

		if ((tmp = strchr(UTF8String, ':')) == NULL)
			@throw [OFInvalidFormatException exception];
		if ((tmp = strstr(UTF8String, "://")) == NULL)

		if (strncmp(tmp, "://", 3) != 0)
			@throw [OFInvalidFormatException exception];

		for (tmp2 = UTF8String; tmp2 < tmp; tmp2++)
			*tmp2 = of_ascii_tolower(*tmp2);

		_scheme = [[OFString alloc]
		    initWithUTF8String: UTF8String
				length: tmp - UTF8String];

		UTF8String = tmp + 3;

		if ([_scheme isEqual: @"file"]) {
			_path = [[OFString alloc]
			    initWithUTF8String: UTF8String];

			objc_autoreleasePoolPop(pool);
			return self;
		}

		if ((tmp = strchr(UTF8String, '/')) != NULL) {
			*tmp = '\0';
			tmp++;
		}

		if ((tmp2 = strchr(UTF8String, '@')) != NULL) {
			char *tmp3;
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
143
144
145
146
147
148
149
150

151
152
153

154
155
156
157








158
159
160
161
162
163
164







+
-
+


-
+



-
-
-
-
-
-
-
-








			pool2 = objc_autoreleasePoolPush();
			portString = [OFString stringWithUTF8String: tmp2];

			if ([portString decimalValue] > 65535)
				@throw [OFInvalidFormatException exception];

			_port = [[OFNumber alloc] initWithUInt16:
			_port = [portString decimalValue];
			    (uint16_t)[portString decimalValue]];

			objc_autoreleasePoolPop(pool2);
		} else {
		} else
			_host = [[OFString alloc]
			    initWithUTF8String: UTF8String];

			if ([_scheme isEqual: @"http"])
				_port = 80;
			else if ([_scheme isEqual: @"https"])
				_port = 443;
			else if ([_scheme isEqual: @"ftp"])
				_port = 21;
		}

		if ((UTF8String = tmp) != NULL) {
			if ((tmp = strchr(UTF8String, '#')) != NULL) {
				*tmp = '\0';

				_fragment = [[OFString alloc]
				    initWithUTF8String: tmp + 1];
			}
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
207
208
209
210
211
212
213

214
215
216
217
218
219
220
221







-
+








	@try {
		void *pool = objc_autoreleasePoolPush();
		char *tmp;

		_scheme = [URL->_scheme copy];
		_host = [URL->_host copy];
		_port = URL->_port;
		_port = [URL->_port copy];
		_user = [URL->_user copy];
		_password = [URL->_password copy];

		if ((UTF8String2 = of_strdup([string UTF8String])) == NULL)
			@throw [OFOutOfMemoryException
			     exceptionWithRequestedSize:
			     [string UTF8StringLength]];
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
360
361

362
363
364
365
366
367
368
289
290
291
292
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







+



















-
+

-
+

-
+



-
+
-

-
+




-
+
-

-
+
-













-
-
+







	return self;
}

- (void)dealloc
{
	[_scheme release];
	[_host release];
	[_port release];
	[_user release];
	[_password release];
	[_path release];
	[_parameters release];
	[_query release];
	[_fragment release];

	[super dealloc];
}

- (bool)isEqual: (id)object
{
	OFURL *URL;

	if (![object isKindOfClass: [OFURL class]])
		return false;

	URL = object;

	if (![URL->_scheme isEqual: _scheme])
	if (URL->_scheme != _scheme && ![URL->_scheme isEqual: _scheme])
		return false;
	if (![URL->_host isEqual: _host])
	if (URL->_host != _host && ![URL->_host isEqual: _host])
		return false;
	if (URL->_port != _port)
	if (URL->_port != _port && ![URL->_port isEqual: _port])
		return false;
	if (URL->_user != _user && ![URL->_user isEqual: _user])
		return false;
	if (URL->_password != _password &&
	if (URL->_password != _password && ![URL->_password isEqual: _password])
	    ![URL->_password isEqual: _password])
		return false;
	if (![URL->_path isEqual: _path])
	if (URL->_path != _path && ![URL->_path isEqual: _path])
		return false;
	if (URL->_parameters != _parameters &&
	    ![URL->_parameters isEqual: _parameters])
		return false;
	if (URL->_query != _query &&
	if (URL->_query != _query && ![URL->_query isEqual: _query])
	    ![URL->_query isEqual: _query])
		return false;
	if (URL->_fragment != _fragment &&
	if (URL->_fragment != _fragment && ![URL->_fragment isEqual: _fragment])
	    ![URL->_fragment isEqual: _fragment])
		return false;

	return true;
}

- (uint32_t)hash
{
	uint32_t hash;

	OF_HASH_INIT(hash);

	OF_HASH_ADD_HASH(hash, [_scheme hash]);
	OF_HASH_ADD_HASH(hash, [_host hash]);
	OF_HASH_ADD(hash, (_port & 0xFF00) >> 8);
	OF_HASH_ADD(hash, _port & 0xFF);
	OF_HASH_ADD_HASH(hash, [_port hash]);
	OF_HASH_ADD_HASH(hash, [_user hash]);
	OF_HASH_ADD_HASH(hash, [_password hash]);
	OF_HASH_ADD_HASH(hash, [_path hash]);
	OF_HASH_ADD_HASH(hash, [_parameters hash]);
	OF_HASH_ADD_HASH(hash, [_query hash]);
	OF_HASH_ADD_HASH(hash, [_fragment hash]);

377
378
379
380
381
382
383
384

385
386
387
388
389
390
391
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377







-
+







}

- (OFString *)host
{
	return _host;
}

- (uint16_t)port
- (OFNumber *)port
{
	return _port;
}

- (OFString *)user
{
	return _user;
446
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
432
433
434
435
436
437
438








439
440
441
442
443
444
445

446




447
448
449
450
451
452
453
454







-
-
-
-
-
-
-
-







-
+
-
-
-
-
+







- (OFString *)string
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();

	[ret appendFormat: @"%@://", _scheme];

	if ([_scheme isEqual: @"file"]) {
		if (_path != nil)
			[ret appendString: _path];

		objc_autoreleasePoolPop(pool);
		return ret;
	}

	if (_user != nil && _password != nil)
		[ret appendFormat: @"%@:%@@", _user, _password];
	else if (_user != nil)
		[ret appendFormat: @"%@@", _user];

	if (_host != nil)
		[ret appendString: _host];

	if (_port != nil)
	if (!(([_scheme isEqual: @"http"] && _port == 80) ||
	    ([_scheme isEqual: @"https"] && _port == 443) ||
	    ([_scheme isEqual: @"ftp"] && _port == 21)))
		[ret appendFormat: @":%u", _port];
		[ret appendFormat: @":%@", _port];

	if (_path != nil) {
		if (![_path hasPrefix: @"/"])
			@throw [OFInvalidFormatException exception];

		[ret appendString: _path];
	}