diff --git a/ktwebdav/ktwebdav.php b/ktwebdav/ktwebdav.php index dbc8484..cbdbbec 100644 --- a/ktwebdav/ktwebdav.php +++ b/ktwebdav/ktwebdav.php @@ -6,39 +6,40 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ + $webdav_pear_path = 'thirdparty/pear'; $kt_pear_path = '../thirdparty/pear'; $include_path = ini_get('include_path'); - ini_set('include_path', $kt_pear_path . PATH_SEPARATOR . $include_path); + ini_set('include_path', $webdav_pear_path . PATH_SEPARATOR . $kt_pear_path . PATH_SEPARATOR . $include_path); require_once "lib/KTWebDAVServer.inc.php"; $ktwebdav = new KTWebDAVServer(); diff --git a/thirdparty/pear/HTTP/WebDAV/Server.php b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Server.php index 8e200c9..76d7135 100755 --- a/thirdparty/pear/HTTP/WebDAV/Server.php +++ b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Server.php @@ -17,22 +17,20 @@ // | Christian Stocker | // +----------------------------------------------------------------------+ // -// $Id$ +// $Id: Server.php,v 1.56 2006/10/10 11:53:16 hholzgra Exp $ // require_once "HTTP/WebDAV/Tools/_parse_propfind.php"; require_once "HTTP/WebDAV/Tools/_parse_proppatch.php"; require_once "HTTP/WebDAV/Tools/_parse_lockinfo.php"; - - /** * Virtual base class for implementing WebDAV servers * * WebDAV server base class, needs to be extended to do useful work * * @package HTTP_WebDAV_Server - * @author Hartmut Holzgraefe - * @version 0.99.1dev + * @author Hartmut Holzgraefe + * @version @package_version@ */ class HTTP_WebDAV_Server { @@ -44,8 +42,8 @@ class HTTP_WebDAV_Server * @var string */ var $uri; - - + + /** * base URI for this request * @@ -96,6 +94,16 @@ class HTTP_WebDAV_Server */ var $_prop_encoding = "utf-8"; + /** + * Copy of $_SERVER superglobal array + * + * Derived classes may extend the constructor to + * modify its contents + * + * @var array + */ + var $_SERVER; + // }}} // {{{ Constructor @@ -109,6 +117,10 @@ class HTTP_WebDAV_Server { // PHP messages destroy XML output -> switch them off ini_set("display_errors", 0); + + // copy $_SERVER variables to local _SERVER array + // so that derived classes can simply modify these + $this->_SERVER = $_SERVER; } // }}} @@ -124,22 +136,53 @@ class HTTP_WebDAV_Server */ function ServeRequest() { + // prevent warning in litmus check 'delete_fragment' + if (strstr($this->_SERVER["REQUEST_URI"], '#')) { + $this->http_status("400 Bad Request"); + return; + } + // default uri is the complete request uri - $uri = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:"); - $uri.= "//$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]"; + $uri = (@$this->_SERVER["HTTPS"] === "on" ? "https:" : "http:"); + $uri.= "//$this->_SERVER[HTTP_HOST]$this->_SERVER[SCRIPT_NAME]"; + $path_info = empty($this->_SERVER["PATH_INFO"]) ? "/" : $this->_SERVER["PATH_INFO"]; + $this->base_uri = $uri; - $this->uri = $uri . $_SERVER["PATH_INFO"]; + $this->uri = $uri . $path_info; + // set path + $this->path = $this->_urldecode($path_info); + if (!strlen($this->path)) { + if ($this->_SERVER["REQUEST_METHOD"] == "GET") { + // redirect clients that try to GET a collection + // WebDAV clients should never try this while + // regular HTTP clients might ... + header("Location: ".$this->base_uri."/"); + return; + } else { + // if a WebDAV client didn't give a path we just assume '/' + $this->path = "/"; + } + } + + if (ini_get("magic_quotes_gpc")) { + $this->path = stripslashes($this->path); + } + + // identify ourselves if (empty($this->dav_powered_by)) { header("X-Dav-Powered-By: PHP class: ".get_class($this)); } else { - header("X-Dav-Powered-By: ".$this->dav_powered_by ); + header("X-Dav-Powered-By: ".$this->dav_powered_by); } // check authentication - if (!$this->_check_auth()) { + // for the motivation for not checking OPTIONS requests on / see + // http://pear.php.net/bugs/bug.php?id=5363 + if ( ( !(($this->_SERVER['REQUEST_METHOD'] == 'OPTIONS') && ($this->path == "/"))) + && (!$this->_check_auth())) { // RFC2518 says we must use Digest instead of Basic // but Microsoft Clients do not support Digest // and we don't support NTLM and Kerberos @@ -154,33 +197,12 @@ class HTTP_WebDAV_Server } // check - if(! $this->_check_if_header_conditions()) { - $this->http_status("412 Precondition failed"); + if (! $this->_check_if_header_conditions()) { return; } - // set path - $this->path = $this->_urldecode($_SERVER["PATH_INFO"]); - if (!strlen($this->path)) { - if ($_SERVER["REQUEST_METHOD"] == "GET") { - // redirect clients that try to GET a collection - // WebDAV clients should never try this while - // regular HTTP clients might ... - header("Location: ".$this->base_uri."/"); - exit; - } else { - // if a WebDAV client didn't give a path we just assume '/' - $this->path = "/"; - } - } - - if(ini_get("magic_quotes_gpc")) { - $this->path = stripslashes($this->path); - } - - // detect requested method names - $method = strtolower($_SERVER["REQUEST_METHOD"]); + $method = strtolower($this->_SERVER["REQUEST_METHOD"]); $wrapper = "http_".$method; // activate HEAD emulation by GET if no HEAD method found @@ -191,7 +213,7 @@ class HTTP_WebDAV_Server if (method_exists($this, $wrapper) && ($method == "options" || method_exists($this, $method))) { $this->$wrapper(); // call method by name } else { // method not found/implemented - if ($_SERVER["REQUEST_METHOD"] == "LOCK") { + if ($this->_SERVER["REQUEST_METHOD"] == "LOCK") { $this->http_status("412 Precondition failed"); } else { $this->http_status("405 Method not allowed"); @@ -224,11 +246,11 @@ class HTTP_WebDAV_Server */ /* abstract - function GET(&$params) - { - // dummy entry for PHPDoc - } - */ + function GET(&$params) + { + // dummy entry for PHPDoc + } + */ // }}} @@ -244,10 +266,10 @@ class HTTP_WebDAV_Server */ /* abstract - function PUT() - { - // dummy entry for PHPDoc - } + function PUT() + { + // dummy entry for PHPDoc + } */ // }}} @@ -265,11 +287,11 @@ class HTTP_WebDAV_Server */ /* abstract - function COPY() - { - // dummy entry for PHPDoc - } - */ + function COPY() + { + // dummy entry for PHPDoc + } + */ // }}} @@ -286,11 +308,11 @@ class HTTP_WebDAV_Server */ /* abstract - function MOVE() - { - // dummy entry for PHPDoc - } - */ + function MOVE() + { + // dummy entry for PHPDoc + } + */ // }}} @@ -307,11 +329,11 @@ class HTTP_WebDAV_Server */ /* abstract - function DELETE() - { - // dummy entry for PHPDoc - } - */ + function DELETE() + { + // dummy entry for PHPDoc + } + */ // }}} // {{{ PROPFIND() @@ -327,11 +349,11 @@ class HTTP_WebDAV_Server */ /* abstract - function PROPFIND() - { - // dummy entry for PHPDoc - } - */ + function PROPFIND() + { + // dummy entry for PHPDoc + } + */ // }}} @@ -348,11 +370,11 @@ class HTTP_WebDAV_Server */ /* abstract - function PROPPATCH() - { - // dummy entry for PHPDoc - } - */ + function PROPPATCH() + { + // dummy entry for PHPDoc + } + */ // }}} // {{{ LOCK() @@ -368,11 +390,11 @@ class HTTP_WebDAV_Server */ /* abstract - function LOCK() - { - // dummy entry for PHPDoc - } - */ + function LOCK() + { + // dummy entry for PHPDoc + } + */ // }}} // {{{ UNLOCK() @@ -388,11 +410,11 @@ class HTTP_WebDAV_Server */ /* abstract - function UNLOCK() - { - // dummy entry for PHPDoc - } - */ + function UNLOCK() + { + // dummy entry for PHPDoc + } + */ // }}} // }}} @@ -414,10 +436,10 @@ class HTTP_WebDAV_Server */ /* abstract - function checkAuth($type, $username, $password) - { - // dummy entry for PHPDoc - } + function checkAuth($type, $username, $password) + { + // dummy entry for PHPDoc + } */ // }}} @@ -437,11 +459,11 @@ class HTTP_WebDAV_Server */ /* abstract - function checklock($resource) - { - // dummy entry for PHPDoc - } - */ + function checklock($resource) + { + // dummy entry for PHPDoc + } + */ // }}} @@ -478,7 +500,7 @@ class HTTP_WebDAV_Server // tell clients what we found $this->http_status("200 OK"); - header("DAV: " .join("," , $dav)); + header("DAV: " .join(", ", $dav)); header("Allow: ".join(", ", $allow)); header("Content-length: 0"); @@ -498,11 +520,13 @@ class HTTP_WebDAV_Server function http_PROPFIND() { $options = Array(); + $files = Array(); + $options["path"] = $this->path; // search depth from header (default is "infinity) - if (isset($_SERVER['HTTP_DEPTH'])) { - $options["depth"] = $_SERVER["HTTP_DEPTH"]; + if (isset($this->_SERVER['HTTP_DEPTH'])) { + $options["depth"] = $this->_SERVER["HTTP_DEPTH"]; } else { $options["depth"] = "infinity"; } @@ -514,11 +538,32 @@ class HTTP_WebDAV_Server return; } $options['props'] = $propinfo->props; - + // call user handler if (!$this->PROPFIND($options, $files)) { - $this->http_status("404 Not Found"); - return; + $files = array("files" => array()); + if (method_exists($this, "checkLock")) { + // is locked? + $lock = $this->checkLock($this->path); + + if (is_array($lock) && count($lock)) { + $created = isset($lock['created']) ? $lock['created'] : time(); + $modified = isset($lock['modified']) ? $lock['modified'] : time(); + $files['files'][] = array("path" => $this->_slashify($this->path), + "props" => array($this->mkprop("displayname", $this->path), + $this->mkprop("creationdate", $created), + $this->mkprop("getlastmodified", $modified), + $this->mkprop("resourcetype", ""), + $this->mkprop("getcontenttype", ""), + $this->mkprop("getcontentlength", 0)) + ); + } + } + + if (empty($files['files'])) { + $this->http_status("404 Not Found"); + return; + } } // collect namespaces here @@ -528,7 +573,7 @@ class HTTP_WebDAV_Server $ns_defs = "xmlns:ns0=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\""; // now we loop over all returned file entries - foreach($files["files"] as $filekey => $file) { + foreach ($files["files"] as $filekey => $file) { // nothing to do if no properties were returend for a file if (!isset($file["props"]) || !is_array($file["props"])) { @@ -536,7 +581,7 @@ class HTTP_WebDAV_Server } // now loop over all returned properties - foreach($file["props"] as $key => $prop) { + foreach ($file["props"] as $key => $prop) { // as a convenience feature we do not require that user handlers // restrict returned properties to the requested ones // here we strip all unrequested entries out of the response @@ -556,9 +601,9 @@ class HTTP_WebDAV_Server $found = false; // search property name in requested properties - foreach((array)$options["props"] as $reqprop) { + foreach ((array)$options["props"] as $reqprop) { if ( $reqprop["name"] == $prop["name"] - && $reqprop["xmlns"] == $prop["ns"]) { + && @$reqprop["xmlns"] == $prop["ns"]) { $found = true; break; } @@ -587,26 +632,26 @@ class HTTP_WebDAV_Server // we also need to add empty entries for properties that were requested // but for which no values where returned by the user handler if (is_array($options['props'])) { - foreach($options["props"] as $reqprop) { - if($reqprop['name']=="") continue; // skip empty entries + foreach ($options["props"] as $reqprop) { + if ($reqprop['name']=="") continue; // skip empty entries $found = false; // check if property exists in result - foreach($file["props"] as $prop) { + foreach ($file["props"] as $prop) { if ( $reqprop["name"] == $prop["name"] - && $reqprop["xmlns"] == $prop["ns"]) { + && @$reqprop["xmlns"] == $prop["ns"]) { $found = true; break; } } if (!$found) { - if($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") { + if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") { // lockdiscovery is handled by the base class $files["files"][$filekey]["props"][] = $this->mkprop("DAV:", - "lockdiscovery" , + "lockdiscovery", $this->lockdiscovery($files["files"][$filekey]['path'])); } else { // add empty value for this property @@ -633,15 +678,18 @@ class HTTP_WebDAV_Server echo "\n"; echo "\n"; - foreach($files["files"] as $file) { + foreach ($files["files"] as $file) { // ignore empty or incomplete entries - if(!is_array($file) || empty($file) || !isset($file["path"])) continue; + if (!is_array($file) || empty($file) || !isset($file["path"])) continue; $path = $file['path']; - if(!is_string($path) || $path==="") continue; + if (!is_string($path) || $path==="") continue; echo " \n"; - $href = $this->_slashify($this->_mergePathes($_SERVER['SCRIPT_NAME'], $path)); + /* TODO right now the user implementation has to make sure + collections end in a slash, this should be done in here + by checking the resource attribute */ + $href = $this->_mergePathes($this->_SERVER['SCRIPT_NAME'], $path); echo " $href\n"; @@ -650,16 +698,16 @@ class HTTP_WebDAV_Server echo " \n"; echo " \n"; - foreach($file["props"] as $key => $prop) { + foreach ($file["props"] as $key => $prop) { if (!is_array($prop)) continue; if (!isset($prop["name"])) continue; if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) { // empty properties (cannot use empty() for check as "0" is a legal value here) - if($prop["ns"]=="DAV:") { + if ($prop["ns"]=="DAV:") { echo " \n"; - } else if(!empty($prop["ns"])) { + } else if (!empty($prop["ns"])) { echo " <".$ns_hash[$prop["ns"]].":$prop[name]/>\n"; } else { echo " <$prop[name] xmlns=\"\"/>"; @@ -669,7 +717,7 @@ class HTTP_WebDAV_Server switch ($prop["name"]) { case "creationdate": echo " " - . gmdate("Y-m-d\\TH:i:s\\Z",$prop['val']) + . gmdate("Y-m-d\\TH:i:s\\Z", $prop['val']) . "\n"; break; case "getlastmodified": @@ -718,7 +766,7 @@ class HTTP_WebDAV_Server echo " \n"; echo " \n"; - foreach($file["noprops"] as $key => $prop) { + foreach ($file["noprops"] as $key => $prop) { if ($prop["ns"] == "DAV:") { echo " \n"; } else if ($prop["ns"] == "") { @@ -752,8 +800,9 @@ class HTTP_WebDAV_Server */ function http_PROPPATCH() { - if($this->_check_lock_status($this->path)) { + if ($this->_check_lock_status($this->path)) { $options = Array(); + $options["path"] = $this->path; $propinfo = new _parse_proppatch("php://input"); @@ -774,9 +823,9 @@ class HTTP_WebDAV_Server echo "\n"; echo " \n"; - echo " ".$this->_urlencode($this->_mergePathes($_SERVER["SCRIPT_NAME"], $this->path))."\n"; + echo " ".$this->_urlencode($this->_mergePathes($this->_SERVER["SCRIPT_NAME"], $this->path))."\n"; - foreach($options["props"] as $prop) { + foreach ($options["props"] as $prop) { echo " \n"; echo " <$prop[name] xmlns=\"$prop[ns]\"/>\n"; echo " HTTP/1.1 $prop[status]\n"; @@ -810,6 +859,7 @@ class HTTP_WebDAV_Server function http_MKCOL() { $options = Array(); + $options["path"] = $this->path; $stat = $this->MKCOL($options); @@ -831,7 +881,7 @@ class HTTP_WebDAV_Server function http_GET() { // TODO check for invalid stream - $options = Array(); + $options = Array(); $options["path"] = $this->path; $this->_get_ranges($options); @@ -861,7 +911,7 @@ class HTTP_WebDAV_Server fseek($options['stream'], $range['start'], SEEK_SET); if (feof($options['stream'])) { $this->http_status("416 Requested range not satisfiable"); - exit; + return; } if (isset($range['end'])) { @@ -872,14 +922,14 @@ class HTTP_WebDAV_Server . (isset($options['size']) ? $options['size'] : "*")); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); - $size -= strlen($buffer); + $size -= strlen($buffer); echo $buffer; } } else { $this->http_status("206 partial"); if (isset($options['size'])) { header("Content-length: ".($options['size'] - $range['start'])); - header("Content-range: $start-$end/" + header("Content-range: ".$range['start']."-".$range['end']."/" . (isset($options['size']) ? $options['size'] : "*")); } fpassthru($options['stream']); @@ -894,21 +944,21 @@ class HTTP_WebDAV_Server foreach ($options['ranges'] as $range) { // TODO what if size unknown? 500? if (isset($range['start'])) { - $from = $range['start']; - $to = !empty($range['end']) ? $range['end'] : $options['size']-1; + $from = $range['start']; + $to = !empty($range['end']) ? $range['end'] : $options['size']-1; } else { $from = $options['size'] - $range['last']-1; - $to = $options['size'] -1; + $to = $options['size'] -1; } $total = isset($options['size']) ? $options['size'] : "*"; - $size = $to - $from + 1; + $size = $to - $from + 1; $this->_multipart_byterange_header($options['mimetype'], $from, $to, $total); - fseek($options['stream'], $start, SEEK_SET); + fseek($options['stream'], $from, SEEK_SET); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); - $size -= strlen($buffer); + $size -= strlen($buffer); echo $buffer; } } @@ -922,7 +972,7 @@ class HTTP_WebDAV_Server fpassthru($options['stream']); return; // no more headers } - } elseif (isset($options['data'])) { + } elseif (isset($options['data'])) { if (is_array($options['data'])) { // reply to partial request } else { @@ -936,10 +986,10 @@ class HTTP_WebDAV_Server if (!headers_sent()) { if (false === $status) { $this->http_status("404 not found"); + } else { + // TODO: check setting of headers in various code pathes above + $this->http_status("$status"); } - - // TODO: check setting of headers in various code pathes above - $this->http_status("$status"); } } @@ -953,10 +1003,10 @@ class HTTP_WebDAV_Server function _get_ranges(&$options) { // process Range: header if present - if (isset($_SERVER['HTTP_RANGE'])) { + if (isset($this->_SERVER['HTTP_RANGE'])) { // we only support standard "bytes" range specifications for now - if (ereg("bytes[[:space:]]*=[[:space:]]*(.+)", $_SERVER['HTTP_RANGE'], $matches)) { + if (preg_match('/bytes\s*=\s*(.+)/', $this->_SERVER['HTTP_RANGE'], $matches)) { $options["ranges"] = array(); // ranges are comma separated @@ -964,8 +1014,8 @@ class HTTP_WebDAV_Server // ranges are either from-to pairs or just end positions list($start, $end) = explode("-", $range); $options["ranges"][] = ($start==="") - ? array("last"=>$end) - : array("start"=>$start, "end"=>$end); + ? array("last"=>$end) + : array("start"=>$start, "end"=>$end); } } } @@ -1025,8 +1075,8 @@ class HTTP_WebDAV_Server */ function http_HEAD() { - $status = false; - $options = Array(); + $status = false; + $options = Array(); $options["path"] = $this->path; if (method_exists($this, "HEAD")) { @@ -1034,11 +1084,27 @@ class HTTP_WebDAV_Server } else if (method_exists($this, "GET")) { ob_start(); $status = $this->GET($options); + if (!isset($options['size'])) { + $options['size'] = ob_get_length(); + } ob_end_clean(); } - if($status===true) $status = "200 OK"; - if($status===false) $status = "404 Not found"; + if (!isset($options['mimetype'])) { + $options['mimetype'] = "application/octet-stream"; + } + header("Content-type: $options[mimetype]"); + + if (isset($options['mtime'])) { + header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT"); + } + + if (isset($options['size'])) { + header("Content-length: ".$options['size']); + } + + if ($status === true) $status = "200 OK"; + if ($status === false) $status = "404 Not found"; $this->http_status($status); } @@ -1056,30 +1122,30 @@ class HTTP_WebDAV_Server function http_PUT() { if ($this->_check_lock_status($this->path)) { - $options = Array(); - $options["path"] = $this->path; - $options["content_length"] = $_SERVER["CONTENT_LENGTH"]; + $options = Array(); + $options["path"] = $this->path; + $options["content_length"] = $this->_SERVER["CONTENT_LENGTH"]; // get the Content-type - if (isset($_SERVER["CONTENT_TYPE"])) { + if (isset($this->_SERVER["CONTENT_TYPE"])) { // for now we do not support any sort of multipart requests - if (!strncmp($_SERVER["CONTENT_TYPE"], "multipart/", 10)) { + if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) { $this->http_status("501 not implemented"); echo "The service does not support mulipart PUT requests"; return; } - $options["content_type"] = $_SERVER["CONTENT_TYPE"]; + $options["content_type"] = $this->_SERVER["CONTENT_TYPE"]; } else { // default content type if none given $options["content_type"] = "application/octet-stream"; } /* RFC 2616 2.6 says: "The recipient of the entity MUST NOT - ignore any Content-* (e.g. Content-Range) headers that it - does not understand or implement and MUST return a 501 - (Not Implemented) response in such cases." + ignore any Content-* (e.g. Content-Range) headers that it + does not understand or implement and MUST return a 501 + (Not Implemented) response in such cases." */ - foreach ($_SERVER as $key => $val) { + foreach ($this->_SERVER as $key => $val) { if (strncmp($key, "HTTP_CONTENT", 11)) continue; switch ($key) { case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11 @@ -1091,20 +1157,20 @@ class HTTP_WebDAV_Server case 'HTTP_CONTENT_LANGUAGE': // RFC 2616 14.12 // we assume it is not critical if this one is ignored // in the actual PUT implementation ... - $options["content_language"] = $value; + $options["content_language"] = $val; break; case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14 /* The meaning of the Content-Location header in PUT - or POST requests is undefined; servers are free - to ignore it in those cases. */ + or POST requests is undefined; servers are free + to ignore it in those cases. */ break; case 'HTTP_CONTENT_RANGE': // RFC 2616 14.16 // single byte range requests are supported // the header format is also specified in RFC 2616 14.16 // TODO we have to ensure that implementations support this or send 501 instead - if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $value, $matches)) { + if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) { $this->http_status("400 bad request"); echo "The service does only support single byte ranges"; return; @@ -1188,8 +1254,8 @@ class HTTP_WebDAV_Server function http_DELETE() { // check RFC 2518 Section 9.2, last paragraph - if (isset($_SERVER["HTTP_DEPTH"])) { - if ($_SERVER["HTTP_DEPTH"] != "infinity") { + if (isset($this->_SERVER["HTTP_DEPTH"])) { + if ($this->_SERVER["HTTP_DEPTH"] != "infinity") { $this->http_status("400 Bad Request"); return; } @@ -1198,7 +1264,7 @@ class HTTP_WebDAV_Server // check lock status if ($this->_check_lock_status($this->path)) { // ok, proceed - $options = Array(); + $options = Array(); $options["path"] = $this->path; $stat = $this->DELETE($options); @@ -1260,30 +1326,38 @@ class HTTP_WebDAV_Server */ function http_LOCK() { - $options = Array(); + $options = Array(); $options["path"] = $this->path; - if (isset($_SERVER['HTTP_DEPTH'])) { - $options["depth"] = $_SERVER["HTTP_DEPTH"]; + if (isset($this->_SERVER['HTTP_DEPTH'])) { + $options["depth"] = $this->_SERVER["HTTP_DEPTH"]; } else { $options["depth"] = "infinity"; } - if (isset($_SERVER["HTTP_TIMEOUT"])) { - $options["timeout"] = explode(",", $_SERVER["HTTP_TIMEOUT"]); + if (isset($this->_SERVER["HTTP_TIMEOUT"])) { + $options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]); } - if(empty($_SERVER['CONTENT_LENGTH']) && !empty($_SERVER['HTTP_IF'])) { + if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) { // check if locking is possible - if(!$this->_check_lock_status($this->path)) { + if (!$this->_check_lock_status($this->path)) { $this->http_status("423 Locked"); return; } // refresh lock - $options["update"] = substr($_SERVER['HTTP_IF'], 2, -2); + $options["locktoken"] = substr($this->_SERVER['HTTP_IF'], 2, -2); + $options["update"] = $options["locktoken"]; + + // setting defaults for required fields, LOCK() SHOULD overwrite these + $options['owner'] = "unknown"; + $options['scope'] = "exclusive"; + $options['type'] = "write"; + + $stat = $this->LOCK($options); - } else { + } else { // extract lock request information from request XML payload $lockinfo = new _parse_lockinfo("php://input"); if (!$lockinfo->success) { @@ -1291,34 +1365,32 @@ class HTTP_WebDAV_Server } // check if locking is possible - if(!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) { + if (!$this->_check_lock_status($this->path, $lockinfo->lockscope === "shared")) { $this->http_status("423 Locked"); return; } // new lock - $options["scope"] = $lockinfo->lockscope; - $options["type"] = $lockinfo->locktype; - $options["owner"] = $lockinfo->owner; - + $options["scope"] = $lockinfo->lockscope; + $options["type"] = $lockinfo->locktype; + $options["owner"] = $lockinfo->owner; $options["locktoken"] = $this->_new_locktoken(); $stat = $this->LOCK($options); } - if(is_bool($stat)) { + if (is_bool($stat)) { $http_stat = $stat ? "200 OK" : "423 Locked"; } else { $http_stat = $stat; } - $this->http_status($http_stat); if ($http_stat{0} == 2) { // 2xx states are ok - if($options["timeout"]) { + if ($options["timeout"]) { // more than a million is considered an absolute timestamp // less is more likely a relative value - if($options["timeout"]>1000000) { + if ($options["timeout"]>1000000) { $timeout = "Second-".($options['timeout']-time()); } else { $timeout = "Second-$options[timeout]"; @@ -1358,17 +1430,17 @@ class HTTP_WebDAV_Server */ function http_UNLOCK() { - $options = Array(); + $options = Array(); $options["path"] = $this->path; - if (isset($_SERVER['HTTP_DEPTH'])) { - $options["depth"] = $_SERVER["HTTP_DEPTH"]; + if (isset($this->_SERVER['HTTP_DEPTH'])) { + $options["depth"] = $this->_SERVER["HTTP_DEPTH"]; } else { $options["depth"] = "infinity"; } // strip surrounding <> - $options["token"] = substr(trim($_SERVER["HTTP_LOCK_TOKEN"]), 1, -1); + $options["token"] = substr(trim($this->_SERVER["HTTP_LOCK_TOKEN"]), 1, -1); // call user method $stat = $this->UNLOCK($options); @@ -1384,39 +1456,39 @@ class HTTP_WebDAV_Server function _copymove($what) { - $options = Array(); + $options = Array(); $options["path"] = $this->path; - if (isset($_SERVER["HTTP_DEPTH"])) { - $options["depth"] = $_SERVER["HTTP_DEPTH"]; + if (isset($this->_SERVER["HTTP_DEPTH"])) { + $options["depth"] = $this->_SERVER["HTTP_DEPTH"]; } else { $options["depth"] = "infinity"; } - extract(parse_url($_SERVER["HTTP_DESTINATION"])); - $path = urldecode($path); + extract(parse_url($this->_SERVER["HTTP_DESTINATION"])); + $path = urldecode($path); $http_host = $host; if (isset($port) && $port != 80) $http_host.= ":$port"; - $http_header_host = ereg_replace(":80$", "", $_SERVER["HTTP_HOST"]); + $http_header_host = preg_replace("/:80$/", "", $this->_SERVER["HTTP_HOST"]); if ($http_host == $http_header_host && - !strncmp($_SERVER["SCRIPT_NAME"], $path, - strlen($_SERVER["SCRIPT_NAME"]))) { - $options["dest"] = substr($path, strlen($_SERVER["SCRIPT_NAME"])); + !strncmp($this->_SERVER["SCRIPT_NAME"], $path, + strlen($this->_SERVER["SCRIPT_NAME"]))) { + $options["dest"] = substr($path, strlen($this->_SERVER["SCRIPT_NAME"])); if (!$this->_check_lock_status($options["dest"])) { $this->http_status("423 Locked"); return; } } else { - $options["dest_url"] = $_SERVER["HTTP_DESTINATION"]; + $options["dest_url"] = $this->_SERVER["HTTP_DESTINATION"]; } // see RFC 2518 Sections 9.6, 8.8.4 and 8.9.3 - if (isset($_SERVER["HTTP_OVERWRITE"])) { - $options["overwrite"] = $_SERVER["HTTP_OVERWRITE"] == "T"; + if (isset($this->_SERVER["HTTP_OVERWRITE"])) { + $options["overwrite"] = $this->_SERVER["HTTP_OVERWRITE"] == "T"; } else { $options["overwrite"] = true; } @@ -1443,7 +1515,7 @@ class HTTP_WebDAV_Server // all other METHODS need both a http_method() wrapper // and a method() implementation // the base class supplies wrappers only - foreach(get_class_methods($this) as $method) { + foreach (get_class_methods($this) as $method) { if (!strncmp("http_", $method, 5)) { $method = strtoupper(substr($method, 5)); if (method_exists($this, $method)) { @@ -1501,14 +1573,14 @@ class HTTP_WebDAV_Server { if (method_exists($this, "checkAuth")) { // PEAR style method name - return $this->checkAuth(@$_SERVER["AUTH_TYPE"], - @$_SERVER["PHP_AUTH_USER"], - @$_SERVER["PHP_AUTH_PW"]); + return $this->checkAuth(@$this->_SERVER["AUTH_TYPE"], + @$this->_SERVER["PHP_AUTH_USER"], + @$this->_SERVER["PHP_AUTH_PW"]); } else if (method_exists($this, "check_auth")) { // old (pre 1.0) method name - return $this->check_auth(@$_SERVER["AUTH_TYPE"], - @$_SERVER["PHP_AUTH_USER"], - @$_SERVER["PHP_AUTH_PW"]); + return $this->check_auth(@$this->_SERVER["AUTH_TYPE"], + @$this->_SERVER["PHP_AUTH_USER"], + @$this->_SERVER["PHP_AUTH_PW"]); } else { // no method found -> no authentication required return true; @@ -1588,34 +1660,34 @@ class HTTP_WebDAV_Server // now it depends on what we found switch ($c) { - case "<": - // URIs are enclosed in <...> - $pos2 = strpos($string, ">", $pos); - $uri = substr($string, $pos, $pos2 - $pos); - $pos = $pos2 + 1; - return array("URI", $uri); - - case "[": - //Etags are enclosed in [...] - if ($string{$pos} == "W") { - $type = "ETAG_WEAK"; - $pos += 2; - } else { - $type = "ETAG_STRONG"; - } - $pos2 = strpos($string, "]", $pos); - $etag = substr($string, $pos + 1, $pos2 - $pos - 2); - $pos = $pos2 + 1; - return array($type, $etag); - - case "N": - // "N" indicates negation + case "<": + // URIs are enclosed in <...> + $pos2 = strpos($string, ">", $pos); + $uri = substr($string, $pos, $pos2 - $pos); + $pos = $pos2 + 1; + return array("URI", $uri); + + case "[": + //Etags are enclosed in [...] + if ($string{$pos} == "W") { + $type = "ETAG_WEAK"; $pos += 2; - return array("NOT", "Not"); + } else { + $type = "ETAG_STRONG"; + } + $pos2 = strpos($string, "]", $pos); + $etag = substr($string, $pos + 1, $pos2 - $pos - 2); + $pos = $pos2 + 1; + return array($type, $etag); + + case "N": + // "N" indicates negation + $pos += 2; + return array("NOT", "Not"); - default: - // anything else is passed verbatim char by char - return array("CHAR", $c); + default: + // anything else is passed verbatim char by char + return array("CHAR", $c); } } @@ -1627,9 +1699,8 @@ class HTTP_WebDAV_Server */ function _if_header_parser($str) { - $pos = 0; - $len = strlen($str); - + $pos = 0; + $len = strlen($str); $uris = array(); // parser loop @@ -1639,7 +1710,7 @@ class HTTP_WebDAV_Server // check for URI if ($token[0] == "URI") { - $uri = $token[1]; // remember URI + $uri = $token[1]; // remember URI $token = $this->_if_header_lexer($str, $pos); // get next token } else { $uri = ""; @@ -1650,9 +1721,9 @@ class HTTP_WebDAV_Server return false; } - $list = array(); + $list = array(); $level = 1; - $not = ""; + $not = ""; while ($level) { $token = $this->_if_header_lexer($str, $pos); if ($token[0] == "NOT") { @@ -1660,39 +1731,39 @@ class HTTP_WebDAV_Server continue; } switch ($token[0]) { - case "CHAR": - switch ($token[1]) { - case "(": - $level++; - break; - case ")": - $level--; - break; - default: - return false; - } + case "CHAR": + switch ($token[1]) { + case "(": + $level++; break; - - case "URI": - $list[] = $not."<$token[1]>"; + case ")": + $level--; break; + default: + return false; + } + break; - case "ETAG_WEAK": - $list[] = $not."[W/'$token[1]']>"; - break; + case "URI": + $list[] = $not."<$token[1]>"; + break; - case "ETAG_STRONG": - $list[] = $not."['$token[1]']>"; - break; + case "ETAG_WEAK": + $list[] = $not."[W/'$token[1]']>"; + break; - default: - return false; + case "ETAG_STRONG": + $list[] = $not."['$token[1]']>"; + break; + + default: + return false; } $not = ""; } if (@is_array($uris[$uri])) { - $uris[$uri] = array_merge($uris[$uri],$list); + $uris[$uri] = array_merge($uris[$uri], $list); } else { $uris[$uri] = $list; } @@ -1712,26 +1783,28 @@ class HTTP_WebDAV_Server */ function _check_if_header_conditions() { - if (isset($_SERVER["HTTP_IF"])) { + if (isset($this->_SERVER["HTTP_IF"])) { $this->_if_header_uris = - $this->_if_header_parser($_SERVER["HTTP_IF"]); + $this->_if_header_parser($this->_SERVER["HTTP_IF"]); - foreach($this->_if_header_uris as $uri => $conditions) { + foreach ($this->_if_header_uris as $uri => $conditions) { if ($uri == "") { $uri = $this->uri; } // all must match $state = true; - foreach($conditions as $condition) { + foreach ($conditions as $condition) { // lock tokens may be free form (RFC2518 6.3) // but if opaquelocktokens are used (RFC2518 6.4) // we have to check the format (litmus tests this) if (!strncmp($condition, "$", $condition)) { + if (!preg_match('/^$/', $condition)) { + $this->http_status("423 Locked"); return false; } } if (!$this->_check_uri_condition($uri, $condition)) { + $this->http_status("412 Precondition failed"); $state = false; break; } @@ -1761,6 +1834,13 @@ class HTTP_WebDAV_Server { // not really implemented here, // implementations must override + + // a lock token can never be from the DAV: scheme + // litmus uses DAV:no-lock in some tests + if (!strncmp("_SERVER["HTTP_IF"]) || !strstr($this->_SERVER["HTTP_IF"], $lock["token"])) { if (!$exclusive_only || ($lock["scope"] !== "shared")) return false; } @@ -1850,7 +1930,7 @@ class HTTP_WebDAV_Server function http_status($status) { // simplified success case - if($status === true) { + if ($status === true) { $status = "200 OK"; } @@ -1918,7 +1998,8 @@ class HTTP_WebDAV_Server * @param string directory path * @returns string directory path wiht trailing slash */ - function _slashify($path) { + function _slashify($path) + { if ($path[strlen($path)-1] != '/') { $path = $path."/"; } @@ -1931,9 +2012,10 @@ class HTTP_WebDAV_Server * @param string directory path * @returns string directory path wihtout trailing slash */ - function _unslashify($path) { + function _unslashify($path) + { if ($path[strlen($path)-1] == '/') { - $path = substr($path, 0, strlen($path, 0, -1)); + $path = substr($path, 0, strlen($path) -1); } return $path; } @@ -1955,10 +2037,10 @@ class HTTP_WebDAV_Server } } - /* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ ?> diff --git a/thirdparty/pear/HTTP/WebDAV/Tools/_parse_lockinfo.php b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Tools/_parse_lockinfo.php index 4a08100..8d33ead 100644 --- a/thirdparty/pear/HTTP/WebDAV/Tools/_parse_lockinfo.php +++ b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Tools/_parse_lockinfo.php @@ -17,7 +17,7 @@ // | Christian Stocker | // +----------------------------------------------------------------------+ // -// $Id$ +// $Id: _parse_lockinfo.php,v 1.4 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -25,135 +25,135 @@ * * @package HTTP_WebDAV_Server * @author Hartmut Holzgraefe - * @version 0.99.1dev + * @version @package-version@ */ class _parse_lockinfo { - /** - * success state flag - * - * @var bool - * @access public - */ - var $success = false; - - /** - * lock type, currently only "write" - * - * @var string - * @access public - */ - var $locktype = ""; - - /** - * lock scope, "shared" or "exclusive" - * - * @var string - * @access public - */ - var $lockscope = ""; - - /** - * lock owner information - * - * @var string - * @access public - */ - var $owner = ""; - - /** - * flag that is set during lock owner read - * - * @var bool - * @access private - */ - var $collect_owner = false; - - /** - * constructor - * - * @param string path of stream to read - * @access public - */ + /** + * success state flag + * + * @var bool + * @access public + */ + var $success = false; + + /** + * lock type, currently only "write" + * + * @var string + * @access public + */ + var $locktype = ""; + + /** + * lock scope, "shared" or "exclusive" + * + * @var string + * @access public + */ + var $lockscope = ""; + + /** + * lock owner information + * + * @var string + * @access public + */ + var $owner = ""; + + /** + * flag that is set during lock owner read + * + * @var bool + * @access private + */ + var $collect_owner = false; + + /** + * constructor + * + * @param string path of stream to read + * @access public + */ function _parse_lockinfo($path) - { - // we assume success unless problems occur - $this->success = true; - - // remember if any input was parsed - $had_input = false; - - // open stream - $f_in = fopen($path, "r"); - if (!$f_in) { - $this->success = false; - return; - } - - // create namespace aware parser - $xml_parser = xml_parser_create_ns("UTF-8", " "); - - // set tag and data handlers - xml_set_element_handler($xml_parser, - array(&$this, "_startElement"), - array(&$this, "_endElement")); - xml_set_character_data_handler($xml_parser, - array(&$this, "_data")); - - // we want a case sensitive parser - xml_parser_set_option($xml_parser, - XML_OPTION_CASE_FOLDING, false); - - // parse input - while($this->success && !feof($f_in)) { - $line = fgets($f_in); - if (is_string($line)) { - $had_input = true; - $this->success &= xml_parse($xml_parser, $line, false); - } - } - - // finish parsing - if($had_input) { - $this->success &= xml_parse($xml_parser, "", true); - } - - // check if required tags where found - $this->success &= !empty($this->locktype); - $this->success &= !empty($this->lockscope); - - // free parser resource - xml_parser_free($xml_parser); - - // close input stream - fclose($f_in); - } + { + // we assume success unless problems occur + $this->success = true; + + // remember if any input was parsed + $had_input = false; + + // open stream + $f_in = fopen($path, "r"); + if (!$f_in) { + $this->success = false; + return; + } + + // create namespace aware parser + $xml_parser = xml_parser_create_ns("UTF-8", " "); + + // set tag and data handlers + xml_set_element_handler($xml_parser, + array(&$this, "_startElement"), + array(&$this, "_endElement")); + xml_set_character_data_handler($xml_parser, + array(&$this, "_data")); + + // we want a case sensitive parser + xml_parser_set_option($xml_parser, + XML_OPTION_CASE_FOLDING, false); + + // parse input + while ($this->success && !feof($f_in)) { + $line = fgets($f_in); + if (is_string($line)) { + $had_input = true; + $this->success &= xml_parse($xml_parser, $line, false); + } + } + + // finish parsing + if ($had_input) { + $this->success &= xml_parse($xml_parser, "", true); + } + + // check if required tags where found + $this->success &= !empty($this->locktype); + $this->success &= !empty($this->lockscope); + + // free parser resource + xml_parser_free($xml_parser); + + // close input stream + fclose($f_in); + } - /** - * tag start handler - * - * @param resource parser - * @param string tag name - * @param array tag attributes - * @return void - * @access private - */ + /** + * tag start handler + * + * @param resource parser + * @param string tag name + * @param array tag attributes + * @return void + * @access private + */ function _startElement($parser, $name, $attrs) { - // namespace handling + // namespace handling if (strstr($name, " ")) { list($ns, $tag) = explode(" ", $name); } else { - $ns = ""; + $ns = ""; $tag = $name; } - + if ($this->collect_owner) { - // everything within the tag needs to be collected + // everything within the tag needs to be collected $ns_short = ""; - $ns_attr = ""; + $ns_attr = ""; if ($ns) { if ($ns == "DAV:") { $ns_short = "D:"; @@ -163,75 +163,75 @@ class _parse_lockinfo } $this->owner .= "<$ns_short$tag$ns_attr>"; } else if ($ns == "DAV:") { - // parse only the essential tags + // parse only the essential tags switch ($tag) { - case "write": - $this->locktype = $tag; - break; - case "exclusive": - case "shared": - $this->lockscope = $tag; - break; - case "owner": - $this->collect_owner = true; - break; + case "write": + $this->locktype = $tag; + break; + case "exclusive": + case "shared": + $this->lockscope = $tag; + break; + case "owner": + $this->collect_owner = true; + break; } } } - - /** - * data handler - * - * @param resource parser - * @param string data - * @return void - * @access private - */ + + /** + * data handler + * + * @param resource parser + * @param string data + * @return void + * @access private + */ function _data($parser, $data) { - // only the tag has data content + // only the tag has data content if ($this->collect_owner) { $this->owner .= $data; } } - /** - * tag end handler - * - * @param resource parser - * @param string tag name - * @return void - * @access private - */ + /** + * tag end handler + * + * @param resource parser + * @param string tag name + * @return void + * @access private + */ function _endElement($parser, $name) { - // namespace handling - if (strstr($name, " ")) { - list($ns, $tag) = explode(" ", $name); - } else { - $ns = ""; - $tag = $name; - } - - // finished? - if (($ns == "DAV:") && ($tag == "owner")) { - $this->collect_owner = false; - } - - // within we have to collect everything - if ($this->collect_owner) { - $ns_short = ""; - $ns_attr = ""; - if ($ns) { - if ($ns == "DAV:") { + // namespace handling + if (strstr($name, " ")) { + list($ns, $tag) = explode(" ", $name); + } else { + $ns = ""; + $tag = $name; + } + + // finished? + if (($ns == "DAV:") && ($tag == "owner")) { + $this->collect_owner = false; + } + + // within we have to collect everything + if ($this->collect_owner) { + $ns_short = ""; + $ns_attr = ""; + if ($ns) { + if ($ns == "DAV:") { $ns_short = "D:"; - } else { - $ns_attr = " xmlns='$ns'"; - } - } - $this->owner .= ""; - } + } else { + $ns_attr = " xmlns='$ns'"; + } + } + $this->owner .= ""; + } } } -?> \ No newline at end of file +?> diff --git a/thirdparty/pear/HTTP/WebDAV/Tools/_parse_propfind.php b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Tools/_parse_propfind.php index ea16cd7..efc8b64 100644 --- a/thirdparty/pear/HTTP/WebDAV/Tools/_parse_propfind.php +++ b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Tools/_parse_propfind.php @@ -17,7 +17,7 @@ // | Christian Stocker | // +----------------------------------------------------------------------+ // -// $Id$ +// $Id: _parse_propfind.php,v 1.4 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -25,154 +25,154 @@ * * @package HTTP_WebDAV_Server * @author Hartmut Holzgraefe - * @version 0.99.1dev + * @version @package-version@ */ class _parse_propfind { - /** - * success state flag - * - * @var bool - * @access public - */ - var $success = false; - - /** - * found properties are collected here - * - * @var array - * @access public - */ - var $props = false; - - /** - * internal tag nesting depth counter - * - * @var int - * @access private - */ - var $depth = 0; - - - /** - * constructor - * - * @access public - */ - function _parse_propfind($path) - { - // success state flag - $this->success = true; - - // property storage array - $this->props = array(); - - // internal tag depth counter - $this->depth = 0; - - // remember if any input was parsed - $had_input = false; - - // open input stream - $f_in = fopen($path, "r"); - if (!$f_in) { - $this->success = false; - return; - } - - // create XML parser - $xml_parser = xml_parser_create_ns("UTF-8", " "); - - // set tag and data handlers - xml_set_element_handler($xml_parser, - array(&$this, "_startElement"), - array(&$this, "_endElement")); - - // we want a case sensitive parser - xml_parser_set_option($xml_parser, - XML_OPTION_CASE_FOLDING, false); - - - // parse input - while($this->success && !feof($f_in)) { - $line = fgets($f_in); - if (is_string($line)) { - $had_input = true; - $this->success &= xml_parse($xml_parser, $line, false); - } - } - - // finish parsing - if($had_input) { - $this->success &= xml_parse($xml_parser, "", true); - } - - // free parser - xml_parser_free($xml_parser); - - // close input stream - fclose($f_in); - - // if no input was parsed it was a request - if(!count($this->props)) $this->props = "all"; // default - } - - - /** - * start tag handler - * - * @access private - * @param resource parser - * @param string tag name - * @param array tag attributes - */ - function _startElement($parser, $name, $attrs) - { - // name space handling - if (strstr($name, " ")) { - list($ns, $tag) = explode(" ", $name); - if ($ns == "") - $this->success = false; - } else { - $ns = ""; - $tag = $name; - } - - // special tags at level 1: and - if ($this->depth == 1) { - if ($tag == "allprop") - $this->props = "all"; - - if ($tag == "propname") - $this->props = "names"; - } - - // requested properties are found at level 2 - if ($this->depth == 2) { - $prop = array("name" => $tag); - if ($ns) - $prop["xmlns"] = $ns; - $this->props[] = $prop; - } - - // increment depth count - $this->depth++; - } - - - /** - * end tag handler - * - * @access private - * @param resource parser - * @param string tag name - */ - function _endElement($parser, $name) - { - // here we only need to decrement the depth count - $this->depth--; - } + /** + * success state flag + * + * @var bool + * @access public + */ + var $success = false; + + /** + * found properties are collected here + * + * @var array + * @access public + */ + var $props = false; + + /** + * internal tag nesting depth counter + * + * @var int + * @access private + */ + var $depth = 0; + + + /** + * constructor + * + * @access public + */ + function _parse_propfind($path) + { + // success state flag + $this->success = true; + + // property storage array + $this->props = array(); + + // internal tag depth counter + $this->depth = 0; + + // remember if any input was parsed + $had_input = false; + + // open input stream + $f_in = fopen($path, "r"); + if (!$f_in) { + $this->success = false; + return; + } + + // create XML parser + $xml_parser = xml_parser_create_ns("UTF-8", " "); + + // set tag and data handlers + xml_set_element_handler($xml_parser, + array(&$this, "_startElement"), + array(&$this, "_endElement")); + + // we want a case sensitive parser + xml_parser_set_option($xml_parser, + XML_OPTION_CASE_FOLDING, false); + + + // parse input + while ($this->success && !feof($f_in)) { + $line = fgets($f_in); + if (is_string($line)) { + $had_input = true; + $this->success &= xml_parse($xml_parser, $line, false); + } + } + + // finish parsing + if ($had_input) { + $this->success &= xml_parse($xml_parser, "", true); + } + + // free parser + xml_parser_free($xml_parser); + + // close input stream + fclose($f_in); + + // if no input was parsed it was a request + if(!count($this->props)) $this->props = "all"; // default + } + + + /** + * start tag handler + * + * @access private + * @param resource parser + * @param string tag name + * @param array tag attributes + */ + function _startElement($parser, $name, $attrs) + { + // name space handling + if (strstr($name, " ")) { + list($ns, $tag) = explode(" ", $name); + if ($ns == "") + $this->success = false; + } else { + $ns = ""; + $tag = $name; + } + + // special tags at level 1: and + if ($this->depth == 1) { + if ($tag == "allprop") + $this->props = "all"; + + if ($tag == "propname") + $this->props = "names"; + } + + // requested properties are found at level 2 + if ($this->depth == 2) { + $prop = array("name" => $tag); + if ($ns) + $prop["xmlns"] = $ns; + $this->props[] = $prop; + } + + // increment depth count + $this->depth++; + } + + + /** + * end tag handler + * + * @access private + * @param resource parser + * @param string tag name + */ + function _endElement($parser, $name) + { + // here we only need to decrement the depth count + $this->depth--; + } } -?> \ No newline at end of file +?> diff --git a/thirdparty/pear/HTTP/WebDAV/Tools/_parse_proppatch.php b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Tools/_parse_proppatch.php index 006efb5..396c3e3 100644 --- a/thirdparty/pear/HTTP/WebDAV/Tools/_parse_proppatch.php +++ b/ktwebdav/thirdparty/pear/HTTP/WebDAV/Tools/_parse_proppatch.php @@ -17,7 +17,7 @@ // | Christian Stocker | // +----------------------------------------------------------------------+ // -// $Id$ +// $Id: _parse_proppatch.php,v 1.6 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -25,7 +25,7 @@ * * @package HTTP_WebDAV_Server * @author Hartmut Holzgraefe - * @version 0.99.1dev + * @version @package-version@ */ class _parse_proppatch { @@ -152,8 +152,10 @@ class _parse_proppatch if ($this->depth >= 4) { $this->current["val"] .= "<$tag"; - foreach ($attr as $key => $val) { - $this->current["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"'; + if (isset($attr)) { + foreach ($attr as $key => $val) { + $this->current["val"] .= ' '.$key.'="'.str_replace('"','"', $val).'"'; + } } $this->current["val"] .= ">"; } @@ -204,11 +206,18 @@ class _parse_proppatch * @return void * @access private */ - function _data($parser, $data) { + function _data($parser, $data) + { if (isset($this->current)) { $this->current["val"] .= $data; } } } -?> \ No newline at end of file +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */