cvs: pear /OLE ChainedBlockStream.php OLE.php PPS.php /OLE/PPS File.php
| From: | Christian Schmidt | Date: | Tue, 13 Feb 2007 21:00:42 +0000 |
| Subject: | cvs: pear /OLE ChainedBlockStream.php OLE.php PPS.php /OLE/PPS File.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44658@lists.php.net to get a copy of this message | ||
schmidt Tue Feb 13 21:00:42 2007 UTC
Added files:
/pear/OLE ChainedBlockStream.php
Modified files:
/pear/OLE OLE.php PPS.php
/pear/OLE/PPS File.php
Log:
Rewrite of parser (hopefully with full BC):
Files inside OLE container are now saved in directory structure.
Parser now properly used Big Block, Small Block and Master Block Allocation Tables.
Added stream interface for reading files inside OLE container (so far the stream wrapper stores
the whole binary data block in memory - this will be fixed soon).
No changes to the parts that *generate* OLE files
http://cvs.php.net/viewvc.cgi/pear/OLE/OLE.php?r1=1.11&r2=1.12&diff_format=u Index: pear/OLE/OLE.php diff -u pear/OLE/OLE.php:1.11 pear/OLE/OLE.php:1.12 --- pear/OLE/OLE.php:1.11 Wed Jan 3 09:18:49 2007 +++ pear/OLE/OLE.php Tue Feb 13 21:00:42 2007 @@ -17,7 +17,7 @@ // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // -// $Id: OLE.php,v 1.11 2007/01/03 09:18:49 tuupola Exp $ +// $Id: OLE.php,v 1.12 2007/02/13 21:00:42 schmidt Exp $ /** @@ -31,12 +31,21 @@ define('OLE_PPS_SIZE', 0x80); require_once 'PEAR.php'; -require_once 'OLE/PPS.php'; +require_once 'OLE/PPS/File.php'; +require_once 'OLE/PPS/Root.php'; + +/** +* Array for storing OLE instances that are accessed from +* OLE_ChainedBlockStream::stream_open(). +* @var array +*/ +$GLOBALS['_OLE_INSTANCES'] = array(); /** * OLE package base class. * * @author Xavier Noguer <xnoguer@php.net> +* @author Christian Schmidt <schmidt@php.net> * @category Structures * @package OLE */ @@ -55,8 +64,37 @@ var $_list; /** + * Root directory of OLE container + * @var OLE_PPS_Root + */ + var $root; + + /** + * Big Block Allocation Table + * @var array (blockId => nextBlockId) + */ + var $bbat; + + /** + * Short Block Allocation Table + * @var array (blockId => nextBlockId) + */ + var $sbat; + + /** + * Size of big blocks. This is usually 512. + * @var int number of octets per block. + */ + var $bigBlockSize; + + /** + * Size of small blocks. This is usually 64. + * @var int number of octets per block + */ + var $smallBlockSize; + + /** * Creates a new OLE object - * Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();) * @access public */ function OLE() @@ -65,6 +103,17 @@ } /** + * Destructor (using PEAR) + * Just closes the file handle on the OLE file. + * + * @access private + */ + function _OLE() + { + fclose($this->_file_handle); + } + + /** * Reads an OLE container from the contents of the file given. * * @acces public @@ -73,58 +122,165 @@ */ function read($file) { - /* consider storing offsets as constants */ - $big_block_size_offset = 30; - $iBdbCnt_offset = 44; - $bd_start_offset = 68; - $fh = @fopen($file, "r"); - if ($fh == false) { + if (!$fh) { return $this->raiseError("Can't open file $file"); } $this->_file_handle = $fh; - /* begin reading OLE attributes */ - fseek($fh, 0); $signature = fread($fh, 8); if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) { return $this->raiseError("File doesn't seem to be an OLE container."); } - fseek($fh, $big_block_size_offset); - list(, $big_block_size_exp) = unpack("v", fread($fh, 2)); - $big_block_size = pow(2, $big_block_size_exp); - - list(, $small_block_size_exp) = unpack("v", fread($fh, 2)); - $small_block_size = pow(2, $small_block_size_exp); - $i1stBdL = ($big_block_size - 0x4C) / OLE_LONG_INT_SIZE; - - fseek($fh, $iBdbCnt_offset); - list(, $iBdbCnt) = unpack("V", fread($fh, 4)); - - list(, $pps_wk_start) = unpack("V", fread($fh, 4)); - - fseek($fh, $bd_start_offset); - list(, $bd_start) = unpack("V", fread($fh, 4)); - list(, $bd_count) = unpack("V", fread($fh, 4)); - list(, $iAll) = unpack("V", fread($fh, 4)); // this may be wrong - /* create OLE_PPS objects from */ - $ret = $this->_readPpsWks($pps_wk_start, $big_block_size); - if (PEAR::isError($ret)) { - return $ret; + fseek($fh, 28); + if (fread($fh, 2) != "\xFE\xFF") { + // This shouldn't be a problem in practice + return $this->raiseError("Only Little-Endian encoding is supported."); + } + // Size of blocks and short blocks in bytes + $this->bigBlockSize = pow(2, $this->_readInt2($fh)); + $this->smallBlockSize = pow(2, $this->_readInt2($fh)); + + // Skip UID, revision number and version number + fseek($fh, 44); + // Number of blocks in Big Block Allocation Table + $bbatBlockCount = $this->_readInt4($fh); + + // Root chain 1st block + $directoryFirstBlockId = $this->_readInt4($fh); + + // Skip unused bytes + fseek($fh, 56); + // Streams shorter than this are stored using small blocks + $this->bigBlockThreshold = $this->_readInt4($fh); + // Block id of first sector in Short Block Allocation Table + $sbatFirstBlockId = $this->_readInt4($fh); + // Number of blocks in Short Block Allocation Table + $sbbatBlockCount = $this->_readInt4($fh); + // Block id of first sector in Master Block Allocation Table + $mbatFirstBlockId = $this->_readInt4($fh); + // Number of blocks in Master Block Allocation Table + $mbbatBlockCount = $this->_readInt4($fh); + $this->bbat = array(); + + // Remaining 4 * 109 bytes of current block is beginning of Master + // Block Allocation Table + $mbatBlocks = array(); + for ($i = 0; $i < 109; $i++) { + $mbatBlocks[] = $this->_readInt4($fh); + } + + // Read rest of Master Block Allocation Table (if any is left) + $pos = $this->_getBlockOffset($mbatFirstBlockId); + for ($i = 0; $i < $mbbatBlockCount; $i++) { + fseek($fh, $pos); + for ($j = 0; $j < $this->bigBlockSize / 4 - 1; $j++) { + $mbatBlocks[] = $this->_readInt4($fh); + } + // Last block id in each block points to next block + $pos = $this->_getBlockOffset($this->_readInt4($fh)); + } + + // Read Big Block Allocation Table according to chain specified by + // $mbatBlocks + for ($i = 0; $i < $bbatBlockCount; $i++) { + $pos = $this->_getBlockOffset($mbatBlocks[$i]); + fseek($fh, $pos); + for ($j = 0 ; $j < $this->bigBlockSize / 4; $j++) { + $this->bbat[] = $this->_readInt4($fh); + } + } + + // Read short block allocation table (SBAT) + $this->sbat = array(); + $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4; + $sbatFh = $this->getStream($sbatFirstBlockId); + for ($blockId = 0; $blockId < $shortBlockCount; $blockId++) { + $this->sbat[$blockId] = $this->_readInt4($sbatFh); } + fclose($sbatFh); + + $this->_readPpsWks($directoryFirstBlockId); return true; } /** - * Destructor (using PEAR) - * Just closes the file handle on the OLE file. - * - * @access private - */ - function _OLE() + * @param int block id + * @param int byte offset from beginning of file + * @access private + */ + function _getBlockOffset($blockId) { - fclose($this->_file_handle); + return 512 + $blockId * $this->bigBlockSize; + } + + /** + * Returns a stream for use with fread() etc. External callers should + * use OLE_PPS_File::getStream(). + * @param int|PPS block id or PPS + * @return resource read-only stream + */ + function getStream($blockIdOrPps) + { + include_once 'OLE/ChainedBlockStream.php'; + static $isRegistered = false; + if (!$isRegistered) { + stream_wrapper_register('ole-chainedblockstream', + 'OLE_ChainedBlockStream'); + $isRegistered = true; + } + + // Store current instance in global array, so that it can be accessed + // in OLE_ChainedBlockStream::stream_open(). + // Object is removed from self::$instances in OLE_Stream::close(). + $GLOBALS['_OLE_INSTANCES'][] = $this; + $instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES'])); + + $path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId; + if ($blockIdOrPps instanceof OLE_PPS) { + $path .= '&blockId=' . $blockIdOrPps->_StartBlock; + $path .= '&size=' . $blockIdOrPps->Size; + } else { + $path .= '&blockId=' . $blockIdOrPps; + } + return fopen($path, 'r'); + } + + /** + * Reads a signed char. + * @param resource file handle + * @return int + * @access private + */ + function _readInt1($fh) + { + list(, $tmp) = unpack("c", fread($fh, 1)); + return $tmp; + } + + /** + * Reads an unsigned short (2 octets). + * @param resource file handle + * @return int + * @access private + */ + function _readInt2($fh) + { + list(, $tmp) = unpack("v", fread($fh, 2)); + return $tmp; + } + + /** + * Reads an unsigned long (4 octets). + * @param resource file handle + * @return int + * @access private + */ + function _readInt4($fh) + { + list(, $tmp) = unpack("V", fread($fh, 4)); + return $tmp; } /** @@ -132,59 +288,78 @@ * creates an OLE_PPS object for each one. * * @access private - * @param integer $pps_wk_start Position inside the OLE file where PPS WK's start - * @param integer $big_block_size Size of big blobks in the OLE file + * @param integer the block id of the first block * @return mixed true on success, PEAR_Error on failure */ - function _readPpsWks($pps_wk_start, $big_block_size) + function _readPpsWks($blockId) { - $pointer = ($pps_wk_start + 1) * $big_block_size; - while (1) { - fseek($this->_file_handle, $pointer); - $pps_wk = fread($this->_file_handle, OLE_PPS_SIZE); - if (strlen($pps_wk) != OLE_PPS_SIZE) { - break; // Excel likes to add a trailing byte sometimes - //return $this->raiseError("PPS at $pointer seems too short: ".strlen($pps_wk)); - } - list(, $name_length) = unpack("c", substr($pps_wk, 64, 2)); - $name = substr($pps_wk, 0, $name_length - 2); + $fh = $this->getStream($blockId); + for ($pos = 0; ; $pos += 128) { + fseek($fh, $pos, SEEK_SET); + $nameUtf16 = fread($fh, 64); + $nameLength = $this->_readInt2($fh); + $nameUtf16 = substr($nameUtf16, 0, $nameLength - 2); // Simple conversion from UTF-16LE to ISO-8859-1 - $name = str_replace("\x00", "", $name); - list(, $type) = unpack("c", substr($pps_wk, 66, 1)); - if (($type != OLE_PPS_TYPE_ROOT) && - ($type != OLE_PPS_TYPE_DIR) && - ($type != OLE_PPS_TYPE_FILE)) - { - return $this->raiseError("PPS at $pointer has unknown type: {$type}"); + $name = str_replace("\x00", "", $nameUtf16); + $type = $this->_readInt1($fh); + switch ($type) { + case OLE_PPS_TYPE_ROOT: + $pps = new OLE_PPS_Root(null, null, array()); + $this->root = $pps; + break; + case OLE_PPS_TYPE_DIR: + $pps = new OLE_PPS(null, null, null, null, null, + null, null, null, null, array()); + break; + case OLE_PPS_TYPE_FILE: + $pps = new OLE_PPS_File($name); + break; + default: + continue; } - list(, $prev) = unpack("V", substr($pps_wk, 68, 4)); - list(, $next) = unpack("V", substr($pps_wk, 72, 4)); - list(, $dir) = unpack("V", substr($pps_wk, 76, 4)); - // there is no magic number, it can take different values. - //$magic = unpack("V", strrev(substr($pps_wk, 92, 4))); - $time_1st = substr($pps_wk, 100, 8); - $time_2nd = substr($pps_wk, 108, 8); - list(, $start_block) = unpack("V", substr($pps_wk, 116, 4)); - list(, $size) = unpack("V", substr($pps_wk, 120, 4)); - - // _data member will point to position in file!! - // OLE_PPS object is created with an empty children array!! - $this->_list[] = new OLE_PPS(null, $name, $type, $prev, $next, - $dir, OLE::OLE2LocalDate($time_1st), - OLE::OLE2LocalDate($time_2nd), - ($start_block + 1) * $big_block_size, array()); - // give it a size - $this->_list[count($this->_list) - 1]->Size = $size; + fseek($fh, 1, SEEK_CUR); + $pps->Type = $type; + $pps->Name = $name; + $pps->PrevPps = $this->_readInt4($fh); + $pps->NextPps = $this->_readInt4($fh); + $pps->DirPps = $this->_readInt4($fh); + fseek($fh, 20, SEEK_CUR); + $pps->Time1st = OLE::OLE2LocalDate(fread($fh, 8)); + $pps->Time2nd = OLE::OLE2LocalDate(fread($fh, 8)); + $pps->_StartBlock = $this->_readInt4($fh); + $pps->Size = $this->_readInt4($fh); + $pps->No = count($this->_list); + $this->_list[] = $pps; + // check if the PPS tree (starting from root) is complete - if ($this->_ppsTreeComplete(0)) { + if (isset($this->root) && + $this->_ppsTreeComplete($this->root->No)) { + break; } - $pointer += OLE_PPS_SIZE; + } + fclose($fh); + + // Initialize $pps->children on directories + foreach ($this->_list as $pps) { + if ($pps->Type == OLE_PPS_TYPE_DIR || $pps->Type == OLE_PPS_TYPE_ROOT) { + $nos = array($pps->DirPps); + $pps->children = array(); + while ($nos) { + $no = array_pop($nos); + if ($no != -1) { + $childPps = $this->_list[$no]; + $nos[] = $childPps->PrevPps; + $nos[] = $childPps->NextPps; + $pps->children[] = $childPps; + } + } + } } return true; } - + /** * It checks whether the PPS tree is complete (all PPS's read) * starting with the given PPS (not necessarily root) @@ -195,21 +370,14 @@ */ function _ppsTreeComplete($index) { - if ($this->_list[$index]->NextPps != -1) { - if (!isset($this->_list[$this->_list[$index]->NextPps])) { - return false; - } else { - return $this->_ppsTreeComplete($this->_list[$index]->NextPps); - } - } - if ($this->_list[$index]->DirPps != -1) { - if (!isset($this->_list[$this->_list[$index]->DirPps])) { - return false; - } else { - return $this->_ppsTreeComplete($this->_list[$index]->DirPps); - } - } - return true; + return isset($this->_list[$index]) && + ($pps = $this->_list[$index]) && + ($pps->PrevPps == -1 || + $this->_ppsTreeComplete($pps->PrevPps)) && + ($pps->NextPps == -1 || + $this->_ppsTreeComplete($pps->NextPps)) && + ($pps->DirPps == -1 || + $this->_ppsTreeComplete($pps->DirPps)); } /** @@ -265,6 +433,7 @@ * (relative to the PPS) * @param integer $length The amount of bytes to read (at most) * @return string The binary string containing the data requested + * @see OLE_PPS_File::getStream() */ function getData($index, $position, $length) { @@ -272,11 +441,12 @@ if (!isset($this->_list[$index]) || ($position >= $this->_list[$index]->Size) || ($position < 0)) { return ''; } - // Beware!!! _data member is actually a position - fseek($this->_file_handle, $this->_list[$index]->_data + $position); - return fread($this->_file_handle, $length); + $fh = $this->getStream($this->_list[$index]); + $data = stream_get_contents($fh, $length, $position); + fclose($fh); + return $data; } - + /** * Gets the data length from a PPS * If there is no PPS for the index given, it will return 0. @@ -326,7 +496,7 @@ } // factor used for separating numbers into 4 bytes parts - $factor = pow(2,32); + $factor = pow(2, 32); // days from 1-1-1601 until the beggining of UNIX era $days = 134774; @@ -394,7 +564,7 @@ $days = 134774; // translate to seconds from beggining of UNIX era - $big_date -= $days*24*3600; + $big_date -= $days * 24 * 3600; return floor($big_date); } } http://cvs.php.net/viewvc.cgi/pear/OLE/PPS.php?r1=1.6&r2=1.7&diff_format=u Index: pear/OLE/PPS.php diff -u pear/OLE/PPS.php:1.6 pear/OLE/PPS.php:1.7 --- pear/OLE/PPS.php:1.6 Tue Mar 1 21:36:25 2005 +++ pear/OLE/PPS.php Tue Feb 13 21:00:42 2007 @@ -17,7 +17,7 @@ // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // -// $Id: PPS.php,v 1.6 2005/03/01 21:36:25 arnaud Exp $ +// $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $ require_once 'PEAR.php'; @@ -105,17 +105,24 @@ var $children = array(); /** + * Pointer to OLE container + * @var OLE + */ + var $ole; + + /** * The constructor * * @access public * @param integer $No The PPS index - * @param string $name The PPS name (in Unicode) + * @param string $name The PPS name * @param integer $type The PPS type. Dir, Root or File * @param integer $prev The index of the previous PPS * @param integer $next The index of the next PPS * @param integer $dir The index of it's first child if this is a Dir or Root PPS * @param integer $time_1st A timestamp * @param integer $time_2nd A timestamp + * @param string $data The (usually binary) source data of the PPS * @param array $children Array containing children PPS for this PPS */ function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children) http://cvs.php.net/viewvc.cgi/pear/OLE/PPS/File.php?r1=1.10&r2=1.11&diff_format=u Index: pear/OLE/PPS/File.php diff -u pear/OLE/PPS/File.php:1.10 pear/OLE/PPS/File.php:1.11 --- pear/OLE/PPS/File.php:1.10 Sat Apr 23 21:53:49 2005 +++ pear/OLE/PPS/File.php Tue Feb 13 21:00:42 2007 @@ -17,7 +17,7 @@ // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // -// $Id: File.php,v 1.10 2005/04/23 21:53:49 dufuz Exp $ +// $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $ require_once 'OLE/PPS.php'; @@ -111,5 +111,14 @@ $this->_data .= $data; } } + + /** + * Returns a stream for reading this file using fread() etc. + * @return resource a read-only stream + */ + function getStream() + { + $this->ole->getStream($this); + } } ?> http://cvs.php.net/viewvc.cgi/pear/OLE/ChainedBlockStream.php?view=markup&rev=1.1 Index: pear/OLE/ChainedBlockStream.php +++ pear/OLE/ChainedBlockStream.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * Stream wrapper for reading data stored in an OLE file. * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Structures * @package OLE * @author Christian Schmidt <schmidt@php.net> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: ChainedBlockStream.php,v 1.1 2007/02/13 21:00:42 schmidt Exp $ * @link http://pear.php.net/package/OLE * @since File available since Release 0.6.0 */ require_once 'PEAR.php'; require_once 'OLE.php'; /** * Stream wrapper for reading data stored in an OLE file. Implements methods * for PHP's stream_wrapper_register(). For creating streams using this * wrapper, use OLE_PPS_File::getStream(). * * @category Structures * @package OLE * @author Christian Schmidt <schmidt@php.net> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/OLE * @since Class available since Release 0.6.0 */ class OLE_ChainedBlockStream extends PEAR { /** * The OLE container of the file that is being read. * @var OLE */ var $ole; /** * Parameters specified by fopen(). * @var array */ var $params; /** * The binary data of the file. * @var string */ var $data; /** * The file pointer. * @var int byte offset */ var $pos; /** * Implements support for fopen(). * For creating streams using this wrapper, use OLE_PPS_File::getStream(). * @param string resource name including scheme, e.g. * ole-chainedblockstream://oleInstanceId=1 * @param string only "r" is supported * @param int mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH * @param string absolute path of the opened stream (out parameter) * @return bool true on success */ function stream_open($path, $mode, $options, &$openedPath) { if ($mode != 'r') { if ($options & STREAM_REPORT_ERRORS) { trigger_error('Only reading is supported', E_USER_WARNING); } return false; } // 25 is length of "ole-chainedblockstream://" parse_str(substr($path, 25), $this->params); if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) { if ($options & STREAM_REPORT_ERRORS) { trigger_error('OLE stream not found', E_USER_WARNING); } return false; } $this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']]; $blockId = $this->params['blockId']; $this->data = ''; if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->_StartBlock) { // Block id refers to small blocks $rootPos = $this->ole->_getBlockOffset($this->ole->root->_StartBlock); while ($blockId != -2) { $pos = $rootPos + $blockId * $this->ole->bigBlockSize; $blockId = $this->ole->sbat[$blockId]; fseek($this->ole->_file_handle, $pos); $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize); } } else { // Block id refers to big blocks while ($blockId != -2) { $pos = $this->ole->_getBlockOffset($blockId); fseek($this->ole->_file_handle, $pos); $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize); $blockId = $this->ole->bbat[$blockId]; } } if (isset($this->params['size'])) { $this->data = substr($this->data, 0, $this->params['size']); } if ($options & STREAM_USE_PATH) { $openedPath = $path; } return true; } /** * Implements support for fclose(). * @return string */ function stream_close() { $this->ole = null; unset($GLOBALS['_OLE_INSTANCES']); } /** * Implements support for fread(), fgets() etc. * @param int maximum number of bytes to read * @return string */ function stream_read($count) { if ($this->stream_eof()) { return false; } $s = substr($this->data, $this->pos, $count); $this->pos += $count; return $s; } /** * Implements support for feof(). * @return bool TRUE if the file pointer is at EOF; otherwise FALSE */ function stream_eof() { $eof = $this->pos >= strlen($this->data); // Workaround for bug in PHP 5.0.x: http://bugs.php.net/27508 if (version_compare(PHP_VERSION, '5.0', '>=') && version_compare(PHP_VERSION, '5.1', '<')) { $eof = !$eof; } return $eof; } /** * Returns the position of the file pointer, i.e. its offset into the file * stream. Implements support for ftell(). * @return int */ function stream_tell() { return $this->pos; } /** * Implements support for fseek(). * @param int byte offset * @param int SEEK_SET, SEEK_CUR or SEEK_END * @return bool */ function stream_seek($offset, $whence) { if ($whence == SEEK_SET && $offset >= 0) { $this->pos = $offset; } elseif ($whence == SEEK_CUR && -$offset <= $this->pos) { $this->pos += $offset; } elseif ($whence == SEEK_END && -$offset <= sizeof($this->data)) { $this->pos = strlen($this->data) + $offset; } else { return false; } return true; } /** * Implements support for fstat(). Currently the only supported field is * "size". * @return array */ function stream_stat() { return array( 'size' => strlen($this->data), ); } // Methods used by stream_wrapper_register() that are not implemented: // bool stream_flush ( void ) // int stream_write ( string data ) // bool rename ( string path_from, string path_to ) // bool mkdir ( string path, int mode, int options ) // bool rmdir ( string path, int options ) // bool dir_opendir ( string path, int options ) // array url_stat ( string path, int flags ) // string dir_readdir ( void ) // bool dir_rewinddir ( void ) // bool dir_closedir ( void ) } ?>
http://cvs.php.net/viewvc.cgi/pear/OLE/OLE.php?r1=1.11&r2=1.12&diff_format=u Index: pear/OLE/OLE.php diff -u pear/OLE/OLE.php:1.11 pear/OLE/OLE.php:1.12 --- pear/OLE/OLE.php:1.11 Wed Jan 3 09:18:49 2007 +++ pear/OLE/OLE.php Tue Feb 13 21:00:42 2007 @@ -17,7 +17,7 @@ // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // -// $Id: OLE.php,v 1.11 2007/01/03 09:18:49 tuupola Exp $ +// $Id: OLE.php,v 1.12 2007/02/13 21:00:42 schmidt Exp $ /** @@ -31,12 +31,21 @@ define('OLE_PPS_SIZE', 0x80); require_once 'PEAR.php'; -require_once 'OLE/PPS.php'; +require_once 'OLE/PPS/File.php'; +require_once 'OLE/PPS/Root.php'; + +/** +* Array for storing OLE instances that are accessed from +* OLE_ChainedBlockStream::stream_open(). +* @var array +*/ +$GLOBALS['_OLE_INSTANCES'] = array(); /** * OLE package base class. * * @author Xavier Noguer <xnoguer@php.net> +* @author Christian Schmidt <schmidt@php.net> * @category Structures * @package OLE */ @@ -55,8 +64,37 @@ var $_list; /** + * Root directory of OLE container + * @var OLE_PPS_Root + */ + var $root; + + /** + * Big Block Allocation Table + * @var array (blockId => nextBlockId) + */ + var $bbat; + + /** + * Short Block Allocation Table + * @var array (blockId => nextBlockId) + */ + var $sbat; + + /** + * Size of big blocks. This is usually 512. + * @var int number of octets per block. + */ + var $bigBlockSize; + + /** + * Size of small blocks. This is usually 64. + * @var int number of octets per block + */ + var $smallBlockSize; + + /** * Creates a new OLE object - * Remember to use ampersand when creating an OLE object ($my_ole =& new OLE();) * @access public */ function OLE() @@ -65,6 +103,17 @@ } /** + * Destructor (using PEAR) + * Just closes the file handle on the OLE file. + * + * @access private + */ + function _OLE() + { + fclose($this->_file_handle); + } + + /** * Reads an OLE container from the contents of the file given. * * @acces public @@ -73,58 +122,165 @@ */ function read($file) { - /* consider storing offsets as constants */ - $big_block_size_offset = 30; - $iBdbCnt_offset = 44; - $bd_start_offset = 68; - $fh = @fopen($file, "r"); - if ($fh == false) { + if (!$fh) { return $this->raiseError("Can't open file $file"); } $this->_file_handle = $fh; - /* begin reading OLE attributes */ - fseek($fh, 0); $signature = fread($fh, 8); if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" != $signature) { return $this->raiseError("File doesn't seem to be an OLE container."); } - fseek($fh, $big_block_size_offset); - list(, $big_block_size_exp) = unpack("v", fread($fh, 2)); - $big_block_size = pow(2, $big_block_size_exp); - - list(, $small_block_size_exp) = unpack("v", fread($fh, 2)); - $small_block_size = pow(2, $small_block_size_exp); - $i1stBdL = ($big_block_size - 0x4C) / OLE_LONG_INT_SIZE; - - fseek($fh, $iBdbCnt_offset); - list(, $iBdbCnt) = unpack("V", fread($fh, 4)); - - list(, $pps_wk_start) = unpack("V", fread($fh, 4)); - - fseek($fh, $bd_start_offset); - list(, $bd_start) = unpack("V", fread($fh, 4)); - list(, $bd_count) = unpack("V", fread($fh, 4)); - list(, $iAll) = unpack("V", fread($fh, 4)); // this may be wrong - /* create OLE_PPS objects from */ - $ret = $this->_readPpsWks($pps_wk_start, $big_block_size); - if (PEAR::isError($ret)) { - return $ret; + fseek($fh, 28); + if (fread($fh, 2) != "\xFE\xFF") { + // This shouldn't be a problem in practice + return $this->raiseError("Only Little-Endian encoding is supported."); + } + // Size of blocks and short blocks in bytes + $this->bigBlockSize = pow(2, $this->_readInt2($fh)); + $this->smallBlockSize = pow(2, $this->_readInt2($fh)); + + // Skip UID, revision number and version number + fseek($fh, 44); + // Number of blocks in Big Block Allocation Table + $bbatBlockCount = $this->_readInt4($fh); + + // Root chain 1st block + $directoryFirstBlockId = $this->_readInt4($fh); + + // Skip unused bytes + fseek($fh, 56); + // Streams shorter than this are stored using small blocks + $this->bigBlockThreshold = $this->_readInt4($fh); + // Block id of first sector in Short Block Allocation Table + $sbatFirstBlockId = $this->_readInt4($fh); + // Number of blocks in Short Block Allocation Table + $sbbatBlockCount = $this->_readInt4($fh); + // Block id of first sector in Master Block Allocation Table + $mbatFirstBlockId = $this->_readInt4($fh); + // Number of blocks in Master Block Allocation Table + $mbbatBlockCount = $this->_readInt4($fh); + $this->bbat = array(); + + // Remaining 4 * 109 bytes of current block is beginning of Master + // Block Allocation Table + $mbatBlocks = array(); + for ($i = 0; $i < 109; $i++) { + $mbatBlocks[] = $this->_readInt4($fh); + } + + // Read rest of Master Block Allocation Table (if any is left) + $pos = $this->_getBlockOffset($mbatFirstBlockId); + for ($i = 0; $i < $mbbatBlockCount; $i++) { + fseek($fh, $pos); + for ($j = 0; $j < $this->bigBlockSize / 4 - 1; $j++) { + $mbatBlocks[] = $this->_readInt4($fh); + } + // Last block id in each block points to next block + $pos = $this->_getBlockOffset($this->_readInt4($fh)); + } + + // Read Big Block Allocation Table according to chain specified by + // $mbatBlocks + for ($i = 0; $i < $bbatBlockCount; $i++) { + $pos = $this->_getBlockOffset($mbatBlocks[$i]); + fseek($fh, $pos); + for ($j = 0 ; $j < $this->bigBlockSize / 4; $j++) { + $this->bbat[] = $this->_readInt4($fh); + } + } + + // Read short block allocation table (SBAT) + $this->sbat = array(); + $shortBlockCount = $sbbatBlockCount * $this->bigBlockSize / 4; + $sbatFh = $this->getStream($sbatFirstBlockId); + for ($blockId = 0; $blockId < $shortBlockCount; $blockId++) { + $this->sbat[$blockId] = $this->_readInt4($sbatFh); } + fclose($sbatFh); + + $this->_readPpsWks($directoryFirstBlockId); return true; } /** - * Destructor (using PEAR) - * Just closes the file handle on the OLE file. - * - * @access private - */ - function _OLE() + * @param int block id + * @param int byte offset from beginning of file + * @access private + */ + function _getBlockOffset($blockId) { - fclose($this->_file_handle); + return 512 + $blockId * $this->bigBlockSize; + } + + /** + * Returns a stream for use with fread() etc. External callers should + * use OLE_PPS_File::getStream(). + * @param int|PPS block id or PPS + * @return resource read-only stream + */ + function getStream($blockIdOrPps) + { + include_once 'OLE/ChainedBlockStream.php'; + static $isRegistered = false; + if (!$isRegistered) { + stream_wrapper_register('ole-chainedblockstream', + 'OLE_ChainedBlockStream'); + $isRegistered = true; + } + + // Store current instance in global array, so that it can be accessed + // in OLE_ChainedBlockStream::stream_open(). + // Object is removed from self::$instances in OLE_Stream::close(). + $GLOBALS['_OLE_INSTANCES'][] = $this; + $instanceId = end(array_keys($GLOBALS['_OLE_INSTANCES'])); + + $path = 'ole-chainedblockstream://oleInstanceId=' . $instanceId; + if ($blockIdOrPps instanceof OLE_PPS) { + $path .= '&blockId=' . $blockIdOrPps->_StartBlock; + $path .= '&size=' . $blockIdOrPps->Size; + } else { + $path .= '&blockId=' . $blockIdOrPps; + } + return fopen($path, 'r'); + } + + /** + * Reads a signed char. + * @param resource file handle + * @return int + * @access private + */ + function _readInt1($fh) + { + list(, $tmp) = unpack("c", fread($fh, 1)); + return $tmp; + } + + /** + * Reads an unsigned short (2 octets). + * @param resource file handle + * @return int + * @access private + */ + function _readInt2($fh) + { + list(, $tmp) = unpack("v", fread($fh, 2)); + return $tmp; + } + + /** + * Reads an unsigned long (4 octets). + * @param resource file handle + * @return int + * @access private + */ + function _readInt4($fh) + { + list(, $tmp) = unpack("V", fread($fh, 4)); + return $tmp; } /** @@ -132,59 +288,78 @@ * creates an OLE_PPS object for each one. * * @access private - * @param integer $pps_wk_start Position inside the OLE file where PPS WK's start - * @param integer $big_block_size Size of big blobks in the OLE file + * @param integer the block id of the first block * @return mixed true on success, PEAR_Error on failure */ - function _readPpsWks($pps_wk_start, $big_block_size) + function _readPpsWks($blockId) { - $pointer = ($pps_wk_start + 1) * $big_block_size; - while (1) { - fseek($this->_file_handle, $pointer); - $pps_wk = fread($this->_file_handle, OLE_PPS_SIZE); - if (strlen($pps_wk) != OLE_PPS_SIZE) { - break; // Excel likes to add a trailing byte sometimes - //return $this->raiseError("PPS at $pointer seems too short: ".strlen($pps_wk)); - } - list(, $name_length) = unpack("c", substr($pps_wk, 64, 2)); - $name = substr($pps_wk, 0, $name_length - 2); + $fh = $this->getStream($blockId); + for ($pos = 0; ; $pos += 128) { + fseek($fh, $pos, SEEK_SET); + $nameUtf16 = fread($fh, 64); + $nameLength = $this->_readInt2($fh); + $nameUtf16 = substr($nameUtf16, 0, $nameLength - 2); // Simple conversion from UTF-16LE to ISO-8859-1 - $name = str_replace("\x00", "", $name); - list(, $type) = unpack("c", substr($pps_wk, 66, 1)); - if (($type != OLE_PPS_TYPE_ROOT) && - ($type != OLE_PPS_TYPE_DIR) && - ($type != OLE_PPS_TYPE_FILE)) - { - return $this->raiseError("PPS at $pointer has unknown type: {$type}"); + $name = str_replace("\x00", "", $nameUtf16); + $type = $this->_readInt1($fh); + switch ($type) { + case OLE_PPS_TYPE_ROOT: + $pps = new OLE_PPS_Root(null, null, array()); + $this->root = $pps; + break; + case OLE_PPS_TYPE_DIR: + $pps = new OLE_PPS(null, null, null, null, null, + null, null, null, null, array()); + break; + case OLE_PPS_TYPE_FILE: + $pps = new OLE_PPS_File($name); + break; + default: + continue; } - list(, $prev) = unpack("V", substr($pps_wk, 68, 4)); - list(, $next) = unpack("V", substr($pps_wk, 72, 4)); - list(, $dir) = unpack("V", substr($pps_wk, 76, 4)); - // there is no magic number, it can take different values. - //$magic = unpack("V", strrev(substr($pps_wk, 92, 4))); - $time_1st = substr($pps_wk, 100, 8); - $time_2nd = substr($pps_wk, 108, 8); - list(, $start_block) = unpack("V", substr($pps_wk, 116, 4)); - list(, $size) = unpack("V", substr($pps_wk, 120, 4)); - - // _data member will point to position in file!! - // OLE_PPS object is created with an empty children array!! - $this->_list[] = new OLE_PPS(null, $name, $type, $prev, $next, - $dir, OLE::OLE2LocalDate($time_1st), - OLE::OLE2LocalDate($time_2nd), - ($start_block + 1) * $big_block_size, array()); - // give it a size - $this->_list[count($this->_list) - 1]->Size = $size; + fseek($fh, 1, SEEK_CUR); + $pps->Type = $type; + $pps->Name = $name; + $pps->PrevPps = $this->_readInt4($fh); + $pps->NextPps = $this->_readInt4($fh); + $pps->DirPps = $this->_readInt4($fh); + fseek($fh, 20, SEEK_CUR); + $pps->Time1st = OLE::OLE2LocalDate(fread($fh, 8)); + $pps->Time2nd = OLE::OLE2LocalDate(fread($fh, 8)); + $pps->_StartBlock = $this->_readInt4($fh); + $pps->Size = $this->_readInt4($fh); + $pps->No = count($this->_list); + $this->_list[] = $pps; + // check if the PPS tree (starting from root) is complete - if ($this->_ppsTreeComplete(0)) { + if (isset($this->root) && + $this->_ppsTreeComplete($this->root->No)) { + break; } - $pointer += OLE_PPS_SIZE; + } + fclose($fh); + + // Initialize $pps->children on directories + foreach ($this->_list as $pps) { + if ($pps->Type == OLE_PPS_TYPE_DIR || $pps->Type == OLE_PPS_TYPE_ROOT) { + $nos = array($pps->DirPps); + $pps->children = array(); + while ($nos) { + $no = array_pop($nos); + if ($no != -1) { + $childPps = $this->_list[$no]; + $nos[] = $childPps->PrevPps; + $nos[] = $childPps->NextPps; + $pps->children[] = $childPps; + } + } + } } return true; } - + /** * It checks whether the PPS tree is complete (all PPS's read) * starting with the given PPS (not necessarily root) @@ -195,21 +370,14 @@ */ function _ppsTreeComplete($index) { - if ($this->_list[$index]->NextPps != -1) { - if (!isset($this->_list[$this->_list[$index]->NextPps])) { - return false; - } else { - return $this->_ppsTreeComplete($this->_list[$index]->NextPps); - } - } - if ($this->_list[$index]->DirPps != -1) { - if (!isset($this->_list[$this->_list[$index]->DirPps])) { - return false; - } else { - return $this->_ppsTreeComplete($this->_list[$index]->DirPps); - } - } - return true; + return isset($this->_list[$index]) && + ($pps = $this->_list[$index]) && + ($pps->PrevPps == -1 || + $this->_ppsTreeComplete($pps->PrevPps)) && + ($pps->NextPps == -1 || + $this->_ppsTreeComplete($pps->NextPps)) && + ($pps->DirPps == -1 || + $this->_ppsTreeComplete($pps->DirPps)); } /** @@ -265,6 +433,7 @@ * (relative to the PPS) * @param integer $length The amount of bytes to read (at most) * @return string The binary string containing the data requested + * @see OLE_PPS_File::getStream() */ function getData($index, $position, $length) { @@ -272,11 +441,12 @@ if (!isset($this->_list[$index]) || ($position >= $this->_list[$index]->Size) || ($position < 0)) { return ''; } - // Beware!!! _data member is actually a position - fseek($this->_file_handle, $this->_list[$index]->_data + $position); - return fread($this->_file_handle, $length); + $fh = $this->getStream($this->_list[$index]); + $data = stream_get_contents($fh, $length, $position); + fclose($fh); + return $data; } - + /** * Gets the data length from a PPS * If there is no PPS for the index given, it will return 0. @@ -326,7 +496,7 @@ } // factor used for separating numbers into 4 bytes parts - $factor = pow(2,32); + $factor = pow(2, 32); // days from 1-1-1601 until the beggining of UNIX era $days = 134774; @@ -394,7 +564,7 @@ $days = 134774; // translate to seconds from beggining of UNIX era - $big_date -= $days*24*3600; + $big_date -= $days * 24 * 3600; return floor($big_date); } } http://cvs.php.net/viewvc.cgi/pear/OLE/PPS.php?r1=1.6&r2=1.7&diff_format=u Index: pear/OLE/PPS.php diff -u pear/OLE/PPS.php:1.6 pear/OLE/PPS.php:1.7 --- pear/OLE/PPS.php:1.6 Tue Mar 1 21:36:25 2005 +++ pear/OLE/PPS.php Tue Feb 13 21:00:42 2007 @@ -17,7 +17,7 @@ // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // -// $Id: PPS.php,v 1.6 2005/03/01 21:36:25 arnaud Exp $ +// $Id: PPS.php,v 1.7 2007/02/13 21:00:42 schmidt Exp $ require_once 'PEAR.php'; @@ -105,17 +105,24 @@ var $children = array(); /** + * Pointer to OLE container + * @var OLE + */ + var $ole; + + /** * The constructor * * @access public * @param integer $No The PPS index - * @param string $name The PPS name (in Unicode) + * @param string $name The PPS name * @param integer $type The PPS type. Dir, Root or File * @param integer $prev The index of the previous PPS * @param integer $next The index of the next PPS * @param integer $dir The index of it's first child if this is a Dir or Root PPS * @param integer $time_1st A timestamp * @param integer $time_2nd A timestamp + * @param string $data The (usually binary) source data of the PPS * @param array $children Array containing children PPS for this PPS */ function OLE_PPS($No, $name, $type, $prev, $next, $dir, $time_1st, $time_2nd, $data, $children) http://cvs.php.net/viewvc.cgi/pear/OLE/PPS/File.php?r1=1.10&r2=1.11&diff_format=u Index: pear/OLE/PPS/File.php diff -u pear/OLE/PPS/File.php:1.10 pear/OLE/PPS/File.php:1.11 --- pear/OLE/PPS/File.php:1.10 Sat Apr 23 21:53:49 2005 +++ pear/OLE/PPS/File.php Tue Feb 13 21:00:42 2007 @@ -17,7 +17,7 @@ // | Based on OLE::Storage_Lite by Kawai, Takanori | // +----------------------------------------------------------------------+ // -// $Id: File.php,v 1.10 2005/04/23 21:53:49 dufuz Exp $ +// $Id: File.php,v 1.11 2007/02/13 21:00:42 schmidt Exp $ require_once 'OLE/PPS.php'; @@ -111,5 +111,14 @@ $this->_data .= $data; } } + + /** + * Returns a stream for reading this file using fread() etc. + * @return resource a read-only stream + */ + function getStream() + { + $this->ole->getStream($this); + } } ?> http://cvs.php.net/viewvc.cgi/pear/OLE/ChainedBlockStream.php?view=markup&rev=1.1 Index: pear/OLE/ChainedBlockStream.php +++ pear/OLE/ChainedBlockStream.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ /** * Stream wrapper for reading data stored in an OLE file. * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category Structures * @package OLE * @author Christian Schmidt <schmidt@php.net> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: ChainedBlockStream.php,v 1.1 2007/02/13 21:00:42 schmidt Exp $ * @link http://pear.php.net/package/OLE * @since File available since Release 0.6.0 */ require_once 'PEAR.php'; require_once 'OLE.php'; /** * Stream wrapper for reading data stored in an OLE file. Implements methods * for PHP's stream_wrapper_register(). For creating streams using this * wrapper, use OLE_PPS_File::getStream(). * * @category Structures * @package OLE * @author Christian Schmidt <schmidt@php.net> * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: @package_version@ * @link http://pear.php.net/package/OLE * @since Class available since Release 0.6.0 */ class OLE_ChainedBlockStream extends PEAR { /** * The OLE container of the file that is being read. * @var OLE */ var $ole; /** * Parameters specified by fopen(). * @var array */ var $params; /** * The binary data of the file. * @var string */ var $data; /** * The file pointer. * @var int byte offset */ var $pos; /** * Implements support for fopen(). * For creating streams using this wrapper, use OLE_PPS_File::getStream(). * @param string resource name including scheme, e.g. * ole-chainedblockstream://oleInstanceId=1 * @param string only "r" is supported * @param int mask of STREAM_REPORT_ERRORS and STREAM_USE_PATH * @param string absolute path of the opened stream (out parameter) * @return bool true on success */ function stream_open($path, $mode, $options, &$openedPath) { if ($mode != 'r') { if ($options & STREAM_REPORT_ERRORS) { trigger_error('Only reading is supported', E_USER_WARNING); } return false; } // 25 is length of "ole-chainedblockstream://" parse_str(substr($path, 25), $this->params); if (!isset($this->params['oleInstanceId'], $this->params['blockId'], $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']])) { if ($options & STREAM_REPORT_ERRORS) { trigger_error('OLE stream not found', E_USER_WARNING); } return false; } $this->ole = $GLOBALS['_OLE_INSTANCES'][$this->params['oleInstanceId']]; $blockId = $this->params['blockId']; $this->data = ''; if (isset($this->params['size']) && $this->params['size'] < $this->ole->bigBlockThreshold && $blockId != $this->ole->root->_StartBlock) { // Block id refers to small blocks $rootPos = $this->ole->_getBlockOffset($this->ole->root->_StartBlock); while ($blockId != -2) { $pos = $rootPos + $blockId * $this->ole->bigBlockSize; $blockId = $this->ole->sbat[$blockId]; fseek($this->ole->_file_handle, $pos); $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize); } } else { // Block id refers to big blocks while ($blockId != -2) { $pos = $this->ole->_getBlockOffset($blockId); fseek($this->ole->_file_handle, $pos); $this->data .= fread($this->ole->_file_handle, $this->ole->bigBlockSize); $blockId = $this->ole->bbat[$blockId]; } } if (isset($this->params['size'])) { $this->data = substr($this->data, 0, $this->params['size']); } if ($options & STREAM_USE_PATH) { $openedPath = $path; } return true; } /** * Implements support for fclose(). * @return string */ function stream_close() { $this->ole = null; unset($GLOBALS['_OLE_INSTANCES']); } /** * Implements support for fread(), fgets() etc. * @param int maximum number of bytes to read * @return string */ function stream_read($count) { if ($this->stream_eof()) { return false; } $s = substr($this->data, $this->pos, $count); $this->pos += $count; return $s; } /** * Implements support for feof(). * @return bool TRUE if the file pointer is at EOF; otherwise FALSE */ function stream_eof() { $eof = $this->pos >= strlen($this->data); // Workaround for bug in PHP 5.0.x: http://bugs.php.net/27508 if (version_compare(PHP_VERSION, '5.0', '>=') && version_compare(PHP_VERSION, '5.1', '<')) { $eof = !$eof; } return $eof; } /** * Returns the position of the file pointer, i.e. its offset into the file * stream. Implements support for ftell(). * @return int */ function stream_tell() { return $this->pos; } /** * Implements support for fseek(). * @param int byte offset * @param int SEEK_SET, SEEK_CUR or SEEK_END * @return bool */ function stream_seek($offset, $whence) { if ($whence == SEEK_SET && $offset >= 0) { $this->pos = $offset; } elseif ($whence == SEEK_CUR && -$offset <= $this->pos) { $this->pos += $offset; } elseif ($whence == SEEK_END && -$offset <= sizeof($this->data)) { $this->pos = strlen($this->data) + $offset; } else { return false; } return true; } /** * Implements support for fstat(). Currently the only supported field is * "size". * @return array */ function stream_stat() { return array( 'size' => strlen($this->data), ); } // Methods used by stream_wrapper_register() that are not implemented: // bool stream_flush ( void ) // int stream_write ( string data ) // bool rename ( string path_from, string path_to ) // bool mkdir ( string path, int mode, int options ) // bool rmdir ( string path, int options ) // bool dir_opendir ( string path, int options ) // array url_stat ( string path, int flags ) // string dir_readdir ( void ) // bool dir_rewinddir ( void ) // bool dir_closedir ( void ) } ?>