Skip to content

Commit 0aa6a94

Browse files
openharmony_cigitee-org
openharmony_ci
authored andcommitted
!176 修复wget命令异常
Merge pull request !176 from 张吉东/wget_update
2 parents c836ff2 + b5e0ab8 commit 0aa6a94

File tree

2 files changed

+21
-25
lines changed

2 files changed

+21
-25
lines changed

generated/globals.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ struct wget_data {
11591159
char*filename;
11601160
longredirects;
11611161

1162-
intsock;
1162+
intsock, https;
11631163
char*url;
11641164
#ifCFG_WGET_LIBTLS
11651165
structtls*tls;

toys/pending/wget.c

+20-24
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ config WGET_OPENSSL
7878

7979
#defineWGET_IS_HTTP (strncmp(TT.url, "http://", 7) == 0)
8080
#defineWGET_IS_HTTPS (WGET_SSL && (strncmp(TT.url, "https://", 8) == 0))
81+
#defineHTTPS (WGET_SSL && TT.https)
8182

8283
GLOBALS(
8384
char*filename;
8485
longredirects;
8586

86-
intsock;
87+
intsock, https;
8788
char*url;
8889
#ifCFG_WGET_LIBTLS
8990
structtls*tls;
@@ -103,30 +104,25 @@ static char *wget_strncaseafter(char *haystack, char *needle)
103104
// get http info in URL
104105
staticvoidwget_info(char*url, char**host, char**port, char**path)
105106
{
106-
*host=strafter(url, "://");
107-
*path=strchr(*host, '/');
108-
109-
if ((*path=strchr(*host, '/'))) {
110-
**path='\0';
111-
*path=*path+1;
112-
} else {
113-
*path="";
114-
}
115-
116-
if ( *host[0] =='['&&strchr(*host, ']') ) { // IPv6
117-
*port=strafter(*host, "]:");
118-
*host=*host+1;
119-
strchr(*host, ']')[0] ='\0';
120-
} else { // IPv4
121-
if ((*port=strchr(*host, ':'))) {
122-
**port='\0';
123-
*port=*port+1;
124-
}
107+
char*ss=url;
108+
109+
// Must start with case insensitive http:// or https://
110+
if (strncasecmp(url, "http", 4)) url=0;
111+
else {
112+
url+=4;
113+
if ((TT.https=WGET_SSL&&toupper(*url=='s'))) url++;
114+
if (!strstart(&url, "://")) url=0;
125115
}
126-
127-
if (!*port&&WGET_IS_HTTP) *port="80";
128-
elseif (!*port&&WGET_IS_HTTPS) *port="443";
129-
elseif (!*port) error_exit("unsupported protocol");
116+
if (!url) error_exit("unsupported protocol: %s", ss);
117+
if ((*path=strchr(*host=url, '/'))) *((*path)++) =0;
118+
else*path="";
119+
120+
// Get port number and trim literal IPv6 addresses
121+
if (**host=='['&& (ss=strchr(++*host, ']'))) {
122+
*ss++=0;
123+
*port= (*ss==':') ? ++ss : 0;
124+
} elseif ((*port=strchr(*host, ':'))) *((*port)++) =0;
125+
if (!*port) *port=HTTPS ? "443" : "80";
130126
}
131127

132128
staticvoidwget_connect(char*host, char*port)

0 commit comments

Comments
 (0)
close