ObjFW  Check-in [e2f4c1283c]

Overview
Comment:OFString: Improved API for getting C strings.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e2f4c1283c21720ccdab22e047da3ab9b1ed30cb5a1e84608433ba337019eb22
User & Date: js on 2012-12-15 23:31:17
Other Links: manifest | tags
Context
2012-12-16
01:15
Add encodings for -[cStringUsingEncoding:]. check-in: 556234e290 user: js tags: trunk
2012-12-15
23:31
OFString: Improved API for getting C strings. check-in: e2f4c1283c user: js tags: trunk
20:35
OFHTTPRequest: Add property remoteAddress. check-in: b8d3e09eff user: js tags: trunk
Changes

Modified src/OFConstantString.m from [7dbd47e4c7] to [2b5371b50c].

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







-
+



-
+
















-
+



-
+







- (const char*)UTF8String
{
	[self finishInitialization];

	return [self UTF8String];
}

- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
- (const char*)cStringUsingEncoding: (of_string_encoding_t)encoding
{
	[self finishInitialization];

	return [self cStringWithEncoding: encoding];
	return [self cStringUsingEncoding: encoding];
}

- (size_t)length
{
	[self finishInitialization];

	return [self length];
}

- (size_t)UTF8StringLength
{
	[self finishInitialization];

	return [self UTF8StringLength];
}

- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
- (size_t)lengthOfBytesUsingEncoding: (of_string_encoding_t)encoding
{
	[self finishInitialization];

	return [self cStringLengthWithEncoding: encoding];
	return [self lengthOfBytesUsingEncoding: encoding];
}

- (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString
{
	[self finishInitialization];

	return [self caseInsensitiveCompare: otherString];

Modified src/OFDataArray.m from [9afe18d8f2] to [84f1c9eaa1].

175
176
177
178
179
180
181
182


183
184
185
186
187
188
189


190
191
192
193
194
195
196
175
176
177
178
179
180
181

182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
197
198







-
+
+






-
+
+







	self = [super init];

	@try {
		const char *cString;
		size_t i;

		itemSize = 1;
		count = [string UTF8StringLength];
		count = [string
		    lengthOfBytesUsingEncoding: OF_STRING_ENCODING_ASCII];

		if (count & 1)
			@throw [OFInvalidFormatException
			    exceptionWithClass: [self class]];

		count >>= 1;
		cString = [string UTF8String];
		cString = [string
		    cStringUsingEncoding: OF_STRING_ENCODING_ASCII];
		items = [self allocMemoryWithSize: count];

		for (i = 0; i < count; i++) {
			uint8_t c1 = cString[2 * i];
			uint8_t c2 = cString[2 * i + 1];
			uint8_t byte;

227
228
229
230
231
232
233
234

235
236

237
238
239
240
241
242
243
229
230
231
232
233
234
235

236
237

238
239
240
241
242
243
244
245







-
+

-
+







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

	@try {
		itemSize = 1;

		if (!of_base64_decode(self, [string cStringWithEncoding:
		if (!of_base64_decode(self, [string cStringUsingEncoding:
		    OF_STRING_ENCODING_ASCII], [string
		    cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) {
		    lengthOfBytesUsingEncoding: OF_STRING_ENCODING_ASCII])) {
			Class c = [self class];
			[self release];
			@throw [OFInvalidFormatException exceptionWithClass: c];
		}
	} @catch (id e) {
		[self release];
		@throw e;
260
261
262
263
264
265
266
267
268
269



270
271
272
273
274
275
276
262
263
264
265
266
267
268



269
270
271
272
273
274
275
276
277
278







-
-
-
+
+
+







		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		stringValue = [element stringValue];

		if (!of_base64_decode(self,
		    [stringValue cStringWithEncoding: OF_STRING_ENCODING_ASCII],
		    [stringValue cStringLengthWithEncoding:
		if (!of_base64_decode(self, [stringValue
		    cStringUsingEncoding: OF_STRING_ENCODING_ASCII],
		    [stringValue lengthOfBytesUsingEncoding:
		    OF_STRING_ENCODING_ASCII]))
			@throw [OFInvalidFormatException
			    exceptionWithClass: [self class]];

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

Modified src/OFFile.m from [d382f915ee] to [136919bb87].

201
202
203
204
205
206
207
208

209
210
211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234
235

236
237
238

239
240
241
242
243
244
245
201
202
203
204
205
206
207

208
209
210
211
212
213
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
229
230
231
232
233
234

235
236
237

238
239
240
241
242
243
244
245







-
+













-
+












-
+


-
+







	return ret;
}

+ (BOOL)fileExistsAtPath: (OFString*)path
{
	struct stat s;

	if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    &s) == -1)
		return NO;

	if (S_ISREG(s.st_mode))
		return YES;

	return NO;
}

+ (BOOL)directoryExistsAtPath: (OFString*)path
{
	struct stat s;

	if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    &s) == -1)
		return NO;

	if (S_ISDIR(s.st_mode))
		return YES;

	return NO;
}

+ (void)createDirectoryAtPath: (OFString*)path
{
#ifndef _WIN32
	if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (mkdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    DIR_MODE))
#else
	if (mkdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]))
	if (mkdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]))
#endif
		@throw [OFCreateDirectoryFailedException
		    exceptionWithClass: self
				  path: path];
}

+ (void)createDirectoryAtPath: (OFString*)path
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300







-
+







{
	OFMutableArray *files = [OFMutableArray array];

#ifndef _WIN32
	DIR *dir;
	struct dirent *dirent;

	if ((dir = opendir([path cStringWithEncoding:
	if ((dir = opendir([path cStringUsingEncoding:
	    OF_STRING_ENCODING_NATIVE])) == NULL)
		@throw [OFOpenFileFailedException exceptionWithClass: self
								path: path
							  mode: @"r"];

	@try {
		while ((dirent = readdir(dir)) != NULL) {
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
318
319
320
321
322
323
324

325
326
327
328
329
330
331
332







-
+







#else
	void *pool = objc_autoreleasePoolPush();
	HANDLE handle;
	WIN32_FIND_DATA fd;

	path = [path stringByAppendingString: @"\\*"];

	if ((handle = FindFirstFile([path cStringWithEncoding:
	if ((handle = FindFirstFile([path cStringUsingEncoding:
	    OF_STRING_ENCODING_NATIVE], &fd)) == INVALID_HANDLE_VALUE)
		@throw [OFOpenFileFailedException exceptionWithClass: self
								path: path
								mode: @"r"];

	@try {
		do {
354
355
356
357
358
359
360
361

362
363
364
365
366
367
368
369
370
371
372

373
374
375
376
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
411
412
413
414
415
416
417
418
419
420

421
422
423
424
425
426
427
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369
370
371

372
373
374
375
376
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
411
412
413
414
415
416
417
418
419

420
421
422
423
424
425
426
427







-
+










-
+






-
+












-
+













-
+













-
+







	[files makeImmutable];

	return files;
}

+ (void)changeToDirectoryAtPath: (OFString*)path
{
	if (chdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]))
	if (chdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]))
		@throw [OFChangeDirectoryFailedException
		    exceptionWithClass: self
				  path: path];
}

#ifndef _PSP
+ (void)changeModeOfFileAtPath: (OFString*)path
			  mode: (mode_t)mode
{
# ifndef _WIN32
	if (chmod([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], mode))
	if (chmod([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE], mode))
		@throw [OFChangeFileModeFailedException
		    exceptionWithClass: self
				  path: path
				  mode: mode];
# else
	DWORD attributes = GetFileAttributes(
	    [path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);
	    [path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]);

	if (attributes == INVALID_FILE_ATTRIBUTES)
		@throw [OFChangeFileModeFailedException
		    exceptionWithClass: self
				  path: path
				  mode: mode];

	if ((mode / 100) & 2)
		attributes &= ~FILE_ATTRIBUTE_READONLY;
	else
		attributes |= FILE_ATTRIBUTE_READONLY;

	if (!SetFileAttributes([path cStringWithEncoding:
	if (!SetFileAttributes([path cStringUsingEncoding:
	    OF_STRING_ENCODING_NATIVE], attributes))
		@throw [OFChangeFileModeFailedException
		    exceptionWithClass: self
				  path: path
				  mode: mode];
# endif
}
#endif

+ (off_t)sizeOfFileAtPath: (OFString*)path
{
	struct stat s;

	if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    &s) == -1)
		/* FIXME: Maybe use another exception? */
		@throw [OFOpenFileFailedException exceptionWithClass: self
								path: path
								mode: @"r"];

	return s.st_size;
}

+ (OFDate*)modificationDateOfFileAtPath: (OFString*)path
{
	struct stat s;

	if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    &s) == -1)
		/* FIXME: Maybe use another exception? */
		@throw [OFOpenFileFailedException exceptionWithClass: self
								path: path
								mode: @"r"];

	/* FIXME: We could be more precise on some OSes */
445
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
480
481
482
483
484

485
486
487
488
489
490
491
445
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
480
481
482
483

484
485
486
487
488
489
490
491







-
+













-
+

















-
+







		@throw [OFLockFailedException exceptionWithClass: self];

	@try {
# endif
		if (owner != nil) {
			struct passwd *passwd;

			if ((passwd = getpwnam([owner cStringWithEncoding:
			if ((passwd = getpwnam([owner cStringUsingEncoding:
			    OF_STRING_ENCODING_NATIVE])) == NULL)
				@throw [OFChangeFileOwnerFailedException
				    exceptionWithClass: self
						  path: path
						 owner: owner
						 group: group];

			uid = passwd->pw_uid;
		}

		if (group != nil) {
			struct group *group_;

			if ((group_ = getgrnam([group cStringWithEncoding:
			if ((group_ = getgrnam([group cStringUsingEncoding:
			    OF_STRING_ENCODING_NATIVE])) == NULL)
				@throw [OFChangeFileOwnerFailedException
				    exceptionWithClass: self
						  path: path
						 owner: owner
						 group: group];

			gid = group_->gr_gid;
		}
# ifdef OF_THREADS
	} @finally {
		if (!of_mutex_unlock(&mutex))
			@throw [OFUnlockFailedException
			    exceptionWithClass: self];
	}
# endif

	if (chown([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (chown([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    uid, gid))
		@throw [OFChangeFileOwnerFailedException
		    exceptionWithClass: self
				  path: path
				 owner: owner
				 group: group];
}
554
555
556
557
558
559
560
561
562


563
564
565


566
567
568
569
570
571
572
573
574
575
576
577
578

579
580

581
582
583
584
585
586
587
588

589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607


608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629


630
631
632
633
634
635
636
554
555
556
557
558
559
560


561
562
563


564
565
566
567
568
569
570
571
572
573
574
575
576
577

578
579

580
581
582
583
584
585
586
587

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605


606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627


628
629
630
631
632
633
634
635
636







-
-
+
+

-
-
+
+












-
+

-
+







-
+

















-
-
+
+




















-
-
+
+







	if ([self directoryExistsAtPath: destination]) {
		OFString *filename = [source lastPathComponent];
		destination = [OFString stringWithPath: destination, filename,
							nil];
	}

#ifndef _WIN32
	if (rename([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]))
	if (rename([source cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]))
#else
	if (!MoveFile([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]))
	if (!MoveFile([source cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]))
#endif
		@throw [OFRenameFileFailedException
		    exceptionWithClass: self
			    sourcePath: source
		       destinationPath: destination];

	objc_autoreleasePoolPop(pool);
}

+ (void)deleteFileAtPath: (OFString*)path
{
#ifndef _WIN32
	if (unlink([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]))
	if (unlink([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]))
#else
	if (!DeleteFile([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]))
	if (!DeleteFile([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]))
#endif
		@throw [OFDeleteFileFailedException exceptionWithClass: self
								  path: path];
}

+ (void)deleteDirectoryAtPath: (OFString*)path
{
	if (rmdir([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE]))
	if (rmdir([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]))
		@throw [OFDeleteDirectoryFailedException
		    exceptionWithClass: self
				  path: path];
}

#ifndef _WIN32
+ (void)linkFileAtPath: (OFString*)source
		toPath: (OFString*)destination
{
	void *pool = objc_autoreleasePoolPush();

	if ([self directoryExistsAtPath: destination]) {
		OFString *filename = [source lastPathComponent];
		destination = [OFString stringWithPath: destination, filename,
							nil];
	}

	if (link([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0)
	if (link([source cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]) != 0)
		@throw [OFLinkFailedException exceptionWithClass: self
						      sourcePath: source
						 destinationPath: destination];

	objc_autoreleasePoolPop(pool);
}
#endif

#if !defined(_WIN32) && !defined(_PSP)
+ (void)symlinkFileAtPath: (OFString*)source
		   toPath: (OFString*)destination
{
	void *pool = objc_autoreleasePoolPush();

	if ([self directoryExistsAtPath: destination]) {
		OFString *filename = [source lastPathComponent];
		destination = [OFString stringWithPath: destination, filename,
							nil];
	}

	if (symlink([source cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0)
	if (symlink([source cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    [destination cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]) != 0)
		@throw [OFSymlinkFailedException
		    exceptionWithClass: self
			    sourcePath: source
		       destinationPath: destination];

	objc_autoreleasePoolPop(pool);
}
648
649
650
651
652
653
654
655

656
657
658
659
660
661

662
663
664
665
666
667
668
648
649
650
651
652
653
654

655
656
657
658
659
660

661
662
663
664
665
666
667
668







-
+





-
+







	  mode: (OFString*)mode
{
	self = [super init];

	@try {
		int flags;

		if ((flags = parse_mode([mode cStringWithEncoding:
		if ((flags = parse_mode([mode cStringUsingEncoding:
		    OF_STRING_ENCODING_NATIVE])) == -1)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		if ((fd = open([path cStringWithEncoding:
		if ((fd = open([path cStringUsingEncoding:
		    OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1)
			@throw [OFOpenFileFailedException
			    exceptionWithClass: [self class]
					  path: path
					  mode: mode];

		closable = YES;

Modified src/OFObject.m from [517d28e9f2] to [5c04a02683].

229
230
231
232
233
234
235
236

237
238
239
240
241
242
243
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243







-
+







	return instance;
}

const char*
_NSPrintForDebugger(id object)
{
	return [[object description]
	    cStringWithEncoding: OF_STRING_ENCODING_NATIVE];
	    cStringUsingEncoding: OF_STRING_ENCODING_NATIVE];
}

/* References for static linking */
void _references_to_categories_of_OFObject(void)
{
	_OFObject_Serialization_reference = 1;
}

Modified src/OFPlugin.m from [1e21ccb1ef] to [26711ccaf1].

45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
45
46
47
48
49
50
51

52
53
54
55
56
57
58
59







-
+







	of_plugin_handle_t handle;
	OFPlugin *(*initPlugin)(void);
	OFPlugin *plugin;

	file = [OFMutableString stringWithString: path];
	[file appendString: @PLUGIN_SUFFIX];

	if ((handle = dlopen([file cStringWithEncoding:
	if ((handle = dlopen([file cStringUsingEncoding:
	    OF_STRING_ENCODING_NATIVE], RTLD_LAZY)) == NULL)
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];

	objc_autoreleasePoolPop(pool);

	initPlugin = (OFPlugin*(*)(void))dlsym(handle, "init_plugin");

Modified src/OFProcess.m from [0d39282550] to [ed7607de4d].

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







-
+




-
+








-
+







			OFString **objects = [arguments objects];
			size_t i, count = [arguments count];
			char **argv;

			argv = [self allocMemoryWithSize: sizeof(char*)
						   count: count + 2];

			argv[0] = (char*)[programName cStringWithEncoding:
			argv[0] = (char*)[programName cStringUsingEncoding:
			    OF_STRING_ENCODING_NATIVE];

			for (i = 0; i < count; i++)
				argv[i + 1] = (char*)[objects[i]
				    cStringWithEncoding:
				    cStringUsingEncoding:
				    OF_STRING_ENCODING_NATIVE];

			argv[i + 1] = NULL;

			close(readPipe[0]);
			close(writePipe[1]);
			dup2(writePipe[0], 0);
			dup2(readPipe[1], 1);
			execvp([program cStringWithEncoding:
			execvp([program cStringUsingEncoding:
			    OF_STRING_ENCODING_NATIVE], argv);

			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];
		case -1:
			@throw [OFInitializationFailedException
			    exceptionWithClass: [self class]];
195
196
197
198
199
200
201
202

203
204

205
206
207
208
209
210
211
195
196
197
198
199
200
201

202
203

204
205
206
207
208
209
210
211







-
+

-
+







			[argumentsString appendString: tmp];

			if (containsSpaces)
				[argumentsString appendString: @"\""];
		}

		argumentsCString = strdup([argumentsString
		    cStringWithEncoding: OF_STRING_ENCODING_NATIVE]);
		    cStringUsingEncoding: OF_STRING_ENCODING_NATIVE]);
		@try {
			if (!CreateProcess([program cStringWithEncoding:
			if (!CreateProcess([program cStringUsingEncoding:
			    OF_STRING_ENCODING_NATIVE], argumentsCString, NULL,
			    NULL, TRUE, 0, NULL, NULL, &si, &pi))
				@throw [OFInitializationFailedException
				    exceptionWithClass: [self class]];
		} @finally {
			free(argumentsString);
		}

Modified src/OFString.h from [0b6a858bc6] to [2600a4af67].

542
543
544
545
546
547
548













549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594








595
596
597
598
599
600
601
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572













573
574
575
576
577
578
579







580
581
582
583
584
585
586

587
588
589
590
591
592
593
594
595
596
597
598
599
600
601







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











-
-
-
-
-
-
-
-
-
-
-
-
-







-
-
-
-
-
-
-







-
+
+
+
+
+
+
+
+







 * @param URL The URL to the contents for the string
 * @param encoding The encoding to assume
 * @return An initialized OFString
 */
- initWithContentsOfURL: (OFURL*)URL
	       encoding: (of_string_encoding_t)encoding;

/*!
 * @brief Returns the OFString as a C string in the specified encoding.
 *
 * The result is valid until the autorelease pool is released. If you want to
 * use the result outside the scope of the current autorelease pool, you have to
 * copy it.
 *
 * @param encoding The encoding for the C string
 * @return The OFString as a C string in the specified encoding
 */
- (const char*)cStringUsingEncoding: (of_string_encoding_t)encoding
    OF_RETURNS_INNER_POINTER;

/*!
 * @brief Returns the OFString as a UTF-8 encoded C string.
 *
 * The result is valid until the autorelease pool is released. If you want to
 * use the result outside the scope of the current autorelease pool, you have to
 * copy it.
 *
 * @return The OFString as a UTF-8 encoded C string
 */
- (const char*)UTF8String OF_RETURNS_INNER_POINTER;

/*!
 * @brief Returns the OFString as a C string in the specified encoding.
 *
 * The result is valid until the autorelease pool is released. If you want to
 * use the result outside the scope of the current autorelease pool, you have to
 * copy it.
 *
 * @param encoding The encoding for the C string
 * @return The OFString as a C string in the specified encoding
 */
- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
    OF_RETURNS_INNER_POINTER;

/*!
 * @brief Returns the length of the string in Unicode characters.
 *
 * @return The length of the string in Unicode characters
 */
- (size_t)length;

/*!
 * @brief Returns the number of bytes the string needs in UTF-8 encoding.
 *
 * @return The number of bytes the string needs in UTF-8 encoding.
 */
- (size_t)UTF8StringLength;

/*!
 * @brief Returns the number of bytes the string needs in the specified
 *	  encoding.
 *
 * @param encoding The encoding for the string
 * @return The number of bytes the string needs in the specified encoding.
 */
- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding;
- (size_t)lengthOfBytesUsingEncoding: (of_string_encoding_t)encoding;

/*!
 * @brief Returns the number of bytes the string needs in UTF-8 encoding.
 *
 * @return The number of bytes the string needs in UTF-8 encoding.
 */
- (size_t)UTF8StringLength;

/*!
 * @brief Compares the OFString to another OFString without caring about the
 *	  case.
 *
 * @param otherString A string to compare with
 * @return An of_comparison_result_t

Modified src/OFString.m from [712053e8f6] to [10b3048cbe].

686
687
688
689
690
691
692
693

694
695
696
697
698
699
700
686
687
688
689
690
691
692

693
694
695
696
697
698
699
700







-
+







{
	char *tmp;
	struct stat st;

	@try {
		OFFile *file;

		if (stat([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
		if (stat([path cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
		    &st) == -1)
			@throw [OFOpenFileFailedException
			    exceptionWithClass: [self class]
					  path: path
					  mode: @"rb"];

		if (st.st_size > SIZE_MAX)
820
821
822
823
824
825
826
827

828
829
830
831

832
833
834








835
836

837
838
839
840
841
842
843
820
821
822
823
824
825
826

827
828
829
830

831

832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851







-
+



-
+
-


+
+
+
+
+
+
+
+


+







		[self release];
		@throw e;
	}

	return self;
}

- (const char*)UTF8String
- (const char*)cStringUsingEncoding: (of_string_encoding_t)encoding
{
	const of_unichar_t *unicodeString = [self unicodeString];
	char *UTF8String;
	size_t i, j = 0, length = [self length];
	size_t i, j = 0, length, UTF8StringLength;
	size_t UTF8StringLength = length;
	OFObject *object;

	if (encoding != OF_STRING_ENCODING_UTF_8)
		/* TODO: Implement! */
		@throw [OFNotImplementedException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	unicodeString = [self unicodeString];
	length = [self length];
	object = [[[OFObject alloc] init] autorelease];
	UTF8String = [object allocMemoryWithSize: (length * 4) + 1];
	UTF8StringLength = length;

	for (i = 0; i < length; i++) {
		char buffer[4];
		size_t len = of_string_utf8_encode(unicodeString[i], buffer);

		switch (len) {
		case 1:
878
879
880
881
882
883
884
885

886
887

888
889
890
891
892
893
894
895
896
897
898
899
900



901
902
903
904










905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921

922
923

924
925
926
927
928
929
930
931
932
933
934
935
886
887
888
889
890
891
892

893
894

895





896
897
898
899
900
901
902
903
904
905
906




907
908
909
910
911
912
913
914
915
916

917
918
919
920
921
922
923
924
925
926
927
928
929
930
931

932
933

934





935
936
937
938
939
940
941







-
+

-
+
-
-
-
-
-








+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-















-
+

-
+
-
-
-
-
-







	} @catch (OFOutOfMemoryException *e) {
		/* We don't care, as we only tried to make it smaller */
	}

	return UTF8String;
}

- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
- (const char*)UTF8String
{
	if (encoding == OF_STRING_ENCODING_UTF_8)
	return [self cStringUsingEncoding: OF_STRING_ENCODING_UTF_8];
		return [self UTF8String];

	/* TODO: Implement! */
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (size_t)length
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (size_t)lengthOfBytesUsingEncoding: (of_string_encoding_t)encoding
{
	const of_unichar_t *unicodeString;
- (size_t)UTF8StringLength
{
	const of_unichar_t *unicodeString = [self unicodeString];
	size_t length = [self length];
	size_t i, length, UTF8StringLength = 0;

	if (encoding != OF_STRING_ENCODING_UTF_8)
		/* TODO: Implement! */
		@throw [OFNotImplementedException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	unicodeString = [self unicodeString];
	length = [self length];
	size_t i, UTF8StringLength = 0;

	for (i = 0; i < length; i++) {
		char buffer[4];
		size_t len = of_string_utf8_encode(unicodeString[i], buffer);

		if (len == 0)
			@throw [OFInvalidEncodingException
			    exceptionWithClass: [self class]];

		UTF8StringLength += len;
	}

	return UTF8StringLength;
}

- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
- (size_t)UTF8StringLength
{
	if (encoding == OF_STRING_ENCODING_UTF_8)
	return [self lengthOfBytesUsingEncoding: OF_STRING_ENCODING_UTF_8];
		return [self UTF8StringLength];

	/* TODO: Implement! */
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

- (of_unichar_t)characterAtIndex: (size_t)index
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]
						    selector: _cmd];
}

Modified src/OFString_UTF8.m from [b90943c641] to [7793b455ee].

775
776
777
778
779
780
781
782
783
784
785
786
787

788
789
790
791
792
793
794
795
796
797
798
799

800
801
802
803





804
805
806
807
808
809
810
811
812
813
814
815

816
817
818
819
820
821
822
823
824
825
826
827

828
829
830
831





832
833
834
835
836
837
838
775
776
777
778
779
780
781






782
783
784
785
786
787
788
789
790
791
792
793

794


795
796
797
798
799
800
801
802
803
804
805
806
807






808
809
810
811
812
813
814
815
816
817
818
819

820


821
822
823
824
825
826
827
828
829
830
831
832
833
834







-
-
-
-
-
-
+











-
+
-
-


+
+
+
+
+






-
-
-
-
-
-
+











-
+
-
-


+
+
+
+
+







{
	if (s != NULL && s->freeWhenDone != NULL)
		free(s->freeWhenDone);

	[super dealloc];
}

- (const char*)UTF8String
{
	return s->cString;
}

- (const char*)cStringWithEncoding: (of_string_encoding_t)encoding
- (const char*)cStringUsingEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:
		return s->cString;
	case OF_STRING_ENCODING_ASCII:
		if (s->isUTF8)
			@throw [OFInvalidEncodingException
			    exceptionWithClass: [self class]];

		return s->cString;
	default:
		@throw [OFNotImplementedException
		return [super cStringUsingEncoding: encoding];
		    exceptionWithClass: [self class]
			      selector: _cmd];
	}
}

- (const char*)UTF8String
{
	return s->cString;
}

- (size_t)length
{
	return s->length;
}

- (size_t)UTF8StringLength
{
	return s->cStringLength;
}

- (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding
- (size_t)lengthOfBytesUsingEncoding: (of_string_encoding_t)encoding
{
	switch (encoding) {
	case OF_STRING_ENCODING_UTF_8:
		return s->cStringLength;
	case OF_STRING_ENCODING_ASCII:
		if (s->isUTF8)
			@throw [OFInvalidEncodingException
			    exceptionWithClass: [self class]];

		return s->cStringLength;
	default:
		@throw [OFNotImplementedException
		return [super lengthOfBytesUsingEncoding: encoding];
		    exceptionWithClass: [self class]
			      selector: _cmd];
	}
}

- (size_t)UTF8StringLength
{
	return s->cStringLength;
}

- (BOOL)isEqual: (id)object
{
	OFString_UTF8 *otherString;

	if (object == self)
		return YES;

Modified src/OFTCPSocket+SOCKS5.m from [b4620fe017] to [2044202797].

50
51
52
53
54
55
56
57
58


59
60

61
62
63
64
65
66
67
50
51
52
53
54
55
56


57
58
59

60
61
62
63
64
65
66
67







-
-
+
+

-
+







	oldWriteBufferEnabled = [self writeBufferEnabled];
	[self setWriteBufferEnabled: YES];

	/* CONNECT request */
	[self writeBuffer: request
		   length: 4];
	[self writeInt8:
	    [host cStringLengthWithEncoding: OF_STRING_ENCODING_NATIVE]];
	[self writeBuffer: [host cStringWithEncoding:
	    [host lengthOfBytesUsingEncoding: OF_STRING_ENCODING_NATIVE]];
	[self writeBuffer: [host cStringUsingEncoding:
			       OF_STRING_ENCODING_NATIVE]
		   length: [host cStringLengthWithEncoding:
		   length: [host lengthOfBytesUsingEncoding:
			       OF_STRING_ENCODING_NATIVE]];
	[self writeBigEndianInt16: port];

	[self flushWriteBuffer];
	[self setWriteBufferEnabled: oldWriteBufferEnabled];

	[self readIntoBuffer: reply

Modified src/OFTCPSocket.m from [d55696187d] to [a9ec628526].

308
309
310
311
312
313
314
315

316
317
318
319
320
321
322
308
309
310
311
312
313
314

315
316
317
318
319
320
321
322







-
+







	char portCString[7];

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	snprintf(portCString, 7, "%" PRIu16, port);

	if (getaddrinfo([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (getaddrinfo([host cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    portCString, &hints, &res0))
		@throw [OFAddressTranslationFailedException
		    exceptionWithClass: [self class]
				socket: self
				  host: host];

	for (res = res0; res != NULL; res = res->ai_next) {
342
343
344
345
346
347
348
349

350
351
352
353
354
355
356
342
343
344
345
346
347
348

349
350
351
352
353
354
355
356







-
+







# ifdef OF_THREADS
	OFDataArray *addrlist;

	addrlist = [[OFDataArray alloc] initWithItemSize: sizeof(char**)];
	[mutex lock];
# endif

	if ((he = gethostbyname([host cStringWithEncoding:
	if ((he = gethostbyname([host cStringUsingEncoding:
	    OF_STRING_ENCODING_NATIVE])) == NULL) {
# ifdef OF_THREADS
		[addrlist release];
		[mutex unlock];
# endif
		@throw [OFAddressTranslationFailedException
		    exceptionWithClass: [self class]
485
486
487
488
489
490
491
492

493
494
495
496
497
498
499
485
486
487
488
489
490
491

492
493
494
495
496
497
498
499







-
+







	char portCString[7];

	memset(&hints, 0, sizeof(struct addrinfo));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	snprintf(portCString, 7, "%" PRIu16, port);

	if (getaddrinfo([host cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
	if (getaddrinfo([host cStringUsingEncoding: OF_STRING_ENCODING_NATIVE],
	    portCString, &hints, &res))
		@throw [OFAddressTranslationFailedException
		    exceptionWithClass: [self class]
				socket: self
				  host: host];

	if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
516
517
518
519
520
521
522
523

524
525
526
527
528
529
530
516
517
518
519
520
521
522

523
524
525
526
527
528
529
530







-
+







#else
	struct hostent *he;

# ifdef OF_THREADS
	[mutex lock];
# endif

	if ((he = gethostbyname([host cStringWithEncoding:
	if ((he = gethostbyname([host cStringUsingEncoding:
	    OF_STRING_ENCODING_NATIVE])) == NULL) {
# ifdef OF_THREADS
		[mutex unlock];
# endif
		@throw [OFAddressTranslationFailedException
		    exceptionWithClass: [self class]
				socket: self

Modified src/OFXMLElement+Serialization.m from [2f13ccd9ab] to [9ca8fe4ac9].

32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46







-
+







@implementation OFXMLElement (Serialization)
- (id)objectByDeserializing
{
	void *pool = objc_autoreleasePoolPush();
	Class class;
	id object;

	if ((class = objc_lookUpClass([name cStringWithEncoding:
	if ((class = objc_getClass([name cStringUsingEncoding:
	    OF_STRING_ENCODING_ASCII])) == Nil)
		@throw [OFNotImplementedException exceptionWithClass: Nil];

	if (![class conformsToProtocol: @protocol(OFSerialization)])
		@throw [OFNotImplementedException
		    exceptionWithClass: class
			      selector: @selector(initWithSerialization:)];