util_lock.c revision 4d0b0b6d8341c5e54b2081665fc91b4e4f781753
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna/* ====================================================================
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * The Apache Software License, Version 1.1
5f5d1b4cc970b7f06ff8ef6526128e9a27303d88nd * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * reserved.
031b91a62d25106ae69d4693475c79618dd5e884fielding * Redistribution and use in source and binary forms, with or without
031b91a62d25106ae69d4693475c79618dd5e884fielding * modification, are permitted provided that the following conditions
031b91a62d25106ae69d4693475c79618dd5e884fielding * 1. Redistributions of source code must retain the above copyright
031b91a62d25106ae69d4693475c79618dd5e884fielding * notice, this list of conditions and the following disclaimer.
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * 2. Redistributions in binary form must reproduce the above copyright
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * notice, this list of conditions and the following disclaimer in
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * the documentation and/or other materials provided with the
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * distribution.
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * 3. The end-user documentation included with the redistribution,
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * if any, must include the following acknowledgment:
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * "This product includes software developed by the
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * Apache Software Foundation (http://www.apache.org/)."
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * Alternately, this acknowledgment may appear in the software itself,
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * if and wherever such third-party acknowledgments normally appear.
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * 4. The names "Apache" and "Apache Software Foundation" must
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * not be used to endorse or promote products derived from this
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * software without prior written permission. For written
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * permission, please contact apache@apache.org.
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * 5. Products derived from this software may not be called "Apache",
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * nor may "Apache" appear in their name, without prior written
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * permission of the Apache Software Foundation.
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
397e9a692c0255ea1581b5427894c5fe0da68f83jerenkrantz * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9b68f730221daaa1d7576a157b93358f62e70533takashi * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9b68f730221daaa1d7576a157b93358f62e70533takashi * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantz * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantz * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantz * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantz * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * SUCH DAMAGE.
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna * ====================================================================
1a2bc936a6b4aaf5713c98a230a449fd878d1f06takashi * This software consists of voluntary contributions made by many
a1ef40892ffa2b44fc249423c5b6c42a74a84c68nd * individuals on behalf of the Apache Software Foundation. For more
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin * information on the Apache Software Foundation, please see
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun** DAV repository-independent lock functions
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna/* ---------------------------------------------------------------
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun** Property-related lock functions
6b797d6bd26bbf8589eb0e2b6cfa2fa808f456b1pquerna** dav_lock_get_activelock: Returns a <lockdiscovery> containing
91be90604bd426eb406711cf00e1380966bdcf81jorton** an activelock element for every item in the lock_discovery tree
91be90604bd426eb406711cf00e1380966bdcf81jortonconst char *dav_lock_get_activelock(request_rec *r, dav_lock *lock,
88505bf463771d152b14e5d513a4562175183e31jorton /* If no locks or no lock provider, there are no locks */
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun ** Since resourcediscovery is defined with (activelock)*,
88505bf463771d152b14e5d513a4562175183e31jorton ** <D:activelock/> shouldn't be necessary for an empty lock.
ea8572f0df1c69b398e9d677648a0fa5f31b2d60pquerna ** Note: it could be interesting to sum the lengths of the owners
ea8572f0df1c69b398e9d677648a0fa5f31b2d60pquerna ** and locktokens during this loop. However, the buffer
5c915a9a86688ef70d4e17a5a459f85e9f0e5d00niq ** mechanism provides some rough padding so that we don't
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun ** really need to have an exact size. Further, constructing
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun ** locktoken strings could be relatively expensive.
5c915a9a86688ef70d4e17a5a459f85e9f0e5d00niq for (lock_scan = lock; lock_scan != NULL; lock_scan = lock_scan->next)
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna /* if a buffer was not provided, then use an internal buffer */
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantz /* reset the length before we start appending stuff */
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun /* prep the buffer with a "good" size */
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantz if (lock->rectype == DAV_LOCKREC_INDIRECT_PARTIAL) {
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantz /* ### crap. design error */
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun "DESIGN ERROR: attempted to product an "
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun "activelock element from a partial, indirect "
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun "lock record. Creating an XML parsing error "
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun "to ease detection of this situation: <");
e678e297836a60ee5a456f110cac71377763b96etakashi dav_buffer_append(p, pbuf, "<D:activelock>" DEBUG_CR "<D:locktype>");
e678e297836a60ee5a456f110cac71377763b96etakashi /* ### internal error. log something? */
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna dav_buffer_append(p, pbuf, "</D:locktype>" DEBUG_CR "<D:lockscope>");
5b6890f4bf64eff2abec93f06ad5b5cb7560f780pquerna /* ### internal error. log something? */
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun dav_buffer_append(p, pbuf, "</D:lockscope>" DEBUG_CR);
5b6890f4bf64eff2abec93f06ad5b5cb7560f780pquerna ** This contains a complete, self-contained <DAV:owner> element,
5b6890f4bf64eff2abec93f06ad5b5cb7560f780pquerna ** with namespace declarations and xml:lang handling. Just drop
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna sprintf(tmp, "Second-%lu", (long unsigned int)(lock->timeout - now));
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun "<D:href>");
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun** dav_lock_parse_lockinfo: Validates the given xml_doc to contain a
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun** lockinfo XML element, then populates a dav_lock structure
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun** with its contents.
5c3c22e3324f26848c1782e711c24faf28136012jerenkrantzdav_error * dav_lock_parse_lockinfo(request_rec *r,
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna "The request body contains an unexpected "
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna "XML root element.");
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna if ((err = (*lockdb->hooks->create_lock)(lockdb, resource,
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun "Could not parse the lockinfo due to an "
0c294487ab3a4e567dc574bb2ad81c7ce07cfd31pquerna "internal problem creating a lock structure.",
7248fa34fc5d506ec1f37a929f939fe075c1a030niq "An invalid Depth header was specified.");
7248fa34fc5d506ec1f37a929f939fe075c1a030niq /* Parse elements in the XML body */
5c915a9a86688ef70d4e17a5a459f85e9f0e5d00niq for (child = doc->root->first_child; child; child = child->next) {
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun if (strcmp(child->first_child->name, "write") == 0) {
91be90604bd426eb406711cf00e1380966bdcf81jorton if (strcmp(child->first_child->name, "exclusive") == 0)
91be90604bd426eb406711cf00e1380966bdcf81jorton else if (strcmp(child->first_child->name, "shared") == 0)
7dd2be584ba36c686d9f748b55451f54f0043bccniq if (strcmp(child->name, "owner") == 0 && lock->owner == NULL) {
d875a16355b0db5971788e6374841ea5aa6e6b86nilgun const char *text;
7dd2be584ba36c686d9f748b55451f54f0043bccniq /* quote all the values in the <DAV:owner> element */
7dd2be584ba36c686d9f748b55451f54f0043bccniq ** Store a full <DAV:owner> element with namespace definitions
7dd2be584ba36c686d9f748b55451f54f0043bccniq ** and an xml:lang definition, if applicable.
7dd2be584ba36c686d9f748b55451f54f0043bccniq ap_xml_to_text(p, child, AP_XML_X2T_FULL_NS_LANG, doc->namespaces,
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);
!= NULL) {
return err;
return err;
return NULL;
return err;
return NULL;
return err;
int result;
return OK;
return HTTP_INTERNAL_SERVER_ERROR;
/* At this point, lock_resource/locktoken refers to a direct lock (key), ie
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 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;