You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Sander Striker <st...@apache.org> on 2001/12/22 22:48:37 UTC

[PATCH] Get mod_dav to dynamically register its methods [2]

Hi,

Like Greg announced previously: here is a new patch.
I changed a variable name in ap_method_register, because
it is more appropiate with the patch in.

Sander

Index: modules/dav/main/mod_dav.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/dav/main/mod_dav.c,v
retrieving revision 1.65
diff -u -r1.65 mod_dav.c
--- modules//dav/main/mod_dav.c	2001/11/23 16:35:21	1.65
+++ modules//dav/main/mod_dav.c	2001/12/22 21:28:35
@@ -132,12 +132,46 @@
 /* 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;
 }
 
@@ -4478,61 +4512,52 @@
     if (r->method_number == M_UNLOCK) {
 	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: modules/http/http_protocol.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/http/http_protocol.c,v
retrieving revision 1.382
diff -u -r1.382 http_protocol.c
--- modules//http/http_protocol.c	2001/12/06 02:57:19	1.382
+++ modules//http/http_protocol.c	2001/12/22 21:28:49
@@ -337,7 +337,7 @@
 
 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 @@
     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 @@
         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