@@ -78,12 +78,13 @@ config WGET_OPENSSL
78
78
79
79
#define WGET_IS_HTTP (strncmp(TT.url, "http://", 7) == 0)
80
80
#define WGET_IS_HTTPS (WGET_SSL && (strncmp(TT.url, "https://", 8) == 0))
81
+ #define HTTPS (WGET_SSL && TT.https)
81
82
82
83
GLOBALS (
83
84
char * filename ;
84
85
long redirects ;
85
86
86
- int sock ;
87
+ int sock , https ;
87
88
char * url ;
88
89
#if CFG_WGET_LIBTLS
89
90
struct tls * tls ;
@@ -103,30 +104,25 @@ static char *wget_strncaseafter(char *haystack, char *needle)
103
104
// get http info in URL
104
105
static void wget_info (char * url , char * * host , char * * port , char * * path )
105
106
{
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 ;
125
115
}
126
-
127
- if (!* port && WGET_IS_HTTP ) * port = "80" ;
128
- else if (!* port && WGET_IS_HTTPS ) * port = "443" ;
129
- else if (!* 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
+ } else if ((* port = strchr (* host , ':' ))) * ((* port )++ ) = 0 ;
125
+ if (!* port ) * port = HTTPS ? "443" : "80" ;
130
126
}
131
127
132
128
static void wget_connect (char * host , char * port )
0 commit comments