Hi,
It is not uncommon for modules to register the same method.
Therefor it is better to return the already registered
method number, instead of allowing the registration twice.
Sander
PS. I split this out of the mod_dav patch I sent in earlier,
because it affects more than just mod_dav.
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