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

Source for file _parse_lockinfo.php

Documentation is available at _parse_lockinfo.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. /**
  38.  * helper class for parsing LOCK request bodies
  39.  * 
  40.  * @package HTTP_WebDAV_Server
  41.  * @author Hartmut Holzgraefe <hholzgra@php.net>
  42.  * @version @package-version@
  43.  */
  44. {
  45.     /**
  46.      * success state flag
  47.      *
  48.      * @var bool 
  49.      * @access public
  50.      */
  51.     var $success = false;
  52.  
  53.     /**
  54.      * lock type, currently only "write"
  55.      *
  56.      * @var string 
  57.      * @access public
  58.      */
  59.     var $locktype = "";
  60.  
  61.     /**
  62.      * lock scope, "shared" or "exclusive"
  63.      *
  64.      * @var string 
  65.      * @access public
  66.      */
  67.     var $lockscope = "";
  68.  
  69.     /**
  70.      * lock owner information
  71.      *
  72.      * @var string 
  73.      * @access public
  74.      */
  75.     var $owner = "";
  76.  
  77.     /**
  78.      * flag that is set during lock owner read
  79.      *
  80.      * @var bool 
  81.      * @access private
  82.      */
  83.     var $collect_owner = false;
  84.     
  85.     /**
  86.      * constructor
  87.      *
  88.      * @param  string  path of stream to read
  89.      * @access public
  90.      */
  91.     function _parse_lockinfo($path
  92.     {
  93.         // we assume success unless problems occur
  94.         $this->success = true;
  95.  
  96.         // remember if any input was parsed
  97.         $had_input = false;
  98.         
  99.         // open stream
  100.         $f_in fopen($path"r");
  101.         if (!$f_in{
  102.             $this->success = false;
  103.             return;
  104.         }
  105.  
  106.         // create namespace aware parser
  107.         $xml_parser xml_parser_create_ns("UTF-8"" ");
  108.  
  109.         // set tag and data handlers
  110.         xml_set_element_handler($xml_parser,
  111.                                 array(&$this"_startElement"),
  112.                                 array(&$this"_endElement"));
  113.         xml_set_character_data_handler($xml_parser,
  114.                                        array(&$this"_data"));
  115.  
  116.         // we want a case sensitive parser
  117.         xml_parser_set_option($xml_parser,
  118.                               XML_OPTION_CASE_FOLDINGfalse);
  119.  
  120.         // parse input
  121.         while ($this->success && !feof($f_in)) {
  122.             $line fgets($f_in);
  123.             if (is_string($line)) {
  124.                 $had_input = true;
  125.                 $this->success &= xml_parse($xml_parser$linefalse);
  126.             }
  127.         
  128.  
  129.         // finish parsing
  130.         if ($had_input{
  131.             $this->success &= xml_parse($xml_parser""true);
  132.         }
  133.  
  134.         // check if required tags where found
  135.         $this->success &= !empty($this->locktype);
  136.         $this->success &= !empty($this->lockscope);
  137.  
  138.         // free parser resource
  139.         xml_parser_free($xml_parser);
  140.  
  141.         // close input stream
  142.         fclose($f_in);      
  143.     }
  144.     
  145.  
  146.     /**
  147.      * tag start handler
  148.      *
  149.      * @param  resource  parser
  150.      * @param  string    tag name
  151.      * @param  array     tag attributes
  152.      * @return void 
  153.      * @access private
  154.      */
  155.     function _startElement($parser$name$attrs
  156.     {
  157.         // namespace handling
  158.         if (strstr($name" ")) {
  159.             list($ns$tagexplode(" "$name);
  160.         else {
  161.             $ns  "";
  162.             $tag $name;
  163.         }
  164.         
  165.   
  166.         if ($this->collect_owner{
  167.             // everything within the <owner> tag needs to be collected
  168.             $ns_short "";
  169.             $ns_attr  "";
  170.             if ($ns{
  171.                 if ($ns == "DAV:"{
  172.                     $ns_short "D:";
  173.                 else {
  174.                     $ns_attr = " xmlns='$ns'";
  175.                 }
  176.             }
  177.             $this->owner .= "<$ns_short$tag$ns_attr>";
  178.         else if ($ns == "DAV:"{
  179.             // parse only the essential tags
  180.             switch ($tag{
  181.             case "write":
  182.                 $this->locktype = $tag;
  183.                 break;
  184.             case "exclusive":
  185.             case "shared":
  186.                 $this->lockscope = $tag;
  187.                 break;
  188.             case "owner":
  189.                 $this->collect_owner = true;
  190.                 break;
  191.             }
  192.         }
  193.     }
  194.     
  195.     /**
  196.      * data handler
  197.      *
  198.      * @param  resource  parser
  199.      * @param  string    data
  200.      * @return void 
  201.      * @access private
  202.      */
  203.     function _data($parser$data
  204.     {
  205.         // only the <owner> tag has data content
  206.         if ($this->collect_owner{
  207.             $this->owner .= $data;
  208.         }
  209.     }
  210.  
  211.     /**
  212.      * tag end handler
  213.      *
  214.      * @param  resource  parser
  215.      * @param  string    tag name
  216.      * @return void 
  217.      * @access private
  218.      */
  219.     function _endElement($parser$name
  220.     {
  221.         // namespace handling
  222.         if (strstr($name" ")) {
  223.             list($ns$tagexplode(" "$name);
  224.         else {
  225.             $ns  "";
  226.             $tag $name;
  227.         }
  228.  
  229.         // <owner> finished?
  230.         if (($ns == "DAV:"&& ($tag == "owner")) {
  231.             $this->collect_owner = false;
  232.         }
  233.  
  234.         // within <owner> we have to collect everything
  235.         if ($this->collect_owner{
  236.             $ns_short "";
  237.             $ns_attr  "";
  238.             if ($ns{
  239.                 if ($ns == "DAV:"{
  240.                     $ns_short "D:";
  241.                 else {
  242.                     $ns_attr = " xmlns='$ns'";
  243.                 }
  244.             }
  245.             $this->owner .= "</$ns_short$tag$ns_attr>";
  246.         }
  247.     }
  248. }
  249.  
  250. ?>

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