util_lock.c revision f94aab38f6ee899f463f0118ea395291f7c5b4ce
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder/* ====================================================================
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * The Apache Software License, Version 1.1
97018cf5fa25b494adffd7e9b4e87320dae6bf47Christian Maeder * Copyright (c) 2000 The Apache Software Foundation. All rights
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * Redistribution and use in source and binary forms, with or without
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * modification, are permitted provided that the following conditions
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * 1. Redistributions of source code must retain the above copyright
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * notice, this list of conditions and the following disclaimer.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * 2. Redistributions in binary form must reproduce the above copyright
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * notice, this list of conditions and the following disclaimer in
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * the documentation and/or other materials provided with the
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * distribution.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * 3. The end-user documentation included with the redistribution,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * if any, must include the following acknowledgment:
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * "This product includes software developed by the
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * Apache Software Foundation (http://www.apache.org/)."
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * Alternately, this acknowledgment may appear in the software itself,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * if and wherever such third-party acknowledgments normally appear.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * 4. The names "Apache" and "Apache Software Foundation" must
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder * not be used to endorse or promote products derived from this
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * software without prior written permission. For written
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * permission, please contact apache@apache.org.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * 5. Products derived from this software may not be called "Apache",
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * nor may "Apache" appear in their name, without prior written
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * permission of the Apache Software Foundation.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * SUCH DAMAGE.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * ====================================================================
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * This software consists of voluntary contributions made by many
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * individuals on behalf of the Apache Software Foundation. For more
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski * information on the Apache Software Foundation, please see
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** DAV repository-independent lock functions
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder/* ---------------------------------------------------------------
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** Property-related lock functions
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** dav_lock_get_activelock: Returns a <lockdiscovery> containing
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski** an activelock element for every item in the lock_discovery tree
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowskiconst char *dav_lock_get_activelock(request_rec *r, dav_lock *lock,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski const dav_hooks_locks *hooks = DAV_GET_HOOKS_LOCKS(r);
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder /* If no locks or no lock provider, there are no locks */
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ** Since resourcediscovery is defined with (activelock)*,
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ** <D:activelock/> shouldn't be necessary for an empty lock.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ** Note: it could be interesting to sum the lengths of the owners
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ** and locktokens during this loop. However, the buffer
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ** mechanism provides some rough padding so that we don't
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski ** really need to have an exact size. Further, constructing
adea2e45fa61f1097aadc490a0aeaf4831b729ccChristian Maeder ** locktoken strings could be relatively expensive.
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski for (lock_scan = lock; lock_scan != NULL; lock_scan = lock_scan->next)
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* if a buffer was not provided, then use an internal buffer */
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* reset the length before we start appending stuff */
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* prep the buffer with a "good" size */
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski if (lock->rectype == DAV_LOCKREC_INDIRECT_PARTIAL) {
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski /* ### crap. design error */
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski "DESIGN ERROR: attempted to product an "
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski "activelock element from a partial, indirect "
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski "lock record. Creating an XML parsing error "
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski "to ease detection of this situation: <");
df11e5eab86d8247f58e301d8f0a2c6ecf4c9541Till Mossakowski dav_buffer_append(p, pbuf, "<D:activelock>" DEBUG_CR "<D:locktype>");
case DAV_LOCKTYPE_WRITE:
case DAV_LOCKSCOPE_EXCLUSIVE:
case DAV_LOCKSCOPE_SHARED:
err);
const char *text;
apr_psprintf(p,
return NULL;
return NULL;
return err;
return NULL;
depth = 0;
return err;
if (depth > 0) {
ctx.r = r;
return err;
return NULL;
return NULL;
locks);
return err;
return NULL;
return err;
return NULL;
int result;
return HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
/* At this point, lock_resource/locktoken refers to a direct lock (key), ie
return HTTP_INTERNAL_SERVER_ERROR;
ctx.r = r;
return result;
return NULL;
** locks on the collection should be inherited to the resource/collection.
int use_parent)
if (use_parent) {
return err;
return NULL;
ctx.r = r;
return DAV_RESOURCE_EXISTS;
int locks_present;
** Apache sets r->filename to known-dir/unknown-file and r->path_info
return DAV_RESOURCE_NULL;
r->filename);
return DAV_RESOURCE_ERROR;
if (locks_present)
return DAV_RESOURCE_LOCK_NULL;
return DAV_RESOURCE_NULL;
int resource_state,
int depth)
if (depth > 0 &&
return err;
err);
return err;
return NULL;