LMPX.COM |
Home | Linux | Mysql | PHP | XML | ||
|
|
|||
From: jhorwitz@cvs.perl.org Date: Sun Sep 21 11:23:28 2008 Subject: [svn:mod_parrot] r446 - in mod_parrot/branches/hll-modules: . include languages/perl6/lib lib/Apache lib/ModParrot/HLL src
Author: jhorwitz
Date: Sun Sep 21 10:23:27 2008
New Revision: 446
Modified:
mod_parrot/branches/hll-modules/call_list.txt
mod_parrot/branches/hll-modules/include/mod_parrot.h
mod_parrot/branches/hll-modules/include/modparrot_config.h
mod_parrot/branches/hll-modules/languages/perl6/lib/mod_perl6.pm
mod_parrot/branches/hll-modules/lib/Apache/Module.pir
mod_parrot/branches/hll-modules/lib/ModParrot/HLL/pir.pir
mod_parrot/branches/hll-modules/src/module.c
mod_parrot/branches/hll-modules/src/nci.c
Log:
implement hook bitmap so HLLs register only the hooks they need
Modified: mod_parrot/branches/hll-modules/call_list.txt
==============================================================================
--- mod_parrot/branches/hll-modules/call_list.txt (original)
+++ mod_parrot/branches/hll-modules/call_list.txt Sun Sep 21 10:23:27 2008
@@ -18,5 +18,5 @@
v pit
v ptt
v Jtiiipt
-p JttP
+p JttPP
P Jtpi
Modified: mod_parrot/branches/hll-modules/include/mod_parrot.h
==============================================================================
--- mod_parrot/branches/hll-modules/include/mod_parrot.h (original)
+++ mod_parrot/branches/hll-modules/include/mod_parrot.h Sun Sep 21 10:23:27 2008
@@ -82,6 +82,6 @@
modparrot_context *modparrot_startup(apr_pool_t *, server_rec *, Parrot_Interp);
void modparrot_load_file(Parrot_Interp, server_rec *, const char *);
module *modparrot_add_module(Parrot_Interp, apr_pool_t *, const char *, char *,
- Parrot_PMC);
+ Parrot_PMC, Parrot_PMC);
#endif /* _MODPARROT_H */
Modified: mod_parrot/branches/hll-modules/include/modparrot_config.h
==============================================================================
--- mod_parrot/branches/hll-modules/include/modparrot_config.h (original)
+++ mod_parrot/branches/hll-modules/include/modparrot_config.h Sun Sep 21 10:23:27 2008
@@ -54,9 +54,32 @@
# define MP_INIT_CMD_FLAG(c) (c.func = modparrot_module_cmd_flag)
#endif /* (AP_HAVE_DESIGNATED_INITIALIZER) || defined(DOXYGEN) */
-/* number of apache hooks we support */
-/* XXX can we obtain this number dynamically? */
-#define MODPARROT_NUM_HOOKS 20
+/* hook types */
+enum modparrot_hooks {
+ /* server scope */
+ MP_HOOK_OPEN_LOGS,
+ MP_HOOK_POST_CONFIG,
+ MP_HOOK_CHILD_INIT,
+ MP_HOOK_PRE_CONNECTION,
+ MP_HOOK_PROCESS_CONNECTION,
+ MP_HOOK_POST_READ_REQUEST,
+ MP_HOOK_MAP_TO_STORAGE,
+ MP_HOOK_TRANS,
+
+ /* directory scope */
+ MP_HOOK_INPUT_FILTER,
+ MP_HOOK_HEADER_PARSER,
+ MP_HOOK_ACCESS,
+ MP_HOOK_AUTHEN,
+ MP_HOOK_AUTHZ,
+ MP_HOOK_RESPONSE,
+ MP_HOOK_OUTPUT_FILTER,
+ MP_HOOK_TYPE,
+ MP_HOOK_FIXUP,
+ MP_HOOK_LOG,
+ MP_HOOK_CLEANUP,
+ MP_HOOK_LAST
+};
struct modparrot_module_info
{
@@ -65,7 +88,7 @@
Parrot_PMC dir_create_sub;
Parrot_PMC dir_merge_sub;
char *namespace; /* can be a real namespace or the name of an HLL */
- short hooks[MODPARROT_NUM_HOOKS]; /* index is from modparrot_hooks enum */
+ short hooks[MP_HOOK_LAST]; /* index is from modparrot_hooks enum */
};
typedef struct modparrot_module_info modparrot_module_info;
@@ -101,33 +124,6 @@
* typedef struct modparrot_dir_config modparrot_dir_config;
*/
-/* hook types */
-enum modparrot_hooks {
- /* server scope */
- MP_HOOK_OPEN_LOGS,
- MP_HOOK_CHILD_INIT,
- MP_HOOK_CHILD_EXIT,
- MP_HOOK_POST_CONFIG,
- MP_HOOK_PRE_CONNECTION,
- MP_HOOK_PROCESS_CONNECTION,
- MP_HOOK_MAP_TO_STORAGE,
- MP_HOOK_TRANS,
- MP_HOOK_POST_READ_REQUEST,
-
- /* directory scope */
- MP_HOOK_INPUT_FILTER,
- MP_HOOK_OUTPUT_FILTER,
- MP_HOOK_HEADER_PARSER,
- MP_HOOK_RESPONSE,
- MP_HOOK_ACCESS,
- MP_HOOK_AUTHEN,
- MP_HOOK_AUTHZ,
- MP_HOOK_TYPE,
- MP_HOOK_FIXUP,
- MP_HOOK_LOG,
- MP_HOOK_CLEANUP
-};
-
struct modparrot_module_cmd_data
{
module *modp;
Modified: mod_parrot/branches/hll-modules/languages/perl6/lib/mod_perl6.pm
==============================================================================
--- mod_parrot/branches/hll-modules/languages/perl6/lib/mod_perl6.pm (original)
+++ mod_parrot/branches/hll-modules/languages/perl6/lib/mod_perl6.pm Sun Sep 21 10:23:27 2008
@@ -21,7 +21,6 @@
our @preloaded_modules = ();
our @postconfig_requires = ();
our %loaded_modules;
-
sub load($handler)
{
unless (%loaded_modules{$handler}) {
@@ -46,6 +45,10 @@
{
my $r = $ctx.request_rec();
+ unless ($r.handler() ~~ any(<modperl6 perl6-script>)) {
+ return -1; # DECLINED
+ }
+
my %cfg = Apache::Module::get_config("modparrot_perl6_module");
my %dircfg = Apache::Module::get_config("modparrot_perl6_module",
$r.per_dir_config());
@@ -103,8 +106,13 @@
}
);
+# register hooks
+# XXX would be nice to use the enum strings here
+my @hooks = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0);
+
Apache::Module::add(
'modparrot_perl6_module',
'perl6',
- @cmds
+ @cmds,
+ @hooks
);
Modified: mod_parrot/branches/hll-modules/lib/Apache/Module.pir
==============================================================================
--- mod_parrot/branches/hll-modules/lib/Apache/Module.pir (original)
+++ mod_parrot/branches/hll-modules/lib/Apache/Module.pir Sun Sep 21 10:23:27 2008
@@ -33,7 +33,7 @@
null nul
- dlfunc func, nul, "mpnci_add_apache_module", "pJttP"
+ dlfunc func, nul, "mpnci_add_apache_module", "pJttPP"
set_root_global [ '_modparrot'; 'NCI' ], "add_apache_module", func
dlfunc func, nul, "mpnci_get_module_config", "PJtpi"
@@ -133,10 +133,11 @@
.param string name
.param string namespace
.param pmc cmds
+ .param pmc hooks
.local pmc add_module
add_module = get_root_global ['_modparrot'; 'NCI' ], "add_apache_module"
- add_module(name, namespace, cmds)
+ add_module(name, namespace, cmds, hooks)
.end
=back
Modified: mod_parrot/branches/hll-modules/lib/ModParrot/HLL/pir.pir
==============================================================================
--- mod_parrot/branches/hll-modules/lib/ModParrot/HLL/pir.pir (original)
+++ mod_parrot/branches/hll-modules/lib/ModParrot/HLL/pir.pir Sun Sep 21 10:23:27 2008
@@ -20,7 +20,7 @@
load_bytecode 'ModParrot/Constants.pbc'
# register apache directives
- .local pmc add_module, cmds
+ .local pmc add_module, cmds, hooks
cmds = new 'ResizablePMCArray'
@@ -61,8 +61,18 @@
$P0 = new_cmd('ParrotCleanupHandler', 'TAKE1', 'cmd_parrotcleanuphandler', 'OR_AUTHCFG', 'usage: ParrotCleanupHandler handler-name')
cmds.push($P0)
+ # XXX shouldn't have to hardcode the size of this array
+ hooks = new 'ResizablePMCArray'
+ $I0 = 0
+ loop_start:
+ $P0 = new 'Integer'
+ $P0 = 1
+ hooks[$I0] = $P0
+ inc $I0
+ if $I0 < 19 goto loop_start
+
add_module = get_hll_global [ 'Apache'; 'Module' ], 'add'
- $P1 = add_module("modparrot_pir_module", "PIR", cmds)
+ $P1 = add_module("modparrot_pir_module", "PIR", cmds, hooks)
.end
.sub new_cmd
Modified: mod_parrot/branches/hll-modules/src/module.c
==============================================================================
--- mod_parrot/branches/hll-modules/src/module.c (original)
+++ mod_parrot/branches/hll-modules/src/module.c Sun Sep 21 10:23:27 2008
@@ -37,6 +37,9 @@
extern module AP_MODULE_DECLARE_DATA parrot_module;
AP_DECLARE_DATA extern module *ap_top_module;
+/* used when we have no other way of getting the server config */
+static server_rec *our_server;
+
static apr_status_t modparrot_remove_module(void *data)
{
module *modp = (module *)data;
@@ -203,48 +206,108 @@
static void register_meta_hooks(apr_pool_t *p)
{
+ modparrot_srv_config *mpcfg;
+ modparrot_module_config *cfg;
+ modparrot_module_info *minfo;
+ module *modp;
+ int i;
+
/* XXX does this also work for Apache >= 2.3 */
static const char *aszSucc[] = { "mod_auth.c", NULL };
- ap_hook_open_logs(modparrot_meta_open_logs_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_post_config(modparrot_meta_post_config_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_child_init(modparrot_meta_child_init_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_pre_connection(modparrot_meta_pre_connection_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_process_connection(modparrot_meta_process_connection_handler, NULL,
- NULL, APR_HOOK_MIDDLE);
- ap_hook_map_to_storage(modparrot_meta_map_to_storage_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_translate_name(modparrot_meta_trans_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_post_read_request(modparrot_meta_post_read_request_handler, NULL,
- NULL, APR_HOOK_MIDDLE);
- ap_hook_header_parser(modparrot_meta_header_parser_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_access_checker(modparrot_meta_access_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_check_user_id(modparrot_meta_authen_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_auth_checker(modparrot_meta_authz_handler, NULL, aszSucc,
- APR_HOOK_MIDDLE);
- ap_hook_handler(modparrot_meta_response_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_type_checker(modparrot_meta_type_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_fixups(modparrot_meta_fixup_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_log_transaction(modparrot_meta_log_handler, NULL, NULL,
- APR_HOOK_MIDDLE);
+ /* initialize the index to 0 for the first module only */
+ static int module_index = 0;
+
+ /* this assumes we're called in the same order modules were added */
+ mpcfg = ap_get_module_config(our_server->module_config, &parrot_module);
+ modp = ((module **)mpcfg->module_array->elts)[module_index];
+ minfo = modp->dynamic_load_handle;
+
+ for (i = 0; i < MP_HOOK_LAST; i++) {
+ if (minfo->hooks[i]) {
+ switch(i) {
+ case MP_HOOK_OPEN_LOGS:
+ ap_hook_open_logs(modparrot_meta_open_logs_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_POST_CONFIG:
+ ap_hook_post_config(modparrot_meta_post_config_handler,
+ NULL, NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_CHILD_INIT:
+ ap_hook_child_init(modparrot_meta_child_init_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_PRE_CONNECTION:
+ ap_hook_pre_connection(
+ modparrot_meta_pre_connection_handler, NULL, NULL,
+ APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_PROCESS_CONNECTION:
+ ap_hook_process_connection(
+ modparrot_meta_process_connection_handler, NULL, NULL,
+ APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_POST_READ_REQUEST:
+ ap_hook_post_read_request(
+ modparrot_meta_post_read_request_handler, NULL, NULL,
+ APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_MAP_TO_STORAGE:
+ ap_hook_map_to_storage(
+ modparrot_meta_map_to_storage_handler, NULL, NULL,
+ APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_TRANS:
+ ap_hook_translate_name(modparrot_meta_trans_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_HEADER_PARSER:
+ ap_hook_header_parser(modparrot_meta_header_parser_handler,
+ NULL, NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_ACCESS:
+ ap_hook_access_checker(modparrot_meta_access_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_AUTHEN:
+ ap_hook_check_user_id(modparrot_meta_authen_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_AUTHZ:
+ ap_hook_auth_checker(modparrot_meta_authz_handler, NULL,
+ aszSucc, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_RESPONSE:
+ ap_hook_handler(modparrot_meta_response_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_TYPE:
+ ap_hook_type_checker(modparrot_meta_type_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_FIXUP:
+ ap_hook_fixups(modparrot_meta_fixup_handler, NULL, NULL,
+ APR_HOOK_MIDDLE);
+ break;
+ case MP_HOOK_LOG:
+ ap_hook_log_transaction(modparrot_meta_log_handler, NULL,
+ NULL, APR_HOOK_MIDDLE);
+ break;
+ default:
+ /* we should NEVER get here by definition */
+ break;
+ }
+ }
+ }
}
/* this is very leaky */
module *modparrot_add_module(Parrot_Interp interp, apr_pool_t *p,
const char *name,
char *namespace,
- Parrot_PMC cmd_array)
+ Parrot_PMC cmd_array,
+ Parrot_PMC hook_array)
{
int i, num;
modparrot_srv_config *mpcfg;
@@ -259,6 +322,9 @@
num = Parrot_PMC_get_intval(interp, cmd_array);
if (!num) return(NULL);
+ /* save for later use by register_meta_hooks */
+ our_server = ctxp->s;
+
mpcfg = ap_get_module_config(s->module_config, &parrot_module);
command_rec *cmds =
@@ -341,6 +407,18 @@
minfo = apr_pcalloc(p, sizeof(modparrot_module_info));
minfo->namespace = (char *)apr_pstrdup(p, namespace);
+
+ /* populate hook array for use by register_meta_hooks */
+ i = Parrot_PMC_get_intval(interp, hook_array);
+ if (i != MP_HOOK_LAST) {
+ /* XXX how do we output an error here? */
+ return(NULL);
+ }
+ for (i = 0; i < MP_HOOK_LAST; i++) {
+ Parrot_PMC flag;
+ flag = Parrot_PMC_get_pmc_keyed_int(interp, hook_array, i);
+ minfo->hooks[i] = Parrot_PMC_get_intval(interp, flag);
+ }
modp->dynamic_load_handle = minfo;
if (sub = get_sub_pmc(interp, namespace, "server_create")) {
Modified: mod_parrot/branches/hll-modules/src/nci.c
==============================================================================
--- mod_parrot/branches/hll-modules/src/nci.c (original)
+++ mod_parrot/branches/hll-modules/src/nci.c Sun Sep 21 10:23:27 2008
@@ -190,7 +190,8 @@
module *mpnci_add_apache_module(Parrot_Interp interp,
const char *name,
char *namespace,
- Parrot_PMC cmd_array)
+ Parrot_PMC cmd_array,
+ Parrot_PMC hook_array)
{
modparrot_context *ctxp;
module *modp;
@@ -198,7 +199,7 @@
ctxp = get_interp_ctx(interp);
if (!ctxp) return NULL;
modp = modparrot_add_module(interp, ctxp->pconf, name, namespace,
- cmd_array);
+ cmd_array, hook_array);
return(modp);
}
| Navigate in group perl.cvs.mod_parrot at sever nntp.perl.org | |
| Previous | Next |
| © No Copyright You are free to use Anything |
Site Maintained by PHP Developer
Powered By PHP Consultants |