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