mod_dav.c revision c7548bcd69fbe1338ad855ba44f0b2b774e57bd8
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein/* ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * The Apache Software License, Version 1.1
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Copyright (c) 2000 The Apache Software Foundation. All rights
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * reserved.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Redistribution and use in source and binary forms, with or without
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * modification, are permitted provided that the following conditions
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 1. Redistributions of source code must retain the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 2. Redistributions in binary form must reproduce the above copyright
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * notice, this list of conditions and the following disclaimer in
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * the documentation and/or other materials provided with the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * distribution.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 3. The end-user documentation included with the redistribution,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if any, must include the following acknowledgment:
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * "This product includes software developed by the
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Apache Software Foundation (http://www.apache.org/)."
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * Alternately, this acknowledgment may appear in the software itself,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * if and wherever such third-party acknowledgments normally appear.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 4. The names "Apache" and "Apache Software Foundation" must
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * not be used to endorse or promote products derived from this
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * software without prior written permission. For written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission, please contact apache@apache.org.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * 5. Products derived from this software may not be called "Apache",
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * nor may "Apache" appear in their name, without prior written
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * permission of the Apache Software Foundation.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * SUCH DAMAGE.
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * ====================================================================
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * This software consists of voluntary contributions made by many
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * individuals on behalf of the Apache Software Foundation. For more
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein * information on the Apache Software Foundation, please see
b0fb330a8581c8bfab5e523084f9f39264a52b12gstein** DAV extension module for Apache 2.0.*
f4c310fd2555c6faca1f980f00b161eadb089023gstein** This module is repository-independent. It depends on hooks provided by a
f4c310fd2555c6faca1f980f00b161eadb089023gstein** repository implementation.
f4c310fd2555c6faca1f980f00b161eadb089023gstein** APACHE ISSUES:
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - within a DAV hierarchy, if an unknown method is used and we default
f4c310fd2555c6faca1f980f00b161eadb089023gstein** to Apache's implementation, it sends back an OPTIONS with the wrong
f4c310fd2555c6faca1f980f00b161eadb089023gstein** set of methods -- there is NO HOOK for us.
f4c310fd2555c6faca1f980f00b161eadb089023gstein** therefore: we need to manually handle the HTTP_METHOD_NOT_ALLOWED
f4c310fd2555c6faca1f980f00b161eadb089023gstein** and HTTP_NOT_IMPLEMENTED responses (not ap_send_error_response).
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - process_mkcol_body() had to dup code from ap_setup_client_block().
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - it would be nice to get status lines from Apache for arbitrary
f4c310fd2555c6faca1f980f00b161eadb089023gstein** status codes
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - it would be nice to be able to extend Apache's set of response
f4c310fd2555c6faca1f980f00b161eadb089023gstein** codes so that it doesn't return 500 when an unknown code is placed
f4c310fd2555c6faca1f980f00b161eadb089023gstein** into r->status.
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - http_vhost functions should apply "const" to their params
f4c310fd2555c6faca1f980f00b161eadb089023gstein** DESIGN NOTES:
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - For PROPFIND, we batch up the entire response in memory before
f4c310fd2555c6faca1f980f00b161eadb089023gstein** sending it. We may want to reorganize around sending the information
f4c310fd2555c6faca1f980f00b161eadb089023gstein** as we suck it in from the propdb. Alternatively, we should at least
f4c310fd2555c6faca1f980f00b161eadb089023gstein** generate a total Content-Length if we're going to buffer in memory
f4c310fd2555c6faca1f980f00b161eadb089023gstein** so that we can keep the connection open.
000397350b42c6266351bd618fa07df929fa7c79gstein/* ### what is the best way to set this? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* per-dir configuration */
f4c310fd2555c6faca1f980f00b161eadb089023gsteintypedef struct {
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *dir;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_table_t *d_params; /* per-directory DAV config parameters */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* per-server configuration */
f4c310fd2555c6faca1f980f00b161eadb089023gsteintypedef struct {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* forward-declare for use in configuration lookup */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void dav_init_handler(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* DBG0("dav_init_handler"); */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void *dav_create_server_config(apr_pool_t *p, server_rec *s)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm newconf = (dav_server_conf *) apr_pcalloc(p, sizeof(*newconf));
b47464a901075041e800be2de098a603923fa4f9gstein /* ### this isn't used at the moment... */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void *dav_merge_server_config(apr_pool_t *p, void *base, void *overrides)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm newconf = (dav_server_conf *) apr_pcalloc(p, sizeof(*newconf));
b47464a901075041e800be2de098a603923fa4f9gstein /* ### nothing to merge right now... */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void *dav_create_dir_config(apr_pool_t *p, char *dir)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOTE: dir==NULL creates the default per-dir config */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm conf = (dav_dir_conf *) apr_pcalloc(p, sizeof(*conf));
de18a9e85398b9c79c422f578633ed56c2747bbbgstein /* clean up the directory to remove any trailing slash */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic void *dav_merge_dir_config(apr_pool_t *p, void *base, void *overrides)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm dav_dir_conf *newconf = (dav_dir_conf *) apr_pcalloc(p, sizeof(*newconf));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* DBG3("dav_merge_dir_config: new=%08lx base=%08lx overrides=%08lx",
f4c310fd2555c6faca1f980f00b161eadb089023gstein (long)newconf, (long)base, (long)overrides); */
de18a9e85398b9c79c422f578633ed56c2747bbbgstein newconf->provider_name = DAV_INHERIT_VALUE(parent, child, provider_name);
de18a9e85398b9c79c422f578633ed56c2747bbbgstein newconf->provider = DAV_INHERIT_VALUE(parent, child, provider);
000397350b42c6266351bd618fa07df929fa7c79gstein ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
000397350b42c6266351bd618fa07df929fa7c79gstein "\"DAV Off\" cannot be used to turn off a subtree "
000397350b42c6266351bd618fa07df929fa7c79gstein "of a DAV-enabled location.");
000397350b42c6266351bd618fa07df929fa7c79gstein ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, NULL,
000397350b42c6266351bd618fa07df929fa7c79gstein "A subtree cannot specify a different DAV provider "
000397350b42c6266351bd618fa07df929fa7c79gstein "than its parent.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein newconf->locktimeout = DAV_INHERIT_VALUE(parent, child, locktimeout);
f4c310fd2555c6faca1f980f00b161eadb089023gstein newconf->dir = DAV_INHERIT_VALUE(parent, child, dir);
f4c310fd2555c6faca1f980f00b161eadb089023gstein newconf->allow_depthinfinity = DAV_INHERIT_VALUE(parent, child,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm newconf->d_params = apr_copy_table(p, parent->d_params);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_overlap_tables(newconf->d_params, child->d_params,
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = ap_get_module_config(r->per_dir_config, &dav_module);
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gsteinstatic const dav_provider * dav_get_provider(request_rec *r)
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gstein conf = ap_get_module_config(r->per_dir_config, &dav_module);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein /* assert: conf->provider_name != NULL
9f18c80269be35c0b5653e84b0db0a24044722c4gstein (otherwise, DAV is disabled, and we wouldn't be here) */
9f18c80269be35c0b5653e84b0db0a24044722c4gstein /* assert: conf->provider != NULL
9f18c80269be35c0b5653e84b0db0a24044722c4gstein (checked when conf->provider_name is set) */
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gsteinconst dav_hooks_locks *dav_get_lock_hooks(request_rec *r)
eb2abb2d3f87f28e99bcb282b91e432822b4d9b4gsteinconst dav_hooks_propdb *dav_get_propdb_hooks(request_rec *r)
709df1e1c2e1710570f8cb4209497e88662829c3gsteinconst dav_hooks_vsn *dav_get_vsn_hooks(request_rec *r)
7281ea331999debdc337b02ce37a3169e0e033a2gsteinconst dav_hooks_binding *dav_get_binding_hooks(request_rec *r)
000397350b42c6266351bd618fa07df929fa7c79gstein * Command handler for the DAV directive, which is TAKE1.
000397350b42c6266351bd618fa07df929fa7c79gsteinstatic const char *dav_cmd_dav(cmd_parms *cmd, void *config, const char *arg1)
9f18c80269be35c0b5653e84b0db0a24044722c4gstein /* lookup and cache the actual provider now */
9f18c80269be35c0b5653e84b0db0a24044722c4gstein conf->provider = dav_lookup_provider(conf->provider_name);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein /* by the time they use it, the provider should be loaded and
9f18c80269be35c0b5653e84b0db0a24044722c4gstein registered with us. */
9f18c80269be35c0b5653e84b0db0a24044722c4gstein "Unknown DAV provider: %s",
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Command handler for the DAVDepthInfinity directive, which is FLAG.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *dav_cmd_davdepthinfinity(cmd_parms *cmd, void *config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Command handler for DAVMinTimeout directive, which is TAKE1
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *dav_cmd_davmintimeout(cmd_parms *cmd, void *config,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein const char *arg1)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return "DAVMinTimeout requires a non-negative integer.";
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Command handler for DAVParam directive, which is TAKE2
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *dav_cmd_davparam(cmd_parms *cmd, void *config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein** dav_error_response()
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Send a nice response back to the user. In most cases, Apache doesn't
f4c310fd2555c6faca1f980f00b161eadb089023gstein** allow us to provide details in the body about what happened. This
f4c310fd2555c6faca1f980f00b161eadb089023gstein** function allows us to completely specify the response body.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int dav_error_response(request_rec *r, int status, const char *body)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* since we're returning DONE, ensure the request body is consumed. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* begin the response now... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* the response has been sent. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### Use of DONE obviates logging..!
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Apache's URI escaping does not replace '&' since that is a valid character
f4c310fd2555c6faca1f980f00b161eadb089023gstein** in a URI (to form a query section). We must explicitly handle it so that
f4c310fd2555c6faca1f980f00b161eadb089023gstein** we can embed the URI into an XML document.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic const char *dav_xml_escape_uri(apr_pool_t *p, const char *uri)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* check the easy case... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* more work needed... sigh. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note: this is a teeny bit of overkill since we know there are no
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** '<' or '>' characters, but who cares.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void dav_send_multistatus(request_rec *r, int status,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Set the correct status and Content-Type */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Send all of the headers now */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Send the actual multistatus response now... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "<D:multistatus xmlns:D=\"DAV:\"", r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ap_rputc('>', r); */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_rputs(dav_xml_escape_uri(r->pool, first->href), r);
d839a9822ee53ce00da24c15f2d9fe054233d342gstein /* use the Status-Line text from Apache. Note, this will
d839a9822ee53ce00da24c15f2d9fe054233d342gstein * default to 500 Internal Server Error if first->status
d839a9822ee53ce00da24c15f2d9fe054233d342gstein * is not a known (or valid) status code. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* assume this includes <propstat> and is quoted properly */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (t = first->propresult.propstats; t; t = t->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** We supply the description, so we know it doesn't have to
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** have any escaping/encoding applied to it.
f4c310fd2555c6faca1f980f00b161eadb089023gstein** dav_log_err()
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Write error information to the log.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic void dav_log_err(request_rec *r, dav_error *err, int level)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Log the errors */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### should have a directive to log the first or all */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (errscan = err; errscan != NULL; errscan = errscan->prev) {
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, level, errno, r, "%s [%d, #%d]",
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, level | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "%s [%d, #%d]",
f4c310fd2555c6faca1f980f00b161eadb089023gstein** dav_handle_err()
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Handle the standard error processing. <err> must be non-NULL.
f4c310fd2555c6faca1f980f00b161eadb089023gstein** <response> is set by the following:
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - dav_validate_request()
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - dav_add_lock()
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - repos_hooks->remove_resource
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - repos_hooks->move_resource
f4c310fd2555c6faca1f980f00b161eadb089023gstein** - repos_hooks->copy_resource
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int dav_handle_err(request_rec *r, dav_error *err,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* log the errors */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* our error messages are safe; tell Apache this */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* since we're returning DONE, ensure the request body is consumed. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* send the multistatus and tell Apache the request/response is DONE. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_send_multistatus(r, err->status, response, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handy function for return values of methods that (may) create things */
50bd75672ef114fb839dd9643c192b432fdf344cgsteinstatic int dav_created(request_rec *r, const char *locn, const char *what,
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *body;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* did the target resource already exist? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default message */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Per HTTP/1.1, S10.2.2: add a Location header to contain the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * URI that was created. */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* Convert locn to an absolute URI, and return in Location header */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein apr_table_setn(r->headers_out, "Location", ap_construct_url(r->pool, locn, r));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### insert an ETag header? see HTTP/1.1 S10.2.2 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache doesn't allow us to set a variable body for HTTP_CREATED, so
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we must manufacture the entire response. */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm body = apr_psprintf(r->pool, "%s %s has been created.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ### move to dav_util? */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *depth = apr_table_get(r->headers_in, "Depth");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The caller will return an HTTP_BAD_REQUEST. This will augment the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * default message that Apache provides. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "An invalid Depth header was specified.");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *overwrite = apr_table_get(r->headers_in, "Overwrite");
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((*overwrite == 'F' || *overwrite == 'f') && overwrite[1] == '\0') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((*overwrite == 'T' || *overwrite == 't') && overwrite[1] == '\0') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The caller will return an HTTP_BAD_REQUEST. This will augment the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * default message that Apache provides. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "An invalid Overwrite header was specified.");
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein/* resolve a request URI to a resource descriptor.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * If target_allowed != 0, then allow the request target to be overridden
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * by either a DAV:version or DAV:label-name element (passed as
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * the target argument), or any Target-Selector header in the request.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gsteinstatic int dav_get_resource(request_rec *r, int target_allowed,
ba8574a7fe6f1c3405982bb856591b5f13fe205agstein /* go look for the resource if it isn't already present */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm (void) apr_get_userdata(&data, DAV_KEY_RESOURCE, r->pool);
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* if the request target can be overridden, get any target selector */
9f18c80269be35c0b5653e84b0db0a24044722c4gstein conf = ap_get_module_config(r->per_dir_config, &dav_module);
9f18c80269be35c0b5653e84b0db0a24044722c4gstein /* assert: conf->provider != NULL */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* resolve the resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein *res_p = (*conf->provider->repos->get_resource)(r, conf->dir,
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein /* Apache will supply a default error for this. */
5a47cad1aef57039cd47eb34ebbc2959c610f326gstein (void) apr_set_userdata(*res_p, DAV_KEY_RESOURCE, apr_null_cleanup,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* ### hmm. this doesn't feel like the right place or thing to do */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* if there were any input headers requiring a Vary header in the response,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * add it now */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic dav_error * dav_open_lockdb(request_rec *r, int ro, dav_lockdb **lockdb)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_locks *hooks = DAV_GET_HOOKS_LOCKS(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* open the thing lazily */
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein const char *range_c;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm range_c = apr_table_get(r->headers_in, "content-range");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* malformed header. ignore it (per S14.16 of RFC2616) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (slash[1] != '*' && atol(slash + 1) <= *range_end)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* invalid range. ignore it (per S14.16 of RFC2616) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we now have a valid range */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the GET method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This method should only be called when the resource is not
f4c310fd2555c6faca1f980f00b161eadb089023gstein * visible to Apache. We will fetch the resource from the repository,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * then create a subrequest for Apache to handle.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 1 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Check resource type */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot GET this type of resource.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Cannot handle GET of a collection from a repository */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "No default response to GET for a "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "collection.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** We can use two different approaches for a GET.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** 1) get_pathname will return a pathname to a file which should be
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** sent to the client. If the repository provides this, then we
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** This is the best alternative since it allows us to do a sub-
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** request on the file, which gives the Apache framework a chance
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** to deal with negotiation, MIME types, or whatever.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** 2) open_stream and read_stream.
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *pathname;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository for copy of file */
f4c310fd2555c6faca1f980f00b161eadb089023gstein pathname = (*resource->hooks->get_pathname)(resource, &fhandle);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Convert to canonical filename, so Apache detects component
f4c310fd2555c6faca1f980f00b161eadb089023gstein * separators (on Windows, it only looks for '/', not '\')
f4c310fd2555c6faca1f980f00b161eadb089023gstein pathname = ap_os_case_canonical_filename(r->pool, pathname);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Create a sub-request with the new filename */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This may be a HEAD request */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### this enables header generation */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Run the sub-request */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Free resources */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* set up the HTTP headers for the response */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*resource->hooks->set_headers)(r, resource)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Unable to set up HTTP headers.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* use plain READ mode unless we see a Content-Range */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* process the Content-Range header (if present) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein has_range = dav_parse_range(r, &range_start, &range_end);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* use a read mode which is seekable */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* prep the output */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Content-Range",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_set_content_length(r, range_end - range_start + 1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*resource->hooks->open_stream)(resource, mode,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### assuming FORBIDDEN is probably not quite right... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Unable to GET contents for %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not seek to beginning of the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* all set. send the headers now. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (1) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if ((range_end - range_start + 1) > DAV_READ_BLOCKSIZE)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* note: range_end - range_start is an ssize_t */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*resource->hooks->read_stream)(stream, buffer,
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (amt == 0) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no more content */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### what to do with this error? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### range_start should equal range_end+1. if it doesn't, then
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### we did not send enough data to the client. the client will
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### hang (and timeout) waiting for the data.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### what to do? abort the connection?
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOTREACHED */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* validate resource on POST, then pass it off to the default handler */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Note: depth == 0. Implies no need for a multistatus response. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(r, resource, 0, NULL, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the PUT method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *body;
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((result = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK)) != OK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If not a file or collection resource, PUT not allowed */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot create resource %s with PUT.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Cannot PUT a collection */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot PUT to a collection.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein resource_state = dav_get_resource_state(r, resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note: depth == 0 normally requires no multistatus response. However,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** if we pass DAV_VALIDATE_PARENT, then we could get an error on a URI
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** other than the Request-URI, thereby requiring a multistatus.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** If the resource does not exist (DAV_RESOURCE_NULL), then we must
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** check the resource *and* its parent. If the resource exists or is
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** a locknull resource, then we check only the resource.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(r, resource, 0, NULL, &multi_response,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* make sure the resource can be modified (if versioning repository) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein 0 /* not parent_only */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* truncate and rewrite the file unless we see a Content-Range */
f4c310fd2555c6faca1f980f00b161eadb089023gstein has_range = dav_parse_range(r, &range_start, &range_end);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Create the new file in the repository */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*resource->hooks->open_stream)(resource, mode,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### assuming FORBIDDEN is probably not quite right... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Unable to PUT new contents for %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* a range was provided. seek to the start */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = (*resource->hooks->seek_stream)(stream, range_start);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm char *buffer = apr_palloc(r->pool, DAV_READ_BLOCKSIZE);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Once we start reading the request, then we must read the
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** whole darn thing. ap_discard_request_body() won't do anything
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** for a partially-read request.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* write whatever we read, until we see an error */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### what happens if we read more/less than the amount
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### specified in the Content-Range? eek...
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Error reading request body. This has precedence over
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** prior errors.
f4c310fd2555c6faca1f980f00b161eadb089023gstein "An error occurred while reading the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "request body.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no error during the write, but we hit one at close. use it. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Ensure that we think the resource exists now.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### eek. if an error occurred during the write and we did not commit,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### then the resource might NOT exist (e.g. dav_fs_repos.c)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* restore modifiability of resources back to what they were */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein err2 = dav_revert_resource_writability(r, resource, err != NULL /* undo if error */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* check for errors now */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just log a warning */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The PUT was successful, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem reverting the writability of "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "the resource or its parent collection.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### place the Content-Type and Content-Language into the propdb */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*locks_hooks->open_lockdb)(r, 0, 0, &lockdb)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The file creation was successful, but the locking failed. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The file was PUT successfully, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem opening the lock database "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "which prevents inheriting locks from the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "parent resources.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* notify lock system that we have created/replaced a resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = dav_notify_created(r, lockdb, resource, resource_state, 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The file creation was successful, but the locking failed. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The file was PUT successfully, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem updating its lock "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "information.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOTE: WebDAV spec, S8.7.1 states properties should be unaffected */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* return an appropriate response (HTTP_CREATED or HTTP_NO_CONTENT) */
7281ea331999debdc337b02ce37a3169e0e033a2gstein return dav_created(r, NULL, "Resource", resource_state == DAV_RESOURCE_EXISTS);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ### move this to dav_util? */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gsteinDAV_DECLARE(void) dav_add_response(dav_walk_resource *wres,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just drop some data into an dav_response */
00f73f5096966f34c7db15562e5d2e1233eb4571gstein resp->href = apr_pstrdup(wres->pool, wres->resource->uri);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the DELETE method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We don't use the request body right now, so torch it. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* 2518 says that depth must be infinity only for collections.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * For non-collections, depth is ignored, unless it is an illegal value (1).
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Depth must be \"infinity\" for DELETE of a collection.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Depth of \"1\" is not allowed for DELETE.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** If any resources fail the lock/If: conditions, then we must fail
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** the delete. Each of the failing resources will be listed within
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** a DAV:multistatus body, wrapped into a 424 response.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note that a failure on the resource itself does not generate a
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** multistatus response -- only internal members/collections.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(r, resource, depth, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not DELETE %s due to a failed "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "precondition (e.g. locks).",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### RFC 2518 s. 8.10.5 says to remove _all_ locks, not just those
f4c310fd2555c6faca1f980f00b161eadb089023gstein * locked by the token(s) in the if_header.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((result = dav_unlock(r, resource, NULL)) != OK) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* if versioned resource, make sure parent is checked out */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_ensure_resource_writable(r, resource, 1 /* parent_only */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* try to remove the resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = (*resource->hooks->remove_resource)(resource, &multi_response);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* restore writability of parent back to what it was */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein err2 = dav_revert_resource_writability(r, NULL, err != NULL /* undo if error */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* check for errors now */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not DELETE %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just log a warning */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The DELETE was successful, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem reverting the writability of "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "its parent collection.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### HTTP_NO_CONTENT if no body, HTTP_OK if there is a body (some day) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein/* generate DAV:supported-method-set OPTIONS response */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic dav_error *dav_gen_supported_methods(request_rec *r,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_text_append(r->pool, body, "<D:supported-method-set>" DEBUG_CR);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* show all supported methods */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* check for support of specific methods */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein for (child = elem->first_child; child != NULL; child = child->next) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* go through attributes to find method name */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein for (attr = child->attr; attr != NULL; attr = attr->next) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "A DAV:supported-method element "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "does not have a \"name\" attribute");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* see if method is supported */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_text_append(r->pool, body, "</D:supported-method-set>" DEBUG_CR);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein/* generate DAV:supported-live-property-set OPTIONS response */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic dav_error *dav_gen_supported_live_props(request_rec *r,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* open lock database, to report on supported lock properties */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* ### should open read-only */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if ((err = dav_open_lockdb(r, 0, &lockdb)) != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "The lock database could not be opened, "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "preventing report of supported lock properties.",
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* open the property database (readonly) for the resource */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "The property database could not be opened, "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "preventing report of supported properties.",
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_text_append(r->pool, body, "<D:supported-live-property-set>" DEBUG_CR);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* show all supported live properties */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein dav_get_props_result props = dav_get_allprops(propdb, DAV_PROP_INSERT_SUPPORTED);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* check for support of specific live property */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein for (child = elem->first_child; child != NULL; child = child->next) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein && strcmp(child->name, "supported-live-property") == 0) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* go through attributes to find name and namespace */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein for (attr = child->attr; attr != NULL; attr = attr->next) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "A DAV:supported-live-property element "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "does not have a \"name\" attribute");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* default namespace to DAV: */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* check for support of property */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein dav_get_liveprop_supported(propdb, nmspace, name, body);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_text_append(r->pool, body, "</D:supported-live-property-set>" DEBUG_CR);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein/* generate DAV:supported-report-set OPTIONS response */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gsteinstatic dav_error *dav_gen_supported_reports(request_rec *r,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_text_append(r->pool, body, "<D:supported-report-set>" DEBUG_CR);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if ((err = (*vsn_hooks->avail_reports)(resource, &reports)) != NULL) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "DAV:supported-report-set could not be determined "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "due to a problem fetching the available reports "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "for this resource.",
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* show all supported reports */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* Note: we presume reports->namespace is properly XML/URL quoted */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "<D:supported-report D:name=\"%s\" D:namespace=\"%s\"/>" DEBUG_CR,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* check for support of specific report */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein for (child = elem->first_child; child != NULL; child = child->next) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* go through attributes to find name and namespace */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein for (attr = child->attr; attr != NULL; attr = attr->next) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "A DAV:supported-report element "
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "does not have a \"name\" attribute");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* default namespace to DAV: */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* Note: we presume reports->nmspace is properly XML/URL quoted */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "<D:supported-report D:name=\"%s\" D:namespace=\"%s\"/>" DEBUG_CR,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_text_append(r->pool, body, "</D:supported-report-set>" DEBUG_CR);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the OPTIONS method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
7281ea331999debdc337b02ce37a3169e0e033a2gstein const dav_hooks_binding *binding_hooks = DAV_GET_HOOKS_BINDING(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *dav_level;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* parse any request body */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* note: doc == NULL if no request body */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "The \"options\" element was not found.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* determine which providers are available */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein dav_level = apr_pstrcat(r->pool, dav_level, ",bindings", NULL);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** MSFT Web Folders chokes if length of DAV header value > 63 characters!
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** To workaround that, we use separate DAV headers for versioning and
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** live prop provider namespace URIs.
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** If there is a versioning provider, generate DAV headers
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** for versioning options.
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein (*vsn_hooks->get_vsn_options)(r->pool, &vsn_options);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** Gather property set URIs from all the liveprop providers,
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** and generate a separate DAV header for each URI, to avoid
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** problems with long header lengths.
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm uri_ary = apr_make_array(r->pool, 5, sizeof(const char *));
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein apr_table_addn(r->headers_out, "DAV", ((char **)uri_ary->elts)[i]);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* this tells MSFT products to skip looking for FrontPage extensions */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_table_setn(r->headers_out, "MS-Author-Via", "DAV");
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** Determine which methods are allowed on the resource.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Three cases: resource is null (3), is lock-null (7.4), or exists.
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** All cases support OPTIONS, and if there is a lock provider, LOCK.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** (Lock-) null resources also support MKCOL and PUT.
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein ** Lock-null supports PROPFIND and UNLOCK.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Existing resources support lots of stuff.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### take into account resource type */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resource exists */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resource is lock-null. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resource is null. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### internal error! */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* If there is a versioning provider, add versioning methods */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* If there is a bindings provider, see if resource is bindable */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* Generate the Allow header */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* first, compute total length */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* add 1 for comma or null */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein *s++ = ',';
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* if there was no request body, then there is no response body */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* ### this will send a Content-Type. the default OPTIONS does not. */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* ### the default (ap_send_http_options) returns OK, but I believe
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein * ### that is because it is the default handler and nothing else
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein * ### will run after the thing. */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* handle each options request */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein for (elem = doc->root->first_child; elem != NULL; elem = elem->next) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* check for something we recognize first */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if (strcmp(elem->name, "supported-method-set") == 0) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein err = dav_gen_supported_methods(r, elem, methods, &body);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein else if (strcmp(elem->name, "supported-live-property-set") == 0) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein err = dav_gen_supported_live_props(r, resource, elem, &body);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein else if (strcmp(elem->name, "supported-report-set") == 0) {
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein err = dav_gen_supported_reports(r, resource, elem, vsn_hooks, &body);
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* if unrecognized option, pass to versioning provider */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein if ((err = (*vsn_hooks->get_option)(resource, elem, &body))
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* send the options response */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* send the headers */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein /* send the response body */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein "<D:options-response xmlns:D=\"DAV:\">" DEBUG_CR, r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* we've sent everything necessary to the client. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just return if we built the thing already */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (elem = elem->first_child; elem; elem = elem->next) {
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein "<D:status>HTTP/1.1 404 Not Found</D:status>" DEBUG_CR
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gsteinstatic dav_error * dav_propfind_walker(dav_walk_resource *wres, int calltype)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note: ctx->doc can only be NULL for DAV_PROPFIND_IS_ALLPROP. Since
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** dav_get_allprops() does not need to do namespace translation,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** we're okay.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note: we cast to lose the "const". The propdb won't try to change
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** the resource, however, since we are opening readonly.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### do something with err! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* some props were expected on this collection/resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no props on this collection/resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### what to do about closing the propdb on server failure? */
c7548bcd69fbe1338ad855ba44f0b2b774e57bd8gstein dav_prop_insert what = ctx->propfind_type == DAV_PROPFIND_IS_ALLPROP
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the PROPFIND method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 1 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (dav_get_resource_state(r, resource) == DAV_RESOURCE_NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* dav_get_depth() supplies additional information for the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * default message. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* default is to DISALLOW these requests */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "PROPFIND requests with a "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Depth of \"infinity\" are "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "not allowed for %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* note: doc == NULL if no request body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The \"propfind\" element was not found.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### validate that only one of these three elements is present */
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (child = dav_find_child(doc->root, "allprop")) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* note: no request body implies allprop */
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if ((child = dav_find_child(doc->root, "propname")) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if ((child = dav_find_child(doc->root, "prop")) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* "propfind" element must have one of the above three children */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The \"propfind\" element does not contain one of "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "the required child elements (the specific command).");
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein ctx.w.walk_type = DAV_WALKTYPE_NORMAL | DAV_WALKTYPE_AUTH;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### should open read-only */
52c1d304b1bd8e05da40a7cded2ecb9f0ba614c5gstein if ((err = dav_open_lockdb(r, 0, &ctx.w.lockdb)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The lock database could not be opened, "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "preventing access to the various lock "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "properties for the PROPFIND.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* if we have a lock database, then we can walk locknull resources */
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein err = (*resource->hooks->walk)(&ctx.w, depth, &multi_status);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* return a 207 (Multi-Status) response now. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* if a 404 was generated for an HREF, then we need to spit out the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * doc's namespaces for use by the 404. Note that <response> elements
f4c310fd2555c6faca1f980f00b161eadb089023gstein * will override these ns0, ns1, etc, but NOT within the <response>
f4c310fd2555c6faca1f980f00b161eadb089023gstein * scope for the badprops. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOTE: propstat_404 != NULL implies doc != NULL */
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein dav_send_multistatus(r, HTTP_MULTI_STATUS, multi_status,
f94aab38f6ee899f463f0118ea395291f7c5b4cegstein dav_send_multistatus(r, HTTP_MULTI_STATUS, multi_status, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* the response has been sent. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *s;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### might be nice to sort by status code and description */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for ( ; i-- > 0; ++ctx ) {
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein "<D:prop>");
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein ap_text_append(p, &hdr, ap_xml_empty_elem(p, ctx->prop));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* nothing was assigned here yet, so make it a 424 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err424_set = dav_new_error(p, HTTP_FAILED_DEPENDENCY, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Attempted DAV:set operation "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "could not be completed due "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "to other errors.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein err424_delete = dav_new_error(p, HTTP_FAILED_DEPENDENCY, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Attempted DAV:remove "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "operation could not be "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "completed due to other "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "errors.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein "<D:status>"
f4c310fd2555c6faca1f980f00b161eadb089023gstein "HTTP/1.1 %d (status)"
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### we should use compute_desc if necessary... */
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein ap_text_append(p, &hdr, "<D:responsedescription>" DEBUG_CR);
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein ap_text_append(p, &hdr, "</D:responsedescription>" DEBUG_CR);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougmstatic ap_text * dav_success_proppatch(apr_pool_t *p, apr_array_header_t *prop_ctx)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### we probably need to revise the way we assemble the response...
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### this code assumes everything will return status==200.
f4c310fd2555c6faca1f980f00b161eadb089023gstein for ( ; i-- > 0; ++ctx ) {
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein ap_text_append(p, &hdr, ap_xml_empty_elem(p, ctx->prop));
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Call <func> for each context. This can stop when an error occurs, or
f4c310fd2555c6faca1f980f00b161eadb089023gstein** simply iterate through the whole list.
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Returns 1 if an error occurs (and the iteration is aborted). Returns 0
f4c310fd2555c6faca1f980f00b161eadb089023gstein** if all elements are processed.
f4c310fd2555c6faca1f980f00b161eadb089023gstein** If <reverse> is true (non-zero), then the list is traversed in
f4c310fd2555c6faca1f980f00b161eadb089023gstein** reverse order.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int dav_process_ctx_list(void (*func)(dav_prop_ctx *ctx),
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (i--) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the PROPPATCH method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* note: doc == NULL if no request body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (doc == NULL || !dav_validate_root(doc, "propertyupdate")) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The request body does not contain "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "a \"propertyupdate\" element.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Check If-Headers and existing locks */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Note: depth == 0. Implies no need for a multistatus response. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(r, resource, 0, NULL, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_open_propdb(r, NULL, resource, 0, doc->namespaces,
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = dav_push_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not open the property "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "database for %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### what to do about closing the propdb on server failure? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### validate "live" properties */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* set up an array to hold property operation contexts */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ctx_list = apr_make_array(r->pool, 10, sizeof(dav_prop_ctx));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* do a first pass to ensure that all "remove" properties exist */
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (child = doc->root->first_child; child; child = child->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ignore children that are not set/remove */
f4c310fd2555c6faca1f980f00b161eadb089023gstein || (!(is_remove = strcmp(child->name, "remove") == 0)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* make sure that a "prop" child exists for set/remove */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((prop_group = dav_find_child(child, "prop")) == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "A \"prop\" element is missing inside "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "the propertyupdate command.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ctx->operation = is_remove ? DAV_PROP_OP_DELETE : DAV_PROP_OP_SET;
f4c310fd2555c6faca1f980f00b161eadb089023gstein ctx->r = r; /* for later use by dav_prop_log_errors() */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### should test that we found at least one set/remove */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* execute all of the operations */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (!failure && dav_process_ctx_list(dav_prop_exec, ctx_list, 1, 0)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* generate a failure/success response */
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void)dav_process_ctx_list(dav_prop_rollback, ctx_list, 0, 1);
f4c310fd2555c6faca1f980f00b161eadb089023gstein propstat_text = dav_failed_proppatch(r->pool, ctx_list);
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void)dav_process_ctx_list(dav_prop_commit, ctx_list, 0, 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein propstat_text = dav_success_proppatch(r->pool, ctx_list);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* make sure this gets closed! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* log any errors that occurred */
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void)dav_process_ctx_list(dav_prop_log_errors, ctx_list, 0, 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### should probably use something new to pass along this text... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_send_multistatus(r, HTTP_MULTI_STATUS, &resp, doc->namespaces);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* the response has been sent. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This is snarfed from ap_setup_client_block(). We could get pretty
f4c310fd2555c6faca1f980f00b161eadb089023gstein * close to this behavior by passing REQUEST_NO_BODY, but we need to
f4c310fd2555c6faca1f980f00b161eadb089023gstein * return HTTP_UNSUPPORTED_MEDIA_TYPE (while ap_setup_client_block
f4c310fd2555c6faca1f980f00b161eadb089023gstein * returns HTTP_REQUEST_ENTITY_TOO_LARGE). */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *tenc = apr_table_get(r->headers_in, "Transfer-Encoding");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *lenp = apr_table_get(r->headers_in, "Content-Length");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* make sure to set the Apache request fields properly. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Use this instead of Apache's default error string */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein else if (lenp) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### log something? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Get rid of the body. this will call ap_setup_client_block(), but
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** our copy above has already verified its work.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the MKCOL method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* handle the request body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### this may move lower once we start processing bodies */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* oops. something was already there! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### we should provide a specific error message! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein resource_state = dav_get_resource_state(r, resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Check If-Headers and existing locks.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note: depth == 0 normally requires no multistatus response. However,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** if we pass DAV_VALIDATE_PARENT, then we could get an error on a URI
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** other than the Request-URI, thereby requiring a multistatus.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** If the resource does not exist (DAV_RESOURCE_NULL), then we must
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** check the resource *and* its parent. If the resource exists or is
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** a locknull resource, then we check only the resource.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(r, resource, 0, NULL, &multi_status,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* if versioned resource, make sure parent is checked out */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_ensure_resource_writable(r, resource, 1 /* parent_only */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* try to create the collection */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein err = (*resource->hooks->create_collection)(resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* restore modifiability of parent back to what it was */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein err2 = dav_revert_resource_writability(r, NULL, err != NULL /* undo if error */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* check for errors now */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just log a warning */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The MKCOL was successful, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem reverting the writability of "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "its parent collection.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*locks_hooks->open_lockdb)(r, 0, 0, &lockdb)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The directory creation was successful, but the locking failed. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The MKCOL was successful, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem opening the lock database "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "which prevents inheriting locks from the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "parent resources.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* notify lock system that we have created/replaced a resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = dav_notify_created(r, lockdb, resource, resource_state, 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The dir creation was successful, but the locking failed. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The MKCOL was successful, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem updating its lock "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "information.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* return an appropriate response (HTTP_CREATED) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the COPY and MOVE methods */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int dav_method_copymove(request_rec *r, int is_move)
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *body;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *dest;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, !is_move /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If not a file or collection resource, COPY/MOVE not allowed */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot COPY/MOVE resource %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein return dav_error_response(r, HTTP_METHOD_NOT_ALLOWED, body);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* get the destination URI */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Look in headers provided by Netscape's Roaming Profiles */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *nscp_host = apr_table_get(r->headers_in, "Host");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm const char *nscp_path = apr_table_get(r->headers_in, "New-uri");
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm dest = apr_psprintf(r->pool, "http://%s%s", nscp_host, nscp_path);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The request is missing a Destination header.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### this assumes that dav_lookup_uri() only generates a status
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### that Apache can provide a status line for!! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return dav_error_response(r, lookup.err.status, lookup.err.desc);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### how best to report this... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Destination URI had an error.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Resolve destination resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(lookup.rnew, 0 /*target_allowed*/, NULL, &resnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* are the two resources handled by the same repository? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### this message exposes some backend config, but screw it... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Destination URI is handled by a "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "different repository than the source URI. "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "MOVE or COPY between repositories is "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "not possible.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* get and parse the overwrite header value */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* dav_get_overwrite() supplies additional information for the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * default message. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* quick failure test: if dest exists and overwrite is false. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Supply some text for the error response body. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return dav_error_response(r, HTTP_PRECONDITION_FAILED,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Destination is not empty and "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Overwrite is not \"T\"");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* are the source and destination the same? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((*resource->hooks->is_same_resource)(resource, resnew)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Supply some text for the error response body. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Source and Destination URIs are the same.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* get and parse the Depth header value. "0" and "infinity" are legal. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* dav_get_depth() supplies additional information for the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * default message. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Depth must be \"0\" or \"infinity\" for COPY or MOVE.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* This supplies additional information for the default message. */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Depth must be \"infinity\" when moving a collection.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Check If-Headers and existing locks for each resource in the source
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** if we are performing a MOVE. We will return a 424 response with a
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** DAV:multistatus body. The multistatus responses will contain the
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** information about any resource that fails the validation.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** We check the parent resource, too, since this is a MOVE. Moving the
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** resource effectively removes it from the parent collection, so we
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** must ensure that we have met the appropriate conditions.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** If a problem occurs with the Request-URI itself, then a plain error
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** (rather than a multistatus) will be returned.
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (err = dav_validate_request(r, resource, depth, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not MOVE %s due to a failed "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "precondition on the source "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "(e.g. locks).",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Check If-Headers and existing locks for destination. Note that we
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** use depth==infinity since the target (hierarchy) will be deleted
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** before the move/copy is completed.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note that we are overwriting the target, which implies a DELETE, so
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** we are subject to the error/response rules as a DELETE. Namely, we
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** will return a 424 error if any of the validations fail.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** (see dav_method_delete() for more information)
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(lookup.rnew, resnew, DAV_INFINITY, NULL,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not MOVE/COPY %s due to a "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "failed precondition on the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "destination (e.g. locks).",
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (*resource->hooks->is_parent_resource)(resource, resnew)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Supply some text for the error response body. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Source collection contains the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Destination.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (*resnew->hooks->is_parent_resource)(resnew, resource)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The destination must exist (since it contains the source), and
f4c310fd2555c6faca1f980f00b161eadb089023gstein * a condition above implies Overwrite==T. Obviously, we cannot
f4c310fd2555c6faca1f980f00b161eadb089023gstein * delete the Destination before the MOVE/COPY, as that would
f4c310fd2555c6faca1f980f00b161eadb089023gstein * delete the Source.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Supply some text for the error response body. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Destination collection contains the Source "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "and Overwrite has been specified.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### for now, we don't need anything in the body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_open_lockdb(r, 0, &lockdb)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* remove any locks from the old resources */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### this is Yet Another Traversal. if we do a rename(), then we
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### really don't have to do this in some cases since the inode
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### values will remain constant across the move. but we can't
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### know that fact from outside the provider :-(
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### note that we now have a problem atomicity in the move/copy
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### since a failure after this would have removed locks (technically,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### this is okay to do, but really...)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### this is wrong! it blasts direct locks on parent resources */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### pass lockdb! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* remember whether target resource existed */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* if this is a move, then the source parent collection will be modified */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if ((err = dav_ensure_resource_writable(r, resource, 1 /* parent_only */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* prepare the destination collection for modification */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_ensure_resource_writable(r, resnew, 1 /* parent_only */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* could not make destination writable:
f4c310fd2555c6faca1f980f00b161eadb089023gstein * if move, restore state of source parent
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein (void) dav_revert_resource_writability(r, NULL, 1 /* undo */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If source and destination parents are the same, then
f4c310fd2555c6faca1f980f00b161eadb089023gstein * use the same object, so status updates to one are reflected
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * in the other, when reverting their writable states.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein && (*src_av_info.parent_resource->hooks->is_same_resource)
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein (src_av_info.parent_resource, dst_av_info.parent_resource)) {
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein dst_av_info.parent_resource = src_av_info.parent_resource;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* New resource will be same kind as source */
4b28d4385b48010bc271cba9b40b56e458cbd5d8keith resource_state = dav_get_resource_state(lookup.rnew, resnew);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If target exists, remove it first (we know Ovewrite must be TRUE).
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Then try to copy/move the resource.
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = (*resnew->hooks->remove_resource)(resnew, &multi_response);
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = (*resource->hooks->move_resource)(resource, resnew,
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = (*resource->hooks->copy_resource)(resource, resnew, depth,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* restore parent collection states */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein err2 = dav_revert_resource_writability(r, NULL, err != NULL /* undo if error */,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein err3 = dav_revert_resource_writability(r, NULL, err != NULL /* undo if error */,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* check for error from remove/copy/move operations */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not MOVE/COPY %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* check for errors from reverting writability */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just log a warning */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The MOVE/COPY was successful, but there was a "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "problem reverting the writability of the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "source parent collection.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just log a warning */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The MOVE/COPY was successful, but there was a "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "problem reverting the writability of the "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "destination parent collection.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* propagate any indirect locks at the target */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* notify lock system that we have created/replaced a resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = dav_notify_created(r, lockdb, resnew, resource_state, depth);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* The move/copy was successful, but the locking failed. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The MOVE/COPY was successful, but there "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "was a problem updating the lock "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "information.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* return an appropriate response (HTTP_CREATED or HTTP_NO_CONTENT) */
50bd75672ef114fb839dd9643c192b432fdf344cgstein return dav_created(r, lookup.rnew->uri, "Destination", replaced);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* dav_method_lock: Handler to implement the DAV LOCK method
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Returns appropriate HTTP_* response.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If no locks provider, decline the request */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Depth must be 0 or \"infinity\" for LOCK.");
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* Ask repository module to resolve the resource.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * DeltaV says result of target selector is undefined,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * so allow it, and let provider reject the lock attempt
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * on a version if it wants to.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 1 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Open writable. Unless an error occurs, we'll be
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** writing into the database.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*locks_hooks->open_lockdb)(r, 0, 0, &lockdb)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_lock_parse_lockinfo(r, resource, lockdb, doc,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description to err? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein resource_state = dav_get_resource_state(r, resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Check If-Headers and existing locks.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** If this will create a locknull resource, then the LOCK will affect
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** the parent collection (much like a PUT/MKCOL). For that case, we must
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** validate the parent resource's conditions.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(r, resource, depth, NULL, &multi_response,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not LOCK %s due to a failed "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "precondition (e.g. other locks).",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Refresh request
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### Assumption: We can renew multiple locks on the same resource
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### at once. First harvest all the positive lock-tokens given in
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### the If header. Then modify the lock entries for this resource
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### with the new Timeout val.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_get_locktoken_list(r, <l)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The lock refresh for %s failed "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "because no lock tokens were "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "specified in an \"If:\" "
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*locks_hooks->refresh_locks)(lockdb, resource, ltl,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description to err? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* New lock request */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* apply lower bound (if any) from DAVMinTimeout directive */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = dav_add_lock(r, resource, lockdb, lock, &multi_response);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description to err? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein (*locks_hooks->format_locktoken)(r->pool, lock->locktoken),
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm apr_table_set(r->headers_out, "Lock-Token", locktoken_txt);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_rputs(DAV_XML_HEADER DEBUG_CR "<D:prop xmlns:D=\"DAV:\">" DEBUG_CR, r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* the response has been sent. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* dav_method_unlock: Handler to implement the DAV UNLOCK method
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Returns appropriate HTTP_* response.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If no locks provider, decline the request */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm if ((const_locktoken_txt = apr_table_get(r->headers_in, "Lock-Token")) == NULL) {
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Unlock failed (%s): No Lock-Token specified in header", r->filename);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm locktoken_txt = apr_pstrdup(r->pool, const_locktoken_txt);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### should provide more specifics... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (locktoken_txt[strlen(locktoken_txt) - 1] != '>') {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### should provide more specifics... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*locks_hooks->parse_locktoken)(r->pool, locktoken_txt,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The UNLOCK on %s failed -- an "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "invalid lock token was specified "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "in the \"If:\" header.",
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein /* Ask repository module to resolve the resource.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * DeltaV says result of target selector is undefined,
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * so allow it, and let provider reject the unlock attempt
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein * on a version if it wants to.
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 1 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein resource_state = dav_get_resource_state(r, resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Check If-Headers and existing locks.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Note: depth == 0 normally requires no multistatus response. However,
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** if we pass DAV_VALIDATE_PARENT, then we could get an error on a URI
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** other than the Request-URI, thereby requiring a multistatus.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** If the resource is a locknull resource, then the UNLOCK will affect
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** the parent collection (much like a delete). For that case, we must
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** validate the parent resource's conditions.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_validate_request(r, resource, 0, locktoken,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add a higher-level description? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### RFC 2518 s. 8.11: If this resource is locked by locktoken,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * _all_ resources locked by locktoken are released. It does not say
f4c310fd2555c6faca1f980f00b161eadb089023gstein * resource has to be the root of an infinte lock. Thus, an UNLOCK
f4c310fd2555c6faca1f980f00b161eadb089023gstein * on any part of an infinte lock will remove the lock on all resources.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * For us, if r->filename represents an indirect lock (part of an infinity lock),
f4c310fd2555c6faca1f980f00b161eadb089023gstein * we must actually perform an UNLOCK on the direct lock for this resource.
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((result = dav_unlock(r, resource, locktoken)) != OK) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r);
7281ea331999debdc337b02ce37a3169e0e033a2gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* if no versioning provider, decline the request */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ask repository module to resolve the resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* remember the pre-creation resource state */
7281ea331999debdc337b02ce37a3169e0e033a2gstein resource_state = dav_get_resource_state(r, resource);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* parse the request body (may be a version-control element) */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* note: doc == NULL if no request body */
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The request body does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a \"version-control\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* get the version URI */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((child = dav_find_child(doc->root, "version")) == NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The \"version-control\" element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a \"version\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((child = dav_find_child(child, "href")) == NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The \"version\" element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "an \"href\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* get version URI */
1d69b25dcd7ca16cd3ee662bf768ffb1d36c46b6gstein ap_xml_to_text(r->pool, child, AP_XML_X2T_INNER, NULL, NULL,
1d69b25dcd7ca16cd3ee662bf768ffb1d36c46b6gstein if (tsize == 0) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "An \"href\" element does not contain a URI.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Check request preconditions */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### need a general mechanism for reporting precondition violations
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### (should be returning XML document for 403/409 responses)
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* if not versioning existing resource, must specify version to select */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "<DAV:initial-version-required/>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* cannot add resource to existing version history */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "<DAV:cannot-add-to-existing-history/>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* resource must be unversioned and versionable, or version selector */
7281ea331999debdc337b02ce37a3169e0e033a2gstein || (!resource->versioned && !(vsn_hooks->versionable)(resource))) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein "<DAV:must-be-versionable/>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* the DeltaV spec says if resource is a version selector,
7281ea331999debdc337b02ce37a3169e0e033a2gstein * then VERSION-CONTROL is a no-op
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* set the Cache-Control header, per the spec */
7281ea331999debdc337b02ce37a3169e0e033a2gstein apr_table_setn(r->headers_out, "Cache-Control", "no-cache");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* no body */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Check If-Headers and existing locks */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Note: depth == 0. Implies no need for a multistatus response. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = dav_validate_request(r, resource, 0, NULL, NULL,
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* if in versioned collection, make sure parent is checked out */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = dav_ensure_resource_writable(r, resource, 1 /* parent_only */,
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* attempt to version-control the resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = (*vsn_hooks->vsn_control)(resource, target)) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein dav_revert_resource_writability(r, resource, 1 /*undo*/, &av_info);
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Could not VERSION-CONTROL resource %s.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* revert writability of parent directory */
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = dav_revert_resource_writability(r, resource, 0 /*undo*/, &av_info);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* just log a warning */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The VERSION-CONTROL was successful, but there "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "was a problem reverting the writability of "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "the parent collection.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* if the resource is lockable, let lock system know of new resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein && (*locks_hooks->get_supportedlock)(resource) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = (*locks_hooks->open_lockdb)(r, 0, 0, &lockdb)) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* The resource creation was successful, but the locking failed. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The VERSION-CONTROL was successful, but there "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "was a problem opening the lock database "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "which prevents inheriting locks from the "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "parent resources.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* notify lock system that we have created/replaced a resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = dav_notify_created(r, lockdb, resource, resource_state, 0);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* The dir creation was successful, but the locking failed. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The VERSION-CONTROL was successful, but there "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "was a problem updating its lock "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "information.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* set the Cache-Control header, per the spec */
7281ea331999debdc337b02ce37a3169e0e033a2gstein apr_table_setn(r->headers_out, "Cache-Control", "no-cache");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* return an appropriate response (HTTP_CREATED) */
7281ea331999debdc337b02ce37a3169e0e033a2gstein return dav_created(r, resource->uri, "Version selector", 0 /*replaced*/);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the CHECKOUT method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If no versioning provider, decline the request */
50bd75672ef114fb839dd9643c192b432fdf344cgstein /* This supplies additional information for the default msg. */
50bd75672ef114fb839dd9643c192b432fdf344cgstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
50bd75672ef114fb839dd9643c192b432fdf344cgstein "The request body, if present, must be a "
50bd75672ef114fb839dd9643c192b432fdf344cgstein "DAV:checkout element.");
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if ((target = dav_find_child(doc->root, "version")) == NULL)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 1 /*target_allowed*/, target, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Check the state of the resource: must be a file or collection,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * must be versioned, and must not already be checked out.
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot checkout this type of resource.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot checkout unversioned resource.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The resource is already checked out to the workspace.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### do lock checks, once behavior is defined */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Do the checkout */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if ((err = (*vsn_hooks->checkout)(resource, &working_resource)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not CHECKOUT resource %s.",
de18a9e85398b9c79c422f578633ed56c2747bbbgstein /* set the Cache-Control header, per the spec */
50bd75672ef114fb839dd9643c192b432fdf344cgstein apr_table_setn(r->headers_out, "Cache-Control", "no-cache");
de18a9e85398b9c79c422f578633ed56c2747bbbgstein /* use appropriate URI for Location header */
de18a9e85398b9c79c422f578633ed56c2747bbbgstein return dav_created(r, working_resource->uri, "Checked-out resource", 0);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the UNCHECKOUT method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If no versioning provider, decline the request */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Check the state of the resource: must be a file or collection,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * must be versioned, and must be checked out.
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot uncheckout this type of resource.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot uncheckout unversioned resource.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The resource is not checked out to the workspace.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### do lock checks, once behavior is defined */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Do the uncheckout */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*vsn_hooks->uncheckout)(resource)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not UNCHECKOUT resource %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the CHECKIN method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If no versioning provider, decline the request */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the resource */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein result = dav_get_resource(r, 0 /* target_allowed */, NULL, &resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Check the state of the resource: must be a file or collection,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * must be versioned, and must be checked out.
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot checkin this type of resource.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot checkin unversioned resource.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein "The resource is not checked out to the workspace.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### do lock checks, once behavior is defined */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Do the checkin */
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein if ((err = (*vsn_hooks->checkin)(resource, &new_version)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not CHECKIN resource %s.",
83719c22db4a6d0575bb4f7f34382d7b185a6f74gstein return dav_created(r, new_version->uri, "Version", 0);
7281ea331999debdc337b02ce37a3169e0e033a2gstein/* context maintained during SET-TARGET treewalk */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* input: */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* target specifier */
7281ea331999debdc337b02ce37a3169e0e033a2gstein const char *target;
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* flag for whether target is version URI or label */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* version provider hooks */
7281ea331999debdc337b02ce37a3169e0e033a2gsteinstatic dav_error * dav_set_target_walker(dav_walk_resource *wres, int calltype)
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Check the state of the resource: must be a checked-in version
7281ea331999debdc337b02ce37a3169e0e033a2gstein * or baseline selector
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### need a general mechanism for reporting precondition violations
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### (should be returning XML document for 403/409 responses)
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (wres->resource->type != DAV_RESOURCE_TYPE_REGULAR
7281ea331999debdc337b02ce37a3169e0e033a2gstein || !wres->resource->versioned || wres->resource->working) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein "<DAV:must-be-checked-in-version-selector/>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* do the set-target operation */
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = (*ctx->vsn_hooks->set_target)(wres->resource, ctx->target, ctx->is_label);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### need utility routine to add response with description? */
50bd75672ef114fb839dd9643c192b432fdf344cgstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
50bd75672ef114fb839dd9643c192b432fdf344cgstein /* If no versioning provider, decline the request */
50bd75672ef114fb839dd9643c192b432fdf344cgstein /* Ask repository module to resolve the resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
50bd75672ef114fb839dd9643c192b432fdf344cgstein /* Apache will supply a default error for this. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* dav_get_depth() supplies additional information for the
7281ea331999debdc337b02ce37a3169e0e033a2gstein * default message. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* parse the request body */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (doc == NULL || !dav_validate_root(doc, "set-target")) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* This supplies additional information for the default message. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The request body does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a \"set-target\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* check for label-name or version element */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((child = dav_find_child(doc->root, "label-name")) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein else if ((child = dav_find_child(doc->root, "version")) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* get the href element */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((child = dav_find_child(child, "href")) == NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The version element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "an \"href\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The \"set-target\" element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a \"label-name\" or \"version\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* get the target value (a label or a version URI */
1d69b25dcd7ca16cd3ee662bf768ffb1d36c46b6gstein ap_xml_to_text(r->pool, child, AP_XML_X2T_INNER, NULL, NULL,
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (tsize == 0) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "A \"label-name\" or \"href\" element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "any content.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* do the set-target operation walk */
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = (*resource->hooks->walk)(&ctx.w, depth, &multi_status);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* some sort of error occurred which terminated the walk */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The SET-TARGET operation was terminated prematurely.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* One or more resources had errors. If depth was zero, convert
7281ea331999debdc337b02ce37a3169e0e033a2gstein * response to simple error, else make sure there is an
7281ea331999debdc337b02ce37a3169e0e033a2gstein * overall error to pass to dav_handle_err()
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (depth == 0) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = dav_new_error(r->pool, multi_status->status, 0, multi_status->desc);
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Errors occurred during the SET-TARGET operation.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* set the Cache-Control header, per the spec */
7281ea331999debdc337b02ce37a3169e0e033a2gstein apr_table_setn(r->headers_out, "Cache-Control", "no-cache");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* no body */
7281ea331999debdc337b02ce37a3169e0e033a2gstein/* context maintained during LABEL treewalk */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* input: */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* label being manipulated */
7281ea331999debdc337b02ce37a3169e0e033a2gstein const char *label;
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* label operation */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* version provider hooks */
7281ea331999debdc337b02ce37a3169e0e033a2gsteinstatic dav_error * dav_label_walker(dav_walk_resource *wres, int calltype)
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Check the state of the resource: must be a version or
7281ea331999debdc337b02ce37a3169e0e033a2gstein * non-checkedout version selector
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### need a general mechanism for reporting precondition violations
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### (should be returning XML document for 403/409 responses)
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (wres->resource->type != DAV_RESOURCE_TYPE_VERSION &&
7281ea331999debdc337b02ce37a3169e0e033a2gstein "<DAV:must-be-version-or-version-selector/>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein "<DAV:must-not-be-checked-out/>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* do the label operation */
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = (*ctx->vsn_hooks->remove_label)(wres->resource, ctx->label);
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = (*ctx->vsn_hooks->add_label)(wres->resource, ctx->label,
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### need utility routine to add response with description? */
7281ea331999debdc337b02ce37a3169e0e033a2gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* If no versioning provider, or the provider doesn't support
7281ea331999debdc337b02ce37a3169e0e033a2gstein * labels, decline the request */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (vsn_hooks == NULL || vsn_hooks->add_label == NULL)
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Ask repository module to resolve the resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein result = dav_get_resource(r, 1 /*target_allowed*/, NULL, &resource);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Apache will supply a default error for this. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* dav_get_depth() supplies additional information for the
7281ea331999debdc337b02ce37a3169e0e033a2gstein * default message. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* parse the request body */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (doc == NULL || !dav_validate_root(doc, "label")) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* This supplies additional information for the default message. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The request body does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a \"label\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* check for add, set, or remove element */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((child = dav_find_child(doc->root, "add")) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein else if ((child = dav_find_child(doc->root, "set")) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein else if ((child = dav_find_child(doc->root, "remove")) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The \"label\" element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "an \"add\", \"set\", or \"remove\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* get the label string */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((child = dav_find_child(child, "label-name")) == NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The label command element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a \"label-name\" element.");
1d69b25dcd7ca16cd3ee662bf768ffb1d36c46b6gstein ap_xml_to_text(r->pool, child, AP_XML_X2T_INNER, NULL, NULL,
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (tsize == 0) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "A \"label-name\" element does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a label name.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* do the label operation walk */
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = (*resource->hooks->walk)(&ctx.w, depth, &multi_status);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* some sort of error occurred which terminated the walk */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The LABEL operation was terminated prematurely.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* One or more resources had errors. If depth was zero, convert
7281ea331999debdc337b02ce37a3169e0e033a2gstein * response to simple error, else make sure there is an
7281ea331999debdc337b02ce37a3169e0e033a2gstein * overall error to pass to dav_handle_err()
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (depth == 0) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = dav_new_error(r->pool, multi_status->status, 0, multi_status->desc);
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Errors occurred during the LABEL operation.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* set the Cache-Control header, per the spec */
7281ea331999debdc337b02ce37a3169e0e033a2gstein apr_table_setn(r->headers_out, "Cache-Control", "no-cache");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* no body */
7281ea331999debdc337b02ce37a3169e0e033a2gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* If no versioning provider, decline the request */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* This supplies additional information for the default msg. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The request body must specify a report.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Ask repository module to resolve the resource.
7281ea331999debdc337b02ce37a3169e0e033a2gstein * First determine whether a Target-Selector header is allowed
7281ea331999debdc337b02ce37a3169e0e033a2gstein * for this report.
7281ea331999debdc337b02ce37a3169e0e033a2gstein target_allowed = (*vsn_hooks->report_target_selector_allowed)(doc);
7281ea331999debdc337b02ce37a3169e0e033a2gstein result = dav_get_resource(r, target_allowed, NULL, &resource);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Apache will supply a default error for this. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* run report hook */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### writing large reports to memory could be bad...
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### but if provider generated output directly, it would
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### have to handle error responses as well.
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = (*vsn_hooks->get_report)(r, resource, doc, &hdr)) != NULL)
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* send the report response */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* send the headers and start a timeout */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* send the response body */
7281ea331999debdc337b02ce37a3169e0e033a2gstein const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* if no versioning provider, or the provider does not support workspaces,
7281ea331999debdc337b02ce37a3169e0e033a2gstein * decline the request
7281ea331999debdc337b02ce37a3169e0e033a2gstein if (vsn_hooks == NULL || vsn_hooks->make_workspace == NULL)
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ask repository module to resolve the resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein result = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* parse the request body (must be a mkworkspace element) */
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The request body does not contain "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "a \"mkworkspace\" element.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Check request preconditions */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### need a general mechanism for reporting precondition violations
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### (should be returning XML document for 403/409 responses)
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* resource must not already exist */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "<DAV:resource-must-be-null/>");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### what about locking? */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* attempt to create the workspace */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = (*vsn_hooks->make_workspace)(resource, doc)) != NULL) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Could not create workspace %s.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* set the Cache-Control header, per the spec */
7281ea331999debdc337b02ce37a3169e0e033a2gstein apr_table_setn(r->headers_out, "Cache-Control", "no-cache");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* return an appropriate response (HTTP_CREATED) */
7281ea331999debdc337b02ce37a3169e0e033a2gstein return dav_created(r, resource->uri, "Workspace", 0 /*replaced*/);
7281ea331999debdc337b02ce37a3169e0e033a2gsteinstatic int dav_method_baseline_control(request_rec *r)
7281ea331999debdc337b02ce37a3169e0e033a2gstein const dav_hooks_binding *binding_hooks = DAV_GET_HOOKS_BINDING(r);
7281ea331999debdc337b02ce37a3169e0e033a2gstein const char *dest;
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* If no bindings provider, decline the request */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Ask repository module to resolve the resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein result = dav_get_resource(r, 0 /*!target_allowed*/, NULL, &resource);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* Apache will supply a default error for this. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* get the destination URI */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* This supplies additional information for the default message. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The request is missing a Destination header.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* This supplies additional information for the default message. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### Bindings protocol draft 02 says to return 507
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### (Cross Server Binding Forbidden); Apache already defines 507
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### as HTTP_INSUFFICIENT_STORAGE. So, for now, we'll return
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### HTTP_FORBIDDEN
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Cross server bindings are not allowed by this server.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### this assumes that dav_lookup_uri() only generates a status
7281ea331999debdc337b02ce37a3169e0e033a2gstein * ### that Apache can provide a status line for!! */
7281ea331999debdc337b02ce37a3169e0e033a2gstein return dav_error_response(r, lookup.err.status, lookup.err.desc);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### how best to report this... */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Destination URI had an error.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* resolve binding resource */
7281ea331999debdc337b02ce37a3169e0e033a2gstein result = dav_get_resource(lookup.rnew, 0 /*!target_allowed*/, NULL, &binding);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* are the two resources handled by the same repository? */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### this message exposes some backend config, but screw it... */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Destination URI is handled by a "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "different repository than the source URI. "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "BIND between repositories is not possible.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* get and parse the overwrite header value */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* dav_get_overwrite() supplies additional information for the
7281ea331999debdc337b02ce37a3169e0e033a2gstein * default message. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* quick failure test: if dest exists and overwrite is false. */
7281ea331999debdc337b02ce37a3169e0e033a2gstein return dav_error_response(r, HTTP_PRECONDITION_FAILED,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Destination is not empty and "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Overwrite is not \"T\"");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* are the source and destination the same? */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((*resource->hooks->is_same_resource)(resource, binding)) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Source and Destination URIs are the same.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein ** Check If-Headers and existing locks for destination. Note that we
7281ea331999debdc337b02ce37a3169e0e033a2gstein ** use depth==infinity since the target (hierarchy) will be deleted
7281ea331999debdc337b02ce37a3169e0e033a2gstein ** before the move/copy is completed.
7281ea331999debdc337b02ce37a3169e0e033a2gstein ** Note that we are overwriting the target, which implies a DELETE, so
7281ea331999debdc337b02ce37a3169e0e033a2gstein ** we are subject to the error/response rules as a DELETE. Namely, we
7281ea331999debdc337b02ce37a3169e0e033a2gstein ** will return a 424 error if any of the validations fail.
7281ea331999debdc337b02ce37a3169e0e033a2gstein ** (see dav_method_delete() for more information)
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = dav_validate_request(lookup.rnew, binding, DAV_INFINITY, NULL,
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Could not BIND %s due to a "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "failed precondition on the "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "destination (e.g. locks).",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* guard against creating circular bindings */
7281ea331999debdc337b02ce37a3169e0e033a2gstein && (*resource->hooks->is_parent_resource)(resource, binding)) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Source collection contains the Destination.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein && (*resource->hooks->is_parent_resource)(binding, resource)) {
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* The destination must exist (since it contains the source), and
7281ea331999debdc337b02ce37a3169e0e033a2gstein * a condition above implies Overwrite==T. Obviously, we cannot
7281ea331999debdc337b02ce37a3169e0e033a2gstein * delete the Destination before the BIND, as that would
7281ea331999debdc337b02ce37a3169e0e033a2gstein * delete the Source.
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Destination collection contains the Source and "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Overwrite has been specified.");
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* prepare the destination collection for modification */
7281ea331999debdc337b02ce37a3169e0e033a2gstein if ((err = dav_ensure_resource_writable(r, binding, 1 /* parent_only */,
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* could not make destination writable */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* If target exists, remove it first (we know Ovewrite must be TRUE).
7281ea331999debdc337b02ce37a3169e0e033a2gstein * Then try to bind to the resource.
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = (*resource->hooks->remove_resource)(binding, &multi_response);
7281ea331999debdc337b02ce37a3169e0e033a2gstein err = (*binding_hooks->bind_resource)(resource, binding);
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* restore parent collection states */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* check for error from remove/bind operations */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "Could not BIND %s.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* check for errors from reverting writability */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* just log a warning */
7281ea331999debdc337b02ce37a3169e0e033a2gstein "The BIND was successful, but there was a "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "problem reverting the writability of the "
7281ea331999debdc337b02ce37a3169e0e033a2gstein "source parent collection.",
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* return an appropriate response (HTTP_CREATED) */
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* ### spec doesn't say what happens when destination was replaced */
7281ea331999debdc337b02ce37a3169e0e033a2gstein return dav_created(r, lookup.rnew->uri, "Binding", 0);
7281ea331999debdc337b02ce37a3169e0e033a2gstein * Response handler for DAV resources
7281ea331999debdc337b02ce37a3169e0e033a2gstein /* quickly ignore any HTTP/0.9 requests */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### do we need to do anything with r->proxyreq ?? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Set up the methods mask, since that's one of the reasons this handler
f4c310fd2555c6faca1f980f00b161eadb089023gstein * gets called, and lower-level things may need the info.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * First, set the mask to the methods we handle directly. Since by
f4c310fd2555c6faca1f980f00b161eadb089023gstein * definition we own our managed space, we unconditionally set
f4c310fd2555c6faca1f980f00b161eadb089023gstein * the r->allowed field rather than ORing our values with anything
f4c310fd2555c6faca1f980f00b161eadb089023gstein * any other module may have put in there.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * These are the HTTP-defined methods that we handle directly.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * These are the DAV methods we handle.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * These are methods that we don't handle directly, but let the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * server's default handler do for us as our agent.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### hrm. if we return HTTP_METHOD_NOT_ALLOWED, then an Allow header
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### is sent; it will need the other allowed states; since the default
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### handler is not called on error, then it doesn't add the other
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### allowed states, so we must */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### we might need to refine this for just where we return the error.
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### also, there is the issue with other methods (see ISSUES) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### more work necessary, now that we have M_foo for DAV methods */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* dispatch the appropriate method handler */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * NOTE: When Apache moves creates defines for the add'l DAV methods,
f4c310fd2555c6faca1f980f00b161eadb089023gstein * then it will no longer use M_INVALID. This code must be
f4c310fd2555c6faca1f980f00b161eadb089023gstein * updated each time Apache adds method defines.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### add'l methods for Advanced Collections, ACLs, DASL */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* if DAV is not enabled, then we've got nothing to do */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### need some work to pull Content-Type and Content-Language
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### from the property database.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** If the repository hasn't indicated that it will handle the
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** GET method, then just punt.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### this isn't quite right... taking over the response can break
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### things like mod_negotiation. need to look into this some more.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### we should (instead) trap the ones that we DO understand */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### the handler DOES handle POST, so we need to fix one of these */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### anything else to do here? could another module and/or
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### config option "take over" the handler here? i.e. how do
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### we lock down this hierarchy so that we are the ultimate
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### arbiter? (or do we simply depend on the administrator
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### to avoid conflicting configurations?)
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** ### I think the OK stops running type-checkers. need to look.
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe ap_hook_handler(dav_handler, NULL, NULL, APR_HOOK_MIDDLE);
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe ap_hook_post_config(dav_init_handler, NULL, NULL, APR_HOOK_MIDDLE);
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe ap_hook_type_checker(dav_type_checker, NULL, NULL, APR_HOOK_FIRST);
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe dav_hook_find_liveprop(dav_core_find_liveprop, NULL, NULL, APR_HOOK_LAST);
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe dav_hook_insert_all_liveprops(dav_core_insert_all_liveprops,
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*---------------------------------------------------------------------------
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Configuration info for the module
000397350b42c6266351bd618fa07df929fa7c79gstein "specify the DAV provider for a directory or location"),
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein /* per directory/location, or per server */
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein AP_INIT_TAKE1("DAVMinTimeout", dav_cmd_davmintimeout, NULL,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein "specify minimum allowed timeout"),
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein /* per directory/location, or per server */
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein AP_INIT_FLAG("DAVDepthInfinity", dav_cmd_davdepthinfinity, NULL,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein "allow Depth infinity PROPFIND requests"),
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein /* per directory/location, or per server */
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein "DAVParam <parameter name> <parameter value>"),
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_merge_dir_config, /* dir merger --- default is to override */
b980ad7fdc218b4855cde9f75a747527f50c554dwroweAPR_IMPLEMENT_EXTERNAL_HOOK_VOID(dav, DAV, gather_propsets,
b980ad7fdc218b4855cde9f75a747527f50c554dwroweAPR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(dav, DAV, int, find_liveprop,