| 1 | <?php |
| 2 | // |
| 3 | // +----------------------------------------------------------------------+ |
| 4 | // | PHP Version 4 | |
| 5 | // +----------------------------------------------------------------------+ |
| 6 | // | Copyright (c) 1997-2003 The PHP Group | |
| 7 | // +----------------------------------------------------------------------+ |
| 8 | // | This source file is subject to version 2.02 of the PHP license, | |
| 9 | // | that is bundled with this package in the file LICENSE, and is | |
| 10 | // | available at through the world-wide-web at | |
| 11 | // | http://www.php.net/license/2_02.txt. | |
| 12 | // | If you did not receive a copy of the PHP license and are unable to | |
| 13 | // | obtain it through the world-wide-web, please send a note to | |
| 14 | // | license@php.net so we can mail you a copy immediately. | |
| 15 | // +----------------------------------------------------------------------+ |
| 16 | // | Authors: Hartmut Holzgraefe <hholzgra@php.net> | |
| 17 | // | Christian Stocker <chregu@bitflux.ch> | |
| 18 | // +----------------------------------------------------------------------+ |
| 19 | // |
| 20 | // $Id: _parse_proppatch.php,v 1.3 2004/01/05 12:41:34 hholzgra Exp $ |
| 21 | // |
| 22 | |
| 23 | /** |
| 24 | * helper class for parsing PROPPATCH request bodies |
| 25 | * |
| 26 | * @package HTTP_WebDAV_Server |
| 27 | * @author Hartmut Holzgraefe <hholzgra@php.net> |
| 28 | * @version 0.99.1dev |
| 29 | */ |
| 30 | class _parse_proppatch |
| 31 | { |
| 32 | /** |
| 33 | * |
| 34 | * |
| 35 | * @var |
| 36 | * @access |
| 37 | */ |
| 38 | var $success; |
| 39 | |
| 40 | /** |
| 41 | * |
| 42 | * |
| 43 | * @var |
| 44 | * @access |
| 45 | */ |
| 46 | var $props; |
| 47 | |
| 48 | /** |
| 49 | * |
| 50 | * |
| 51 | * @var |
| 52 | * @access |
| 53 | */ |
| 54 | var $depth; |
| 55 | |
| 56 | /** |
| 57 | * |
| 58 | * |
| 59 | * @var |
| 60 | * @access |
| 61 | */ |
| 62 | var $mode; |
| 63 | |
| 64 | /** |
| 65 | * |
| 66 | * |
| 67 | * @var |
| 68 | * @access |
| 69 | */ |
| 70 | var $current; |
| 71 | |
| 72 | /** |
| 73 | * constructor |
| 74 | * |
| 75 | * @param string path of input stream |
| 76 | * @access public |
| 77 | */ |
| 78 | function _parse_proppatch($path) |
| 79 | { |
| 80 | $this->success = true; |
| 81 | |
| 82 | $this->depth = 0; |
| 83 | $this->props = array(); |
| 84 | $had_input = false; |
| 85 | |
| 86 | $f_in = fopen($path, "r"); |
| 87 | if (!$f_in) { |
| 88 | $this->success = false; |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | $xml_parser = xml_parser_create_ns("UTF-8", " "); |
| 93 | |
| 94 | xml_set_element_handler($xml_parser, |
| 95 | array(&$this, "_startElement"), |
| 96 | array(&$this, "_endElement")); |
| 97 | |
| 98 | xml_set_character_data_handler($xml_parser, |
| 99 | array(&$this, "_data")); |
| 100 | |
| 101 | xml_parser_set_option($xml_parser, |
| 102 | XML_OPTION_CASE_FOLDING, false); |
| 103 | |
| 104 | while($this->success && !feof($f_in)) { |
| 105 | $line = fgets($f_in); |
| 106 | if (is_string($line)) { |
| 107 | $had_input = true; |
| 108 | $this->success &= xml_parse($xml_parser, $line, false); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if($had_input) { |
| 113 | $this->success &= xml_parse($xml_parser, "", true); |
| 114 | } |
| 115 | |
| 116 | xml_parser_free($xml_parser); |
| 117 | |
| 118 | fclose($f_in); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * tag start handler |
| 123 | * |
| 124 | * @param resource parser |
| 125 | * @param string tag name |
| 126 | * @param array tag attributes |
| 127 | * @return void |
| 128 | * @access private |
| 129 | */ |
| 130 | function _startElement($parser, $name, $attrs) |
| 131 | { |
| 132 | if (strstr($name, " ")) { |
| 133 | list($ns, $tag) = explode(" ", $name); |
| 134 | if ($ns == "") |
| 135 | $this->success = false; |
| 136 | } else { |
| 137 | $ns = ""; |
| 138 | $tag = $name; |
| 139 | } |
| 140 | |
| 141 | if ($this->depth == 1) { |
| 142 | $this->mode = $tag; |
| 143 | } |
| 144 | |
| 145 | if ($this->depth == 3) { |
| 146 | $prop = array("name" => $tag); |
| 147 | $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200); |
| 148 | if ($this->mode == "set") { |
| 149 | $this->current["val"] = ""; // default set val |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | if ($this->depth >= 4) { |
| 154 | $this->current["val"] .= "<$tag"; |
| 155 | foreach ($attr as $key => $val) { |
| 156 | $this->current["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"'; |
| 157 | } |
| 158 | $this->current["val"] .= ">"; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | |
| 163 | $this->depth++; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * tag end handler |
| 168 | * |
| 169 | * @param resource parser |
| 170 | * @param string tag name |
| 171 | * @return void |
| 172 | * @access private |
| 173 | */ |
| 174 | function _endElement($parser, $name) |
| 175 | { |
| 176 | if (strstr($name, " ")) { |
| 177 | list($ns, $tag) = explode(" ", $name); |
| 178 | if ($ns == "") |
| 179 | $this->success = false; |
| 180 | } else { |
| 181 | $ns = ""; |
| 182 | $tag = $name; |
| 183 | } |
| 184 | |
| 185 | $this->depth--; |
| 186 | |
| 187 | if ($this->depth >= 4) { |
| 188 | $this->current["val"] .= "</$tag>"; |
| 189 | } |
| 190 | |
| 191 | if ($this->depth == 3) { |
| 192 | if (isset($this->current)) { |
| 193 | $this->props[] = $this->current; |
| 194 | unset($this->current); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * input data handler |
| 201 | * |
| 202 | * @param resource parser |
| 203 | * @param string data |
| 204 | * @return void |
| 205 | * @access private |
| 206 | */ |
| 207 | function _data($parser, $data) { |
| 208 | if (isset($this->current)) { |
| 209 | $this->current["val"] .= $data; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | ?> |