ObjFW  Diff

Differences From Artifact [945c020d4d]:

To Artifact [74dd1893f5]:


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#import "OFData+Private.h"
#import "OFString.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFFileManager.h"
#endif
#import "OFURL.h"
#ifdef OF_HAVE_SOCKETS
# import "OFHTTPClient.h"
# import "OFHTTPRequest.h"
# import "OFHTTPResponse.h"
#endif
#import "OFDictionary.h"
#import "OFXMLElement.h"
#import "OFSystemInfo.h"

#ifdef OF_HAVE_SOCKETS
# import "OFHTTPRequestFailedException.h"
#endif
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"







<
<
<
<
<




<
<
<







24
25
26
27
28
29
30





31
32
33
34



35
36
37
38
39
40
41
#import "OFData+Private.h"
#import "OFString.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
# import "OFFileManager.h"
#endif
#import "OFURL.h"





#import "OFDictionary.h"
#import "OFXMLElement.h"
#import "OFSystemInfo.h"




#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
#import "OFUnsupportedProtocolException.h"
250
251
252
253
254
255
256
257
258
259
260
261
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
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

	scheme = [URL scheme];

# ifdef OF_HAVE_FILES
	if ([scheme isEqual: @"file"])
		self = [self initWithContentsOfFile: [URL path]];
	else
# endif
# ifdef OF_HAVE_SOCKETS
	if ([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) {
		bool mutable = [self isKindOfClass: [OFMutableData class]];

		if (!mutable) {
			[self release];
			self = [OFMutableData alloc];
		}

		self = [(OFMutableData *)self init];

		@try {
			OFHTTPClient *client = [OFHTTPClient client];
			OFHTTPRequest *request = [OFHTTPRequest
			    requestWithURL: URL];
			OFHTTPResponse *response = [client
			    performRequest: request];
			size_t pageSize;
			char *buffer;
			OFDictionary *headers;
			OFString *contentLengthString;

			if ([response statusCode] != 200)
				@throw [OFHTTPRequestFailedException
				    exceptionWithRequest: request
						response: response];

			pageSize = [OFSystemInfo pageSize];
			buffer = [self allocMemoryWithSize: pageSize];

			@try {
				while (![response isAtEndOfStream]) {
					size_t length;

					length = [response
					    readIntoBuffer: buffer
						    length: pageSize];
					[(OFMutableData *)self
					    addItems: buffer
					       count: length];
				}
			} @finally {
				[self freeMemory: buffer];
			}

			headers = [response headers];
			if ((contentLengthString =
			    [headers objectForKey: @"Content-Length"]) != nil) {
				intmax_t contentLength =
				    [contentLengthString decimalValue];

				if (contentLength < 0)
					@throw [OFInvalidServerReplyException
					    exception];

				if ((uintmax_t)[self count] !=
				    (uintmax_t)contentLength)
					@throw [OFTruncatedDataException
					    exception];
			}
		} @catch (id e) {
			[self release];
			@throw e;
		}

		if (!mutable)
			[(OFMutableData *)self makeImmutable];
	} else
# endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	objc_autoreleasePoolPop(pool);

	return self;
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







242
243
244
245
246
247
248





































































249
250
251
252
253
254
255

	scheme = [URL scheme];

# ifdef OF_HAVE_FILES
	if ([scheme isEqual: @"file"])
		self = [self initWithContentsOfFile: [URL path]];
	else





































































# endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	objc_autoreleasePoolPop(pool);

	return self;
}