[Mod_transform] patch erratum: forgot to free transform context

Dorian Taylor dorian at foobarsystems.com
Thu May 26 18:56:10 EST 2005


woops!

.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	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:50:24.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,45 @@
         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;
+
+            /* dup-check so as not to trip the transform context */
+            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);
+
+    /* we don't need this anymore */
+    xsltFreeTransformContext(xctxt);
+
     if (!result) {
         if (!stylesheet_is_cached) {
             xsltFreeStylesheet(transform);


More information about the Mod_transform mailing list