summaryrefslogtreecommitdiffstats
path: root/lib/libfetch
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-11-10 08:43:40 +0000
committerdes <des@FreeBSD.org>2000-11-10 08:43:40 +0000
commit985bff769942e74d8a4614115b7153a96bf6d0b6 (patch)
treeda8eae065a0f12e6489dde4d5fef45d7a0b7ac3d /lib/libfetch
parentfaf86e96f0a2a44d87ffbce68497bf4426dcc3af (diff)
downloadFreeBSD-src-985bff769942e74d8a4614115b7153a96bf6d0b6.zip
FreeBSD-src-985bff769942e74d8a4614115b7153a96bf6d0b6.tar.gz
Use the documented (and historical) defaults. Centralize the decision logic
in order to avoid this bug in the future. Submitted by: se
Diffstat (limited to 'lib/libfetch')
-rw-r--r--lib/libfetch/common.c34
-rw-r--r--lib/libfetch/common.h4
-rw-r--r--lib/libfetch/ftp.c21
-rw-r--r--lib/libfetch/http.c23
4 files changed, 45 insertions, 37 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index c03b1f5..4d05a6b6 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -168,6 +168,40 @@ _fetch_info(char *fmt, ...)
/*** Network-related utility functions ***************************************/
/*
+ * Return the default port for a scheme
+ */
+int
+_fetch_default_port(char *scheme)
+{
+ struct servent *se;
+
+ if ((se = getservbyname(scheme, "tcp")) != NULL)
+ return ntohs(se->s_port);
+ if (strcasecmp(scheme, SCHEME_FTP) == 0)
+ return FTP_DEFAULT_PORT;
+ if (strcasecmp(scheme, SCHEME_HTTP) == 0)
+ return HTTP_DEFAULT_PORT;
+ return 0;
+}
+
+/*
+ * Return the default proxy port for a scheme
+ */
+int
+_fetch_default_proxy_port(char *scheme)
+{
+ struct servent *se;
+
+ if ((se = getservbyname(scheme, "tcp")) != NULL)
+ return ntohs(se->s_port);
+ if (strcasecmp(scheme, SCHEME_FTP) == 0)
+ return FTP_DEFAULT_PROXY_PORT;
+ if (strcasecmp(scheme, SCHEME_HTTP) == 0)
+ return HTTP_DEFAULT_PROXY_PORT;
+ return 0;
+}
+
+/*
* Establish a TCP connection to the specified port on the specified host.
*/
int
diff --git a/lib/libfetch/common.h b/lib/libfetch/common.h
index 4470c5b..13723a3 100644
--- a/lib/libfetch/common.h
+++ b/lib/libfetch/common.h
@@ -33,6 +33,8 @@
#define FTP_DEFAULT_PORT 21
#define HTTP_DEFAULT_PORT 80
+#define FTP_DEFAULT_PROXY_PORT 21
+#define HTTP_DEFAULT_PROXY_PORT 3128
/* Structure used for error message lists */
struct fetcherr {
@@ -43,6 +45,8 @@ struct fetcherr {
void _fetch_seterr(struct fetcherr *p, int e);
void _fetch_syserr(void);
void _fetch_info(char *fmt, ...);
+int _fetch_default_port(char *);
+int _fetch_default_proxy_port(char *);
int _fetch_connect(char *host, int port, int af, int verbose);
int _fetch_getln(int fd, char **buf, size_t *size, size_t *len);
int _fetch_putln(int fd, char *str, size_t len);
diff --git a/lib/libfetch/ftp.c b/lib/libfetch/ftp.c
index 18da8b2..3e56342 100644
--- a/lib/libfetch/ftp.c
+++ b/lib/libfetch/ftp.c
@@ -711,19 +711,6 @@ ouch:
}
/*
- * Return default port
- */
-static int
-_ftp_default_port(void)
-{
- struct servent *se;
-
- if ((se = getservbyname(SCHEME_FTP, "tcp")) != NULL)
- return ntohs(se->s_port);
- return FTP_DEFAULT_PORT;
-}
-
-/*
* Log on to FTP server
*/
static int
@@ -776,7 +763,7 @@ _ftp_connect(struct url *url, struct url *purl, char *flags)
user = url->user;
if (!user || !*user)
user = FTP_ANONYMOUS_USER;
- if (purl && url->port == FTP_DEFAULT_PORT)
+ if (purl && url->port == _fetch_default_port(url->scheme))
e = _ftp_cmd(cd, "USER %s@%s", user, url->host);
else if (purl)
e = _ftp_cmd(cd, "USER %s@%s@%d", user, url->host, url->port);
@@ -859,7 +846,7 @@ _ftp_cached_connect(struct url *url, struct url *purl, char *flags)
/* set default port */
if (!url->port)
- url->port = _ftp_default_port();
+ url->port = _fetch_default_port(url->scheme);
/* try to use previously cached connection */
if (_ftp_isconnected(url)) {
@@ -890,9 +877,9 @@ _ftp_get_proxy(void)
if (((p = getenv("FTP_PROXY")) || (p = getenv("HTTP_PROXY"))) &&
*p && (purl = fetchParseURL(p)) != NULL) {
if (!*purl->scheme)
- strcpy(purl->scheme, SCHEME_FTP);
+ strcpy(purl->scheme, SCHEME_HTTP);
if (!purl->port)
- purl->port = _ftp_default_port();
+ purl->port = _fetch_default_proxy_port(purl->scheme);
if (strcasecmp(purl->scheme, SCHEME_FTP) == 0 ||
strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
return purl;
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index e8d193b..9c4bebb 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -609,23 +609,6 @@ _http_authorize(int fd, char *hdr, char *p)
*/
/*
- * Return the default port for this scheme
- */
-static int
-_http_default_port(char *scheme)
-{
- struct servent *se;
-
- if ((se = getservbyname(scheme, "tcp")) != NULL)
- return ntohs(se->s_port);
- if (strcasecmp(scheme, SCHEME_FTP) == 0)
- return FTP_DEFAULT_PORT;
- if (strcasecmp(scheme, SCHEME_HTTP) == 0)
- return HTTP_DEFAULT_PORT;
- return 0;
-}
-
-/*
* Connect to the correct HTTP server or proxy.
*/
static int
@@ -672,7 +655,7 @@ _http_get_proxy()
if (!*purl->scheme)
strcpy(purl->scheme, SCHEME_HTTP);
if (!purl->port)
- purl->port = _http_default_port(SCHEME_HTTP);
+ purl->port = _fetch_default_proxy_port(purl->scheme);
if (strcasecmp(purl->scheme, SCHEME_HTTP) == 0)
return purl;
fetchFreeURL(purl);
@@ -733,7 +716,7 @@ _http_request(struct url *URL, char *op, struct url_stat *us,
retry:
/* check port */
if (!url->port)
- url->port = _http_default_port(url->scheme);
+ url->port = _fetch_default_port(url->scheme);
/* connect to server or proxy */
if ((fd = _http_connect(url, purl, flags)) == -1)
@@ -781,7 +764,7 @@ _http_request(struct url *URL, char *op, struct url_stat *us,
}
/* other headers */
- if (url->port == _http_default_port(url->scheme))
+ if (url->port == _fetch_default_port(url->scheme))
_http_cmd(fd, "Host: %s", host);
else
_http_cmd(fd, "Host: %s:%d", host, url->port);
OpenPOWER on IntegriCloud