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 - 2004, 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.1009 2009/01/08 23:14:46 mast Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.1010 2009/01/10 16:34:08 mast 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:1466:    catch {    res = port->bind(0, 0, ip);    };       destruct(port);    return host_is_local_cache[hostname] = res;   }      array(Protocol|mapping(string:mixed)) find_port_for_url (    Standards.URI url, void|Configuration only_this_conf) - // Returns ({port_obj, url_data}) for an url that matches the given + // Returns ({port_obj, url_data}) for a url that matches the given   // one. url_data is the mapping for the url in port_obj->urls. If   // only_this_conf is given then only ports for that configuration are   // searched.   {    // Force string coersion to incorporate any separate base URI    Standards.URI url2 = Standards.URI((string) url);    url2->fragment = 0;    url2->query = 0;    string url_with_port = (string) url2;       URL2CONF_MSG("URL with port: %s\n", url_with_port);       foreach (urls; string u; mapping(string:mixed) q)    {    URL2CONF_MSG("Trying %O:%O\n", u, q);    if( glob( u+"*", url_with_port ) )    {    URL2CONF_MSG("glob match\n");    if (Protocol p = q->port)    if (mapping(string:mixed) url_data = -  p->find_url_data_for_url (url_with_port, 0 )) +  p->find_url_data_for_url (url_with_port, 0, 0))    {    Configuration c = url_data->conf;    URL2CONF_MSG("Found config: %O\n", url_data->conf);       if ((only_this_conf && (c != only_this_conf)) ||    (sscanf (u, "%*s://%*[^*?]%*c") == 3 && // u contains * or ?.    // 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",
Roxen.git/server/base_server/roxen.pike:1635:    int bound;    //! 0 if the port isn't bound, 1 if it is, and -1 if it binding it    //! failed with EADDRINUSE when told to ignore that error.    //!    //! @note    //! The -1 state should be uncommon since @[register_url] should    //! remove such objects after the failed bind attempt.       string path;    constant name = "unknown"; +     constant supports_ipless = 0;    //! If true, the protocol handles ip-less virtual hosting       constant requesthandlerfile = "";    //! Filename of a by-connection handling class. It is also possible    //! to set the 'requesthandler' class member in a overloaded create    //! function.       constant default_port = 4711;    //! If no port is specified in the URL, use this one
Roxen.git/server/base_server/roxen.pike:1795:    });    return;    }    } else    c = mu->conf;    }    requesthandler( q, this_object(), c );    }    }    -  private function(string,int:mapping(string:mixed)) sp_fudfu; +  private function(string,int,RequestID:mapping(string:mixed)) sp_fudfu;    -  mapping(string:mixed) find_url_data_for_url (string url, int no_default) +  mapping(string:mixed) find_url_data_for_url (string url, int no_default, +  RequestID id)    {    if( sizeof( urls ) == 1 && !no_default)    {    if(!mu) mu=urls[sorted_urls[0]];    URL2CONF_MSG ("%O %O Only one configuration: %O\n", this, url, mu->conf);    return mu;    } else if (!sizeof(sorted_urls)) {    URL2CONF_MSG("%O %O No active URLS!\n", this, url);    return 0;    }
Roxen.git/server/base_server/roxen.pike:1829:    URL2CONF_MSG ("%O %O sorted_urls: %O\n", this, url, urls[in]->conf);    return urls[in];    }    }       if( no_default ) {    URL2CONF_MSG ("%O %O no default\n", this, url);    return 0;    }    +  // Note: The docs for RequestID.misc->default_conf has a +  // description of this fallback procedure. +     // No host matched, or no host header was included in the request.    // Is the URL in the '*' ports?    if (!sp_fudfu)    if (Protocol p = open_ports[ name ][ 0 ][ port ] )    sp_fudfu = p->find_url_data_for_url;    if (sp_fudfu && sp_fudfu != find_url_data_for_url) -  if (mapping(string:mixed) u = sp_fudfu( url, 1 )) { +  if (mapping(string:mixed) u = sp_fudfu (url, 1, id)) {    URL2CONF_MSG ("%O %O sp_fudfu: %O\n", this, url, u->conf); -  +  if (id) id->misc->defaulted_conf = 1;    return u;    }       // No. We have to default to one of the other ports.    // It might be that one of the servers is tagged as a default server.    mapping(Configuration:int(1..1)) choices = ([]);    foreach( configurations, Configuration c )    if( c->query( "default_server" ) )    choices[c] = 1;       if( sizeof( choices ) )    {    // Pick a default server bound to this port    foreach (urls;; mapping cc)    if( choices[ cc->conf ] )    {    URL2CONF_MSG ("%O %O conf in choices: %O\n", this, url, cc->conf); -  +  if (id) id->misc->defaulted_conf = 2;    return cc;    }    }       return 0;    }       Configuration find_configuration_for_url( string url, RequestID id )    //! Given a url and requestid, try to locate a suitable configuration    //! (virtual site) for the request.    //! This interface is not at all set in stone, and might change at    //! any time.    { -  mapping(string:mixed) url_data = find_url_data_for_url (url, 0); +  mapping(string:mixed) url_data = find_url_data_for_url (url, 0, id);       if (!url_data) {    // Pick the first default server available. FIXME: This makes    // it impossible to handle the server path correctly.    foreach (configurations, Configuration c)    if (c->query ("default_server")) {    URL2CONF_MSG ("%O %O any default server: %O\n", this, url, c); -  +  if (id) id->misc->defaulted_conf = 3;    if(!c->inited)    // FIXME: We can be called from the backend thread, so    // this should be queued for a handler thread.    c->enable_all_modules();    return c;    }       // if we end up here, there is no default port at all available    // so grab the first configuration that is available at all. -  url_data = urls[sorted_urls[0]]; -  if (id) id->misc->defaulted=1; -  URL2CONF_MSG ("%O %O first in sorted_urls: %O\n", this, url, +  // We choose the last entry in sorted_urls since that's the most +  // generic one and therefore probably the best option for a +  // fallback. +  url_data = urls[sorted_urls[-1]]; +  if (id) { +  id->misc->defaulted_conf = 4; +  id->misc->defaulted=1; // Compat. +  } +  URL2CONF_MSG ("%O %O last in sorted_urls: %O\n", this, url,    url_data->conf);    }       string config_path = url_data->path;    if (config_path && id && id->adjust_for_config_path)    id->adjust_for_config_path (config_path);    Configuration c = url_data->conf;    if(!c->inited)    // FIXME: We can be called from the backend thread, so this    // should be queued for a handler thread.