modules/dav/main/mod_dav.c:2776: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `dav_validate_request`.

modules/dav/main/mod_dav.c:2735:9: Unknown value from: non-const function
2733. 
2734.     /* are the source and destination the same? */
2735.     if ((*resource->hooks->is_same_resource)(resource, resnew)) {
              ^
2736.         /* Supply some text for the error response body. */
2737.         return dav_error_response(r, HTTP_FORBIDDEN,

modules/dav/main/mod_dav.c:2776:16: Call
2774.      * (rather than a multistatus) will be returned.
2775.      */
2776.     if ((err = dav_validate_request(r, resource, depth, NULL,
                     ^
2777.                                     &multi_response,
2778.                                     (is_move ? DAV_VALIDATE_PARENT

modules/dav/main/util.c:1494:1: Parameter `resource->uri->strlen`
  1492. ** error is necessary, response will point to it, else NULL.
  1493. */
  1494. DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r,
        ^
  1495.                                               dav_resource *resource,
  1496.                                               int depth,

modules/dav/main/util.c:1627:15: Call
  1625.     }
  1626.     else {
  1627.         err = dav_validate_resource_state(r->pool, resource, lockdb,
                      ^
  1628.                                           if_header, flags, &work_buf, r);
  1629.     }

modules/dav/main/util.c:838:1: <LHS trace>
836.  *    Returns NULL if path/uri meets if-header and lock requirements
837.  */
838. static dav_error * dav_validate_resource_state(apr_pool_t *p,
     ^
839.                                                const dav_resource *resource,
840.                                                dav_lockdb *lockdb,

modules/dav/main/util.c:838:1: Parameter `resource->uri->strlen`
    836.  *    Returns NULL if path/uri meets if-header and lock requirements
    837.  */
    838. static dav_error * dav_validate_resource_state(apr_pool_t *p,
         ^
    839.                                                const dav_resource *resource,
    840.                                                dav_lockdb *lockdb,

modules/dav/main/util.c:1027:5: Assignment
    1025.     */
    1026.     uri = resource->uri;
    1027.     uri_len = strlen(uri);
              ^
    1028.     if (uri[uri_len - 1] == '/') {
    1029.         dav_set_bufsize(p, pbuf, uri_len);

modules/dav/main/util.c:1028:9: Binary operation: ([0, +oo] - 1):unsigned64 by call to `dav_validate_request` 
    1026.     uri = resource->uri;
    1027.     uri_len = strlen(uri);
    1028.     if (uri[uri_len - 1] == '/') {
                  ^
    1029.         dav_set_bufsize(p, pbuf, uri_len);
    1030.         memcpy(pbuf->buf, uri, uri_len);

static dav_error * dav_validate_resource_state(apr_pool_t *p,
                                               const dav_resource *resource,
                                               dav_lockdb *lockdb,
                                               const dav_if_header *if_header,
                                               int flags,
                                               dav_buffer *pbuf,
                                               request_rec *r)
{
    dav_error *err;
    const char *uri;
    const char *etag;
    const dav_hooks_locks *locks_hooks = (lockdb ? lockdb->hooks : NULL);
    const dav_if_header *ifhdr_scan;
    dav_if_state_list *state_list;
    dav_lock *lock_list;
    dav_lock *lock;
    int num_matched;
    int num_that_apply;
    int seen_locktoken;
    apr_size_t uri_len;
    const char *reason = NULL;
    if (lockdb == NULL) {
        lock_list = NULL;
    }
    else {
        if ((err = dav_lock_query(lockdb, resource, &lock_list)) != NULL) {
            return dav_push_error(p,
                                  HTTP_INTERNAL_SERVER_ERROR, 0,
                                  "The locks could not be queried for "
                                  "verification against a possible \"If:\" "
                                  "header.",
                                  err);
        }
    }
    if (flags & DAV_LOCKSCOPE_EXCLUSIVE) {
        if (lock_list != NULL) {
            return dav_new_error(p, HTTP_LOCKED, 0, 0,
                                 "Existing lock(s) on the requested resource "
                                 "prevent an exclusive lock.");
        }
        seen_locktoken = 1;
    }
    else if (flags & DAV_LOCKSCOPE_SHARED) {
        for (lock = lock_list; lock != NULL; lock = lock->next) {
            if (lock->scope == DAV_LOCKSCOPE_EXCLUSIVE) {
                return dav_new_error(p, HTTP_LOCKED, 0, 0,
                                     "The requested resource is already "
                                     "locked exclusively.");
            }
        }
        seen_locktoken = 1;
    }
    else {
        seen_locktoken = (lock_list == NULL
                          || flags & DAV_VALIDATE_NO_MODIFY);
    }
    if (if_header == NULL) {
        if (seen_locktoken)
            return NULL;
        return dav_new_error(p, HTTP_LOCKED, 0, 0,
                             "This resource is locked and an \"If:\" header "
                             "was not supplied to allow access to the "
                             "resource.");
    }
    if (lock_list == NULL && if_header->dummy_header) {
        if (flags & DAV_VALIDATE_IS_PARENT)
            return NULL;
        return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,
                             "The locktoken specified in the \"Lock-Token:\" "
                             "header is invalid because this resource has no "
                             "outstanding locks.");
    }
    uri = resource->uri;
    uri_len = strlen(uri);
    if (uri[uri_len - 1] == '/') {
        dav_set_bufsize(p, pbuf, uri_len);
        memcpy(pbuf->buf, uri, uri_len);
        pbuf->buf[--uri_len] = '\0';
        uri = pbuf->buf;
    }
    etag = (*resource->hooks->getetag)(resource);
    num_that_apply = 0;
    for (ifhdr_scan = if_header;
         ifhdr_scan != NULL;
         ifhdr_scan = ifhdr_scan->next) {
        if (ifhdr_scan->uri != NULL
            && (uri_len != ifhdr_scan->uri_len
                || memcmp(uri, ifhdr_scan->uri, uri_len) != 0)) {
            continue;
        }
        ++num_that_apply;
        for (state_list = ifhdr_scan->state;
             state_list != NULL;
             state_list = state_list->next) {
            switch(state_list->type) {
            case dav_if_etag:
            {
                const char *given_etag, *current_etag;
                int mismatch;
                if (state_list->etag[0] == 'W' &&
                    state_list->etag[1] == '/') {
                    given_etag = state_list->etag + 2;
                }
                else {
                    given_etag = state_list->etag;
                }
                if (etag[0] == 'W' &&
                    etag[1] == '/') {
                    current_etag = etag + 2;
                }
                else {
                    current_etag = etag;
                }
                mismatch = strcmp(given_etag, current_etag);
                if (state_list->condition == DAV_IF_COND_NORMAL && mismatch) {
                    reason =
                        "an entity-tag was specified, but the resource's "
                        "actual ETag does not match.";
                    goto state_list_failed;
                }
                else if (state_list->condition == DAV_IF_COND_NOT
                         && !mismatch) {
                    reason =
                        "an entity-tag was specified using the \"Not\" form, "
                        "but the resource's actual ETag matches the provided "
                        "entity-tag.";
                    goto state_list_failed;
                }
                break;
            }
            case dav_if_opaquelock:
                if (lockdb == NULL) {
                    if (state_list->condition == DAV_IF_COND_NOT) {
                        continue;
                    }
                    reason =
                        "a State-token was supplied, but a lock database "
                        "is not available for to provide the required lock.";
                    goto state_list_failed;
                }
                num_matched = 0;
                for (lock = lock_list; lock != NULL; lock = lock->next) {
                    if ((*locks_hooks->compare_locktoken)(state_list->locktoken, lock->locktoken)) {
                        continue;
                    }
                    seen_locktoken = 1;
                    if (state_list->condition == DAV_IF_COND_NOT) {
                        reason =
                            "a State-token was supplied, which used a "
                            "\"Not\" condition. The State-token was found "
                            "in the locks on this resource";
                        goto state_list_failed;
                    }
                    if (lock->auth_user &&
                        (!r->user ||
                         strcmp(lock->auth_user, r->user))) {
                        const char *errmsg;
                        errmsg = apr_pstrcat(p, "User \"",
                                            r->user,
                                            "\" submitted a locktoken created "
                                            "by user \"",
                                            lock->auth_user, "\".", NULL);
                        return dav_new_error(p, HTTP_FORBIDDEN, 0, 0, errmsg);
                    }
                    num_matched = 1;
                    break;
                }
                if (num_matched == 0
                    && state_list->condition == DAV_IF_COND_NORMAL) {
                    reason =
                        "a State-token was supplied, but it was not found "
                        "in the locks on this resource.";
                    goto state_list_failed;
                }
                break;
            case dav_if_unknown:
                if (state_list->condition == DAV_IF_COND_NORMAL) {
                    reason =
                        "an unknown state token was supplied";
                    goto state_list_failed;
                }
                break;
            }
        }
        if (seen_locktoken) {
            return NULL;
        }
        break;
      state_list_failed:
        ;
    }
    if (ifhdr_scan == NULL) {
        if (num_that_apply == 0) {
            if (seen_locktoken)
                return NULL;
            if (dav_find_submitted_locktoken(if_header, lock_list,
                                             locks_hooks)) {
                return NULL;
            }
            return dav_new_error(p, HTTP_LOCKED, 0  , 0,
                                 "This resource is locked and the \"If:\" "
                                 "header did not specify one of the "
                                 "locktokens for this resource's lock(s).");
        }
        if (if_header->dummy_header) {
            return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,
                                 "The locktoken specified in the "
                                 "\"Lock-Token:\" header did not specify one "
                                 "of this resource's locktoken(s).");
        }
        if (reason == NULL) {
            return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0,
                                 "The preconditions specified by the \"If:\" "
                                 "header did not match this resource.");
        }
        return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0,
                             apr_psprintf(p,
                                         "The precondition(s) specified by "
                                         "the \"If:\" header did not match "
                                         "this resource. At least one "
                                         "failure is because: %s", reason));
    }
    if (dav_find_submitted_locktoken(if_header, lock_list, locks_hooks)) {
        return NULL;
    }
    if (if_header->dummy_header) {
        return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,
                             "The locktoken specified in the "
                             "\"Lock-Token:\" header did not specify one "
                             "of this resource's locktoken(s).");
    }
    return dav_new_error(p, HTTP_LOCKED, 1  , 0,
                         "This resource is locked and the \"If:\" header "
                         "did not specify one of the "
                         "locktokens for this resource's lock(s).");
}
['static int dav_method_copymove(request_rec *r, int is_move)\n{\n    dav_resource *resource;\n    dav_resource *resnew;\n    dav_auto_version_info src_av_info = { 0 };\n    dav_auto_version_info dst_av_info = { 0 };\n    const char *body;\n    const char *dest;\n    dav_error *err;\n    dav_error *err2;\n    dav_error *err3;\n    dav_response *multi_response;\n    dav_lookup_result lookup;\n    int is_dir;\n    int overwrite;\n    int depth;\n    int result;\n    dav_lockdb *lockdb;\n    int replace_dest;\n    int resnew_state;\n    err = dav_get_resource(r, !is_move  ,\n                           0  , &resource);\n    if (err != NULL)\n        return dav_handle_err(r, err, NULL);\n    if (!resource->exists) {\n        return HTTP_NOT_FOUND;\n    }\n    if (resource->type != DAV_RESOURCE_TYPE_REGULAR) {\n        body = apr_psprintf(r->pool,\n                            "Cannot COPY/MOVE resource %s.",\n                            ap_escape_html(r->pool, r->uri));\n        return dav_error_response(r, HTTP_METHOD_NOT_ALLOWED, body);\n    }\n    dest = apr_table_get(r->headers_in, "Destination");\n    if (dest == NULL) {\n        const char *nscp_host = apr_table_get(r->headers_in, "Host");\n        const char *nscp_path = apr_table_get(r->headers_in, "New-uri");\n        if (nscp_host != NULL && nscp_path != NULL)\n            dest = apr_psprintf(r->pool, "http://%s%s", nscp_host, nscp_path);\n    }\n    if (dest == NULL) {\n        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00591)\n                      "The request is missing a Destination header.");\n        return HTTP_BAD_REQUEST;\n    }\n    lookup = dav_lookup_uri(dest, r, 1  );\n    if (lookup.rnew == NULL) {\n        if (lookup.err.status == HTTP_BAD_REQUEST) {\n            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00592)\n                          "%s", lookup.err.desc);\n            return HTTP_BAD_REQUEST;\n        }\n        return dav_error_response(r, lookup.err.status, lookup.err.desc);\n    }\n    if (lookup.rnew->status != HTTP_OK) {\n        const char *auth = apr_table_get(lookup.rnew->err_headers_out,\n                                        "WWW-Authenticate");\n        if (lookup.rnew->status == HTTP_UNAUTHORIZED && auth != NULL) {\n            apr_table_setn(r->err_headers_out, "WWW-Authenticate",\n                           apr_pstrdup(r->pool, auth));\n        }\n        return dav_error_response(r, lookup.rnew->status,\n                                  "Destination URI had an error.");\n    }\n    err = dav_get_resource(lookup.rnew, 0  ,\n                           0  , &resnew);\n    if (err != NULL)\n        return dav_handle_err(r, err, NULL);\n    if (resource->hooks != resnew->hooks) {\n        return dav_error_response(r, HTTP_BAD_GATEWAY,\n                                  "Destination URI is handled by a "\n                                  "different repository than the source URI. "\n                                  "MOVE or COPY between repositories is "\n                                  "not possible.");\n    }\n    if ((overwrite = dav_get_overwrite(r)) < 0) {\n        return HTTP_BAD_REQUEST;\n    }\n    if (resnew->exists && !overwrite) {\n        return dav_error_response(r, HTTP_PRECONDITION_FAILED,\n                                  "Destination is not empty and "\n                                  "Overwrite is not \\"T\\"");\n    }\n    if ((*resource->hooks->is_same_resource)(resource, resnew)) {\n        return dav_error_response(r, HTTP_FORBIDDEN,\n                                  "Source and Destination URIs are the same.");\n    }\n    is_dir = resource->collection;\n    if ((depth = dav_get_depth(r, DAV_INFINITY)) < 0) {\n        return HTTP_BAD_REQUEST;\n    }\n    if (depth == 1) {\n        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00593)\n                      "Depth must be \\"0\\" or \\"infinity\\" for COPY or MOVE.");\n        return HTTP_BAD_REQUEST;\n    }\n    if (is_move && is_dir && depth != DAV_INFINITY) {\n        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00594)\n                      "Depth must be \\"infinity\\" when moving a collection.");\n        return HTTP_BAD_REQUEST;\n    }\n    if ((err = dav_validate_request(r, resource, depth, NULL,\n                                    &multi_response,\n                                    (is_move ? DAV_VALIDATE_PARENT\n                                             : DAV_VALIDATE_RESOURCE\n                                               | DAV_VALIDATE_NO_MODIFY)\n                                    | DAV_VALIDATE_USE_424,\n                                    NULL)) != NULL) {\n        err = dav_push_error(r->pool, err->status, 0,\n                             apr_psprintf(r->pool,\n                                          "Could not %s %s due to a failed "\n                                          "precondition on the source "\n                                          "(e.g. locks).",\n                                          is_move ? "MOVE" : "COPY",\n                                          ap_escape_html(r->pool, r->uri)),\n                             err);\n        return dav_handle_err(r, err, multi_response);\n    }\n    if ((err = dav_validate_request(lookup.rnew, resnew, DAV_INFINITY, NULL,\n                                    &multi_response,\n                                    DAV_VALIDATE_PARENT\n                                    | DAV_VALIDATE_USE_424, NULL)) != NULL) {\n        err = dav_push_error(r->pool, err->status, 0,\n                             apr_psprintf(r->pool,\n                                          "Could not MOVE/COPY %s due to a "\n                                          "failed precondition on the "\n                                          "destination (e.g. locks).",\n                                          ap_escape_html(r->pool, r->uri)),\n                             err);\n        return dav_handle_err(r, err, multi_response);\n    }\n    if (is_dir\n        && depth == DAV_INFINITY\n        && (*resource->hooks->is_parent_resource)(resource, resnew)) {\n        return dav_error_response(r, HTTP_FORBIDDEN,\n                                  "Source collection contains the "\n                                  "Destination.");\n    }\n    if (is_dir\n        && (*resnew->hooks->is_parent_resource)(resnew, resource)) {\n        return dav_error_response(r, HTTP_FORBIDDEN,\n                                  "Destination collection contains the Source "\n                                  "and Overwrite has been specified.");\n    }\n    if ((result = ap_discard_request_body(r)) != OK) {\n        return result;\n    }\n    if ((err = dav_open_lockdb(r, 0, &lockdb)) != NULL) {\n        return dav_handle_err(r, err, NULL);\n    }\n    if (is_move && lockdb != NULL) {\n        (void)dav_unlock(r, resource, NULL);\n    }\n    if (is_move) {\n        if ((err = dav_auto_checkout(r, resource, 1  ,\n                                     &src_av_info)) != NULL) {\n            if (lockdb != NULL)\n                (*lockdb->hooks->close_lockdb)(lockdb);\n            return dav_handle_err(r, err, NULL);\n        }\n    }\n    resnew_state = dav_get_resource_state(lookup.rnew, resnew);\n    if (!resnew->exists)\n        replace_dest = 0;\n    else if (is_move || !resource->versioned)\n        replace_dest = 1;\n    else if (resource->type != resnew->type)\n        replace_dest = 1;\n    else if ((resource->collection == 0) != (resnew->collection == 0))\n        replace_dest = 1;\n    else\n        replace_dest = 0;\n    if (!resnew->exists || replace_dest) {\n        if ((err = dav_auto_checkout(r, resnew, 1  ,\n                                     &dst_av_info)) != NULL) {\n            if (is_move) {\n                (void)dav_auto_checkin(r, NULL, 1  ,\n                                       0  , &src_av_info);\n            }\n            if (lockdb != NULL)\n                (*lockdb->hooks->close_lockdb)(lockdb);\n            return dav_handle_err(r, err, NULL);\n        }\n    }\n    if (src_av_info.parent_resource != NULL\n        && dst_av_info.parent_resource != NULL\n        && (*src_av_info.parent_resource->hooks->is_same_resource)\n            (src_av_info.parent_resource, dst_av_info.parent_resource)) {\n        dst_av_info.parent_resource = src_av_info.parent_resource;\n    }\n    if (replace_dest)\n        err = (*resnew->hooks->remove_resource)(resnew, &multi_response);\n    if (err == NULL) {\n        if (is_move)\n            err = (*resource->hooks->move_resource)(resource, resnew,\n                                                    &multi_response);\n        else\n            err = (*resource->hooks->copy_resource)(resource, resnew, depth,\n                                                    &multi_response);\n    }\n    err2 = dav_auto_checkin(r, NULL, err != NULL  ,\n                            0  , &dst_av_info);\n    if (is_move) {\n        err3 = dav_auto_checkin(r, NULL, err != NULL  ,\n                                0  , &src_av_info);\n    }\n    else\n        err3 = NULL;\n    if (err != NULL) {\n        if (lockdb != NULL)\n            (*lockdb->hooks->close_lockdb)(lockdb);\n        err = dav_push_error(r->pool, err->status, 0,\n                             apr_psprintf(r->pool,\n                                          "Could not MOVE/COPY %s.",\n                                          ap_escape_html(r->pool, r->uri)),\n                             err);\n        return dav_handle_err(r, err, multi_response);\n    }\n    if (err2 != NULL) {\n        err = dav_push_error(r->pool, err2->status, 0,\n                             "The MOVE/COPY was successful, but there was a "\n                             "problem automatically checking in the "\n                             "source parent collection.",\n                             err2);\n        dav_log_err(r, err, APLOG_WARNING);\n    }\n    if (err3 != NULL) {\n        err = dav_push_error(r->pool, err3->status, 0,\n                             "The MOVE/COPY was successful, but there was a "\n                             "problem automatically checking in the "\n                             "destination or its parent collection.",\n                             err3);\n        dav_log_err(r, err, APLOG_WARNING);\n    }\n    if (lockdb != NULL) {\n        err = dav_notify_created(r, lockdb, resnew, resnew_state, depth);\n        (*lockdb->hooks->close_lockdb)(lockdb);\n        if (err != NULL) {\n            err = dav_push_error(r->pool, err->status, 0,\n                                 "The MOVE/COPY was successful, but there "\n                                 "was a problem updating the lock "\n                                 "information.",\n                                 err);\n            return dav_handle_err(r, err, NULL);\n        }\n    }\n    return dav_created(r, lookup.rnew->unparsed_uri, "Destination",\n                       resnew_state == DAV_RESOURCE_EXISTS);\n}', 'DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r,\n                                              dav_resource *resource,\n                                              int depth,\n                                              dav_locktoken *locktoken,\n                                              dav_response **response,\n                                              int flags,\n                                              dav_lockdb *lockdb)\n{\n    dav_error *err;\n    int result;\n    dav_if_header *if_header;\n    int lock_db_opened_locally = 0;\n    const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r);\n    const dav_hooks_repository *repos_hooks = resource->hooks;\n    dav_buffer work_buf = { 0 };\n    dav_response *new_response;\n    int resource_state;\n    const char *etag;\n    int set_etag = 0;\n#if DAV_DEBUG\n    if (depth && response == NULL) {\n        return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0,\n                             "DESIGN ERROR: dav_validate_request called "\n                             "with depth>0, but no response ptr.");\n    }\n#endif\n    if (response != NULL)\n        *response = NULL;\n    etag = apr_table_get(r->headers_out, "ETag");\n    if (!etag) {\n        etag = (*resource->hooks->getetag)(resource);\n        if (etag && *etag) {\n            apr_table_set(r->headers_out, "ETag", etag);\n            set_etag = 1;\n        }\n    }\n    resource_state = dav_get_resource_state(r, resource);\n    result = dav_meets_conditions(r, resource_state);\n    if (set_etag) {\n        apr_table_unset(r->headers_out, "ETag");\n    }\n    if (result != OK) {\n        return dav_new_error(r->pool, result, 0, 0, NULL);\n    }\n    if ((err = dav_process_if_header(r, &if_header)) != NULL) {\n        return err;\n    }\n    if (locktoken != NULL) {\n        dav_if_header *ifhdr_new;\n        ifhdr_new = apr_pcalloc(r->pool, sizeof(*ifhdr_new));\n        ifhdr_new->uri = resource->uri;\n        ifhdr_new->uri_len = strlen(resource->uri);\n        ifhdr_new->dummy_header = 1;\n        ifhdr_new->state = apr_pcalloc(r->pool, sizeof(*ifhdr_new->state));\n        ifhdr_new->state->type = dav_if_opaquelock;\n        ifhdr_new->state->condition = DAV_IF_COND_NORMAL;\n        ifhdr_new->state->locktoken = locktoken;\n        ifhdr_new->next = if_header;\n        if_header = ifhdr_new;\n    }\n    if (lockdb == NULL) {\n        if (locks_hooks != NULL) {\n            if ((err = (*locks_hooks->open_lockdb)(r, 0, 0, &lockdb)) != NULL) {\n                return err;\n            }\n            lock_db_opened_locally = 1;\n        }\n    }\n    if (resource->exists && depth > 0 && !(!if_header && flags & DAV_VALIDATE_NO_MODIFY)) {\n        dav_walker_ctx ctx = { { 0 } };\n        dav_response *multi_status;\n        ctx.w.walk_type = DAV_WALKTYPE_NORMAL;\n        ctx.w.func = dav_validate_walker;\n        ctx.w.walk_ctx = &ctx;\n        ctx.w.pool = r->pool;\n        ctx.w.root = resource;\n        ctx.if_header = if_header;\n        ctx.r = r;\n        ctx.flags = flags;\n        if (lockdb != NULL) {\n            ctx.w.lockdb = lockdb;\n            ctx.w.walk_type |= DAV_WALKTYPE_LOCKNULL;\n        }\n        err = (*repos_hooks->walk)(&ctx.w, DAV_INFINITY, &multi_status);\n        if (err == NULL) {\n            *response = multi_status;\n        }\n    }\n    else {\n        err = dav_validate_resource_state(r->pool, resource, lockdb,\n                                          if_header, flags, &work_buf, r);\n    }\n    if (err == NULL && (flags & DAV_VALIDATE_PARENT)) {\n        dav_resource *parent_resource;\n        err = (*repos_hooks->get_parent_resource)(resource, &parent_resource);\n        if (err == NULL && parent_resource == NULL) {\n            err = dav_new_error(r->pool, HTTP_FORBIDDEN, 0, 0,\n                                "Cannot access parent of repository root.");\n        }\n        else if (err == NULL) {\n            err = dav_validate_resource_state(r->pool, parent_resource, lockdb,\n                                              if_header,\n                                              flags | DAV_VALIDATE_IS_PARENT,\n                                              &work_buf, r);\n            if (err != NULL) {\n                new_response = apr_pcalloc(r->pool, sizeof(*new_response));\n                new_response->href = parent_resource->uri;\n                new_response->status = err->status;\n                new_response->desc =\n                    "A validation error has occurred on the parent resource, "\n                    "preventing the operation on the resource specified by "\n                    "the Request-URI.";\n                if (err->desc != NULL) {\n                    new_response->desc = apr_pstrcat(r->pool,\n                                                    new_response->desc,\n                                                    " The error was: ",\n                                                    err->desc, NULL);\n                }\n                new_response->next = *response;\n                *response = new_response;\n                err = NULL;\n            }\n        }\n    }\n    if (lock_db_opened_locally)\n        (*locks_hooks->close_lockdb)(lockdb);\n    if (err == NULL && response != NULL && *response != NULL) {\n        apr_text *propstat = NULL;\n        if ((flags & DAV_VALIDATE_USE_424) != 0) {\n            return dav_new_error(r->pool, HTTP_FAILED_DEPENDENCY, 0, 0,\n                                 "An error occurred on another resource, "\n                                 "preventing the requested operation on "\n                                 "this resource.");\n        }\n        if ((flags & DAV_VALIDATE_ADD_LD) != 0) {\n            propstat = apr_pcalloc(r->pool, sizeof(*propstat));\n            propstat->text =\n                "<D:propstat>" DEBUG_CR\n                "<D:prop><D:lockdiscovery/></D:prop>" DEBUG_CR\n                "<D:status>HTTP/1.1 424 Failed Dependency</D:status>" DEBUG_CR\n                "</D:propstat>" DEBUG_CR;\n        }\n        new_response = apr_pcalloc(r->pool, sizeof(*new_response));\n        new_response->href = resource->uri;\n        new_response->status = HTTP_FAILED_DEPENDENCY;\n        new_response->propresult.propstats = propstat;\n        new_response->desc =\n            "An error occurred on another resource, preventing the "\n            "requested operation on this resource.";\n        new_response->next = *response;\n        *response = new_response;\n        return dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, 0,\n                             "Error(s) occurred on resources during the "\n                             "validation process.");\n    }\n    return err;\n}', 'static dav_error * dav_validate_resource_state(apr_pool_t *p,\n                                               const dav_resource *resource,\n                                               dav_lockdb *lockdb,\n                                               const dav_if_header *if_header,\n                                               int flags,\n                                               dav_buffer *pbuf,\n                                               request_rec *r)\n{\n    dav_error *err;\n    const char *uri;\n    const char *etag;\n    const dav_hooks_locks *locks_hooks = (lockdb ? lockdb->hooks : NULL);\n    const dav_if_header *ifhdr_scan;\n    dav_if_state_list *state_list;\n    dav_lock *lock_list;\n    dav_lock *lock;\n    int num_matched;\n    int num_that_apply;\n    int seen_locktoken;\n    apr_size_t uri_len;\n    const char *reason = NULL;\n    if (lockdb == NULL) {\n        lock_list = NULL;\n    }\n    else {\n        if ((err = dav_lock_query(lockdb, resource, &lock_list)) != NULL) {\n            return dav_push_error(p,\n                                  HTTP_INTERNAL_SERVER_ERROR, 0,\n                                  "The locks could not be queried for "\n                                  "verification against a possible \\"If:\\" "\n                                  "header.",\n                                  err);\n        }\n    }\n    if (flags & DAV_LOCKSCOPE_EXCLUSIVE) {\n        if (lock_list != NULL) {\n            return dav_new_error(p, HTTP_LOCKED, 0, 0,\n                                 "Existing lock(s) on the requested resource "\n                                 "prevent an exclusive lock.");\n        }\n        seen_locktoken = 1;\n    }\n    else if (flags & DAV_LOCKSCOPE_SHARED) {\n        for (lock = lock_list; lock != NULL; lock = lock->next) {\n            if (lock->scope == DAV_LOCKSCOPE_EXCLUSIVE) {\n                return dav_new_error(p, HTTP_LOCKED, 0, 0,\n                                     "The requested resource is already "\n                                     "locked exclusively.");\n            }\n        }\n        seen_locktoken = 1;\n    }\n    else {\n        seen_locktoken = (lock_list == NULL\n                          || flags & DAV_VALIDATE_NO_MODIFY);\n    }\n    if (if_header == NULL) {\n        if (seen_locktoken)\n            return NULL;\n        return dav_new_error(p, HTTP_LOCKED, 0, 0,\n                             "This resource is locked and an \\"If:\\" header "\n                             "was not supplied to allow access to the "\n                             "resource.");\n    }\n    if (lock_list == NULL && if_header->dummy_header) {\n        if (flags & DAV_VALIDATE_IS_PARENT)\n            return NULL;\n        return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,\n                             "The locktoken specified in the \\"Lock-Token:\\" "\n                             "header is invalid because this resource has no "\n                             "outstanding locks.");\n    }\n    uri = resource->uri;\n    uri_len = strlen(uri);\n    if (uri[uri_len - 1] == \'/\') {\n        dav_set_bufsize(p, pbuf, uri_len);\n        memcpy(pbuf->buf, uri, uri_len);\n        pbuf->buf[--uri_len] = \'\\0\';\n        uri = pbuf->buf;\n    }\n    etag = (*resource->hooks->getetag)(resource);\n    num_that_apply = 0;\n    for (ifhdr_scan = if_header;\n         ifhdr_scan != NULL;\n         ifhdr_scan = ifhdr_scan->next) {\n        if (ifhdr_scan->uri != NULL\n            && (uri_len != ifhdr_scan->uri_len\n                || memcmp(uri, ifhdr_scan->uri, uri_len) != 0)) {\n            continue;\n        }\n        ++num_that_apply;\n        for (state_list = ifhdr_scan->state;\n             state_list != NULL;\n             state_list = state_list->next) {\n            switch(state_list->type) {\n            case dav_if_etag:\n            {\n                const char *given_etag, *current_etag;\n                int mismatch;\n                if (state_list->etag[0] == \'W\' &&\n                    state_list->etag[1] == \'/\') {\n                    given_etag = state_list->etag + 2;\n                }\n                else {\n                    given_etag = state_list->etag;\n                }\n                if (etag[0] == \'W\' &&\n                    etag[1] == \'/\') {\n                    current_etag = etag + 2;\n                }\n                else {\n                    current_etag = etag;\n                }\n                mismatch = strcmp(given_etag, current_etag);\n                if (state_list->condition == DAV_IF_COND_NORMAL && mismatch) {\n                    reason =\n                        "an entity-tag was specified, but the resource\'s "\n                        "actual ETag does not match.";\n                    goto state_list_failed;\n                }\n                else if (state_list->condition == DAV_IF_COND_NOT\n                         && !mismatch) {\n                    reason =\n                        "an entity-tag was specified using the \\"Not\\" form, "\n                        "but the resource\'s actual ETag matches the provided "\n                        "entity-tag.";\n                    goto state_list_failed;\n                }\n                break;\n            }\n            case dav_if_opaquelock:\n                if (lockdb == NULL) {\n                    if (state_list->condition == DAV_IF_COND_NOT) {\n                        continue;\n                    }\n                    reason =\n                        "a State-token was supplied, but a lock database "\n                        "is not available for to provide the required lock.";\n                    goto state_list_failed;\n                }\n                num_matched = 0;\n                for (lock = lock_list; lock != NULL; lock = lock->next) {\n                    if ((*locks_hooks->compare_locktoken)(state_list->locktoken, lock->locktoken)) {\n                        continue;\n                    }\n                    seen_locktoken = 1;\n                    if (state_list->condition == DAV_IF_COND_NOT) {\n                        reason =\n                            "a State-token was supplied, which used a "\n                            "\\"Not\\" condition. The State-token was found "\n                            "in the locks on this resource";\n                        goto state_list_failed;\n                    }\n                    if (lock->auth_user &&\n                        (!r->user ||\n                         strcmp(lock->auth_user, r->user))) {\n                        const char *errmsg;\n                        errmsg = apr_pstrcat(p, "User \\"",\n                                            r->user,\n                                            "\\" submitted a locktoken created "\n                                            "by user \\"",\n                                            lock->auth_user, "\\".", NULL);\n                        return dav_new_error(p, HTTP_FORBIDDEN, 0, 0, errmsg);\n                    }\n                    num_matched = 1;\n                    break;\n                }\n                if (num_matched == 0\n                    && state_list->condition == DAV_IF_COND_NORMAL) {\n                    reason =\n                        "a State-token was supplied, but it was not found "\n                        "in the locks on this resource.";\n                    goto state_list_failed;\n                }\n                break;\n            case dav_if_unknown:\n                if (state_list->condition == DAV_IF_COND_NORMAL) {\n                    reason =\n                        "an unknown state token was supplied";\n                    goto state_list_failed;\n                }\n                break;\n            }\n        }\n        if (seen_locktoken) {\n            return NULL;\n        }\n        break;\n      state_list_failed:\n        ;\n    }\n    if (ifhdr_scan == NULL) {\n        if (num_that_apply == 0) {\n            if (seen_locktoken)\n                return NULL;\n            if (dav_find_submitted_locktoken(if_header, lock_list,\n                                             locks_hooks)) {\n                return NULL;\n            }\n            return dav_new_error(p, HTTP_LOCKED, 0  , 0,\n                                 "This resource is locked and the \\"If:\\" "\n                                 "header did not specify one of the "\n                                 "locktokens for this resource\'s lock(s).");\n        }\n        if (if_header->dummy_header) {\n            return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,\n                                 "The locktoken specified in the "\n                                 "\\"Lock-Token:\\" header did not specify one "\n                                 "of this resource\'s locktoken(s).");\n        }\n        if (reason == NULL) {\n            return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0,\n                                 "The preconditions specified by the \\"If:\\" "\n                                 "header did not match this resource.");\n        }\n        return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0,\n                             apr_psprintf(p,\n                                         "The precondition(s) specified by "\n                                         "the \\"If:\\" header did not match "\n                                         "this resource. At least one "\n                                         "failure is because: %s", reason));\n    }\n    if (dav_find_submitted_locktoken(if_header, lock_list, locks_hooks)) {\n        return NULL;\n    }\n    if (if_header->dummy_header) {\n        return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0,\n                             "The locktoken specified in the "\n                             "\\"Lock-Token:\\" header did not specify one "\n                             "of this resource\'s locktoken(s).");\n    }\n    return dav_new_error(p, HTTP_LOCKED, 1  , 0,\n                         "This resource is locked and the \\"If:\\" header "\n                         "did not specify one of the "\n                         "locktokens for this resource\'s lock(s).");\n}']