@@ -26,10 +26,13 @@ #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFLocale.h" #import "OFOptionsParser.h" +#ifdef OF_HAVE_PLUGINS +# import "OFPlugin.h" +#endif #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFSystemInfo.h" #import "OFTCPSocket.h" #import "OFTLSSocket.h" @@ -67,11 +70,11 @@ of_http_request_method_t _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; - intmax_t _received, _length, _resumedFrom; + unsigned long long _received, _length, _resumedFrom; ProgressBar *_progressBar; } - (void)downloadNextURL; @end @@ -272,10 +275,21 @@ objc_autoreleasePoolPop(pool); return [fileName autorelease]; } @implementation OFHTTP +#ifdef OF_HAVE_PLUGINS ++ (void)initialize +{ + if (self != [OFHTTP class]) + return; + + /* Opportunistically try loading ObjOpenSSL and ignore any errors. */ + of_dlopen(@"objopenssl", OF_RTLD_LAZY); +} +#endif + - (instancetype)init { self = [super init]; @try { @@ -332,11 +346,12 @@ else { _body = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { - uintmax_t fileSize = [[OFFileManager defaultManager] + unsigned long long fileSize = + [[OFFileManager defaultManager] attributesOfItemAtPath: path].fileSize; contentLength = [OFString stringWithFormat: @"%ju", fileSize]; [_clientHeaders setObject: contentLength @@ -374,18 +389,18 @@ @try { size_t pos = [proxy rangeOfString: @":" options: OF_STRING_SEARCH_BACKWARDS].location; OFString *host; - intmax_t port; + unsigned long long port; if (pos == OF_NOT_FOUND) @throw [OFInvalidFormatException exception]; host = [proxy substringWithRange: of_range(0, pos)]; - port = [proxy substringWithRange: - of_range(pos + 1, proxy.length - pos - 1)].decimalValue; + port = [proxy substringWithRange: of_range(pos + 1, + proxy.length - pos - 1)].unsignedLongLongValue; if (port > UINT16_MAX) @throw [OFOutOfRangeException exception]; [OFTCPSocket setSOCKS5Host: host]; @@ -719,12 +734,15 @@ [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; - if (!_quiet) - [of_stdout writeString: @"\n Error!\n"]; + if (!_quiet) { + [of_stdout writeString: @"\n "]; + [of_stdout writeLine: OF_LOCALIZED(@"download_error", + @"Error!")]; + } URL = [_URLs objectAtIndex: _URLIndex - 1]; [of_stderr writeLine: OF_LOCALIZED( @"download_failed_exception", @"%[prog]: Failed to download <%[url]>!\n" @@ -783,11 +801,11 @@ if (type == nil) type = OF_LOCALIZED(@"type_unknown", @"unknown"); if (lengthString != nil) { - _length = lengthString.decimalValue; + _length = lengthString.unsignedLongLongValue; if (_resumedFrom + _length >= GIBIBYTE) { lengthString = [OFString stringWithFormat: @"%,.2f", (float)(_resumedFrom + _length) / GIBIBYTE]; @@ -810,16 +828,16 @@ @"num", lengthString); } else { lengthString = [OFString stringWithFormat: @"%jd", _resumedFrom + _length]; lengthString = OF_LOCALIZED(@"size_bytes", - [@"[" - @" [" - @" {'num == 1': '1 byte'}," - @" {'': '%[num] bytes'}" - @" ]" - @"]" JSONValue], + @"[" + @" [" + @" {'num == 1': '1 byte'}," + @" {'': '%[num] bytes'}" + @" ]" + @"]".objectByParsingJSON, @"num", lengthString); } } else lengthString = OF_LOCALIZED(@"size_unknown", @"unknown"); @@ -1008,18 +1026,19 @@ if (_currentFileName == nil) _currentFileName = [URL.path.lastPathComponent copy]; if (_continue) { @try { - uintmax_t size = [[OFFileManager defaultManager] + unsigned long long size = + [[OFFileManager defaultManager] attributesOfItemAtPath: _currentFileName].fileSize; OFString *range; - if (size > INTMAX_MAX) + if (size > ULLONG_MAX) @throw [OFOutOfRangeException exception]; - _resumedFrom = (intmax_t)size; + _resumedFrom = (unsigned long long)size; range = [OFString stringWithFormat: @"bytes=%jd-", _resumedFrom]; [clientHeaders setObject: range forKey: @"Range"];