PageRenderTime 62ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/filemanager/libraries/HTTP/WebDAV/Tools/_parse_proppatch.php

https://github.com/ibnoe/Microweber
PHP | 237 lines | 99 code | 30 blank | 108 comment | 25 complexity | c5fa806fc6504cf71ccd7b751b0ba74a MD5 | raw file
  1. <?php // $Id: _parse_proppatch.php 246152 2007-11-14 10:49:27Z hholzgra $
  2. /*
  3. +----------------------------------------------------------------------+
  4. | Copyright (c) 2002-2007 Christian Stocker, Hartmut Holzgraefe |
  5. | All rights reserved |
  6. | |
  7. | Redistribution and use in source and binary forms, with or without |
  8. | modification, are permitted provided that the following conditions |
  9. | are met: |
  10. | |
  11. | 1. Redistributions of source code must retain the above copyright |
  12. | notice, this list of conditions and the following disclaimer. |
  13. | 2. Redistributions in binary form must reproduce the above copyright |
  14. | notice, this list of conditions and the following disclaimer in |
  15. | the documentation and/or other materials provided with the |
  16. | distribution. |
  17. | 3. The names of the authors may not be used to endorse or promote |
  18. | products derived from this software without specific prior |
  19. | written permission. |
  20. | |
  21. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  22. | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  23. | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
  24. | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
  25. | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
  26. | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  27. | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
  28. | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
  29. | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  30. | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
  31. | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
  32. | POSSIBILITY OF SUCH DAMAGE. |
  33. +----------------------------------------------------------------------+
  34. */
  35. /**
  36. * helper class for parsing PROPPATCH request bodies
  37. *
  38. * @package HTTP_WebDAV_Server
  39. * @author Hartmut Holzgraefe <hholzgra@php.net>
  40. * @version @package-version@
  41. */
  42. class _parse_proppatch
  43. {
  44. /**
  45. *
  46. *
  47. * @var
  48. * @access
  49. */
  50. var $success;
  51. /**
  52. *
  53. *
  54. * @var
  55. * @access
  56. */
  57. var $props;
  58. /**
  59. *
  60. *
  61. * @var
  62. * @access
  63. */
  64. var $depth;
  65. /**
  66. *
  67. *
  68. * @var
  69. * @access
  70. */
  71. var $mode;
  72. /**
  73. *
  74. *
  75. * @var
  76. * @access
  77. */
  78. var $current;
  79. /**
  80. * constructor
  81. *
  82. * @param string path of input stream
  83. * @access public
  84. */
  85. function _parse_proppatch($path)
  86. {
  87. $this->success = true;
  88. $this->depth = 0;
  89. $this->props = array();
  90. $had_input = false;
  91. $f_in = fopen($path, "r");
  92. if (!$f_in) {
  93. $this->success = false;
  94. return;
  95. }
  96. $xml_parser = xml_parser_create_ns("UTF-8", " ");
  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"));
  102. xml_parser_set_option($xml_parser,
  103. XML_OPTION_CASE_FOLDING, false);
  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. if($had_input) {
  112. $this->success &= xml_parse($xml_parser, "", true);
  113. }
  114. xml_parser_free($xml_parser);
  115. fclose($f_in);
  116. }
  117. /**
  118. * tag start handler
  119. *
  120. * @param resource parser
  121. * @param string tag name
  122. * @param array tag attributes
  123. * @return void
  124. * @access private
  125. */
  126. function _startElement($parser, $name, $attrs)
  127. {
  128. if (strstr($name, " ")) {
  129. list($ns, $tag) = explode(" ", $name);
  130. if ($ns == "")
  131. $this->success = false;
  132. } else {
  133. $ns = "";
  134. $tag = $name;
  135. }
  136. if ($this->depth == 1) {
  137. $this->mode = $tag;
  138. }
  139. if ($this->depth == 3) {
  140. $prop = array("name" => $tag);
  141. $this->current = array("name" => $tag, "ns" => $ns, "status"=> 200);
  142. if ($this->mode == "set") {
  143. $this->current["val"] = ""; // default set val
  144. }
  145. }
  146. if ($this->depth >= 4) {
  147. $this->current["val"] .= "<$tag";
  148. if (isset($attr)) {
  149. foreach ($attr as $key => $val) {
  150. $this->current["val"] .= ' '.$key.'="'.str_replace('"','&quot;', $val).'"';
  151. }
  152. }
  153. $this->current["val"] .= ">";
  154. }
  155. $this->depth++;
  156. }
  157. /**
  158. * tag end handler
  159. *
  160. * @param resource parser
  161. * @param string tag name
  162. * @return void
  163. * @access private
  164. */
  165. function _endElement($parser, $name)
  166. {
  167. if (strstr($name, " ")) {
  168. list($ns, $tag) = explode(" ", $name);
  169. if ($ns == "")
  170. $this->success = false;
  171. } else {
  172. $ns = "";
  173. $tag = $name;
  174. }
  175. $this->depth--;
  176. if ($this->depth >= 4) {
  177. $this->current["val"] .= "</$tag>";
  178. }
  179. if ($this->depth == 3) {
  180. if (isset($this->current)) {
  181. $this->props[] = $this->current;
  182. unset($this->current);
  183. }
  184. }
  185. }
  186. /**
  187. * input data handler
  188. *
  189. * @param resource parser
  190. * @param string data
  191. * @return void
  192. * @access private
  193. */
  194. function _data($parser, $data)
  195. {
  196. if (isset($this->current)) {
  197. $this->current["val"] .= $data;
  198. }
  199. }
  200. }
  201. /*
  202. * Local variables:
  203. * tab-width: 4
  204. * c-basic-offset: 4
  205. * indent-tabs-mode:nil
  206. * End:
  207. */