summaryrefslogtreecommitdiff
path: root/networking/wget.c
diff options
context:
space:
mode:
authorDenys Vlasenko2018-04-07 13:22:52 +0200
committerDenys Vlasenko2018-04-07 13:22:52 +0200
commit32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3 (patch)
tree32fa4cc8f164ea093ee4a0d45ac9128fe9bbf2f5 /networking/wget.c
parent9fe8bd8d61d8cf187ad40affb1f69fe72ae74744 (diff)
downloadbusybox-32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3.zip
busybox-32c3e3a44cb6ae2b0ff949e9f60fa0405f081dc3.tar.gz
wget,ftpd: shorten and reuse strings
function old new delta wget_main 2382 2386 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/0 up/down: 4/0) Total: 4 bytes text data bss dec hex filename 934228 477 7296 942001 e5fb1 busybox_old 934202 477 7296 941975 e5f97 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/wget.c')
-rw-r--r--networking/wget.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 12ee29a..c9e576e 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -762,12 +762,9 @@ static void spawn_ssl_client(const char *host, int network_fd, int flags)
static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)
{
FILE *sfp;
- char *str;
+ char *pass;
int port;
- if (!target->user)
- target->user = xstrdup("anonymous:busybox@");
-
sfp = open_socket(lsa);
#if ENABLE_FEATURE_WGET_HTTPS
if (target->protocol == P_FTPS)
@@ -778,18 +775,20 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
bb_error_msg_and_die("%s", G.wget_buf);
/* note: ftpcmd() sanitizes G.wget_buf, ok to print */
- /*
- * Splitting username:password pair,
- * trying to log in
- */
- str = strchr(target->user, ':');
- if (str)
- *str++ = '\0';
- switch (ftpcmd("USER ", target->user, sfp)) {
+ /* Split username:password pair */
+ pass = (char*)"busybox"; /* password for "anonymous" */
+ if (target->user) {
+ pass = strchr(target->user, ':');
+ if (pass)
+ *pass++ = '\0';
+ }
+
+ /* Log in */
+ switch (ftpcmd("USER ", target->user ?: "anonymous", sfp)) {
case 230:
break;
case 331:
- if (ftpcmd("PASS ", str, sfp) == 230)
+ if (ftpcmd("PASS ", pass, sfp) == 230)
break;
/* fall through (failed login) */
default:
@@ -798,9 +797,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
ftpcmd("TYPE I", NULL, sfp);
- /*
- * Querying file size
- */
+ /* Query file size */
if (ftpcmd("SIZE ", target->path, sfp) == 213) {
G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10);
if (G.content_len < 0 || errno) {
@@ -809,9 +806,7 @@ static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_
G.got_clen = 1;
}
- /*
- * Entering passive mode
- */
+ /* Enter passive mode */
if (ENABLE_FEATURE_IPV6 && ftpcmd("EPSV", NULL, sfp) == 229) {
/* good */
} else