417e693
From fc99472b8b2fc837148f71755f23349a71e307bf Mon Sep 17 00:00:00 2001
417e693
From: Bas Couwenberg <sebastic@xs4all.nl>
417e693
Date: Sat, 26 Apr 2014 13:46:41 +0200
417e693
Subject: [PATCH] Use php://input instead of raw_post_data to support PHP 5.6.
417e693
417e693
php_stream handling largely taken from PECL HTTP:
417e693
417e693
http://git.php.net/?p=pecl/http/pecl_http.git;a=blob;f=php_http_env.c;h=30ee32d7c68b3341aeaeb24c909b102537caccdf;hb=8ec2c825719482e62222163a300b0e18319591d0#l229
417e693
417e693
Copyright (c) 2004-2014, Michael Wallner <mike@iworks.at>.
417e693
All rights reserved.
417e693
417e693
Redistribution and use in source and binary forms, with or without
417e693
modification, are permitted provided that the following conditions are met:
417e693
417e693
    * Redistributions of source code must retain the above copyright notice,
417e693
      this list of conditions and the following disclaimer.
417e693
    * Redistributions in binary form must reproduce the above copyright
417e693
      notice, this list of conditions and the following disclaimer in the
417e693
     documentation and/or other materials provided with the distribution.
417e693
417e693
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
417e693
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
417e693
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
417e693
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
417e693
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
417e693
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
417e693
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
417e693
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
417e693
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
417e693
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
417e693
417e693
Bug-Debian: https://bugs.debian.org/745600
417e693
---
417e693
 .travis.yml                |  1 +
417e693
 mapscript/php/owsrequest.c | 23 +++++++++++++++++++++++
417e693
 2 files changed, 24 insertions(+)
417e693
417e693
diff --git a/mapscript/php/owsrequest.c b/mapscript/php/owsrequest.c
417e693
index 428c8dd..f01d361 100644
417e693
--- a/mapscript/php/owsrequest.c
417e693
+++ b/mapscript/php/owsrequest.c
417e693
@@ -32,6 +32,9 @@
417e693
 #include "php_mapscript.h"
417e693
 #include "SAPI.h"
417e693
 #include "php_variables.h"
417e693
+#if PHP_VERSION_ID >= 50600
417e693
+#include "php_streams.h"
417e693
+#endif
417e693
 
417e693
 char *owsrequest_getenv(const char *name, void *thread_context);
417e693
 
417e693
@@ -193,9 +196,29 @@ PHP_METHOD(OWSRequestObj, loadParams)
417e693
         cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv, NULL, 0, thread_context);
417e693
       }
417e693
     } else {
417e693
+#if PHP_VERSION_ID >= 50600
417e693
+      php_stream *s = php_stream_temp_new();
417e693
+      php_stream *input = php_stream_open_wrapper("php://input", "r", 0, NULL);
417e693
+
417e693
+      /* php://input does not support stat */
417e693
+      php_stream_copy_to_stream_ex(input, s, -1, NULL);
417e693
+      php_stream_close(input);
417e693
+
417e693
+      php_stream_rewind(s);
417e693
+      
417e693
+      char *raw_post_data = NULL;
417e693
+      long raw_post_data_length = 0;
417e693
+
417e693
+      raw_post_data_length = php_stream_copy_to_mem(s, raw_post_data, -1, 0);
417e693
+
417e693
+      cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv,
417e693
+                               raw_post_data,
417e693
+                               raw_post_data_length, thread_context);
417e693
+#else
417e693
       cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv,
417e693
                                SG(request_info).raw_post_data,
417e693
                                SG(request_info).raw_post_data_length, thread_context);
417e693
+#endif
417e693
     }
417e693
   }
417e693
 
417e693
-- 
417e693
1.9.3
417e693