ObjFW  Check-in [d040a0989d]

Overview
Comment:ofhttp: Add --insecure flag to ignore TLS errors
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d040a0989d67fd5b7ac977cfa4f149dad5358e8cace07582df1e89df338ffc9a
User & Date: js on 2017-01-29 19:08:46
Other Links: manifest | tags
Context
2017-01-29
23:10
OFHTTPResponse: Work around a wrong GCC warning check-in: 17b6341164 user: js tags: trunk
19:08
ofhttp: Add --insecure flag to ignore TLS errors check-in: d040a0989d user: js tags: trunk
2017-01-22
04:02
objfw-config.in: Remove trailing quotes in help check-in: dccc73288f user: js tags: trunk
Changes

Modified src/OFHTTPClient.h from [ba8c9a7683] to [08ff8ce82a].

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 * proxy it should use for this connection.
 *
 * @param client The OFHTTPClient that created a socket
 * @param socket The socket created by the OFHTTPClient
 * @param request The request for which the socket was created
 */
-    (void)client: (OFHTTPClient*)client
  didCreateSocket: (OFTCPSocket*)socket
	  request: (OFHTTPRequest*)request;

/*!
 * @brief A callback which is called when an OFHTTPClient received headers.
 *
 * @param client The OFHTTPClient which received the headers
 * @param headers The headers received







|







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 * proxy it should use for this connection.
 *
 * @param client The OFHTTPClient that created a socket
 * @param socket The socket created by the OFHTTPClient
 * @param request The request for which the socket was created
 */
-    (void)client: (OFHTTPClient*)client
  didCreateSocket: (OF_KINDOF(OFTCPSocket*))socket
	  request: (OFHTTPRequest*)request;

/*!
 * @brief A callback which is called when an OFHTTPClient received headers.
 *
 * @param client The OFHTTPClient which received the headers
 * @param headers The headers received

Modified utils/ofhttp/OFHTTP.m from [b07f7b6ae5] to [cc6aaa39b2].

25
26
27
28
29
30
31

32
33
34
35
36
37
38
#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"
#import "OFOptionsParser.h"
#import "OFStdIOStream.h"
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"

#import "OFURL.h"
#import "OFLocalization.h"

#import "OFAddressTranslationFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidFormatException.h"







>







25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"
#import "OFOptionsParser.h"
#import "OFStdIOStream.h"
#import "OFSystemInfo.h"
#import "OFTCPSocket.h"
#import "OFTLSSocket.h"
#import "OFURL.h"
#import "OFLocalization.h"

#import "OFAddressTranslationFailedException.h"
#import "OFConnectionFailedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidFormatException.h"
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

@interface OFHTTP: OFObject <OFHTTPClientDelegate>
{
	OFArray OF_GENERIC(OFString*) *_URLs;
	size_t _URLIndex;
	int _errorCode;
	OFString *_outputPath;
	bool _continue, _force, _detectFileName, _quiet, _verbose;
	OFDataArray *_body;
	of_http_request_method_t _method;
	OFMutableDictionary *_clientHeaders;
	OFHTTPClient *_HTTPClient;
	char *_buffer;
	OFStream *_output;
	intmax_t _received, _length, _resumedFrom;







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

@interface OFHTTP: OFObject <OFHTTPClientDelegate>
{
	OFArray OF_GENERIC(OFString*) *_URLs;
	size_t _URLIndex;
	int _errorCode;
	OFString *_outputPath;
	bool _continue, _force, _detectFileName, _quiet, _verbose, _insecure;
	OFDataArray *_body;
	of_http_request_method_t _method;
	OFMutableDictionary *_clientHeaders;
	OFHTTPClient *_HTTPClient;
	char *_buffer;
	OFStream *_output;
	intmax_t _received, _length, _resumedFrom;
98
99
100
101
102
103
104
105


106
107
108
109
110
111
112
		    @"-O  --detect-filename"
		    @"  Do a HEAD request to detect the file name\n    "
		    @"-P  --proxy          "
		    @"  Specify SOCKS5 proxy\n    "
		    @"-q  --quiet          "
		    @"  Quiet mode (no output, except errors)\n    "
		    @"-v  --verbose        "
		    @"  Verbose mode (print headers)\n")];



	[OFApplication terminateWithStatus: status];
}

@implementation OFHTTP
- init
{







|
>
>







99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
		    @"-O  --detect-filename"
		    @"  Do a HEAD request to detect the file name\n    "
		    @"-P  --proxy          "
		    @"  Specify SOCKS5 proxy\n    "
		    @"-q  --quiet          "
		    @"  Quiet mode (no output, except errors)\n    "
		    @"-v  --verbose        "
		    @"  Verbose mode (print headers)\n    "
		    @"    --insecure       "
		    @"  Ignore TLS errors\n")];

	[OFApplication terminateWithStatus: status];
}

@implementation OFHTTP
- init
{
237
238
239
240
241
242
243

244
245
246
247
248
249
250
		{ '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', nil, 0, NULL, NULL }
	};
	OFOptionsParser *optionsParser = [OFOptionsParser
	    parserWithOptions: options];
	of_unichar_t option;

	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];







>







240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
		{ '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', nil, 0, NULL, NULL }
	};
	OFOptionsParser *optionsParser = [OFOptionsParser
	    parserWithOptions: options];
	of_unichar_t option;

	[OFLocalization addLanguageDirectory: @LANGUAGE_DIR];
342
343
344
345
346
347
348









349
350
351
352
353
354
355
		    @"prog", [OFApplication programName])];
		[OFApplication terminateWithStatus: 1];
	}

	[self performSelector: @selector(downloadNextURL)
		   afterDelay: 0];
}










-	  (bool)client: (OFHTTPClient*)client
  shouldFollowRedirect: (OFURL*)URL
	    statusCode: (int)statusCode
	       request: (OFHTTPRequest*)request
	      response: (OFHTTPResponse*)response
{







>
>
>
>
>
>
>
>
>







346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
		    @"prog", [OFApplication programName])];
		[OFApplication terminateWithStatus: 1];
	}

	[self performSelector: @selector(downloadNextURL)
		   afterDelay: 0];
}

-    (void)client: (OFHTTPClient*)client
  didCreateSocket: (OF_KINDOF(OFTCPSocket*))socket
	  request: (OFHTTPRequest*)request
{
	if (_insecure && [socket respondsToSelector:
	    @selector(setCertificateVerificationEnabled:)])
		[socket setCertificateVerificationEnabled: false];
}

-	  (bool)client: (OFHTTPClient*)client
  shouldFollowRedirect: (OFURL*)URL
	    statusCode: (int)statusCode
	       request: (OFHTTPRequest*)request
	      response: (OFHTTPResponse*)response
{
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
		    @"prog", [OFApplication programName],
		    @"url", [[request URL] string])];
	} @catch (OFUnsupportedProtocolException *e) {
		if (!_quiet)
			[of_stdout writeString: @"\n"];

		[of_stderr writeString: OF_LOCALIZED(@"no_ssl_library",
		    @"%[prog]: No SSL library loaded!\n"
		    @"  In order to download via https, you need to preload an "
		    @"SSL library for ObjFW\n"
		    "such as ObjOpenSSL!\n",
		    @"prog", [OFApplication programName])];
	} @catch (OFReadOrWriteFailedException *e) {
		OFString *error = OF_LOCALIZED(
		    @"download_failed_read_or_write_failed_any",
		    @"Read or write failed");








|

|







431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
		    @"prog", [OFApplication programName],
		    @"url", [[request URL] string])];
	} @catch (OFUnsupportedProtocolException *e) {
		if (!_quiet)
			[of_stdout writeString: @"\n"];

		[of_stderr writeString: OF_LOCALIZED(@"no_ssl_library",
		    @"%[prog]: No TLS library loaded!\n"
		    @"  In order to download via https, you need to preload an "
		    @"TLS library for ObjFW\n"
		    "such as ObjOpenSSL!\n",
		    @"prog", [OFApplication programName])];
	} @catch (OFReadOrWriteFailedException *e) {
		OFString *error = OF_LOCALIZED(
		    @"download_failed_read_or_write_failed_any",
		    @"Read or write failed");

Modified utils/ofhttp/lang/de.json from [0371c6a7bd] to [767e814d4b].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
    "usage": "Benutzung: %[prog] -[cehHmoOPqv] url1 [url2 ...]\n",
    "full_usage": [
        "\n",
        "Optionen:\n",
        "    -b  --body             Angegebene Datei als Body übergeben\n",
        "    -c  --continue         Download von existierender Datei ",
	"fortsetzen\n",
        "    -f  --force            Existierende Datei überschreiben\n",
        "    -h  --help             Diese Hilfe anzeigen\n",
        "    -H  --header           Einen Header (z.B. X-Foo:Bar) hinzufügen\n",
        "    -m  --method           HTTP Request-Methode setzen\n",
        "    -o  --output           Ausgabe-Dateiname angeben\n",
        "    -O  --detect-filename  Dateiname mittels HEAD-Request ermitteln\n",
        "    -P  --proxy            SOCKS5-Proxy angeben\n",
        "    -q  --quiet            Ruhiger Modus (keine Ausgabe außer Fehler)",
	"\n",
        "    -v  --verbose          Geschwätziger Modus (gibt Header aus)\n"

    ],
    "invalid_input_header": [
        "%[prog]: Header müssen im Format Name:Wert sein!\n"
    ],
    "invalid_input_method": "%[prog]: Ungültige Request-Methode %[method]!\n",
    "invalid_input_proxy": "%[prog]: Proxy muss im Format Host:Port sein!\n",
    "long_argument_missing": "%[prog]: Argument für Option --%[opt] fehlt\n",
    "argument_missing": "%[prog]: Argument für option -%[opt] fehlt\n",
    "takes_no_argument": "%[prog]: Option --%[opt] nimmt kein Argument\n",
    "unknown_long_option": "%[prog]: Unbekannte Option: --%[opt]\n",
    "unknown_option": "%[prog]: Unbekannte Option: -%[opt]\n",
    "quiet_xor_verbose": [
        "%[prog]: -q / --quiet und -v / --verbose schließen sich gegenseitig ",
	"aus!\n"
    ],
    "output_only_with_one_url": [
        "%[prog]: -o / --output kann nicht mit mehr als einer URL benutzt ",
	"werden!\n"
    ],
    "download_failed_address_translation": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Adressauflösung fehlgeschlagen: %[exception]\n"
    ],
    "download_failed_connection_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Verbindung fehlgeschlagen: %[exception]\n"
    ],
    "download_failed_invalid_server_reply": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Ungültige Antwort vom Server!\n"
    ],
    "no_ssl_library": [
        "%[prog]: Keine SSL-Bibliothek geladen!\n",
        "  Um Dateien über https zu laden, müssen Sie eine SSL-Bibliothek für ",
        "ObjFW,\n",
        "  wie z.B. ObjOpenSSL, mittels LD_PRELOAD laden."
    ],
    "download_failed_read_or_write_failed_any": "Lesen oder Schreiben",
    "download_failed_read_or_write_failed_read": "Lesen",
    "download_failed_read_or_write_failed_write": "Schreiben",
    "download_failed_read_or_write_failed": [







|








|
|
>













|



|














|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{
    "usage": "Benutzung: %[prog] -[cehHmoOPqv] url1 [url2 ...]\n",
    "full_usage": [
        "\n",
        "Optionen:\n",
        "    -b  --body             Angegebene Datei als Body übergeben\n",
        "    -c  --continue         Download von existierender Datei ",
        "fortsetzen\n",
        "    -f  --force            Existierende Datei überschreiben\n",
        "    -h  --help             Diese Hilfe anzeigen\n",
        "    -H  --header           Einen Header (z.B. X-Foo:Bar) hinzufügen\n",
        "    -m  --method           HTTP Request-Methode setzen\n",
        "    -o  --output           Ausgabe-Dateiname angeben\n",
        "    -O  --detect-filename  Dateiname mittels HEAD-Request ermitteln\n",
        "    -P  --proxy            SOCKS5-Proxy angeben\n",
        "    -q  --quiet            Ruhiger Modus (keine Ausgabe außer Fehler)",
        "\n",
        "    -v  --verbose          Geschwätziger Modus (gibt Header aus)\n",
        "        --insecure         TLS-Fehler ignorieren\n"
    ],
    "invalid_input_header": [
        "%[prog]: Header müssen im Format Name:Wert sein!\n"
    ],
    "invalid_input_method": "%[prog]: Ungültige Request-Methode %[method]!\n",
    "invalid_input_proxy": "%[prog]: Proxy muss im Format Host:Port sein!\n",
    "long_argument_missing": "%[prog]: Argument für Option --%[opt] fehlt\n",
    "argument_missing": "%[prog]: Argument für option -%[opt] fehlt\n",
    "takes_no_argument": "%[prog]: Option --%[opt] nimmt kein Argument\n",
    "unknown_long_option": "%[prog]: Unbekannte Option: --%[opt]\n",
    "unknown_option": "%[prog]: Unbekannte Option: -%[opt]\n",
    "quiet_xor_verbose": [
        "%[prog]: -q / --quiet und -v / --verbose schließen sich gegenseitig ",
        "aus!\n"
    ],
    "output_only_with_one_url": [
        "%[prog]: -o / --output kann nicht mit mehr als einer URL benutzt ",
        "werden!\n"
    ],
    "download_failed_address_translation": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Adressauflösung fehlgeschlagen: %[exception]\n"
    ],
    "download_failed_connection_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Verbindung fehlgeschlagen: %[exception]\n"
    ],
    "download_failed_invalid_server_reply": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "  Ungültige Antwort vom Server!\n"
    ],
    "no_ssl_library": [
        "%[prog]: Keine TLS-Bibliothek geladen!\n",
        "  Um Dateien über https zu laden, müssen Sie eine TLS-Bibliothek für ",
        "ObjFW,\n",
        "  wie z.B. ObjOpenSSL, mittels LD_PRELOAD laden."
    ],
    "download_failed_read_or_write_failed_any": "Lesen oder Schreiben",
    "download_failed_read_or_write_failed_read": "Lesen",
    "download_failed_read_or_write_failed_write": "Schreiben",
    "download_failed_read_or_write_failed": [