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.1020 2009/01/17 13:50:31 mast Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.1021 2009/01/21 00:12:47 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:2500:    }    array res = gethostbyname( what );    if( res && sizeof( res[1] ) )    return Array.uniq(res[1]);       report_error(LOC_M(46, "Cannot possibly bind to %O, that host is "    "unknown. Substituting with ANY")+"\n", what);    return 0; // FAIL   }    - string normalize_url(string url) + string normalize_url(string url, void|int port_match_form) + //! Normalizes the given url to a short form. + //! + //! If @[port_match_form] is set, it normalizes to the form that is + //! used for port matching, i.e. what + //! @[roxen.Protocol.find_configuration_for_url] expects.   {    if (!sizeof (url - " " - "\t")) return "";       Standards.URI ui = Standards.URI(url); -  ui->fragment = 0; -  if (ui->host == "any" || ui->host == "ANY" || ui->host == "::") -  ui->host = "*"; +  string host = ui->host; +  +  if (lower_case (host) == "any" || host == "::") +  host = "*";    else    // FIXME: Maybe Standards.URI should do this internally? -  ui->host = lower_case(Standards.IDNA.zone_to_ascii (ui->host)); +  host = lower_case(Standards.IDNA.zone_to_ascii (host));    -  string host = ui->host; +  if (has_value (host, ":")) +  if (string h = port_match_form ? +  Protocols.IPv6.normalize_addr_basic (host) : +  Protocols.IPv6.normalize_addr_short (host)) { +  ui->host = h; +  host = "[" + h + "]"; +  } +     string protocol = ui->scheme; -  if (!host || !sizeof(host) || !protocols[protocol]) +  if (host == "" || !protocols[protocol])    return ""; -  if (!ui->port) -  ui->port = protocols[protocol]->default_port; +  +  if (port_match_form) { +  int port = ui->port || protocols[protocol]->default_port; +  +  string path = ui->path; +  if (path) { +  if (has_suffix(path, "/")) +  path = path[..<1]; +  } +  else +  path = ""; +  +  return sprintf ("%s://%s:%d%s/", protocol, host, port, +  // If the path is set it's assumed to begin with a +  // "/", but not end with one. +  path); +  } +  +  else { +  ui->fragment = 0;    return (string) ui;    } -  + }      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:2560:   void sort_urls()   {    sorted_urls = indices( urls );    sort( map( map( sorted_urls, strlen ), `-), sorted_urls );   }      int register_url( string url, Configuration conf )   {    string ourl = url;    if (!sizeof (url - " " - "\t")) return 1; -  string protocol; -  string host; -  int port; -  string path; +        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; +        if( (int)opts->nobind )    {    report_warning(    LOC_M(61,"Not binding the port %O, disabled in configuration")+"\n",    (string) ui );    return 0;    } -  if (lower_case (ui->host) == "any" || ui->host == "::") -  host = "*"; -  else -  // FIXME: Maybe Standards.URI should do this internally? -  host = lower_case (Standards.IDNA.zone_to_ascii (ui->host)); +     -  protocol = ui->scheme; +  url = normalize_url (url, 1); +  ui = Standards.URI (url); +  +  string protocol = ui->scheme; +  string host = ui->host;    if (host == "" || !protocols[protocol]) { -  report_error(LOC_M(19,"Bad URL '%s' for server `%s'")+"\n", -  (string) ui, conf->query_name()); +  report_error(LOC_M(19,"Bad URL %O for server `%s'")+"\n", +  ourl, conf->query_name());    }    -  port = ui->port || protocols[protocol]->default_port; +  int port = ui->port || protocols[protocol]->default_port;    -  if (path = ui->path) { +  string path = ui->path;    if (has_suffix(path, "/"))    path = path[..<1];    if (path == "") path = 0; -  } +     -  { -  string h; -  if (has_value (host, ":")) { -  h = Protocols.IPv6.normalize_addr_basic (host); -  if (!h) -  report_error ( -  LOC_M(0, "Bad IPv6 address in '%s' for server '%s'") + "\n", -  (string) ui, conf->query_name()); -  h = "[" + h + "]"; -  } -  else -  h = host; -  url = sprintf ("%s://%s:%d%s/", protocol, h, port, -  // If the path is set it's assumed to begin with a -  // "/", but not end with one. -  path || ""); -  } -  +     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, "