ObjFW  Diff

Differences From Artifact [7077269c5c]:

To Artifact [537b9ea7bb]:


39
40
41
42
43
44
45

46
47
48
49
50
51
52
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53







+







#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOpenFileFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"

#import "autorelease.h"
#import "macros.h"
#import "of_asprintf.h"
#import "unicode.h"

/*
897
898
899
900
901
902
903

904


905
906
907
908
909
910
911
898
899
900
901
902
903
904
905

906
907
908
909
910
911
912
913
914







+
-
+
+







- initWithContentsOfURL: (OFURL*)URL
	       encoding: (of_string_encoding_t)encoding
{
	void *pool;
	OFHTTPClient *client;
	OFHTTPRequest *request;
	OFHTTPRequestReply *reply;
	OFDictionary *headers;
	OFString *contentType;
	OFString *contentType, *contentLength;
	OFDataArray *data;
	Class c;

	c = [self class];
	[self release];

	pool = objc_autoreleasePoolPush();

924
925
926
927
928
929
930
931


932
933

934
935
936
937
938
939
940
941
942
943
944
945
946
947
948







949

950
951

952
953

954
955
956
957
958
959
960
927
928
929
930
931
932
933
934
935
936
937

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960

961
962

963
964
965
966
967
968
969
970
971
972
973








+
+

-
+















+
+
+
+
+
+
+
-
+

-
+


+







	reply = [client performRequest: request];

	if ([reply statusCode] != 200)
		@throw [OFHTTPRequestFailedException
		    exceptionWithClass: [request class]
			       request: request
				 reply: reply];

	headers = [reply headers];

	if (encoding == OF_STRING_ENCODING_AUTODETECT &&
	    (contentType = [[reply headers] objectForKey: @"Content-Type"])) {
	    (contentType = [headers objectForKey: @"Content-Type"]) != nil) {
		contentType = [contentType lowercaseString];

		if ([contentType hasSuffix: @"charset=utf-8"])
			encoding = OF_STRING_ENCODING_UTF_8;
		if ([contentType hasSuffix: @"charset=iso-8859-1"])
			encoding = OF_STRING_ENCODING_ISO_8859_1;
		if ([contentType hasSuffix: @"charset=iso-8859-15"])
			encoding = OF_STRING_ENCODING_ISO_8859_15;
		if ([contentType hasSuffix: @"charset=windows-1252"])
			encoding = OF_STRING_ENCODING_WINDOWS_1252;
	}

	if (encoding == OF_STRING_ENCODING_AUTODETECT)
		encoding = OF_STRING_ENCODING_UTF_8;

	data = [reply readDataArrayTillEndOfStream];

	if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil)
		if ([data count] != (size_t)[contentLength decimalValue])
			@throw [OFTruncatedDataException
			    exceptionWithClass: [self class]];

	self = [[c alloc] initWithCString: (char*)[[reply data] items]
	self = [[c alloc] initWithCString: (char*)[data items]
				 encoding: encoding
				   length: [[reply data] count]];
				   length: [data count]];

	objc_autoreleasePoolPop(pool);

	return self;
}

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