diff options
author | Jack Bates <jablko@users.sourceforge.net> | 2006-04-13 05:10:24 +0000 |
---|---|---|
committer | Jack Bates <jablko@users.sourceforge.net> | 2006-04-13 05:10:24 +0000 |
commit | 428ef55248c513015bc3233cf62c0e9db0dfbb3a (patch) | |
tree | 05ded9ab63ef157aded0ca1075607ae7da49945c /lib/HTTP/CalDAV/Tools/ReportParser.php | |
parent | 4ec912ca0ff14694f7cc8ae7d6a01d084847a5f9 (diff) | |
download | phpicalendar-428ef55248c513015bc3233cf62c0e9db0dfbb3a.tar.gz phpicalendar-428ef55248c513015bc3233cf62c0e9db0dfbb3a.tar.bz2 phpicalendar-428ef55248c513015bc3233cf62c0e9db0dfbb3a.zip |
* Almost working preliminary REPORT support
* ReportParser successfully parses calendar-data request values
* _componentParser almost parses iCalendar files & limits by calendar-data request value
* TODO Determine whether _componentParser is rejecting valid iCalendar files
* TODO Reduce duplicate code by factoring special property handling out of propfind_response_helper
* TODO Push filtering parser into bennu?
Diffstat (limited to 'lib/HTTP/CalDAV/Tools/ReportParser.php')
-rw-r--r-- | lib/HTTP/CalDAV/Tools/ReportParser.php | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/lib/HTTP/CalDAV/Tools/ReportParser.php b/lib/HTTP/CalDAV/Tools/ReportParser.php new file mode 100644 index 0000000..9d9c9c7 --- /dev/null +++ b/lib/HTTP/CalDAV/Tools/ReportParser.php @@ -0,0 +1,251 @@ +<?php + +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ + +/** + * Helper for parsing REPORT request bodies + * + * Long description for file (if any)... + * + * PHP versions 4 & 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 & 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 HTTP + * @package HTTP_CalDAV_Server + * @author Jack Bates <ms419@freezone.co.uk> + * @copyright 2006 The PHP Group + * @license PHP License 3.0 http://www.php.net/license/3_0.txt + * @version CVS: $Id: ReportParser.php,v 1.1 2006/04/13 05:10:24 jablko Exp $ + * @link http://pear.php.net/package/HTTP_CalDAV_Server + * @see HTTP_WebDAV_Server + */ + +/** + * Helper for parsing REPORT request bodies + * + * Long description + * + * @category HTTP + * @package HTTP_CalDAV_Server + * @author Jack Bates <ms419@freezone.co.uk> + * @copyright 2006 The PHP Group + * @license PHP License 3.0 http://www.php.net/license/3_0.txt + * @version CVS: $Id: ReportParser.php,v 1.1 2006/04/13 05:10:24 jablko Exp $ + * @link http://pear.php.net/package/HTTP_CalDAV_Server + * @see HTTP_WebDAV_Server + */ +class ReportParser +{ + /** + * Success state flag + * + * @var bool + * @access public + */ + var $success = false; + + /** + * Name of the requested report + * + * @var string + * @access public + */ + var $report; + + /** + * Found properties are collected here + * + * @var array + * @access public + */ + var $props = array(); + + /** + * Stack of ancestor tag names + * + * @var array + * @access private + */ + var $_names = array(); + + /** + * Stack of component data + * + * @var array + * @access private + */ + var $_comps = array(); + + /** + * Constructor + * + * @param string path to report input data + * @access public + */ + function ReportParser($input) + { + $handle = fopen($input, 'r'); + if (!$handle) { + return; + } + + $parser = xml_parser_create_ns('UTF-8', ' '); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false); + xml_set_element_handler($parser, array(&$this, '_startElement'), + array(&$this, '_endElement')); + + $this->success = true; + while (($line = fgets($handle, 4096)) !== false) { + $this->success = xml_parse($parser, $line); + if (!$this->success) { + return; + } + } + + if (!feof($handle)) { + $this->success = false; + return; + } + + xml_parser_free($parser); + fclose($handle); + + if (empty($this->props)) { + $this->props = 'allprop'; + } + } + + /** + * Start tag handler + * + * @param object parser + * @param string tag name + * @param array tag attributes + * @access private + */ + function _startElement($parser, $name, $attrs) + { + $nameComponents = explode(' ', $name); + if (count($nameComponents) > 2) { + $this->success = false; + return; + } + + if (count($nameComponents) == 2) { + list ($ns, $name) = $nameComponents; + if (empty($ns)) { + $this->success = false; + return; + } + } + + if (empty($this->_names)) { + $this->report = $name; + $this->_names[] = $name; + return; + } + + if (count($this->_names) == 1 && + ($name == 'allprop' || $name == 'propname')) { + $this->props = $name; + $this->_names[] = $name; + return; + } + + if (count($this->_names) == 2 && end($this->_names) == 'prop') { + $prop = array('name' => $name); + + if ($ns) { + $prop['ns'] = $ns; + } + + if ($name == 'calendar-data') { + $prop['value'] = array(); + $this->_comps[] =& $prop['value']; + } + + $this->props[] = $prop; + $this->_names[] = $name; + return; + } + + if ($name == 'comp') { + end($this->_comps); + + // Gross - end returns a copy of the last value + $comp =& $this->_comps[key($this->_comps)]; + + if (!is_array($comp['comps'])) { + $comp['comps'] = array(); + } + + $comp['comps'][$attrs['name']] = array(); + $this->_comps[] =& $comp['comps'][$attrs['name']]; + $this->_names[] = $name; + return; + } + + if (end($this->_names) == 'comp' && $name == 'prop') { + end($this->_comps); + + // Gross - end returns a copy of the last value + $comp =& $this->_comps[key($this->_comps)]; + + if (!is_array($comp['props'])) { + $comp['props'] = array(); + } + + $comp['props'][] = $attrs['name']; + $this->_names[] = $name; + return; + } + + $this->_names[] = $name; + } + + /** + * End tag handler + * + * @param object parser + * @param string tag name + * @param array tag attributes + * @access private + */ + function _endElement($parser, $name) { + $nameComponents = explode(' ', $name); + if (count($nameComponents) > 2) { + $this->success = false; + return; + } + + if (count($nameComponents) == 2) { + list ($ns, $name) = $nameComponents; + if (empty($ns)) { + $this->success = false; + return; + } + } + + // Any need to pop at end of calendar-data? + if ($name == 'comp') { + array_pop($this->_comps); + } + + array_pop($this->_names); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-handling-comment-ender-p: nil + * End: + */ + +?> |