[svn:mod_parrot] r417 - in mod_parrot/trunk: . include languages/perl6/lib lib/Apache lib/ModParrot/HLL src

[email protected] Mon, 1 Sep 2008 11:21:18 -0700 (PDT)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Mon Sep  1 11:21:17 2008
New Revision: 417

Modified:
   mod_parrot/trunk/call_list.txt
   mod_parrot/trunk/include/modparrot_config.h
   mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm
   mod_parrot/trunk/lib/Apache/Module.pir
   mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir
   mod_parrot/trunk/src/nci.c

Log:
refactor dircfg_handler to support all relevant hooks
add srvcfg_handler to support server-scope hooks


Modified: mod_parrot/trunk/call_list.txt
==============================================================================
--- mod_parrot/trunk/call_list.txt	(original)
+++ mod_parrot/trunk/call_list.txt	Mon Sep  1 11:21:17 2008
@@ -19,4 +19,4 @@
 v       ptt
 v       Jtiiipt
 p       JtP
-P	Jtti
+P	Jitti

Modified: mod_parrot/trunk/include/modparrot_config.h
==============================================================================
--- mod_parrot/trunk/include/modparrot_config.h	(original)
+++ mod_parrot/trunk/include/modparrot_config.h	Mon Sep  1 11:21:17 2008
@@ -104,6 +104,33 @@
 };
 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
 {
     Parrot_PMC func;     /* parrot callback sub */

Modified: mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm
==============================================================================
--- mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm	(original)
+++ mod_parrot/trunk/languages/perl6/lib/mod_perl6.pm	Mon Sep  1 11:21:17 2008
@@ -18,6 +18,8 @@
 
 use v6;
 
+our @preloaded_modules = ();
+our @postconfig_requires = ();
 our %loaded_modules;
 
 sub load($handler)
@@ -35,3 +37,30 @@
     my $status = ::($handler)::handler($r);
     return $status;
 }
+
+sub post_config_handler($ctx, $handler)
+{
+    #my $conf_pool = $ctx.conf_pool();
+    #my $log_pool = $ctx.log_pool();
+    #my $temp_pool = $ctx.temp_pool();
+    #my $s = $ctx.server_rec();
+
+    # preload modules
+    for @preloaded_modules -> $m {
+        # XXX fix when namespace interpolation works
+        # use ::($m);
+        eval "use $m";
+    }
+
+    # load postconfig requires
+    for @postconfig_requires -> $r {
+        # XXX does this work???
+        require $r;
+    }
+
+    # run the postconfig handler
+    load($handler);
+    #my $status = ::($handler)::handler($conf_pool, $log_pool, $temp_pool, $s);
+    my $status = ::($handler)::handler();
+    return $status;
+}

Modified: mod_parrot/trunk/lib/Apache/Module.pir
==============================================================================
--- mod_parrot/trunk/lib/Apache/Module.pir	(original)
+++ mod_parrot/trunk/lib/Apache/Module.pir	Mon Sep  1 11:21:17 2008
@@ -36,9 +36,12 @@
     dlfunc func, nul, "mpnci_add_apache_module", "pJtP"
     set_root_global [ '_modparrot'; 'NCI' ], "add_apache_module", func
 
-    dlfunc func, nul, "mpnci_dircfg_handler", "PJtti"
+    dlfunc func, nul, "mpnci_dircfg_handler", "PJitti"
     set_root_global [ '_modparrot'; 'NCI' ], "dircfg_handler", func
 
+    dlfunc func, nul, "mpnci_srvcfg_handler", "PJitti"
+    set_root_global [ '_modparrot'; 'NCI' ], "srvcfg_handler", func
+
     newclass module_class, [ 'Apache'; 'Module' ]
     addattribute module_class, 'module'
 .end
@@ -137,17 +140,18 @@
 
 =back
 
-=over 4 
+=over 4
 
-=item C<modparrot_dircfg_handler(STRING hll, STRING id)>
+=item C<modparrot_dircfg_handler(INT hook, STRING hll, STRING id)>
 
 =over 4
 
-Get or set the mod_parrot response handler.
+Get or set a mod_parrot handler.
 
 =cut
 
 .sub modparrot_dircfg_handler
+    .param int hook
     .param pmc hll :optional
     .param pmc id :optional
     .param int update :opt_flag
@@ -159,7 +163,37 @@
     hll = new 'String'
     id = new 'String'
   do_update:
-    res = func(hll, id, update)
+    res = func(hook, hll, id, update)
+
+    .return(res)
+.end
+
+=back
+
+=over 4 
+
+=item C<modparrot_srvcfg_handler(INT hook, STRING hll, STRING id)>
+
+=over 4
+
+Get or set a mod_parrot handler.
+
+=cut
+
+.sub modparrot_srvcfg_handler
+    .param int hook
+    .param pmc hll :optional
+    .param pmc id :optional
+    .param int update :opt_flag
+    .local pmc func, res
+
+    func = get_root_global ['_modparrot'; 'NCI' ], "srvcfg_handler"
+
+    if update goto do_update
+    hll = new 'String'
+    id = new 'String'
+  do_update:
+    res = func(hook, hll, id, update)
    
     .return(res)
 .end 

Modified: mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir	(original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/perl6.pir	Mon Sep  1 11:21:17 2008
@@ -45,18 +45,19 @@
     ap_const = get_root_global ['Apache'; 'Constants'], 'ap_constants'
 
     load_bytecode 'Apache/Module.pbc'
+    load_bytecode 'ModParrot/Constants.pbc'
 
     cmds = new 'Array'
-    cmds = 1
-    $P0 = new 'Hash'
+    cmds = 2
 
+    $P0 = new 'Hash'
     $P1 = new 'String'
     $P1 = 'Perl6ResponseHandler'
     $P0['name'] = $P1
     $P1 = new 'Integer'
     $P1 = ap_const['TAKE1']
     $P0['args_how'] = $P1
-    $P1 = get_hll_global 'cmd_perl6responsehandler'
+    $P1 = get_hll_global [ 'ModParrot'; 'HLL'; 'perl6' ], 'cmd_perl6responsehandler'
     $P0['func'] = $P1
     $P1 = new 'Integer'
     $P1 = ap_const['OR_AUTHCFG']
@@ -66,20 +67,49 @@
     $P0['errmsg'] = $P1
     cmds[0] = $P0
 
+    $P0 = new 'Hash'
+    $P1 = new 'String'
+    $P1 = 'Perl6Module'
+    $P0['name'] = $P1
+    $P1 = new 'Integer'
+    $P1 = ap_const['TAKE1']
+    $P0['args_how'] = $P1
+    $P1 = get_hll_global [ 'ModParrot'; 'HLL'; 'perl6' ], 'cmd_perl6module'
+    $P0['func'] = $P1
+    $P1 = new 'Integer'
+    $P1 = ap_const['RSRC_CONF']
+    $P0['req_override'] = $P1
+    $P1 = new 'String'
+    $P1 = "usage: Perl6Module module"
+    $P0['errmsg'] = $P1
+    cmds[1] = $P0
+
     add_module = get_hll_global [ 'Apache'; 'Module' ], 'add'
     $P1 = add_module("modparrot_perl6_module", cmds)
 .end
 
+# declare namespace AFTER loading compiler
+# otherwise we get method resolution errors
+.namespace [ 'ModParrot'; 'HLL'; 'perl6' ]
+
+# helper functions go here
+
 .sub cmd_perl6responsehandler
     .param pmc args
     .local string handler
+    .local pmc mp_const
+
+    mp_const = get_root_global ['ModParrot'; 'Constants'], 'mp_constants'
     handler = args[0]
     $P0 = get_hll_global ['Apache'; 'Module'], 'modparrot_dircfg_handler'
-    $P1 = $P0('perl6', handler)
+    $I0 = mp_const['MP_HOOK_RESPONSE']
+    $P1 = $P0($I0, 'perl6', handler)
 .end
 
-# declare namespace AFTER loading compiler
-# otherwise we get method resolution errors
-.namespace [ 'ModParrot'; 'HLL'; 'perl6' ]
-
-# helper functions go here
+.sub cmd_perl6module
+    .param pmc args
+    $P0 = get_hll_global [ 'ModParrot'; 'HLL'; 'perl6' ], '@preloaded_modules'
+    $P1 = new 'Perl6Str'
+    $P1 = args[0]
+    $P0.push($P1)
+.end

Modified: mod_parrot/trunk/src/nci.c
==============================================================================
--- mod_parrot/trunk/src/nci.c	(original)
+++ mod_parrot/trunk/src/nci.c	Mon Sep  1 11:21:17 2008
@@ -33,6 +33,8 @@
 
 #include "../build/src/nci/request_rec.c"
 
+extern module AP_MODULE_DECLARE_DATA parrot_module;
+
 request_rec *mpnci_request_rec(Parrot_Interp interp)
 {
     modparrot_context *ctxp;
@@ -190,23 +192,91 @@
     return(modp);
 }
 
-Parrot_PMC mpnci_dircfg_handler(Parrot_Interp interp, char *hll, char *id,
-    int update)
+#define SET_DIRCFG_INFO(x) if (update) { ctxp->dircfg->x = handler_info; } \
+                             else { handler_info = ctxp->dircfg->x; }
+
+Parrot_PMC mpnci_dircfg_handler(Parrot_Interp interp, int hook, char *hll,
+    char *id, int update)
+{
+    modparrot_context *ctxp;
+    modparrot_handler_info *handler_info;
+    Parrot_PMC handler;
+    int typenum;
+
+    ctxp = get_interp_ctx(interp);
+    if (!ctxp) return NULL;
+
+    if (update) {
+        handler_info = (modparrot_handler_info *)apr_pcalloc(
+            ctxp->pconf, sizeof(modparrot_handler_info));
+    }
+
+    switch(hook) {
+        case MP_HOOK_RESPONSE:
+            SET_DIRCFG_INFO(handler);
+            break;
+        default:
+            return NULL;
+    }
+
+    if (update) {
+        handler_info->hll = apr_pstrdup(ctxp->pconf, hll);
+        handler_info->id = apr_pstrdup(ctxp->pconf, id);
+    }
+
+    typenum = Parrot_PMC_typenum(interp, "SArray");
+    handler = (Parrot_PMC)Parrot_PMC_new(interp, typenum);
+    /* XXX how do we unregister this after it's used? */
+    Parrot_register_pmc(interp, handler);
+    Parrot_PMC_set_intval(interp, handler, 2);
+
+    if (handler_info) {
+        Parrot_PMC_set_cstring_intkey(interp, handler, 0,
+            handler_info ? handler_info->hll : "");
+        Parrot_PMC_set_cstring_intkey(interp, handler, 1,
+            handler_info ? handler_info->id : "");
+    }
+    else {
+        Parrot_PMC_set_pmc_intkey(interp, handler, 0, PMCNULL);
+        Parrot_PMC_set_pmc_intkey(interp, handler, 1, PMCNULL);
+    }
+
+    return(handler);
+}
+
+#define SET_SRVCFG_INFO(x) if (update) { cfg->x = handler_info; } \
+                             else { handler_info = cfg->x; }
+
+Parrot_PMC mpnci_srvcfg_handler(Parrot_Interp interp, int hook, char *hll,
+    char *id, int update)
 {
     modparrot_context *ctxp;
+    modparrot_handler_info *handler_info;
     Parrot_PMC handler;
+    modparrot_srv_config *cfg;
     int typenum;
 
     ctxp = get_interp_ctx(interp);
     if (!ctxp) return NULL;
 
+    cfg = ap_get_module_config(ctxp->s->module_config, &parrot_module);
+
+    if (update) {
+        handler_info = (modparrot_handler_info *)apr_pcalloc(
+            ctxp->pconf, sizeof(modparrot_handler_info));
+    }
+
+    switch(hook) {
+        case MP_HOOK_POST_CONFIG:
+            SET_SRVCFG_INFO(post_config_handler);
+            break;
+        default:
+            return NULL;
+    }
+
     if (update) {
-        if (!ctxp->dircfg->handler) {
-            ctxp->dircfg->handler = (modparrot_handler_info *)apr_pcalloc(
-                ctxp->pconf, sizeof(modparrot_handler_info));
-        }
-        ctxp->dircfg->handler->hll = apr_pstrdup(ctxp->pconf, hll);
-        ctxp->dircfg->handler->id = apr_pstrdup(ctxp->pconf, id);
+        handler_info->hll = apr_pstrdup(ctxp->pconf, hll);
+        handler_info->id = apr_pstrdup(ctxp->pconf, id);
     }
 
     typenum = Parrot_PMC_typenum(interp, "SArray");
@@ -215,11 +285,11 @@
     Parrot_register_pmc(interp, handler);
     Parrot_PMC_set_intval(interp, handler, 2);
 
-    if (ctxp->dircfg->handler) {
+    if (handler_info) {
         Parrot_PMC_set_cstring_intkey(interp, handler, 0,
-            ctxp->dircfg->handler ? ctxp->dircfg->handler->hll : "");
+            handler_info ? handler_info->hll : "");
         Parrot_PMC_set_cstring_intkey(interp, handler, 1,
-            ctxp->dircfg->handler ? ctxp->dircfg->handler->id : "");
+            handler_info ? handler_info->id : "");
     }
     else {
         Parrot_PMC_set_pmc_intkey(interp, handler, 0, PMCNULL);