Skip to content

Commit

Permalink
Use Horde_Stream
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Sep 29, 2013
1 parent 05f0c89 commit 45f3cfb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Wbxml.php
Expand Up @@ -863,7 +863,7 @@ class Horde_ActiveSync_Wbxml
*/
public function __construct($stream)
{
$this->_stream = $stream;
$this->_stream = new Horde_Stream_Existing(array('stream' => $stream));
$this->_logger = new Horde_Support_Stub();
$this->_procid = getmypid();
}
Expand Down
8 changes: 4 additions & 4 deletions framework/ActiveSync/lib/Horde/ActiveSync/Wbxml/Decoder.php
Expand Up @@ -599,9 +599,9 @@ private function _getOpaque($len)
while (1) {
$l = (($len - strlen($d)) > 8192) ? 8192 : ($len - strlen($d));
if ($l > 0) {
$data = fread($this->_stream, $l);
$data = $this->_stream->read($l);
// Stream ends prematurely on instable connections and big mails
if ($data === false || feof($this->_stream)) {
if ($data === false || $this->_stream->eof()) {
throw new Horde_ActiveSync_Exception(sprintf(
'Connection unavailable while trying to read %d bytes from stream. Aborting after %d bytes read.',
$len,
Expand All @@ -625,7 +625,7 @@ private function _getOpaque($len)
*/
private function _getByte()
{
$ch = fread($this->_stream, 1);
$ch = $this->_stream->read(1);
if (strlen($ch) > 0) {
$ch = ord($ch);
return $ch;
Expand Down Expand Up @@ -665,7 +665,7 @@ private function _getStringTable()
$stringtable = '';
$length = $this->_getMBUInt();
if ($length > 0) {
$stringtable = fread($this->_stream, $length);
$stringtable = $this->_stream->read($length);
}

return $stringtable;
Expand Down
33 changes: 12 additions & 21 deletions framework/ActiveSync/lib/Horde/ActiveSync/Wbxml/Encoder.php
Expand Up @@ -107,7 +107,7 @@ public function startWBXML($multipart = false)
$this->multipart = $multipart;
if ($multipart) {
$this->_tempStream = $this->_stream;
$this->_stream = fopen('php://temp', 'r+');
$this->_stream = new Horde_Stream_Temp();
}
$this->outputWbxmlHeader();
}
Expand Down Expand Up @@ -157,9 +157,8 @@ public function endTag()
if ($stackelem['sent']) {
$this->_endTag();
if (count($this->_stack) == 0 && $this->multipart) {
rewind($this->_stream);
$stat = fstat($this->_stream);
$len = $stat['size'];
$this->_stream->rewind();
$len = $this->_stream->length();

$totalCount = count($this->_parts) + 1;
$header = pack('i', $totalCount);
Expand All @@ -181,23 +180,19 @@ public function endTag()
}

// Output
fwrite($this->_tempStream, $header);
rewind($this->_stream);
while (!feof($this->_stream)) {
fwrite($this->_tempStream, fread($this->_stream, 8192));
}
$this->_tempStream->add($header);
$this->_stream->rewind();
$this->_tempStream->add($this->_stream);
foreach($this->_parts as $bp) {
if (is_resource($bp)) {
rewind($bp);
while (!feof($bp)) {
fwrite($this->_tempStream, fread($bp, 8192));
}
$this->_tempStream->add($bp);
fclose($bp);
} else {
fwrite($this->_tempStream, $bp);
$this->_tempStream->add($bp);
}
}
fclose($this->_stream);
$this->_stream->close();
$this->_stream = $this->_tempStream;
}
}
Expand Down Expand Up @@ -334,7 +329,7 @@ private function _endTag() {
*/
private function _outByte($byte)
{
fwrite($this->_stream, chr($byte));
$this->_stream->add(chr($byte));
}

/**
Expand Down Expand Up @@ -365,13 +360,9 @@ private function _outTermStr($content)
{
if (is_resource($content)) {
rewind($content);
while (!feof($content)) {
fwrite($this->_stream, fread($content, 8192));
}
} else {
fwrite($this->_stream, $content);
}
fwrite($this->_stream, chr(0));
$this->_stream->add($content);
$this->_stream->add(chr(0));
}

/**
Expand Down
11 changes: 9 additions & 2 deletions framework/ActiveSync/package.xml
Expand Up @@ -21,7 +21,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
*
*
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand Down Expand Up @@ -284,6 +284,13 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Stream</name>
<channel>pear.horde.org</channel>
<min>1.4.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Support</name>
<channel>pear.horde.org</channel>
Expand Down Expand Up @@ -1725,7 +1732,7 @@
<date>2013-09-27</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
*
*
</notes>
</release>
</changelog>
Expand Down

0 comments on commit 45f3cfb

Please sign in to comment.