[Mod_transform] two patches to mod_transform

Dorian Taylor dorian at foobarsystems.com
Thu May 26 18:48:30 EST 2005


the first implements an InitialOnly flag, which disables transformation
for subrequests and internal redirects. the second implements
rudimentary support for environment variables as global parameters.

these were written against the 0.6.0 release.

cheers

dorian
-------------- next part --------------
diff -ur mod_transform-0.6.0/include/mod_transform_private.h mod_transform-0.6.0-djt/include/mod_transform_private.h
--- mod_transform-0.6.0/include/mod_transform_private.h	Sun Oct 17 20:06:36 2004
+++ mod_transform-0.6.0-djt/include/mod_transform_private.h	Mon Feb 21 18:57:41 2005
@@ -61,6 +61,7 @@
 #define NO_OPTIONS          (1 <<  0)
 #define USE_APACHE_FS       (1 <<  1)
 #define XINCLUDES           (1 <<  2)
+#define INITIAL_ONLY        (1 <<  3)
 
 /* Static Style Sheet Caching */
 typedef struct transform_xslt_cache
diff -ur mod_transform-0.6.0/src/mod_transform.c mod_transform-0.6.0-djt/src/mod_transform.c
--- mod_transform-0.6.0/src/mod_transform.c	Mon Oct 18 09:01:50 2004
+++ mod_transform-0.6.0-djt/src/mod_transform.c	Mon Feb 21 19:20:58 2005
@@ -78,6 +78,12 @@
     svr_cfg *sconf = ap_get_module_config(f->r->server->module_config,
                                           &transform_module);
 
+    if (dconf->opts & INITIAL_ONLY && !ap_is_initial_req(f->r)) {
+        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, "mod_transform: %s",
+                  "Declining request transform due to InitialOnly flag.");
+        return DECLINED;
+    }
+
     if (!doc) {
         return pass_failure(f, "XSLT: Couldn't parse XML Document", notes);
     }
@@ -371,6 +377,9 @@
             opts = NO_OPTIONS;
             opts_add = 0;
             opts_remove = 0;
+        }
+        else if (!strcasecmp(w, "InitialOnly")) {
+            option = INITIAL_ONLY;
         }
         else {
             return "Invalid TransformOption";
-------------- next part --------------
diff -ur mod_transform-0.6.0/include/mod_transform_private.h mod_transform-0.6.0-djt/include/mod_transform_private.h
--- mod_transform-0.6.0/include/mod_transform_private.h	2004-10-17 20:06:36.000000000 -0700
+++ mod_transform-0.6.0-djt/include/mod_transform_private.h	2005-05-26 16:29:38.000000000 -0700
@@ -46,6 +46,7 @@
 #include <libxml/xmlIO.h>
 #include <libxslt/xsltutils.h>
 #include <libxslt/transform.h>
+#include <libxslt/variables.h>
 #include <libexslt/exslt.h>
 
 /* Did I mention auto*foo sucks? */
diff -ur mod_transform-0.6.0/src/mod_transform.c mod_transform-0.6.0-djt/src/mod_transform.c
--- mod_transform-0.6.0/src/mod_transform.c	2004-10-18 09:01:50.000000000 -0700
+++ mod_transform-0.6.0-djt/src/mod_transform.c	2005-05-26 16:30:02.000000000 -0700
@@ -78,6 +78,12 @@
     svr_cfg *sconf = ap_get_module_config(f->r->server->module_config,
                                           &transform_module);
 
+    /* environment grabbing stuff */
+    apr_table_t             *env;
+    apr_array_header_t      *envarr;
+    apr_table_entry_t       *elts;
+    xsltTransformContextPtr xctxt;
+
     if (!doc) {
         return pass_failure(f, "XSLT: Couldn't parse XML Document", notes);
     }
@@ -128,7 +134,39 @@
         return pass_failure(f, "XSLT: Loading of the XSLT File has failed", notes);
     }
 
-    result = xsltApplyStylesheet(transform, doc, 0);
+    if (!(xctxt = xsltNewTransformContext(transform, doc))) {
+        return pass_failure
+            (f, "XSLT: Could not create transform context", notes);
+    }
+
+    /* acquire parameter set from environment */
+
+    env     = f->r->subprocess_env;
+    envarr  = (apr_array_header_t *)apr_table_elts(env);
+    elts    = (apr_table_entry_t *)envarr->elts;
+
+    if (!apr_is_empty_array(envarr)) {
+        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r,
+                      "Adding environment to global parameters");
+        int i;
+        for (i = 0; i < envarr->nelts; i++) {
+            xmlChar *k = (xmlChar *)elts[i].key;
+            xmlChar *v = (xmlChar *)elts[i].val;
+            
+            if (!k || !v) continue;
+            if (xmlHashLookup2(xctxt->globalVars, k, (xmlChar *)NULL)) continue;
+            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r,
+                          "Adding environment variable %s => %s", k, v);
+
+            if (xsltQuoteOneUserParam(xctxt, (xmlChar *)k, (xmlChar *)v) != 0) {
+                ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, f->r,
+                              "Failed xpath parsing attempt for %s => %s",
+                              k, v);
+            }
+        }
+    }
+
+    result = xsltApplyStylesheetUser(transform, doc, NULL, NULL, NULL, xctxt);
     if (!result) {
         if (!stylesheet_is_cached) {
             xsltFreeStylesheet(transform);


More information about the Mod_transform mailing list