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_lockinfo.php,v 1.2 2004/01/05 12:32:40 hholzgra Exp $
24 * helper class for parsing LOCK request bodies
26 * @package HTTP_WebDAV_Server
27 * @author Hartmut Holzgraefe <hholzgra@php.net>
41 * lock type, currently only "write"
49 * lock scope, "shared" or "exclusive"
57 * lock owner information
65 * flag that is set during lock owner read
70 var $collect_owner = false
;
75 * @param string path of stream to read
78 function _parse_lockinfo($path)
80 // we assume success unless problems occur
81 $this->success
= true
;
83 // remember if any input was parsed
87 $f_in = fopen($path, "r");
89 $this->success
= false
;
93 // create namespace aware parser
94 $xml_parser = xml_parser_create_ns("UTF-8", " ");
96 // set tag and data handlers
97 xml_set_element_handler($xml_parser,
98 array(&$this, "_startElement"),
99 array(&$this, "_endElement"));
100 xml_set_character_data_handler($xml_parser,
101 array(&$this, "_data"));
103 // we want a case sensitive parser
104 xml_parser_set_option($xml_parser,
105 XML_OPTION_CASE_FOLDING
, false
);
108 while($this->success
&& !feof($f_in)) {
109 $line = fgets($f_in);
110 if (is_string($line)) {
112 $this->success
&= xml_parse($xml_parser, $line, false
);
118 $this->success
&= xml_parse($xml_parser, "", true
);
121 // check if required tags where found
122 $this->success
&= !empty($this->locktype
);
123 $this->success
&= !empty($this->lockscope
);
125 // free parser resource
126 xml_parser_free($xml_parser);
128 // close input stream
136 * @param resource parser
137 * @param string tag name
138 * @param array tag attributes
142 function _startElement($parser, $name, $attrs)
144 // namespace handling
145 if (strstr($name, " ")) {
146 list($ns, $tag) = explode(" ", $name);
153 if ($this->collect_owner
) {
154 // everything within the <owner> tag needs to be collected
161 $ns_attr = " xmlns='$ns'";
164 $this->owner
.= "<$ns_short$tag$ns_attr>";
165 } else if ($ns == "DAV:") {
166 // parse only the essential tags
169 $this->locktype
= $tag;
173 $this->lockscope
= $tag;
176 $this->collect_owner
= true
;
185 * @param resource parser
190 function _data($parser, $data)
192 // only the <owner> tag has data content
193 if ($this->collect_owner
) {
194 $this->owner
.= $data;
201 * @param resource parser
202 * @param string tag name
206 function _endElement($parser, $name)
208 // namespace handling
209 if (strstr($name, " ")) {
210 list($ns, $tag) = explode(" ", $name);
217 if (($ns == "DAV:") && ($tag == "owner")) {
218 $this->collect_owner
= false
;
221 // within <owner> we have to collect everything
222 if ($this->collect_owner
) {
229 $ns_attr = " xmlns='$ns'";
232 $this->owner
.= "</$ns_short$tag$ns_attr>";