summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/url.c
diff options
context:
space:
mode:
Diffstat (limited to 'mdk-stage1/url.c')
-rw-r--r--mdk-stage1/url.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/mdk-stage1/url.c b/mdk-stage1/url.c
index ea155419c..14f1e25d6 100644
--- a/mdk-stage1/url.c
+++ b/mdk-stage1/url.c
@@ -1,7 +1,7 @@
/*
- * Guillaume Cottenceau (gc@mandrakesoft.com)
+ * Guillaume Cottenceau (gc)
*
- * Copyright 2000 Mandrakesoft
+ * Copyright 2000 Mandriva
*
* This software may be freely redistributed under the terms of the GNU
* public license.
@@ -46,6 +46,7 @@
#include "dns.h"
#include "log.h"
#include "tools.h"
+#include "utils.h"
#include "url.h"
@@ -136,13 +137,7 @@ static int ftp_command(int sock, char * command, char * param)
char buf[500];
int rc;
- strcpy(buf, command);
- if (param) {
- strcat(buf, " ");
- strcat(buf, param);
- }
-
- strcat(buf, "\r\n");
+ snprintf(buf, sizeof(buf), "%s%s%s\r\n", command, param ? " " : "", param ? param : "");
if (write(sock, buf, strlen(buf)) != (ssize_t)strlen(buf)) {
return FTPERR_SERVER_IO_ERROR;
@@ -403,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;
@@ -423,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)",
@@ -435,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;
}
@@ -444,13 +448,15 @@ 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;
}
- buf = proxyprotocol ? asprintf_("GET %s://%s%s HTTP/0.9\r\nHost: %s\r\n\r\n", proxyprotocol, hostname, remotename, hostname)
- : asprintf_("GET %s HTTP/0.9\r\nHost: %s\r\n\r\n", remotename, hostname);
+ buf = proxyprotocol ? asprintf_("GET %s://%s%s HTTP/1.0\r\nHost: %s\r\n\r\n", proxyprotocol, hostname, remotename, hostname)
+ : 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: