PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/include/HTTP_WebDAV_Server/Tools/_parse_propfind.php

https://gitlab.com/tjaafar/SuiteCRM
PHP | 178 lines | 67 code | 29 blank | 82 comment | 18 complexity | a714317051491612e3d70d066e18b7b6 MD5 | raw file
  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 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/3_0.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. // +----------------------------------------------------------------------+
  19. //
  20. //
  21. /**
  22. * helper class for parsing PROPFIND request bodies
  23. *
  24. * @package HTTP_WebDAV_Server
  25. * @author Hartmut Holzgraefe <hholzgra@php.net>
  26. * @version 0.99.1dev
  27. */
  28. class _parse_propfind
  29. {
  30. /**
  31. * success state flag
  32. *
  33. * @var bool
  34. * @access public
  35. */
  36. var $success = false;
  37. /**
  38. * found properties are collected here
  39. *
  40. * @var array
  41. * @access public
  42. */
  43. var $props = false;
  44. /**
  45. * internal tag nesting depth counter
  46. *
  47. * @var int
  48. * @access private
  49. */
  50. var $depth = 0;
  51. /**
  52. * constructor
  53. *
  54. * @access public
  55. */
  56. function _parse_propfind($path)
  57. {
  58. // success state flag
  59. $this->success = true;
  60. // property storage array
  61. $this->props = array();
  62. // internal tag depth counter
  63. $this->depth = 0;
  64. // remember if any input was parsed
  65. $had_input = false;
  66. // open input stream
  67. $f_in = fopen($path, "r");
  68. if (!$f_in) {
  69. $this->success = false;
  70. return;
  71. }
  72. // create XML parser
  73. $xml_parser = xml_parser_create_ns("UTF-8", " ");
  74. // set tag and data handlers
  75. xml_set_element_handler($xml_parser,
  76. array(&$this, "_startElement"),
  77. array(&$this, "_endElement"));
  78. // we want a case sensitive parser
  79. xml_parser_set_option($xml_parser,
  80. XML_OPTION_CASE_FOLDING, false);
  81. // parse input
  82. while($this->success && !feof($f_in)) {
  83. $line = fgets($f_in);
  84. if (is_string($line)) {
  85. $had_input = true;
  86. $this->success &= xml_parse($xml_parser, $line, false);
  87. }
  88. }
  89. // finish parsing
  90. if($had_input) {
  91. $this->success &= xml_parse($xml_parser, "", true);
  92. }
  93. // free parser
  94. xml_parser_free($xml_parser);
  95. // close input stream
  96. fclose($f_in);
  97. // if no input was parsed it was a request
  98. if(!count($this->props)) $this->props = "all"; // default
  99. }
  100. /**
  101. * start tag handler
  102. *
  103. * @access private
  104. * @param resource parser
  105. * @param string tag name
  106. * @param array tag attributes
  107. */
  108. function _startElement($parser, $name, $attrs)
  109. {
  110. // name space handling
  111. if (strstr($name, " ")) {
  112. list($ns, $tag) = explode(" ", $name);
  113. if ($ns == "")
  114. $this->success = false;
  115. } else {
  116. $ns = "";
  117. $tag = $name;
  118. }
  119. // special tags at level 1: <allprop> and <propname>
  120. if ($this->depth == 1) {
  121. if ($tag == "allprop")
  122. $this->props = "all";
  123. if ($tag == "propname")
  124. $this->props = "names";
  125. }
  126. // requested properties are found at level 2
  127. if ($this->depth == 2) {
  128. $prop = array("name" => $tag);
  129. if ($ns)
  130. $prop["xmlns"] = $ns;
  131. $this->props[] = $prop;
  132. }
  133. // increment depth count
  134. $this->depth++;
  135. }
  136. /**
  137. * end tag handler
  138. *
  139. * @access private
  140. * @param resource parser
  141. * @param string tag name
  142. */
  143. function _endElement($parser, $name)
  144. {
  145. // here we only need to decrement the depth count
  146. $this->depth--;
  147. }
  148. }
  149. ?>