You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by Alexei Kosut <ak...@hyperreal.com> on 1996/03/28 08:59:38 UTC
cvs commit: apache/src CHANGES http_config.c http_config.h http_core.c http_main.c http_protocol.c httpd.h util.c
akosut 96/03/27 23:59:37
Modified: src CHANGES http_config.c http_config.h http_core.c
http_main.c http_protocol.c httpd.h util.c
Log:
Add new directive, <HostAlias>, very similar to <VirtualHost> in
function, but instead of binding the server to a new IP address, it
uses hostnames derived from the Host: header and/or full-URI
requests. (Requests that have neither will be served the documents as
given normally) The directive is of the form <HostAlias *.foo.com
foo.bar.net foo.com> (multiple entires seperated by spaces, with
wildcards).
Also, server->is_virtual is now set correctly in
init_virtual_host(). This was a long-standing bug, finially fixed.
Revision Changes Path
1.16 +5 -0 apache/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apache/src/CHANGES,v
retrieving revision 1.15
retrieving revision 1.16
diff -C3 -r1.15 -r1.16
*** CHANGES 1996/03/25 11:35:10 1.15
--- CHANGES 1996/03/28 07:59:29 1.16
***************
*** 1,3 ****
--- 1,8 ----
+ *) Add <HostAlias> directive, similar to <VirtualHost>, but does not
+ require additional IP addresses - instead uses the Host: header sent
+ by some (but not all) clients - those that do not will get the normal
+ set of documents. Use as: <HostAlias foo.bar.net *.foo.com foo.com>
+
*) Added Status module with preliminary documentation available
http://www.apache.org/docs/1.1/mod_status.html
1.8 +34 -0 apache/src/http_config.c
Index: http_config.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_config.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C3 -r1.7 -r1.8
*** http_config.c 1996/03/13 10:49:05 1.7
--- http_config.c 1996/03/28 07:59:30 1.8
***************
*** 656,661 ****
--- 656,695 ----
s->port = s->host_port; /* set them the same, by default */
s->next = NULL;
+ s->is_virtual = 1;
+
+ s->module_config = create_empty_config (p);
+ s->lookup_defaults = create_per_dir_config (p);
+
+ return s;
+ }
+
+ server_rec *init_host_alias (pool *p, char *hostnames)
+ {
+ server_rec *s = (server_rec *)pcalloc (p, sizeof (server_rec));
+
+ #ifdef RLIMIT_NOFILE
+ struct rlimit limits;
+
+ getrlimit ( RLIMIT_NOFILE, &limits );
+ if ( limits.rlim_cur < limits.rlim_max ) {
+ limits.rlim_cur += 2;
+ if ( setrlimit ( RLIMIT_NOFILE, &limits ) < 0 )
+ fprintf (stderr, "Cannot exceed hard limit for open files");
+ }
+ #endif
+
+ s->server_admin = NULL;
+ s->server_hostname = NULL;
+ s->error_fname = NULL;
+ s->srm_confname = NULL;
+ s->access_confname = NULL;
+ s->timeout = 0;
+ s->names = pstrdup(p, hostnames);
+ s->next = NULL;
+
+ s->is_virtual = 2;
+
s->module_config = create_empty_config (p);
s->lookup_defaults = create_per_dir_config (p);
1.3 +1 -0 apache/src/http_config.h
Index: http_config.h
===================================================================
RCS file: /export/home/cvs/apache/src/http_config.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C3 -r1.2 -r1.3
*** http_config.h 1996/02/22 11:46:44 1.2
--- http_config.h 1996/03/28 07:59:30 1.3
***************
*** 242,247 ****
--- 242,248 ----
char *srm_command_loop (cmd_parms *parms, void *config);
server_rec *init_virtual_host (pool *p, char *hostname);
+ server_rec *init_host_alias (pool *p, char *hostnames);
int is_virtual_server (server_rec *);
void process_resource_config(server_rec *s, char *fname, pool *p, pool *ptemp);
1.7 +41 -0 apache/src/http_core.c
Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C3 -r1.6 -r1.7
*** http_core.c 1996/03/21 03:50:14 1.6
--- http_core.c 1996/03/28 07:59:30 1.7
***************
*** 550,555 ****
--- 550,594 ----
return errmsg;
}
+ char *end_hostalias_magic = "</HostAlias> out of place";
+
+ char *end_hostalias_section (cmd_parms *cmd, void *dummy) {
+ return end_hostalias_magic;
+ }
+
+ char *hostalias_section (cmd_parms *cmd, void *dummy, char *arg)
+ {
+ server_rec *main_server = cmd->server, *s;
+ char *errmsg, *endp = strrchr (arg, '>');
+ pool *p = cmd->pool, *ptemp = cmd->temp_pool;
+
+ if (endp) *endp = '\0';
+
+ if (main_server->is_virtual)
+ return "<HostAlias> doesn't nest!";
+
+ s = init_host_alias (p, arg);
+ s->next = main_server->next;
+ main_server->next = s;
+
+ cmd->server = s;
+ errmsg = srm_command_loop (cmd, s->lookup_defaults);
+ cmd->server = main_server;
+
+ if (s->srm_confname)
+ process_resource_config (s, s->srm_confname, p, ptemp);
+
+ if (s->access_confname)
+ process_resource_config (s, s->access_confname, p, ptemp);
+
+ if (errmsg == end_hostalias_magic) {
+ if (!s->server_hostname)
+ return "ServerName must be specified in a <HostAlias>";
+ return NULL;
+ }
+ return errmsg;
+ }
+
char *set_server_string_slot (cmd_parms *cmd, void *dummy, char *arg)
{
/* This one's pretty generic... */
***************
*** 773,778 ****
--- 812,819 ----
"a port number or a numeric IP address and a port number"},
{ "<VirtualHost", virtualhost_section, NULL, RSRC_CONF, RAW_ARGS, NULL },
{ "</VirtualHost>", end_virtualhost_section, NULL, RSRC_CONF, NO_ARGS, NULL },
+ { "<HostAlias", hostalias_section, NULL, RSRC_CONF, RAW_ARGS, NULL },
+ { "</HostAlias>", end_hostalias_section, NULL, RSRC_CONF, NO_ARGS, NULL },
{ NULL },
};
1.11 +2 -1 apache/src/http_main.c
Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C3 -r1.10 -r1.11
*** http_main.c 1996/03/25 10:54:29 1.10
--- http_main.c 1996/03/28 07:59:31 1.11
***************
*** 956,962 ****
server_rec *virt;
for (virt = server->next; virt; virt = virt->next)
! if ((virt->host_addr.s_addr == htonl(INADDR_ANY) ||
virt->host_addr.s_addr == server_ip.s_addr) &&
(virt->host_port == 0 || virt->host_port == port))
return virt;
--- 956,963 ----
server_rec *virt;
for (virt = server->next; virt; virt = virt->next)
! if ((virt->is_virtual == 1) && /* VirtualHost */
! (virt->host_addr.s_addr == htonl(INADDR_ANY) ||
virt->host_addr.s_addr == server_ip.s_addr) &&
(virt->host_port == 0 || virt->host_port == port))
return virt;
1.13 +39 -3 apache/src/http_protocol.c
Index: http_protocol.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_protocol.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C3 -r1.12 -r1.13
*** http_protocol.c 1996/03/27 11:45:06 1.12
--- http_protocol.c 1996/03/28 07:59:31 1.13
***************
*** 277,288 ****
/* Make sure ports patch */
if (port != r->server->port) return uri;
/* The easy cases first */
if (!strcasecmp(host, r->server->server_hostname)) {
! return (uri + 7 + i);
}
else if (!strcmp(host, inet_ntoa(r->connection->local_addr.sin_addr))) {
! return (uri + 7 + i);
}
/* Now things get a bit trickier - check the IP address(es) of the host */
--- 277,292 ----
/* Make sure ports patch */
if (port != r->server->port) return uri;
+ /* Save it for later use */
+ r->hostname = pstrdup(r->pool, host);
+ r->hostlen = 7 + i;
+
/* The easy cases first */
if (!strcasecmp(host, r->server->server_hostname)) {
! return (uri + r->hostlen);
}
else if (!strcmp(host, inet_ntoa(r->connection->local_addr.sin_addr))) {
! return (uri + r->hostlen);
}
/* Now things get a bit trickier - check the IP address(es) of the host */
***************
*** 295,301 ****
for (n = 0; hp->h_addr_list[n] != NULL; n++) {
if (r->connection->local_addr.sin_addr.s_addr ==
(((struct in_addr *)(hp->h_addr_list[n]))->s_addr)) {
! return (uri + 7 + i);
}
}
}
--- 299,305 ----
for (n = 0; hp->h_addr_list[n] != NULL; n++) {
if (r->connection->local_addr.sin_addr.s_addr ==
(((struct in_addr *)(hp->h_addr_list[n]))->s_addr)) {
! return (uri + r->hostlen);
}
}
}
***************
*** 345,350 ****
--- 349,383 ----
}
}
+ void check_hostalias (request_rec *r) {
+ char *host = getword(r->pool, &r->hostname, ':'); /* Get rid of port */
+ server_rec *s;
+
+ if (*r->hostname && (atoi(r->hostname) != r->server->port))
+ return;
+
+ r->hostname = host;
+
+ for (s = r->server->next; s; s = s->next) {
+ char *names = s->names;
+
+ if (s->is_virtual != 2) continue; /* No a HostAlias */
+
+ while (*names) {
+ char *name = getword_conf (r->pool, &names);
+
+ if ((is_matchexp(name) && !strcasecmp_match(host, name)) ||
+ (!strcasecmp(host, name))) {
+ r->server = r->connection->server = s;
+ if (r->hostlen && !strncmp(r->uri, "http://", 7)) {
+ r->uri += r->hostlen;
+ r->proxyreq = 0;
+ }
+ }
+ }
+ }
+ }
+
request_rec *read_request (conn_rec *conn)
{
request_rec *r = (request_rec *)pcalloc (conn->pool, sizeof(request_rec));
***************
*** 382,387 ****
--- 415,423 ----
if (!r->assbackwards) get_mime_headers(r);
/* handle Host header here, to get virtual server */
+
+ if (r->hostname || (r->hostname = table_get(r->headers_in, "Host")))
+ check_hostalias(r);
kill_timeout (r);
conn->keptalive = 0; /* We now have a request - so no more short timeouts */
1.12 +6 -1 apache/src/httpd.h
Index: httpd.h
===================================================================
RCS file: /export/home/cvs/apache/src/httpd.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C3 -r1.11 -r1.12
*** httpd.h 1996/03/27 14:56:12 1.11
--- httpd.h 1996/03/28 07:59:32 1.12
***************
*** 315,321 ****
int proxyreq; /* A proxy request */
int header_only; /* HEAD request, as opposed to GET */
char *protocol; /* Protocol, as given to us, or HTTP/0.9 */
!
char *status_line; /* Status line, if set by script */
int status; /* In any case */
--- 315,323 ----
int proxyreq; /* A proxy request */
int header_only; /* HEAD request, as opposed to GET */
char *protocol; /* Protocol, as given to us, or HTTP/0.9 */
! char *hostname; /* Host, as set by full URI or Host: */
! int hostlen; /* Length of http://host:port in full URI */
!
char *status_line; /* Status line, if set by script */
int status; /* In any case */
***************
*** 458,463 ****
--- 460,467 ----
int timeout; /* Timeout, in seconds, before we give up */
int keep_alive_timeout; /* Seconds we'll wait for another request */
int keep_alive; /* Maximum requests per connection */
+
+ char *names; /* Wildcarded names for HostAlias servers */
};
/* These are more like real hosts than virtual hosts */
***************
*** 500,505 ****
--- 504,510 ----
int is_matchexp(char *str);
int strcmp_match(char *str, char *exp);
+ int strcasecmp_match(char *str, char *exp);
char *uudecode (pool *, char *);
void str_tolower (char *);
1.6 +23 -0 apache/src/util.c
Index: util.c
===================================================================
RCS file: /export/home/cvs/apache/src/util.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C3 -r1.5 -r1.6
*** util.c 1996/03/05 17:28:50 1.5
--- util.c 1996/03/28 07:59:32 1.6
***************
*** 195,200 ****
--- 195,223 ----
return (str[x] != '\0');
}
+ int strcasecmp_match(char *str, char *exp) {
+ int x,y;
+
+ for(x=0,y=0;exp[y];++y,++x) {
+ if((!str[x]) && (exp[y] != '*'))
+ return -1;
+ if(exp[y] == '*') {
+ while(exp[++y] == '*');
+ if(!exp[y])
+ return 0;
+ while(str[x]) {
+ int ret;
+ if((ret = strcasecmp_match(&str[x++],&exp[y])) != 1)
+ return ret;
+ }
+ return -1;
+ } else
+ if((exp[y] != '?') && (tolower(str[x]) != tolower(exp[y])))
+ return 1;
+ }
+ return (str[x] != '\0');
+ }
+
int is_matchexp(char *str) {
register int x;