ObjFW  Diff

Differences From Artifact [31a910dc3b]:

To Artifact [3f32c8135b]:


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "OFFile.h"
#import "OFURL.h"
#import "OFHTTPRequest.h"
#import "OFXMLElement.h"

#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "autorelease.h"
#import "base64.h"
#import "macros.h"







|







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "OFFile.h"
#import "OFURL.h"
#import "OFHTTPRequest.h"
#import "OFXMLElement.h"

#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "autorelease.h"
#import "base64.h"
#import "macros.h"
60
61
62
63
64
65
66






67
68
69
70
71
72
73
	return [[[self alloc] initWithContentsOfFile: path] autorelease];
}

+ dataArrayWithContentsOfURL: (OFURL*)URL
{
	return [[[self alloc] initWithContentsOfURL: URL] autorelease];
}







+ dataArrayWithBase64EncodedString: (OFString*)string
{
	return [[[self alloc] initWithBase64EncodedString: string] autorelease];
}

- init







>
>
>
>
>
>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
	return [[[self alloc] initWithContentsOfFile: path] autorelease];
}

+ dataArrayWithContentsOfURL: (OFURL*)URL
{
	return [[[self alloc] initWithContentsOfURL: URL] autorelease];
}

+ dataArrayWithStringRepresentation: (OFString*)string
{
	return [[[self alloc]
	    initWithStringRepresentation: string] autorelease];
}

+ dataArrayWithBase64EncodedString: (OFString*)string
{
	return [[[self alloc] initWithBase64EncodedString: string] autorelease];
}

- init
156
157
158
159
160
161
162
163






















































164
165
166
167

168
169
170
171
172
173
174
175




176
177
178
179
180
181
182
			       request: request
				result: result];

	self = [[result data] retain];
	objc_autoreleasePoolPop(pool);
	return self;
}























































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


	itemSize = 1;

	if (!of_base64_decode(self,
	    [string cStringWithEncoding: OF_STRING_ENCODING_ASCII],
	    [string cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) {
		Class c = [self class];
		[self release];
		@throw [OFInvalidEncodingException exceptionWithClass: c];




	}

	return self;
}

- initWithSerialization: (OFXMLElement*)element
{








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
|

|
|
|
|
|
|
>
>
>
>







162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
246
247
			       request: request
				result: result];

	self = [[result data] retain];
	objc_autoreleasePoolPop(pool);
	return self;
}

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

	@try {
		const char *cString;
		size_t i;

		itemSize = 1;
		count = [string UTF8StringLength];

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

		count >>= 1;
		cString = [string UTF8String];
		data = [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;

			if (c1 >= '0' && c1 <= '9')
				byte = (c1 - '0') << 4;
			else if (c1 >= 'a' && c1 <= 'f')
				byte = (c1 - 'a' + 10) << 4;
			else if (c1 >= 'A' && c1 <= 'F')
				byte = (c1 - 'A' + 10) << 4;
			else
				@throw [OFInvalidFormatException
				    exceptionWithClass: [self class]];

			if (c2 >= '0' && c2 <= '9')
				byte |= c2 - '0';
			else if (c2 >= 'a' && c2 <= 'f')
				byte |= c2 - 'a' + 10;
			else if (c2 >= 'A' && c2 <= 'F')
				byte |= c2 - 'A' + 10;
			else
				@throw [OFInvalidFormatException
				    exceptionWithClass: [self class]];

			data[i] = byte;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

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

	@try {
		itemSize = 1;

		if (!of_base64_decode(self, [string cStringWithEncoding:
		    OF_STRING_ENCODING_ASCII], [string
		    cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) {
			Class c = [self class];
			[self release];
			@throw [OFInvalidFormatException exceptionWithClass: c];
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithSerialization: (OFXMLElement*)element
{
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

		stringValue = [element stringValue];

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

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







|







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

		stringValue = [element stringValue];

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

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}
441
442
443
444
445
446
447













448
449
450
451
452
453
454

		for (j = 0; j < itemSize; j++)
			[ret appendFormat: @"%02x", data[i * itemSize + j]];
	}

	[ret appendString: @">"];














	[ret makeImmutable];
	return ret;
}

- (OFString*)stringByBase64Encoding
{
	return of_base64_encode(data, count * itemSize);







>
>
>
>
>
>
>
>
>
>
>
>
>







506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532

		for (j = 0; j < itemSize; j++)
			[ret appendFormat: @"%02x", data[i * itemSize + j]];
	}

	[ret appendString: @">"];

	[ret makeImmutable];
	return ret;
}

- (OFString*)stringRepresentation
{
	OFMutableString *ret = [OFMutableString string];
	size_t i, j;

	for (i = 0; i < count; i++)
		for (j = 0; j < itemSize; j++)
			[ret appendFormat: @"%02x", data[i * itemSize + j]];

	[ret makeImmutable];
	return ret;
}

- (OFString*)stringByBase64Encoding
{
	return of_base64_encode(data, count * itemSize);