3 // +----------------------------------------------------------------------+
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 // +----------------------------------------------------------------------+
20 // $Id: _parse_proppatch.php,v 1.3 2004/01/05 12:41:34 hholzgra Exp $
24 * helper class for parsing PROPPATCH request bodies
26 * @package HTTP_WebDAV_Server
27 * @author Hartmut Holzgraefe <hholzgra@php.net>
30 class _parse_proppatch
75 * @param string path of input stream
78 function _parse_proppatch($path)
80 $this->success
= true
;
83 $this->props
= array();
86 $f_in = fopen($path, "r");
88 $this->success
= false
;
92 $xml_parser = xml_parser_create_ns("UTF-8", " ");
94 xml_set_element_handler($xml_parser,
95 array(&$this, "_startElement"),
96 array(&$this, "_endElement"));
98 xml_set_character_data_handler($xml_parser,
99 array(&$this, "_data"));
101 xml_parser_set_option($xml_parser,
102 XML_OPTION_CASE_FOLDING
, false
);
104 while($this->success
&& !feof($f_in)) {
105 $line = fgets($f_in);
106 if (is_string($line)) {
108 $this->success
&= xml_parse($xml_parser, $line, false
);
113 $this->success
&= xml_parse($xml_parser, "", true
);
116 xml_parser_free($xml_parser);
124 * @param resource parser
125 * @param string tag name
126 * @param array tag attributes
130 function _startElement($parser, $name, $attrs)
132 if (strstr($name, " ")) {
133 list($ns, $tag) = explode(" ", $name);
135 $this->success
= false
;
141 if ($this->depth
== 1) {
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
153 if ($this->depth
>= 4) {
154 $this->current
["val"] .= "<$tag";
155 foreach ($attr as $key => $val) {
156 $this->current
["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"';
158 $this->current
["val"] .= ">";
169 * @param resource parser
170 * @param string tag name
174 function _endElement($parser, $name)
176 if (strstr($name, " ")) {
177 list($ns, $tag) = explode(" ", $name);
179 $this->success
= false
;
187 if ($this->depth
>= 4) {
188 $this->current
["val"] .= "</$tag>";
191 if ($this->depth
== 3) {
192 if (isset($this->current
)) {
193 $this->props
[] = $this->current
;
194 unset($this->current
);
202 * @param resource parser
207 function _data($parser, $data) {
208 if (isset($this->current
)) {
209 $this->current
["val"] .= $data;