cvs: pear /HTTP_WebDAV_Server Server.php /HTTP_WebDAV_Server/Server Filesystem.php /HTTP_WebDAV_Server/Tools _parse_lockinfo.php _parse_propfind.php
_parse_proppatch.php
| From: | Hartmut Holzgraefe | Date: | Tue, 10 Oct 2006 11:53:17 +0000 |
| Subject: | cvs: pear /HTTP_WebDAV_Server Server.php /HTTP_WebDAV_Server/Server Filesystem.php /HTTP_WebDAV_Server/Tools _parse_lockinfo.php _parse_propfind.php _parse_proppatch.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-42479@lists.php.net to get a copy of this message | ||
hholzgra Tue Oct 10 11:53:17 2006 UTC
Modified files:
/pear/HTTP_WebDAV_Server Server.php
/pear/HTTP_WebDAV_Server/Server Filesystem.php
/pear/HTTP_WebDAV_Server/Tools _parse_lockinfo.php
_parse_propfind.php
_parse_proppatch.php
Log:
CS/WS fixes
http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Server.php?r1=1.55&r2=1.56&diff_format=u Index: pear/HTTP_WebDAV_Server/Server.php diff -u pear/HTTP_WebDAV_Server/Server.php:1.55 pear/HTTP_WebDAV_Server/Server.php:1.56 --- pear/HTTP_WebDAV_Server/Server.php:1.55 Tue Oct 10 11:04:19 2006 +++ pear/HTTP_WebDAV_Server/Server.php Tue Oct 10 11:53:16 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: Server.php,v 1.55 2006/10/10 11:04:19 hholzgra Exp $ +// $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"; @@ -881,7 +881,7 @@ function http_GET() { // TODO check for invalid stream - $options = Array(); + $options = Array(); $options["path"] = $this->path; $this->_get_ranges($options); @@ -922,7 +922,7 @@ . (isset($options['size']) ? $options['size'] : "*")); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); - $size -= strlen($buffer); + $size -= strlen($buffer); echo $buffer; } } else { @@ -958,7 +958,7 @@ fseek($options['stream'], $from, SEEK_SET); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); - $size -= strlen($buffer); + $size -= strlen($buffer); echo $buffer; } } @@ -972,7 +972,7 @@ 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 { @@ -1075,8 +1075,8 @@ */ function http_HEAD() { - $status = false; - $options = Array(); + $status = false; + $options = Array(); $options["path"] = $this->path; if (method_exists($this, "HEAD")) { @@ -1103,8 +1103,8 @@ header("Content-length: ".$options['size']); } - if ($status===true) $status = "200 OK"; - if ($status===false) $status = "404 Not found"; + if ($status === true) $status = "200 OK"; + if ($status === false) $status = "404 Not found"; $this->http_status($status); } @@ -1122,8 +1122,8 @@ function http_PUT() { if ($this->_check_lock_status($this->path)) { - $options = Array(); - $options["path"] = $this->path; + $options = Array(); + $options["path"] = $this->path; $options["content_length"] = $this->_SERVER["CONTENT_LENGTH"]; // get the Content-type @@ -1264,7 +1264,7 @@ // check lock status if ($this->_check_lock_status($this->path)) { // ok, proceed - $options = Array(); + $options = Array(); $options["path"] = $this->path; $stat = $this->DELETE($options); @@ -1326,7 +1326,7 @@ */ function http_LOCK() { - $options = Array(); + $options = Array(); $options["path"] = $this->path; if (isset($this->_SERVER['HTTP_DEPTH'])) { @@ -1357,7 +1357,7 @@ $stat = $this->LOCK($options); - } else { + } else { // extract lock request information from request XML payload $lockinfo = new _parse_lockinfo("php://input"); if (!$lockinfo->success) { @@ -1371,10 +1371,9 @@ } // 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); @@ -1431,7 +1430,7 @@ */ function http_UNLOCK() { - $options = Array(); + $options = Array(); $options["path"] = $this->path; if (isset($this->_SERVER['HTTP_DEPTH'])) { @@ -1457,7 +1456,7 @@ function _copymove($what) { - $options = Array(); + $options = Array(); $options["path"] = $this->path; if (isset($this->_SERVER["HTTP_DEPTH"])) { @@ -1467,7 +1466,7 @@ } extract(parse_url($this->_SERVER["HTTP_DESTINATION"])); - $path = urldecode($path); + $path = urldecode($path); $http_host = $host; if (isset($port) && $port != 80) $http_host.= ":$port"; @@ -1664,8 +1663,8 @@ case "<": // URIs are enclosed in <...> $pos2 = strpos($string, ">", $pos); - $uri = substr($string, $pos, $pos2 - $pos); - $pos = $pos2 + 1; + $uri = substr($string, $pos, $pos2 - $pos); + $pos = $pos2 + 1; return array("URI", $uri); case "[": @@ -1678,7 +1677,7 @@ } $pos2 = strpos($string, "]", $pos); $etag = substr($string, $pos + 1, $pos2 - $pos - 2); - $pos = $pos2 + 1; + $pos = $pos2 + 1; return array($type, $etag); case "N": @@ -1700,9 +1699,8 @@ */ function _if_header_parser($str) { - $pos = 0; - $len = strlen($str); - + $pos = 0; + $len = strlen($str); $uris = array(); // parser loop @@ -1712,7 +1710,7 @@ // 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 = ""; @@ -1723,9 +1721,9 @@ return false; } - $list = array(); + $list = array(); $level = 1; - $not = ""; + $not = ""; while ($level) { $token = $this->_if_header_lexer($str, $pos); if ($token[0] == "NOT") { http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Server/Filesystem.php?r1=1.33&r2=1.34&diff_format=u Index: pear/HTTP_WebDAV_Server/Server/Filesystem.php diff -u pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.33 pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.34 --- pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.33 Mon Oct 2 10:38:30 2006 +++ pear/HTTP_WebDAV_Server/Server/Filesystem.php Tue Oct 10 11:53:16 2006 @@ -1,720 +1,717 @@ <?php - require_once "HTTP/WebDAV/Server.php"; - require_once "System.php"; +require_once "HTTP/WebDAV/Server.php"; +require_once "System.php"; +/** + * Filesystem access using WebDAV + * + * @access public + * @author Hartmut Holzgraefe <hartmut@php.net> + * @version @package-version@ + */ +class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server +{ /** - * Filesystem access using WebDAV + * Root directory for WebDAV access * - * @access public - * @author Hartmut Holzgraefe <hartmut@php.net> - * @version @package-version@ - */ - class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server - { - /** - * Root directory for WebDAV access - * - * Defaults to webserver document root (set by ServeRequest) - * - * @access private - * @var string - */ - var $base = ""; - - /** - * MySQL Host where property and locking information is stored - * - * @access private - * @var string - */ - var $db_host = "localhost"; - - /** - * MySQL database for property/locking information storage - * - * @access private - * @var string - */ - var $db_name = "webdav"; - - /** - * MySQL table name prefix - * - * @access private - * @var string - */ - var $db_prefix = ""; - - /** - * MySQL user for property/locking db access - * - * @access private - * @var string - */ - var $db_user = "root"; - - /** - * MySQL password for property/locking db access - * - * @access private - * @var string - */ - var $db_passwd = ""; - - /** - * Serve a webdav request - * - * @access public - * @param string - */ - function ServeRequest($base = false) - { - // special treatment for litmus compliance test - // reply on its identifier header - // not needed for the test itself but eases debugging - foreach(apache_request_headers() as $key => $value) { - if (stristr($key,"litmus")) { - error_log("Litmus test $value"); - header("X-Litmus-reply: ".$value); - } - } + * Defaults to webserver document root (set by ServeRequest) + * + * @access private + * @var string + */ + var $base = ""; - // set root directory, defaults to webserver document root if not set - if ($base) { - $this->base = realpath($base); // TODO throw if not a directory - } else if (!$this->base) { - $this->base = $this->_SERVER['DOCUMENT_ROOT']; + /** + * MySQL Host where property and locking information is stored + * + * @access private + * @var string + */ + var $db_host = "localhost"; + + /** + * MySQL database for property/locking information storage + * + * @access private + * @var string + */ + var $db_name = "webdav"; + + /** + * MySQL table name prefix + * + * @access private + * @var string + */ + var $db_prefix = ""; + + /** + * MySQL user for property/locking db access + * + * @access private + * @var string + */ + var $db_user = "root"; + + /** + * MySQL password for property/locking db access + * + * @access private + * @var string + */ + var $db_passwd = ""; + + /** + * Serve a webdav request + * + * @access public + * @param string + */ + function ServeRequest($base = false) + { + // special treatment for litmus compliance test + // reply on its identifier header + // not needed for the test itself but eases debugging + foreach (apache_request_headers() as $key => $value) { + if (stristr($key, "litmus")) { + error_log("Litmus test $value"); + header("X-Litmus-reply: ".$value); } - - // establish connection to property/locking db - mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error()); - mysql_select_db($this->db_name) or die(mysql_error()); - // TODO throw on connection problems - - // let the base class do all the work - parent::ServeRequest(); - } - - /** - * No authentication is needed here - * - * @access private - * @param string HTTP Authentication type (Basic, Digest, ...) - * @param string Username - * @param string Password - * @return bool true on successful authentication - */ - function check_auth($type, $user, $pass) - { - return true; } + // set root directory, defaults to webserver document root if not set + if ($base) { + $this->base = realpath($base); // TODO throw if not a directory + } else if (!$this->base) { + $this->base = $this->_SERVER['DOCUMENT_ROOT']; + } + + // establish connection to property/locking db + mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error()); + mysql_select_db($this->db_name) or die(mysql_error()); + // TODO throw on connection problems + + // let the base class do all the work + parent::ServeRequest(); + } - /** - * PROPFIND method handler - * - * @param array general parameter passing array - * @param array return array for file properties - * @return bool true on success - */ - function PROPFIND(&$options, &$files) - { - // get absolute fs path to requested resource - $fspath = $this->base . $options["path"]; + /** + * No authentication is needed here + * + * @access private + * @param string HTTP Authentication type (Basic, Digest, ...) + * @param string Username + * @param string Password + * @return bool true on successful authentication + */ + function check_auth($type, $user, $pass) + { + return true; + } + + + /** + * PROPFIND method handler + * + * @param array general parameter passing array + * @param array return array for file properties + * @return bool true on success + */ + function PROPFIND(&$options, &$files) + { + // get absolute fs path to requested resource + $fspath = $this->base . $options["path"]; - // sanity check - if (!file_exists($fspath)) { - return false; - } + // sanity check + if (!file_exists($fspath)) { + return false; + } - // prepare property array - $files["files"] = array(); + // prepare property array + $files["files"] = array(); - // store information for the requested path itself - $files["files"][] = $this->fileinfo($options["path"]); + // store information for the requested path itself + $files["files"][] = $this->fileinfo($options["path"]); - // information for contained resources requested? - if (!empty($options["depth"])) { // TODO check for is_dir() first? + // information for contained resources requested? + if (!empty($options["depth"])) { // TODO check for is_dir() first? - // make sure path ends with '/' - $options["path"] = $this->_slashify($options["path"]); + // make sure path ends with '/' + $options["path"] = $this->_slashify($options["path"]); - // try to open directory - $handle = @opendir($fspath); + // try to open directory + $handle = @opendir($fspath); - if ($handle) { - // ok, now get all its contents - while ($filename = readdir($handle)) { - if ($filename != "." && $filename != "..") { - $files["files"][] = $this->fileinfo($options["path"].$filename); - } + if ($handle) { + // ok, now get all its contents + while ($filename = readdir($handle)) { + if ($filename != "." && $filename != "..") { + $files["files"][] = $this->fileinfo($options["path"].$filename); } - // TODO recursion needed if "Depth: infinite" } + // TODO recursion needed if "Depth: infinite" } + } - // ok, all done - return true; - } + // ok, all done + return true; + } - /** - * Get properties for a single file/resource - * - * @param string resource path - * @return array resource properties - */ - function fileinfo($path) - { - // map URI path to filesystem path - $fspath = $this->base . $path; - - // create result array - $info = array(); - // TODO remove slash append code when base clase is able to do it itself - $info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path; - $info["props"] = array(); - - // no special beautified displayname here ... - $info["props"][] = $this->mkprop("displayname", strtoupper($path)); - - // creation and modification time - $info["props"][] = $this->mkprop("creationdate", filectime($fspath)); - $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath)); - - // type and size (caller already made sure that path exists) - if (is_dir($fspath)) { - // directory (WebDAV collection) - $info["props"][] = $this->mkprop("resourcetype", "collection"); - $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); + /** + * Get properties for a single file/resource + * + * @param string resource path + * @return array resource properties + */ + function fileinfo($path) + { + // map URI path to filesystem path + $fspath = $this->base . $path; + + // create result array + $info = array(); + // TODO remove slash append code when base clase is able to do it itself + $info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path; + $info["props"] = array(); + + // no special beautified displayname here ... + $info["props"][] = $this->mkprop("displayname", strtoupper($path)); + + // creation and modification time + $info["props"][] = $this->mkprop("creationdate", filectime($fspath)); + $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath)); + + // type and size (caller already made sure that path exists) + if (is_dir($fspath)) { + // directory (WebDAV collection) + $info["props"][] = $this->mkprop("resourcetype", "collection"); + $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); + } else { + // plain file (WebDAV resource) + $info["props"][] = $this->mkprop("resourcetype", ""); + if (is_readable($fspath)) { + $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); } else { - // plain file (WebDAV resource) - $info["props"][] = $this->mkprop("resourcetype", ""); - if (is_readable($fspath)) { - $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); - } else { - $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); - } - $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); - } + $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); + } + $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); + } - // get additional properties from database - $query = "SELECT ns, name, value + // get additional properties from database + $query = "SELECT ns, name, value FROM {$this->db_prefix}properties WHERE path = '$path'"; - $res = mysql_query($query); - while ($row = mysql_fetch_assoc($res)) { - $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); - } - mysql_free_result($res); + $res = mysql_query($query); + while ($row = mysql_fetch_assoc($res)) { + $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); + } + mysql_free_result($res); + + return $info; + } - return $info; + /** + * detect if a given program is found in the search PATH + * + * helper function used by _mimetype() to detect if the + * external 'file' utility is available + * + * @param string program name + * @param string optional search path, defaults to $PATH + * @return bool true if executable program found in path + */ + function _can_execute($name, $path = false) + { + // path defaults to PATH from environment if not set + if ($path === false) { + $path = getenv("PATH"); } + + // check method depends on operating system + if (!strncmp(PHP_OS, "WIN", 3)) { + // on Windows an appropriate COM or EXE file needs to exist + $exts = array(".exe", ".com"); + $check_fn = "file_exists"; + } else { + // anywhere else we look for an executable file of that name + $exts = array(""); + $check_fn = "is_executable"; + } + + // now check the directories in the path for the program + foreach (explode(PATH_SEPARATOR, $path) as $dir) { + // skip invalid path entries + if (!file_exists($dir)) continue; + if (!is_dir($dir)) continue; - /** - * detect if a given program is found in the search PATH - * - * helper function used by _mimetype() to detect if the - * external 'file' utility is available - * - * @param string program name - * @param string optional search path, defaults to $PATH - * @return bool true if executable program found in path - */ - function _can_execute($name, $path = false) - { - // path defaults to PATH from environment if not set - if ($path === false) { - $path = getenv("PATH"); - } - - // check method depends on operating system - if (!strncmp(PHP_OS, "WIN", 3)) { - // on Windows an appropriate COM or EXE file needs to exist - $exts = array(".exe", ".com"); - $check_fn = "file_exists"; - } else { - // anywhere else we look for an executable file of that name - $exts = array(""); - $check_fn = "is_executable"; - } - - // now check the directories in the path for the program - foreach (explode(PATH_SEPARATOR, $path) as $dir) { - // skip invalid path entries - if (!file_exists($dir)) continue; - if (!is_dir($dir)) continue; - - // and now look for the file - foreach ($exts as $ext) { - if ($check_fn("$dir/$name".$ext)) return true; - } + // and now look for the file + foreach ($exts as $ext) { + if ($check_fn("$dir/$name".$ext)) return true; } - - return false; } + return false; + } + - /** - * try to detect the mime type of a file - * - * @param string file path - * @return string guessed mime type - */ - function _mimetype($fspath) - { - if (@is_dir($fspath)) { - // directories are easy - return "httpd/unix-directory"; - } else if (function_exists("mime_content_type")) { - // use mime magic extension if available - $mime_type = mime_content_type($fspath); - } else if ($this->_can_execute("file")) { - // it looks like we have a 'file' command, - // lets see it it does have mime support - $fp = popen("file -i '$fspath' 2>/dev/null", "r"); - $reply = fgets($fp); - pclose($fp); + /** + * try to detect the mime type of a file + * + * @param string file path + * @return string guessed mime type + */ + function _mimetype($fspath) + { + if (@is_dir($fspath)) { + // directories are easy + return "httpd/unix-directory"; + } else if (function_exists("mime_content_type")) { + // use mime magic extension if available + $mime_type = mime_content_type($fspath); + } else if ($this->_can_execute("file")) { + // it looks like we have a 'file' command, + // lets see it it does have mime support + $fp = popen("file -i '$fspath' 2>/dev/null", "r"); + $reply = fgets($fp); + pclose($fp); - // popen will not return an error if the binary was not found - // and find may not have mime support using "-i" - // so we test the format of the returned string + // popen will not return an error if the binary was not found + // and find may not have mime support using "-i" + // so we test the format of the returned string - // the reply begins with the requested filename - if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { - $reply = substr($reply, strlen($fspath)+2); - // followed by the mime type (maybe including options) - if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) { - $mime_type = $matches[0]; - } - } - } - - if (empty($mime_type)) { - // Fallback solution: try to guess the type by the file extension - // TODO: add more ... - // TODO: it has been suggested to delegate mimetype detection - // to apache but this has at least three issues: - // - works only with apache - // - needs file to be within the document tree - // - requires apache mod_magic - // TODO: can we use the registry for this on Windows? - // OTOH if the server is Windos the clients are likely to - // be Windows, too, and tend do ignore the Content-Type - // anyway (overriding it with information taken from - // the registry) - // TODO: have a seperate PEAR class for mimetype detection? - switch (strtolower(strrchr(basename($fspath), "."))) { - case ".html": - $mime_type = "text/html"; - break; - case ".gif": - $mime_type = "image/gif"; - break; - case ".jpg": - $mime_type = "image/jpeg"; - break; - default: - $mime_type = "application/octet-stream"; - break; + // the reply begins with the requested filename + if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { + $reply = substr($reply, strlen($fspath)+2); + // followed by the mime type (maybe including options) + if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) { + $mime_type = $matches[0]; } } + } - return $mime_type; + if (empty($mime_type)) { + // Fallback solution: try to guess the type by the file extension + // TODO: add more ... + // TODO: it has been suggested to delegate mimetype detection + // to apache but this has at least three issues: + // - works only with apache + // - needs file to be within the document tree + // - requires apache mod_magic + // TODO: can we use the registry for this on Windows? + // OTOH if the server is Windos the clients are likely to + // be Windows, too, and tend do ignore the Content-Type + // anyway (overriding it with information taken from + // the registry) + // TODO: have a seperate PEAR class for mimetype detection? + switch (strtolower(strrchr(basename($fspath), "."))) { + case ".html": + $mime_type = "text/html"; + break; + case ".gif": + $mime_type = "image/gif"; + break; + case ".jpg": + $mime_type = "image/jpeg"; + break; + default: + $mime_type = "application/octet-stream"; + break; + } } + + return $mime_type; + } - /** - * GET method handler - * - * @param array parameter passing array - * @return bool true on success - */ - function GET(&$options) - { - // get absolute fs path to requested resource - $fspath = $this->base . $options["path"]; - - // sanity check - if (!file_exists($fspath)) return false; - - // is this a collection? - if (is_dir($fspath)) { - return $this->GetDir($fspath, $options); - } + /** + * GET method handler + * + * @param array parameter passing array + * @return bool true on success + */ + function GET(&$options) + { + // get absolute fs path to requested resource + $fspath = $this->base . $options["path"]; + + // sanity check + if (!file_exists($fspath)) return false; - // detect resource type - $options['mimetype'] = $this->_mimetype($fspath); + // is this a collection? + if (is_dir($fspath)) { + return $this->GetDir($fspath, $options); + } + + // detect resource type + $options['mimetype'] = $this->_mimetype($fspath); - // detect modification time - // see rfc2518, section 13.7 - // some clients seem to treat this as a reverse rule - // requiering a Last-Modified header if the getlastmodified header was set - $options['mtime'] = filemtime($fspath); - - // detect resource size - $options['size'] = filesize($fspath); - - // no need to check result here, it is handled by the base class - $options['stream'] = fopen($fspath, "r"); - - return true; - } - - /** - * GET method handler for directories - * - * This is a very simple mod_index lookalike. - * See RFC 2518, Section 8.4 on GET/HEAD for collections - * - * @param string directory path - * @return void function has to handle HTTP response itself - */ - function GetDir($fspath, &$options) - { - $path = $this->_slashify($options["path"]); - if ($path != $options["path"]) { - header("Location: ".$this->base_uri.$path); - exit; - } + // detect modification time + // see rfc2518, section 13.7 + // some clients seem to treat this as a reverse rule + // requiering a Last-Modified header if the getlastmodified header was set + $options['mtime'] = filemtime($fspath); + + // detect resource size + $options['size'] = filesize($fspath); + + // no need to check result here, it is handled by the base class + $options['stream'] = fopen($fspath, "r"); + + return true; + } + + /** + * GET method handler for directories + * + * This is a very simple mod_index lookalike. + * See RFC 2518, Section 8.4 on GET/HEAD for collections + * + * @param string directory path + * @return void function has to handle HTTP response itself + */ + function GetDir($fspath, &$options) + { + $path = $this->_slashify($options["path"]); + if ($path != $options["path"]) { + header("Location: ".$this->base_uri.$path); + exit; + } - // fixed width directory column format - $format = "%15s %-19s %-s\n"; + // fixed width directory column format + $format = "%15s %-19s %-s\n"; - $handle = @opendir($fspath); - if (!$handle) { - return false; - } + $handle = @opendir($fspath); + if (!$handle) { + return false; + } - echo "<html><head><title>Index of ".htmlspecialchars($options['path'])."</title></head>\n"; + echo "<html><head><title>Index of ".htmlspecialchars($options['path'])."</title></head>\n"; - echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n"; + echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n"; - echo "<pre>"; - printf($format, "Size", "Last modified", "Filename"); - echo "<hr>"; - - while ($filename = readdir($handle)) { - if ($filename != "." && $filename != "..") { - $fullpath = $fspath."/".$filename; - $name = htmlspecialchars($filename); - printf($format, - number_format(filesize($fullpath)), - strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), - "<a href='$name'>$name</a>"); - } + echo "<pre>"; + printf($format, "Size", "Last modified", "Filename"); + echo "<hr>"; + + while ($filename = readdir($handle)) { + if ($filename != "." && $filename != "..") { + $fullpath = $fspath."/".$filename; + $name = htmlspecialchars($filename); + printf($format, + number_format(filesize($fullpath)), + strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), + "<a href='$name'>$name</a>"); } + } - echo "</pre>"; + echo "</pre>"; - closedir($handle); + closedir($handle); - echo "</html>\n"; + echo "</html>\n"; - exit; - } + exit; + } - /** - * PUT method handler - * - * @param array parameter passing array - * @return bool true on success - */ - function PUT(&$options) - { - $fspath = $this->base . $options["path"]; + /** + * PUT method handler + * + * @param array parameter passing array + * @return bool true on success + */ + function PUT(&$options) + { + $fspath = $this->base . $options["path"]; - if (!@is_dir(dirname($fspath))) { - return "409 Conflict"; - } + if (!@is_dir(dirname($fspath))) { + return "409 Conflict"; + } - $options["new"] = ! file_exists($fspath); + $options["new"] = ! file_exists($fspath); - $fp = fopen($fspath, "w"); + $fp = fopen($fspath, "w"); - return $fp; - } + return $fp; + } - /** - * MKCOL method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function MKCOL($options) - { - $path = $this->base .$options["path"]; - $parent = dirname($path); - $name = basename($path); + /** + * MKCOL method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function MKCOL($options) + { + $path = $this->base .$options["path"]; + $parent = dirname($path); + $name = basename($path); - if (!file_exists($parent)) { - return "409 Conflict"; - } + if (!file_exists($parent)) { + return "409 Conflict"; + } - if (!is_dir($parent)) { - return "403 Forbidden"; - } + if (!is_dir($parent)) { + return "403 Forbidden"; + } - if ( file_exists($parent."/".$name) ) { - return "405 Method not allowed"; - } + if ( file_exists($parent."/".$name) ) { + return "405 Method not allowed"; + } - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet - return "415 Unsupported media type"; - } + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet + return "415 Unsupported media type"; + } - $stat = mkdir ($parent."/".$name,0777); - if (!$stat) { - return "403 Forbidden"; - } - - return ("201 Created"); + $stat = mkdir($parent."/".$name, 0777); + if (!$stat) { + return "403 Forbidden"; } + + return ("201 Created"); + } - /** - * DELETE method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function DELETE($options) - { - $path = $this->base . "/" .$options["path"]; + /** + * DELETE method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function DELETE($options) + { + $path = $this->base . "/" .$options["path"]; - if (!file_exists($path)) { - return "404 Not found"; - } + if (!file_exists($path)) { + return "404 Not found"; + } - if (is_dir($path)) { - $query = "DELETE FROM {$this->db_prefix}properties - WHERE path LIKE '".$this->_slashify($options["path"])."%'"; - mysql_query($query); - System::rm("-rf $path"); - } else { - unlink ($path); - } + if (is_dir($path)) { $query = "DELETE FROM {$this->db_prefix}properties - WHERE path = '$options[path]'"; + WHERE path LIKE '".$this->_slashify($options["path"])."%'"; mysql_query($query); - - return "204 No Content"; + System::rm("-rf $path"); + } else { + unlink($path); } + $query = "DELETE FROM {$this->db_prefix}properties + WHERE path = '$options[path]'"; + mysql_query($query); + return "204 No Content"; + } - /** - * MOVE method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function MOVE($options) - { - return $this->COPY($options, true); - } - /** - * COPY method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function COPY($options, $del=false) - { - // TODO Property updates still broken (Litmus should detect this?) + /** + * MOVE method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function MOVE($options) + { + return $this->COPY($options, true); + } - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet - return "415 Unsupported media type"; - } + /** + * COPY method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function COPY($options, $del=false) + { + // TODO Property updates still broken (Litmus should detect this?) - // no copying to different WebDAV Servers yet - if (isset($options["dest_url"])) { - return "502 bad gateway"; - } + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet + return "415 Unsupported media type"; + } - $source = $this->base .$options["path"]; - if (!file_exists($source)) return "404 Not found"; + // no copying to different WebDAV Servers yet + if (isset($options["dest_url"])) { + return "502 bad gateway"; + } - $dest = $this->base . $options["dest"]; + $source = $this->base .$options["path"]; + if (!file_exists($source)) return "404 Not found"; - $new = !file_exists($dest); - $existing_col = false; + $dest = $this->base . $options["dest"]; + $new = !file_exists($dest); + $existing_col = false; - if (!$new) { - if ($del && is_dir($dest)) { - if (!$options["overwrite"]) { - return "412 precondition failed"; - } - $dest .= basename($source); - if (file_exists($dest)) { - $options["dest"] .= basename($source); - } else { - $new = true; - $existing_col = true; - } + if (!$new) { + if ($del && is_dir($dest)) { + if (!$options["overwrite"]) { + return "412 precondition failed"; + } + $dest .= basename($source); + if (file_exists($dest)) { + $options["dest"] .= basename($source); + } else { + $new = true; + $existing_col = true; } } + } - if (!$new) { - if ($options["overwrite"]) { - $stat = $this->DELETE(array("path" => $options["dest"])); - if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { - return $stat; - } - } else { - return "412 precondition failed"; + if (!$new) { + if ($options["overwrite"]) { + $stat = $this->DELETE(array("path" => $options["dest"])); + if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { + return $stat; } + } else { + return "412 precondition failed"; } + } - if (is_dir($source) && ($options["depth"] != "infinity")) { - // RFC 2518 Section 9.2, last paragraph - return "400 Bad request"; - } + if (is_dir($source) && ($options["depth"] != "infinity")) { + // RFC 2518 Section 9.2, last paragraph + return "400 Bad request"; + } - if ($del) { - if (!rename($source, $dest)) { - return "500 Internal server error"; - } - $destpath = $this->_unslashify($options["dest"]); - if (is_dir($source)) { - $query = "UPDATE {$this->db_prefix}properties + if ($del) { + if (!rename($source, $dest)) { + return "500 Internal server error"; + } + $destpath = $this->_unslashify($options["dest"]); + if (is_dir($source)) { + $query = "UPDATE {$this->db_prefix}properties SET path = REPLACE(path, '".$options["path"]."', '".$destpath."') WHERE path LIKE '".$this->_slashify($options["path"])."%'"; - mysql_query($query); - } + mysql_query($query); + } - $query = "UPDATE {$this->db_prefix}properties + $query = "UPDATE {$this->db_prefix}properties SET path = '".$destpath."' WHERE path = '".$options["path"]."'"; - mysql_query($query); + mysql_query($query); + } else { + if (is_dir($source)) { + $files = System::find($source); + $files = array_reverse($files); } else { - if (is_dir($source)) { - $files = System::find($source); - $files = array_reverse($files); - } else { - $files = array($source); - } + $files = array($source); + } - if (!is_array($files) || empty($files)) { - return "500 Internal server error"; - } + if (!is_array($files) || empty($files)) { + return "500 Internal server error"; + } - foreach ($files as $file) { - if (is_dir($file)) { - $file = $this->_slashify($file); - } + foreach ($files as $file) { + if (is_dir($file)) { + $file = $this->_slashify($file); + } - $destfile = str_replace($source, $dest, $file); + $destfile = str_replace($source, $dest, $file); - if (is_dir($file)) { - if (!is_dir($destfile)) { - // TODO "mkdir -p" here? (only natively supported by PHP 5) - if (!@mkdir($destfile)) { - return "409 Conflict"; - } - } - } else { - if (!@copy($file, $destfile)) { + if (is_dir($file)) { + if (!is_dir($destfile)) { + // TODO "mkdir -p" here? (only natively supported by PHP 5) + if (!@mkdir($destfile)) { return "409 Conflict"; } + } + } else { + if (!@copy($file, $destfile)) { + return "409 Conflict"; } } + } - $query = "INSERT INTO {$this->db_prefix}properties + $query = "INSERT INTO {$this->db_prefix}properties SELECT * FROM {$this->db_prefix}properties WHERE path = '".$options['path']."'"; - } - - return ($new && !$existing_col) ? "201 Created" : "204 No Content"; } - /** - * PROPPATCH method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function PROPPATCH(&$options) - { - global $prefs, $tab; + return ($new && !$existing_col) ? "201 Created" : "204 No Content"; + } - $msg = ""; - - $path = $options["path"]; - - $dir = dirname($path)."/"; - $base = basename($path); - - foreach($options["props"] as $key => $prop) { - if ($prop["ns"] == "DAV:") { - $options["props"][$key]['status'] = "403 Forbidden"; - } else { - if (isset($prop["val"])) { - $query = "REPLACE INTO {$this->db_prefix}properties + /** + * PROPPATCH method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function PROPPATCH(&$options) + { + global $prefs, $tab; + + $msg = ""; + $path = $options["path"]; + $dir = dirname($path)."/"; + $base = basename($path); + + foreach ($options["props"] as $key => $prop) { + if ($prop["ns"] == "DAV:") { + $options["props"][$key]['status'] = "403 Forbidden"; + } else { + if (isset($prop["val"])) { + $query = "REPLACE INTO {$this->db_prefix}properties SET path = '$options[path]' , name = '$prop[name]' , ns= '$prop[ns]' , value = '$prop[val]'"; - } else { - $query = "DELETE FROM {$this->db_prefix}properties + } else { + $query = "DELETE FROM {$this->db_prefix}properties WHERE path = '$options[path]' AND name = '$prop[name]' AND ns = '$prop[ns]'"; - } - mysql_query($query); - } + } + mysql_query($query); } - - return ""; } + + return ""; + } - /** - * LOCK method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function LOCK(&$options) - { - // get absolute fs path to requested resource - $fspath = $this->base . $options["path"]; + /** + * LOCK method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function LOCK(&$options) + { + // get absolute fs path to requested resource + $fspath = $this->base . $options["path"]; - // TODO recursive locks on directories not supported yet - if (is_dir($fspath) && !empty($options["depth"])) { - return "409 Conflict"; - } + // TODO recursive locks on directories not supported yet + if (is_dir($fspath) && !empty($options["depth"])) { + return "409 Conflict"; + } - $options["timeout"] = time()+300; // 5min. hardcoded + $options["timeout"] = time()+300; // 5min. hardcoded - if (isset($options["update"])) { // Lock Update - $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; + if (isset($options["update"])) { // Lock Update + $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; - $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where"; - $res = mysql_query($query); - $row = mysql_fetch_assoc($res); - mysql_free_result($res); + $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where"; + $res = mysql_query($query); + $row = mysql_fetch_assoc($res); + mysql_free_result($res); - if (is_array($row)) { - $query = "UPDATE {$this->db_prefix}locks + if (is_array($row)) { + $query = "UPDATE {$this->db_prefix}locks SET expires = '$options[timeout]' , modified = ".time()." $where"; - mysql_query($query); + mysql_query($query); - $options['owner'] = $row['owner']; - $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared"; - $options['type'] = $row["exclusivelock"] ? "write" : "read"; + $options['owner'] = $row['owner']; + $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared"; + $options['type'] = $row["exclusivelock"] ? "write" : "read"; - return true; - } else { - return false; - } + return true; + } else { + return false; } + } - $query = "INSERT INTO {$this->db_prefix}locks + $query = "INSERT INTO {$this->db_prefix}locks SET token = '$options[locktoken]' , path = '$options[path]' , created = ".time()." @@ -722,77 +719,83 @@ , owner = '$options[owner]' , expires = '$options[timeout]' , exclusivelock = " .($options['scope'] === "exclusive" ? "1" : "0") - ; - mysql_query($query); + ; + mysql_query($query); - return mysql_affected_rows() ? "200 OK" : "409 Conflict"; - } + return mysql_affected_rows() ? "200 OK" : "409 Conflict"; + } - /** - * UNLOCK method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function UNLOCK(&$options) - { - $query = "DELETE FROM {$this->db_prefix}locks + /** + * UNLOCK method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function UNLOCK(&$options) + { + $query = "DELETE FROM {$this->db_prefix}locks WHERE path = '$options[path]' AND token = '$options[token]'"; - mysql_query($query); + mysql_query($query); - return mysql_affected_rows() ? "204 No Content" : "409 Conflict"; - } + return mysql_affected_rows() ? "204 No Content" : "409 Conflict"; + } - /** - * checkLock() helper - * - * @param string resource path to check for locks - * @return bool true on success - */ - function checkLock($path) - { - $result = false; + /** + * checkLock() helper + * + * @param string resource path to check for locks + * @return bool true on success + */ + function checkLock($path) + { + $result = false; - $query = "SELECT owner, token, created, modified, expires, exclusivelock + $query = "SELECT owner, token, created, modified, expires, exclusivelock FROM {$this->db_prefix}locks WHERE path = '$path' "; - $res = mysql_query($query); + $res = mysql_query($query); - if ($res) { - $row = mysql_fetch_array($res); - mysql_free_result($res); - - if ($row) { - $result = array( "type" => "write", - "scope" => $row["exclusivelock"] ? "exclusive" : "shared", - "depth" => 0, - "owner" => $row['owner'], - "token" => $row['token'], - "created" => $row['created'], - "modified" => $row['modified'], - "expires" => $row['expires'] - ); - } - } + if ($res) { + $row = mysql_fetch_array($res); + mysql_free_result($res); - return $result; + if ($row) { + $result = array( "type" => "write", + "scope" => $row["exclusivelock"] ? "exclusive" : "shared", + "depth" => 0, + "owner" => $row['owner'], + "token" => $row['token'], + "created" => $row['created'], + "modified" => $row['modified'], + "expires" => $row['expires'] + ); + } } + return $result; + } - /** - * create database tables for property and lock storage - * - * @param void - * @return bool true on success - */ - function create_database() - { - // TODO - return false; - } + + /** + * create database tables for property and lock storage + * + * @param void + * @return bool true on success + */ + function create_database() + { + // TODO + return false; } +} -?> +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */ http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php diff -u pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php:1.3 pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php:1.4 --- pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php:1.3 Mon Oct 2 07:45:13 2006 +++ pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php Tue Oct 10 11:53:17 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: _parse_lockinfo.php,v 1.3 2006/10/02 07:45:13 hholzgra Exp $ +// $Id: _parse_lockinfo.php,v 1.4 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -29,131 +29,131 @@ */ 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 <owner> tag needs to be collected + // everything within the <owner> tag needs to be collected $ns_short = ""; - $ns_attr = ""; + $ns_attr = ""; if ($ns) { if ($ns == "DAV:") { $ns_short = "D:"; @@ -163,74 +163,74 @@ } $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 <owner> tag has data content + // only the <owner> 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; - } - - // <owner> finished? - if (($ns == "DAV:") && ($tag == "owner")) { - $this->collect_owner = false; - } - - // within <owner> 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; + } + + // <owner> finished? + if (($ns == "DAV:") && ($tag == "owner")) { + $this->collect_owner = false; + } + + // within <owner> 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 .= "</$ns_short$tag$ns_attr>"; - } + } else { + $ns_attr = " xmlns='$ns'"; + } + } + $this->owner .= "</$ns_short$tag$ns_attr>"; + } } } http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php diff -u pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php:1.3 pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php:1.4 --- pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php:1.3 Mon Oct 2 07:45:13 2006 +++ pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php Tue Oct 10 11:53:17 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: _parse_propfind.php,v 1.3 2006/10/02 07:45:13 hholzgra Exp $ +// $Id: _parse_propfind.php,v 1.4 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -29,149 +29,149 @@ */ 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: <allprop> and <propname> - 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: <allprop> and <propname> + 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--; + } } http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php?r1=1.5&r2=1.6&diff_format=u Index: pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php diff -u pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php:1.5 pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php:1.6 --- pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php:1.5 Mon Oct 2 07:45:13 2006 +++ pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php Tue Oct 10 11:53:17 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: _parse_proppatch.php,v 1.5 2006/10/02 07:45:13 hholzgra Exp $ +// $Id: _parse_proppatch.php,v 1.6 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -206,11 +206,18 @@ * @return void * @access private */ - function _data($parser, $data) { + function _data($parser, $data) + { if (isset($this->current)) { $this->current["val"] .= $data; } } } -?> +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */
http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Server.php?r1=1.55&r2=1.56&diff_format=u Index: pear/HTTP_WebDAV_Server/Server.php diff -u pear/HTTP_WebDAV_Server/Server.php:1.55 pear/HTTP_WebDAV_Server/Server.php:1.56 --- pear/HTTP_WebDAV_Server/Server.php:1.55 Tue Oct 10 11:04:19 2006 +++ pear/HTTP_WebDAV_Server/Server.php Tue Oct 10 11:53:16 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: Server.php,v 1.55 2006/10/10 11:04:19 hholzgra Exp $ +// $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"; @@ -881,7 +881,7 @@ function http_GET() { // TODO check for invalid stream - $options = Array(); + $options = Array(); $options["path"] = $this->path; $this->_get_ranges($options); @@ -922,7 +922,7 @@ . (isset($options['size']) ? $options['size'] : "*")); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); - $size -= strlen($buffer); + $size -= strlen($buffer); echo $buffer; } } else { @@ -958,7 +958,7 @@ fseek($options['stream'], $from, SEEK_SET); while ($size && !feof($options['stream'])) { $buffer = fread($options['stream'], 4096); - $size -= strlen($buffer); + $size -= strlen($buffer); echo $buffer; } } @@ -972,7 +972,7 @@ 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 { @@ -1075,8 +1075,8 @@ */ function http_HEAD() { - $status = false; - $options = Array(); + $status = false; + $options = Array(); $options["path"] = $this->path; if (method_exists($this, "HEAD")) { @@ -1103,8 +1103,8 @@ header("Content-length: ".$options['size']); } - if ($status===true) $status = "200 OK"; - if ($status===false) $status = "404 Not found"; + if ($status === true) $status = "200 OK"; + if ($status === false) $status = "404 Not found"; $this->http_status($status); } @@ -1122,8 +1122,8 @@ function http_PUT() { if ($this->_check_lock_status($this->path)) { - $options = Array(); - $options["path"] = $this->path; + $options = Array(); + $options["path"] = $this->path; $options["content_length"] = $this->_SERVER["CONTENT_LENGTH"]; // get the Content-type @@ -1264,7 +1264,7 @@ // check lock status if ($this->_check_lock_status($this->path)) { // ok, proceed - $options = Array(); + $options = Array(); $options["path"] = $this->path; $stat = $this->DELETE($options); @@ -1326,7 +1326,7 @@ */ function http_LOCK() { - $options = Array(); + $options = Array(); $options["path"] = $this->path; if (isset($this->_SERVER['HTTP_DEPTH'])) { @@ -1357,7 +1357,7 @@ $stat = $this->LOCK($options); - } else { + } else { // extract lock request information from request XML payload $lockinfo = new _parse_lockinfo("php://input"); if (!$lockinfo->success) { @@ -1371,10 +1371,9 @@ } // 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); @@ -1431,7 +1430,7 @@ */ function http_UNLOCK() { - $options = Array(); + $options = Array(); $options["path"] = $this->path; if (isset($this->_SERVER['HTTP_DEPTH'])) { @@ -1457,7 +1456,7 @@ function _copymove($what) { - $options = Array(); + $options = Array(); $options["path"] = $this->path; if (isset($this->_SERVER["HTTP_DEPTH"])) { @@ -1467,7 +1466,7 @@ } extract(parse_url($this->_SERVER["HTTP_DESTINATION"])); - $path = urldecode($path); + $path = urldecode($path); $http_host = $host; if (isset($port) && $port != 80) $http_host.= ":$port"; @@ -1664,8 +1663,8 @@ case "<": // URIs are enclosed in <...> $pos2 = strpos($string, ">", $pos); - $uri = substr($string, $pos, $pos2 - $pos); - $pos = $pos2 + 1; + $uri = substr($string, $pos, $pos2 - $pos); + $pos = $pos2 + 1; return array("URI", $uri); case "[": @@ -1678,7 +1677,7 @@ } $pos2 = strpos($string, "]", $pos); $etag = substr($string, $pos + 1, $pos2 - $pos - 2); - $pos = $pos2 + 1; + $pos = $pos2 + 1; return array($type, $etag); case "N": @@ -1700,9 +1699,8 @@ */ function _if_header_parser($str) { - $pos = 0; - $len = strlen($str); - + $pos = 0; + $len = strlen($str); $uris = array(); // parser loop @@ -1712,7 +1710,7 @@ // 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 = ""; @@ -1723,9 +1721,9 @@ return false; } - $list = array(); + $list = array(); $level = 1; - $not = ""; + $not = ""; while ($level) { $token = $this->_if_header_lexer($str, $pos); if ($token[0] == "NOT") { http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Server/Filesystem.php?r1=1.33&r2=1.34&diff_format=u Index: pear/HTTP_WebDAV_Server/Server/Filesystem.php diff -u pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.33 pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.34 --- pear/HTTP_WebDAV_Server/Server/Filesystem.php:1.33 Mon Oct 2 10:38:30 2006 +++ pear/HTTP_WebDAV_Server/Server/Filesystem.php Tue Oct 10 11:53:16 2006 @@ -1,720 +1,717 @@ <?php - require_once "HTTP/WebDAV/Server.php"; - require_once "System.php"; +require_once "HTTP/WebDAV/Server.php"; +require_once "System.php"; +/** + * Filesystem access using WebDAV + * + * @access public + * @author Hartmut Holzgraefe <hartmut@php.net> + * @version @package-version@ + */ +class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server +{ /** - * Filesystem access using WebDAV + * Root directory for WebDAV access * - * @access public - * @author Hartmut Holzgraefe <hartmut@php.net> - * @version @package-version@ - */ - class HTTP_WebDAV_Server_Filesystem extends HTTP_WebDAV_Server - { - /** - * Root directory for WebDAV access - * - * Defaults to webserver document root (set by ServeRequest) - * - * @access private - * @var string - */ - var $base = ""; - - /** - * MySQL Host where property and locking information is stored - * - * @access private - * @var string - */ - var $db_host = "localhost"; - - /** - * MySQL database for property/locking information storage - * - * @access private - * @var string - */ - var $db_name = "webdav"; - - /** - * MySQL table name prefix - * - * @access private - * @var string - */ - var $db_prefix = ""; - - /** - * MySQL user for property/locking db access - * - * @access private - * @var string - */ - var $db_user = "root"; - - /** - * MySQL password for property/locking db access - * - * @access private - * @var string - */ - var $db_passwd = ""; - - /** - * Serve a webdav request - * - * @access public - * @param string - */ - function ServeRequest($base = false) - { - // special treatment for litmus compliance test - // reply on its identifier header - // not needed for the test itself but eases debugging - foreach(apache_request_headers() as $key => $value) { - if (stristr($key,"litmus")) { - error_log("Litmus test $value"); - header("X-Litmus-reply: ".$value); - } - } + * Defaults to webserver document root (set by ServeRequest) + * + * @access private + * @var string + */ + var $base = ""; - // set root directory, defaults to webserver document root if not set - if ($base) { - $this->base = realpath($base); // TODO throw if not a directory - } else if (!$this->base) { - $this->base = $this->_SERVER['DOCUMENT_ROOT']; + /** + * MySQL Host where property and locking information is stored + * + * @access private + * @var string + */ + var $db_host = "localhost"; + + /** + * MySQL database for property/locking information storage + * + * @access private + * @var string + */ + var $db_name = "webdav"; + + /** + * MySQL table name prefix + * + * @access private + * @var string + */ + var $db_prefix = ""; + + /** + * MySQL user for property/locking db access + * + * @access private + * @var string + */ + var $db_user = "root"; + + /** + * MySQL password for property/locking db access + * + * @access private + * @var string + */ + var $db_passwd = ""; + + /** + * Serve a webdav request + * + * @access public + * @param string + */ + function ServeRequest($base = false) + { + // special treatment for litmus compliance test + // reply on its identifier header + // not needed for the test itself but eases debugging + foreach (apache_request_headers() as $key => $value) { + if (stristr($key, "litmus")) { + error_log("Litmus test $value"); + header("X-Litmus-reply: ".$value); } - - // establish connection to property/locking db - mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error()); - mysql_select_db($this->db_name) or die(mysql_error()); - // TODO throw on connection problems - - // let the base class do all the work - parent::ServeRequest(); - } - - /** - * No authentication is needed here - * - * @access private - * @param string HTTP Authentication type (Basic, Digest, ...) - * @param string Username - * @param string Password - * @return bool true on successful authentication - */ - function check_auth($type, $user, $pass) - { - return true; } + // set root directory, defaults to webserver document root if not set + if ($base) { + $this->base = realpath($base); // TODO throw if not a directory + } else if (!$this->base) { + $this->base = $this->_SERVER['DOCUMENT_ROOT']; + } + + // establish connection to property/locking db + mysql_connect($this->db_host, $this->db_user, $this->db_passwd) or die(mysql_error()); + mysql_select_db($this->db_name) or die(mysql_error()); + // TODO throw on connection problems + + // let the base class do all the work + parent::ServeRequest(); + } - /** - * PROPFIND method handler - * - * @param array general parameter passing array - * @param array return array for file properties - * @return bool true on success - */ - function PROPFIND(&$options, &$files) - { - // get absolute fs path to requested resource - $fspath = $this->base . $options["path"]; + /** + * No authentication is needed here + * + * @access private + * @param string HTTP Authentication type (Basic, Digest, ...) + * @param string Username + * @param string Password + * @return bool true on successful authentication + */ + function check_auth($type, $user, $pass) + { + return true; + } + + + /** + * PROPFIND method handler + * + * @param array general parameter passing array + * @param array return array for file properties + * @return bool true on success + */ + function PROPFIND(&$options, &$files) + { + // get absolute fs path to requested resource + $fspath = $this->base . $options["path"]; - // sanity check - if (!file_exists($fspath)) { - return false; - } + // sanity check + if (!file_exists($fspath)) { + return false; + } - // prepare property array - $files["files"] = array(); + // prepare property array + $files["files"] = array(); - // store information for the requested path itself - $files["files"][] = $this->fileinfo($options["path"]); + // store information for the requested path itself + $files["files"][] = $this->fileinfo($options["path"]); - // information for contained resources requested? - if (!empty($options["depth"])) { // TODO check for is_dir() first? + // information for contained resources requested? + if (!empty($options["depth"])) { // TODO check for is_dir() first? - // make sure path ends with '/' - $options["path"] = $this->_slashify($options["path"]); + // make sure path ends with '/' + $options["path"] = $this->_slashify($options["path"]); - // try to open directory - $handle = @opendir($fspath); + // try to open directory + $handle = @opendir($fspath); - if ($handle) { - // ok, now get all its contents - while ($filename = readdir($handle)) { - if ($filename != "." && $filename != "..") { - $files["files"][] = $this->fileinfo($options["path"].$filename); - } + if ($handle) { + // ok, now get all its contents + while ($filename = readdir($handle)) { + if ($filename != "." && $filename != "..") { + $files["files"][] = $this->fileinfo($options["path"].$filename); } - // TODO recursion needed if "Depth: infinite" } + // TODO recursion needed if "Depth: infinite" } + } - // ok, all done - return true; - } + // ok, all done + return true; + } - /** - * Get properties for a single file/resource - * - * @param string resource path - * @return array resource properties - */ - function fileinfo($path) - { - // map URI path to filesystem path - $fspath = $this->base . $path; - - // create result array - $info = array(); - // TODO remove slash append code when base clase is able to do it itself - $info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path; - $info["props"] = array(); - - // no special beautified displayname here ... - $info["props"][] = $this->mkprop("displayname", strtoupper($path)); - - // creation and modification time - $info["props"][] = $this->mkprop("creationdate", filectime($fspath)); - $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath)); - - // type and size (caller already made sure that path exists) - if (is_dir($fspath)) { - // directory (WebDAV collection) - $info["props"][] = $this->mkprop("resourcetype", "collection"); - $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); + /** + * Get properties for a single file/resource + * + * @param string resource path + * @return array resource properties + */ + function fileinfo($path) + { + // map URI path to filesystem path + $fspath = $this->base . $path; + + // create result array + $info = array(); + // TODO remove slash append code when base clase is able to do it itself + $info["path"] = is_dir($fspath) ? $this->_slashify($path) : $path; + $info["props"] = array(); + + // no special beautified displayname here ... + $info["props"][] = $this->mkprop("displayname", strtoupper($path)); + + // creation and modification time + $info["props"][] = $this->mkprop("creationdate", filectime($fspath)); + $info["props"][] = $this->mkprop("getlastmodified", filemtime($fspath)); + + // type and size (caller already made sure that path exists) + if (is_dir($fspath)) { + // directory (WebDAV collection) + $info["props"][] = $this->mkprop("resourcetype", "collection"); + $info["props"][] = $this->mkprop("getcontenttype", "httpd/unix-directory"); + } else { + // plain file (WebDAV resource) + $info["props"][] = $this->mkprop("resourcetype", ""); + if (is_readable($fspath)) { + $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); } else { - // plain file (WebDAV resource) - $info["props"][] = $this->mkprop("resourcetype", ""); - if (is_readable($fspath)) { - $info["props"][] = $this->mkprop("getcontenttype", $this->_mimetype($fspath)); - } else { - $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); - } - $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); - } + $info["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); + } + $info["props"][] = $this->mkprop("getcontentlength", filesize($fspath)); + } - // get additional properties from database - $query = "SELECT ns, name, value + // get additional properties from database + $query = "SELECT ns, name, value FROM {$this->db_prefix}properties WHERE path = '$path'"; - $res = mysql_query($query); - while ($row = mysql_fetch_assoc($res)) { - $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); - } - mysql_free_result($res); + $res = mysql_query($query); + while ($row = mysql_fetch_assoc($res)) { + $info["props"][] = $this->mkprop($row["ns"], $row["name"], $row["value"]); + } + mysql_free_result($res); + + return $info; + } - return $info; + /** + * detect if a given program is found in the search PATH + * + * helper function used by _mimetype() to detect if the + * external 'file' utility is available + * + * @param string program name + * @param string optional search path, defaults to $PATH + * @return bool true if executable program found in path + */ + function _can_execute($name, $path = false) + { + // path defaults to PATH from environment if not set + if ($path === false) { + $path = getenv("PATH"); } + + // check method depends on operating system + if (!strncmp(PHP_OS, "WIN", 3)) { + // on Windows an appropriate COM or EXE file needs to exist + $exts = array(".exe", ".com"); + $check_fn = "file_exists"; + } else { + // anywhere else we look for an executable file of that name + $exts = array(""); + $check_fn = "is_executable"; + } + + // now check the directories in the path for the program + foreach (explode(PATH_SEPARATOR, $path) as $dir) { + // skip invalid path entries + if (!file_exists($dir)) continue; + if (!is_dir($dir)) continue; - /** - * detect if a given program is found in the search PATH - * - * helper function used by _mimetype() to detect if the - * external 'file' utility is available - * - * @param string program name - * @param string optional search path, defaults to $PATH - * @return bool true if executable program found in path - */ - function _can_execute($name, $path = false) - { - // path defaults to PATH from environment if not set - if ($path === false) { - $path = getenv("PATH"); - } - - // check method depends on operating system - if (!strncmp(PHP_OS, "WIN", 3)) { - // on Windows an appropriate COM or EXE file needs to exist - $exts = array(".exe", ".com"); - $check_fn = "file_exists"; - } else { - // anywhere else we look for an executable file of that name - $exts = array(""); - $check_fn = "is_executable"; - } - - // now check the directories in the path for the program - foreach (explode(PATH_SEPARATOR, $path) as $dir) { - // skip invalid path entries - if (!file_exists($dir)) continue; - if (!is_dir($dir)) continue; - - // and now look for the file - foreach ($exts as $ext) { - if ($check_fn("$dir/$name".$ext)) return true; - } + // and now look for the file + foreach ($exts as $ext) { + if ($check_fn("$dir/$name".$ext)) return true; } - - return false; } + return false; + } + - /** - * try to detect the mime type of a file - * - * @param string file path - * @return string guessed mime type - */ - function _mimetype($fspath) - { - if (@is_dir($fspath)) { - // directories are easy - return "httpd/unix-directory"; - } else if (function_exists("mime_content_type")) { - // use mime magic extension if available - $mime_type = mime_content_type($fspath); - } else if ($this->_can_execute("file")) { - // it looks like we have a 'file' command, - // lets see it it does have mime support - $fp = popen("file -i '$fspath' 2>/dev/null", "r"); - $reply = fgets($fp); - pclose($fp); + /** + * try to detect the mime type of a file + * + * @param string file path + * @return string guessed mime type + */ + function _mimetype($fspath) + { + if (@is_dir($fspath)) { + // directories are easy + return "httpd/unix-directory"; + } else if (function_exists("mime_content_type")) { + // use mime magic extension if available + $mime_type = mime_content_type($fspath); + } else if ($this->_can_execute("file")) { + // it looks like we have a 'file' command, + // lets see it it does have mime support + $fp = popen("file -i '$fspath' 2>/dev/null", "r"); + $reply = fgets($fp); + pclose($fp); - // popen will not return an error if the binary was not found - // and find may not have mime support using "-i" - // so we test the format of the returned string + // popen will not return an error if the binary was not found + // and find may not have mime support using "-i" + // so we test the format of the returned string - // the reply begins with the requested filename - if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { - $reply = substr($reply, strlen($fspath)+2); - // followed by the mime type (maybe including options) - if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) { - $mime_type = $matches[0]; - } - } - } - - if (empty($mime_type)) { - // Fallback solution: try to guess the type by the file extension - // TODO: add more ... - // TODO: it has been suggested to delegate mimetype detection - // to apache but this has at least three issues: - // - works only with apache - // - needs file to be within the document tree - // - requires apache mod_magic - // TODO: can we use the registry for this on Windows? - // OTOH if the server is Windos the clients are likely to - // be Windows, too, and tend do ignore the Content-Type - // anyway (overriding it with information taken from - // the registry) - // TODO: have a seperate PEAR class for mimetype detection? - switch (strtolower(strrchr(basename($fspath), "."))) { - case ".html": - $mime_type = "text/html"; - break; - case ".gif": - $mime_type = "image/gif"; - break; - case ".jpg": - $mime_type = "image/jpeg"; - break; - default: - $mime_type = "application/octet-stream"; - break; + // the reply begins with the requested filename + if (!strncmp($reply, "$fspath: ", strlen($fspath)+2)) { + $reply = substr($reply, strlen($fspath)+2); + // followed by the mime type (maybe including options) + if (preg_match('|^[[:alnum:]_-]+/[[:alnum:]_-]+;?.*|', $reply, $matches)) { + $mime_type = $matches[0]; } } + } - return $mime_type; + if (empty($mime_type)) { + // Fallback solution: try to guess the type by the file extension + // TODO: add more ... + // TODO: it has been suggested to delegate mimetype detection + // to apache but this has at least three issues: + // - works only with apache + // - needs file to be within the document tree + // - requires apache mod_magic + // TODO: can we use the registry for this on Windows? + // OTOH if the server is Windos the clients are likely to + // be Windows, too, and tend do ignore the Content-Type + // anyway (overriding it with information taken from + // the registry) + // TODO: have a seperate PEAR class for mimetype detection? + switch (strtolower(strrchr(basename($fspath), "."))) { + case ".html": + $mime_type = "text/html"; + break; + case ".gif": + $mime_type = "image/gif"; + break; + case ".jpg": + $mime_type = "image/jpeg"; + break; + default: + $mime_type = "application/octet-stream"; + break; + } } + + return $mime_type; + } - /** - * GET method handler - * - * @param array parameter passing array - * @return bool true on success - */ - function GET(&$options) - { - // get absolute fs path to requested resource - $fspath = $this->base . $options["path"]; - - // sanity check - if (!file_exists($fspath)) return false; - - // is this a collection? - if (is_dir($fspath)) { - return $this->GetDir($fspath, $options); - } + /** + * GET method handler + * + * @param array parameter passing array + * @return bool true on success + */ + function GET(&$options) + { + // get absolute fs path to requested resource + $fspath = $this->base . $options["path"]; + + // sanity check + if (!file_exists($fspath)) return false; - // detect resource type - $options['mimetype'] = $this->_mimetype($fspath); + // is this a collection? + if (is_dir($fspath)) { + return $this->GetDir($fspath, $options); + } + + // detect resource type + $options['mimetype'] = $this->_mimetype($fspath); - // detect modification time - // see rfc2518, section 13.7 - // some clients seem to treat this as a reverse rule - // requiering a Last-Modified header if the getlastmodified header was set - $options['mtime'] = filemtime($fspath); - - // detect resource size - $options['size'] = filesize($fspath); - - // no need to check result here, it is handled by the base class - $options['stream'] = fopen($fspath, "r"); - - return true; - } - - /** - * GET method handler for directories - * - * This is a very simple mod_index lookalike. - * See RFC 2518, Section 8.4 on GET/HEAD for collections - * - * @param string directory path - * @return void function has to handle HTTP response itself - */ - function GetDir($fspath, &$options) - { - $path = $this->_slashify($options["path"]); - if ($path != $options["path"]) { - header("Location: ".$this->base_uri.$path); - exit; - } + // detect modification time + // see rfc2518, section 13.7 + // some clients seem to treat this as a reverse rule + // requiering a Last-Modified header if the getlastmodified header was set + $options['mtime'] = filemtime($fspath); + + // detect resource size + $options['size'] = filesize($fspath); + + // no need to check result here, it is handled by the base class + $options['stream'] = fopen($fspath, "r"); + + return true; + } + + /** + * GET method handler for directories + * + * This is a very simple mod_index lookalike. + * See RFC 2518, Section 8.4 on GET/HEAD for collections + * + * @param string directory path + * @return void function has to handle HTTP response itself + */ + function GetDir($fspath, &$options) + { + $path = $this->_slashify($options["path"]); + if ($path != $options["path"]) { + header("Location: ".$this->base_uri.$path); + exit; + } - // fixed width directory column format - $format = "%15s %-19s %-s\n"; + // fixed width directory column format + $format = "%15s %-19s %-s\n"; - $handle = @opendir($fspath); - if (!$handle) { - return false; - } + $handle = @opendir($fspath); + if (!$handle) { + return false; + } - echo "<html><head><title>Index of ".htmlspecialchars($options['path'])."</title></head>\n"; + echo "<html><head><title>Index of ".htmlspecialchars($options['path'])."</title></head>\n"; - echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n"; + echo "<h1>Index of ".htmlspecialchars($options['path'])."</h1>\n"; - echo "<pre>"; - printf($format, "Size", "Last modified", "Filename"); - echo "<hr>"; - - while ($filename = readdir($handle)) { - if ($filename != "." && $filename != "..") { - $fullpath = $fspath."/".$filename; - $name = htmlspecialchars($filename); - printf($format, - number_format(filesize($fullpath)), - strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), - "<a href='$name'>$name</a>"); - } + echo "<pre>"; + printf($format, "Size", "Last modified", "Filename"); + echo "<hr>"; + + while ($filename = readdir($handle)) { + if ($filename != "." && $filename != "..") { + $fullpath = $fspath."/".$filename; + $name = htmlspecialchars($filename); + printf($format, + number_format(filesize($fullpath)), + strftime("%Y-%m-%d %H:%M:%S", filemtime($fullpath)), + "<a href='$name'>$name</a>"); } + } - echo "</pre>"; + echo "</pre>"; - closedir($handle); + closedir($handle); - echo "</html>\n"; + echo "</html>\n"; - exit; - } + exit; + } - /** - * PUT method handler - * - * @param array parameter passing array - * @return bool true on success - */ - function PUT(&$options) - { - $fspath = $this->base . $options["path"]; + /** + * PUT method handler + * + * @param array parameter passing array + * @return bool true on success + */ + function PUT(&$options) + { + $fspath = $this->base . $options["path"]; - if (!@is_dir(dirname($fspath))) { - return "409 Conflict"; - } + if (!@is_dir(dirname($fspath))) { + return "409 Conflict"; + } - $options["new"] = ! file_exists($fspath); + $options["new"] = ! file_exists($fspath); - $fp = fopen($fspath, "w"); + $fp = fopen($fspath, "w"); - return $fp; - } + return $fp; + } - /** - * MKCOL method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function MKCOL($options) - { - $path = $this->base .$options["path"]; - $parent = dirname($path); - $name = basename($path); + /** + * MKCOL method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function MKCOL($options) + { + $path = $this->base .$options["path"]; + $parent = dirname($path); + $name = basename($path); - if (!file_exists($parent)) { - return "409 Conflict"; - } + if (!file_exists($parent)) { + return "409 Conflict"; + } - if (!is_dir($parent)) { - return "403 Forbidden"; - } + if (!is_dir($parent)) { + return "403 Forbidden"; + } - if ( file_exists($parent."/".$name) ) { - return "405 Method not allowed"; - } + if ( file_exists($parent."/".$name) ) { + return "405 Method not allowed"; + } - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet - return "415 Unsupported media type"; - } + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet + return "415 Unsupported media type"; + } - $stat = mkdir ($parent."/".$name,0777); - if (!$stat) { - return "403 Forbidden"; - } - - return ("201 Created"); + $stat = mkdir($parent."/".$name, 0777); + if (!$stat) { + return "403 Forbidden"; } + + return ("201 Created"); + } - /** - * DELETE method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function DELETE($options) - { - $path = $this->base . "/" .$options["path"]; + /** + * DELETE method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function DELETE($options) + { + $path = $this->base . "/" .$options["path"]; - if (!file_exists($path)) { - return "404 Not found"; - } + if (!file_exists($path)) { + return "404 Not found"; + } - if (is_dir($path)) { - $query = "DELETE FROM {$this->db_prefix}properties - WHERE path LIKE '".$this->_slashify($options["path"])."%'"; - mysql_query($query); - System::rm("-rf $path"); - } else { - unlink ($path); - } + if (is_dir($path)) { $query = "DELETE FROM {$this->db_prefix}properties - WHERE path = '$options[path]'"; + WHERE path LIKE '".$this->_slashify($options["path"])."%'"; mysql_query($query); - - return "204 No Content"; + System::rm("-rf $path"); + } else { + unlink($path); } + $query = "DELETE FROM {$this->db_prefix}properties + WHERE path = '$options[path]'"; + mysql_query($query); + return "204 No Content"; + } - /** - * MOVE method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function MOVE($options) - { - return $this->COPY($options, true); - } - /** - * COPY method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function COPY($options, $del=false) - { - // TODO Property updates still broken (Litmus should detect this?) + /** + * MOVE method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function MOVE($options) + { + return $this->COPY($options, true); + } - if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet - return "415 Unsupported media type"; - } + /** + * COPY method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function COPY($options, $del=false) + { + // TODO Property updates still broken (Litmus should detect this?) - // no copying to different WebDAV Servers yet - if (isset($options["dest_url"])) { - return "502 bad gateway"; - } + if (!empty($this->_SERVER["CONTENT_LENGTH"])) { // no body parsing yet + return "415 Unsupported media type"; + } - $source = $this->base .$options["path"]; - if (!file_exists($source)) return "404 Not found"; + // no copying to different WebDAV Servers yet + if (isset($options["dest_url"])) { + return "502 bad gateway"; + } - $dest = $this->base . $options["dest"]; + $source = $this->base .$options["path"]; + if (!file_exists($source)) return "404 Not found"; - $new = !file_exists($dest); - $existing_col = false; + $dest = $this->base . $options["dest"]; + $new = !file_exists($dest); + $existing_col = false; - if (!$new) { - if ($del && is_dir($dest)) { - if (!$options["overwrite"]) { - return "412 precondition failed"; - } - $dest .= basename($source); - if (file_exists($dest)) { - $options["dest"] .= basename($source); - } else { - $new = true; - $existing_col = true; - } + if (!$new) { + if ($del && is_dir($dest)) { + if (!$options["overwrite"]) { + return "412 precondition failed"; + } + $dest .= basename($source); + if (file_exists($dest)) { + $options["dest"] .= basename($source); + } else { + $new = true; + $existing_col = true; } } + } - if (!$new) { - if ($options["overwrite"]) { - $stat = $this->DELETE(array("path" => $options["dest"])); - if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { - return $stat; - } - } else { - return "412 precondition failed"; + if (!$new) { + if ($options["overwrite"]) { + $stat = $this->DELETE(array("path" => $options["dest"])); + if (($stat{0} != "2") && (substr($stat, 0, 3) != "404")) { + return $stat; } + } else { + return "412 precondition failed"; } + } - if (is_dir($source) && ($options["depth"] != "infinity")) { - // RFC 2518 Section 9.2, last paragraph - return "400 Bad request"; - } + if (is_dir($source) && ($options["depth"] != "infinity")) { + // RFC 2518 Section 9.2, last paragraph + return "400 Bad request"; + } - if ($del) { - if (!rename($source, $dest)) { - return "500 Internal server error"; - } - $destpath = $this->_unslashify($options["dest"]); - if (is_dir($source)) { - $query = "UPDATE {$this->db_prefix}properties + if ($del) { + if (!rename($source, $dest)) { + return "500 Internal server error"; + } + $destpath = $this->_unslashify($options["dest"]); + if (is_dir($source)) { + $query = "UPDATE {$this->db_prefix}properties SET path = REPLACE(path, '".$options["path"]."', '".$destpath."') WHERE path LIKE '".$this->_slashify($options["path"])."%'"; - mysql_query($query); - } + mysql_query($query); + } - $query = "UPDATE {$this->db_prefix}properties + $query = "UPDATE {$this->db_prefix}properties SET path = '".$destpath."' WHERE path = '".$options["path"]."'"; - mysql_query($query); + mysql_query($query); + } else { + if (is_dir($source)) { + $files = System::find($source); + $files = array_reverse($files); } else { - if (is_dir($source)) { - $files = System::find($source); - $files = array_reverse($files); - } else { - $files = array($source); - } + $files = array($source); + } - if (!is_array($files) || empty($files)) { - return "500 Internal server error"; - } + if (!is_array($files) || empty($files)) { + return "500 Internal server error"; + } - foreach ($files as $file) { - if (is_dir($file)) { - $file = $this->_slashify($file); - } + foreach ($files as $file) { + if (is_dir($file)) { + $file = $this->_slashify($file); + } - $destfile = str_replace($source, $dest, $file); + $destfile = str_replace($source, $dest, $file); - if (is_dir($file)) { - if (!is_dir($destfile)) { - // TODO "mkdir -p" here? (only natively supported by PHP 5) - if (!@mkdir($destfile)) { - return "409 Conflict"; - } - } - } else { - if (!@copy($file, $destfile)) { + if (is_dir($file)) { + if (!is_dir($destfile)) { + // TODO "mkdir -p" here? (only natively supported by PHP 5) + if (!@mkdir($destfile)) { return "409 Conflict"; } + } + } else { + if (!@copy($file, $destfile)) { + return "409 Conflict"; } } + } - $query = "INSERT INTO {$this->db_prefix}properties + $query = "INSERT INTO {$this->db_prefix}properties SELECT * FROM {$this->db_prefix}properties WHERE path = '".$options['path']."'"; - } - - return ($new && !$existing_col) ? "201 Created" : "204 No Content"; } - /** - * PROPPATCH method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function PROPPATCH(&$options) - { - global $prefs, $tab; + return ($new && !$existing_col) ? "201 Created" : "204 No Content"; + } - $msg = ""; - - $path = $options["path"]; - - $dir = dirname($path)."/"; - $base = basename($path); - - foreach($options["props"] as $key => $prop) { - if ($prop["ns"] == "DAV:") { - $options["props"][$key]['status'] = "403 Forbidden"; - } else { - if (isset($prop["val"])) { - $query = "REPLACE INTO {$this->db_prefix}properties + /** + * PROPPATCH method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function PROPPATCH(&$options) + { + global $prefs, $tab; + + $msg = ""; + $path = $options["path"]; + $dir = dirname($path)."/"; + $base = basename($path); + + foreach ($options["props"] as $key => $prop) { + if ($prop["ns"] == "DAV:") { + $options["props"][$key]['status'] = "403 Forbidden"; + } else { + if (isset($prop["val"])) { + $query = "REPLACE INTO {$this->db_prefix}properties SET path = '$options[path]' , name = '$prop[name]' , ns= '$prop[ns]' , value = '$prop[val]'"; - } else { - $query = "DELETE FROM {$this->db_prefix}properties + } else { + $query = "DELETE FROM {$this->db_prefix}properties WHERE path = '$options[path]' AND name = '$prop[name]' AND ns = '$prop[ns]'"; - } - mysql_query($query); - } + } + mysql_query($query); } - - return ""; } + + return ""; + } - /** - * LOCK method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function LOCK(&$options) - { - // get absolute fs path to requested resource - $fspath = $this->base . $options["path"]; + /** + * LOCK method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function LOCK(&$options) + { + // get absolute fs path to requested resource + $fspath = $this->base . $options["path"]; - // TODO recursive locks on directories not supported yet - if (is_dir($fspath) && !empty($options["depth"])) { - return "409 Conflict"; - } + // TODO recursive locks on directories not supported yet + if (is_dir($fspath) && !empty($options["depth"])) { + return "409 Conflict"; + } - $options["timeout"] = time()+300; // 5min. hardcoded + $options["timeout"] = time()+300; // 5min. hardcoded - if (isset($options["update"])) { // Lock Update - $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; + if (isset($options["update"])) { // Lock Update + $where = "WHERE path = '$options[path]' AND token = '$options[update]'"; - $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where"; - $res = mysql_query($query); - $row = mysql_fetch_assoc($res); - mysql_free_result($res); + $query = "SELECT owner, exclusivelock FROM {$this->db_prefix}locks $where"; + $res = mysql_query($query); + $row = mysql_fetch_assoc($res); + mysql_free_result($res); - if (is_array($row)) { - $query = "UPDATE {$this->db_prefix}locks + if (is_array($row)) { + $query = "UPDATE {$this->db_prefix}locks SET expires = '$options[timeout]' , modified = ".time()." $where"; - mysql_query($query); + mysql_query($query); - $options['owner'] = $row['owner']; - $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared"; - $options['type'] = $row["exclusivelock"] ? "write" : "read"; + $options['owner'] = $row['owner']; + $options['scope'] = $row["exclusivelock"] ? "exclusive" : "shared"; + $options['type'] = $row["exclusivelock"] ? "write" : "read"; - return true; - } else { - return false; - } + return true; + } else { + return false; } + } - $query = "INSERT INTO {$this->db_prefix}locks + $query = "INSERT INTO {$this->db_prefix}locks SET token = '$options[locktoken]' , path = '$options[path]' , created = ".time()." @@ -722,77 +719,83 @@ , owner = '$options[owner]' , expires = '$options[timeout]' , exclusivelock = " .($options['scope'] === "exclusive" ? "1" : "0") - ; - mysql_query($query); + ; + mysql_query($query); - return mysql_affected_rows() ? "200 OK" : "409 Conflict"; - } + return mysql_affected_rows() ? "200 OK" : "409 Conflict"; + } - /** - * UNLOCK method handler - * - * @param array general parameter passing array - * @return bool true on success - */ - function UNLOCK(&$options) - { - $query = "DELETE FROM {$this->db_prefix}locks + /** + * UNLOCK method handler + * + * @param array general parameter passing array + * @return bool true on success + */ + function UNLOCK(&$options) + { + $query = "DELETE FROM {$this->db_prefix}locks WHERE path = '$options[path]' AND token = '$options[token]'"; - mysql_query($query); + mysql_query($query); - return mysql_affected_rows() ? "204 No Content" : "409 Conflict"; - } + return mysql_affected_rows() ? "204 No Content" : "409 Conflict"; + } - /** - * checkLock() helper - * - * @param string resource path to check for locks - * @return bool true on success - */ - function checkLock($path) - { - $result = false; + /** + * checkLock() helper + * + * @param string resource path to check for locks + * @return bool true on success + */ + function checkLock($path) + { + $result = false; - $query = "SELECT owner, token, created, modified, expires, exclusivelock + $query = "SELECT owner, token, created, modified, expires, exclusivelock FROM {$this->db_prefix}locks WHERE path = '$path' "; - $res = mysql_query($query); + $res = mysql_query($query); - if ($res) { - $row = mysql_fetch_array($res); - mysql_free_result($res); - - if ($row) { - $result = array( "type" => "write", - "scope" => $row["exclusivelock"] ? "exclusive" : "shared", - "depth" => 0, - "owner" => $row['owner'], - "token" => $row['token'], - "created" => $row['created'], - "modified" => $row['modified'], - "expires" => $row['expires'] - ); - } - } + if ($res) { + $row = mysql_fetch_array($res); + mysql_free_result($res); - return $result; + if ($row) { + $result = array( "type" => "write", + "scope" => $row["exclusivelock"] ? "exclusive" : "shared", + "depth" => 0, + "owner" => $row['owner'], + "token" => $row['token'], + "created" => $row['created'], + "modified" => $row['modified'], + "expires" => $row['expires'] + ); + } } + return $result; + } - /** - * create database tables for property and lock storage - * - * @param void - * @return bool true on success - */ - function create_database() - { - // TODO - return false; - } + + /** + * create database tables for property and lock storage + * + * @param void + * @return bool true on success + */ + function create_database() + { + // TODO + return false; } +} -?> +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */ http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php diff -u pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php:1.3 pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php:1.4 --- pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php:1.3 Mon Oct 2 07:45:13 2006 +++ pear/HTTP_WebDAV_Server/Tools/_parse_lockinfo.php Tue Oct 10 11:53:17 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: _parse_lockinfo.php,v 1.3 2006/10/02 07:45:13 hholzgra Exp $ +// $Id: _parse_lockinfo.php,v 1.4 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -29,131 +29,131 @@ */ 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 <owner> tag needs to be collected + // everything within the <owner> tag needs to be collected $ns_short = ""; - $ns_attr = ""; + $ns_attr = ""; if ($ns) { if ($ns == "DAV:") { $ns_short = "D:"; @@ -163,74 +163,74 @@ } $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 <owner> tag has data content + // only the <owner> 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; - } - - // <owner> finished? - if (($ns == "DAV:") && ($tag == "owner")) { - $this->collect_owner = false; - } - - // within <owner> 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; + } + + // <owner> finished? + if (($ns == "DAV:") && ($tag == "owner")) { + $this->collect_owner = false; + } + + // within <owner> 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 .= "</$ns_short$tag$ns_attr>"; - } + } else { + $ns_attr = " xmlns='$ns'"; + } + } + $this->owner .= "</$ns_short$tag$ns_attr>"; + } } } http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php?r1=1.3&r2=1.4&diff_format=u Index: pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php diff -u pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php:1.3 pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php:1.4 --- pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php:1.3 Mon Oct 2 07:45:13 2006 +++ pear/HTTP_WebDAV_Server/Tools/_parse_propfind.php Tue Oct 10 11:53:17 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: _parse_propfind.php,v 1.3 2006/10/02 07:45:13 hholzgra Exp $ +// $Id: _parse_propfind.php,v 1.4 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -29,149 +29,149 @@ */ 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: <allprop> and <propname> - 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: <allprop> and <propname> + 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--; + } } http://cvs.php.net/viewvc.cgi/pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php?r1=1.5&r2=1.6&diff_format=u Index: pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php diff -u pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php:1.5 pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php:1.6 --- pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php:1.5 Mon Oct 2 07:45:13 2006 +++ pear/HTTP_WebDAV_Server/Tools/_parse_proppatch.php Tue Oct 10 11:53:17 2006 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@bitflux.ch> | // +----------------------------------------------------------------------+ // -// $Id: _parse_proppatch.php,v 1.5 2006/10/02 07:45:13 hholzgra Exp $ +// $Id: _parse_proppatch.php,v 1.6 2006/10/10 11:53:17 hholzgra Exp $ // /** @@ -206,11 +206,18 @@ * @return void * @access private */ - function _data($parser, $data) { + function _data($parser, $data) + { if (isset($this->current)) { $this->current["val"] .= $data; } } } -?> +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * indent-tabs-mode:nil + * End: + */