From 658ec6df00e15a85fc70993b6e04fe87b2f05ae6 Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Thu, 9 Nov 2000 13:08:06 +0000 Subject: [PATCH] final round of walker cleanup: fix the provider API to match what is Right. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86887 13f79535-47bb-0310-9956-ffa450edef68 --- modules/dav/fs/repos.c | 34 ++++++++++++++++------------------ modules/dav/main/mod_dav.c | 7 ++++--- modules/dav/main/mod_dav.h | 18 +++++++++--------- modules/dav/main/util.c | 5 +++-- modules/dav/main/util_lock.c | 15 ++++++++++----- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index 546883f362..c6d198fb4e 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -208,7 +208,8 @@ struct dav_stream { }; /* forward declaration for internal treewalkers */ -static dav_error * dav_fs_walk(dav_walker_ctx *wctx, int depth); +static dav_error * dav_fs_walk(const dav_walk_params *params, int depth, + dav_response **response); static dav_error * dav_fs_internal_walk(const dav_walk_params *params, int depth, int is_move, const dav_resource *root_dst, @@ -1251,23 +1252,24 @@ static dav_error * dav_fs_remove_resource(dav_resource *resource, * including the state dirs */ if (resource->collection) { - dav_walker_ctx ctx = { { 0 } }; + dav_walk_params params = { 0 }; dav_error *err = NULL; + dav_response *multi_status; - ctx.w.walk_type = (DAV_WALKTYPE_NORMAL - | DAV_WALKTYPE_HIDDEN - | DAV_WALKTYPE_POSTFIX); - ctx.w.func = dav_fs_delete_walker; - ctx.w.walk_ctx = &ctx; - ctx.w.pool = info->pool; - ctx.w.root = resource; + params.walk_type = (DAV_WALKTYPE_NORMAL + | DAV_WALKTYPE_HIDDEN + | DAV_WALKTYPE_POSTFIX); + params.func = dav_fs_delete_walker; + params.pool = info->pool; + params.root = resource; - if ((err = dav_fs_walk(&ctx, DAV_INFINITY)) != NULL) { + if ((err = dav_fs_walk(¶ms, DAV_INFINITY, + &multi_status)) != NULL) { /* on a "real" error, then just punt. nothing else to do. */ return err; } - if ((*response = ctx.response) != NULL) { + if ((*response = multi_status) != NULL) { /* some multistatus responses exist. wrap them in a 207 */ return dav_new_error(info->pool, HTTP_MULTI_STATUS, 0, "Error(s) occurred on some resources during " @@ -1648,15 +1650,11 @@ static dav_error * dav_fs_internal_walk(const dav_walk_params *params, return err; } -static dav_error * dav_fs_walk(dav_walker_ctx *wctx, int depth) +static dav_error * dav_fs_walk(const dav_walk_params *params, int depth, + dav_response **response) { - dav_response *response; - dav_error *err; - /* always return the error, and any/all multistatus responses */ - err = dav_fs_internal_walk(&wctx->w, depth, 0, NULL, &response); - wctx->response = response; - return err; + return dav_fs_internal_walk(params, depth, 0, NULL, response); } /* dav_fs_etag: Stolen from ap_make_etag. Creates a strong etag diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 703036d5d9..a61a7f85b5 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -1531,6 +1531,7 @@ static int dav_method_propfind(request_rec *r) ap_xml_doc *doc; const ap_xml_elem *child; dav_walker_ctx ctx = { { 0 } }; + dav_response *multi_status; /* Ask repository module to resolve the resource */ result = dav_get_resource(r, 1 /*target_allowed*/, NULL, &resource); @@ -1622,7 +1623,7 @@ static int dav_method_propfind(request_rec *r) ctx.w.walk_type |= DAV_WALKTYPE_LOCKNULL; } - err = (*resource->hooks->walk)(&ctx, depth); + err = (*resource->hooks->walk)(&ctx.w, depth, &multi_status); if (ctx.w.lockdb != NULL) { (*ctx.w.lockdb->hooks->close_lockdb)(ctx.w.lockdb); @@ -1641,11 +1642,11 @@ static int dav_method_propfind(request_rec *r) * scope for the badprops. */ /* NOTE: propstat_404 != NULL implies doc != NULL */ if (ctx.propstat_404 != NULL) { - dav_send_multistatus(r, HTTP_MULTI_STATUS, ctx.response, + dav_send_multistatus(r, HTTP_MULTI_STATUS, multi_status, doc->namespaces); } else { - dav_send_multistatus(r, HTTP_MULTI_STATUS, ctx.response, NULL); + dav_send_multistatus(r, HTTP_MULTI_STATUS, multi_status, NULL); } /* the response has been sent. */ diff --git a/modules/dav/main/mod_dav.h b/modules/dav/main/mod_dav.h index 73571536db..ae0968c124 100644 --- a/modules/dav/main/mod_dav.h +++ b/modules/dav/main/mod_dav.h @@ -1267,9 +1267,6 @@ typedef struct dav_walker_ctx /* input: */ dav_walk_params w; - /* output: */ - dav_response *response; - /* ### client data... phasing out this big glom */ @@ -1529,14 +1526,17 @@ struct dav_hooks_repository /* Walk a resource hierarchy. * - * Iterates over the resource hierarchy specified by wctx->resource. - * Parameter for control of the walk and the callback are specified - * by wctx. + * Iterates over the resource hierarchy specified by params->root. + * Control of the walk and the callback are specified by 'params'. * - * An HTTP_* status code is returned if an error occurs during the - * walk or the callback indicates an error. OK is returned on success. + * An error may be returned. *response will contain multistatus + * responses (if any) suitable for the body of the error. It is also + * possible to return NULL, yet still have multistatus responses. + * In this case, typically the caller should return a 207 (Multistatus) + * and the responses (in the body) as the HTTP response. */ - dav_error * (*walk)(dav_walker_ctx *wctx, int depth); + dav_error * (*walk)(const dav_walk_params *params, int depth, + dav_response **response); /* Get the entity tag for a resource */ const char * (*getetag)(const dav_resource *resource); diff --git a/modules/dav/main/util.c b/modules/dav/main/util.c index 00c0a0e63e..5af802f727 100644 --- a/modules/dav/main/util.c +++ b/modules/dav/main/util.c @@ -1314,6 +1314,7 @@ dav_error * dav_validate_request(request_rec *r, dav_resource *resource, /* (1) Validate the specified resource, at the specified depth */ if (resource->exists && depth > 0) { dav_walker_ctx ctx = { { 0 } }; + dav_response *multi_status; ctx.w.walk_type = DAV_WALKTYPE_NORMAL; ctx.w.func = dav_validate_walker; @@ -1330,9 +1331,9 @@ dav_error * dav_validate_request(request_rec *r, dav_resource *resource, ctx.w.walk_type |= DAV_WALKTYPE_LOCKNULL; } - err = (*repos_hooks->walk)(&ctx, DAV_INFINITY); + err = (*repos_hooks->walk)(&ctx.w, DAV_INFINITY, &multi_status); if (err == NULL) { - *response = ctx.response; + *response = multi_status;; } /* else: implies a 5xx status code occurred. */ } diff --git a/modules/dav/main/util_lock.c b/modules/dav/main/util_lock.c index edbd69d538..4c23d5e595 100644 --- a/modules/dav/main/util_lock.c +++ b/modules/dav/main/util_lock.c @@ -356,6 +356,7 @@ dav_error * dav_add_lock(request_rec *r, const dav_resource *resource, if (depth > 0) { /* Walk existing collection and set indirect locks */ dav_walker_ctx ctx = { { 0 } }; + dav_response *multi_status; ctx.w.walk_type = DAV_WALKTYPE_NORMAL | DAV_WALKTYPE_AUTH; ctx.w.func = dav_lock_walker; @@ -367,15 +368,15 @@ dav_error * dav_add_lock(request_rec *r, const dav_resource *resource, ctx.r = r; ctx.lock = lock; - err = (*resource->hooks->walk)(&ctx, DAV_INFINITY); + err = (*resource->hooks->walk)(&ctx.w, DAV_INFINITY, &multi_status); if (err != NULL) { /* implies a 5xx status code occurred. screw the multistatus */ return err; } - if (ctx.response != NULL) { + if (multi_status != NULL) { /* manufacture a 207 error for the multistatus response */ - *response = ctx.response; + *response = multi_status; return dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, "Error(s) occurred on resources during the " "addition of a depth lock."); @@ -556,6 +557,7 @@ int dav_unlock(request_rec *r, const dav_resource *resource, if (lock_resource->collection) { dav_walker_ctx ctx = { { 0 } }; + dav_response *multi_status; ctx.w.walk_type = DAV_WALKTYPE_NORMAL | DAV_WALKTYPE_LOCKNULL; ctx.w.func = dav_unlock_walker; @@ -567,9 +569,10 @@ int dav_unlock(request_rec *r, const dav_resource *resource, ctx.r = r; ctx.locktoken = locktoken; - err = (*repos_hooks->walk)(&ctx, DAV_INFINITY); + err = (*repos_hooks->walk)(&ctx.w, DAV_INFINITY, &multi_status); /* ### fix this! */ + /* ### do something with multi_status */ result = err == NULL ? OK : err->status; } else @@ -614,6 +617,7 @@ static dav_error * dav_inherit_locks(request_rec *r, dav_lockdb *lockdb, dav_lock *prev; dav_walker_ctx ctx = { { 0 } }; const dav_hooks_repository *repos_hooks = resource->hooks; + dav_response *multi_status; if (use_parent) { which_resource = (*repos_hooks->get_parent_resource)(resource); @@ -677,7 +681,8 @@ static dav_error * dav_inherit_locks(request_rec *r, dav_lockdb *lockdb, ctx.lock = locks; ctx.skip_root = !use_parent; - return (*repos_hooks->walk)(&ctx, DAV_INFINITY); + /* ### do something with multi_status */ + return (*repos_hooks->walk)(&ctx.w, DAV_INFINITY, &multi_status); } /* --------------------------------------------------------------- -- 2.50.1