77b343a
--- apache2/msc_crypt.c.orig	2012-10-18 10:42:43.381000000 +0100
77b343a
+++ apache2/msc_crypt.c	2012-10-18 10:46:52.442000000 +0100
77b343a
@@ -1079,6 +1079,70 @@
77b343a
 
77b343a
     htmlDocContentDumpFormatOutput(output_buf, msr->crypto_html_tree, NULL, 0);
77b343a
 
77b343a
+#ifdef  LIBXML2_NEW_BUFFER
77b343a
+
77b343a
+    if (output_buf->conv == NULL || (output_buf->conv && xmlOutputBufferGetSize(output_buf) == 0)) {
77b343a
+
77b343a
+        if(output_buf->buffer == NULL || xmlOutputBufferGetSize(output_buf) == 0)  {
77b343a
+            xmlOutputBufferClose(output_buf);
77b343a
+            xmlFreeDoc(msr->crypto_html_tree);
77b343a
+            msr->of_stream_changed = 0;
77b343a
+            return -1;
77b343a
+        }
77b343a
+
77b343a
+        if(msr->stream_output_data != NULL) {
77b343a
+            free(msr->stream_output_data);
77b343a
+            msr->stream_output_data =  NULL;
77b343a
+        }
77b343a
+
77b343a
+        msr->stream_output_length = xmlOutputBufferGetSize(output_buf);
77b343a
+        msr->stream_output_data = (char *)malloc(msr->stream_output_length+1);
77b343a
+
77b343a
+        if (msr->stream_output_data == NULL) {
77b343a
+            xmlOutputBufferClose(output_buf);
77b343a
+            xmlFreeDoc(msr->crypto_html_tree);
77b343a
+            return -1;
77b343a
+        }
77b343a
+
77b343a
+        memset(msr->stream_output_data, 0x0, msr->stream_output_length+1);
77b343a
+        memcpy(msr->stream_output_data, xmlOutputBufferGetContent(output_buf), msr->stream_output_length);
77b343a
+
77b343a
+        if (msr->txcfg->debuglog_level >= 4)
77b343a
+            msr_log(msr, 4, "inject_encrypted_response_body: Copying XML tree from CONTENT to stream buffer [%d] bytes.", xmlOutputBufferGetSize(output_buf));
77b343a
+
77b343a
+    } else {
77b343a
+
77b343a
+        if(output_buf->conv == NULL || xmlOutputBufferGetSize(output_buf) == 0)  {
77b343a
+            xmlOutputBufferClose(output_buf);
77b343a
+            xmlFreeDoc(msr->crypto_html_tree);
77b343a
+            msr->of_stream_changed = 0;
77b343a
+            return -1;
77b343a
+        }
77b343a
+
77b343a
+        if(msr->stream_output_data != NULL) {
77b343a
+            free(msr->stream_output_data);
77b343a
+            msr->stream_output_data =  NULL;
77b343a
+        }
77b343a
+
77b343a
+        msr->stream_output_length = xmlOutputBufferGetSize(output_buf);
77b343a
+        msr->stream_output_data = (char *)malloc(msr->stream_output_length+1);
77b343a
+
77b343a
+        if (msr->stream_output_data == NULL) {
77b343a
+            xmlOutputBufferClose(output_buf);
77b343a
+            xmlFreeDoc(msr->crypto_html_tree);
77b343a
+            return -1;
77b343a
+        }
77b343a
+
77b343a
+        memset(msr->stream_output_data, 0x0, msr->stream_output_length+1);
77b343a
+        memcpy(msr->stream_output_data, xmlOutputBufferGetContent(output_buf), msr->stream_output_length);
77b343a
+
77b343a
+        if (msr->txcfg->debuglog_level >= 4)
77b343a
+            msr_log(msr, 4, "inject_encrypted_response_body: Copying XML tree from CONV to stream buffer [%d] bytes.", xmlOutputBufferGetSize(output_buf));
77b343a
+
77b343a
+    }
77b343a
+
77b343a
+#else
77b343a
+
77b343a
     if (output_buf->conv == NULL || (output_buf->conv && output_buf->conv->use == 0)) {
77b343a
 
77b343a
         if(output_buf->buffer == NULL || output_buf->buffer->use == 0)  {
77b343a
@@ -1139,6 +1203,8 @@
77b343a
 
77b343a
     }
77b343a
 
77b343a
+#endif
77b343a
+
77b343a
     xmlOutputBufferClose(output_buf);
77b343a
 
77b343a
     content_value = (char*)apr_psprintf(msr->mp, "%"APR_SIZE_T_FMT, msr->stream_output_length);