HTTP_WebDAV_Server
[ class tree: HTTP_WebDAV_Server ] [ index: HTTP_WebDAV_Server ] [ all elements ]

Source for file _parse_propfind.php

Documentation is available at _parse_propfind.php

  1. <?php // $Id$
  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. /**
  37.  * helper class for parsing PROPFIND request bodies
  38.  * 
  39.  * @package HTTP_WebDAV_Server
  40.  * @author Hartmut Holzgraefe <hholzgra@php.net>
  41.  * @version @package-version@
  42.  */
  43. {
  44.     /**
  45.      * success state flag
  46.      *
  47.      * @var bool 
  48.      * @access public
  49.      */
  50.     var $success = false;
  51.  
  52.     /**
  53.      * found properties are collected here
  54.      *
  55.      * @var array 
  56.      * @access public
  57.      */
  58.     var $props = false;
  59.  
  60.     /**
  61.      * internal tag nesting depth counter
  62.      *
  63.      * @var int 
  64.      * @access private
  65.      */
  66.     var $depth = 0;
  67.  
  68.     
  69.     /**
  70.      * constructor
  71.      *
  72.      * @access public
  73.      */
  74.     function _parse_propfind($path
  75.     {
  76.         // success state flag
  77.         $this->success = true;
  78.         
  79.         // property storage array
  80.         $this->props = array();
  81.  
  82.         // internal tag depth counter
  83.         $this->depth = 0;
  84.  
  85.         // remember if any input was parsed
  86.         $had_input = false;
  87.  
  88.         // open input stream
  89.         $f_in fopen($path"r");
  90.         if (!$f_in{
  91.             $this->success = false;
  92.             return;
  93.         }
  94.  
  95.         // create XML parser
  96.         $xml_parser xml_parser_create_ns("UTF-8"" ");
  97.  
  98.         // set tag and data handlers
  99.         xml_set_element_handler($xml_parser,
  100.                                 array(&$this"_startElement"),
  101.                                 array(&$this"_endElement"));
  102.  
  103.         // we want a case sensitive parser
  104.         xml_parser_set_option($xml_parser
  105.                               XML_OPTION_CASE_FOLDINGfalse);
  106.  
  107.  
  108.         // parse input
  109.         while ($this->success && !feof($f_in)) {
  110.             $line fgets($f_in);
  111.             if (is_string($line)) {
  112.                 $had_input = true;
  113.                 $this->success &= xml_parse($xml_parser$linefalse);
  114.             }
  115.         
  116.         
  117.         // finish parsing
  118.         if ($had_input{
  119.             $this->success &= xml_parse($xml_parser""true);
  120.         }
  121.  
  122.         // free parser
  123.         xml_parser_free($xml_parser);
  124.         
  125.         // close input stream
  126.         fclose($f_in);
  127.  
  128.         // if no input was parsed it was a request
  129.         if(!count($this->props)) $this->props = "all"// default
  130.     }
  131.     
  132.  
  133.     /**
  134.      * start tag handler
  135.      * 
  136.      * @access private
  137.      * @param  resource  parser
  138.      * @param  string    tag name
  139.      * @param  array     tag attributes
  140.      */
  141.     function _startElement($parser$name$attrs
  142.     {
  143.         // name space handling
  144.         if (strstr($name" ")) {
  145.             list($ns$tagexplode(" "$name);
  146.             if ($ns == "")
  147.                 $this->success = false;
  148.         else {
  149.             $ns  "";
  150.             $tag $name;
  151.         }
  152.  
  153.         // special tags at level 1: <allprop> and <propname>
  154.         if ($this->depth == 1{
  155.             if ($tag == "allprop")
  156.                 $this->props = "all";
  157.  
  158.             if ($tag == "propname")
  159.                 $this->props = "names";
  160.         }
  161.  
  162.         // requested properties are found at level 2
  163.         if ($this->depth == 2{
  164.             $prop = array("name" => $tag);
  165.             if ($ns)
  166.                 $prop["xmlns"$ns;
  167.             $this->props[$prop;
  168.         }
  169.  
  170.         // increment depth count
  171.         $this->depth++;
  172.     }
  173.     
  174.  
  175.     /**
  176.      * end tag handler
  177.      * 
  178.      * @access private
  179.      * @param  resource  parser
  180.      * @param  string    tag name
  181.      */
  182.     function _endElement($parser$name
  183.     {
  184.         // here we only need to decrement the depth count
  185.         $this->depth--;
  186.     }
  187. }
  188.  
  189.  
  190. ?>

Documentation generated on Mon, 11 Mar 2019 15:50:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.