Some modifications required by CalDAV

This commit is contained in:
Ralf Becker 2008-05-08 20:33:09 +00:00
parent d2e9143213
commit 6587e340fc
2 changed files with 51 additions and 33 deletions

View File

@ -968,7 +968,7 @@ class egw_vfs extends vfs_stream_wrapper
* lock a ressource/path * lock a ressource/path
* *
* @param string $path path or url * @param string $path path or url
* @param string $token * @param string &$token
* @param int &$timeout * @param int &$timeout
* @param string &$owner * @param string &$owner
* @param string &$scope * @param string &$scope
@ -977,7 +977,7 @@ class egw_vfs extends vfs_stream_wrapper
* @param boolean $check_writable=true should we check if the ressource is writable, before granting locks, default yes * @param boolean $check_writable=true should we check if the ressource is writable, before granting locks, default yes
* @return boolean true on success * @return boolean true on success
*/ */
function lock($path,$token,&$timeout,&$owner,&$scope,&$type,$update=false,$check_writable=true) static function lock($path,&$token,&$timeout,&$owner,&$scope,&$type,$update=false,$check_writable=true)
{ {
// we require write rights to lock/unlock a resource // we require write rights to lock/unlock a resource
if (!$path || $update && !$token || $check_writable && !egw_vfs::is_writable($path)) if (!$path || $update && !$token || $check_writable && !egw_vfs::is_writable($path))
@ -987,6 +987,11 @@ class egw_vfs extends vfs_stream_wrapper
// remove the lock info evtl. set in the cache // remove the lock info evtl. set in the cache
unset(self::$lock_cache[$path]); unset(self::$lock_cache[$path]);
if ($timeout < 1000000) // < 1000000 is a relative timestamp, so we add the current time
{
$timeout += time();
}
if ($update) // Lock Update if ($update) // Lock Update
{ {
if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE,array('lock_owner','lock_exclusive','lock_write'),array( if (($ret = (boolean)($row = self::$db->select(self::LOCK_TABLE,array('lock_owner','lock_exclusive','lock_write'),array(
@ -1021,6 +1026,7 @@ class egw_vfs extends vfs_stream_wrapper
} }
if (!$token) if (!$token)
{ {
require_once('HTTP/WebDAV/Server.php');
$token = HTTP_WebDAV_Server::_new_locktoken(); $token = HTTP_WebDAV_Server::_new_locktoken();
} }
try { try {
@ -1052,7 +1058,7 @@ class egw_vfs extends vfs_stream_wrapper
* @param boolean $check_writable=true should we check if the ressource is writable, before granting locks, default yes * @param boolean $check_writable=true should we check if the ressource is writable, before granting locks, default yes
* @return boolean true on success * @return boolean true on success
*/ */
function unlock($path,$token,$check_writable=true) static function unlock($path,$token,$check_writable=true)
{ {
// we require write rights to lock/unlock a resource // we require write rights to lock/unlock a resource
if ($check_writable && !egw_vfs::is_writable($path)) if ($check_writable && !egw_vfs::is_writable($path))
@ -1077,7 +1083,7 @@ class egw_vfs extends vfs_stream_wrapper
* @param string resource path to check for locks * @param string resource path to check for locks
* @return array|boolean false if there's no lock, else array with lock info * @return array|boolean false if there's no lock, else array with lock info
*/ */
function checkLock($path) static function checkLock($path)
{ {
if (isset(self::$lock_cache[$path])) if (isset(self::$lock_cache[$path]))
{ {
@ -1109,6 +1115,18 @@ class egw_vfs extends vfs_stream_wrapper
return self::$lock_cache[$path] = $result; return self::$lock_cache[$path] = $result;
} }
/**
* Mapps entries of applications to a path for the locking
*
* @param string $app
* @param int|string $id
* @return string
*/
static function app_entry_lock_path($app,$id)
{
return "/apps/$app/entry/$id";
}
/** /**
* Initialise our static vars * Initialise our static vars
*/ */

View File

@ -248,37 +248,37 @@ class vfs_webdav_server extends HTTP_WebDAV_Server_Filesystem
} }
/** /**
* LOCK method handler * LOCK method handler
* *
* @param array general parameter passing array * @param array general parameter passing array
* @return bool true on success * @return bool true on success
*/ */
function LOCK(&$options) function LOCK(&$options)
{ {
error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')');
// TODO recursive locks on directories not supported yet // TODO recursive locks on directories not supported yet
if (is_dir($this->base . $options['path']) && !empty($options['depth'])) if (is_dir($this->base . $options['path']) && !empty($options['depth']))
{ {
return '409 Conflict'; return '409 Conflict';
} }
$options['timeout'] = time()+300; // 5min. hardcoded $options['timeout'] = time()+300; // 5min. hardcoded
// dont know why, but HTTP_WebDAV_Server passes the owner in D:href tags, which get's passed unchanged to checkLock/PROPFIND // dont know why, but HTTP_WebDAV_Server passes the owner in D:href tags, which get's passed unchanged to checkLock/PROPFIND
// that's wrong according to the standard and cadaver does not show it on discover --> strip_tags removes eventual tags // that's wrong according to the standard and cadaver does not show it on discover --> strip_tags removes eventual tags
if (($ret = egw_vfs::lock($options['path'],$options['locktoken'],$options['timeout'],strip_tags($options['owner']), if (($ret = egw_vfs::lock($options['path'],$options['locktoken'],$options['timeout'],strip_tags($options['owner']),
$options['scope'],$options['type'],isset($options['update']))) && !isset($options['update'])) $options['scope'],$options['type'],isset($options['update']))) && !isset($options['update']))
{ {
return $ret ? '200 OK' : '409 Conflict'; return $ret ? '200 OK' : '409 Conflict';
} }
return $ret; return $ret;
} }
/** /**
* UNLOCK method handler * UNLOCK method handler
* *
* @param array general parameter passing array * @param array general parameter passing array
* @return bool true on success * @return bool true on success
*/ */
function UNLOCK(&$options) function UNLOCK(&$options)
{ {
error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')'); error_log(__METHOD__.'('.str_replace(array("\n",' '),'',print_r($options,true)).')');
@ -286,13 +286,13 @@ class vfs_webdav_server extends HTTP_WebDAV_Server_Filesystem
} }
/** /**
* checkLock() helper * checkLock() helper
* *
* @param string resource path to check for locks * @param string resource path to check for locks
* @return bool true on success * @return bool true on success
*/ */
function checkLock($path) function checkLock($path)
{ {
return egw_vfs::checkLock($path); return egw_vfs::checkLock($path);
} }
} }