Prevent / doubling and shrink parse_url.
This commit is contained in:
parent
59c09d06e3
commit
a9711a5969
@ -241,31 +241,28 @@ int wget_main(int argc, char **argv)
|
|||||||
|
|
||||||
void parse_url(char *url, char **uri_host, int *uri_port, char **uri_path)
|
void parse_url(char *url, char **uri_host, int *uri_port, char **uri_path)
|
||||||
{
|
{
|
||||||
char *s, *h;
|
char *cp, *sp;
|
||||||
static char *defaultpath = "/";
|
|
||||||
|
|
||||||
*uri_port = 80;
|
*uri_port = 80;
|
||||||
|
|
||||||
if (strncmp(url, "http://", 7) != 0)
|
if (strncmp(url, "http://", 7) != 0)
|
||||||
error_msg_and_die("not an http url: %s\n", url);
|
error_msg_and_die("not an http url: %s\n", url);
|
||||||
|
|
||||||
/* pull the host portion to the front of the buffer */
|
*uri_host = url + 7;
|
||||||
for (s = url, h = url+7 ; *h != '/' && *h != 0; ++h) {
|
|
||||||
if (*h == ':') {
|
cp = strchr(*uri_host, ':');
|
||||||
*uri_port = atoi(h+1);
|
sp = strchr(*uri_host, '/');
|
||||||
*h = '\0';
|
|
||||||
|
if (cp != NULL && (sp == NULL || cp < sp)) {
|
||||||
|
*cp++ = '\0';
|
||||||
|
*uri_port = atoi(cp);
|
||||||
}
|
}
|
||||||
*s++ = *h;
|
|
||||||
}
|
|
||||||
*s = '\0';
|
|
||||||
|
|
||||||
if (*h == 0) h = defaultpath;
|
if (sp != NULL) {
|
||||||
|
*sp++ = '\0';
|
||||||
*uri_host = url;
|
*uri_path = sp;
|
||||||
*uri_path = h;
|
} else
|
||||||
|
*uri_path = "";
|
||||||
if (!strcmp( *uri_host, *uri_path))
|
|
||||||
*uri_path = defaultpath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -514,7 +511,7 @@ progressmeter(int flag)
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: wget.c,v 1.14 2000/12/18 03:08:29 kraai Exp $
|
* $Id: wget.c,v 1.15 2001/01/03 16:15:15 kraai Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
33
wget.c
33
wget.c
@ -241,31 +241,28 @@ int wget_main(int argc, char **argv)
|
|||||||
|
|
||||||
void parse_url(char *url, char **uri_host, int *uri_port, char **uri_path)
|
void parse_url(char *url, char **uri_host, int *uri_port, char **uri_path)
|
||||||
{
|
{
|
||||||
char *s, *h;
|
char *cp, *sp;
|
||||||
static char *defaultpath = "/";
|
|
||||||
|
|
||||||
*uri_port = 80;
|
*uri_port = 80;
|
||||||
|
|
||||||
if (strncmp(url, "http://", 7) != 0)
|
if (strncmp(url, "http://", 7) != 0)
|
||||||
error_msg_and_die("not an http url: %s\n", url);
|
error_msg_and_die("not an http url: %s\n", url);
|
||||||
|
|
||||||
/* pull the host portion to the front of the buffer */
|
*uri_host = url + 7;
|
||||||
for (s = url, h = url+7 ; *h != '/' && *h != 0; ++h) {
|
|
||||||
if (*h == ':') {
|
cp = strchr(*uri_host, ':');
|
||||||
*uri_port = atoi(h+1);
|
sp = strchr(*uri_host, '/');
|
||||||
*h = '\0';
|
|
||||||
|
if (cp != NULL && (sp == NULL || cp < sp)) {
|
||||||
|
*cp++ = '\0';
|
||||||
|
*uri_port = atoi(cp);
|
||||||
}
|
}
|
||||||
*s++ = *h;
|
|
||||||
}
|
|
||||||
*s = '\0';
|
|
||||||
|
|
||||||
if (*h == 0) h = defaultpath;
|
if (sp != NULL) {
|
||||||
|
*sp++ = '\0';
|
||||||
*uri_host = url;
|
*uri_path = sp;
|
||||||
*uri_path = h;
|
} else
|
||||||
|
*uri_path = "";
|
||||||
if (!strcmp( *uri_host, *uri_path))
|
|
||||||
*uri_path = defaultpath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -514,7 +511,7 @@ progressmeter(int flag)
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: wget.c,v 1.14 2000/12/18 03:08:29 kraai Exp $
|
* $Id: wget.c,v 1.15 2001/01/03 16:15:15 kraai Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user