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

Source for file _parse_proppatch.php

Documentation is available at _parse_proppatch.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 PROPPATCH request bodies
  39.  * 
  40.  * @package HTTP_WebDAV_Server
  41.  * @author Hartmut Holzgraefe <hholzgra@php.net>
  42.  * @version @package-version@
  43.  */
  44. {
  45.     /**
  46.      *
  47.      * 
  48.      * @var 
  49.      * @access
  50.      */
  51.     var $success;
  52.  
  53.     /**
  54.      *
  55.      * 
  56.      * @var 
  57.      * @access
  58.      */
  59.     var $props;
  60.  
  61.     /**
  62.      *
  63.      * 
  64.      * @var 
  65.      * @access
  66.      */
  67.     var $depth;
  68.  
  69.     /**
  70.      *
  71.      * 
  72.      * @var 
  73.      * @access
  74.      */
  75.     var $mode;
  76.  
  77.     /**
  78.      *
  79.      * 
  80.      * @var 
  81.      * @access
  82.      */
  83.     var $current;
  84.  
  85.     /**
  86.      * constructor
  87.      * 
  88.      * @param  string  path of input stream
  89.      * @access public
  90.      */
  91.     function _parse_proppatch($path
  92.     {
  93.         $this->success = true;
  94.  
  95.         $this->depth = 0;
  96.         $this->props = array();
  97.         $had_input = false;
  98.  
  99.         $f_in fopen($path"r");
  100.         if (!$f_in{
  101.             $this->success = false;
  102.             return;
  103.         }
  104.  
  105.         $xml_parser xml_parser_create_ns("UTF-8"" ");
  106.  
  107.         xml_set_element_handler($xml_parser,
  108.                                 array(&$this"_startElement"),
  109.                                 array(&$this"_endElement"));
  110.  
  111.         xml_set_character_data_handler($xml_parser,
  112.                                        array(&$this"_data"));
  113.  
  114.         xml_parser_set_option($xml_parser,
  115.                               XML_OPTION_CASE_FOLDINGfalse);
  116.  
  117.         while($this->success && !feof($f_in)) {
  118.             $line fgets($f_in);
  119.             if (is_string($line)) {
  120.                 $had_input = true;
  121.                 $this->success &= xml_parse($xml_parser$linefalse);
  122.             }
  123.         
  124.         
  125.         if($had_input{
  126.             $this->success &= xml_parse($xml_parser""true);
  127.         }
  128.  
  129.         xml_parser_free($xml_parser);
  130.  
  131.         fclose($f_in);
  132.     }
  133.  
  134.     /**
  135.      * tag start handler
  136.      *
  137.      * @param  resource  parser
  138.      * @param  string    tag name
  139.      * @param  array     tag attributes
  140.      * @return void 
  141.      * @access private
  142.      */
  143.     function _startElement($parser$name$attrs
  144.     {
  145.         if (strstr($name" ")) {
  146.             list($ns$tagexplode(" "$name);
  147.             if ($ns == "")
  148.                 $this->success = false;
  149.         else {
  150.             $ns "";
  151.             $tag $name;
  152.         }
  153.  
  154.         if ($this->depth == 1{
  155.             $this->mode = $tag;
  156.         
  157.  
  158.         if ($this->depth == 3{
  159.             $prop = array("name" => $tag);
  160.             $this->current = array("name" => $tag"ns" => $ns"status"=> 200);
  161.             if ($this->mode == "set"{
  162.                 $this->current["val""";     // default set val
  163.             }
  164.         }
  165.  
  166.         if ($this->depth >= 4{
  167.             $this->current["val".= "<$tag";
  168.             if (isset($attr)) {
  169.                 foreach ($attr as $key => $val{
  170.                     $this->current["val".= ' '.$key.'="'.str_replace('"','&quot;'$val).'"';
  171.                 }
  172.             }
  173.             $this->current["val".= ">";
  174.         }
  175.  
  176.         
  177.  
  178.         $this->depth++;
  179.     }
  180.  
  181.     /**
  182.      * tag end handler
  183.      *
  184.      * @param  resource  parser
  185.      * @param  string    tag name
  186.      * @return void 
  187.      * @access private
  188.      */
  189.     function _endElement($parser$name
  190.     {
  191.         if (strstr($name" ")) {
  192.             list($ns$tagexplode(" "$name);
  193.             if ($ns == "")
  194.                 $this->success = false;
  195.         else {
  196.             $ns "";
  197.             $tag $name;
  198.         }
  199.  
  200.         $this->depth--;
  201.  
  202.         if ($this->depth >= 4{
  203.             $this->current["val".= "</$tag>";
  204.         }
  205.  
  206.         if ($this->depth == 3{
  207.             if (isset($this->current)) {
  208.                 $this->props[$this->current;
  209.                 unset($this->current);
  210.             }
  211.         }
  212.     }
  213.  
  214.     /**
  215.      * input data handler
  216.      *
  217.      * @param  resource  parser
  218.      * @param  string    data
  219.      * @return void 
  220.      * @access private
  221.      */
  222.     function _data($parser$data
  223.     {
  224.         if (isset($this->current)) {
  225.             $this->current["val".= $data;
  226.         }
  227.     }
  228. }
  229.  
  230. /*
  231.  * Local variables:
  232.  * tab-width: 4
  233.  * c-basic-offset: 4
  234.  * indent-tabs-mode:nil
  235.  * End:
  236.  */

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