[svn:mod_parrot] r426 - mod_parrot/branches/hll-modules/src

[email protected] Thu, 18 Sep 2008 19:54:07 -0700 (PDT)
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Thu Sep 18 19:54:06 2008
New Revision: 426

Modified:
   mod_parrot/branches/hll-modules/src/mod_parrot.c

Log:
fix cleanup handler


Modified: mod_parrot/branches/hll-modules/src/mod_parrot.c
==============================================================================
--- mod_parrot/branches/hll-modules/src/mod_parrot.c	(original)
+++ mod_parrot/branches/hll-modules/src/mod_parrot.c	Thu Sep 18 19:54:06 2008
@@ -328,7 +328,7 @@
     return DECLINED;
 }
 
-#define MP_REQUEST_METAHANDLER(hname) \
+#define MP_REQUEST_METAHANDLER(hname, register_cleanup) \
     int modparrot_meta_##hname(request_rec *r) \
     { \
         modparrot_context *ctxp; \
@@ -349,6 +349,14 @@
         mpcfg = ap_get_module_config(r->server->module_config, \
             &parrot_module); \
         if (!(mpcfg->option_flags & MP_OPT_ENABLE)) return DECLINED; \
+        /* take this opportunity to register the mod_parrot cleanup handler \
+         * here, \
+         * as we may not handle any other part of the request until then. \
+         */ \
+        if (register_cleanup) { \
+            apr_pool_cleanup_register(r->pool, r, modparrot_request_cleanup, \
+                apr_pool_cleanup_null); \
+        } \
         ctxp->r = r; \
         /* XXX register cleanup handler here or in the meta handler? */ \
         /* XXX does header_only check belong in the meta handler? */ \
@@ -374,17 +382,17 @@
         return status; \
     }
 
-MP_REQUEST_METAHANDLER(map_to_storage_handler)
-MP_REQUEST_METAHANDLER(translate_name_handler)
-MP_REQUEST_METAHANDLER(post_read_request_handler)
-MP_REQUEST_METAHANDLER(header_parser_handler)
-MP_REQUEST_METAHANDLER(access_handler)
-MP_REQUEST_METAHANDLER(authen_handler)
-MP_REQUEST_METAHANDLER(authz_handler)
-MP_REQUEST_METAHANDLER(response_handler)
-MP_REQUEST_METAHANDLER(type_checker_handler)
-MP_REQUEST_METAHANDLER(fixup_handler)
-MP_REQUEST_METAHANDLER(log_handler)
+MP_REQUEST_METAHANDLER(map_to_storage_handler, 1)
+MP_REQUEST_METAHANDLER(translate_name_handler, 0)
+MP_REQUEST_METAHANDLER(post_read_request_handler, 0)
+MP_REQUEST_METAHANDLER(header_parser_handler, 0)
+MP_REQUEST_METAHANDLER(access_handler, 0)
+MP_REQUEST_METAHANDLER(authen_handler, 0)
+MP_REQUEST_METAHANDLER(authz_handler, 0)
+MP_REQUEST_METAHANDLER(response_handler, 0)
+MP_REQUEST_METAHANDLER(type_checker_handler, 0)
+MP_REQUEST_METAHANDLER(fixup_handler, 0)
+MP_REQUEST_METAHANDLER(log_handler, 0)
 
 static int modparrot_meta_pre_connection_handler(conn_rec *c, void *csd)
 {
@@ -738,44 +746,47 @@
     return status;
 }
 
+/* not a true handler since it has no hook */
 static int modparrot_cleanup_handler(request_rec *r)
 {
-    modparrot_dir_config *dircfg;
-    modparrot_srv_config *cfg;
     modparrot_context *ctxp;
-    int handler_status;
-    char *sub, *hll, *hll_handler;
-
-    /* get apache configs */
-    dircfg = (modparrot_dir_config *)ap_get_module_config(r->per_dir_config, &parrot_module);
-    cfg = ap_get_module_config(r->server->module_config, &parrot_module);
-
-    SET_HLL_HANDLER(cleanup_handler);
+    modparrot_srv_config *mpcfg;
+    module *modp;
+    modparrot_module_info *minfo;
+    Parrot_PMC sub;
+    int status;
 
     /* initialize context */
     if (!(ctxp = init_ctx(r->server))) {
-        MPLOG_ERRORF(r->server,
-            "context initialization failed for cleanup handler '%s'",
-            dircfg->cleanup_handler->id);
+        MPLOG_ERROR(r->server, "context initialization failed");
         return HTTP_INTERNAL_SERVER_ERROR;
     }
+
+    /* get next module in line */
+    ctxp->module_index++;
+
+    /* decline if mod_parrot isn't enabled  */
+    mpcfg = ap_get_module_config(r->server->module_config, &parrot_module);
+    if (!(mpcfg->option_flags & MP_OPT_ENABLE)) return DECLINED;
+
     ctxp->r = r;
 
-    /* call HLL handler */
-    sub = "cleanup_handler";
-    if (!modparrot_meta_handler(ctxp->interp, hll, sub, hll_handler,
-        &handler_status)) {
-        MPLOG_ERRORF(r->server, "no subroutine found for handler '%s'",
-            hll_handler);
-        release_ctx(ctxp);
-        return HTTP_INTERNAL_SERVER_ERROR;
+    /* get HLL config */
+    modp = ((module **)mpcfg->module_array->elts)[ctxp->module_index];
+    minfo = (modparrot_module_info *)modp->dynamic_load_handle;
+    /* call meta handler */
+    if (!modparrot_call_meta_handler(ctxp->interp, minfo->namespace,
+       "cleanup_handler", &status)) {
+        MPLOG_ERRORF(r->server, "no cleanup metahandler found for module '%s'",
+            modp->name);
+        status = HTTP_INTERNAL_SERVER_ERROR;
     }
 
     /* clean up */
     release_ctx(ctxp);
 
     /* tell apache we're done */
-    return handler_status;
+    return status;
 }
 
 static apr_status_t modparrot_request_cleanup(void *data)