Roxen.git/
server/
base_server/
configuration.pike
Branch:
Tag:
Non-build tags
All tags
No tags
2018-03-28
2018-03-28 09:28:44 by Henrik Grubbström (Grubba) <grubba@grubba.org>
7ee0b0904ea007ca648a4b9753cdca5ce9fcad30 (
106
lines) (+
72
/-
34
)
[
Show
|
Annotate
]
Branch:
093159e5f507b5c0c3756d3bc764016f80533172
Configuration
[WebDAV]
: Changed API for check_locks().
It is now relies on find_locks().
1789:
return locks; }
-
//! Check
if
there
are
any
applicable
locks
for
this
user on @[path].
-
DAVLock|
LockFlag
check_locks(string path, int(0..1) recursive, RequestID id)
+
//! Check
that
all
locks
that
apply
to
@[path]
for
the
user
the request
+
//! is authenticated as have been mentioned in the if-header.
+
//!
+
//! WARNING: This function has some design issues and will very likely
+
//! get a different interface. Compatibility is NOT guaranteed.
+
//!
+
//! @param path
+
//! Normalized path below the filesystem location.
+
//!
+
//! @param recursive
+
//! If @expr{1@} also check recursively under @[path] for locks.
+
//!
+
//! @returns
+
//! Returns one of
+
//! @mixed
+
//! @type int(0..0)
+
//! Zero if not locked, or all locks were mentioned.
+
//! @type mapping(zero:zero)
+
//! An empty mapping if @[recursive] was true and there
+
//! were unmentioned locks
on
paths with
@[path]
as a prefix
.
+
//! The missing locks are registered in the multistatus for
+
//! the @[id] object.
+
//! @type mapping(string:mixed)
+
//! A @[Protocols.HTTP.DAV_LOCKED] error status in all other cases.
+
//! @endmixed
+
//!
+
//! @note
+
//! @[
DAVLock
] objects may be created if the filesystem has some
+
//! persistent storage of them. The default implementation does not
+
//! store locks persistently.
+
mapping(string:mixed)
|
int(-1..0)
check_locks(string path,
+
int(0..1) recursive,
+
RequestID id)
{
-
LockFlag state = 0;
-
foreach
(
location
_
module_cache||location_modules
(
)
,
-
[string loc
,
function func]
)
-
{
-
string
subpath;
-
int check
_
above;
-
if
(
has_prefix(
path,
loc))
{
-
//
path
== loc + subpath
.
-
subpath = path[sizeof(loc)..];
-
} else
if (
recursive && has_prefix
(
loc, path
)) {
-
//
loc == path + ignored
.
-
subpath =
"
"
;
-
check_above = 1
;
-
} else {
-
// Does not apply to this location module.
-
continue;
+
TRACE_ENTER
(
sprintf("check
_
locks
(
%O
,
%d,
X)",
path,
recursive)
,
this
)
;
+
+
mapping(
string
:DAVLock)
locks
=
find
_
locks
(path,
recursive, 0, id
)
;
+
//
Common
case
.
+
if (
!sizeof
(
locks
)) {
+
TRACE_LEAVE
("Got
no
locks
."
)
;
+
return
0
;
}
-
int/*LockFlag*/|DAVLock lock
_
info
=
-
function_object(func)
->
check
_
locks
(
subpath, recursive, id
);
-
if (
objectp(lock
_
info
)
)
{
-
if (
!check_above
)
{
-
return lock_info;
-
} else
{
-
lock
_
info
= LOCK_OWN_BELOW
;
// We have a lock on some subpath.
+
+
mapping(string:array(array(array(string))))
if
_
data
=
id
->
get
_
if_data
();
+
if (
if
_
data
) {
+
foreach(
if
_data[0],
array
(
array(string
)
)
tokens)
{
+
m
_
delete(locks,
tokens[0][1])
;
}
-
+
+
if (!sizeof(locks)) {
+
TRACE_LEAVE ("All locks unlocked.");
+
return 0;
}
-
else
-
if (check_above && (lock_info & 1))
-
// Convert LOCK_*_AT to LOCK_*_BELOW.
-
lock_info &= ~1;
-
if (lock_info > state) state = lock_info;
-
if (state == LOCK_EXCL_AT) return LOCK_EXCL_AT; // Doesn't get any worse.
-
if (function_object(func)->webdav_opaque) break;
+
}
-
return
state
;
+
+
// path = id->not_query;
+
if (!has_suffix(path, "/")) path += "/";
+
mapping(string:mixed) ret =
+
Roxen.http_dav_error(Protocols.HTTP.DAV_LOCKED, "lock-token-submitted");
+
foreach(locks;;DAVLock lock) {
+
TRACE_ENTER(sprintf("Checking lock %O against %O.", lock, path), 0);
+
if (has_prefix(path, lock->path)) {
+
TRACE_LEAVE("Direct lock.");
+
TRACE_LEAVE("Locked.");
+
return
ret
;
}
-
+
if (lock->is_file) {
+
id->set_status_for_path(lock->path[..<1], ret);
+
} else {
+
id->set_status_for_path(lock->path, ret);
+
}
+
TRACE_LEAVE("Added to multi status.");
+
}
+
TRACE_LEAVE("Multi status.");
+
return ([]);
+
}
protected multiset(DAVLock) active_locks = (<>);