Skip to content

Commit

Permalink
More efficient/cleaner multipart output handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Sep 19, 2013
1 parent c09823a commit 373413c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions framework/ActiveSync/lib/Horde/ActiveSync.php
Expand Up @@ -820,6 +820,7 @@ public function handleRequest($cmd, $devId)
// Load the request handler to handle the request
// We must send the eas header here, since some requests may start
// output and be large enough to flush the buffer (e.g., GetAttachment)
// See Bug: 12486
$this->activeSyncHeader();
if ($cmd != 'GetAttachment') {
$this->contentTypeHeader();
Expand Down
23 changes: 15 additions & 8 deletions framework/ActiveSync/lib/Horde/ActiveSync/Wbxml/Encoder.php
Expand Up @@ -150,21 +150,28 @@ public function endTag()
$data = ob_get_contents();
ob_end_clean();
ob_start();
$blockstart = ((count($this->_parts) + 1) * 2) * 4 + 4;
$sizeinfo = pack('iii', count($this->_parts) + 1, $blockstart, $len);
$this->_logger->debug('Multipart Debug Output Total parts ' . (count($this->_parts) + 1));

$totalCount = count($this->_parts) + 1;
$header = pack('i', $totalCount);
$offset = (($totalCount * 2) * 4) + 4;
$header .= pack('ii', $offset, $len);
$offset += $len;

// start/length of parts
foreach ($this->_parts as $bp) {
$blockstart = $blockstart + $len;
if (is_resource($bp)) {
rewind($bp);
fseek($bp, 0, SEEK_END);
$len = ftell($bp);
$stat = fstat($bp);
$len = $stat['size'];
} else {
$len = strlen(bin2hex($bp)) / 2;
}
$sizeinfo .= pack('ii', $blockstart, $len);
$header .= pack('ii', $offset, $len);
$offset += $len;
}
fwrite($this->_stream, $sizeinfo);

// Output
fwrite($this->_stream, $header);
fwrite($this->_stream, $data);
foreach($this->_parts as $bp) {
if (is_resource($bp)) {
Expand Down

0 comments on commit 373413c

Please sign in to comment.