ObjFW  Diff

Differences From Artifact [e58d501e5e]:

  • File src/OFDataArray.m — part of check-in [13ee56edf3] at 2014-06-21 21:43:43 on branch trunk — Move all macros from OFObject.h to macros.h

    This means that OFObject.h imports macros.h now, making it unnecessary
    to manually import macros.h in almost every file. And while at it, also
    import autorelease.h in OFObject.h, so that this doesn't need to be
    manually imported in almost every file as well. (user: js, size: 14228) [annotate] [blame] [check-ins using]

To Artifact [41037dbb74]:


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
	return self;
}
#endif

- initWithContentsOfURL: (OFURL*)URL
{
	void *pool;
#ifdef OF_HAVE_SOCKETS
	OFHTTPClient *client;
	OFHTTPRequest *request;
	OFHTTPResponse *response;
	OFDictionary *headers;
	OFString *contentLength;
#endif
#ifdef OF_HAVE_FILES
	Class c = [self class];
#endif

	[self release];

	pool = objc_autoreleasePoolPush();

	if ([[URL scheme] isEqual: @"file"]) {

#ifdef OF_HAVE_FILES

		self = [[c alloc] initWithContentsOfFile: [URL path]];
		objc_autoreleasePoolPop(pool);
		return self;
#else
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
#endif
	}

#ifdef OF_HAVE_SOCKETS

	client = [OFHTTPClient client];
	request = [OFHTTPRequest requestWithURL: URL];
	response = [client performRequest: request];



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

	/*
	 * TODO: This can be optimized by allocating a data array with the
	 * capacity from the Content-Length header.
	 */
	self = [[response readDataArrayTillEndOfStream] retain];

	headers = [response headers];

	if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil)

		if ([self count] != (size_t)[contentLength decimalValue])
			@throw [OFTruncatedDataException exception];
#else
	@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
#endif


	objc_autoreleasePoolPop(pool);

	return self;
}

- initWithStringRepresentation: (OFString*)string







<
<
<
<
<
|
<








|
>

>

<
<
|
<

<
<

>
|
|
|
>
>

|
|
|
|

|
|
|
|
|

|
>
|
>
|
|
|
<

>







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
	return self;
}
#endif

- initWithContentsOfURL: (OFURL*)URL
{
	void *pool;





	OFString *scheme;

#ifdef OF_HAVE_FILES
	Class c = [self class];
#endif

	[self release];

	pool = objc_autoreleasePoolPush();

	scheme = [URL scheme];

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


	else

#endif


#ifdef OF_HAVE_SOCKETS
	if ([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) {
		OFHTTPClient *client = [OFHTTPClient client];
		OFHTTPRequest *request = [OFHTTPRequest requestWithURL: URL];
		OFHTTPResponse *response = [client performRequest: request];
		OFDictionary *headers;
		OFString *contentLength;

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

		/*
		 * TODO: This can be optimized by allocating a data array with
		 * the capacity from the Content-Length header.
		 */
		self = [[response readDataArrayTillEndOfStream] retain];

		headers = [response headers];
		if ((contentLength =
		    [headers objectForKey: @"Content-Length"]) != nil)
			if ([self count] !=
			    (size_t)[contentLength decimalValue])
				@throw [OFTruncatedDataException exception];
	} else

#endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	objc_autoreleasePoolPop(pool);

	return self;
}

- initWithStringRepresentation: (OFString*)string