From: Jeff Trawick Date: Thu, 7 Dec 2000 18:12:48 +0000 (+0000) Subject: ab: use apr_parse_addr_port() in parse_url(). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6b2f16f52414972cbae4b63f19365dc0280bd655;p=apache ab: use apr_parse_addr_port() in parse_url(). httpd.exp: Add the new APR symbol apr_parse_addr_port. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87252 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/support/ab.c b/support/ab.c index ecf4014b0e..c609529590 100644 --- a/support/ab.c +++ b/support/ab.c @@ -189,9 +189,8 @@ int concurrency = 1; /* Number of multiple requests to make */ int tlimit = 0; /* time limit in cs */ int keepalive = 0; /* try and do keepalive connections */ char servername[1024]; /* name that server reports */ -char hostname[1024]; /* host name */ +char *hostname; /* host name from URL */ char *host_field; /* value of "Host:" header field */ -int family = APR_UNSPEC; /* requested address family */ char path[1024]; /* path name */ char postfile[1024]; /* name of file containing post data */ char *postdata; /* *buffer containing data from postfile */ @@ -201,7 +200,7 @@ char cookie[1024], /* optional cookie line */ auth[1024], /* optional (basic/uuencoded) * authentification */ hdrs[4096]; /* optional arbitrary headers */ -int port = 80; /* port number */ +apr_port_t port; /* port number */ apr_time_t aprtimeout = 30 * APR_USEC_PER_SEC; /* timeout value */ int use_html = 0; /* use html in the report */ @@ -300,7 +299,7 @@ static void output_results(void) printf("\r \r"); printf("Server Software: %s\n", servername); printf("Server Hostname: %s\n", hostname); - printf("Server Port: %d\n", port); + printf("Server Port: %hd\n", port); printf("\n"); printf("Document Path: %s\n", path); printf("Document Length: %d bytes\n", doclen); @@ -382,7 +381,7 @@ static void output_html_results(void) "%s\n", trstring, tdstring, tdstring, hostname); printf("Server Port:" - "%d\n", + "%hd\n", trstring, tdstring, tdstring, port); printf("Document Path:" "%s\n", @@ -504,7 +503,7 @@ static void start_connect(struct connection *c) c->cbx = 0; c->gotheader = 0; - if ((rv = apr_getaddrinfo(&destsa, hostname, family, port, 0, cntxt)) + if ((rv = apr_getaddrinfo(&destsa, hostname, APR_UNSPEC, port, 0, cntxt)) != APR_SUCCESS) { char buf[120]; @@ -514,7 +513,7 @@ static void start_connect(struct connection *c) } if ((rv = apr_create_socket(&c->aprsock, destsa->sa.sin.sin_family, SOCK_STREAM, cntxt)) != APR_SUCCESS) { - apr_err("Socket:", rv); + apr_err("socket", rv); } c->start = apr_now(); if ((rv = apr_connect(c->aprsock, destsa)) != APR_SUCCESS) { @@ -895,14 +894,14 @@ static void test(void) static void copyright(void) { if (!use_html) { - printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.42 $> apache-2.0"); + printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.43 $> apache-2.0"); printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n"); printf("Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/\n"); printf("\n"); } else { printf("

\n"); - printf(" This is ApacheBench, Version %s <%s> apache-2.0
\n", AB_VERSION, "$Revision: 1.42 $"); + printf(" This is ApacheBench, Version %s <%s> apache-2.0
\n", AB_VERSION, "$Revision: 1.43 $"); printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
\n"); printf(" Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/
\n"); printf("

\n

\n"); @@ -946,51 +945,31 @@ static int parse_url(char *url) { char *cp; char *h; - char *p = NULL; /* points to port if url has it */ + char *scope_id; + apr_status_t rv; if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0) url += 7; - h = url; -#if APR_HAVE_INET6 - if (*url == '[') { /* RFC 2732 format */ - h = url + 1; - url = strchr(h, ']'); - if (!url) { /* malformed IPv6 literal address format */ - return 1; - } - *url = '\0'; - ++url; - /* According to RFC 2732, this syntax is allowed only for IPv6 numeric - * address strings, so set the family passed to apr_getaddrinfo() so - * that it fails if the hostname is IPv4. - * - * It is certainly possible that the hostname parameter isn't a numeric - * address string; that error won't be caught here. - */ - family = APR_INET6; - } -#endif /* APR_HAVE_INET6 */ - if ((cp = strchr(url, ':')) != NULL) { - *cp++ = '\0'; - p = cp; - url = cp; - } if ((cp = strchr(url, '/')) == NULL) return 1; + h = apr_palloc(cntxt, cp - url + 1); + memcpy(h, url, cp - url); + h[cp - url] = '\0'; + rv = apr_parse_addr_port(&hostname, &scope_id, &port, h, cntxt); + if (rv != APR_SUCCESS || !hostname || scope_id) { + return 1; + } strcpy(path, cp); *cp = '\0'; - strcpy(hostname, h); -#if APR_HAVE_INET6 - if (family == APR_INET6) { - host_field = apr_psprintf(cntxt, "[%s]",hostname); + if (*url == '[') { /* IPv6 numeric address string */ + host_field = apr_psprintf(cntxt, "[%s]", hostname); } - else -#endif /* APR_HAVE_INET6 */ - { + else { host_field = hostname; } - if (p != NULL) - port = atoi(p); + if (port == 0) { /* no port specified */ + port = 80; + } return 0; } diff --git a/support/httpd.exp b/support/httpd.exp index bd9c18bd82..9dd926d007 100644 --- a/support/httpd.exp +++ b/support/httpd.exp @@ -467,6 +467,7 @@ apr_opendir apr_overlap_tables apr_overlay_tables apr_palloc +apr_parse_addr_port apr_parse_uuid apr_pcalloc apr_poll