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