[svn:mod_parrot] r280 - in mod_parrot/trunk: docs lib/ModParrot/HLL src

[email protected]
Newsgroups perl.cvs.mod_parrot
Message-ID <[email protected]>
Author: jhorwitz
Date: Mon Dec 17 11:55:38 2007
New Revision: 280

Modified:
   mod_parrot/trunk/docs/apache-conf.txt
   mod_parrot/trunk/lib/ModParrot/HLL/pir.pir
   mod_parrot/trunk/src/mod_parrot.c

Log:
implement request cleanup handlers


Modified: mod_parrot/trunk/docs/apache-conf.txt
==============================================================================
--- mod_parrot/trunk/docs/apache-conf.txt	(original)
+++ mod_parrot/trunk/docs/apache-conf.txt	Mon Dec 17 11:55:38 2007
@@ -166,3 +166,10 @@
 Default:     none
 Context:     directory config
 Description: Sets the Parrot log handler
+
+ParrotCleanupHandler
+----------------
+Syntax:      ParrotCleanupHandler [hll,]handler
+Default:     none
+Context:     directory config
+Description: Sets the Parrot request cleanup handler

Modified: mod_parrot/trunk/lib/ModParrot/HLL/pir.pir
==============================================================================
--- mod_parrot/trunk/lib/ModParrot/HLL/pir.pir	(original)
+++ mod_parrot/trunk/lib/ModParrot/HLL/pir.pir	Mon Dec 17 11:55:38 2007
@@ -369,3 +369,22 @@
     # return status code
     .return(status)
 .end
+
+# cleanup handler
+.sub _cleanup_handler
+    .param string handler_name
+    .local pmc r
+    .local pmc handler
+    .local int status
+
+    # get the request_rec object
+    $P0 = get_class [ 'Apache'; 'RequestRec' ]
+    r = new $P0
+
+    # find the handler sub and call it
+    find_global handler, handler_name, '_handler'
+    status = handler(r)
+
+    # return status code
+    .return(status)
+.end

Modified: mod_parrot/trunk/src/mod_parrot.c
==============================================================================
--- mod_parrot/trunk/src/mod_parrot.c	(original)
+++ mod_parrot/trunk/src/mod_parrot.c	Mon Dec 17 11:55:38 2007
@@ -45,6 +45,9 @@
 /* declare our module */
 extern module AP_MODULE_DECLARE_DATA parrot_module;
 
+/* we need to forward declare this */
+static apr_status_t modparrot_request_cleanup(void *data);
+
 static Parrot_Interp modparrot_init(modparrot_context *ctx, server_rec *s)
 {
     Parrot_Interp interp;
@@ -183,6 +186,12 @@
     int handler_status;
     char *sub, *hll, *hll_handler;
 
+    /* take this opportunity to register the mod_parrot cleanup handler here,
+     * as we may not handle any other part of the request until then.
+     */
+    apr_pool_cleanup_register(r->pool, r, modparrot_request_cleanup,
+        modparrot_request_cleanup);
+
     if (!r->handler) return DECLINED;
 
     /* get apache configs */
@@ -871,6 +880,57 @@
     return handler_status;
 }
 
+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);
+
+    /* initialize context */
+    if (!(ctxp = init_ctx(r->server))) {
+        MPLOG_ERRORF(r->server,
+            "context initialization failed for cleanup handler '%s'",
+            dircfg->cleanup_handler->id);
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+    ctxp->r = r;
+
+    /* call HLL handler */
+    sub = "_cleanup_handler";
+    if (!modparrot_hll_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;
+    }
+
+    /* clean up */
+    release_ctx(ctxp);
+
+    /* tell apache we're done */
+    return handler_status;
+}
+
+static apr_status_t modparrot_request_cleanup(void *data)
+{
+    modparrot_srv_config *cfg;
+    apr_array_header_t *ctx_pool;
+    request_rec *r = (request_rec *)data;
+
+    modparrot_cleanup_handler(r);
+
+    return APR_SUCCESS;
+}
+
 static void register_hooks(apr_pool_t *p)
 {
     /* this allows <IfDefine MODPARROT> blocks */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.