62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
-
+
|
size_t _URLIndex;
int _errorCode;
OFString *_outputPath, *_currentFileName;
bool _continue, _force, _detectFileName, _detectFileNameRequest;
bool _detectedFileName, _quiet, _verbose, _insecure, _ignoreStatus;
bool _useUnicode;
OFStream *_body;
of_http_request_method_t _method;
OFHTTPRequestMethod _method;
OFMutableDictionary *_clientHeaders;
OFHTTPClient *_HTTPClient;
char *_buffer;
OFStream *_output;
unsigned long long _received, _length, _resumedFrom;
ProgressBar *_progressBar;
}
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
|
-
+
-
+
-
+
|
- (void)setMethod: (OFString *)method
{
void *pool = objc_autoreleasePoolPush();
method = method.uppercaseString;
@try {
_method = of_http_request_method_from_string(method);
_method = OFHTTPRequestMethodParseName(method);
} @catch (OFInvalidArgumentException *e) {
[of_stderr writeLine: OF_LOCALIZED(@"invalid_input_method",
@"%[prog]: Invalid request method %[method]!",
@"prog", [OFApplication programName],
@"method", method)];
[OFApplication terminateWithStatus: 1];
}
objc_autoreleasePoolPop(pool);
}
- (void)setProxy: (OFString *)proxy
{
@try {
size_t pos = [proxy
rangeOfString: @":"
options: OF_STRING_SEARCH_BACKWARDS].location;
options: OFStringSearchBackwards].location;
OFString *host;
unsigned long long port;
if (pos == OF_NOT_FOUND)
if (pos == OFNotFound)
@throw [OFInvalidFormatException exception];
host = [proxy substringToIndex: pos];
port = [proxy substringFromIndex: pos + 1]
.unsignedLongLongValue;
if (port > UINT16_MAX)
|
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
-
+
-
+
|
[OFApplication terminateWithStatus: 1];
}
}
- (void)applicationDidFinishLaunching
{
OFString *outputPath;
const of_options_parser_option_t options[] = {
const OFOptionsParserOption options[] = {
{ 'b', @"body", 1, NULL, NULL },
{ 'c', @"continue", 0, &_continue, NULL },
{ 'f', @"force", 0, &_force, NULL },
{ 'h', @"help", 0, NULL, NULL },
{ 'H', @"header", 1, NULL, NULL },
{ 'm', @"method", 1, NULL, NULL },
{ 'o', @"output", 1, NULL, &outputPath },
{ 'O', @"detect-filename", 0, &_detectFileName, NULL },
{ 'P', @"socks5-proxy", 1, NULL, NULL },
{ 'q', @"quiet", 0, &_quiet, NULL },
{ 'v', @"verbose", 0, &_verbose, NULL },
{ '\0', @"insecure", 0, &_insecure, NULL },
{ '\0', @"ignore-status", 0, &_ignoreStatus, NULL },
{ '\0', nil, 0, NULL, NULL }
};
OFOptionsParser *optionsParser;
of_unichar_t option;
OFUnichar option;
#ifdef OF_HAVE_SANDBOX
OFSandbox *sandbox = [OFSandbox sandbox];
sandbox.allowsStdIO = true;
sandbox.allowsReadingFiles = true;
sandbox.allowsWritingFiles = true;
sandbox.allowsCreatingFiles = true;
|
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
|
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
|
-
+
-
-
+
|
if (_ignoreStatus) {
exception = nil;
goto after_exception_handling;
}
statusCode = response.statusCode;
codeString = [OFString stringWithFormat: @"%hd %@",
statusCode,
statusCode, OFHTTPStatusCodeString(statusCode)];
of_http_status_code_to_string(statusCode)];
[of_stderr writeLine: OF_LOCALIZED(@"download_failed",
@"%[prog]: Failed to download <%[url]>!\n"
@" HTTP status code: %[code]",
@"prog", [OFApplication programName],
@"url", request.URL.string,
@"code", codeString)];
} else
@throw exception;
_errorCode = 1;
[self performSelector: @selector(downloadNextURL)
afterDelay: 0];
return;
}
after_exception_handling:
if (_method == OF_HTTP_REQUEST_METHOD_HEAD)
if (_method == OFHTTPRequestMethodHead)
goto next;
if (_detectFileNameRequest) {
_currentFileName = [fileNameFromContentDisposition(
[response.headers objectForKey: @"Content-Disposition"])
copy];
_detectedFileName = true;
|