Roxen.git / server / base_server / roxen.pike

version» Context lines:

Roxen.git/server/base_server/roxen.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2001, Roxen IS.   //   // The Roxen WebServer main program.   //   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.838 2003/10/22 13:27:43 grubba Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.839 2003/10/22 15:45:15 grubba Exp $";      //! @appears roxen   //!   //! The Roxen WebServer main program.      // The argument cache. Used by the image cache.   ArgCache argcache;      // Some headerfiles   #define IN_ROXEN
Roxen.git/server/base_server/roxen.pike:1112:    set( "port_options" , q );    save( );   }      #ifdef DEBUG_URL2CONF   #define URL2CONF_MSG(X...) report_debug (X)   #else   #define URL2CONF_MSG(X...)   #endif    - Configuration find_configuration_for_url(object url, void|string url_base) + static mapping(string:int(0..1)) host_is_local_cache = ([]); +  + //! Check if @[hostname] is local to this machine. + int(0..1) host_is_local(string hostname) + { +  int(0..1) res; +  if (!zero_type(res = host_is_local_cache[hostname])) return res; +  +  // Look up the IP. +  string ip = blocking_host_to_ip(hostname); +  +  // Can we bind to it? +  Stdio.Port port = Stdio.Port(); +  res = port->bind(0, 0, ip); +  +  destruct(port); +  return host_is_local_cache[hostname] = res; + } +  + Configuration find_configuration_for_url(Standards.URI url, +  void|Configuration only_this_conf)   //! Tries to to determine if a request for the given url would end up   //! in this server, and if so returns the corresponding configuration. -  + //! + //! If @[only_this_conf] has been specified only matches against it + //! will be returned.   {    Configuration c;    string url_with_port = sprintf("%s://%s:%d%s", url->scheme, url->host,    url->port,    (sizeof(url->path)?url->path:"/"));       URL2CONF_MSG("URL with port: %s\n", url_with_port);       foreach( indices(urls), string u )    {    mixed q = urls[u];    URL2CONF_MSG("Trying %O:%O\n", u, q);    if( glob( u+"*", url_with_port ) )    {    URL2CONF_MSG("glob match\n");    if( q->port &&    (c = q->port->find_configuration_for_url(url_with_port, 0, 1 )) )    {    URL2CONF_MSG("Found config: %O\n", c); - #if 0 -  // FIXME: The following code looks suspect; what's its intention? -  // /grubba 2003-10-22 -  if (search(u, "*") != -1 || -  search(u, "?") != -1) -  { -  // Something like "http://*:80/" +     -  // Base url -  if (url_base) -  { -  Standards.URI base = Standards.URI(url_base); -  if (url->host == base->host && -  url->port == base->port && -  url->scheme == base->scheme) -  break; -  } -  -  // Configuration location -  Standards.URI config = Standards.URI(c->get_url()); -  if (url->host == config->host && -  url->port == config->port && -  url->scheme == config->scheme) -  break; -  -  URL2CONF_MSG("No match:\n" -  " host: %O : %O\n" -  " port: %O : %O\n" -  " scheme: %O : %O\n", -  url->host, config->host, -  url->port, config->port, -  url->scheme, config->scheme); -  -  // Do not match +  if ((only_this_conf && (c != only_this_conf)) || +  ((search(u, "*") != -1 || search(u, "?") != -1) && +  // u is something like "http://*:80/" +  (!host_is_local(url->host)))) { +  // Bad match. +  URL2CONF_MSG("Bad match: only_this_conf:%O, host_is_local:%O\n", +  (only_this_conf && (c == only_this_conf)), +  (!host_is_local(url->host)));    c = 0; -  +  continue;    } -  else - #endif /* 0 */ +     break;    }    }    }    URL2CONF_MSG("Result: %O\n", c);    return c;   }      class InternalRequestID   //! ID for internal requests that are not linked to any real request.