ObjFW  Check-in [dbe286c39f]

Overview
Comment:initWithContentsOfURL: Require files or sockets
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dbe286c39fb2f2949dc83ddfc8af1f7d2eb484b3de999c82360141e1696519ac
User & Date: js on 2015-05-14 09:10:55
Other Links: manifest | tags
Context
2015-05-14
09:32
configure: Check for SSIZE_MAX check-in: ea080ec7ac user: js tags: trunk
09:10
initWithContentsOfURL: Require files or sockets check-in: dbe286c39f user: js tags: trunk
2015-05-10
21:48
OFZIPArchive_FileStream: Add _closed ivar check-in: 85c16c3a42 user: js tags: trunk
Changes

Modified src/OFDataArray.h from [c3cbb81f31] to [5959e95840].

88
89
90
91
92
93
94

95
96
97
98
99
100
101
102

103
104
105
106
107
108
109
 *
 * @param path The path of the file
 * @return A new autoreleased OFDataArray
 */
+ (instancetype)dataArrayWithContentsOfFile: (OFString*)path;
#endif


/*!
 * @brief Creates a new OFDataArray with an item size of 1, containing the data
 *	  of the specified URL.
 *
 * @param URL The URL to the contents for the OFDataArray
 * @return A new autoreleased OFDataArray
 */
+ (instancetype)dataArrayWithContentsOfURL: (OFURL*)URL;


/*!
 * @brief Creates a new OFDataArray with an item size of 1, containing the data
 *	  of the string representation.
 *
 * @param string The string representation of the data
 * @return A new autoreleased OFDataArray







>








>







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 *
 * @param path The path of the file
 * @return A new autoreleased OFDataArray
 */
+ (instancetype)dataArrayWithContentsOfFile: (OFString*)path;
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
/*!
 * @brief Creates a new OFDataArray with an item size of 1, containing the data
 *	  of the specified URL.
 *
 * @param URL The URL to the contents for the OFDataArray
 * @return A new autoreleased OFDataArray
 */
+ (instancetype)dataArrayWithContentsOfURL: (OFURL*)URL;
#endif

/*!
 * @brief Creates a new OFDataArray with an item size of 1, containing the data
 *	  of the string representation.
 *
 * @param string The string representation of the data
 * @return A new autoreleased OFDataArray
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170

171
172
173
174
175
176
177
 *
 * @param path The path of the file
 * @return An initialized OFDataArray
 */
- initWithContentsOfFile: (OFString*)path;
#endif


/*!
 * @brief Initializes an already allocated OFDataArray with an item size of 1,
 *	  containing the data of the specified URL.
 *
 * @param URL The URL to the contents for the OFDataArray
 * @return A new autoreleased OFDataArray
 */
- initWithContentsOfURL: (OFURL*)URL;


/*!
 * @brief Initializes an already allocated OFDataArray with an item size of 1,
 *	  containing the data of the string representation.
 *
 * @param string The string representation of the data
 * @return A new autoreleased OFDataArray







>








>







158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
 *
 * @param path The path of the file
 * @return An initialized OFDataArray
 */
- initWithContentsOfFile: (OFString*)path;
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
/*!
 * @brief Initializes an already allocated OFDataArray with an item size of 1,
 *	  containing the data of the specified URL.
 *
 * @param URL The URL to the contents for the OFDataArray
 * @return A new autoreleased OFDataArray
 */
- initWithContentsOfURL: (OFURL*)URL;
#endif

/*!
 * @brief Initializes an already allocated OFDataArray with an item size of 1,
 *	  containing the data of the string representation.
 *
 * @param string The string representation of the data
 * @return A new autoreleased OFDataArray

Modified src/OFDataArray.m from [f234733150] to [8d104459de].

80
81
82
83
84
85
86

87
88
89
90

91
92
93
94
95
96
97
#ifdef OF_HAVE_FILES
+ (instancetype)dataArrayWithContentsOfFile: (OFString*)path
{
	return [[[self alloc] initWithContentsOfFile: path] autorelease];
}
#endif


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


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








>




>







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifdef OF_HAVE_FILES
+ (instancetype)dataArrayWithContentsOfFile: (OFString*)path
{
	return [[[self alloc] initWithContentsOfFile: path] autorelease];
}
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
+ (instancetype)dataArrayWithContentsOfURL: (OFURL*)URL
{
	return [[[self alloc] initWithContentsOfURL: URL] autorelease];
}
#endif

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

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
		@throw e;
	}

	return self;
}
#endif


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

	pool = objc_autoreleasePoolPush();

	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"]) {
		self = [self init];

		@try {
			OFHTTPClient *client = [OFHTTPClient client];
			OFHTTPRequest *request = [OFHTTPRequest
			    requestWithURL: URL];







>









|



|
|







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
		@throw e;
	}

	return self;
}
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
- initWithContentsOfURL: (OFURL*)URL
{
	void *pool;
	OFString *scheme;

	pool = objc_autoreleasePoolPush();

	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"]) {
		self = [self init];

		@try {
			OFHTTPClient *client = [OFHTTPClient client];
			OFHTTPRequest *request = [OFHTTPRequest
			    requestWithURL: URL];
245
246
247
248
249
250
251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
					@throw [OFTruncatedDataException
					    exception];
		} @catch (id e) {
			[self release];
			@throw e;
		}
	} else
#endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	objc_autoreleasePoolPop(pool);

	return self;
}


- initWithStringRepresentation: (OFString*)string
{
	@try {
		const char *cString;
		size_t i, count;








|






>







248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
					@throw [OFTruncatedDataException
					    exception];
		} @catch (id e) {
			[self release];
			@throw e;
		}
	} else
# endif
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- initWithStringRepresentation: (OFString*)string
{
	@try {
		const char *cString;
		size_t i, count;

Modified src/OFString.h from [a93b145417] to [d43c26adbd].

289
290
291
292
293
294
295

296
297
298
299
300
301
302
 * @param encoding The encoding of the file
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithContentsOfFile: (OFString*)path
				encoding: (of_string_encoding_t)encoding;
#endif


/*!
 * @brief Creates a new OFString with the contents of the specified URL.
 *
 * If the URL's scheme is file, it tries UTF-8 encoding.
 *
 * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP
 * headers. If it could not detect the encoding using the HTTP headers, it tries







>







289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
 * @param encoding The encoding of the file
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithContentsOfFile: (OFString*)path
				encoding: (of_string_encoding_t)encoding;
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
/*!
 * @brief Creates a new OFString with the contents of the specified URL.
 *
 * If the URL's scheme is file, it tries UTF-8 encoding.
 *
 * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP
 * headers. If it could not detect the encoding using the HTTP headers, it tries
313
314
315
316
317
318
319

320
321
322
323
324
325
326
 *
 * @param URL The URL to the contents for the string
 * @param encoding The encoding to assume
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithContentsOfURL: (OFURL*)URL
			       encoding: (of_string_encoding_t)encoding;


/*!
 * @brief Creates a path from the specified path components.
 *
 * @param components An array of components for the path
 * @return A new autoreleased OFString
 */







>







314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
 *
 * @param URL The URL to the contents for the string
 * @param encoding The encoding to assume
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithContentsOfURL: (OFURL*)URL
			       encoding: (of_string_encoding_t)encoding;
#endif

/*!
 * @brief Creates a path from the specified path components.
 *
 * @param components An array of components for the path
 * @return A new autoreleased OFString
 */
533
534
535
536
537
538
539

540
541
542
543
544
545
546
 * @param encoding The encoding of the file
 * @return An initialized OFString
 */
- initWithContentsOfFile: (OFString*)path
		encoding: (of_string_encoding_t)encoding;
#endif


/*!
 * @brief Initializes an already allocated OFString with the contents of the
 *	  specified URL.
 *
 * If the URL's scheme is file, it tries UTF-8 encoding.
 *
 * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP







>







535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
 * @param encoding The encoding of the file
 * @return An initialized OFString
 */
- initWithContentsOfFile: (OFString*)path
		encoding: (of_string_encoding_t)encoding;
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
/*!
 * @brief Initializes an already allocated OFString with the contents of the
 *	  specified URL.
 *
 * If the URL's scheme is file, it tries UTF-8 encoding.
 *
 * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP
558
559
560
561
562
563
564

565
566
567
568
569
570
571
 *
 * @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 Writes the OFString into the specified C string with the specified
 *	  encoding.
 *
 * @param cString The C string to write into
 * @param maxLength The maximum number of bytes to write into the C string,







>







561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
 *
 * @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;
#endif

/*!
 * @brief Writes the OFString into the specified C string with the specified
 *	  encoding.
 *
 * @param cString The C string to write into
 * @param maxLength The maximum number of bytes to write into the C string,

Modified src/OFString.m from [ef29c8b8a2] to [c1b245bad8].

441
442
443
444
445
446
447

448
449
450
451
452
453
454
455
456
457
458

459
460
461
462
463
464
465
		encoding: (of_string_encoding_t)encoding
{
	return (id)[[OFString_UTF8 alloc] initWithContentsOfFile: path
							encoding: encoding];
}
#endif


- initWithContentsOfURL: (OFURL*)URL
{
	return (id)[[OFString_UTF8 alloc] initWithContentsOfURL: URL];
}

- initWithContentsOfURL: (OFURL*)URL
	       encoding: (of_string_encoding_t)encoding
{
	return (id)[[OFString_UTF8 alloc] initWithContentsOfURL: URL
						       encoding: encoding];
}


- initWithSerialization: (OFXMLElement*)element
{
	return (id)[[OFString_UTF8 alloc] initWithSerialization: element];
}

- retain







>











>







441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
		encoding: (of_string_encoding_t)encoding
{
	return (id)[[OFString_UTF8 alloc] initWithContentsOfFile: path
							encoding: encoding];
}
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
- initWithContentsOfURL: (OFURL*)URL
{
	return (id)[[OFString_UTF8 alloc] initWithContentsOfURL: URL];
}

- initWithContentsOfURL: (OFURL*)URL
	       encoding: (of_string_encoding_t)encoding
{
	return (id)[[OFString_UTF8 alloc] initWithContentsOfURL: URL
						       encoding: encoding];
}
#endif

- initWithSerialization: (OFXMLElement*)element
{
	return (id)[[OFString_UTF8 alloc] initWithSerialization: element];
}

- retain
633
634
635
636
637
638
639

640
641
642
643
644
645
646
647
648
649
650

651
652
653
654
655
656
657
				encoding: (of_string_encoding_t)encoding
{
	return [[[self alloc] initWithContentsOfFile: path
					    encoding: encoding] autorelease];
}
#endif


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

+ (instancetype)stringWithContentsOfURL: (OFURL*)URL
			       encoding: (of_string_encoding_t)encoding
{
	return [[[self alloc] initWithContentsOfURL: URL
					   encoding: encoding] autorelease];
}


+ (OFString*)pathWithComponents: (OFArray*)components
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();
	OFEnumerator *enumerator = [components objectEnumerator];
	OFString *component;







>











>







635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
				encoding: (of_string_encoding_t)encoding
{
	return [[[self alloc] initWithContentsOfFile: path
					    encoding: encoding] autorelease];
}
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
+ (instancetype)stringWithContentsOfURL: (OFURL*)URL
{
	return [[[self alloc] initWithContentsOfURL: URL] autorelease];
}

+ (instancetype)stringWithContentsOfURL: (OFURL*)URL
			       encoding: (of_string_encoding_t)encoding
{
	return [[[self alloc] initWithContentsOfURL: URL
					   encoding: encoding] autorelease];
}
#endif

+ (OFString*)pathWithComponents: (OFArray*)components
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();
	OFEnumerator *enumerator = [components objectEnumerator];
	OFString *component;
859
860
861
862
863
864
865

866
867
868
869
870
871
872
873
874
875
876
877
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
			      length: (size_t)st.st_size];
	[self freeMemory: tmp];

	return self;
}
#endif


- initWithContentsOfURL: (OFURL*)URL
{
	return [self initWithContentsOfURL: URL
				  encoding: OF_STRING_ENCODING_AUTODETECT];
}

- initWithContentsOfURL: (OFURL*)URL
	       encoding: (of_string_encoding_t)encoding
{
	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"]) {
		if (encoding == OF_STRING_ENCODING_AUTODETECT)
			encoding = OF_STRING_ENCODING_UTF_8;

		self = [[c alloc] initWithContentsOfFile: [URL path]
						encoding: encoding];
	} 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 *contentType, *contentLength;
		OFDataArray *data;







>











|

|







|







|
|







863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
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
			      length: (size_t)st.st_size];
	[self freeMemory: tmp];

	return self;
}
#endif

#if defined(OF_HAVE_FILES) || defined(OF_HAVE_SOCKETS)
- initWithContentsOfURL: (OFURL*)URL
{
	return [self initWithContentsOfURL: URL
				  encoding: OF_STRING_ENCODING_AUTODETECT];
}

- initWithContentsOfURL: (OFURL*)URL
	       encoding: (of_string_encoding_t)encoding
{
	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"]) {
		if (encoding == OF_STRING_ENCODING_AUTODETECT)
			encoding = OF_STRING_ENCODING_UTF_8;

		self = [[c alloc] initWithContentsOfFile: [URL path]
						encoding: encoding];
	} 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 *contentType, *contentLength;
		OFDataArray *data;
935
936
937
938
939
940
941
942
943
944
945
946
947
948

949
950
951
952
953
954
955
			    (size_t)[contentLength decimalValue])
				@throw [OFTruncatedDataException exception];

		self = [[c alloc] initWithCString: (char*)[data items]
					 encoding: encoding
					   length: [data count]];
	} else
#endif
		@throw [OFUnsupportedProtocolException exception];

	objc_autoreleasePoolPop(pool);

	return self;
}


- initWithSerialization: (OFXMLElement*)element
{
	@try {
		void *pool = objc_autoreleasePoolPush();

		if (![[element namespace] isEqual: OF_SERIALIZATION_NS])







|






>







940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
			    (size_t)[contentLength decimalValue])
				@throw [OFTruncatedDataException exception];

		self = [[c alloc] initWithCString: (char*)[data items]
					 encoding: encoding
					   length: [data count]];
	} else
# endif
		@throw [OFUnsupportedProtocolException exception];

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- initWithSerialization: (OFXMLElement*)element
{
	@try {
		void *pool = objc_autoreleasePoolPush();

		if (![[element namespace] isEqual: OF_SERIALIZATION_NS])