From f1548fa15e6a86bdb903d6645750bd850517b10f Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Wed, 5 Jan 2022 11:07:51 +0100 Subject: allow to specify a different http port (mga#28367) The default being the well know "80" port --- mdk-stage1/NEWS | 2 ++ mdk-stage1/url.c | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'mdk-stage1') diff --git a/mdk-stage1/NEWS b/mdk-stage1/NEWS index e8181198d..86d9c944a 100644 --- a/mdk-stage1/NEWS +++ b/mdk-stage1/NEWS @@ -1,3 +1,5 @@ +- http server: allow to specify a port different than default "80" (mga#28367) + 2.56 - load exfat module to mount exfat (mga#28371) diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c index 3d2846649..14f1e25d6 100644 --- a/mdk-stage1/url.c +++ b/mdk-stage1/url.c @@ -398,9 +398,10 @@ char *str_ftp_error(int error) } -static int _http_download_file(char * hostname, char * remotename, int * size, char * proxyprotocol, char * proxyname, char * proxyport, int recursion) +static int _http_download_file(char * hostport, char * remotename, int * size, char * proxyprotocol, char * proxyname, char * proxyport, int recursion) { char * buf; + char * hostname = strdup(hostport); char headers[4096]; char * nextChar = headers; int statusCode; @@ -418,8 +419,15 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c http_server_name = proxyname; http_server_port = atoi(proxyport); } else { - http_server_name = hostname; - http_server_port = 80; + char *port = strchr(hostname, ':'); + if (port) { + *port = '\0'; + http_server_name = hostname; + http_server_port = atoi(++port); + } else { + http_server_name = hostname; + http_server_port = 80; + } } log_message("HTTP: connecting to server %s:%i (%s)", @@ -430,6 +438,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c sock = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (sock < 0) { + free(hostname); return FTPERR_FAILED_CONNECT; } @@ -439,6 +448,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c if (connect(sock, (struct sockaddr *) &destPort, sizeof(destPort))) { close(sock); + free(hostname); return FTPERR_FAILED_CONNECT; } @@ -446,6 +456,7 @@ static int _http_download_file(char * hostname, char * remotename, int * size, c : asprintf_("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", remotename, hostname); write(sock, buf, strlen(buf)); + free(hostname); /* This is fun; read the response a character at a time until we: -- cgit v1.2.1