Commit 3caccf58 authored by Etienne CHAMPETIER's avatar Etienne CHAMPETIER

ZP-797 WBXMLDecoder->getOpaque() use stream_get_contents().

Released under the Affero GNU General Public License (AGPL) version 3.
parent 0f0b058a
...@@ -591,30 +591,12 @@ class WBXMLDecoder extends WBXMLDefs { ...@@ -591,30 +591,12 @@ class WBXMLDecoder extends WBXMLDefs {
* @return string * @return string
*/ */
private function getOpaque($len) { private function getOpaque($len) {
// TODO check if it's possible to do it other way $d = stream_get_contents($this->in, $len);
// fread stops reading because the following condition is true (from php.net): if ($d === false)
// if the stream is read buffered and it does not represent a plain file, throw new HTTPReturnCodeException("WBXMLDecoder->getOpaque(): stream_get_contents === false", HTTP_CODE_500, null, LOGLEVEL_WARN);
// at most one read of up to a number of bytes equal to the chunk size $l = strlen($d);
// (usually 8192) is made; depending on the previously buffered data, if ($l !== $len)
// the size of the returned data may be larger than the chunk size. throw new HTTPReturnCodeException("WBXMLDecoder->getOpaque(): only $l byte read instead of $len", HTTP_CODE_500, null, LOGLEVEL_WARN);
// using only return fread it will return only a part of stream if chunk is smaller
// than $len. Read from stream in a loop until the $len is reached.
$d = "";
$l = 0;
while (1) {
$l = (($len - strlen($d)) > 8192) ? 8192 : ($len - strlen($d));
if ($l > 0) {
$data = fread($this->in, $l);
// Stream ends prematurely on instable connections and big mails
if ($data === false || feof($this->in))
throw new HTTPReturnCodeException(sprintf("WBXMLDecoder->getOpaque() connection unavailable while trying to read %d bytes from stream. Aborting after %d bytes read.", $len, strlen($d)), HTTP_CODE_500, null, LOGLEVEL_WARN);
else
$d .= $data;
}
if (strlen($d) >= $len) break;
}
return $d; return $d;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment