Roxen.git / server / base_server / module.pike

version» Context lines:

Roxen.git/server/base_server/module.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2001, Roxen IS. - // $Id: module.pike,v 1.172 2004/05/04 13:26:55 grubba Exp $ + // $Id: module.pike,v 1.173 2004/05/04 14:38:57 grubba Exp $      #include <module_constants.h>   #include <module.h>   #include <request_trace.h>      constant __pragma_save_parent__ = 1;      inherit "basic_defvar";   mapping(string:array(int)) error_log=([]);   
Roxen.git/server/base_server/module.pike:602:   //! The default implementation only handles the @expr{"DAV:write"@}   //! lock type.   multiset(DAVLock) find_locks(string path,    int(0..1) recursive,    int(0..1) exclude_shared,    RequestID id)   {    // Common case.    if (!sizeof(file_locks) && !sizeof(prefix_locks)) return 0;    +  TRACE_ENTER(sprintf("find_locks(%O, %O, %O, X)", +  path, recursive, exclude_shared), this); +     multiset(DAVLock) locks = (<>);    function(mapping(string:DAVLock):void) add_locks;       if (exclude_shared) {    User uid = id->conf->authenticate (id);    string auth_user = uid && uid->name();    add_locks = lambda (mapping(string:DAVLock) sub_locks) {    foreach (sub_locks; string user; DAVLock lock) -  if (user == auth_user || lock->lockscope == "DAV:exclusive") +  if (user == auth_user || +  lock->lockscope == "DAV:exclusive")    locks[lock] = 1;    };    }    else    add_locks = lambda (mapping(string:DAVLock) sub_locks) {    locks |= mkmultiset (values (sub_locks));    };       if (file_locks[path]) {    add_locks (file_locks[path]);
Roxen.git/server/base_server/module.pike:642:    foreach(file_locks|prefix_locks;    string prefix; mapping(string:DAVLock) sub_locks) {    if (has_prefix(prefix, path)) {    add_locks (sub_locks);    }    }    }       add_locks = 0;    +  TRACE_LEAVE(sprintf("Done, found %d locks.", sizeof(locks))); +     return sizeof(locks) && locks;   }      //! Check if there are one or more locks that apply to @[path] for the   //! user the request is authenticated as.   //!   //! @param path   //! Canonical path relative to the filesystem root. Always ends with   //! a @expr{"/"@}.   //!
Roxen.git/server/base_server/module.pike:694:   //! @note   //! The default implementation only handles the @expr{"DAV:write"@}   //! lock type.   DAVLock|int(0..3) check_locks(string path,    int(0..1) recursive,    RequestID id)   {    // Common case.    if (!sizeof(file_locks) && !sizeof(prefix_locks)) return 0;    +  TRACE_ENTER(sprintf("check_locks(%O, %d, X)", path, recursive), this); +     User uid = id->conf->authenticate (id);    string auth_user = uid && uid->name();       if (DAVLock lock =    file_locks[path] && file_locks[path][auth_user] || -  prefix_locks[path] && prefix_locks[path][auth_user]) +  prefix_locks[path] && prefix_locks[path][auth_user]) { +  TRACE_LEAVE(sprintf("Found lock %O.", lock->locktoken));    return lock; -  +  }    int(0..1) shared;       if (mapping(string:DAVLock) locks = file_locks[path]) {    foreach(locks;; DAVLock lock) { -  if (lock->lockscope == "DAV:exclusive") return 3; +  if (lock->lockscope == "DAV:exclusive") { +  TRACE_LEAVE(sprintf("Found other user's exclusive lock %O.", +  lock->locktoken)); +  return 3; +  }    shared = 1;    break;    }    }       foreach(prefix_locks;    string prefix; mapping(string:DAVLock) locks) {    if (has_prefix(path, prefix)) {    if (DAVLock lock = locks[auth_user]) return lock;    if (!shared)    // If we've found a shared lock then we won't find an    // exclusive one higher up.    foreach(locks;; DAVLock lock) { -  if (lock->lockscope == "DAV:exclusive") return 3; +  if (lock->lockscope == "DAV:exclusive") { +  TRACE_LEAVE(sprintf("Found other user's exclusive lock %O.", +  lock->locktoken)); +  return 3; +  }    shared = 1;    break;    }    }    }    -  if (!recursive) return shared; +  if (!recursive) { +  TRACE_LEAVE(sprintf("Returning %O.", shared)); +  return shared; +  }       int(0..1) locked_by_auth_user;       // We want to know if there are any locks with @[path] as prefix    // that apply to us.    foreach(file_locks|prefix_locks;    string prefix; mapping(string:DAVLock) locks) {    if (has_prefix(prefix, path)) {    if (locks[auth_user])    locked_by_auth_user = 1;    else    foreach(locks;; DAVLock lock) { -  if (lock->lockscope == "DAV:exclusive") return 3; +  if (lock->lockscope == "DAV:exclusive") { +  TRACE_LEAVE(sprintf("Found other user's exclusive lock %O.", +  lock->locktoken)); +  return 3; +  }    shared = 1;    break;    }    }    }    -  +  TRACE_LEAVE(sprintf("Returning %O.", locked_by_auth_user ? 2 : shared));    return locked_by_auth_user ? 2 : shared;   }      //! Lock the resource at @[path] with the given @[lock]. It's already   //! checked that no other lock that applies, i.e. a call   //! @code{check_locks(path,lock->recursive,id)@} would return   //! @expr{0@} or @expr{1@}.   //!   //! The implementation must at least support the @expr{"DAV:write"@}   //! lock type (RFC 2518, section 7). Briefly: An exclusive lock on a
Roxen.git/server/base_server/module.pike:787:   //! The default implementation supports only @expr{"DAV:write"@}. It   //! works under the assumption that every path maps to exactly one   //! file or directory (when it exists), and that the authenticated   //! user is uniquely identified by   //! @code{id->conf->authenticate(id)->name()@}.   mapping(string:mixed) lock_file(string path,    DAVLock lock,    RequestID id)   {    ASSERT_IF_DEBUG (lock->locktype == "DAV:write"); +  TRACE_ENTER(sprintf("lock_file(%O, lock(%O), X).", path, lock->locktoken), +  this);    User uid = id->conf->authenticate (id);    string user = uid && uid->name();    if (lock->recursive) {    if (prefix_locks[path]) {    prefix_locks[path][user] = lock;    } else {    prefix_locks[path] = ([ user:lock ]);    }    } else {    if (file_locks[path]) {    file_locks[path][user] = lock;    } else {    file_locks[path] = ([ user:lock ]);    }    } -  +  TRACE_LEAVE("Ok.");    return 0;   }      //! Remove @[lock] that currently is locking the resource at @[path].   //!   //! @param path   //! Canonical path that the lock applies to. It's relative to the   //! filesystem root and always ends with a @expr{"/"@}.   //!   //! @param lock   //! The lock to unregister. (It must not be changed or destructed.)   //!   //! @returns   //! Returns a status mapping on any error, zero otherwise.   mapping(string:mixed) unlock_file (string path,    DAVLock lock,    RequestID id)   { -  +  TRACE_ENTER(sprintf("unlock_file(%O, lock(%O), X).", path, lock->locktoken), +  this);    User uid = id->conf->authenticate (id);    string user = uid && uid->name();    DAVLock removed_lock;    if (lock->recursive) {    removed_lock = m_delete (prefix_locks[path], user);    if (!sizeof (prefix_locks[path])) m_delete (prefix_locks, path);    }    else {    removed_lock = m_delete (file_locks[path], user);    if (!sizeof (file_locks[path])) m_delete (file_locks, path);    }    ASSERT_IF_DEBUG (lock /*%O*/ == removed_lock /*%O*/, lock, removed_lock); -  +  TRACE_LEAVE("Ok.");    return 0;   }         mapping(string:mixed)|int(-1..0)|Stdio.File find_file(string path,    RequestID id);      //! Delete the file specified by @[path].   //!   //! @note