Roxen.git / server / base_server / configuration.pike

version» Context lines:

Roxen.git/server/base_server/configuration.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2009, Roxen IS.   //      // @appears Configuration   //! A site's main configuration    - constant cvs_version = "$Id: configuration.pike,v 1.680 2009/06/24 11:38:00 mast Exp $"; + constant cvs_version = "$Id: configuration.pike,v 1.681 2009/10/31 19:37:33 mast Exp $";   #include <module.h>   #include <module_constants.h>   #include <roxen.h>   #include <request_trace.h>   #include <timers.h>      #define CATCH(P,X) do{mixed e;if(e=catch{X;})report_error("While "+P+"\n"+describe_backtrace(e));}while(0)      // Tell Pike.count_memory this is global.   constant pike_cycle_depth = 0;
Roxen.git/server/base_server/configuration.pike:638:    registered_urls = ({});   }      private int num_modules = 0;   #ifdef THREADS   private Thread.Condition modules_stopped = Thread.Condition();   private Thread.Mutex modules_stopped_mutex = Thread.Mutex();   #endif   private void safe_stop_module (RoxenModule mod, string desc)   { -  if (mixed err = catch (mod && mod->stop && mod->stop())) +  if (mixed err = catch (mod && mod->stop && +  call_module_func_with_cbs (mod, "stop")))    report_error ("While stopping " + desc + ": " + describe_backtrace (err));   #ifdef THREADS    Thread.MutexKey lock = modules_stopped_mutex->lock();    if (!--num_modules)    modules_stopped->signal();    lock = 0;   #else    --num_modules;   #endif   }
Roxen.git/server/base_server/configuration.pike:3367:    SNMP.set_owner(mib, this_object());    prot->mib->merge(mib);    }    }       if (retrieve ("EnabledModules", this)["config_filesystem#0"])    return 1; // Signal that this is the admin UI config.    return 0;   }    + // ([func: ([mod_name: ({cb, cb, ...})])]) + protected mapping(string: +  mapping(string: +  array(function(RoxenModule,mixed...:void)))) +  module_pre_callbacks = ([]), module_post_callbacks = ([]); +  + void add_module_pre_callback (string mod_name, string func, +  function(RoxenModule,mixed...:void) cb) + { +  ASSERT_IF_DEBUG ((<"start", "stop">)[func]); +  mapping(string:array(function(RoxenModule,mixed...:void))) func_cbs = +  module_pre_callbacks[func] || (module_pre_callbacks[func] = ([])); +  if (func_cbs[mod_name] && has_value (func_cbs[mod_name], cb)) +  return; +  func_cbs[mod_name] += ({cb}); + } +  + void delete_module_pre_callback (string mod_name, string func, +  function(RoxenModule,mixed...:void) cb) + { +  if (mapping(string:array(function(RoxenModule,mixed...:void))) func_cbs = +  module_pre_callbacks[func]) +  if (func_cbs[mod_name]) +  func_cbs[mod_name] -= ({cb}); + } +  + void add_module_post_callback (string mod_name, string func, +  function(RoxenModule,mixed...:void) cb) + { +  ASSERT_IF_DEBUG ((<"start", "stop">)[func]); +  mapping(string:array(function(RoxenModule,mixed...:void))) func_cbs = +  module_post_callbacks[func] || (module_post_callbacks[func] = ([])); +  if (func_cbs[mod_name] && has_value (func_cbs[mod_name], cb)) +  return; +  func_cbs[mod_name] += ({cb}); + } +  + void delete_module_post_callback (string mod_name, string func, +  function(RoxenModule,mixed...:void) cb) + { +  if (mapping(string:array(function(RoxenModule,mixed...:void))) func_cbs = +  module_post_callbacks[func]) +  if (func_cbs[mod_name]) +  func_cbs[mod_name] -= ({cb}); + } +  + void call_module_func_with_cbs (RoxenModule mod, string func, mixed... args) + { +  string mod_name; +  +  if (mapping(string:array(function(RoxenModule,mixed...:void))) func_cbs = +  module_pre_callbacks[func]) { +  sscanf (mod->module_local_id(), "%[^#]", mod_name); +  array(function(RoxenModule,mixed...:void)) cbs; +  if (array(function(RoxenModule,mixed...:void)) a = func_cbs[mod_name]) { +  func_cbs[mod_name] = (a -= ({0})); +  cbs = a; +  } +  if (array(function(RoxenModule,mixed...:void)) a = func_cbs[0]) { +  func_cbs[0] = (a -= ({0})); +  if (cbs) cbs += a; else cbs = a; +  } +  if (cbs) { +  foreach (cbs, function(RoxenModule,mixed...:void) cb) { + #ifdef MODULE_CB_DEBUG +  werror ("Calling callback before %O->%s: %O\n", mod, func, cb); + #endif +  if (mixed err = catch (cb (mod, @args))) +  report_error ("Error calling callback %O before %O->%s:\n%s\n", +  cb, mod, func, describe_backtrace (err)); +  } +  } +  } +  +  // Exceptions thrown here are the responsibility of the caller. + #ifdef MODULE_CB_DEBUG +  werror ("Calling %O->%s (%s)\n", mod, func, +  map (args, lambda (mixed arg) +  {return sprintf ("%O", arg);}) * ", "); + #endif +  mod[func] (@args); +  +  if (mapping(string:array(function(RoxenModule,mixed...:void))) func_cbs = +  module_post_callbacks[func]) { +  if (!mod_name) +  sscanf (mod->module_local_id(), "%[^#]", mod_name); +  array(function(RoxenModule,mixed...:void)) cbs; +  if (array(function(RoxenModule,mixed...:void)) a = func_cbs[mod_name]) { +  func_cbs[mod_name] = (a -= ({0})); +  cbs = a; +  } +  if (array(function(RoxenModule,mixed...:void)) a = func_cbs[0]) { +  func_cbs[0] = (a -= ({0})); +  if (cbs) cbs += a; else cbs = a; +  } +  if (cbs) { +  foreach (cbs, function(RoxenModule,mixed...:void) cb) { + #ifdef MODULE_CB_DEBUG +  werror ("Calling callback after %O->%s: %O\n", mod, func, cb); + #endif +  if (mixed err = catch (cb (mod, @args))) +  report_error ("Error calling callback %O after %O->%s:\n%s\n", +  cb, mod, func, describe_backtrace (err)); +  } +  } +  } + } +    void save_me()   {    save_one( 0 );   }      void save(int|void all)   //! Save this configuration. If all is included, save all configuration   //! global variables as well, otherwise only all module variables.   {    if(all)
Roxen.git/server/base_server/configuration.pike:3413:    start(2);    return 1;    }    string q = otomod[ o ];    if( !q )    error("Invalid module");       store(q, o->query(), 0, this_object());    invalidate_cache();    mixed error; -  if( error = catch( o->start(2, this_object(), 0) ) ) +  if( o->start && +  (error = catch( call_module_func_with_cbs (o, "start", 2, this, 0) )) )    {    if( objectp(error ) )    error = (array)error;    if( sizeof(error)>1 && arrayp( error[1] ) )    {    int i;    for( i = 0; i<sizeof( error[1] ); i++ )    if( error[1][i][2] == save_one )    break;    error[1] = error[1][i+1..];
Roxen.git/server/base_server/configuration.pike:3604:   #endif    got_no_delayed_load = -1;    roxen->bootstrap_info->set (0);    return module[id];    }    }       if(module[id] && module[id] != me)    {    if( module[id]->stop ) { -  if (err = catch( module[id]->stop() )) { +  if (err = catch( call_module_func_with_cbs (module[id], "stop") )) {    string bt=describe_backtrace(err);    report_error("disable_module(): " +    LOC_M(44, "Error while disabling module %s%s"),    descr, (bt ? ":\n"+bt : "\n"));    }    }    }       me->set_configuration( this_object() );   
Roxen.git/server/base_server/configuration.pike:3943:      void call_high_start_callbacks (RoxenModule me, ModuleInfo moduleinfo,    void|int newly_added)   {    // This is icky, but I don't know if it's safe to remove. /mast    if(!me) return;    if(!moduleinfo) return;       mixed err;    if((me->start) && -  (err = catch( me->start(0, this_object(), newly_added) ) ) ) +  (err = catch( call_module_func_with_cbs (me, "start", +  0, this, newly_added) ) ) )    {   #ifdef MODULE_DEBUG    if (enable_module_batch_msgs)    report_debug("\bERROR\n");   #endif    string bt=describe_backtrace(err);    report_error(LOC_M(41, "Error while initiating module copy of %s%s"),    moduleinfo->get_name(), (bt ? ":\n"+bt : "\n"));    got_no_delayed_load = -1;    }
Roxen.git/server/base_server/configuration.pike:4117:       if(!me)    {    report_error("disable_module(): " +    LOC_M(43, "Failed to disable module \"%s\".\n"),    descr);    return 0;    }       if(me->stop) -  if (mixed err = catch (me->stop())) { +  if (mixed err = catch (call_module_func_with_cbs (me, "stop"))) {    string bt=describe_backtrace(err);    report_error("disable_module(): " +    LOC_M(44, "Error while disabling module %s%s"),    descr, (bt ? ":\n"+bt : "\n"));    }      #ifdef MODULE_DEBUG    report_debug("Disabling "+descr+"\n");   #endif