]> granicus.if.org Git - apache/commitdiff
Fix how mod_dav examines methods in the request -- use the method number
authorGreg Stein <gstein@apache.org>
Mon, 7 Jan 2002 22:36:15 +0000 (22:36 +0000)
committerGreg Stein <gstein@apache.org>
Mon, 7 Jan 2002 22:36:15 +0000 (22:36 +0000)
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 <striker@apache.org>

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92764 13f79535-47bb-0310-9956-ffa450edef68

modules/dav/main/mod_dav.c
modules/http/http_protocol.c

index 90879c4012bcb66910ae5172099913b350cf974f..f049f879590482e2e01fda4256181c197afde40b 100644 (file)
@@ -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);
     }
 
index 8b202544bad458bafc7b9bbb713d0123c9464aa0..8aa5fb01625a6de2c5cf0d0b09c14c3bb024f451 100644 (file)
@@ -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