|
@@ -37,6 +37,7 @@
|
37
|
37
|
#include <gpxe/download.h>
|
38
|
38
|
#include <gpxe/resolv.h>
|
39
|
39
|
#include <gpxe/tcp.h>
|
|
40
|
+#include <gpxe/tls.h>
|
40
|
41
|
#include <gpxe/http.h>
|
41
|
42
|
|
42
|
43
|
static struct async_operations http_async_operations;
|
|
@@ -387,6 +388,7 @@ static struct stream_application_operations http_stream_operations = {
|
387
|
388
|
*/
|
388
|
389
|
int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
|
389
|
390
|
struct http_request *http = NULL;
|
|
391
|
+ struct sockaddr_tcpip *st;
|
390
|
392
|
int rc;
|
391
|
393
|
|
392
|
394
|
/* Allocate and populate HTTP structure */
|
|
@@ -398,6 +400,17 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
|
398
|
400
|
http->buffer = buffer;
|
399
|
401
|
async_init ( &http->async, &http_async_operations, parent );
|
400
|
402
|
http->stream.op = &http_stream_operations;
|
|
403
|
+ st = ( struct sockaddr_tcpip * ) &http->server;
|
|
404
|
+ st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
|
|
405
|
+
|
|
406
|
+ /* Open TCP connection */
|
|
407
|
+ if ( ( rc = tcp_open ( &http->stream ) ) != 0 )
|
|
408
|
+ goto err;
|
|
409
|
+ if ( strcmp ( http->uri->scheme, "https" ) == 0 ) {
|
|
410
|
+ st->st_port = htons ( uri_port ( http->uri, HTTPS_PORT ) );
|
|
411
|
+ if ( ( rc = add_tls ( &http->stream ) ) != 0 )
|
|
412
|
+ goto err;
|
|
413
|
+ }
|
401
|
414
|
|
402
|
415
|
/* Start name resolution. The download proper will start when
|
403
|
416
|
* name resolution completes.
|
|
@@ -424,7 +437,6 @@ int http_get ( struct uri *uri, struct buffer *buffer, struct async *parent ) {
|
424
|
437
|
static void http_sigchld ( struct async *async, enum signal signal __unused ) {
|
425
|
438
|
struct http_request *http =
|
426
|
439
|
container_of ( async, struct http_request, async );
|
427
|
|
- struct sockaddr_tcpip *st = ( struct sockaddr_tcpip * ) &http->server;
|
428
|
440
|
int rc;
|
429
|
441
|
|
430
|
442
|
/* If name resolution failed, abort now */
|
|
@@ -435,13 +447,6 @@ static void http_sigchld ( struct async *async, enum signal signal __unused ) {
|
435
|
447
|
}
|
436
|
448
|
|
437
|
449
|
/* Otherwise, start the HTTP connection */
|
438
|
|
- if ( ( rc = tcp_open ( &http->stream ) ) != 0 ) {
|
439
|
|
- DBGC ( http, "HTTP %p could not open stream connection: %s\n",
|
440
|
|
- http, strerror ( rc ) );
|
441
|
|
- http_done ( http, rc );
|
442
|
|
- return;
|
443
|
|
- }
|
444
|
|
- st->st_port = htons ( uri_port ( http->uri, HTTP_PORT ) );
|
445
|
450
|
if ( ( rc = stream_connect ( &http->stream, &http->server ) ) != 0 ) {
|
446
|
451
|
DBGC ( http, "HTTP %p could not connect stream: %s\n",
|
447
|
452
|
http, strerror ( rc ) );
|
|
@@ -472,3 +477,9 @@ struct download_protocol http_download_protocol __download_protocol = {
|
472
|
477
|
.name = "http",
|
473
|
478
|
.start_download = http_get,
|
474
|
479
|
};
|
|
480
|
+
|
|
481
|
+/** HTTPS download protocol */
|
|
482
|
+struct download_protocol https_download_protocol __download_protocol = {
|
|
483
|
+ .name = "https",
|
|
484
|
+ .start_download = http_get,
|
|
485
|
+};
|