Branch: Tag:

1999-02-15

1999-02-15 23:19:03 by Per Hedbor <ph@opera.com>

Added support for transparent virtual hosting. Added support for comments in configuration files. Moved handle_request from http.pike to this module (handle_request is the function that now includes the virtual hosting support)

Rev: server/base_server/configuration.pike:1.179

1: - string cvs_version = "$Id: configuration.pike,v 1.178 1999/02/15 22:36:15 marcus Exp $"; + string cvs_version = "$Id: configuration.pike,v 1.179 1999/02/15 23:19:03 per Exp $";   #include <module.h>   #include <roxen.h>   
7:   mapping profile_map = ([]);   #endif    - #define CATCH(X) do { mixed err; if(err = catch{X;}) report_error(describe_backtrace(err)); } while(0) + #define CATCH(P,X) do{mixed e;if(e=catch{X;})report_error("While "+P+"\n"+describe_backtrace(e));}while(0)      // Locale support...   #define LOCALE LOW_LOCALE->base_server
44:    */   mapping variables = ([]);    +  +  + string get_doc_for( string region, string variable ) + { +  object module; +  if(variable[0] == '_') +  return 0; +  if((int)reverse(region)) +  return 0; +  if(module = find_module( region )) +  { +  if(module->variables[variable]) +  return module->variables[variable][VAR_NAME]+ +  "\n"+module->variables[ variable ][ VAR_DOC_STR ]; +  } +  if(variables[ variable ]) +  return variables[variable][VAR_NAME]+ +  "\n"+variables[ variable ][ VAR_DOC_STR ]; + } +    public mixed query(string var)   {    if(var && variables[var])
185:       void stop()    { -  foreach(url_modules, object m) CATCH(m->stop && m->stop()); -  foreach(logger_modules, object m) CATCH(m->stop && m->stop()); -  foreach(filter_modules, object m) CATCH(m->stop && m->stop()); -  foreach(location_modules, object m) CATCH(m->stop && m->stop()); -  foreach(last_modules, object m) CATCH(m->stop && m->stop()); -  foreach(first_modules, object m) CATCH(m->stop && m->stop()); -  foreach(indices(provider_modules), object m) CATCH(m->stop && m->stop()); +  foreach(url_modules, object m) +  CATCH("stopping url modules",m->stop && m->stop()); +  foreach(logger_modules, object m) +  CATCH("stopping logging modules",m->stop && m->stop()); +  foreach(filter_modules, object m) +  CATCH("stopping filter modules",m->stop && m->stop()); +  foreach(location_modules, object m) +  CATCH("stopping location modules",m->stop && m->stop()); +  foreach(last_modules, object m) +  CATCH("stopping last modules",m->stop && m->stop()); +  foreach(first_modules, object m) +  CATCH("stopping first modules",m->stop && m->stop()); +  foreach(indices(provider_modules), object m) +  CATCH("stopping provider modules",m->stop && m->stop());    }   }   
325:   // Call stop in all modules.   void stop()   { -  CATCH(types_module && types_module->stop && types_module->stop()); -  CATCH(auth_module && auth_module->stop && auth_module->stop()); -  CATCH(dir_module && dir_module->stop && dir_module->stop()); -  for(int i=0; i<10; i++) CATCH(pri[i] && pri[i]->stop && pri[i]->stop()); +  CATCH("stopping type modules", +  types_module && types_module->stop && types_module->stop()); +  CATCH("stopping auth module", +  auth_module && auth_module->stop && auth_module->stop()); +  CATCH("stopping directory module", +  dir_module && dir_module->stop && dir_module->stop()); +  for(int i=0; i<10; i++) +  CATCH("stopping priority group", +  pri[i] && pri[i]->stop && pri[i]->stop());   }      public string type_from_filename( string file, int|void to )
643:    if(strlen(logfile))    {    do { - #ifndef THREADS -  object privs = Privs(LOCALE->opening_logfile(logfile)); - #endif + // #ifndef THREADS + // object privs = Privs(LOCALE->opening_logfile(logfile)); + // #endif    object lf=open( logfile, "wac"); - #if efun(chmod) - #if efun(geteuid) -  if(geteuid() != getuid()) catch {chmod(logfile,0666);}; - #endif - #endif + // #if efun(chmod) + // #if efun(geteuid) + // if(geteuid() != getuid()) catch {chmod(logfile,0666);}; + // #endif + // #endif    if(!lf) {    mkdirhier(logfile);    if(!(lf=open( logfile, "wac"))) {
782:    (string)request_id->method,    http_encode_string((string)request_id->not_query +    ((request_id->misc && -  request_id->misc->path_info) || "")), +  request_id->misc->path_info) || "") + +  ((request_id->query && +  strlen(request_id->query))? +  "?"+request_id->query:"")),    (string)request_id->prot,    (string)(file->error||200),    unsigned_short_to_bin(file->error||200),
1095:      mapping (mixed:function|int) locks = ([]);    - public mapping|int get_file(object id, int|void no_magic); -  +    #ifdef THREADS   // import Thread;   
1215:       return res;   } -  +    mapping|int low_get_file(object id, int|void no_magic)   {   #ifdef MODULE_LEVEL_SECURITY
1587:    return ([ "file":fid, ]);    }    if(!fid) +  {    TRACE_LEAVE(LOCALE->returned_not_found()); -  +  }    else    TRACE_LEAVE(LOCALE->returning_data());    return fid;   }    -  +  + mixed handle_request( object id ) + { +  function funp; +  mixed file; +  +  if(roxen->find_site_for( id ) != this_object()) +  return id->conf->handle_request(id); +  foreach(first_modules(id), funp) +  { +  if(file = funp( id )) +  break; +  if(id->conf != this_object) +  return id->conf->handle_request(id); +  } +  +  file = get_file(id); +  +  if(!mappingp(file)) +  { +  mixed ret; +  foreach(last_modules(id), funp) if(ret = funp(id)) break; +  if (ret == 1) +  return handle_request(id); +  file = ret; +  } +  return file; + } +    mixed get_file(object id, int|void no_magic)   {    mixed res, res2;
1621:    string loc;    array dir = ({ }), tmp;    array | mapping d; + // if(roxen->find_site_for( id ) != this_object()) + // return id->conf->find_dir( file, id );    TRACE_ENTER(LOCALE->list_directory(file), 0); -  file=replace(file, "//", "/"); + // file=replace(file, "//", "/");       if(file[0] != '/')    file = "/" + file;
1855:    function funp;    mapping file;    +  if(roxen->find_site_for( id ) != this_object()) +  return id->open_file( fname, mode, id ); +     id->not_query = fname; -  +     foreach(oc->first_modules(), funp)    if(file = funp( id ))    break;
1904:    ({fname,query("MyWorldLocation")})));       id->not_query = oq; +     return ({ 0, file });    }   
1926:    mapping(string:array(mixed)) dir = ([]);    mixed d, tmp;    +  +  if(roxen->find_site_for( id ) != this_object()) +  return id->find_dir_stat( file, id ); +     file=replace(file, "//", "/");       if(file[0] != '/')