* @author Ben Klang <ben@alkaloid.net>
* @author Hartmut Holzgraefe
* @author Christian Stocker
- * @since Horde 3.0
* @package Horde_Rpc
*/
class Horde_Rpc_Webdav extends Horde_Rpc
/**
*
- *
+ *
* @var
* @access
*/
/**
*
- *
+ *
* @var
* @access
*/
/**
* complete URI for this request
*
- * @var string
+ * @var string
*/
var $uri;
-
-
+
+
/**
* base URI for this request
*
- * @var string
+ * @var string
*/
var $base_uri;
/**
* URI path for this request
*
- * @var string
+ * @var string
*/
var $path;
/**
- * Remember parsed If: (RFC2518/9.4) header conditions
+ * Remember parsed If: (RFC2518/9.4) header conditions
*
* @var array
*/
* @return mixed Array of objects with properties if the request is a dir,
* array of file metadata + data if request is a file,
* false if the object is not found.
+ * @throws Horde_Exception
*/
function _list($options)
{
global $registry;
- // $path (or $options['path']) is the node on which we will list
+ // $path (or $options['path']) is the node on which we will list
// collections and resources. $this->path is the path of the original
// request from the client.
$path = $options['path'];
// $list will contain the data to return to the client
$list = array();
-
+
if ($path == '/') {
// $root is a virtual collection describing the root of the Horde
// WebDAV space
$props[] = $this->mkprop('caldav', 'calendar-home-set', $calendar_home_set);
unset($properties[self::CALDAVNS]['calendar-home-set']);
}
-
+
if (in_array('calendar-user-address-set', $properties[self::CALDAVNS]) &&
isset($item[self::CALDAVNS . ':calendar-user-address-set'])) {
$calendar_user_address_set = array();
}
}
- /**
+ /**
* Serve WebDAV HTTP request
*
* dispatch WebDAV HTTP request to the apropriate method handler
- *
+ *
* @param void
* @return void
*/
- function ServeRequest()
+ function ServeRequest()
{
// prevent warning in litmus check 'delete_fragment'
if (strstr($this->_SERVER["REQUEST_URI"], '#')) {
$uri = "https";
}
$uri.= "://".$this->_SERVER["HTTP_HOST"].$this->_SERVER["SCRIPT_NAME"];
-
+
// WebDAV has no concept of a query string and clients (including cadaver)
// seem to pass '?' unencoded, so we need to extract the path info out
// of the request URI ourselves
// if a WebDAV client didn't give a path we just assume '/'
$this->path = "/";
}
- }
-
+ }
+
if (ini_get("magic_quotes_gpc")) {
$this->path = stripslashes($this->path);
}
-
-
+
+
// identify ourselves
if (empty($this->dav_powered_by)) {
header("X-Dav-Powered-By: PHP class: ".get_class($this));
}
// check authentication
- // for the motivation for not checking OPTIONS requests on / see
+ // for the motivation for not checking OPTIONS requests on / see
// http://pear.php.net/bugs/bug.php?id=5363
if ( ( !(($this->_SERVER['REQUEST_METHOD'] == 'OPTIONS') && ($this->path == "/")))
&& (!$this->_check_auth())) {
return;
}
-
- // check
+
+ // check
if (! $this->_check_if_header_conditions()) {
return;
}
-
+
// detect requested method names
$method = strtolower($this->_SERVER["REQUEST_METHOD"]);
$wrapper = "http_".$method;
-
+
// activate HEAD emulation by GET if no HEAD method found
if ($method == "head" && !method_exists($this, "head")) {
$method = "get";
}
-
+
if (method_exists($this, $wrapper) && ($method == "options" || method_exists($this, $method))) {
$this->$wrapper(); // call method by name
} else { // method not found/implemented
// }}}
- // {{{ abstract WebDAV methods
+ // {{{ abstract WebDAV methods
- // {{{ GET()
+ // {{{ GET()
/**
* GET implementation
*
* overload this method to retrieve resources from your server
* <br>
- *
*
- * @abstract
+ *
+ * @abstract
* @param array &$params Array of input and output parameters
* <br><b>input</b><ul>
- * <li> path -
+ * <li> path -
* </ul>
* <br><b>output</b><ul>
- * <li> size -
+ * <li> size -
* </ul>
* @returns int HTTP-Statuscode
*/
/* abstract
- function GET(&$params)
+ function GET(&$params)
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
- // {{{ PUT()
+ // {{{ PUT()
/**
* PUT implementation
*
* PUT implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
-
+
/* abstract
- function PUT()
+ function PUT()
{
// dummy entry for PHPDoc
- }
+ }
*/
-
+
// }}}
- // {{{ COPY()
+ // {{{ COPY()
/**
* COPY implementation
*
* COPY implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
-
+
/* abstract
- function COPY()
+ function COPY()
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
- // {{{ MOVE()
+ // {{{ MOVE()
/**
* MOVE implementation
*
* MOVE implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
-
+
/* abstract
- function MOVE()
+ function MOVE()
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
- // {{{ DELETE()
+ // {{{ DELETE()
/**
* DELETE implementation
*
* DELETE implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
-
+
/* abstract
- function DELETE()
+ function DELETE()
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
- // {{{ PROPFIND()
+ // {{{ PROPFIND()
/**
* PROPFIND implementation
*
* PROPFIND implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
-
+
/* abstract
- function PROPFIND()
+ function PROPFIND()
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
- // {{{ PROPPATCH()
+ // {{{ PROPPATCH()
/**
* PROPPATCH implementation
*
* PROPPATCH implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
-
+
/* abstract
- function PROPPATCH()
+ function PROPPATCH()
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
- // {{{ LOCK()
+ // {{{ LOCK()
/**
* LOCK implementation
*
* LOCK implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
-
+
/* abstract
- function LOCK()
+ function LOCK()
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
- // {{{ UNLOCK()
+ // {{{ UNLOCK()
/**
* UNLOCK implementation
*
* UNLOCK implementation
*
- * @abstract
+ * @abstract
* @param array &$params
* @returns int HTTP-Statuscode
*/
/* abstract
- function UNLOCK()
+ function UNLOCK()
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
// }}}
- // {{{ other abstract methods
+ // {{{ other abstract methods
- // {{{ check_auth()
+ // {{{ check_auth()
/**
* check authentication
*
* overload this method to retrieve and confirm authentication information
*
- * @abstract
+ * @abstract
* @param string type Authentication type, e.g. "basic" or "digest"
* @param string username Transmitted username
* @param string passwort Transmitted password
* @returns bool Authentication status
*/
-
+
/* abstract
- function checkAuth($type, $username, $password)
+ function checkAuth($type, $username, $password)
{
// dummy entry for PHPDoc
- }
+ }
*/
-
+
// }}}
- // {{{ checklock()
+ // {{{ checklock()
/**
* check lock status for a resource
*
- * overload this method to return shared and exclusive locks
+ * overload this method to return shared and exclusive locks
* active for this resource
*
- * @abstract
+ * @abstract
* @param string resource Resource path to check
* @returns array An array of lock entries each consisting
* of 'type' ('shared'/'exclusive'), 'token' and 'timeout'
*/
-
+
/* abstract
- function checklock($resource)
+ function checklock($resource)
{
// dummy entry for PHPDoc
- }
+ }
*/
// }}}
// }}}
- // {{{ WebDAV HTTP method wrappers
+ // {{{ WebDAV HTTP method wrappers
- // {{{ http_OPTIONS()
+ // {{{ http_OPTIONS()
/**
* OPTIONS method handler
* @param void
* @return void
*/
- function http_OPTIONS()
+ function http_OPTIONS()
{
- // Microsoft clients default to the Frontpage protocol
+ // Microsoft clients default to the Frontpage protocol
// unless we tell them to use WebDAV
header("MS-Author-Via: DAV");
// dav header
$dav = array(1); // assume we are always dav class 1 compliant
if (isset($allow['LOCK'])) {
- $dav[] = 2; // dav class 2 requires that locking is supported
+ $dav[] = 2; // dav class 2 requires that locking is supported
}
// tell clients what we found
// }}}
- // {{{ http_PROPFIND()
+ // {{{ http_PROPFIND()
/**
* PROPFIND method handler
* @param void
* @return void
*/
- function http_PROPFIND()
+ function http_PROPFIND()
{
$options = Array();
$files = Array();
$options["path"] = $this->path;
-
+
// search depth from header (default is "infinity)
if (isset($this->_SERVER['HTTP_DEPTH'])) {
$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
} else {
$options["depth"] = "infinity";
- }
+ }
// analyze request payload
$propinfo = $this->_parse_propfind("php://input");
return;
}
}
-
+
$this->_xml = new Horde_Xml_Element('<D:multistatus xmlns:D="DAV:"/>');
// Microsoft Clients need this special namespace for date and
// time values
// FIXME: Unless we use this XMLNS on an attribute H_X_E will not send
// it with the output.
- $this->_xml->registerNamespace('xmldata', "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
+ $this->_xml->registerNamespace('xmldata', "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/");
$this->_xml->registerNamespace('caldav', self::CALDAVNS);
-
+
// now we loop over all returned file entries
foreach ($files["files"] as $filekey => $file) {
-
+
// nothing to do if no properties were returend for a file
if (!isset($file["props"]) || !is_array($file["props"])) {
continue;
}
-
+
// now loop over all returned properties
foreach ($file["props"] as $key => $prop) {
// as a convenience feature we do not require that user handlers
// restrict returned properties to the requested ones
// here we strip all unrequested entries out of the response
-
+
switch($options['props']) {
case "all":
// nothing to remove
break;
-
+
case "names":
// only the names of all existing properties were requested
// so we remove all values
unset($files["files"][$filekey]["props"][$key]["val"]);
break;
-
+
default:
$found = false;
-
- // search property name in requested properties
+
+ // search property name in requested properties
foreach ((array)$options["props"] as $reqprop) {
if (!isset($reqprop["xmlns"])) {
$reqprop["xmlns"] = "";
}
- if ( $reqprop["name"] == $prop["name"]
+ if ( $reqprop["name"] == $prop["name"]
&& $reqprop["xmlns"] == $prop["ns"]) {
$found = true;
break;
}
}
-
+
// unset property and continue with next one if not found/requested
if (!$found) {
$files["files"][$filekey]["props"][$key]="";
}
break;
}
-
- // namespace handling
+
+ // namespace handling
if (empty($prop["ns"])) continue; // no namespace
- $ns = $prop["ns"];
+ $ns = $prop["ns"];
if ($ns == "DAV:") continue; // default namespace
if (isset($this->ns_hash[$ns])) continue; // already known
- // register namespace
+ // register namespace
$ns_name = "ns".(count($this->ns_hash));
$this->ns_hash[$ns] = $ns_name;
$this->_xml->registerNamespace($ns_name, $ns);
}
-
+
// we also need to add empty entries for properties that were requested
// but for which no values where returned by the user handler
if (is_array($options['props'])) {
foreach ($options["props"] as $reqprop) {
if ($reqprop['name']=="") continue; // skip empty entries
-
+
$found = false;
-
+
if (!isset($reqprop["xmlns"])) {
$reqprop["xmlns"] = "";
}
break;
}
}
-
+
if (!$found) {
if ($reqprop["xmlns"]==="DAV:" && $reqprop["name"]==="lockdiscovery") {
// lockdiscovery is handled by the base class
- $files["files"][$filekey]["props"][]
- = $this->mkprop("DAV:",
- "lockdiscovery",
+ $files["files"][$filekey]["props"][]
+ = $this->mkprop("DAV:",
+ "lockdiscovery",
$this->lockdiscovery($files["files"][$filekey]['path']));
} else {
// add empty value for this property
}
}
}
-
+
// now we generate the reply header ...
$this->http_status("207 Multi-Status");
header('Content-Type: text/xml; charset="utf-8"');
-
+
// ... and payload
foreach ($files["files"] as $file) {
// ignore empty or incomplete entries
if (!is_array($file) || empty($file) || !isset($file["path"])) continue;
- $path = $file['path'];
+ $path = $file['path'];
if (!is_string($path) || $path==="") continue;
$xmldata = array('D:response' => array());
#echo " <D:response $ns_defs>\n";
-
+
/* TODO right now the user implementation has to make sure
collections end in a slash, this should be done in here
by checking the resource attribute */
/* minimal urlencoding is needed for the resource path */
$xmldata['D:response']['D:href'] = $this->_urlencode($href);
#echo " <D:href>$href</D:href>\n";
-
+
// report all found properties and their values (if any)
if (isset($file["props"]) && is_array($file["props"])) {
#echo " <D:propstat>\n";
#echo " <D:prop>\n";
foreach ($file["props"] as $key => $prop) {
-
+
if (!is_array($prop)) continue;
if (!isset($prop["name"])) continue;
-
+
if (!isset($prop["val"]) || $prop["val"] === "" || $prop["val"] === false) {
// empty properties (cannot use empty() for check as "0" is a legal value here)
if ($prop["ns"]=="DAV:") {
$propstats[$i]['D:prop']['D:supportedlock'] = $prop['val'];
#echo " <D:supportedlock>$prop[val]</D:supportedlock>\n";
break;
- case "lockdiscovery":
+ case "lockdiscovery":
$propstats[$i]['D:prop']['D:lockdiscovery'] = $prop['val'];
#echo " <D:lockdiscovery>\n";
#echo $prop["val"];
# . is_string($prop['val']) ? $prop['val'] : ($prop['val'] ? 'true' : 'false')
# . "</D:ishidden>\n";
break;
- default:
+ default:
$propstats[$i]['D:prop']['D:'. $prop['name']] = $prop['val'];
#echo " <D:$prop[name]>"
# . $this->_prop_encode(htmlspecialchars($prop['val']))
- # . "</D:$prop[name]>\n";
+ # . "</D:$prop[name]>\n";
break;
}
} else {
}
// Increment to the next propstat stanza.
$i++;
-
+
// now report all properties requested but not found
if (isset($file["noprops"])) {
#echo " <D:propstat>\n";
#echo " <D:status>HTTP/1.1 404 Not Found</D:status>\n";
#echo " </D:propstat>\n";
}
-
+
$xmldata['D:response']['D:propstat'] = $propstats;
#echo " </D:response>\n";
}
-
+
#echo "</D:multistatus>\n";
echo $this->_xml->saveXml();
}
-
+
// }}}
-
- // {{{ http_PROPPATCH()
+
+ // {{{ http_PROPPATCH()
/**
* PROPPATCH method handler
* @param void
* @return void
*/
- function http_PROPPATCH()
+ function http_PROPPATCH()
{
if ($this->_check_lock_status($this->path)) {
$options = Array();
$options["path"] = $this->path;
$propinfo = $this->_parse_proppatch("php://input");
-
+
if (!$this->parseSuccess) {
$this->http_status("400 Error");
return;
}
-
+
$options['props'] = $this->parseProps;
-
+
$responsedescr = $this->PROPPATCH($options);
-
+
$this->http_status("207 Multi-Status");
header('Content-Type: text/xml; charset="utf-8"');
-
+
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "<D:multistatus xmlns:D=\"DAV:\">\n";
$this->http_status("423 Locked");
}
}
-
+
// }}}
- // {{{ http_MKCOL()
+ // {{{ http_MKCOL()
/**
* MKCOL method handler
* @param void
* @return void
*/
- function http_MKCOL()
+ function http_MKCOL()
{
$options = Array();
// }}}
- // {{{ http_GET()
+ // {{{ http_GET()
/**
* GET method handler
* @param void
* @returns void
*/
- function http_GET()
+ function http_GET()
{
// TODO check for invalid stream
$options = Array();
$options['mimetype'] = "application/octet-stream";
}
header("Content-type: $options[mimetype]");
-
+
if (isset($options['mtime'])) {
header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
}
-
+
if (isset($options['stream'])) {
// GET handler returned a stream
if (!empty($options['ranges']) && (0===fseek($options['stream'], 0, SEEK_SET))) {
- // partial request and stream is seekable
-
+ // partial request and stream is seekable
+
if (count($options['ranges']) === 1) {
$range = $options['ranges'][0];
-
+
if (isset($range['start'])) {
fseek($options['stream'], $range['start'], SEEK_SET);
if (feof($options['stream'])) {
// TODO what if size unknown? 500?
if (isset($range['start'])) {
$from = $range['start'];
- $to = !empty($range['end']) ? $range['end'] : $options['size']-1;
+ $to = !empty($range['end']) ? $range['end'] : $options['size']-1;
} else {
$from = $options['size'] - $range['last']-1;
$to = $options['size'] -1;
}
- $total = isset($options['size']) ? $options['size'] : "*";
+ $total = isset($options['size']) ? $options['size'] : "*";
$size = $to - $from + 1;
$this->_multipart_byterange_header($options['mimetype'], $from, $to, $total);
echo $options['data'];
}
}
- }
- }
+ }
+ }
if (!headers_sent()) {
if (false === $status) {
* @param array options array to store result in
* @return void
*/
- function _get_ranges(&$options)
+ function _get_ranges(&$options)
{
// process Range: header if present
if (isset($this->_SERVER['HTTP_RANGE'])) {
foreach (explode(",", $matches[1]) as $range) {
// ranges are either from-to pairs or just end positions
list($start, $end) = explode("-", $range);
- $options["ranges"][] = ($start==="")
- ? array("last"=>$end)
+ $options["ranges"][] = ($start==="")
+ ? array("last"=>$end)
: array("start"=>$start, "end"=>$end);
}
}
/**
* generate separator headers for multipart response
*
- * first and last call happen without parameters to generate
+ * first and last call happen without parameters to generate
* the initial header and closing sequence, all calls inbetween
* require content mimetype, start and end byte position and
* optionaly the total byte length of the requested resource
* @param int end byte position
* @param int total resource byte size
*/
- function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
+ function _multipart_byterange_header($mimetype = false, $from = false, $to=false, $total=false)
{
if ($mimetype === false) {
if (!isset($this->multipart_separator)) {
// initial
// a little naive, this sequence *might* be part of the content
- // but it's really not likely and rather expensive to check
+ // but it's really not likely and rather expensive to check
$this->multipart_separator = "SEPARATOR_".md5(microtime());
// generate HTTP header
header("Content-type: multipart/byteranges; boundary=".$this->multipart_separator);
} else {
- // final
+ // final
// generate closing multipart sequence
echo "\n--{$this->multipart_separator}--";
}
}
-
+
// }}}
- // {{{ http_HEAD()
+ // {{{ http_HEAD()
/**
* HEAD method handler
* @param void
* @return void
*/
- function http_HEAD()
+ function http_HEAD()
{
$status = false;
$options = Array();
$options["path"] = $this->path;
-
+
if (method_exists($this, "HEAD")) {
$status = $this->head($options);
} else if (method_exists($this, "GET")) {
}
ob_end_clean();
}
-
+
if (!isset($options['mimetype'])) {
$options['mimetype'] = "application/octet-stream";
}
header("Content-type: $options[mimetype]");
-
+
if (isset($options['mtime'])) {
header("Last-modified:".gmdate("D, d M Y H:i:s ", $options['mtime'])."GMT");
}
-
+
if (isset($options['size'])) {
header("Content-length: ".$options['size']);
}
if ($status === true) $status = "200 OK";
if ($status === false) $status = "404 Not found";
-
+
$this->http_status($status);
}
// }}}
- // {{{ http_PUT()
+ // {{{ http_PUT()
/**
* PUT method handler
* @param void
* @return void
*/
- function http_PUT()
+ function http_PUT()
{
if ($this->_check_lock_status($this->path)) {
$options = Array();
$options["path"] = $this->path;
$options["content_length"] = $this->_SERVER["CONTENT_LENGTH"];
- // get the Content-type
+ // get the Content-type
if (isset($this->_SERVER["CONTENT_TYPE"])) {
// for now we do not support any sort of multipart requests
if (!strncmp($this->_SERVER["CONTENT_TYPE"], "multipart/", 10)) {
$options["content_type"] = "application/octet-stream";
}
- /* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
- ignore any Content-* (e.g. Content-Range) headers that it
- does not understand or implement and MUST return a 501
+ /* RFC 2616 2.6 says: "The recipient of the entity MUST NOT
+ ignore any Content-* (e.g. Content-Range) headers that it
+ does not understand or implement and MUST return a 501
(Not Implemented) response in such cases."
- */
+ */
foreach ($this->_SERVER as $key => $val) {
if (strncmp($key, "HTTP_CONTENT", 11)) continue;
switch ($key) {
case 'HTTP_CONTENT_ENCODING': // RFC 2616 14.11
// TODO support this if ext/zlib filters are available
- $this->http_status("501 not implemented");
+ $this->http_status("501 not implemented");
echo "The service does not support '$val' content encoding";
return;
break;
case 'HTTP_CONTENT_LOCATION': // RFC 2616 14.14
- /* The meaning of the Content-Location header in PUT
- or POST requests is undefined; servers are free
+ /* The meaning of the Content-Location header in PUT
+ or POST requests is undefined; servers are free
to ignore it in those cases. */
break;
// the header format is also specified in RFC 2616 14.16
// TODO we have to ensure that implementations support this or send 501 instead
if (!preg_match('@bytes\s+(\d+)-(\d+)/((\d+)|\*)@', $val, $matches)) {
- $this->http_status("400 bad request");
+ $this->http_status("400 bad request");
echo "The service does only support single byte ranges";
return;
}
-
+
$range = array("start"=>$matches[1], "end"=>$matches[2]);
if (is_numeric($matches[3])) {
$range["total_length"] = $matches[3];
case 'HTTP_CONTENT_MD5': // RFC 2616 14.15
// TODO: maybe we can just pretend here?
- $this->http_status("501 not implemented");
- echo "The service does not support content MD5 checksum verification";
+ $this->http_status("501 not implemented");
+ echo "The service does not support content MD5 checksum verification";
return;
- default:
+ default:
// any other unknown Content-* headers
- $this->http_status("501 not implemented");
- echo "The service does not support '$key'";
+ $this->http_status("501 not implemented");
+ echo "The service does not support '$key'";
return;
}
}
if (0 == fseek($stream, $range[0]["start"], SEEK_SET)) {
$length = $range[0]["end"]-$range[0]["start"]+1;
if (!fwrite($stream, fread($options["stream"], $length))) {
- $stat = "403 Forbidden";
+ $stat = "403 Forbidden";
}
} else {
- $stat = "403 Forbidden";
+ $stat = "403 Forbidden";
}
} else {
while (!feof($options["stream"])) {
if (false === fwrite($stream, fread($options["stream"], 4096))) {
- $stat = "403 Forbidden";
+ $stat = "403 Forbidden";
break;
}
}
}
- fclose($stream);
- }
+ fclose($stream);
+ }
$this->http_status($stat);
} else {
// }}}
- // {{{ http_DELETE()
+ // {{{ http_DELETE()
/**
* DELETE method handler
* @param void
* @return void
*/
- function http_DELETE()
+ function http_DELETE()
{
// check RFC 2518 Section 9.2, last paragraph
if (isset($this->_SERVER["HTTP_DEPTH"])) {
// }}}
- // {{{ http_COPY()
+ // {{{ http_COPY()
/**
* COPY method handler
* @param void
* @return void
*/
- function http_COPY()
+ function http_COPY()
{
- // no need to check source lock status here
+ // no need to check source lock status here
// destination lock status is always checked by the helper method
$this->_copymove("copy");
}
// }}}
- // {{{ http_MOVE()
+ // {{{ http_MOVE()
/**
* MOVE method handler
* @param void
* @return void
*/
- function http_MOVE()
+ function http_MOVE()
{
if ($this->_check_lock_status($this->path)) {
// destination lock status is always checked by the helper method
// }}}
- // {{{ http_LOCK()
+ // {{{ http_LOCK()
/**
* LOCK method handler
* @param void
* @return void
*/
- function http_LOCK()
+ function http_LOCK()
{
$options = Array();
$options["path"] = $this->path;
-
+
if (isset($this->_SERVER['HTTP_DEPTH'])) {
$options["depth"] = $this->_SERVER["HTTP_DEPTH"];
} else {
$options["depth"] = "infinity";
}
-
+
if (isset($this->_SERVER["HTTP_TIMEOUT"])) {
$options["timeout"] = explode(",", $this->_SERVER["HTTP_TIMEOUT"]);
}
-
+
if (empty($this->_SERVER['CONTENT_LENGTH']) && !empty($this->_SERVER['HTTP_IF'])) {
// check if locking is possible
if (!$this->_check_lock_status($this->path)) {
// extract lock request information from request XML payload
$lockinfo = $this->_parse_lockinfo("php://input");
if (!$lockinfo->parseSuccess) {
- $this->http_status("400 bad request");
+ $this->http_status("400 bad request");
}
// check if locking is possible
return;
}
- // new lock
+ // new lock
$options["scope"] = $this->lockscope;
$options["type"] = $this->locktype;
- $options["owner"] = $this->owner;
+ $options["owner"] = $this->owner;
$options["locktoken"] = $this->_new_locktoken();
-
- $stat = $this->LOCK($options);
+
+ $stat = $this->LOCK($options);
}
-
+
if (is_bool($stat)) {
$http_stat = $stat ? "200 OK" : "423 Locked";
} else {
$http_stat = (string)$stat;
}
$this->http_status($http_stat);
-
- if ($http_stat{0} == 2) { // 2xx states are ok
+
+ if ($http_stat{0} == 2) { // 2xx states are ok
if ($options["timeout"]) {
// if multiple timeout values were given we take the first only
if (is_array($options["timeout"])) {
} else {
$timeout = "Infinite";
}
-
+
header('Content-Type: text/xml; charset="utf-8"');
header("Lock-Token: <$options[locktoken]>");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
echo "</D:prop>\n\n";
}
}
-
+
// }}}
- // {{{ http_UNLOCK()
+ // {{{ http_UNLOCK()
/**
* UNLOCK method handler
* @param void
* @return void
*/
- function http_UNLOCK()
+ function http_UNLOCK()
{
$options = Array();
$options["path"] = $this->path;
}
// strip surrounding <>
- $options["token"] = substr(trim($this->_SERVER["HTTP_LOCK_TOKEN"]), 1, -1);
+ $options["token"] = substr(trim($this->_SERVER["HTTP_LOCK_TOKEN"]), 1, -1);
// call user method
$stat = $this->UNLOCK($options);
// }}}
- // {{{ _copymove()
+ // {{{ _copymove()
- function _copymove($what)
+ function _copymove($what)
{
$options = Array();
$options["path"] = $this->path;
// }}}
- // {{{ _allow()
+ // {{{ _allow()
/**
* check for implemented HTTP methods
* @param void
* @return array something
*/
- function _allow()
+ function _allow()
{
// OPTIONS is always there
$allow = array("OPTIONS" =>"OPTIONS");
* @param string property value
* @return array property array
*/
- function mkprop()
+ function mkprop()
{
$args = func_get_args();
if (count($args) == 3) {
}
}
- // {{{ _check_auth
+ // {{{ _check_auth
/**
* check authentication if check is implemented
- *
+ *
* @param void
* @return bool true if authentication succeded or not necessary
*/
- function _check_auth()
+ function _check_auth()
{
- $auth_type = isset($this->_SERVER["AUTH_TYPE"])
- ? $this->_SERVER["AUTH_TYPE"]
+ $auth_type = isset($this->_SERVER["AUTH_TYPE"])
+ ? $this->_SERVER["AUTH_TYPE"]
: null;
- $auth_user = isset($this->_SERVER["PHP_AUTH_USER"])
- ? $this->_SERVER["PHP_AUTH_USER"]
+ $auth_user = isset($this->_SERVER["PHP_AUTH_USER"])
+ ? $this->_SERVER["PHP_AUTH_USER"]
: null;
- $auth_pw = isset($this->_SERVER["PHP_AUTH_PW"])
- ? $this->_SERVER["PHP_AUTH_PW"]
+ $auth_pw = isset($this->_SERVER["PHP_AUTH_PW"])
+ ? $this->_SERVER["PHP_AUTH_PW"]
: null;
if (method_exists($this, "checkAuth")) {
// }}}
- // {{{ UUID stuff
-
+ // {{{ UUID stuff
+
/**
* create a new opaque lock token as defined in RFC2518
*
* @param void
* @return string new RFC2518 opaque lock token
*/
- function _new_locktoken()
+ function _new_locktoken()
{
return "opaquelocktoken:" . ((string)new Horde_Support_Uuid());
}
// }}}
- // {{{ WebDAV If: header parsing
+ // {{{ WebDAV If: header parsing
/**
- *
+ *
*
* @param string header string to parse
* @param int current parsing position
* @return array next token (type and value)
*/
- function _if_header_lexer($string, &$pos)
+ function _if_header_lexer($string, &$pos)
{
// skip whitespace
while (ctype_space($string{$pos})) {
}
}
- /**
+ /**
* parse If: header
*
* @param string header string
* @return array URIs and their conditions
*/
- function _if_header_parser($str)
+ function _if_header_parser($str)
{
$pos = 0;
$len = strlen($str);
}
/**
- * check if conditions from "If:" headers are meat
+ * check if conditions from "If:" headers are meat
*
* the "If:" header is an extension to HTTP/1.1
* defined in RFC 2518 section 9.4
* @param void
* @return void
*/
- function _check_if_header_conditions()
+ function _check_if_header_conditions()
{
if (isset($this->_SERVER["HTTP_IF"])) {
$this->_if_header_uris =
*
* Check a single URI condition parsed from an if-header
*
- * @abstract
+ * @abstract
* @param string $uri URI to check
* @param string $condition Condition to check for this URI
* @returns bool Condition check result
*/
- function _check_uri_condition($uri, $condition)
+ function _check_uri_condition($uri, $condition)
{
- // not really implemented here,
+ // not really implemented here,
// implementations must override
// a lock token can never be from the DAV: scheme
/**
- *
+ *
*
* @param string path of resource to check
* @param bool exclusive lock?
*/
- function _check_lock_status($path, $exclusive_only = false)
+ function _check_lock_status($path, $exclusive_only = false)
{
// FIXME depth -> ignored for now
if (method_exists($this, "checkLock")) {
* @param string resource path to check
* @return string lockdiscovery response
*/
- function lockdiscovery($path)
+ function lockdiscovery($path)
{
// no lock support without checklock() method
if (!method_exists($this, "checklock")) {
* @param string status code and message
* @return void
*/
- function http_status($status)
+ function http_status($status)
{
// simplified success case
if ($status === true) {
* @param string URL to encode
* @return string encoded URL
*/
- function _urlencode($url)
+ function _urlencode($url)
{
return strtr($url, array(" "=>"%20",
"%"=>"%25",
* @param string URL to decode
* @return string decoded URL
*/
- function _urldecode($path)
+ function _urldecode($path)
{
return rawurldecode($path);
}
* @param string text to encode
* @return string utf-8 encoded text
*/
- function _prop_encode($text)
+ function _prop_encode($text)
{
switch (strtolower($this->_prop_encoding)) {
case "utf-8":
* @param string directory path
* @returns string directory path wiht trailing slash
*/
- function _slashify($path)
+ function _slashify($path)
{
if ($path[strlen($path)-1] != '/') {
$path = $path."/";
* @param string directory path
* @returns string directory path wihtout trailing slash
*/
- function _unslashify($path)
+ function _unslashify($path)
{
if ($path[strlen($path)-1] == '/') {
$path = substr($path, 0, strlen($path) -1);
* @param string child path
* @return string merged path
*/
- function _mergePaths($parent, $child)
+ function _mergePaths($parent, $child)
{
if ($child{0} == '/') {
return $this->_unslashify($parent).$child;
Horde::logMessage(print_r($prop, true), __FILE__, __LINE__, PEAR_LOG_ERR);
$res = array();
- // properties from namespaces != "DAV:" or without any namespace
+ // properties from namespaces != "DAV:" or without any namespace
if ($prop["ns"]) {
$key = $this->ns_hash[$prop['ns']] . ':' . $prop['name'];
#$res .= "<" . $this->ns_hash[$prop["ns"]] . ":$prop[name]>";
return $res;
}
-
+
/**
* mbstring.func_overload save strlen version: counting the bytes not the chars
*
function bytes($str)
{
static $func_overload;
-
+
if (is_null($func_overload))
{
$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
}
- function _parse_propfind($path)
+ function _parse_propfind($path)
{
// success state flag
$this->parseSuccess = true;
-
+
// property storage array
$this->parseProps = array();
array(&$this, "_endPropinfoElement"));
// we want a case sensitive parser
- xml_parser_set_option($xml_parser,
+ xml_parser_set_option($xml_parser,
XML_OPTION_CASE_FOLDING, false);
$had_input = true;
$this->parseSuccess &= xml_parse($xml_parser, $line, false);
}
- }
-
+ }
+
// finish parsing
if ($had_input) {
$this->parseSuccess &= 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->parseProps)) $this->parseProps = "all"; // default
}
-
+
/**
* start tag handler
- *
+ *
* @access private
* @param resource parser
* @param string tag name
* @param array tag attributes
*/
- function _startPropinfoElement($parser, $name, $attrs)
+ function _startPropinfoElement($parser, $name, $attrs)
{
// name space handling
if (strstr($name, " ")) {
// increment depth count
$this->parseDepth++;
}
-
+
/**
* end tag handler
- *
+ *
* @access private
* @param resource parser
* @param string tag name
*/
- function _endPropinfoElement($parser, $name)
+ function _endPropinfoElement($parser, $name)
{
// here we only need to decrement the depth count
$this->parseDepth--;
}
- function _parse_lockinfo($path)
+ function _parse_lockinfo($path)
{
// we assume success unless problems occur
$this->parseSuccess = true;
// remember if any input was parsed
$had_input = false;
-
+
// open stream
$f_in = fopen($path, "r");
if (!$f_in) {
$had_input = true;
$this->parseSuccess &= xml_parse($xml_parser, $line, false);
}
- }
+ }
// finish parsing
if ($had_input) {
xml_parser_free($xml_parser);
// close input stream
- fclose($f_in);
+ fclose($f_in);
}
-
+
/**
* tag start handler
* @return void
* @access private
*/
- function _startLockElement($parser, $name, $attrs)
+ function _startLockElement($parser, $name, $attrs)
{
// namespace handling
if (strstr($name, " ")) {
$ns = "";
$tag = $name;
}
-
-
+
+
if ($this->collect_owner) {
// everything within the <owner> tag needs to be collected
$ns_short = "";
}
}
}
-
+
/**
* data handler
*
* @return void
* @access private
*/
- function _lockData($parser, $data)
+ function _lockData($parser, $data)
{
// only the <owner> tag has data content
if ($this->collect_owner) {
* @return void
* @access private
*/
- function _endLockElement($parser, $name)
+ function _endLockElement($parser, $name)
{
// namespace handling
if (strstr($name, " ")) {
}
}
- function _parse_proppatch($path)
+ function _parse_proppatch($path)
{
$this->parseSuccess = true;
$had_input = true;
$this->parseSuccess &= xml_parse($xml_parser, $line, false);
}
- }
-
+ }
+
if($had_input) {
$this->parseSuccess &= xml_parse($xml_parser, "", true);
}
* @return void
* @access private
*/
- function _startProppatchElement($parser, $name, $attrs)
+ function _startProppatchElement($parser, $name, $attrs)
{
if (strstr($name, " ")) {
list($ns, $tag) = explode(" ", $name);
if ($this->parseDepth == 1) {
$this->mode = $tag;
- }
+ }
if ($this->parseDepth == 3) {
$prop = array("name" => $tag);
$this->current["val"] .= ">";
}
-
+
$this->parseDepth++;
}
* @return void
* @access private
*/
- function _endProppatchElement($parser, $name)
+ function _endProppatchElement($parser, $name)
{
if (strstr($name, " ")) {
list($ns, $tag) = explode(" ", $name);
* @return void
* @access private
*/
- function _proppatchData($parser, $data)
+ function _proppatchData($parser, $data)
{
if (isset($this->current)) {
$this->current["val"] .= $data;
}
}
-}
+}