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.1000 2008/12/03 14:44:44 jonasw Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.1001 2008/12/11 15:32:28 jonasw 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:1471:    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   // 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.   { -  string url_with_port = sprintf("%s://%s:%d%s", url->scheme, url->host, -  url->port, -  (sizeof(url->path)?url->path:"/")); +  // 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 ))    {    Configuration c = url_data->conf;    URL2CONF_MSG("Found config: %O\n", url_data->conf);       if ((only_this_conf && (c != only_this_conf)) || -  (sscanf (u, "%*[^*?]%*c") == 2 && // u contains * or ?. +  (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",    (only_this_conf && (c == only_this_conf)),    (!host_is_local(url->host)));    c = 0;    continue;    }   
Roxen.git/server/base_server/roxen.pike:2541:    return 0; // FAIL   }      string normalize_url(string url)   {    if (!sizeof (url - " " - "\t")) return "";       url = lower_case( url );    Standards.URI ui = Standards.URI(url);    ui->fragment = 0; -  url = (string)ui; -  url = replace( url, "/ANY", "/*" ); -  url = replace( url, "/any", "/*" ); +  if (ui->host == "any") +  ui->host = "*";    -  string host, path, protocol; -  -  sscanf( url, "%[^:]://%[^/]%s", protocol, host, path ); -  -  if (!host || !stringp(host)) return ""; -  if (!protocols[ protocol ]) return ""; -  -  int port; -  sscanf(host, "%[^:]:%d", host, port); -  -  if( !port ) -  { -  port = protocols[ protocol ]->default_port; -  url = protocol+"://"+host+":"+port+path; +  string host = ui->host; +  string protocol = ui->scheme; +  if (!host || !sizeof(host) || !protocols[protocol]) +  return ""; +  if (!ui->port) +  ui->port = protocols[protocol]->default_port; +  return (string) ui;   } -  return url; - } +       void unregister_url(string url, Configuration conf)   {    string ourl = url;    if (!sizeof(url = normalize_url(url))) return;       report_debug("Unregister "+url+"\n");       if (urls[url] && (!conf || !urls[url]->conf || (urls[url]->conf == conf)) &&    urls[url]->port)
Roxen.git/server/base_server/roxen.pike:2617:       Standards.URI ui = Standards.URI(url);    mapping opts = ([]);    string a, b;    foreach( (ui->fragment||"")/";", string x )    {    sscanf( x, "%s=%s", a, b );    opts[a]=b;    }    ui->fragment = 0; -  url = (string)ui; +        if( (int)opts->nobind )    {    report_warning(    LOC_M(61,"Not binding the port %O, disabled in configuration")+"\n", -  url ); +  (string) ui );    return 0;    } -  url = replace( url, "/ANY", "/*" ); -  url = replace( url, "/any", "/*" ); +  if (ui->host == "any") +  ui->host = "*";    -  sscanf( url, "%[^:]://%[^/]%s", protocol, host, path ); -  if (!host || !stringp(host)) -  { +  protocol = ui->scheme; +  host = ui->host; +  if (!sizeof(host || "") || !protocols[protocol]) {    report_error(LOC_M(19,"Bad URL '%s' for server `%s'")+"\n", -  url, conf->query_name()); -  return 0; +  (string) ui, conf->query_name());    } -  +  if (!ui->port) +  ui->port = protocols[protocol]->default_port; +  port = ui->port;    -  if( !protocols[ protocol ] ) -  { -  report_error(LOC_M(7,"The protocol '%s' is not available")+"\n", protocol); -  return 0; -  } +  url = (string) ui;    -  sscanf(host, "%[^:]:%d", host, port); -  -  if( !port ) -  { -  port = protocols[ protocol ]->default_port; -  url = protocol+"://"+host+":"+port+path; +  if (path = ui->path) +  if (sizeof(path)) { +  if (has_suffix(path, "/")) +  path = path[..sizeof(path) - 2]; +  } else { +  path = 0;    }    -  if( strlen( path ) && ( path[-1] == '/' ) ) -  path = path[..strlen(path)-2]; -  if( !strlen( path ) ) -  path = 0; -  +     if( urls[ url ] )    {    if( !urls[ url ]->port )    m_delete( urls, url );    else if( urls[ url ]->conf )    {    if( urls[ url ]->conf != conf )    {    report_error(LOC_M(20,    "Cannot register URL %s, "
Roxen.git/server/base_server/roxen.pike:2687:    program prot;       if( !( prot = protocols[ protocol ] ) )    {    report_error(LOC_M(21, "Cannot register URL %s, "    "cannot find the protocol %s!")+"\n",    url, protocol);    return 0;    }    -  if( !port ) -  port = prot->default_port; -  +     urls[ url ] = ([ "conf":conf, "path":path, "hostname": host ]);    urls[ ourl ] = urls[url] + ([]);    sorted_urls += ({ url });       array(string)|int(-1..0) required_hosts;       if (is_ip(host))    required_hosts = ({ host });    else if(!sizeof(required_hosts =    filter(replace(opts->ip||"", " ","")/",", is_ip)) )
Roxen.git/server/base_server/roxen.pike:4984:    string data;    if(id->misc->_load_image_called < 5)    {    // We were recursing very badly with the demo module here...    id->misc->_load_image_called++;    if(!(data=id->conf->try_get_file(f, id, 0, 0, 0, err)))    {   #ifdef THREADS    if (sscanf( f, "http://%[^/]", string host ) ||    sscanf (f, "https://%[^/]", host)) { -  if( sscanf( host, "%*s:%*d" ) != 2) -  host += ":80"; +     mapping hd = ([    "User-Agent":version(),    "Host":host,    ]);    if (mixed err = catch {    data = Protocols.HTTP.get_url_data( f, 0, hd );    })    werror (describe_backtrace (err));    }   #endif
Roxen.git/server/base_server/roxen.pike:5018:    mapping res = ([]);    if(id->misc->_load_image_called < 5)    {    // We were recursing very badly with the demo module here...    id->misc->_load_image_called++;    if(!(data=id->conf->try_get_file(f, id, 0, 0, 0, res)))    {   #ifdef THREADS    if (sscanf( f, "http://%[^/]", string host ) ||    sscanf (f, "https://%[^/]", host)) { -  if( sscanf( host, "%*s:%*d" ) != 2) -  host += ":80"; +     mapping hd = ([    "User-Agent":version(),    "Host":host,    ]);    if (mixed err = catch {    data = Protocols.HTTP.get_url_data( f, 0, hd );    })    werror (describe_backtrace (err));    }   #endif