ObjFW  Diff

Differences From Artifact [1abecd6ce8]:

To Artifact [b38122cc28]:


267
268
269
270
271
272
273
274

275
276
277
278
279
280
281


282
283

284
285
286
287
288
289
290
267
268
269
270
271
272
273

274
275
276
277
278
279


280
281
282

283
284
285
286
287
288
289
290







-
+





-
-
+
+

-
+







	return _protocolVersion;
}

- (void)setProtocolVersionString: (OFString *)string
{
	void *pool = objc_autoreleasePoolPush();
	OFArray *components = [string componentsSeparatedByString: @"."];
	intmax_t major, minor;
	unsigned long long major, minor;
	of_http_request_protocol_version_t protocolVersion;

	if (components.count != 2)
		@throw [OFInvalidFormatException exception];

	major = [components.firstObject decimalValue];
	minor = [components.lastObject decimalValue];
	major = [components.firstObject unsignedLongLongValue];
	minor = [components.lastObject unsignedLongLongValue];

	if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX)
	if (major > UINT8_MAX || minor > UINT8_MAX)
		@throw [OFOutOfRangeException exception];

	protocolVersion.major = (uint8_t)major;
	protocolVersion.minor = (uint8_t)minor;

	self.protocolVersion = protocolVersion;

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







-
+











-
-
+
+
+
+
+
+
+
+
+

+







{
	return [self stringWithEncoding: OF_STRING_ENCODING_AUTODETECT];
}

- (OFString *)stringWithEncoding: (of_string_encoding_t)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFString *contentType, *contentLength, *ret;
	OFString *contentType, *contentLengthString, *ret;
	OFData *data;

	if (encoding == OF_STRING_ENCODING_AUTODETECT &&
	    (contentType = [_headers objectForKey: @"Content-Type"]) != nil)
		encoding = encodingForContentType(contentType);

	if (encoding == OF_STRING_ENCODING_AUTODETECT)
		encoding = OF_STRING_ENCODING_UTF_8;

	data = [self readDataUntilEndOfStream];

	if ((contentLength = [_headers objectForKey: @"Content-Length"]) != nil)
		if (data.count != (size_t)contentLength.decimalValue)
	contentLengthString = [_headers objectForKey: @"Content-Length"];
	if (contentLengthString != nil) {
		unsigned long long contentLength =
		    contentLengthString.unsignedLongLongValue;

		if (contentLength > SIZE_MAX)
			@throw [OFOutOfRangeException exception];

		if (data.count != (size_t)contentLength)
			@throw [OFTruncatedDataException exception];
	}

	ret = [[OFString alloc] initWithCString: (char *)data.items
				       encoding: encoding
					 length: data.count];

	objc_autoreleasePoolPop(pool);