From: Greg Stein Date: Mon, 7 Jan 2002 22:36:15 +0000 (+0000) Subject: Fix how mod_dav examines methods in the request -- use the method number X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2737183fc3c4fb7a0ff25b9123901b612e9a1838;p=apache Fix how mod_dav examines methods in the request -- use the method number from the request. To do this, we also need to register all of the new/custom methods that mod_dav recognizes. Note: this fixes a bug where a method (e.g. REPORT) would appear in a Limit(Except) directive and Apache would register the method. The method number in the request would then be something *other* than M_INVALID, which threw off mod_dav's tests. Submitted by: Sander Striker git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92764 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 90879c4012..f049f87959 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -132,12 +132,46 @@ typedef struct { /* forward-declare for use in configuration lookup */ extern module DAV_DECLARE_DATA dav_module; +/* DAV methods */ +enum { + DAV_M_VERSION_CONTROL = 0, + DAV_M_CHECKOUT, + DAV_M_UNCHECKOUT, + DAV_M_CHECKIN, + DAV_M_UPDATE, + DAV_M_LABEL, + DAV_M_REPORT, + DAV_M_MKWORKSPACE, + DAV_M_MKACTIVITY, + DAV_M_BASELINE_CONTROL, + DAV_M_MERGE, + DAV_M_BIND, + DAV_M_LAST +}; + +static int dav_methods[DAV_M_LAST]; + static int dav_init_handler(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { /* DBG0("dav_init_handler"); */ + /* Register DAV methods */ + dav_methods[DAV_M_VERSION_CONTROL] = ap_method_register(p, "VERSION-CONTROL"); + dav_methods[DAV_M_CHECKOUT] = ap_method_register(p, "CHECKOUT"); + dav_methods[DAV_M_UNCHECKOUT] = ap_method_register(p, "UNCHECKOUT"); + dav_methods[DAV_M_CHECKIN] = ap_method_register(p, "CHECKIN"); + dav_methods[DAV_M_UPDATE] = ap_method_register(p, "UPDATE"); + dav_methods[DAV_M_LABEL] = ap_method_register(p, "LABEL"); + dav_methods[DAV_M_REPORT] = ap_method_register(p, "REPORT"); + dav_methods[DAV_M_MKWORKSPACE] = ap_method_register(p, "MKWORKSPACE"); + dav_methods[DAV_M_MKACTIVITY] = ap_method_register(p, "MKACTIVITY"); + dav_methods[DAV_M_BASELINE_CONTROL] = ap_method_register(p, "BASELINE-CONTROL"); + dav_methods[DAV_M_MERGE] = ap_method_register(p, "MERGE"); + dav_methods[DAV_M_BIND] = ap_method_register(p, "BIND"); + ap_add_version_component(p, "DAV/2"); + return OK; } @@ -4479,60 +4513,51 @@ static int dav_handler(request_rec *r) return dav_method_unlock(r); } - /* - * NOTE: When Apache moves creates defines for the add'l DAV methods, - * then it will no longer use M_INVALID. This code must be - * updated each time Apache adds method defines. - */ - if (r->method_number != M_INVALID) { - return DECLINED; - } - - if (!strcmp(r->method, "VERSION-CONTROL")) { + if (r->method_number == dav_methods[DAV_M_VERSION_CONTROL]) { return dav_method_vsn_control(r); } - if (!strcmp(r->method, "CHECKOUT")) { + if (r->method_number == dav_methods[DAV_M_CHECKOUT]) { return dav_method_checkout(r); } - if (!strcmp(r->method, "UNCHECKOUT")) { + if (r->method_number == dav_methods[DAV_M_UNCHECKOUT]) { return dav_method_uncheckout(r); } - if (!strcmp(r->method, "CHECKIN")) { + if (r->method_number == dav_methods[DAV_M_CHECKIN]) { return dav_method_checkin(r); } - if (!strcmp(r->method, "UPDATE")) { + if (r->method_number == dav_methods[DAV_M_UPDATE]) { return dav_method_update(r); } - if (!strcmp(r->method, "LABEL")) { + if (r->method_number == dav_methods[DAV_M_LABEL]) { return dav_method_label(r); } - if (!strcmp(r->method, "REPORT")) { + if (r->method_number == dav_methods[DAV_M_REPORT]) { return dav_method_report(r); } - if (!strcmp(r->method, "MKWORKSPACE")) { + if (r->method_number == dav_methods[DAV_M_MKWORKSPACE]) { return dav_method_make_workspace(r); } - if (!strcmp(r->method, "MKACTIVITY")) { + if (r->method_number == dav_methods[DAV_M_MKACTIVITY]) { return dav_method_make_activity(r); } - if (!strcmp(r->method, "BASELINE-CONTROL")) { + if (r->method_number == dav_methods[DAV_M_BASELINE_CONTROL]) { return dav_method_baseline_control(r); } - if (!strcmp(r->method, "MERGE")) { + if (r->method_number == dav_methods[DAV_M_MERGE]) { return dav_method_merge(r); } - if (!strcmp(r->method, "BIND")) { + if (r->method_number == dav_methods[DAV_M_BIND]) { return dav_method_bind(r); } diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 8b202544ba..8aa5fb0162 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -337,7 +337,7 @@ AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p) AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname) { - int *newmethnum; + int *methnum; if (methods_registry == NULL) { ap_method_registry_init(p); @@ -346,7 +346,15 @@ AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname) if (methname == NULL) { return M_INVALID; } - + + /* Check if the method was previously registered. If it was + * return the associated method number. + */ + methnum = (int *)apr_hash_get(methods_registry, methname, + APR_HASH_KEY_STRING); + if (methnum != NULL) + return *methnum; + if (cur_method_number > METHOD_NUMBER_LAST) { /* The method registry has run out of dynamically * assignable method numbers. Log this and return M_INVALID. @@ -358,11 +366,11 @@ AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname) return M_INVALID; } - newmethnum = (int*)apr_palloc(p, sizeof(int)); - *newmethnum = cur_method_number++; - apr_hash_set(methods_registry, methname, APR_HASH_KEY_STRING, newmethnum); + methnum = (int *)apr_palloc(p, sizeof(int)); + *methnum = cur_method_number++; + apr_hash_set(methods_registry, methname, APR_HASH_KEY_STRING, methnum); - return *newmethnum; + return *methnum; } /* Get the method number associated with the given string, assumed to