Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
_parse_lockinfo.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * helper class for parsing LOCK request bodies
8  *
9  * @package FDL
10  * @author Hartmut Holzgraefe <hholzgra@php.net>
11  * @version @package-version@
12  */
13 /**
14  */
15 //
16 // +----------------------------------------------------------------------+
17 // | PHP Version 4 |
18 // +----------------------------------------------------------------------+
19 // | Copyright (c) 1997-2003 The PHP Group |
20 // +----------------------------------------------------------------------+
21 // | This source file is subject to version 2.02 of the PHP license, |
22 // | that is bundled with this package in the file LICENSE, and is |
23 // | available at through the world-wide-web at |
24 // | http://www.php.net/license/2_02.txt. |
25 // | If you did not receive a copy of the PHP license and are unable to |
26 // | obtain it through the world-wide-web, please send a note to |
27 // | license@php.net so we can mail you a copy immediately. |
28 // +----------------------------------------------------------------------+
29 // | Authors: Hartmut Holzgraefe <hholzgra@php.net> |
30 // | Christian Stocker <chregu@bitflux.ch> |
31 // +----------------------------------------------------------------------+
32 //
33 // $Id: _parse_lockinfo.php,v 1.1 2006/11/22 10:33:59 eric Exp $
34 //
36 {
37  /**
38  * success state flag
39  *
40  * @var bool
41  * @access public
42  */
43  var $success = false;
44  /**
45  * lock type, currently only "write"
46  *
47  * @var string
48  * @access public
49  */
50  var $locktype = "";
51  /**
52  * lock scope, "shared" or "exclusive"
53  *
54  * @var string
55  * @access public
56  */
57  var $lockscope = "";
58  /**
59  * lock owner information
60  *
61  * @var string
62  * @access public
63  */
64  var $owner = "";
65  /**
66  * flag that is set during lock owner read
67  *
68  * @var bool
69  * @access private
70  */
71  var $collect_owner = false;
72  /**
73  * constructor
74  *
75  * @param string path of stream to read
76  * @access public
77  */
79  {
80  // we assume success unless problems occur
81  $this->success = true;
82  // remember if any input was parsed
83  $had_input = false;
84  // open stream
85  $f_in = fopen($path, "r");
86  if (!$f_in) {
87  $this->success = false;
88  return;
89  }
90  // create namespace aware parser
91  $xml_parser = xml_parser_create_ns("UTF-8", " ");
92  // set tag and data handlers
93  xml_set_element_handler($xml_parser, array(&$this,
94  "_startElement"
95  ) , array(&$this,
96  "_endElement"
97  ));
98  xml_set_character_data_handler($xml_parser, array(&$this,
99  "_data"
100  ));
101  // we want a case sensitive parser
102  xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
103  // parse input
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  // finish parsing
112  if ($had_input) {
113  $this->success&= xml_parse($xml_parser, "", true);
114  }
115  // check if required tags where found
116  $this->success&= !empty($this->locktype);
117  $this->success&= !empty($this->lockscope);
118  // free parser resource
119  xml_parser_free($xml_parser);
120  // close input stream
121  fclose($f_in);
122  }
123  /**
124  * tag start handler
125  *
126  * @param resource parser
127  * @param string tag name
128  * @param array tag attributes
129  * @return void
130  * @access private
131  */
132  function _startElement($parser, $name, $attrs)
133  {
134  // namespace handling
135  if (strstr($name, " ")) {
136  list($ns, $tag) = explode(" ", $name);
137  } else {
138  $ns = "";
139  $tag = $name;
140  }
141 
142  if ($this->collect_owner) {
143  // everything within the <owner> tag needs to be collected
144  $ns_short = "";
145  $ns_attr = "";
146  if ($ns) {
147  if ($ns == "DAV:") {
148  $ns_short = "D:";
149  } else {
150  $ns_attr = " xmlns='$ns'";
151  }
152  }
153  $this->owner.= "<$ns_short$tag$ns_attr>";
154  } else if ($ns == "DAV:") {
155  // parse only the essential tags
156  switch ($tag) {
157  case "write":
158  $this->locktype = $tag;
159  break;
160 
161  case "exclusive":
162  case "shared":
163  $this->lockscope = $tag;
164  break;
165 
166  case "owner":
167  $this->collect_owner = true;
168  break;
169  }
170  }
171  }
172  /**
173  * data handler
174  *
175  * @param resource parser
176  * @param string data
177  * @return void
178  * @access private
179  */
180  function _data($parser, $data)
181  {
182  // only the <owner> tag has data content
183  if ($this->collect_owner) {
184  $this->owner.= $data;
185  }
186  }
187  /**
188  * tag end handler
189  *
190  * @param resource parser
191  * @param string tag name
192  * @return void
193  * @access private
194  */
195  function _endElement($parser, $name)
196  {
197  // namespace handling
198  if (strstr($name, " ")) {
199  list($ns, $tag) = explode(" ", $name);
200  } else {
201  $ns = "";
202  $tag = $name;
203  }
204  // <owner> finished?
205  if (($ns == "DAV:") && ($tag == "owner")) {
206  $this->collect_owner = false;
207  }
208  // within <owner> we have to collect everything
209  if ($this->collect_owner) {
210  $ns_short = "";
211  $ns_attr = "";
212  if ($ns) {
213  if ($ns == "DAV:") {
214  $ns_short = "D:";
215  } else {
216  $ns_attr = " xmlns='$ns'";
217  }
218  }
219  $this->owner.= "</$ns_short$tag$ns_attr>";
220  }
221  }
222 }
223 ?>
$path
Definition: dav.php:39
_data($parser, $data)
_endElement($parser, $name)
_startElement($parser, $name, $attrs)
$data
← centre documentaire © anakeen