randy 98/02/02 14:33:41
Modified: src/include httpd.h
src/main http_config.c http_core.c http_protocol.c util.c
src/modules/proxy mod_proxy.c proxy_http.c
src/modules/standard mod_rewrite.c
Log:
Generalize default_port manipulations.
The proxy may still need some work, but will defer until I can
review these changes with others.
Obtained from: Ben Laurie, Randy Terbush
Reviewed by: Ben Laurie, Randy Terbush
Revision Changes Path
1.180 +6 -2 apache-1.3/src/include/httpd.h
Index: httpd.h
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/include/httpd.h,v
retrieving revision 1.179
retrieving revision 1.180
diff -u -r1.179 -r1.180
--- httpd.h 1998/02/01 22:05:34 1.179
+++ httpd.h 1998/02/02 22:33:29 1.180
@@ -116,7 +116,11 @@
/* -------------- Port number for server running standalone ---------------
*/
-#define DEFAULT_PORT 80
+#define DEFAULT_HTTP_PORT 80
+#define DEFAULT_HTTPS_PORT 443
+#define is_default_port(port,r) ((port) == default_port(r))
+#define http_method(r) "http"
+#define default_port(r) DEFAULT_HTTP_PORT
/* --------- Default user name and group name running standalone ----------
*/
/* --- These may be specified as numbers by placing a # before a number ---
*/
@@ -802,7 +806,7 @@
#define escape_uri(ppool,path) os_escape_path(ppool,path,1)
API_EXPORT(char *) escape_html(pool *p, const char *s);
API_EXPORT(char *) construct_server(pool *p, const char *hostname,
- unsigned port);
+ unsigned port, const request_rec *r);
API_EXPORT(char *) escape_shell_cmd(pool *p, const char *s);
API_EXPORT(int) count_dirs(const char *path);
1.95 +1 -1 apache-1.3/src/main/http_config.c
Index: http_config.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/main/http_config.c,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- http_config.c 1998/01/21 22:11:01 1.94
+++ http_config.c 1998/02/02 22:33:31 1.95
@@ -1225,7 +1225,7 @@
{
server_rec *s = (server_rec *) pcalloc(p, sizeof(server_rec));
- s->port = DEFAULT_PORT;
+ s->port = 0;
s->server_admin = DEFAULT_ADMIN;
s->server_hostname = NULL;
s->error_fname = DEFAULT_ERRORLOG;
1.156 +3 -3 apache-1.3/src/main/http_core.c
Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/main/http_core.c,v
retrieving revision 1.155
retrieving revision 1.156
diff -u -r1.155 -r1.156
--- http_core.c 1998/02/02 19:46:53 1.155
+++ http_core.c 1998/02/02 22:33:32 1.156
@@ -622,11 +622,11 @@
: r->server->port;
host = r->hostname ? r->hostname : r->server->server_hostname;
}
- if (port == DEFAULT_PORT) {
- return pstrcat(p, "http://", host, uri, NULL);
+ if (is_default_port(port, r)) {
+ return pstrcat(p, http_method(r), "://", host, uri, NULL);
}
ap_snprintf(portnum, sizeof(portnum), "%u", port);
- return pstrcat(p, "http://", host, ":", portnum, uri, NULL);
+ return pstrcat(p, http_method(r), "://", host, ":", portnum, uri, NULL);
}
/*****************************************************************
1.184 +9 -6 apache-1.3/src/main/http_protocol.c
Index: http_protocol.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/main/http_protocol.c,v
retrieving revision 1.183
retrieving revision 1.184
diff -u -r1.183 -r1.184
--- http_protocol.c 1998/01/31 00:15:43 1.183
+++ http_protocol.c 1998/02/02 22:33:33 1.184
@@ -625,14 +625,17 @@
const char *check_fulluri(request_rec *r, const char *uri)
{
- char *name, *host;
- int i;
+ char *name, *host, *proto;
+ int i, plen;
unsigned port;
/* This routine parses full URLs, if they match the server */
- if (strncasecmp(uri, "http://", 7))
+ proto = http_method(r);
+ plen = strlen(proto);
+
+ if (strncasecmp(uri, proto, plen) || strncasecmp(uri + plen, "://", 3))
return uri;
- name = pstrdup(r->pool, uri + 7);
+ name = pstrdup(r->pool, uri + plen);
/* Find the hostname, assuming a valid request */
i = ind(name, '/');
@@ -643,7 +646,7 @@
if (*name)
port = atoi(name);
else
- port = 80;
+ port = default_port(r);
/* Make sure ports patch */
if (port != r->server->port)
@@ -651,7 +654,7 @@
/* Save it for later use */
r->hostname = pstrdup(r->pool, host);
- r->hostlen = 7 + i;
+ r->hostlen = plen + 3 + i;
/* The easy cases first */
if (!strcasecmp(host, r->server->server_hostname)) {
1.93 +2 -2 apache-1.3/src/main/util.c
Index: util.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/main/util.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -u -r1.92 -r1.93
--- util.c 1998/02/01 22:05:37 1.92
+++ util.c 1998/02/02 22:33:34 1.93
@@ -1071,12 +1071,12 @@
}
API_EXPORT(char *) construct_server(pool *p, const char *hostname,
- unsigned port)
+ unsigned port, const request_rec *r)
{
char portnum[22];
/* Long enough, even if port > 16 bits for some reason */
- if (port == DEFAULT_PORT)
+ if (is_default_port(port, r))
return pstrdup(p, hostname);
else {
ap_snprintf(portnum, sizeof(portnum), "%u", port);
1.35 +2 -2 apache-1.3/src/modules/proxy/mod_proxy.c
Index: mod_proxy.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/proxy/mod_proxy.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- mod_proxy.c 1998/01/28 11:33:24 1.34
+++ mod_proxy.c 1998/02/02 22:33:38 1.35
@@ -60,7 +60,7 @@
{
{"ftp", DEFAULT_FTP_PORT},
{"gopher", DEFAULT_GOPHER_PORT},
- {"http", DEFAULT_PORT},
+ {"http", DEFAULT_HTTP_PORT},
{"nntp", DEFAULT_NNTP_PORT},
{"wais", DEFAULT_WAIS_PORT},
{"https", DEFAULT_HTTPS_PORT},
@@ -177,7 +177,7 @@
/* canonicalise each specific scheme */
if (strncmp(url, "http:", 5) == 0)
- return proxy_http_canon(r, url + 5, "http", DEFAULT_PORT);
+ return proxy_http_canon(r, url + 5, "http", DEFAULT_HTTP_PORT);
else if (strncmp(url, "ftp:", 4) == 0)
return proxy_ftp_canon(r, url + 4);
else
1.37 +2 -2 apache-1.3/src/modules/proxy/proxy_http.c
Index: proxy_http.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/proxy/proxy_http.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- proxy_http.c 1998/01/07 16:46:37 1.36
+++ proxy_http.c 1998/02/02 22:33:38 1.37
@@ -181,7 +181,7 @@
if (urlptr == NULL)
return BAD_REQUEST;
urlptr += 3;
- destport = DEFAULT_PORT;
+ destport = DEFAULT_HTTP_PORT;
strp = strchr(urlptr, '/');
if (strp == NULL) {
desthost = pstrdup(p, urlptr);
@@ -280,7 +280,7 @@
bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.0\015\012",
NULL);
bvputs(f, "Host: ", desthost, NULL);
- if (destportstr != NULL && destport != DEFAULT_PORT)
+ if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
bvputs(f, ":", destportstr, "\015\012", NULL);
else
bputs("\015\012", f);
1.66 +6 -31 apache-1.3/src/modules/standard/mod_rewrite.c
Index: mod_rewrite.c
===================================================================
RCS file: /export/home/cvs/apache-1.3/src/modules/standard/mod_rewrite.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- mod_rewrite.c 1998/02/01 22:05:41 1.65
+++ mod_rewrite.c 1998/02/02 22:33:40 1.66
@@ -923,12 +923,7 @@
/* add the canonical URI of this URL */
thisserver = r->server->server_hostname;
-#ifdef APACHE_SSL
- if (((!r->connection->client->ssl) && (r->server->port == DEFAULT_PORT))
||
- ((r->connection->client->ssl) && (r->server->port == 443)))
-#else
- if (r->server->port == DEFAULT_PORT)
-#endif
+ if (is_default_port(r->server->port, r))
thisport = "";
else {
ap_snprintf(buf, sizeof(buf), ":%u", r->server->port);
@@ -937,15 +932,10 @@
thisurl = table_get(r->subprocess_env, ENVVAR_SCRIPT_URL);
/* set the variable */
-#ifdef APACHE_SSL
var = pstrcat(r->pool, http_method(r), "://", thisserver, thisport,
thisurl, NULL);
-#else
- var = pstrcat(r->pool, "http://", thisserver, thisport, thisurl, NULL);
-#endif
table_setn(r->subprocess_env, ENVVAR_SCRIPT_URI, var);
-
/* if filename was not initially set,
* we start with the requested URI
*/
@@ -2108,11 +2098,7 @@
olduri = pstrdup(r->pool, r->filename); /* save for logging */
/* cut the hostname and port out of the URI */
-#ifdef APACHE_SSL
ap_cpystrn(buf, r->filename+strlen(http_method(r))+3, sizeof(buf));
-#else
- ap_cpystrn(buf, r->filename+7, sizeof(buf));
-#endif
hostp = buf;
for (cp = hostp; *cp != '\0' && *cp != '/' && *cp != ':'; cp++)
;
@@ -2137,7 +2123,7 @@
ap_cpystrn(host, hostp, sizeof(host));
*cp = '/';
/* set port */
- port = DEFAULT_PORT;
+ port = default_port(r);
/* set remaining url */
url = cp;
}
@@ -2145,7 +2131,7 @@
/* set host */
ap_cpystrn(host, hostp, sizeof(host));
/* set port */
- port = DEFAULT_PORT;
+ port = default_port(r);
/* set remaining url */
url = "/";
}
@@ -2179,32 +2165,21 @@
|| (i > 8 && strncasecmp(r->filename, "https://", 8) == 0)
|| (i > 9 && strncasecmp(r->filename, "gopher://", 9) == 0)
|| (i > 6 && strncasecmp(r->filename, "ftp://", 6) == 0))) {
-#ifdef APACHE_SSL
+
if (is_default_port(r->server->port,r))
-#else
- if (r->server->port == DEFAULT_PORT)
-#endif
port[0] = '\0';
else
ap_snprintf(port, sizeof(port), ":%u", r->server->port);
+
if (r->filename[0] == '/')
-#ifdef APACHE_SSL
ap_snprintf(newuri, sizeof(newuri), "%s://%s%s%s",
http_method(r), r->server->server_hostname,
port, r->filename);
-#else
- ap_snprintf(newuri, sizeof(newuri), "http://%s%s%s",
- r->server->server_hostname, port, r->filename);
-#endif
else
-#ifdef APACHE_SSL
ap_snprintf(newuri, sizeof(newuri), "%s://%s%s/%s",
http_method(r), r->server->server_hostname,
port, r->filename);
-#else
- ap_snprintf(newuri, sizeof(newuri), "http://%s%s/%s",
- r->server->server_hostname, port, r->filename);
-#endif
+
r->filename = pstrdup(r->pool, newuri);
}
return;