Branch: Tag:

1999-10-10

1999-10-10 10:37:53 by Per Hedbor <ph@opera.com>

Some cleanups

Rev: server/base_server/roxen.pike:1.334

1:   /* -  * $Id: roxen.pike,v 1.333 1999/10/09 21:30:33 grubba Exp $ +  * $Id: roxen.pike,v 1.334 1999/10/10 10:37:53 per Exp $    *    * The Roxen Challenger main program.    *
7:    */      // ABS and suicide systems contributed freely by Francesco Chemolli - constant cvs_version="$Id: roxen.pike,v 1.333 1999/10/09 21:30:33 grubba Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.334 1999/10/10 10:37:53 per Exp $";      object backend_thread;   object argcache;
539:   }   #endif /* THREADS */    -  - #if 0 - /* Grubbas */ -  - /* -  * Port DB stuff. -  */ -  - // ([ "prot" : ([ "ip" : ([ port : protocol_handler, ]), ]), ]) - static mapping(string:mapping(string:mapping(int:object))) handler_db = ([]); -  - // ([ "prot" : protocol_program, ]) - static mapping(string:program) port_db = ([]); -  - // Is there a handler for this port? - object low_find_handler(string prot, string ip, int port) + class fallback_redirect_request   { -  mixed res; -  return((res = handler_db[prot]) && (res = res[ip]) && res[port]); - } -  - // Register a handler for a port. - void register_handler(string prot, string ip, int port, object handler) - { -  mapping m; -  if (m = handler_db[prot]) { -  mapping mm; -  if (mm = m[ip]) { -  // FIXME: What if mm[port] already exists? -  mm[port] = handler; -  } else { -  m[ip] = ([ port : handler ]); -  } -  } else { -  handler_db[prot] = ([ ip : ([ port : handler ]) ]); -  } - } -  - object find_handler(string prot, string ip, int port) - { -  object handler = low_find_handler(prot, ip, port); -  -  if (!handler) { -  program prog = port_db[prot]; -  if (!prog) { -  return 0; -  } -  mixed err = catch { -  handler = prog(prot, ip, port); -  }; -  if (err) { -  report_error(LOCALE->failed_to_open_port("?", -  sprintf("%s://%s:%d/", -  prot, ip, port), -  describe_backtrace(err))); -  } else { -  register_handler(prot, ip, port, handler); -  } -  } -  return handler; - } - #endif -  -  - #if 1 -  - /* Pers */ -  - class fallback_redirect_request { +     string in = "";    string out;    string default_prefix;
821: Inside #if 1
   return res;    }    } -  +  if( all_options[""] )    return all_options[""][option]; -  +  return 0;    }       void create( int pn, string i )
1188:    if( what == "*" || lower_case(what) == "any" )    return 0;    -  if( !strlen( replace( what, "01234567890."/"", (" "*11)/"" ) ) ) +  if( is_ip( what ) )    return ({ what });       array res = gethostbyname( what );
1199:    else    return Array.uniq(res[1][0] + Array.filter(res[2],    lambda(string ip) { -  return !strlen( replace( what, "01234567890."/"", (" "*11)/"" ) ); +  return is_ip( what );    }));   }   
1318:   }       - #endif -  +    object find_configuration( string name )   {    name = replace( lower_case( name )-" ", "/", "-" );
2340:      object enable_configuration(string name)   { -  object cf = Configuration(name); +  object cf = Configuration( name );    configurations += ({ cf }); -  report_notice(LOCALE->enabled_server(name)); -  +  report_notice( LOCALE->enabled_server(name) );    return cf;   }   
2351:   void enable_configurations()   {    array err; -  +     configurations = ({}); -  +     foreach(list_all_configurations(), string config) -  { -  if(err=catch { enable_configuration(config)->start(); }) -  perror("Error while loading configuration "+config+":\n"+ +  if(err=catch( enable_configuration(config)->start() )) +  report_error("Error while loading configuration "+config+":\n"+    describe_backtrace(err)+"\n"); -  }; +    }         void enable_configurations_modules()   { -  +  mixed err; +     foreach(configurations, object config) -  { -  array err; -  if(err=catch { config->enable_all_modules(); }) -  perror("Error while loading modules in configuration "+config->name+":\n"+ -  describe_backtrace(err)+"\n"); -  }; +  if(err=catch( config->enable_all_modules() )) +  report_error("Error while loading modules in configuration "+ +  config->name+":\n"+describe_backtrace(err)+"\n");   }      array(int) invert_color(array color )
2614:    return 0;   }    -  -  +    // do the chroot() call. This is not currently recommended, since   // roxen dynamically loads modules, all module files must be   // available at the new location.
2883: Inside #if defined(THREADS)
   start_handler_threads();    catch( this_thread()->set_name("Backend") );    backend_thread = this_thread(); - #if efun(thread_set_concurrency) -  thread_set_concurrency(QUERY(numthreads)+1); - #endif +    #endif /* THREADS */       // Signals which cause a restart (exitcode != 0) -  foreach( ({ "SIGINT", "SIGTERM" }), string sig) { -  catch { signal(signum(sig), exit_when_done); }; -  } -  catch { signal(signum("SIGHUP"), reload_all_configurations); }; -  // Signals which cause a shutdown (exitcode == 0) -  foreach( ({ }), string sig) { -  catch { signal(signum(sig), shutdown); }; -  } +  foreach( ({ "SIGINT", "SIGTERM" }), string sig) +  catch( signal(signum(sig), exit_when_done) ); +  +  catch( signal(signum("SIGHUP"), reload_all_configurations) ); +     // Signals which cause Roxen to dump the thread state -  foreach( ({ "SIGUSR1", "SIGUSR2", "SIGTRAP" }), string sig) { -  catch { signal(signum(sig), describe_all_threads); }; -  } +  foreach( ({ "SIGUSR1", "SIGUSR2", "SIGTRAP" }), string sig) +  catch( signal(signum(sig), describe_all_threads) );      #ifdef __RUN_TRACE    trace(1);
2955:   {    return (replace(s,"0123456789."/"",({""})*11) == "");   } -  +