mod_dav.c revision fe4d394397840dd4823e3d6fc5affc1ab395e161
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.
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* per-dir configuration */
f4c310fd2555c6faca1f980f00b161eadb089023gsteintypedef struct {
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *dir;
f4c310fd2555c6faca1f980f00b161eadb089023gstein int handle_get; /* cached from repository hook structure */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_table_t *d_params; /* per-directory DAV config parameters */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* per-server configuration */
f4c310fd2555c6faca1f980f00b161eadb089023gsteintypedef struct {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* LimitXMLRequestBody handling */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* forward-declare for use in configuration lookup */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* copy a module's providers into our per-directory configuration state */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void dav_copy_providers(ap_pool_t *p, const char *name, dav_dir_conf *conf)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### if NULL? need to error out somehow... */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Set hooks for any providers in the module */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### how to signal an error? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein while (!dav_scan_providers(ctx, &provider, &hooks)) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### not yet defined */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### not yet defined */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf->handle_get = DAV_AS_HOOKS_REPOSITORY(&hooks)->handle_get;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### need to error out somehow... */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void dav_init_handler(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* DBG0("dav_init_handler"); */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void *dav_create_server_config(ap_pool_t *p, server_rec *s)
f4c310fd2555c6faca1f980f00b161eadb089023gstein newconf = (dav_server_conf *) ap_pcalloc(p, sizeof(*newconf));
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void *dav_merge_server_config(ap_pool_t *p, void *base, void *overrides)
f4c310fd2555c6faca1f980f00b161eadb089023gstein newconf = (dav_server_conf *) ap_pcalloc(p, sizeof(*newconf));
fe4d394397840dd4823e3d6fc5affc1ab395e161gstein /* ### hmm. we should share the uuid state rather than copy it. if we
fe4d394397840dd4823e3d6fc5affc1ab395e161gstein ### do another merge, then we'll just get the old one, rather than
fe4d394397840dd4823e3d6fc5affc1ab395e161gstein ### an updated state.
fe4d394397840dd4823e3d6fc5affc1ab395e161gstein ### of course... the UUID generation should move into APR
f4c310fd2555c6faca1f980f00b161eadb089023gstein memcpy(&newconf->st, &child->st, sizeof(newconf->st));
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void *dav_create_dir_config(ap_pool_t *p, char *dir)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* NOTE: dir==NULL creates the default per-dir config */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_pcalloc(p, sizeof(*conf));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* DBG1("dav_create_dir_config: %08lx", (long)conf); */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Locate the appropriate module (NULL == default) and copy the module's
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** providers' hooks into our configuration state.
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void *dav_merge_dir_config(ap_pool_t *p, void *base, void *overrides)
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_dir_conf *newconf = (dav_dir_conf *) ap_pcalloc(p, sizeof(*newconf));
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* DBG3("dav_merge_dir_config: new=%08lx base=%08lx overrides=%08lx",
f4c310fd2555c6faca1f980f00b161eadb089023gstein (long)newconf, (long)base, (long)overrides); */
f4c310fd2555c6faca1f980f00b161eadb089023gstein newconf->enabled = DAV_INHERIT_VALUE(parent, child, enabled);
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,
f4c310fd2555c6faca1f980f00b161eadb089023gstein newconf->d_params = ap_copy_table(p, parent->d_params);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_overlap_tables(newconf->d_params, child->d_params,
f4c310fd2555c6faca1f980f00b161eadb089023gstein && DAV_AS_HOOKS_REPOSITORY(&newconf->repository)->handle_get;
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = ap_get_module_config(r->server->module_config, &dav_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = ap_get_module_config(r->per_dir_config, &dav_module);
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = ap_get_module_config(r->per_dir_config, &dav_module);
f4c310fd2555c6faca1f980f00b161eadb089023gsteinconst dav_dyn_hooks *dav_get_provider_hooks(request_rec *r, int provider_type)
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### not yet defined */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### not yet defined */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* unknown provider type */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Command handler for the DAV directive, which is FLAG.
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *dav_cmd_dav(cmd_parms *cmd, void *config, int arg)
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 * Command handler for LimitXMLRequestBody directive, which is TAKE1
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic const char *dav_cmd_limitxmlrequestbody(cmd_parms *cmd, void *config,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein const char *arg1)
f4c310fd2555c6faca1f980f00b161eadb089023gstein return "LimitXMLRequestBody requires a non-negative integer.";
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.
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic const char *dav_xml_escape_uri(ap_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 */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int dav_created(request_rec *r, request_rec *rnew,
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. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### rnew->uri does not contain an absoluteURI. S14.30 states that
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### the Location header requires an absoluteURI. where to get it? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### disable until we get the right value */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_table_setn(r->headers_out, "Location", rnew->uri);
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. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein body = ap_psprintf(r->pool, "%s %s has been created.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ### move to dav_util? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *depth = ap_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.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *overwrite = ap_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.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* resolve a request URI to a resource descriptor */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic int dav_get_resource(request_rec *r, dav_resource **res_p)
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Call repository hook to resolve resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein repos_hooks = DAV_AS_HOOKS_REPOSITORY(&conf->repository);
f4c310fd2555c6faca1f980f00b161eadb089023gstein if (repos_hooks == NULL || repos_hooks->get_resource == NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### this should happen at startup rather than per-request */
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
f4c310fd2555c6faca1f980f00b161eadb089023gstein "No %s has been configured.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein ? "repository module"
f4c310fd2555c6faca1f980f00b161eadb089023gstein : "GET handler");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
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;
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein range_c = ap_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.
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 */
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 */
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);
f4c310fd2555c6faca1f980f00b161eadb089023gstein char *buffer = ap_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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err2 = dav_revert_resource_writability(r, resource, resource_parent,
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) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return dav_created(r, NULL, resource, "Resource", resource_existed);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* ### move this to dav_util? */
f4c310fd2555c6faca1f980f00b161eadb089023gsteinvoid dav_add_response(dav_walker_ctx *ctx, const char *href, int status,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* just drop some data into an dav_response */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the DELETE method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *body;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* We don't use the request body right now, so torch it. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the 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 /* Check for valid resource type */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### allow DAV_RESOURCE_TYPE_REVISION with All-Bindings header */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Cannot delete resource %s.",
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err2 = dav_revert_resource_writability(r, NULL, resource_parent,
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. */
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);
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *options;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *dav_level;
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *vsn_level;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* per HTTP/1.1 S9.2, we can discard this body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resolve the resource */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* determine which providers are available */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Iterate through the live property providers; add their URIs to
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** the dav_level string.
f4c310fd2555c6faca1f980f00b161eadb089023gstein conf = (dav_dir_conf *) ap_get_module_config(r->per_dir_config,
f4c310fd2555c6faca1f980f00b161eadb089023gstein for (lp = conf->liveprop; lp != NULL; lp = lp->next) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *uri = DAV_AS_HOOKS_LIVEPROP(lp)->propset_uri;
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_level = ap_pstrcat(r->pool, dav_level, ",<", uri, ">", NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* this tells MSFT products to skip looking for FrontPage extensions */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_table_setn(r->headers_out, "MS-Author-Via", "DAV");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Three cases: resource is null (3), is lock-null (7.4), or exists.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** All cases support OPTIONS and LOCK.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** (Lock-) null resources also support MKCOL and PUT.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Lock-null support PROPFIND and UNLOCK.
f4c310fd2555c6faca1f980f00b161eadb089023gstein ** Existing resources support lots of stuff.
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### take into account resource type */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resource exists */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "OPTIONS, "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "GET, HEAD, POST, DELETE, TRACE, "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "PROPFIND, PROPPATCH, COPY, MOVE",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* files also support PUT */
f4c310fd2555c6faca1f980f00b161eadb089023gstein "OPTIONS, "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "GET, HEAD, POST, DELETE, TRACE, "
f4c310fd2555c6faca1f980f00b161eadb089023gstein "PROPFIND, PROPPATCH, COPY, MOVE, PUT",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resource is lock-null. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein options = ap_pstrcat(r->pool, "OPTIONS, MKCOL, PUT, PROPFIND",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* resource is null. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### internal error! */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* If there is a versioning provider, add versioning options */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### take into account resource type */
f4c310fd2555c6faca1f980f00b161eadb089023gstein options = ap_pstrcat(r->pool, options, vsn_options, NULL);
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_table_setn(r->headers_out, "Versioning", vsn_level);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### this will send a Content-Type. the default OPTIONS does not. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### the default (ap_send_http_options) returns OK, but I believe
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### that is because it is the default handler and nothing else
f4c310fd2555c6faca1f980f00b161eadb089023gstein * ### will run after the thing. */
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 ap_text_append(ctx->pool, &hdr, ap_xml_empty_elem(ctx->pool, elem));
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gstein "<D:status>HTTP/1.1 404 Not Found</D:status>" DEBUG_CR
f4c310fd2555c6faca1f980f00b161eadb089023gsteinstatic dav_error * dav_propfind_walker(dav_walker_ctx *ctx, 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? */
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the PROPFIND method */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the 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).");
f4c310fd2555c6faca1f980f00b161eadb089023gstein ctx.walk_type = DAV_WALKTYPE_ALL | DAV_WALKTYPE_AUTH;
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### should open read-only */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = dav_open_lockdb(r, 0, &ctx.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 */
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_send_multistatus(r, HTTP_MULTI_STATUS, ctx.response,
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_send_multistatus(r, HTTP_MULTI_STATUS, ctx.response, 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);
252e2478cb56afb5ca8585b50bc2ffb780d2efb6gsteinstatic ap_text * dav_success_proppatch(ap_pool_t *p, ap_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 */
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein ctx_list = ap_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). */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *tenc = ap_table_get(r->headers_in, "Transfer-Encoding");
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *lenp = ap_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 */
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err = (*resource->hooks->create_collection)(r->pool, resource);
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* restore modifiability of parent back to what it was */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err2 = dav_revert_resource_writability(r, NULL, resource_parent,
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 return dav_created(r, NULL, resource, "Collection", 0);
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 */
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *nscp_host = ap_table_get(r->headers_in, "Host");
f4c310fd2555c6faca1f980f00b161eadb089023gstein const char *nscp_path = ap_table_get(r->headers_in, "New-uri");
f4c310fd2555c6faca1f980f00b161eadb089023gstein dest = ap_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 */
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 */
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
f4c310fd2555c6faca1f980f00b161eadb089023gstein (void) dav_revert_resource_writability(r, NULL, resource_parent,
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
f4c310fd2555c6faca1f980f00b161eadb089023gstein * in the other.
f4c310fd2555c6faca1f980f00b161eadb089023gstein && (*resource_parent->hooks->is_same_resource)(resource_parent,
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* New resource will be same kind as source */
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein err2 = dav_revert_resource_writability(r, NULL, resnew_parent,
f4c310fd2555c6faca1f980f00b161eadb089023gstein err3 = dav_revert_resource_writability(r, NULL, resource_parent,
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 int resource_state = dav_get_resource_state(lookup.rnew, resnew);
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) */
f4c310fd2555c6faca1f980f00b161eadb089023gstein return dav_created(r, lookup.rnew, resnew, "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.");
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the 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),
f4c310fd2555c6faca1f980f00b161eadb089023gstein ap_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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((const_locktoken_txt = ap_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);
f4c310fd2555c6faca1f980f00b161eadb089023gstein locktoken_txt = ap_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.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the 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) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein/* handle the SEARCH method from DASL */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### we know this method, but we won't allow it yet */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Apache will supply a default error for this. */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Do some error checking, like if the querygrammar is
f4c310fd2555c6faca1f980f00b161eadb089023gstein * supported by the content type, and then pass the
f4c310fd2555c6faca1f980f00b161eadb089023gstein * request on to the appropriate query module.
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* ### eventually check body for DAV:checkin-policy */
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* Ask repository module to resolve the 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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*vsn_hooks->checkout)(resource)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not CHECKOUT resource %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no body */
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 */
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 */
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 */
f4c310fd2555c6faca1f980f00b161eadb089023gstein if ((err = (*vsn_hooks->checkin)(resource)) != NULL) {
f4c310fd2555c6faca1f980f00b161eadb089023gstein "Could not CHECKIN resource %s.",
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* no body */
f4c310fd2555c6faca1f980f00b161eadb089023gstein * Response handler for DAV resources
f4c310fd2555c6faca1f980f00b161eadb089023gstein /* 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.
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagsteinstatic void register_hooks(void)
f5ec9b038bb9db933072ba2c0a8e7bb2a3cedbdagstein ap_hook_post_config(dav_init_handler, NULL, NULL, AP_HOOK_MIDDLE);
06cb1a83b6a1cfbe9c7815569e6c1d1408966ff7gstein ap_hook_type_checker(dav_type_checker, NULL, NULL, AP_HOOK_FIRST);
f4c310fd2555c6faca1f980f00b161eadb089023gstein/*---------------------------------------------------------------------------
f4c310fd2555c6faca1f980f00b161eadb089023gstein** Configuration info for the module
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein "turn DAV on/off 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>"),
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein /* per directory/location, or per server */
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein AP_INIT_TAKE1("LimitXMLRequestBody", dav_cmd_limitxmlrequestbody, NULL,
26250b0077972bf21b6d8a8d23772a4cf53f9477gstein "Limit (in bytes) on maximum size of an XML-based request "
f4c310fd2555c6faca1f980f00b161eadb089023gstein dav_merge_dir_config, /* dir merger --- default is to override */