You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Justin Erenkrantz <je...@ebuilt.com> on 2001/02/06 02:39:35 UTC

mod_example patch for Apache 2.0

For everyone's consideration, here is a quick patch to make
mod_example functional in Apache 2.0.

It seems that the handler_rec structure was discarded,
but no one told mod_example.  I just subscribed to 
new-httpd last week, so I am not familiar when this 
change occurred.  I tried my best to describe the 
functionality of the handlers, but I may or may not
be accurate (any input would be appreciated).

Since I've written some Apache 1.3 modules, I expected
mod_example to be ported to the new API.  That was not 
the case, so I decided it might be beneficial to get it
working again.

I am not sure if mod_example is going to be punted (seems 
to be the word of the day) for something cleaner down the 
road, but this patch lets it compile and work with what is 
currently in CVS.

This patch is also not extensively tested.  It just returned
data that LOOKED correct.

Please let me know if you have any comments or suggestions,
Justin Erenkrantz
jerenkrantz@ebuilt.com

Index: mod_example.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/experimental/mod_example.c,v
retrieving revision 1.17
diff -u -r1.17 mod_example.c
--- mod_example.c	2001/01/19 07:04:18	1.17
+++ mod_example.c	2001/02/06 01:30:12
@@ -74,6 +74,18 @@
 
 #include <stdio.h>
 
+/* 
+ * Content handlers our module supplies.  Each handler is defined by
+ * a name by which it can be referenced (such as by {Add,Set}Handler).
+ *
+ * Note that content-handlers are always invoked; that is each declared
+ * handler will be called in a non-specific order.  It is the 
+ * content-handler's responsibility to act upon the correct type.  Note 
+ * also that if a content-handler returns anything except DECLINED, 
+ * no other content-handlers will be called.
+ */
+#define EXAMPLE_HANDLER "example-handler"
+
 /*--------------------------------------------------------------------------*/
 /*                                                                          */
 /* Data declarations.                                                       */
@@ -499,6 +511,16 @@
     excfg *dcfg;
 
     dcfg = our_dconfig(r);
+
+    /*
+     * In Apache 2.0, all handlers receive a request and have
+     * a chance to process them.  Therefore, we need to only
+     * handle those that we explicitly agreed to handle (see 
+     * above).
+     */
+    if (!r->handler || strcmp(r->handler, EXAMPLE_HANDLER))
+        return DECLINED;
+
     trace_add(r->server, r, dcfg, "example_handler()");
     /*
      * We're about to start sending content, so we need to force the HTTP
@@ -1119,8 +1141,9 @@
     /* [8] fixups */
     ap_hook_fixups(example_fixer_upper,
 		   NULL, NULL, APR_HOOK_MIDDLE);
-    /* [9] is for the handlers; see below */
-
+    /* [9] is for the handlers */
+    ap_hook_handler(example_handler,
+           NULL, NULL, APR_HOOK_MIDDLE);
     /* [10] logger */
     ap_hook_log_transaction(example_logger,
 			    NULL, NULL, APR_HOOK_MIDDLE);
@@ -1155,29 +1178,6 @@
 
 /*--------------------------------------------------------------------------*/
 /*                                                                          */
-/* Now the list of content handlers available from this module.             */
-/*                                                                          */
-/*--------------------------------------------------------------------------*/
-/* 
- * List of content handlers our module supplies.  Each handler is defined by
- * two parts: a name by which it can be referenced (such as by
- * {Add,Set}Handler), and the actual routine name.  The list is terminated by
- * a NULL block, since it can be of variable length.
- *
- * Note that content-handlers are invoked on a most-specific to least-specific
- * basis; that is, a handler that is declared for "text/plain" will be
- * invoked before one that was declared for "text / *".  Note also that
- * if a content-handler returns anything except DECLINED, no other
- * content-handlers will be called.
- */
-static const handler_rec example_handlers[] =
-{
-    {"example-handler", example_handler},
-    {NULL}
-};
-
-/*--------------------------------------------------------------------------*/
-/*                                                                          */
 /* Finally, the list of callback routines and data structures that provide  */
 /* the static hooks into our module from the other parts of the server.     */
 /*                                                                          */
@@ -1194,6 +1194,5 @@
     example_create_server_config, /* server config creator */
     example_merge_server_config,  /* server config merger */
     example_cmds,                 /* command table */
-    example_handlers,             /* list of content delivery handlers */
-    example_register_hooks,       /* set up other request processing hooks */
+    example_register_hooks        /* set up other request processing hooks */
 };