> No... the default server is still a server. But you make an interesting point, that > certain percolation occurs in the post config. I suppose I would want that to > happen before my handlers dealt with the per-vhost settings, and I would not > want the changes I make to that global server to percolate any longer in the > host_init phase. So running the post config, then the host init phases makes > sense for that paradigm.
cool. just to keep up, new patches attached. > But let's imagine a scenario of dynamic vhosts, al la htaccess. It would actually > be quite cool in one thread to create such a dynamic host (propagate from some > given vhost for example.) This host init hook would still be run against the thread > specific dynamic server record. We could get away with some really cool things > that way :) Discuss ... you'd need a way to direct requests directly to that specific thread, though, right? anyway, what kind of cool things? I can see some advantage to this oven in prefork, where you might want to dedicate a pool of children to specific clients, but I don't really see the threaded advantages. but I generally don't get threaded environments anyway :) --Geoff
Index: include/http_config.h =================================================================== RCS file: /home/cvspublic/httpd-2.0/include/http_config.h,v retrieving revision 1.103 diff -u -r1.103 http_config.h --- include/http_config.h 31 Oct 2003 22:00:38 -0000 1.103 +++ include/http_config.h 23 Dec 2003 16:49:03 -0000 @@ -1001,6 +1001,17 @@ /** + * Run the host_init function for each module + * @param pconf The config pool + * @param plog The logging streams pool + * @param ptemp The temporary pool + * @param s The (virtual) host to initialize + * @return OK or DECLINED on success anything else is a error + */ +AP_DECLARE_HOOK(int,host_init,(apr_pool_t *pconf,apr_pool_t *plog, + apr_pool_t *ptemp,server_rec *s)) + +/** * Run the post_config function for each module * @param pconf The config pool * @param plog The logging streams pool Index: server/main.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/main.c,v retrieving revision 1.149 diff -u -r1.149 main.c --- server/main.c 10 Dec 2003 13:43:14 -0000 1.149 +++ server/main.c 23 Dec 2003 16:49:03 -0000 @@ -444,6 +444,7 @@ const char *temp_error_log = NULL; process_rec *process; server_rec *server_conf; + server_rec *s; /* host-specific server_rec */ apr_pool_t *pglobal; apr_pool_t *pconf; apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */ @@ -655,6 +656,14 @@ destroy_and_exit_process(process, 1); } + for (s = server_conf; s; s = s->next) { + if ( ap_run_host_init(pconf, plog, ptemp, s) != OK) { + ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, + 0, NULL, "Unable to initialize hosts\n"); + destroy_and_exit_process(process, 1); + } + } + apr_pool_destroy(ptemp); for (;;) { @@ -698,6 +707,14 @@ ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0, NULL, "Configuration Failed\n"); destroy_and_exit_process(process, 1); + } + + for (s = server_conf; s; s = s->next) { + if ( ap_run_host_init(pconf, plog, ptemp, s) != OK) { + ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, + 0, NULL, "Unable to initialize hosts\n"); + destroy_and_exit_process(process, 1); + } } apr_pool_destroy(ptemp); Index: server/config.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/server/config.c,v retrieving revision 1.167 diff -u -r1.167 config.c --- server/config.c 11 Oct 2003 06:37:45 -0000 1.167 +++ server/config.c 23 Dec 2003 16:49:03 -0000 @@ -109,6 +109,7 @@ APR_HOOK_STRUCT( APR_HOOK_LINK(header_parser) APR_HOOK_LINK(pre_config) + APR_HOOK_LINK(host_init) APR_HOOK_LINK(post_config) APR_HOOK_LINK(open_logs) APR_HOOK_LINK(child_init) @@ -124,6 +125,11 @@ (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp), (pconf, plog, ptemp), OK, DECLINED) + +AP_IMPLEMENT_HOOK_RUN_ALL(int, host_init, + (apr_pool_t *pconf, apr_pool_t *plog, + apr_pool_t *ptemp, server_rec *s), + (pconf, plog, ptemp, s), OK, DECLINED) AP_IMPLEMENT_HOOK_RUN_ALL(int, post_config, (apr_pool_t *pconf, apr_pool_t *plog,
Index: modules/experimental/mod_example.c =================================================================== RCS file: /home/cvspublic/httpd-2.0/modules/experimental/mod_example.c,v retrieving revision 1.44 diff -u -r1.44 mod_example.c --- modules/experimental/mod_example.c 13 Dec 2003 15:41:33 -0000 1.44 +++ modules/experimental/mod_example.c 23 Dec 2003 16:49:21 -0000 @@ -859,8 +859,28 @@ } /* - * This routine is called to perform any module-specific fixing of header - * fields, et cetera. It is invoked just before any content-handler. + * This routine is called to do virtual host initialization. + * It is invoked just after the post_config phase. + * + * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the + * server will still call any remaining modules with an handler for this + * phase. + */ +static int x_host_init(apr_pool_t *pconf, apr_pool_t *plog, + apr_pool_t *ptemp, server_rec *s) +{ + /* + * Log the call and exit. + */ + trace_add(s, NULL, NULL, + apr_psprintf(ptemp, "x_host_init() for %s host %s", + s->is_virtual ? "virtual" : "", + s->server_hostname)); + return OK; +} +/* + * This routine is called to perform module initialization routines. + * It is invoked just after the open_logs phase. * * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the * server will still call any remaining modules with an handler for this @@ -872,13 +892,13 @@ /* * Log the call and exit. */ - trace_add(NULL, NULL, NULL, "x_post_config()"); + trace_add(s, NULL, NULL, "x_post_config()"); return OK; } /* * This routine is called to perform any module-specific log file - * openings. It is invoked just before the post_config phase + * openings. It is invoked just before the post_config phase. * * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the * server will still call any remaining modules with an handler for this @@ -1304,8 +1324,9 @@ static void x_register_hooks(apr_pool_t *p) { ap_hook_pre_config(x_pre_config, NULL, NULL, APR_HOOK_MIDDLE); - ap_hook_post_config(x_post_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_open_logs(x_open_logs, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_post_config(x_post_config, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_host_init(x_host_init, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_child_init(x_child_init, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_handler(x_handler, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_quick_handler(x_quick_handler, NULL, NULL, APR_HOOK_MIDDLE);
Index: docs/manual/developer/modules.html.en =================================================================== RCS file: /home/cvspublic/httpd-2.0/docs/manual/developer/modules.html.en,v retrieving revision 1.13 diff -u -r1.13 modules.html.en --- docs/manual/developer/modules.html.en 29 May 2003 16:12:50 -0000 1.13 +++ docs/manual/developer/modules.html.en 23 Dec 2003 16:55:31 -0000 @@ -206,6 +206,9 @@ <dt><code>ap_hook_open_logs</code></dt> <dd>open any specified logs</dd> + <dt><code>ap_hook_host_init</code></dt> + <dd>initialize each (virtual) host</dd> + <dt><code>ap_hook_auth_checker</code></dt> <dd>check if the resource requires authorization</dd> Index: docs/manual/developer/modules.xml =================================================================== RCS file: /home/cvspublic/httpd-2.0/docs/manual/developer/modules.xml,v retrieving revision 1.4 diff -u -r1.4 modules.xml --- docs/manual/developer/modules.xml 12 Apr 2003 15:04:45 -0000 1.4 +++ docs/manual/developer/modules.xml 23 Dec 2003 16:55:31 -0000 @@ -192,6 +192,9 @@ <dt><code>ap_hook_open_logs</code></dt> <dd>open any specified logs</dd> + <dt><code>ap_hook_host_init</code></dt> + <dd>initialize each (virtual) host</dd> + <dt><code>ap_hook_auth_checker</code></dt> <dd>check if the resource requires authorization</dd>