vhost.c revision 8fd7c5046d164fb0959222497e5925dfc6a52ff3
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu/* ====================================================================
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * The Apache Software License, Version 1.1
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * Redistribution and use in source and binary forms, with or without
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * modification, are permitted provided that the following conditions
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * 1. Redistributions of source code must retain the above copyright
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * notice, this list of conditions and the following disclaimer.
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * 2. Redistributions in binary form must reproduce the above copyright
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * notice, this list of conditions and the following disclaimer in
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * the documentation and/or other materials provided with the
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * distribution.
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * 3. The end-user documentation included with the redistribution,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * if any, must include the following acknowledgment:
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * "This product includes software developed by the
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * Apache Software Foundation (http://www.apache.org/)."
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * Alternately, this acknowledgment may appear in the software itself,
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * if and wherever such third-party acknowledgments normally appear.
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * 4. The names "Apache" and "Apache Software Foundation" must
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * not be used to endorse or promote products derived from this
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * software without prior written permission. For written
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * permission, please contact apache@apache.org.
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * 5. Products derived from this software may not be called "Apache",
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * nor may "Apache" appear in their name, without prior written
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * permission of the Apache Software Foundation.
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * ====================================================================
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * This software consists of voluntary contributions made by many
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * individuals on behalf of the Apache Software Foundation. For more
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * information on the Apache Software Foundation, please see
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * Portions of this software are based upon public domain software
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * originally written at the National Center for Supercomputing Applications,
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * University of Illinois, Urbana-Champaign.
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * http_vhost.c: functions pertaining to virtual host addresses
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * (configuration and run-time)
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * After all the definitions there's an explanation of how it's all put
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder/* meta-list of name-vhosts. Each server_rec can be in possibly multiple
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder * lists of name-vhosts.
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu server_addr_rec *sar; /* the record causing it to be in
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * this chain (needed for port comparisons) */
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu server_rec *server; /* the server to use on a match */
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroeder/* meta-list of ip addresses. Each server_rec can be in possibly multiple
69b1e90bbb27ce2dd365628c07c0f03a3ae97b26Robert Savu * hash chains since it can have multiple ips.
3d3889e0cefcdce9b3f43c53aaa201943ac2e895Jonathan von Schroedertypedef struct ipaddr_chain ipaddr_chain;
#ifndef IPHASH_TABLE_SIZE
int wild_port;
return NULL;
wild_port = 0;
if (!host) {
if (scope_id) {
return NULL;
return NULL;
const char *hostname,
server_rec *s)
const char *err;
while (hostname[0]) {
if (err) {
return err;
if (s->addrs) {
return NULL;
const char *arg)
#ifdef IPHASH_STATISTICS
static int iphash_compare(const void *a, const void *b)
unsigned total;
total = 0;
for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
count[i] = 0;
++count[i];
if (i < IPHASH_TABLE_SIZE) {
++total;
++total;
unsigned key;
return new;
return new;
unsigned bucket;
return trav;
return NULL;
return trav;
return NULL;
int len;
for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
if (default_list) {
while (*pic) {
server_rec *s;
s = main_s;
if (!s->server_hostname) {
for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
if (!ic) {
if (!s->server_hostname) {
if (has_default_vhost_addr) {
else if (!s->addrs) {
s->server_hostname =
char *hostname;
char *ipaddr_str;
s->server_hostname =
for (i = 0; i < IPHASH_TABLE_SIZE; ++i) {
#ifdef IPHASH_STATISTICS
char *dst;
goto bad;
else if (port) {
dst++;
goto bad;
goto bad;
bad:
if (names) {
if(!name[i]) continue;
if (names) {
if(!name[i]) continue;
server_rec *s;
s = r->server;
server_rec *s;
* do the full ServerName/ServerAlias comparisons once for each
goto found;
if (s == last_s) {
last_s = s;
goto found;
r->server = s;
server_rec *s;
if (s == last_s) {
last_s = s;
r->server = s;
fix_hostname(r);
if (r->hostname)
check_hostalias(r);
check_serverpath(r);
if (trav) {
if (trav) {