upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / modules / experimental / mod_example.c
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /* 
18  * Apache example module.  Provide demonstrations of how modules do things.
19  * It is not meant to be used in a production server.  Since it participates
20  * in all of the processing phases, it could conceivable interfere with
21  * the proper operation of other modules -- particularly the ones related
22  * to security.
23  *
24  * In the interest of brevity, all functions and structures internal to
25  * this module, but which may have counterparts in *real* modules, are
26  * prefixed with 'x_' instead of 'example_'.
27  */
28
29 #include "httpd.h"
30 #include "http_config.h"
31 #include "http_core.h"
32 #include "http_log.h"
33 #include "http_main.h"
34 #include "http_protocol.h"
35 #include "http_request.h"
36 #include "util_script.h"
37 #include "http_connection.h"
38
39 #include "apr_strings.h"
40
41 #include <stdio.h>
42
43 /*--------------------------------------------------------------------------*/
44 /*                                                                          */
45 /* Data declarations.                                                       */
46 /*                                                                          */
47 /* Here are the static cells and structure declarations private to our      */
48 /* module.                                                                  */
49 /*                                                                          */
50 /*--------------------------------------------------------------------------*/
51
52 /*
53  * Sample configuration record.  Used for both per-directory and per-server
54  * configuration data.
55  *
56  * It's perfectly reasonable to have two different structures for the two
57  * different environments.  The same command handlers will be called for
58  * both, though, so the handlers need to be able to tell them apart.  One
59  * possibility is for both structures to start with an int which is 0 for
60  * one and 1 for the other.
61  *
62  * Note that while the per-directory and per-server configuration records are
63  * available to most of the module handlers, they should be treated as
64  * READ-ONLY by all except the command and merge handlers.  Sometimes handlers
65  * are handed a record that applies to the current location by implication or
66  * inheritance, and modifying it will change the rules for other locations.
67  */
68 typedef struct x_cfg {
69     int cmode;                  /* Environment to which record applies
70                                  * (directory, server, or combination).
71                                  */
72 #define CONFIG_MODE_SERVER 1
73 #define CONFIG_MODE_DIRECTORY 2
74 #define CONFIG_MODE_COMBO 3     /* Shouldn't ever happen. */
75     int local;                  /* Boolean: "Example" directive declared
76                                  * here?
77                                  */
78     int congenital;             /* Boolean: did we inherit an "Example"? */
79     char *trace;                /* Pointer to trace string. */
80     char *loc;                  /* Location to which this record applies. */
81 } x_cfg;
82
83 /*
84  * Let's set up a module-local static cell to point to the accreting callback
85  * trace.  As each API callback is made to us, we'll tack on the particulars
86  * to whatever we've already recorded.  To avoid massive memory bloat as
87  * directories are walked again and again, we record the routine/environment
88  * the first time (non-request context only), and ignore subsequent calls for
89  * the same routine/environment.
90  */
91 static const char *trace = NULL;
92 static apr_table_t *static_calls_made = NULL;
93
94 /*
95  * To avoid leaking memory from pools other than the per-request one, we
96  * allocate a module-private pool, and then use a sub-pool of that which gets
97  * freed each time we modify the trace.  That way previous layers of trace
98  * data don't get lost.
99  */
100 static apr_pool_t *x_pool = NULL;
101 static apr_pool_t *x_subpool = NULL;
102
103 /*
104  * Declare ourselves so the configuration routines can find and know us.
105  * We'll fill it in at the end of the module.
106  */
107 module AP_MODULE_DECLARE_DATA example_module;
108
109 /*--------------------------------------------------------------------------*/
110 /*                                                                          */
111 /* The following pseudo-prototype declarations illustrate the parameters    */
112 /* passed to command handlers for the different types of directive          */
113 /* syntax.  If an argument was specified in the directive definition        */
114 /* (look for "command_rec" below), it's available to the command handler    */
115 /* via the (void *) info field in the cmd_parms argument passed to the      */
116 /* handler (cmd->info for the examples below).                              */
117 /*                                                                          */
118 /*--------------------------------------------------------------------------*/
119
120 /*
121  * Command handler for a NO_ARGS directive.  Declared in the command_rec
122  * list with
123  *   AP_INIT_NO_ARGS("directive", function, mconfig, where, help)
124  *
125  * static const char *handle_NO_ARGS(cmd_parms *cmd, void *mconfig);
126  */
127
128 /*
129  * Command handler for a RAW_ARGS directive.  The "args" argument is the text
130  * of the commandline following the directive itself.  Declared in the
131  * command_rec list with
132  *   AP_INIT_RAW_ARGS("directive", function, mconfig, where, help)
133  *
134  * static const char *handle_RAW_ARGS(cmd_parms *cmd, void *mconfig,
135  *                                    const char *args);
136  */
137
138 /*
139  * Command handler for a FLAG directive.  The single parameter is passed in
140  * "bool", which is either zero or not for Off or On respectively.
141  * Declared in the command_rec list with
142  *   AP_INIT_FLAG("directive", function, mconfig, where, help)
143  *
144  * static const char *handle_FLAG(cmd_parms *cmd, void *mconfig, int bool);
145  */
146
147 /*
148  * Command handler for a TAKE1 directive.  The single parameter is passed in
149  * "word1".  Declared in the command_rec list with
150  *   AP_INIT_TAKE1("directive", function, mconfig, where, help)
151  *
152  * static const char *handle_TAKE1(cmd_parms *cmd, void *mconfig,
153  *                                 char *word1);
154  */
155
156 /*
157  * Command handler for a TAKE2 directive.  TAKE2 commands must always have
158  * exactly two arguments.  Declared in the command_rec list with
159  *   AP_INIT_TAKE2("directive", function, mconfig, where, help)
160  *
161  * static const char *handle_TAKE2(cmd_parms *cmd, void *mconfig,
162  *                                 char *word1, char *word2);
163  */
164
165 /*
166  * Command handler for a TAKE3 directive.  Like TAKE2, these must have exactly
167  * three arguments, or the parser complains and doesn't bother calling us.
168  * Declared in the command_rec list with
169  *   AP_INIT_TAKE3("directive", function, mconfig, where, help)
170  *
171  * static const char *handle_TAKE3(cmd_parms *cmd, void *mconfig,
172  *                                 char *word1, char *word2, char *word3);
173  */
174
175 /*
176  * Command handler for a TAKE12 directive.  These can take either one or two
177  * arguments.
178  * - word2 is a NULL pointer if no second argument was specified.
179  * Declared in the command_rec list with
180  *   AP_INIT_TAKE12("directive", function, mconfig, where, help)
181  *
182  * static const char *handle_TAKE12(cmd_parms *cmd, void *mconfig,
183  *                                  char *word1, char *word2);
184  */
185
186 /*
187  * Command handler for a TAKE123 directive.  A TAKE123 directive can be given,
188  * as might be expected, one, two, or three arguments.
189  * - word2 is a NULL pointer if no second argument was specified.
190  * - word3 is a NULL pointer if no third argument was specified.
191  * Declared in the command_rec list with
192  *   AP_INIT_TAKE123("directive", function, mconfig, where, help)
193  *
194  * static const char *handle_TAKE123(cmd_parms *cmd, void *mconfig,
195  *                                   char *word1, char *word2, char *word3);
196  */
197
198 /*
199  * Command handler for a TAKE13 directive.  Either one or three arguments are
200  * permitted - no two-parameters-only syntax is allowed.
201  * - word2 and word3 are NULL pointers if only one argument was specified.
202  * Declared in the command_rec list with
203  *   AP_INIT_TAKE13("directive", function, mconfig, where, help)
204  *
205  * static const char *handle_TAKE13(cmd_parms *cmd, void *mconfig,
206  *                                  char *word1, char *word2, char *word3);
207  */
208
209 /*
210  * Command handler for a TAKE23 directive.  At least two and as many as three
211  * arguments must be specified.
212  * - word3 is a NULL pointer if no third argument was specified.
213  * Declared in the command_rec list with
214  *   AP_INIT_TAKE23("directive", function, mconfig, where, help)
215  *
216  * static const char *handle_TAKE23(cmd_parms *cmd, void *mconfig,
217  *                                  char *word1, char *word2, char *word3);
218  */
219
220 /*
221  * Command handler for a ITERATE directive.
222  * - Handler is called once for each of n arguments given to the directive.
223  * - word1 points to each argument in turn.
224  * Declared in the command_rec list with
225  *   AP_INIT_ITERATE("directive", function, mconfig, where, help)
226  *
227  * static const char *handle_ITERATE(cmd_parms *cmd, void *mconfig,
228  *                                   char *word1);
229  */
230
231 /*
232  * Command handler for a ITERATE2 directive.
233  * - Handler is called once for each of the second and subsequent arguments
234  *   given to the directive.
235  * - word1 is the same for each call for a particular directive instance (the
236  *   first argument).
237  * - word2 points to each of the second and subsequent arguments in turn.
238  * Declared in the command_rec list with
239  *   AP_INIT_ITERATE2("directive", function, mconfig, where, help)
240  *
241  * static const char *handle_ITERATE2(cmd_parms *cmd, void *mconfig,
242  *                                    char *word1, char *word2);
243  */
244
245 /*--------------------------------------------------------------------------*/
246 /*                                                                          */
247 /* These routines are strictly internal to this module, and support its     */
248 /* operation.  They are not referenced by any external portion of the       */
249 /* server.                                                                  */
250 /*                                                                          */
251 /*--------------------------------------------------------------------------*/
252
253 /*
254  * Locate our directory configuration record for the current request.
255  */
256 static x_cfg *our_dconfig(const request_rec *r)
257 {
258     return (x_cfg *) ap_get_module_config(r->per_dir_config, &example_module);
259 }
260
261 #if 0
262 /*
263  * Locate our server configuration record for the specified server.
264  */
265 static x_cfg *our_sconfig(const server_rec *s)
266 {
267     return (x_cfg *) ap_get_module_config(s->module_config, &example_module);
268 }
269
270 /*
271  * Likewise for our configuration record for the specified request.
272  */
273 static x_cfg *our_rconfig(const request_rec *r)
274 {
275     return (x_cfg *) ap_get_module_config(r->request_config, &example_module);
276 }
277 #endif
278
279 /*
280  * Likewise for our configuration record for a connection.
281  */
282 static x_cfg *our_cconfig(const conn_rec *c)
283 {
284     return (x_cfg *) ap_get_module_config(c->conn_config, &example_module);
285 }
286
287 /*
288  * This routine sets up some module-wide cells if they haven't been already.
289  */
290 static void setup_module_cells(void)
291 {
292     /*
293      * If we haven't already allocated our module-private pool, do so now.
294      */
295     if (x_pool == NULL) {
296         apr_pool_create(&x_pool, NULL);
297     };
298     /*
299      * Likewise for the table of routine/environment pairs we visit outside of
300      * request context.
301      */
302     if (static_calls_made == NULL) {
303         static_calls_made = apr_table_make(x_pool, 16);
304     };
305 }
306
307 /*
308  * This routine is used to add a trace of a callback to the list.  We're
309  * passed the server record (if available), the request record (if available),
310  * a pointer to our private configuration record (if available) for the
311  * environment to which the callback is supposed to apply, and some text.  We
312  * turn this into a textual representation and add it to the tail of the list.
313  * The list can be displayed by the x_handler() routine.
314  *
315  * If the call occurs within a request context (i.e., we're passed a request
316  * record), we put the trace into the request apr_pool_t and attach it to the
317  * request via the notes mechanism.  Otherwise, the trace gets added
318  * to the static (non-request-specific) list.
319  *
320  * Note that the r->notes table is only for storing strings; if you need to
321  * maintain per-request data of any other type, you need to use another
322  * mechanism.
323  */
324
325 #define TRACE_NOTE "example-trace"
326
327 static void trace_add(server_rec *s, request_rec *r, x_cfg *mconfig,
328                       const char *note)
329 {
330     const char *sofar;
331     char *addon;
332     char *where;
333     apr_pool_t *p;
334     const char *trace_copy;
335
336     /*
337      * Make sure our pools and tables are set up - we need 'em.
338      */
339     setup_module_cells();
340     /*
341      * Now, if we're in request-context, we use the request pool.
342      */
343     if (r != NULL) {
344         p = r->pool;
345         if ((trace_copy = apr_table_get(r->notes, TRACE_NOTE)) == NULL) {
346             trace_copy = "";
347         }
348     }
349     else {
350         /*
351          * We're not in request context, so the trace gets attached to our
352          * module-wide pool.  We do the create/destroy every time we're called
353          * in non-request context; this avoids leaking memory in some of
354          * the subsequent calls that allocate memory only once (such as the
355          * key formation below).
356          *
357          * Make a new sub-pool and copy any existing trace to it.  Point the
358          * trace cell at the copied value.
359          */
360         apr_pool_create(&p, x_pool);
361         if (trace != NULL) {
362             trace = apr_pstrdup(p, trace);
363         }
364         /*
365          * Now, if we have a sub-pool from before, nuke it and replace with
366          * the one we just allocated.
367          */
368         if (x_subpool != NULL) {
369             apr_pool_destroy(x_subpool);
370         }
371         x_subpool = p;
372         trace_copy = trace;
373     }
374     /*
375      * If we weren't passed a configuration record, we can't figure out to
376      * what location this call applies.  This only happens for co-routines
377      * that don't operate in a particular directory or server context.  If we
378      * got a valid record, extract the location (directory or server) to which
379      * it applies.
380      */
381     where = (mconfig != NULL) ? mconfig->loc : "nowhere";
382     where = (where != NULL) ? where : "";
383     /*
384      * Now, if we're not in request context, see if we've been called with
385      * this particular combination before.  The apr_table_t is allocated in the
386      * module's private pool, which doesn't get destroyed.
387      */
388     if (r == NULL) {
389         char *key;
390
391         key = apr_pstrcat(p, note, ":", where, NULL);
392         if (apr_table_get(static_calls_made, key) != NULL) {
393             /*
394              * Been here, done this.
395              */
396             return;
397         }
398         else {
399             /*
400              * First time for this combination of routine and environment -
401              * log it so we don't do it again.
402              */
403             apr_table_set(static_calls_made, key, "been here");
404         }
405     }
406     addon = apr_pstrcat(p,
407                         "   <li>\n"
408                         "    <dl>\n"
409                         "     <dt><samp>", note, "</samp></dt>\n"
410                         "     <dd><samp>[", where, "]</samp></dd>\n"
411                         "    </dl>\n"
412                         "   </li>\n",
413                         NULL);
414     sofar = (trace_copy == NULL) ? "" : trace_copy;
415     trace_copy = apr_pstrcat(p, sofar, addon, NULL);
416     if (r != NULL) {
417         apr_table_set(r->notes, TRACE_NOTE, trace_copy);
418     }
419     else {
420         trace = trace_copy;
421     }
422     /*
423      * You *could* change the following if you wanted to see the calling
424      * sequence reported in the server's error_log, but beware - almost all of
425      * these co-routines are called for every single request, and the impact
426      * on the size (and readability) of the error_log is considerable.
427      */
428 #define EXAMPLE_LOG_EACH 0
429     if (EXAMPLE_LOG_EACH && (s != NULL)) {
430         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "mod_example: %s", note);
431     }
432 }
433
434 /*--------------------------------------------------------------------------*/
435 /* We prototyped the various syntax for command handlers (routines that     */
436 /* are called when the configuration parser detects a directive declared    */
437 /* by our module) earlier.  Now we actually declare a "real" routine that   */
438 /* will be invoked by the parser when our "real" directive is               */
439 /* encountered.                                                             */
440 /*                                                                          */
441 /* If a command handler encounters a problem processing the directive, it   */
442 /* signals this fact by returning a non-NULL pointer to a string            */
443 /* describing the problem.                                                  */
444 /*                                                                          */
445 /* The magic return value DECLINE_CMD is used to deal with directives       */
446 /* that might be declared by multiple modules.  If the command handler      */
447 /* returns NULL, the directive was processed; if it returns DECLINE_CMD,    */
448 /* the next module (if any) that declares the directive is given a chance   */
449 /* at it.  If it returns any other value, it's treated as the text of an    */
450 /* error message.                                                           */
451 /*--------------------------------------------------------------------------*/
452 /* 
453  * Command handler for the NO_ARGS "Example" directive.  All we do is mark the
454  * call in the trace log, and flag the applicability of the directive to the
455  * current location in that location's configuration record.
456  */
457 static const char *cmd_example(cmd_parms *cmd, void *mconfig)
458 {
459     x_cfg *cfg = (x_cfg *) mconfig;
460
461     /*
462      * "Example Wuz Here"
463      */
464     cfg->local = 1;
465     trace_add(cmd->server, NULL, cfg, "cmd_example()");
466     return NULL;
467 }
468
469 /*--------------------------------------------------------------------------*/
470 /*                                                                          */
471 /* Now we declare our content handlers, which are invoked when the server   */
472 /* encounters a document which our module is supposed to have a chance to   */
473 /* see.  (See mod_mime's SetHandler and AddHandler directives, and the      */
474 /* mod_info and mod_status examples, for more details.)                     */
475 /*                                                                          */
476 /* Since content handlers are dumping data directly into the connection     */
477 /* (using the r*() routines, such as rputs() and rprintf()) without         */
478 /* intervention by other parts of the server, they need to make             */
479 /* sure any accumulated HTTP headers are sent first.  This is done by       */
480 /* calling send_http_header().  Otherwise, no header will be sent at all,   */
481 /* and the output sent to the client will actually be HTTP-uncompliant.     */
482 /*--------------------------------------------------------------------------*/
483 /* 
484  * Sample content handler.  All this does is display the call list that has
485  * been built up so far.
486  *
487  * The return value instructs the caller concerning what happened and what to
488  * do next:
489  *  OK ("we did our thing")
490  *  DECLINED ("this isn't something with which we want to get involved")
491  *  HTTP_mumble ("an error status should be reported")
492  */
493 static int x_handler(request_rec *r)
494 {
495     x_cfg *dcfg;
496
497     if (strcmp(r->handler, "example-handler")) {
498         return DECLINED;
499     }
500
501     dcfg = our_dconfig(r);
502     trace_add(r->server, r, dcfg, "x_handler()");
503     /*
504      * We're about to start sending content, so we need to force the HTTP
505      * headers to be sent at this point.  Otherwise, no headers will be sent
506      * at all.  We can set any we like first, of course.  **NOTE** Here's
507      * where you set the "Content-type" header, and you do so by putting it in
508      * r->content_type, *not* r->headers_out("Content-type").  If you don't
509      * set it, it will be filled in with the server's default type (typically
510      * "text/plain").  You *must* also ensure that r->content_type is lower
511      * case.
512      *
513      * We also need to start a timer so the server can know if the connexion
514      * is broken.
515      */
516     ap_set_content_type(r, "text/html");
517     /*
518      * If we're only supposed to send header information (HEAD request), we're
519      * already there.
520      */
521     if (r->header_only) {
522         return OK;
523     }
524
525     /*
526      * Now send our actual output.  Since we tagged this as being
527      * "text/html", we need to embed any HTML.
528      */
529     ap_rputs(DOCTYPE_HTML_3_2, r);
530     ap_rputs("<HTML>\n", r);
531     ap_rputs(" <HEAD>\n", r);
532     ap_rputs("  <TITLE>mod_example Module Content-Handler Output\n", r);
533     ap_rputs("  </TITLE>\n", r);
534     ap_rputs(" </HEAD>\n", r);
535     ap_rputs(" <BODY>\n", r);
536     ap_rputs("  <H1><SAMP>mod_example</SAMP> Module Content-Handler Output\n", r);
537     ap_rputs("  </H1>\n", r);
538     ap_rputs("  <P>\n", r);
539     ap_rprintf(r, "  Apache HTTP Server version: \"%s\"\n",
540             ap_get_server_version());
541     ap_rputs("  <BR>\n", r);
542     ap_rprintf(r, "  Server built: \"%s\"\n", ap_get_server_built());
543     ap_rputs("  </P>\n", r);;
544     ap_rputs("  <P>\n", r);
545     ap_rputs("  The format for the callback trace is:\n", r);
546     ap_rputs("  </P>\n", r);
547     ap_rputs("  <DL>\n", r);
548     ap_rputs("   <DT><EM>n</EM>.<SAMP>&lt;routine-name&gt;", r);
549     ap_rputs("(&lt;routine-data&gt;)</SAMP>\n", r);
550     ap_rputs("   </DT>\n", r);
551     ap_rputs("   <DD><SAMP>[&lt;applies-to&gt;]</SAMP>\n", r);
552     ap_rputs("   </DD>\n", r);
553     ap_rputs("  </DL>\n", r);
554     ap_rputs("  <P>\n", r);
555     ap_rputs("  The <SAMP>&lt;routine-data&gt;</SAMP> is supplied by\n", r);
556     ap_rputs("  the routine when it requests the trace,\n", r);
557     ap_rputs("  and the <SAMP>&lt;applies-to&gt;</SAMP> is extracted\n", r);
558     ap_rputs("  from the configuration record at the time of the trace.\n", r);
559     ap_rputs("  <STRONG>SVR()</STRONG> indicates a server environment\n", r);
560     ap_rputs("  (blank means the main or default server, otherwise it's\n", r);
561     ap_rputs("  the name of the VirtualHost); <STRONG>DIR()</STRONG>\n", r);
562     ap_rputs("  indicates a location in the URL or filesystem\n", r);
563     ap_rputs("  namespace.\n", r);
564     ap_rputs("  </P>\n", r);
565     ap_rprintf(r, "  <H2>Static callbacks so far:</H2>\n  <OL>\n%s  </OL>\n",
566             trace);
567     ap_rputs("  <H2>Request-specific callbacks so far:</H2>\n", r);
568     ap_rprintf(r, "  <OL>\n%s  </OL>\n", apr_table_get(r->notes, TRACE_NOTE));
569     ap_rputs("  <H2>Environment for <EM>this</EM> call:</H2>\n", r);
570     ap_rputs("  <UL>\n", r);
571     ap_rprintf(r, "   <LI>Applies-to: <SAMP>%s</SAMP>\n   </LI>\n", dcfg->loc);
572     ap_rprintf(r, "   <LI>\"Example\" directive declared here: %s\n   </LI>\n",
573             (dcfg->local ? "YES" : "NO"));
574     ap_rprintf(r, "   <LI>\"Example\" inherited: %s\n   </LI>\n",
575             (dcfg->congenital ? "YES" : "NO"));
576     ap_rputs("  </UL>\n", r);
577     ap_rputs(" </BODY>\n", r);
578     ap_rputs("</HTML>\n", r);
579     /*
580      * We're all done, so cancel the timeout we set.  Since this is probably
581      * the end of the request we *could* assume this would be done during
582      * post-processing - but it's possible that another handler might be
583      * called and inherit our outstanding timer.  Not good; to each its own.
584      */
585     /*
586      * We did what we wanted to do, so tell the rest of the server we
587      * succeeded.
588      */
589     return OK;
590 }
591
592 /*--------------------------------------------------------------------------*/
593 /*                                                                          */
594 /* Now let's declare routines for each of the callback phase in order.      */
595 /* (That's the order in which they're listed in the callback list, *not     */
596 /* the order in which the server calls them!  See the command_rec           */
597 /* declaration near the bottom of this file.)  Note that these may be       */
598 /* called for situations that don't relate primarily to our function - in   */
599 /* other words, the fixup handler shouldn't assume that the request has     */
600 /* to do with "example" stuff.                                              */
601 /*                                                                          */
602 /* With the exception of the content handler, all of our routines will be   */
603 /* called for each request, unless an earlier handler from another module   */
604 /* aborted the sequence.                                                    */
605 /*                                                                          */
606 /* Handlers that are declared as "int" can return the following:            */
607 /*                                                                          */
608 /*  OK          Handler accepted the request and did its thing with it.     */
609 /*  DECLINED    Handler took no action.                                     */
610 /*  HTTP_mumble Handler looked at request and found it wanting.             */
611 /*                                                                          */
612 /* What the server does after calling a module handler depends upon the     */
613 /* handler's return value.  In all cases, if the handler returns            */
614 /* DECLINED, the server will continue to the next module with an handler    */
615 /* for the current phase.  However, if the handler return a non-OK,         */
616 /* non-DECLINED status, the server aborts the request right there.  If      */
617 /* the handler returns OK, the server's next action is phase-specific;      */
618 /* see the individual handler comments below for details.                   */
619 /*                                                                          */
620 /*--------------------------------------------------------------------------*/
621 /* 
622  * This function is called during server initialisation.  Any information
623  * that needs to be recorded must be in static cells, since there's no
624  * configuration record.
625  *
626  * There is no return value.
627  */
628
629 /* 
630  * This function is called when an heavy-weight process (such as a child) is
631  * being run down or destroyed.  As with the child initialisation function,
632  * any information that needs to be recorded must be in static cells, since
633  * there's no configuration record.
634  *
635  * There is no return value.
636  */
637
638 /* 
639  * This function is called during server initialisation when an heavy-weight
640  * process (such as a child) is being initialised.  As with the
641  * module initialisation function, any information that needs to be recorded
642  * must be in static cells, since there's no configuration record.
643  *
644  * There is no return value.
645  */
646
647 /*
648  * This function gets called to create a per-directory configuration
649  * record.  This will be called for the "default" server environment, and for
650  * each directory for which the parser finds any of our directives applicable.
651  * If a directory doesn't have any of our directives involved (i.e., they
652  * aren't in the .htaccess file, or a <Location>, <Directory>, or related
653  * block), this routine will *not* be called - the configuration for the
654  * closest ancestor is used.
655  *
656  * The return value is a pointer to the created module-specific
657  * structure.
658  */
659 static void *x_create_dir_config(apr_pool_t *p, char *dirspec)
660 {
661     x_cfg *cfg;
662     char *dname = dirspec;
663
664     /*
665      * Allocate the space for our record from the pool supplied.
666      */
667     cfg = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
668     /*
669      * Now fill in the defaults.  If there are any `parent' configuration
670      * records, they'll get merged as part of a separate callback.
671      */
672     cfg->local = 0;
673     cfg->congenital = 0;
674     cfg->cmode = CONFIG_MODE_DIRECTORY;
675     /*
676      * Finally, add our trace to the callback list.
677      */
678     dname = (dname != NULL) ? dname : "";
679     cfg->loc = apr_pstrcat(p, "DIR(", dname, ")", NULL);
680     trace_add(NULL, NULL, cfg, "x_create_dir_config()");
681     return (void *) cfg;
682 }
683
684 /*
685  * This function gets called to merge two per-directory configuration
686  * records.  This is typically done to cope with things like .htaccess files
687  * or <Location> directives for directories that are beneath one for which a
688  * configuration record was already created.  The routine has the
689  * responsibility of creating a new record and merging the contents of the
690  * other two into it appropriately.  If the module doesn't declare a merge
691  * routine, the record for the closest ancestor location (that has one) is
692  * used exclusively.
693  *
694  * The routine MUST NOT modify any of its arguments!
695  *
696  * The return value is a pointer to the created module-specific structure
697  * containing the merged values.
698  */
699 static void *x_merge_dir_config(apr_pool_t *p, void *parent_conf,
700                                       void *newloc_conf)
701 {
702
703     x_cfg *merged_config = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
704     x_cfg *pconf = (x_cfg *) parent_conf;
705     x_cfg *nconf = (x_cfg *) newloc_conf;
706     char *note;
707
708     /*
709      * Some things get copied directly from the more-specific record, rather
710      * than getting merged.
711      */
712     merged_config->local = nconf->local;
713     merged_config->loc = apr_pstrdup(p, nconf->loc);
714     /*
715      * Others, like the setting of the `congenital' flag, get ORed in.  The
716      * setting of that particular flag, for instance, is TRUE if it was ever
717      * true anywhere in the upstream configuration.
718      */
719     merged_config->congenital = (pconf->congenital | pconf->local);
720     /*
721      * If we're merging records for two different types of environment (server
722      * and directory), mark the new record appropriately.  Otherwise, inherit
723      * the current value.
724      */
725     merged_config->cmode =
726         (pconf->cmode == nconf->cmode) ? pconf->cmode : CONFIG_MODE_COMBO;
727     /*
728      * Now just record our being called in the trace list.  Include the
729      * locations we were asked to merge.
730      */
731     note = apr_pstrcat(p, "x_merge_dir_config(\"", pconf->loc, "\",\"",
732                    nconf->loc, "\")", NULL);
733     trace_add(NULL, NULL, merged_config, note);
734     return (void *) merged_config;
735 }
736
737 /*
738  * This function gets called to create a per-server configuration
739  * record.  It will always be called for the "default" server.
740  *
741  * The return value is a pointer to the created module-specific
742  * structure.
743  */
744 static void *x_create_server_config(apr_pool_t *p, server_rec *s)
745 {
746
747     x_cfg *cfg;
748     char *sname = s->server_hostname;
749
750     /*
751      * As with the x_create_dir_config() reoutine, we allocate and fill
752      * in an empty record.
753      */
754     cfg = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
755     cfg->local = 0;
756     cfg->congenital = 0;
757     cfg->cmode = CONFIG_MODE_SERVER;
758     /*
759      * Note that we were called in the trace list.
760      */
761     sname = (sname != NULL) ? sname : "";
762     cfg->loc = apr_pstrcat(p, "SVR(", sname, ")", NULL);
763     trace_add(s, NULL, cfg, "x_create_server_config()");
764     return (void *) cfg;
765 }
766
767 /*
768  * This function gets called to merge two per-server configuration
769  * records.  This is typically done to cope with things like virtual hosts and
770  * the default server configuration  The routine has the responsibility of
771  * creating a new record and merging the contents of the other two into it
772  * appropriately.  If the module doesn't declare a merge routine, the more
773  * specific existing record is used exclusively.
774  *
775  * The routine MUST NOT modify any of its arguments!
776  *
777  * The return value is a pointer to the created module-specific structure
778  * containing the merged values.
779  */
780 static void *x_merge_server_config(apr_pool_t *p, void *server1_conf,
781                                          void *server2_conf)
782 {
783
784     x_cfg *merged_config = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
785     x_cfg *s1conf = (x_cfg *) server1_conf;
786     x_cfg *s2conf = (x_cfg *) server2_conf;
787     char *note;
788
789     /*
790      * Our inheritance rules are our own, and part of our module's semantics.
791      * Basically, just note whence we came.
792      */
793     merged_config->cmode =
794         (s1conf->cmode == s2conf->cmode) ? s1conf->cmode : CONFIG_MODE_COMBO;
795     merged_config->local = s2conf->local;
796     merged_config->congenital = (s1conf->congenital | s1conf->local);
797     merged_config->loc = apr_pstrdup(p, s2conf->loc);
798     /*
799      * Trace our call, including what we were asked to merge.
800      */
801     note = apr_pstrcat(p, "x_merge_server_config(\"", s1conf->loc, "\",\"",
802                    s2conf->loc, "\")", NULL);
803     trace_add(NULL, NULL, merged_config, note);
804     return (void *) merged_config;
805 }
806
807 /*
808  * This routine is called before the server processes the configuration
809  * files.  There is no return value.
810  */
811 static int x_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
812                         apr_pool_t *ptemp)
813 {
814     /*
815      * Log the call and exit.
816      */
817     trace_add(NULL, NULL, NULL, "x_pre_config()");
818
819     return OK;
820 }
821
822 /*
823  * This routine is called to perform any module-specific fixing of header
824  * fields, et cetera.  It is invoked just before any content-handler.
825  *
826  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
827  * server will still call any remaining modules with an handler for this
828  * phase.
829  */
830 static int x_post_config(apr_pool_t *pconf, apr_pool_t *plog,
831                           apr_pool_t *ptemp, server_rec *s)
832 {
833     /*
834      * Log the call and exit.
835      */
836     trace_add(NULL, NULL, NULL, "x_post_config()");
837     return OK;
838 }
839
840 /*
841  * This routine is called to perform any module-specific log file
842  * openings. It is invoked just before the post_config phase
843  *
844  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
845  * server will still call any remaining modules with an handler for this
846  * phase.
847  */
848 static int x_open_logs(apr_pool_t *pconf, apr_pool_t *plog,
849                         apr_pool_t *ptemp, server_rec *s)
850 {
851     /*
852      * Log the call and exit.
853      */
854     trace_add(s, NULL, NULL, "x_open_logs()");
855     return OK;
856 }
857
858 /*
859  * All our process-death routine does is add its trace to the log.
860  */
861 static apr_status_t x_child_exit(void *data)
862 {
863     char *note;
864     server_rec *s = data;
865     char *sname = s->server_hostname;
866
867     /*
868      * The arbitrary text we add to our trace entry indicates for which server
869      * we're being called.
870      */
871     sname = (sname != NULL) ? sname : "";
872     note = apr_pstrcat(s->process->pool, "x_child_exit(", sname, ")", NULL);
873     trace_add(s, NULL, NULL, note);
874     return APR_SUCCESS;
875 }
876
877 /*
878  * All our process initialiser does is add its trace to the log.
879  */
880 static void x_child_init(apr_pool_t *p, server_rec *s)
881 {
882     char *note;
883     char *sname = s->server_hostname;
884
885     /*
886      * Set up any module cells that ought to be initialised.
887      */
888     setup_module_cells();
889     /*
890      * The arbitrary text we add to our trace entry indicates for which server
891      * we're being called.
892      */
893     sname = (sname != NULL) ? sname : "";
894     note = apr_pstrcat(p, "x_child_init(", sname, ")", NULL);
895     trace_add(s, NULL, NULL, note);
896
897     apr_pool_cleanup_register(p, s, x_child_exit, x_child_exit);
898 }
899
900 /*
901  * XXX: This routine is called XXX
902  *
903  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
904  * server will still call any remaining modules with an handler for this
905  * phase.
906  */
907 #if 0
908 static const char *x_http_method(const request_rec *r)
909 {
910     x_cfg *cfg;
911
912     cfg = our_dconfig(r);
913     /*
914      * Log the call and exit.
915      */
916     trace_add(r->server, NULL, cfg, "x_http_method()");
917     return "foo";
918 }
919
920 /*
921  * XXX: This routine is called XXX
922  *
923  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
924  * server will still call any remaining modules with an handler for this
925  * phase.
926  */
927 static apr_port_t x_default_port(const request_rec *r)
928 {
929     x_cfg *cfg;
930
931     cfg = our_dconfig(r);
932     /*
933      * Log the call and exit.
934      */
935     trace_add(r->server, NULL, cfg, "x_default_port()");
936     return 80;
937 }
938 #endif /*0*/
939
940 /*
941  * XXX: This routine is called XXX
942  *
943  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
944  * server will still call any remaining modules with an handler for this
945  * phase.
946  */
947 static void x_insert_filter(request_rec *r)
948 {
949     x_cfg *cfg;
950
951     cfg = our_dconfig(r);
952     /*
953      * Log the call and exit.
954      */
955     trace_add(r->server, NULL, cfg, "x_insert_filter()");
956 }
957
958 /*
959  * XXX: This routine is called XXX
960  *
961  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
962  * server will still call any remaining modules with an handler for this
963  * phase.
964  */
965 static int x_quick_handler(request_rec *r, int lookup_uri)
966 {
967     x_cfg *cfg;
968
969     cfg = our_dconfig(r);
970     /*
971      * Log the call and exit.
972      */
973     trace_add(r->server, NULL, cfg, "x_post_config()");
974     return DECLINED;
975 }
976
977 /*
978  * This routine is called just after the server accepts the connection,
979  * but before it is handed off to a protocol module to be served.  The point
980  * of this hook is to allow modules an opportunity to modify the connection
981  * as soon as possible. The core server uses this phase to setup the
982  * connection record based on the type of connection that is being used.
983  *
984  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
985  * server will still call any remaining modules with an handler for this
986  * phase.
987  */
988 static int x_pre_connection(conn_rec *c, void *csd)
989 {
990     x_cfg *cfg;
991
992     cfg = our_cconfig(c);
993 #if 0
994     /*
995      * Log the call and exit.
996      */
997     trace_add(r->server, NULL, cfg, "x_post_config()");
998 #endif
999     return OK;
1000 }
1001
1002 /* This routine is used to actually process the connection that was received.
1003  * Only protocol modules should implement this hook, as it gives them an
1004  * opportunity to replace the standard HTTP processing with processing for
1005  * some other protocol.  Both echo and POP3 modules are available as
1006  * examples.
1007  *
1008  * The return VALUE is OK, DECLINED, or HTTP_mumble.  If we return OK, no 
1009  * further modules are called for this phase.
1010  */
1011 static int x_process_connection(conn_rec *c)
1012 {
1013     return DECLINED;
1014 }
1015
1016 /*
1017  * This routine is called after the request has been read but before any other
1018  * phases have been processed.  This allows us to make decisions based upon
1019  * the input header fields.
1020  *
1021  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
1022  * further modules are called for this phase.
1023  */
1024 static int x_post_read_request(request_rec *r)
1025 {
1026     x_cfg *cfg;
1027
1028     cfg = our_dconfig(r);
1029     /*
1030      * We don't actually *do* anything here, except note the fact that we were
1031      * called.
1032      */
1033     trace_add(r->server, r, cfg, "x_post_read_request()");
1034     return DECLINED;
1035 }
1036
1037 /*
1038  * This routine gives our module an opportunity to translate the URI into an
1039  * actual filename.  If we don't do anything special, the server's default
1040  * rules (Alias directives and the like) will continue to be followed.
1041  *
1042  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
1043  * further modules are called for this phase.
1044  */
1045 static int x_translate_handler(request_rec *r)
1046 {
1047
1048     x_cfg *cfg;
1049
1050     cfg = our_dconfig(r);
1051     /*
1052      * We don't actually *do* anything here, except note the fact that we were
1053      * called.
1054      */
1055     trace_add(r->server, r, cfg, "x_translate_handler()");
1056     return DECLINED;
1057 }
1058
1059 /*
1060  * this routine gives our module another chance to examine the request
1061  * headers and to take special action. This is the first phase whose
1062  * hooks' configuration directives can appear inside the <Directory>
1063  * and similar sections, because at this stage the URI has been mapped
1064  * to the filename. For example this phase can be used to block evil
1065  * clients, while little resources were wasted on these.
1066  *
1067  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK,
1068  * the server will still call any remaining modules with an handler
1069  * for this phase.
1070  */
1071 static int x_header_parser_handler(request_rec *r)
1072 {
1073
1074     x_cfg *cfg;
1075
1076     cfg = our_dconfig(r);
1077     /*
1078      * We don't actually *do* anything here, except note the fact that we were
1079      * called.
1080      */
1081     trace_add(r->server, r, cfg, "header_parser_handler()");
1082     return DECLINED;
1083 }
1084
1085
1086 /*
1087  * This routine is called to check the authentication information sent with
1088  * the request (such as looking up the user in a database and verifying that
1089  * the [encrypted] password sent matches the one in the database).
1090  *
1091  * The return value is OK, DECLINED, or some HTTP_mumble error (typically
1092  * HTTP_UNAUTHORIZED).  If we return OK, no other modules are given a chance
1093  * at the request during this phase.
1094  */
1095 static int x_check_user_id(request_rec *r)
1096 {
1097
1098     x_cfg *cfg;
1099
1100     cfg = our_dconfig(r);
1101     /*
1102      * Don't do anything except log the call.
1103      */
1104     trace_add(r->server, r, cfg, "x_check_user_id()");
1105     return DECLINED;
1106 }
1107
1108 /*
1109  * This routine is called to check to see if the resource being requested
1110  * requires authorisation.
1111  *
1112  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
1113  * other modules are called during this phase.
1114  *
1115  * If *all* modules return DECLINED, the request is aborted with a server
1116  * error.
1117  */
1118 static int x_auth_checker(request_rec *r)
1119 {
1120
1121     x_cfg *cfg;
1122
1123     cfg = our_dconfig(r);
1124     /*
1125      * Log the call and return OK, or access will be denied (even though we
1126      * didn't actually do anything).
1127      */
1128     trace_add(r->server, r, cfg, "x_auth_checker()");
1129     return DECLINED;
1130 }
1131
1132 /*
1133  * This routine is called to check for any module-specific restrictions placed
1134  * upon the requested resource.  (See the mod_access module for an example.)
1135  *
1136  * The return value is OK, DECLINED, or HTTP_mumble.  All modules with an
1137  * handler for this phase are called regardless of whether their predecessors
1138  * return OK or DECLINED.  The first one to return any other status, however,
1139  * will abort the sequence (and the request) as usual.
1140  */
1141 static int x_access_checker(request_rec *r)
1142 {
1143
1144     x_cfg *cfg;
1145
1146     cfg = our_dconfig(r);
1147     trace_add(r->server, r, cfg, "x_access_checker()");
1148     return DECLINED;
1149 }
1150
1151 /*
1152  * This routine is called to determine and/or set the various document type
1153  * information bits, like Content-type (via r->content_type), language, et
1154  * cetera.
1155  *
1156  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, no
1157  * further modules are given a chance at the request for this phase.
1158  */
1159 static int x_type_checker(request_rec *r)
1160 {
1161
1162     x_cfg *cfg;
1163
1164     cfg = our_dconfig(r);
1165     /*
1166      * Log the call, but don't do anything else - and report truthfully that
1167      * we didn't do anything.
1168      */
1169     trace_add(r->server, r, cfg, "x_type_checker()");
1170     return DECLINED;
1171 }
1172
1173 /*
1174  * This routine is called to perform any module-specific fixing of header
1175  * fields, et cetera.  It is invoked just before any content-handler.
1176  *
1177  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, the
1178  * server will still call any remaining modules with an handler for this
1179  * phase.
1180  */
1181 static int x_fixer_upper(request_rec *r)
1182 {
1183
1184     x_cfg *cfg;
1185
1186     cfg = our_dconfig(r);
1187     /*
1188      * Log the call and exit.
1189      */
1190     trace_add(r->server, r, cfg, "x_fixer_upper()");
1191     return OK;
1192 }
1193
1194 /*
1195  * This routine is called to perform any module-specific logging activities
1196  * over and above the normal server things.
1197  *
1198  * The return value is OK, DECLINED, or HTTP_mumble.  If we return OK, any
1199  * remaining modules with an handler for this phase will still be called.
1200  */
1201 static int x_logger(request_rec *r)
1202 {
1203
1204     x_cfg *cfg;
1205
1206     cfg = our_dconfig(r);
1207     trace_add(r->server, r, cfg, "x_logger()");
1208     return DECLINED;
1209 }
1210
1211 /*--------------------------------------------------------------------------*/
1212 /*                                                                          */
1213 /* Which functions are responsible for which hooks in the server.           */
1214 /*                                                                          */
1215 /*--------------------------------------------------------------------------*/
1216 /* 
1217  * Each function our module provides to handle a particular hook is
1218  * specified here.  The functions are registered using 
1219  * ap_hook_foo(name, predecessors, successors, position)
1220  * where foo is the name of the hook.
1221  *
1222  * The args are as follows:
1223  * name         -> the name of the function to call.
1224  * predecessors -> a list of modules whose calls to this hook must be
1225  *                 invoked before this module.
1226  * successors   -> a list of modules whose calls to this hook must be
1227  *                 invoked after this module.
1228  * position     -> The relative position of this module.  One of
1229  *                 APR_HOOK_FIRST, APR_HOOK_MIDDLE, or APR_HOOK_LAST.
1230  *                 Most modules will use APR_HOOK_MIDDLE.  If multiple
1231  *                 modules use the same relative position, Apache will
1232  *                 determine which to call first.
1233  *                 If your module relies on another module to run first,
1234  *                 or another module running after yours, use the 
1235  *                 predecessors and/or successors.
1236  *
1237  * The number in brackets indicates the order in which the routine is called
1238  * during request processing.  Note that not all routines are necessarily
1239  * called (such as if a resource doesn't have access restrictions).
1240  * The actual delivery of content to the browser [9] is not handled by
1241  * a hook; see the handler declarations below.
1242  */
1243 static void x_register_hooks(apr_pool_t *p)
1244 {
1245     ap_hook_pre_config(x_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
1246     ap_hook_post_config(x_post_config, NULL, NULL, APR_HOOK_MIDDLE);
1247     ap_hook_open_logs(x_open_logs, NULL, NULL, APR_HOOK_MIDDLE);
1248     ap_hook_child_init(x_child_init, NULL, NULL, APR_HOOK_MIDDLE);
1249     ap_hook_handler(x_handler, NULL, NULL, APR_HOOK_MIDDLE);
1250     ap_hook_quick_handler(x_quick_handler, NULL, NULL, APR_HOOK_MIDDLE);
1251     ap_hook_pre_connection(x_pre_connection, NULL, NULL, APR_HOOK_MIDDLE);
1252     ap_hook_process_connection(x_process_connection, NULL, NULL, APR_HOOK_MIDDLE);
1253     /* [1] post read_request handling */
1254     ap_hook_post_read_request(x_post_read_request, NULL, NULL,
1255                               APR_HOOK_MIDDLE);
1256     ap_hook_log_transaction(x_logger, NULL, NULL, APR_HOOK_MIDDLE);
1257 #if 0
1258     ap_hook_http_method(x_http_method, NULL, NULL, APR_HOOK_MIDDLE);
1259     ap_hook_default_port(x_default_port, NULL, NULL, APR_HOOK_MIDDLE);
1260 #endif
1261     ap_hook_translate_name(x_translate_handler, NULL, NULL, APR_HOOK_MIDDLE);
1262     ap_hook_header_parser(x_header_parser_handler, NULL, NULL, APR_HOOK_MIDDLE);
1263     ap_hook_check_user_id(x_check_user_id, NULL, NULL, APR_HOOK_MIDDLE);
1264     ap_hook_fixups(x_fixer_upper, NULL, NULL, APR_HOOK_MIDDLE);
1265     ap_hook_type_checker(x_type_checker, NULL, NULL, APR_HOOK_MIDDLE);
1266     ap_hook_access_checker(x_access_checker, NULL, NULL, APR_HOOK_MIDDLE);
1267     ap_hook_auth_checker(x_auth_checker, NULL, NULL, APR_HOOK_MIDDLE);
1268     ap_hook_insert_filter(x_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
1269 }
1270
1271 /*--------------------------------------------------------------------------*/
1272 /*                                                                          */
1273 /* All of the routines have been declared now.  Here's the list of          */
1274 /* directives specific to our module, and information about where they      */
1275 /* may appear and how the command parser should pass them to us for         */
1276 /* processing.  Note that care must be taken to ensure that there are NO    */
1277 /* collisions of directive names between modules.                           */
1278 /*                                                                          */
1279 /*--------------------------------------------------------------------------*/
1280 /* 
1281  * List of directives specific to our module.
1282  */
1283 static const command_rec x_cmds[] =
1284 {
1285     AP_INIT_NO_ARGS(
1286         "Example",                          /* directive name */
1287         cmd_example,                        /* config action routine */
1288         NULL,                               /* argument to include in call */
1289         OR_OPTIONS,                         /* where available */
1290         "Example directive - no arguments"  /* directive description */
1291     ),
1292     {NULL}
1293 };
1294 /*--------------------------------------------------------------------------*/
1295 /*                                                                          */
1296 /* Finally, the list of callback routines and data structures that provide  */
1297 /* the static hooks into our module from the other parts of the server.     */
1298 /*                                                                          */
1299 /*--------------------------------------------------------------------------*/
1300 /* 
1301  * Module definition for configuration.  If a particular callback is not
1302  * needed, replace its routine name below with the word NULL.
1303  */
1304 module AP_MODULE_DECLARE_DATA example_module =
1305 {
1306     STANDARD20_MODULE_STUFF,
1307     x_create_dir_config,    /* per-directory config creator */
1308     x_merge_dir_config,     /* dir config merger */
1309     x_create_server_config, /* server config creator */
1310     x_merge_server_config,  /* server config merger */
1311     x_cmds,                 /* command table */
1312     x_register_hooks,       /* set up other request processing hooks */
1313 };