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
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
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
|
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
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
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
|
-
-
-
-
-
-
+
-
-
-
+
+
+
-
-
-
+
-
-
-
+
-
-
-
+
+
+
+
+
+
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
-
+
|
encoding: OF_STRING_ENCODING_AUTODETECT];
}
- initWithContentsOfURL: (OFURL*)URL
encoding: (of_string_encoding_t)encoding
{
void *pool;
#ifdef OF_HAVE_SOCKETS
OFHTTPClient *client;
OFHTTPRequest *request;
OFHTTPResponse *response;
OFDictionary *headers;
OFString *contentType, *contentLength;
OFString *scheme;
OFDataArray *data;
#endif
#ifdef OF_HAVE_FILES
Class c = [self class];
#endif
[self release];
pool = objc_autoreleasePoolPush();
if ([[URL scheme] isEqual: @"file"]) {
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];
objc_autoreleasePoolPop(pool);
return self;
#else
} else
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
#endif
}
#ifdef OF_HAVE_SOCKETS
if ([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) {
client = [OFHTTPClient client];
request = [OFHTTPRequest requestWithURL: URL];
response = [client performRequest: request];
OFHTTPClient *client = [OFHTTPClient client];
OFHTTPRequest *request = [OFHTTPRequest requestWithURL: URL];
OFHTTPResponse *response = [client performRequest: request];
OFDictionary *headers;
OFString *contentType, *contentLength;
OFDataArray *data;
if ([response statusCode] != 200)
@throw [OFHTTPRequestFailedException
exceptionWithRequest: request
response: response];
if ([response statusCode] != 200)
@throw [OFHTTPRequestFailedException
exceptionWithRequest: request
response: response];
headers = [response headers];
headers = [response headers];
if (encoding == OF_STRING_ENCODING_AUTODETECT &&
(contentType = [headers objectForKey: @"Content-Type"]) != nil) {
contentType = [contentType lowercaseString];
if (encoding == OF_STRING_ENCODING_AUTODETECT &&
(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 ([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;
if (encoding == OF_STRING_ENCODING_AUTODETECT)
encoding = OF_STRING_ENCODING_UTF_8;
data = [response readDataArrayTillEndOfStream];
data = [response readDataArrayTillEndOfStream];
if ((contentLength = [headers objectForKey: @"Content-Length"]) != nil)
if ([data count] != (size_t)[contentLength decimalValue])
@throw [OFTruncatedDataException exception];
if ((contentLength = [headers
objectForKey: @"Content-Length"]) != nil)
if ([data count] !=
(size_t)[contentLength decimalValue])
@throw [OFTruncatedDataException exception];
self = [[c alloc] initWithCString: (char*)[data items]
encoding: encoding
length: [data count]];
#else
self = [[c alloc] initWithCString: (char*)[data items]
encoding: encoding
length: [data count]];
} else
@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
#endif
@throw [OFUnsupportedProtocolException exception];
objc_autoreleasePoolPop(pool);
return self;
}
- initWithSerialization: (OFXMLElement*)element
|