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 19:02:39 UTC

[PATCH] Get mod_dav to dynamically register its methods

This patch gets mod_dav to register its methods dynamically.
Instead of relying on the fact that a method isn't registered
and comparing method strings, it now registers and compares
method numbers.

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 17:51:52
@@ -132,12 +132,51 @@
 /* forward-declare for use in configuration lookup */
 extern module DAV_DECLARE_DATA dav_module;
 
+/* DAV methods */
+#define DAV_M_VERSION_CONTROL  0
+#define DAV_M_CHECKOUT         1
+#define DAV_M_UNCHECKOUT       2
+#define DAV_M_CHECKIN          3
+#define DAV_M_UPDATE           4
+#define DAV_M_LABEL            5
+#define DAV_M_REPORT           6
+#define DAV_M_MKWORKSPACE      7
+#define DAV_M_MKACTIVITY       8
+#define DAV_M_BASELINE_CONTROL 9
+#define DAV_M_MERGE            10
+#define DAV_M_BIND             11
+
+static int dav_methods[12];
+
+static APR_INLINE void dav_register_method(apr_pool_t *p, int method_index, 
+                                           const char *method)
+{
+    dav_methods[method_index] = ap_method_number_of(method);
+    if (dav_methods[method_index] == M_INVALID)
+        dav_methods[method_index] = ap_method_register(p, method);
+}
+
 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_register_method(p, DAV_M_VERSION_CONTROL, "VERSION-CONTROL");
+    dav_register_method(p, DAV_M_CHECKOUT, "CHECKOUT");
+    dav_register_method(p, DAV_M_UNCHECKOUT, "UNCHECKOUT");
+    dav_register_method(p, DAV_M_CHECKIN, "CHECKIN");
+    dav_register_method(p, DAV_M_UPDATE, "UPDATE");
+    dav_register_method(p, DAV_M_LABEL, "LABEL");
+    dav_register_method(p, DAV_M_REPORT, "REPORT");
+    dav_register_method(p, DAV_M_MKWORKSPACE, "MKWORKSPACE");
+    dav_register_method(p, DAV_M_MKACTIVITY, "MKACTIVITY");
+    dav_register_method(p, DAV_M_BASELINE_CONTROL, "BASELINE-CONTROL");
+    dav_register_method(p, DAV_M_MERGE, "MERGE");
+    dav_register_method(p, DAV_M_BIND, "BIND");
+    
     ap_add_version_component(p, "DAV/2");
+    
     return OK;
 }
 
@@ -4478,61 +4517,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);
     }


Re: [PATCH] Get mod_dav to dynamically register its methods

Posted by Greg Stein <gs...@lyra.org>.
On Sat, Dec 22, 2001 at 07:02:39PM +0100, Sander Striker wrote:
> This patch gets mod_dav to register its methods dynamically.
> Instead of relying on the fact that a method isn't registered
> and comparing method strings, it now registers and compares
> method numbers.

Sander and I talked about this via AIM. He's going to do a new patch which
fixes ap_method_register(). That function should return the method number if
someone has already registered the method (which could easily happen across
modules).

Second, he's going to switch the DAV_M_ constants into an enumerated value.

Overall, the patch looks great. It really cleans up dav_handler(), and the
integer checks will be slightly faster (not that it matters right there,
tho).

For those unaware of the problem: with the introduction of the method
registry, at some point, the server started using registered method numbers
rather than M_INVALID for the unknown methods. In particular, this would
happen as a result of a Limit(Except) referring to a new method and
registering it. dav_handler() would then get a method number it doesn't
understand; in particular, it wouldn't get M_INVALID for "REPORT" and it
wouldn't ever respond to that method.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/