2 ## | ____| / \ | _ \_ _|
3 ## | _| / _ \ | |_) | |
4 ## | |__ / ___ \| __/| |
5 ## |____/_/ \_\_| |___| Extended API for Apache
6 ## ____________________________________________________________________________
8 ## Annotated patch file: eapi.patch
9 ## Copyright (c) 1998-2001 Ralf S. Engelschall, All Rights Reserved.
10 ## Created on: 18-Mar-2003
12 ## This file assembles changes to existing Apache source files
13 ## between the original Apache and the patched variant. It can be
14 ## automatically applied to a vanilla Apache source tree with the
15 ## 'patch' tool to upgrade those files. Each patch snippet is
16 ## annotated with a short description.
18 ## This file contains all patches to the Apache source
19 ## tree which add the Extended API (EAPI) support.
22 +---------------------------------------------------------------------------
23 | Add the EAPI and EAPI_MM configuration entries which triggers the EAPI
24 | patches and configured the shared memory support via the MM library.
25 +---------------------------------------------------------------------------
26 Index: src/Configuration.tmpl
27 --- src/Configuration.tmpl 28 Jan 2002 19:21:21 -0000 1.1.1.7
28 +++ src/Configuration.tmpl 28 Jan 2002 19:40:56 -0000 1.23
32 ################################################################
33 +# Extended API (EAPI) support:
36 +# The EAPI rule enables more module hooks, a generic low-level hook
37 +# mechanism, a generic context mechanism and shared memory based pools.
40 +# Set the EAPI_MM variable to either the directory of a MM Shared Memory
41 +# Library source tree or the installation tree of MM. Alternatively you can
42 +# also use the value 'SYSTEM' which then indicates that MM is installed
43 +# under various system locations. When the MM library files cannot be found
44 +# the EAPI still can be built, but without shared memory pool support, of
50 +################################################################
51 # Dynamic Shared Object (DSO) support
53 # There is experimental support for compiling the Apache core and
55 +---------------------------------------------------------------------------
56 | Patch in implementation of the EAPI rule.
57 +---------------------------------------------------------------------------
59 --- src/Configure 4 Oct 2002 11:50:12 -0000 1.1.1.20
60 +++ src/Configure 4 Oct 2002 11:54:56 -0000 1.23
61 @@ -1885,6 +1885,72 @@
64 ####################################################################
65 +## Extended API (EAPI) support:
67 +if [ "x$RULE_EAPI" = "x" ]; then
68 + RULE_EAPI=`./helpers/CutRule EAPI $file`
70 +if [ "x$RULE_EAPI" = "xyes" ]; then
71 + echo " + enabling Extended API (EAPI)"
72 + CFLAGS="$CFLAGS -DEAPI"
73 + # some vendor compilers are too restrictive
74 + # for our ap_hook and ap_ctx sources.
76 + *IRIX-32*:*/cc|*IRIX-32*:cc )
77 + CFLAGS="$CFLAGS -woff 1048,1110,1164"
80 + # MM Shared Memory Library support for EAPI
81 + if [ "x$EAPI_MM" = "x" ]; then
82 + EAPI_MM=`egrep '^EAPI_MM=' $file | sed -n -e '$p' | awk -F= '{print $2}'`
84 + if [ "x$EAPI_MM" != "x" ]; then
87 + * ) for p in . .. ../..; do
88 + if [ -d "$p/$EAPI_MM" ]; then
89 + EAPI_MM="`echo $p/$EAPI_MM | sed -e 's;/\./;/;g'`"
95 + if [ "x$EAPI_MM" = "xSYSTEM" ]; then
96 + echo " using MM library for EAPI: (system-wide)"
97 + CFLAGS="$CFLAGS -DEAPI_MM"
98 + __INCLUDES="`mm-config --cflags`"
99 + if [ "x$__INCLUDES" != "x-I/usr/include" ]; then
100 + INCLUDES="$INCLUDES $__INCLUDES"
102 + LDFLAGS="$LDFLAGS `mm-config --ldflags`"
103 + LIBS="$LIBS `mm-config --libs`"
105 + if [ -f "$EAPI_MM/.libs/libmm.a" -a -f "$EAPI_MM/mm.h" ]; then
106 + echo " using MM library: $EAPI_MM (source-tree only)"
109 + * ) EAPI_MM="\$(SRCDIR)/$EAPI_MM" ;;
111 + CFLAGS="$CFLAGS -DEAPI_MM"
112 + INCLUDES="$INCLUDES -I$EAPI_MM"
113 + LDFLAGS="$LDFLAGS -L$EAPI_MM/.libs"
115 + elif [ -f "$EAPI_MM/bin/mm-config" ]; then
116 + echo " using MM library: $EAPI_MM (installed)"
117 + CFLAGS="$CFLAGS -DEAPI_MM"
118 + INCLUDES="$INCLUDES `$EAPI_MM/bin/mm-config --cflags`"
119 + LDFLAGS="$LDFLAGS `$EAPI_MM/bin/mm-config --ldflags`"
120 + LIBS="$LIBS `$EAPI_MM/bin/mm-config --libs`"
122 + echo "Configure:Error: Cannot find MM library under $EAPI_MM" 1>&2
130 +####################################################################
131 ## Add in the Expat library if needed/wanted.
135 +---------------------------------------------------------------------------
136 | Add the build support for the ap_hook.c and ap_ctx.c sources (Unix)
137 +---------------------------------------------------------------------------
138 Index: src/ap/Makefile.tmpl
139 --- src/ap/Makefile.tmpl 19 Jun 2002 07:20:22 -0000 1.1.1.8
140 +++ src/ap/Makefile.tmpl 19 Jun 2002 07:29:08 -0000 1.8
143 OBJS=ap_cpystrn.o ap_execve.o ap_fnmatch.o ap_getpass.o ap_md5c.o ap_signal.o \
144 ap_slack.o ap_snprintf.o ap_sha1.o ap_checkpass.o ap_base64.o ap_ebcdic.o \
146 + ap_strtol.o ap_hook.o ap_ctx.o ap_mm.o
149 $(CC) -c $(INCLUDES) $(CFLAGS) $<
151 +---------------------------------------------------------------------------
152 | Add the build support for the ap_hook.c and ap_ctx.c sources (Win32)
153 +---------------------------------------------------------------------------
155 --- src/ap/ap.mak 16 Oct 2001 11:47:06 -0000 1.1.1.9
156 +++ src/ap/ap.mak 16 Oct 2001 11:57:38 -0000 1.9
158 -@erase "$(INTDIR)\ap_cpystrn.obj"
159 -@erase "$(INTDIR)\ap_fnmatch.obj"
160 -@erase "$(INTDIR)\ap_md5c.obj"
161 + -@erase "$(INTDIR)\ap_hook.obj"
162 + -@erase "$(INTDIR)\ap_ctx.obj"
163 + -@erase "$(INTDIR)\ap_mm.obj"
164 -@erase "$(INTDIR)\ap_sha1.obj"
165 -@erase "$(INTDIR)\ap_signal.obj"
166 -@erase "$(INTDIR)\ap_slack.obj"
168 "$(INTDIR)\ap_cpystrn.obj" \
169 "$(INTDIR)\ap_fnmatch.obj" \
170 "$(INTDIR)\ap_md5c.obj" \
171 + "$(INTDIR)\ap_hook.obj" \
172 + "$(INTDIR)\ap_ctx.obj" \
173 + "$(INTDIR)\ap_mm.obj" \
174 "$(INTDIR)\ap_sha1.obj" \
175 "$(INTDIR)\ap_signal.obj" \
176 "$(INTDIR)\ap_slack.obj" \
178 -@erase "$(INTDIR)\ap_cpystrn.obj"
179 -@erase "$(INTDIR)\ap_fnmatch.obj"
180 -@erase "$(INTDIR)\ap_md5c.obj"
181 + -@erase "$(INTDIR)\ap_hook.obj"
182 + -@erase "$(INTDIR)\ap_ctx.obj"
183 + -@erase "$(INTDIR)\ap_mm.obj"
184 -@erase "$(INTDIR)\ap_sha1.obj"
185 -@erase "$(INTDIR)\ap_signal.obj"
186 -@erase "$(INTDIR)\ap_slack.obj"
188 "$(INTDIR)\ap_cpystrn.obj" \
189 "$(INTDIR)\ap_fnmatch.obj" \
190 "$(INTDIR)\ap_md5c.obj" \
191 + "$(INTDIR)\ap_hook.obj" \
192 + "$(INTDIR)\ap_ctx.obj" \
193 + "$(INTDIR)\ap_mm.obj" \
194 "$(INTDIR)\ap_sha1.obj" \
195 "$(INTDIR)\ap_signal.obj" \
196 "$(INTDIR)\ap_slack.obj" \
198 +---------------------------------------------------------------------------
199 | Replace the MODULE_MAGIC_COOKIE to allow us to distinguish between
200 | EAPI-aware modules and standard modules.
201 +---------------------------------------------------------------------------
202 Index: src/include/ap_mmn.h
203 --- src/include/ap_mmn.h 19 Jun 2002 07:20:24 -0000 1.1.1.11
204 +++ src/include/ap_mmn.h 19 Jun 2002 07:29:08 -0000 1.11
206 * 19990320.13 - add ap_strtol()
210 + * Under Extended API situations we replace the magic cookie "AP13" with
211 + * "EAPI" to let us distinguish between the EAPI module structure (which
212 + * contain additional pointers at the end) and standard module structures
213 + * (which lack at least NULL's for the pointers at the end). This is
214 + * important because standard ("AP13") modules would dump core when we
215 + * dispatch over the additional hooks because NULL's are missing at the end of
216 + * the module structure. See also the code in mod_so for details on loading
217 + * (we accept both "AP13" and "EAPI").
220 +#define MODULE_MAGIC_COOKIE_AP13 0x41503133UL /* "AP13" */
221 +#define MODULE_MAGIC_COOKIE_EAPI 0x45415049UL /* "EAPI" */
222 +#define MODULE_MAGIC_COOKIE MODULE_MAGIC_COOKIE_EAPI
224 #define MODULE_MAGIC_COOKIE 0x41503133UL /* "AP13" */
227 #ifndef MODULE_MAGIC_NUMBER_MAJOR
228 #define MODULE_MAGIC_NUMBER_MAJOR 19990320
230 +---------------------------------------------------------------------------
231 | Add the additional prototypes and defines for the
232 | shared memory pools.
233 +---------------------------------------------------------------------------
234 Index: src/include/ap_alloc.h
235 --- src/include/ap_alloc.h 27 Mar 2002 15:22:56 -0000 1.1.1.5
236 +++ src/include/ap_alloc.h 27 Mar 2002 15:30:02 -0000 1.6
238 API_EXPORT(pool *) ap_init_alloc(void); /* Set up everything */
239 void ap_cleanup_alloc(void);
240 API_EXPORT(pool *) ap_make_sub_pool(pool *); /* All pools are subpools of permanent_pool */
242 +typedef enum { AP_POOL_RD, AP_POOL_RW } ap_pool_lock_mode;
243 +int ap_shared_pool_possible(void);
244 +void ap_init_alloc_shared(int);
245 +void ap_kill_alloc_shared(void);
246 +API_EXPORT(pool *) ap_make_shared_sub_pool(pool *);
247 +API_EXPORT(int) ap_acquire_pool(pool *, ap_pool_lock_mode);
248 +API_EXPORT(int) ap_release_pool(pool *);
250 API_EXPORT(void) ap_destroy_pool(pool *);
252 /* pools have nested lifetimes -- sub_pools are destroyed when the
254 +---------------------------------------------------------------------------
255 | Add the additional context variable `ctx' for BUFF structures.
256 +---------------------------------------------------------------------------
257 Index: src/include/buff.h
258 --- src/include/buff.h 27 Mar 2002 15:22:57 -0000 1.1.1.6
259 +++ src/include/buff.h 27 Mar 2002 15:30:02 -0000 1.10
261 /* transport handle, for RPC binding handle or some such */
272 /* Internal routines */
273 API_EXPORT(int) ap_bflsbuf(int c, BUFF *fb);
274 API_EXPORT(int) ap_bfilbuf(BUFF *fb);
277 +#define ap_bpeekc(fb) ( ((fb)->incnt == 0) ? EOF : *((fb)->inptr) )
280 #ifndef CHARSET_EBCDIC
283 +---------------------------------------------------------------------------
284 | Add the four additional Apache API module hooks.
285 +---------------------------------------------------------------------------
286 Index: src/include/http_config.h
287 --- src/include/http_config.h 27 Mar 2002 15:22:57 -0000 1.1.1.10
288 +++ src/include/http_config.h 27 Mar 2002 15:30:02 -0000 1.12
290 void (*child_exit) (server_rec *, pool *);
292 int (*post_read_request) (request_rec *);
296 + * ANSI C guarantees us that we can at least _extend_ the module structure
297 + * with additional hooks without the need to change all existing modules.
298 + * Because: ``If there are fewer initializers in the list than members of
299 + * the structure, the trailing members are initialized with 0.'' (The C
300 + * Programming Language, 2nd Ed., A8.7 Initialization). So we just
301 + * have to put our additional hooks here:
304 + * Called from within ap_add_module() right after the module structure
305 + * was linked into the Apache internal module list. It is mainly
306 + * intended to be used to define configuration defines (<IfDefine>)
307 + * which have to be available directly after a LoadModule/AddModule.
308 + * Actually this is the earliest possible hook a module can use.
311 + * Called from within ap_remove_module() right before the module
312 + * structure is kicked out from the Apache internal module list.
313 + * Actually this is last possible hook a module can use and exists for
314 + * consistency with the add_module hook.
317 + * Called right after a configuration directive line was read and
318 + * before it is processed. It is mainly intended to be used for
319 + * rewriting directives in order to provide backward compatibility to
320 + * old directive variants.
323 + * Called from within the internal new_connection() function, right
324 + * after the conn_rec structure for the new established connection was
325 + * created and before Apache starts processing the request with
326 + * ap_read_request(). It is mainly intended to be used to setup/run
327 + * connection dependent things like sending start headers for
328 + * on-the-fly compression, etc.
330 + * close_connection:
331 + * Called from within the Apache dispatching loop just before any
332 + * ap_bclose() is performed on the socket connection, but a long time
333 + * before any pool cleanups are done for the connection (which can be
334 + * too late for some applications). It is mainly intended to be used
335 + * to close/finalize connection dependent things like sending end
336 + * headers for on-the-fly compression, etc.
338 +#ifdef ULTRIX_BRAIN_DEATH
339 + void (*add_module) ();
340 + void (*remove_module) ();
341 + char *(*rewrite_command) ();
342 + void (*new_connection) ();
343 + void (*close_connection) ();
345 + void (*add_module) (struct module_struct *);
346 + void (*remove_module) (struct module_struct *);
347 + char *(*rewrite_command) (cmd_parms *, void *config, const char *);
348 + void (*new_connection) (conn_rec *);
349 + void (*close_connection) (conn_rec *);
354 /* Initializer for the first few module slots, which are only
356 +---------------------------------------------------------------------------
357 | Add the additional variable `ap_global_ctx' for holding
358 | global module context.
359 +---------------------------------------------------------------------------
360 Index: src/include/http_conf_globals.h
361 --- src/include/http_conf_globals.h 4 Oct 2002 11:50:14 -0000 1.1.1.12
362 +++ src/include/http_conf_globals.h 4 Oct 2002 11:54:56 -0000 1.13
365 extern int ap_dump_settings;
366 extern API_VAR_EXPORT int ap_extended_status;
368 +extern API_VAR_EXPORT ap_ctx *ap_global_ctx;
371 extern API_VAR_EXPORT char *ap_pid_fname;
372 extern API_VAR_EXPORT char *ap_scoreboard_fname;
374 +---------------------------------------------------------------------------
375 | Export the ap_set_callback_and_alarm() function because this
376 | first is a useful thing and second we need it because all
377 | other API/timeout functions deal with a request_rec while
378 | some modules need a generic timeout mechanism.
379 +---------------------------------------------------------------------------
380 Index: src/include/http_main.h
382 +---------------------------------------------------------------------------
383 | First add support for the HTTPS protocol scheme via hooks,
384 | second add the additional context variable `ctx' for the
385 | conn_rec, server_rec and request_rec structures. And third
386 | add a prototype for the additional ap_add_config_define()
388 +---------------------------------------------------------------------------
389 Index: src/include/httpd.h
390 --- src/include/httpd.h 4 Oct 2002 11:50:14 -0000 1.1.1.20
391 +++ src/include/httpd.h 4 Oct 2002 11:54:56 -0000 1.30
393 /* Headers in which EVERYONE has an interest... */
395 #include "ap_config.h"
399 #include "ap_alloc.h"
401 + * Include the Extended API headers.
402 + * Don't move the position. It has to be after ap_alloc.h because it uses the
403 + * pool stuff but before buff.h because the buffer stuff uses the EAPI, too.
406 +#include "ap_hook.h"
412 @@ -141,12 +153,17 @@
413 #define DEFAULT_HTTP_PORT 80
414 #define DEFAULT_HTTPS_PORT 443
415 #define ap_is_default_port(port,r) ((port) == ap_default_port(r))
417 +#define ap_http_method(r) (((r)->ctx != NULL && ap_ctx_get((r)->ctx, "ap::http::method") != NULL) ? ((char *)ap_ctx_get((r)->ctx, "ap::http::method")) : "http")
418 +#define ap_default_port(r) (((r)->ctx != NULL && ap_ctx_get((r)->ctx, "ap::default::port") != NULL) ? atoi((char *)ap_ctx_get((r)->ctx, "ap::default::port")) : DEFAULT_HTTP_PORT)
421 #define ap_http_method(r) ap_os_http_method(r)
423 #define ap_http_method(r) "http"
425 #define ap_default_port(r) DEFAULT_HTTP_PORT
428 /* --------- Default user name and group name running standalone ---------- */
429 /* --- These may be specified as numbers by placing a # before a number --- */
431 #define SCOREBOARD_MAINTENANCE_INTERVAL 1000000
436 + * Path to Shared Memory Files
439 +#ifndef EAPI_MM_CORE_PATH
440 +#define EAPI_MM_CORE_PATH "logs/mm"
442 +#ifndef EAPI_MM_CORE_MAXSIZE
443 +#define EAPI_MM_CORE_MAXSIZE 1024*1024*1 /* max. 1MB */
447 /* Number of requests to try to handle in a single process. If <= 0,
448 * the children don't die off. That's the default here, since I'm still
449 * interested in finding and stanching leaks.
451 API_EXPORT(const char *) ap_get_server_version(void);
452 API_EXPORT(void) ap_add_version_component(const char *component);
453 API_EXPORT(const char *) ap_get_server_built(void);
455 +API_EXPORT(void) ap_add_config_define(const char *define);
458 /* Numeric release version identifier: MMNNFFRBB: major minor fix final beta
459 * Always increases along the same track as the source branch.
461 * record to improve 64bit alignment the next time we need to break
462 * binary compatibility for some other reason.
472 char *local_host; /* used for ap_get_server_name when
473 * UseCanonicalName is set to DNS
474 * (ignores setting of HostnameLookups) */
480 /* Per-vhost config... */
481 @@ -966,6 +1006,10 @@
482 int limit_req_line; /* limit on size of the HTTP request line */
483 int limit_req_fieldsize; /* limit on size of any request header field */
484 int limit_req_fields; /* limit on number of request header fields */
491 /* These are more like real hosts than virtual hosts */
493 +---------------------------------------------------------------------------
494 | Patch the shared memory pool support into the Apache pool facility.
495 +---------------------------------------------------------------------------
496 Index: src/main/alloc.c
497 --- src/main/alloc.c 4 Oct 2002 11:50:14 -0000 1.1.1.13
498 +++ src/main/alloc.c 7 Mar 2003 13:45:51 -0000 1.21
504 +#include "http_config.h"
505 +#include "http_conf_globals.h"
507 #include "multithread.h"
508 #include "http_log.h"
511 #define BLOCK_MINALLOC 0
514 +#if defined(EAPI) && defined(EAPI_MM)
515 +static AP_MM *mm = NULL;
518 /*****************************************************************
520 * Managing free storage blocks...
523 union block_hdr *next;
525 +#if defined(EAPI) && defined(EAPI_MM)
529 union block_hdr *global_next;
530 struct pool *owning_pool;
532 /* Get a completely new block from the system pool. Note that we rely on
533 malloc() to provide aligned memory. */
535 +#if defined(EAPI) && defined(EAPI_MM)
536 +static union block_hdr *malloc_block(int size, int is_shm)
538 static union block_hdr *malloc_block(int size)
541 union block_hdr *blok;
543 @@ -230,12 +245,20 @@
545 num_malloc_bytes += size + sizeof(union block_hdr);
547 +#if defined(EAPI) && defined(EAPI_MM)
549 + blok = (union block_hdr *)ap_mm_malloc(mm, size + sizeof(union block_hdr));
552 blok = (union block_hdr *) malloc(size + sizeof(union block_hdr));
554 fprintf(stderr, "Ouch! malloc failed in malloc_block()\n");
557 debug_fill(blok, size + sizeof(union block_hdr));
558 +#if defined(EAPI) && defined(EAPI_MM)
559 + blok->h.is_shm = is_shm;
562 blok->h.first_avail = (char *) (blok + 1);
563 blok->h.endp = size + blok->h.first_avail;
566 return; /* Sanity check --- freeing empty pool? */
568 +#if defined(EAPI) && defined(EAPI_MM)
569 + if (blok->h.is_shm)
570 + (void)ap_mm_lock(mm, AP_MM_LOCK_RW);
572 (void) ap_acquire_mutex(alloc_mutex);
573 old_free_list = block_freelist;
574 block_freelist = blok;
578 (void) ap_release_mutex(alloc_mutex);
579 +#if defined(EAPI) && defined(EAPI_MM)
580 + if (blok->h.is_shm)
581 + (void)ap_mm_unlock(mm);
587 * if necessary. Must be called with alarms blocked.
590 +#if defined(EAPI) && defined(EAPI_MM)
591 +static union block_hdr *new_block(int min_size, int is_shm)
593 static union block_hdr *new_block(int min_size)
596 union block_hdr **lastptr = &block_freelist;
597 union block_hdr *blok = block_freelist;
601 while (blok != NULL) {
602 +#if defined(EAPI) && defined(EAPI_MM)
603 + if (blok->h.is_shm == is_shm &&
604 + min_size + BLOCK_MINFREE <= blok->h.endp - blok->h.first_avail) {
606 if (min_size + BLOCK_MINFREE <= blok->h.endp - blok->h.first_avail) {
608 *lastptr = blok->h.next;
610 debug_verify_filled(blok->h.first_avail, blok->h.endp,
614 min_size += BLOCK_MINFREE;
615 +#if defined(EAPI) && defined(EAPI_MM)
616 + blok = malloc_block((min_size > BLOCK_MINALLOC) ? min_size : BLOCK_MINALLOC, is_shm);
618 blok = malloc_block((min_size > BLOCK_MINALLOC) ? min_size : BLOCK_MINALLOC);
627 +#if defined(EAPI) && defined(EAPI_MM)
632 static pool *permanent_pool;
633 @@ -440,16 +487,28 @@
634 #define POOL_HDR_CLICKS (1 + ((sizeof(struct pool) - 1) / CLICK_SZ))
635 #define POOL_HDR_BYTES (POOL_HDR_CLICKS * CLICK_SZ)
637 +#if defined(EAPI) && defined(EAPI_MM)
638 +static struct pool *make_sub_pool_internal(struct pool *p, int is_shm)
640 API_EXPORT(struct pool *) ap_make_sub_pool(struct pool *p)
643 union block_hdr *blok;
648 +#if defined(EAPI) && defined(EAPI_MM)
650 + (void)ap_mm_lock(mm, AP_MM_LOCK_RW);
652 (void) ap_acquire_mutex(alloc_mutex);
654 +#if defined(EAPI) && defined(EAPI_MM)
655 + blok = new_block(POOL_HDR_BYTES, is_shm);
657 blok = new_block(POOL_HDR_BYTES);
659 new_pool = (pool *) blok->h.first_avail;
660 blok->h.first_avail += POOL_HDR_BYTES;
662 @@ -468,12 +527,38 @@
663 p->sub_pools = new_pool;
666 +#if defined(EAPI) && defined(EAPI_MM)
667 + new_pool->is_shm = is_shm;
670 (void) ap_release_mutex(alloc_mutex);
671 +#if defined(EAPI) && defined(EAPI_MM)
673 + (void)ap_mm_unlock(mm);
681 +#if defined(EAPI_MM)
682 +API_EXPORT(struct pool *) ap_make_sub_pool(struct pool *p)
684 + return make_sub_pool_internal(p, 0);
686 +API_EXPORT(struct pool *) ap_make_shared_sub_pool(struct pool *p)
688 + return make_sub_pool_internal(p, 1);
691 +API_EXPORT(struct pool *) ap_make_shared_sub_pool(struct pool *p)
699 static void stack_var_init(char *s)
706 +int ap_shared_pool_possible(void)
708 + return ap_mm_useable();
713 static void dump_stats(void)
716 return permanent_pool;
720 +void ap_init_alloc_shared(int early)
722 +#if defined(EAPI_MM)
728 + /* process very early on startup */
729 + mm_size = ap_mm_maxsize();
730 + if (mm_size > EAPI_MM_CORE_MAXSIZE)
731 + mm_size = EAPI_MM_CORE_MAXSIZE;
732 + mm_path = ap_server_root_relative(permanent_pool,
733 + ap_psprintf(permanent_pool, "%s.%ld",
734 + EAPI_MM_CORE_PATH, (long)getpid()));
735 + if ((mm = ap_mm_create(mm_size, mm_path)) == NULL) {
736 + fprintf(stderr, "Ouch! ap_mm_create(%d, \"%s\") failed\n", mm_size, mm_path);
737 + err1 = ap_mm_error();
739 + err1 = "-unknown-";
740 + err2 = strerror(errno);
742 + err2 = "-unknown-";
743 + fprintf(stderr, "Error: MM: %s: OS: %s\n", err1, err2);
748 + /* process a lot later on startup */
750 + ap_mm_permission(mm, (_S_IREAD|_S_IWRITE), ap_user_id, -1);
752 + ap_mm_permission(mm, (S_IRUSR|S_IWUSR), ap_user_id, -1);
755 +#endif /* EAPI_MM */
759 +void ap_kill_alloc_shared(void)
761 +#if defined(EAPI_MM)
766 +#endif /* EAPI_MM */
771 void ap_cleanup_alloc(void)
773 ap_destroy_mutex(alloc_mutex);
774 @@ -530,10 +674,18 @@
778 +#if defined(EAPI) && defined(EAPI_MM)
780 + (void)ap_mm_lock(mm, AP_MM_LOCK_RW);
782 (void) ap_acquire_mutex(alloc_mutex);
784 ap_destroy_pool(a->sub_pools);
785 (void) ap_release_mutex(alloc_mutex);
786 +#if defined(EAPI) && defined(EAPI_MM)
788 + (void)ap_mm_unlock(mm);
790 /* Don't hold the mutex during cleanups. */
791 run_cleanups(a->cleanups);
797 +#if defined(EAPI) && defined(EAPI_MM)
799 + (void)ap_mm_lock(mm, AP_MM_LOCK_RW);
801 (void) ap_acquire_mutex(alloc_mutex);
803 if (a->parent->sub_pools == a)
805 a->sub_next->sub_prev = a->sub_prev;
807 (void) ap_release_mutex(alloc_mutex);
808 +#if defined(EAPI) && defined(EAPI_MM)
810 + (void)ap_mm_unlock(mm);
813 free_blocks(a->first);
816 return bytes_in_block_list(block_freelist);
820 +API_EXPORT(int) ap_acquire_pool(pool *p, ap_pool_lock_mode mode)
822 +#if defined(EAPI_MM)
825 + return ap_mm_lock(mm, mode == AP_POOL_RD ? AP_MM_LOCK_RD : AP_MM_LOCK_RW);
831 +API_EXPORT(int) ap_release_pool(pool *p)
833 +#if defined(EAPI_MM)
836 + return ap_mm_unlock(mm);
843 /*****************************************************************
846 @@ -756,16 +940,31 @@
850 +#if defined(EAPI) && defined(EAPI_MM)
852 + (void)ap_mm_lock(mm, AP_MM_LOCK_RW);
854 (void) ap_acquire_mutex(alloc_mutex);
856 +#if defined(EAPI) && defined(EAPI_MM)
857 + blok = new_block(size, a->is_shm);
859 blok = new_block(size);
861 a->last->h.next = blok;
864 blok->h.owning_pool = a;
866 +#if defined(EAPI) && defined(EAPI_MM)
867 + blok->h.is_shm = a->is_shm;
870 (void) ap_release_mutex(alloc_mutex);
871 +#if defined(EAPI) && defined(EAPI_MM)
873 + (void)ap_mm_unlock(mm);
878 @@ -882,6 +1081,11 @@
880 if (size < AP_PSPRINTF_MIN_SIZE)
881 size = AP_PSPRINTF_MIN_SIZE;
882 +#if defined(EAPI) && defined(EAPI_MM)
883 + if (ps->block->h.is_shm)
884 + ptr = ap_mm_realloc(ps->base, size);
887 ptr = realloc(ps->base, size);
889 fputs("Ouch! Out of memory!\n", stderr);
890 @@ -905,9 +1109,21 @@
891 size = AP_PSPRINTF_MIN_SIZE;
893 /* must try another blok */
894 +#if defined(EAPI) && defined(EAPI_MM)
895 + if (blok->h.is_shm)
896 + (void)ap_mm_lock(mm, AP_MM_LOCK_RW);
898 (void) ap_acquire_mutex(alloc_mutex);
899 +#if defined(EAPI) && defined(EAPI_MM)
900 + nblok = new_block(size, blok->h.is_shm);
902 nblok = new_block(size);
904 (void) ap_release_mutex(alloc_mutex);
905 +#if defined(EAPI) && defined(EAPI_MM)
906 + if (blok->h.is_shm)
907 + (void)ap_mm_unlock(mm);
909 memcpy(nblok->h.first_avail, blok->h.first_avail, cur_len);
910 ps->vbuff.curpos = nblok->h.first_avail + cur_len;
911 /* save a byte for the NUL terminator */
912 @@ -916,10 +1132,18 @@
913 /* did we allocate the current blok? if so free it up */
914 if (ps->got_a_new_block) {
915 debug_fill(blok->h.first_avail, blok->h.endp - blok->h.first_avail);
916 +#if defined(EAPI) && defined(EAPI_MM)
917 + if (blok->h.is_shm)
918 + (void)ap_mm_lock(mm, AP_MM_LOCK_RW);
920 (void) ap_acquire_mutex(alloc_mutex);
921 blok->h.next = block_freelist;
922 block_freelist = blok;
923 (void) ap_release_mutex(alloc_mutex);
924 +#if defined(EAPI) && defined(EAPI_MM)
925 + if (blok->h.is_shm)
926 + (void)ap_mm_unlock(mm);
930 ps->got_a_new_block = 1;
931 @@ -938,6 +1162,11 @@
935 +#if defined(EAPI) && defined(EAPI_MM)
937 + ps.base = ap_mm_malloc(mm, 512);
940 ps.base = malloc(512);
941 if (ps.base == NULL) {
942 fputs("Ouch! Out of memory!\n", stderr);
943 @@ -950,6 +1179,11 @@
944 *ps.vbuff.curpos++ = '\0';
947 +#if defined(EAPI) && defined(EAPI_MM)
949 + ptr = ap_mm_realloc(ptr, (char *)ps.vbuff.curpos - (char *)ptr);
952 ptr = realloc(ptr, (char *)ps.vbuff.curpos - (char *)ptr);
954 fputs("Ouch! Out of memory!\n", stderr);
955 @@ -1758,6 +1992,9 @@
956 cleanup_pool_for_exec(permanent_pool);
958 #endif /* ndef WIN32 */
960 + ap_kill_alloc_shared();
964 API_EXPORT_NONSTD(void) ap_null_cleanup(void *data)
966 +---------------------------------------------------------------------------
967 | Patch the low-level buffer routines to additionally allow
968 | modules to intercept the I/O processing via hooks.
969 +---------------------------------------------------------------------------
970 Index: src/main/buff.c
971 --- src/main/buff.c 27 Mar 2002 15:23:00 -0000 1.1.1.12
972 +++ src/main/buff.c 27 Mar 2002 15:30:02 -0000 1.20
978 + if (!ap_hook_call("ap::buff::read", &rv, fb, buf, nbyte))
980 rv = read(fb->fd_in, buf, nbyte);
985 #if defined (WIN32) || defined(NETWARE) || defined(CYGWIN_WINSOCK)
986 if (fb->flags & B_SOCKET) {
988 + if (!ap_hook_call("ap::buff::recvwithtimeout", &rv, fb, buf, nbyte))
990 rv = ap_recvwithtimeout(fb->fd_in, buf, nbyte, 0);
991 if (rv == SOCKET_ERROR)
992 errno = WSAGetLastError();
998 + if (!ap_hook_call("ap::buff::write", &rv, fb, buf, nbyte))
1000 #if defined (B_SFIO)
1001 rv = sfwrite(fb->sf_out, buf, nbyte);
1005 #if defined(WIN32) || defined(NETWARE)
1006 if (fb->flags & B_SOCKET) {
1008 + if (!ap_hook_call("ap::buff::sendwithtimeout", &rv, fb, buf, nbyte))
1010 rv = ap_sendwithtimeout(fb->fd, buf, nbyte, 0);
1011 if (rv == SOCKET_ERROR)
1012 errno = WSAGetLastError();
1013 @@ -464,6 +476,10 @@
1014 fb->callback_data = NULL;
1015 fb->filter_callback = NULL;
1018 + fb->ctx = ap_ctx_new(p);
1024 @@ -1116,6 +1132,9 @@
1029 + if (!ap_hook_call("ap::buff::writev", &rv, fb, &vec[i], nvec -i))
1031 rv = writev(fb->fd, &vec[i], nvec - i);
1032 while (rv == -1 && (errno == EINTR || errno == EAGAIN)
1033 && !(fb->flags & B_EOUT));
1035 +---------------------------------------------------------------------------
1036 | Add the implementation of the additional `add_module' and
1037 | `rewrite_command' module hooks. Additionally the `ctx'
1038 | variables are initialized.
1039 +---------------------------------------------------------------------------
1040 Index: src/main/http_config.c
1041 --- src/main/http_config.c 4 Oct 2002 11:50:15 -0000 1.1.1.15
1042 +++ src/main/http_config.c 4 Oct 2002 11:54:56 -0000 1.18
1043 @@ -600,6 +600,20 @@
1046 #endif /*_OSD_POSIX*/
1050 + * Invoke the `add_module' hook inside the now existing set
1051 + * of modules to let them all now that this module was added.
1055 + for (m2 = top_module; m2 != NULL; m2 = m2->next)
1056 + if (m2->magic == MODULE_MAGIC_COOKIE_EAPI)
1057 + if (m2->add_module != NULL)
1058 + (*m2->add_module)(m);
1064 @@ -614,6 +628,21 @@
1070 + * Invoke the `remove_module' hook inside the now existing
1071 + * set of modules to let them all now that this module is
1076 + for (m2 = top_module; m2 != NULL; m2 = m2->next)
1077 + if (m2->magic == MODULE_MAGIC_COOKIE_EAPI)
1078 + if (m2->remove_module != NULL)
1079 + (*m2->remove_module)(m);
1085 /* We are the top module, special case */
1086 @@ -1007,6 +1036,27 @@
1087 const command_rec *cmd;
1088 module *mod = top_module;
1092 + * Invoke the `rewrite_command' of modules to allow
1093 + * they to rewrite the directive line before we
1099 + for (m = top_module; m != NULL; m = m->next) {
1100 + if (m->magic == MODULE_MAGIC_COOKIE_EAPI) {
1101 + if (m->rewrite_command != NULL) {
1102 + cp = (m->rewrite_command)(parms, config, l);
1111 if ((l[0] == '#') || (!l[0]))
1114 @@ -1467,6 +1517,10 @@
1115 s->limit_req_fieldsize = main_server->limit_req_fieldsize;
1116 s->limit_req_fields = main_server->limit_req_fields;
1119 + s->ctx = ap_ctx_new(p);
1124 return ap_parse_vhost_addrs(p, hostname, s);
1125 @@ -1577,6 +1631,10 @@
1127 s->module_config = create_server_config(p, s);
1128 s->lookup_defaults = create_default_per_dir_config(p);
1131 + s->ctx = ap_ctx_new(p);
1137 +---------------------------------------------------------------------------
1138 | Add the ap_global_ctx variable and the new
1139 | ap_add_config_define() function. Additionally the
1140 | implementation of the additional `new_connection' module hook
1141 | is added plus the initialization of one more `ctx' variable.
1142 +---------------------------------------------------------------------------
1143 Index: src/main/http_main.c
1144 --- src/main/http_main.c 4 Oct 2002 11:50:15 -0000 1.1.1.19
1145 +++ src/main/http_main.c 4 Oct 2002 11:54:56 -0000 1.41
1148 int ap_dump_settings = 0;
1149 API_VAR_EXPORT int ap_extended_status = 0;
1151 +API_VAR_EXPORT ap_ctx *ap_global_ctx;
1155 * The max child slot ever assigned, preserved across restarts. Necessary
1156 @@ -469,6 +472,30 @@
1161 +API_EXPORT(void) ap_add_config_define(const char *define)
1164 + var = (char **)ap_push_array(ap_server_config_defines);
1165 + *var = ap_pstrdup(pcommands, define);
1170 + * Invoke the `close_connection' hook of modules to let them do
1171 + * some connection dependent actions before we close it.
1173 +static void ap_call_close_connection_hook(conn_rec *c)
1176 + for (m = top_module; m != NULL; m = m->next)
1177 + if (m->magic == MODULE_MAGIC_COOKIE_EAPI)
1178 + if (m->close_connection != NULL)
1179 + (*m->close_connection)(c);
1185 static APACHE_TLS int volatile exit_after_unblock = 0;
1187 @@ -1523,6 +1550,10 @@
1188 ap_log_transaction(log_req);
1192 + ap_call_close_connection_hook(save_req->connection);
1195 ap_bsetflag(save_req->connection->client, B_EOUT, 1);
1196 ap_bclose(save_req->connection->client);
1198 @@ -1531,6 +1562,9 @@
1199 ap_longjmp(jmpbuffer, 1);
1201 else { /* abort the connection */
1203 + ap_call_close_connection_hook(current_conn);
1205 ap_bsetflag(current_conn->client, B_EOUT, 1);
1206 ap_bclose(current_conn->client);
1207 current_conn->aborted = 1;
1208 @@ -1833,10 +1867,16 @@
1209 /* Send any leftover data to the client, but never try to again */
1211 if (ap_bflush(r->connection->client) == -1) {
1213 + ap_call_close_connection_hook(r->connection);
1216 ap_bclose(r->connection->client);
1220 + ap_call_close_connection_hook(r->connection);
1222 ap_bsetflag(r->connection->client, B_EOUT, 1);
1224 /* Close our half of the connection --- send the client a FIN */
1225 @@ -2566,6 +2606,9 @@
1226 /* Clear the pool - including any registered cleanups */
1227 ap_destroy_pool(pglobal);
1230 + ap_kill_alloc_shared();
1235 @@ -3577,6 +3620,24 @@
1236 conn->remote_addr = *remaddr;
1237 conn->remote_ip = ap_pstrdup(conn->pool,
1238 inet_ntoa(conn->remote_addr.sin_addr));
1240 + conn->ctx = ap_ctx_new(conn->pool);
1245 + * Invoke the `new_connection' hook of modules to let them do
1246 + * some connection dependent actions before we go on with
1247 + * processing the request on this connection.
1251 + for (m = top_module; m != NULL; m = m->next)
1252 + if (m->magic == MODULE_MAGIC_COOKIE_EAPI)
1253 + if (m->new_connection != NULL)
1254 + (*m->new_connection)(conn);
1260 @@ -4005,6 +4066,15 @@
1261 printf("Server's Module Magic Number: %u:%u\n",
1262 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
1263 printf("Server compiled with....\n");
1265 + printf(" -D EAPI\n");
1268 + printf(" -D EAPI_MM\n");
1269 +#ifdef EAPI_MM_CORE_PATH
1270 + printf(" -D EAPI_MM_CORE_PATH=\"" EAPI_MM_CORE_PATH "\"\n");
1274 show_os_specific_compile_settings();
1276 @@ -4175,6 +4245,22 @@
1277 ap_server_pre_read_config = ap_make_array(pcommands, 1, sizeof(char *));
1278 ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
1279 ap_server_config_defines = ap_make_array(pcommands, 1, sizeof(char *));
1283 + ap_hook_configure("ap::buff::read",
1284 + AP_HOOK_SIG4(int,ptr,ptr,int), AP_HOOK_TOPMOST);
1285 + ap_hook_configure("ap::buff::write",
1286 + AP_HOOK_SIG4(int,ptr,ptr,int), AP_HOOK_TOPMOST);
1287 + ap_hook_configure("ap::buff::writev",
1288 + AP_HOOK_SIG4(int,ptr,ptr,int), AP_HOOK_TOPMOST);
1289 + ap_hook_configure("ap::buff::sendwithtimeout",
1290 + AP_HOOK_SIG4(int,ptr,ptr,int), AP_HOOK_TOPMOST);
1291 + ap_hook_configure("ap::buff::recvwithtimeout",
1292 + AP_HOOK_SIG4(int,ptr,ptr,int), AP_HOOK_TOPMOST);
1294 + ap_global_ctx = ap_ctx_new(NULL);
1299 @@ -4625,6 +4711,9 @@
1301 ap_sync_scoreboard_image();
1302 if (ap_scoreboard_image->global.running_generation != ap_my_generation) {
1304 + ap_call_close_connection_hook(current_conn);
1307 clean_child_exit(0);
1309 @@ -4653,6 +4742,9 @@
1314 + ap_call_close_connection_hook(current_conn);
1316 ap_bclose(conn_io); /* just close it */
1318 if (r && r->connection
1319 @@ -4663,6 +4755,9 @@
1324 + ap_call_close_connection_hook(current_conn);
1326 ap_bsetflag(conn_io, B_EOUT, 1);
1329 @@ -5428,16 +5523,31 @@
1334 + ap_init_alloc_shared(TRUE);
1337 ap_suexec_enabled = init_suexec();
1338 server_conf = ap_read_config(pconf, ptrans, ap_server_confname);
1341 + ap_init_alloc_shared(FALSE);
1344 if (ap_configtestonly) {
1345 fprintf(stderr, "Syntax OK\n");
1347 + clean_parent_exit(0);
1352 if (ap_dump_settings) {
1354 + clean_parent_exit(0);
1360 child_timeouts = !ap_standalone || one_process;
1361 @@ -5585,6 +5695,10 @@
1362 ap_destroy_pool(r->pool);
1366 + ap_call_close_connection_hook(conn);
1372 @@ -5961,6 +6075,9 @@
1373 ap_kill_cleanups_for_socket(ptrans, csd);
1377 + ap_call_close_connection_hook(current_conn);
1379 ap_bclose(conn_io); /* just close it */
1381 if (r && r->connection
1382 @@ -5971,6 +6088,9 @@
1387 + ap_call_close_connection_hook(current_conn);
1389 ap_bsetflag(conn_io, B_EOUT, 1);
1392 @@ -7539,6 +7659,10 @@
1393 if (!conf_specified)
1394 ap_cpystrn(ap_server_confname, SERVER_CONFIG_FILE, sizeof(ap_server_confname));
1397 + ap_init_alloc_shared(TRUE);
1400 if (!ap_os_is_path_absolute(ap_server_confname))
1401 ap_cpystrn(ap_server_confname,
1402 ap_server_root_relative(pcommands, ap_server_confname),
1403 @@ -7578,6 +7702,9 @@
1405 #else /* ndef WIN32 */
1406 server_conf = ap_read_config(pconf, ptrans, ap_server_confname);
1409 + ap_init_alloc_shared(FALSE);
1412 if (ap_configtestonly) {
1414 +---------------------------------------------------------------------------
1415 | Just add the initialization of the `ctx' variable for
1416 | conn_rec structures.
1417 +---------------------------------------------------------------------------
1418 Index: src/main/http_request.c
1419 --- src/main/http_request.c 19 Jun 2002 07:20:26 -0000 1.1.1.15
1420 +++ src/main/http_request.c 19 Jun 2002 07:29:09 -0000 1.15
1421 @@ -1375,6 +1375,10 @@
1423 new->method = r->method;
1424 new->method_number = r->method_number;
1426 + /* initialize context _BEFORE_ ap_parse_uri() call */
1427 + new->ctx = r->ctx;
1429 ap_parse_uri(new, new_uri);
1430 new->request_config = ap_create_request_config(r->pool);
1431 new->per_dir_config = r->server->lookup_defaults;
1433 +---------------------------------------------------------------------------
1434 | Just add the initialization of the `ctx' variable for
1435 | request_rec structures.
1436 +---------------------------------------------------------------------------
1437 Index: src/main/http_protocol.c
1438 --- src/main/http_protocol.c 4 Oct 2002 11:50:15 -0000 1.1.1.18
1439 +++ src/main/http_protocol.c 4 Oct 2002 11:54:56 -0000 1.18
1440 @@ -1203,6 +1203,10 @@
1441 r->status = HTTP_REQUEST_TIME_OUT; /* Until we get a request */
1442 r->the_request = NULL;
1445 + r->ctx = ap_ctx_new(r->pool);
1448 #ifdef CHARSET_EBCDIC
1449 ap_bsetflag(r->connection->client, B_ASCII2EBCDIC, r->ebcdic.conv_in = 1);
1450 ap_bsetflag(r->connection->client, B_EBCDIC2ASCII, r->ebcdic.conv_out = 1);
1451 @@ -1359,6 +1363,11 @@
1452 rnew->read_body = REQUEST_NO_BODY;
1454 rnew->main = (request_rec *) r;
1457 + rnew->ctx = r->ctx;
1462 API_EXPORT(void) ap_finalize_sub_req_protocol(request_rec *sub)
1464 +---------------------------------------------------------------------------
1465 | Add support for loading both EAPI and AP13 modules.
1466 +---------------------------------------------------------------------------
1467 Index: src/modules/standard/mod_so.c
1468 --- src/modules/standard/mod_so.c 27 Mar 2002 15:23:06 -0000 1.1.1.9
1469 +++ src/modules/standard/mod_so.c 27 Mar 2002 15:30:03 -0000 1.10
1470 @@ -269,11 +269,24 @@
1471 * Make sure the found module structure is really a module structure
1475 + if ( modp->magic != MODULE_MAGIC_COOKIE_AP13
1476 + && modp->magic != MODULE_MAGIC_COOKIE_EAPI) {
1478 if (modp->magic != MODULE_MAGIC_COOKIE) {
1480 return ap_pstrcat(cmd->pool, "API module structure `", modname,
1481 "' in file ", szModuleFile, " is garbled -"
1482 " perhaps this is not an Apache module DSO?", NULL);
1485 + if (modp->magic == MODULE_MAGIC_COOKIE_AP13) {
1486 + ap_log_error(APLOG_MARK, APLOG_WARNING|APLOG_NOERRNO, NULL,
1487 + "Loaded DSO %s uses plain Apache 1.3 API, "
1488 + "this module might crash under EAPI! "
1489 + "(please recompile it with -DEAPI)", filename);
1494 * Add this module to the Apache core structures
1496 +---------------------------------------------------------------------------
1497 | Add additional logging functions to the CustomLog directive
1498 | which can be used by other modules to create additional
1499 | logfile tags. Actually we add two types of hooks: One hook
1500 | for intercepting the new and generic %x (eXtension) tag and
1501 | one hook for creating new %x tags at all.
1502 +---------------------------------------------------------------------------
1503 Index: src/modules/standard/mod_log_config.c
1504 --- src/modules/standard/mod_log_config.c 19 Jun 2002 07:20:30 -0000 1.1.1.13
1505 +++ src/modules/standard/mod_log_config.c 19 Jun 2002 07:29:09 -0000 1.26
1507 typedef const char *(*item_key_func) (request_rec *, char *);
1515 int condition_sense;
1516 @@ -580,15 +583,36 @@
1521 +static struct log_item_list *find_log_func(pool *p, char k)
1523 static struct log_item_list *find_log_func(char k)
1528 + struct log_item_list *lil;
1531 for (i = 0; log_item_keys[i].ch; ++i)
1532 if (k == log_item_keys[i].ch) {
1533 return &log_item_keys[i];
1537 + if (ap_hook_status(ap_psprintf(p, "ap::mod_log_config::log_%c", k))
1538 + != AP_HOOK_STATE_NOTEXISTANT) {
1539 + lil = (struct log_item_list *)
1540 + ap_pcalloc(p, sizeof(struct log_item_list));
1545 + lil->want_orig_default = 0;
1553 @@ -714,7 +738,11 @@
1558 + l = find_log_func(p, *s++);
1560 l = find_log_func(*s++);
1566 return ap_pstrcat(p, "Unrecognized LogFormat directive %",
1573 if (it->want_orig == -1) {
1574 it->want_orig = l->want_orig_default;
1575 @@ -784,6 +815,15 @@
1577 /* We do. Do it... */
1580 + if (item->func == NULL) {
1582 + ap_hook_use(ap_psprintf(r->pool, "ap::mod_log_config::log_%c", item->ch),
1583 + AP_HOOK_SIG3(ptr,ptr,ptr), AP_HOOK_DECLINE(NULL),
1584 + &cp, r, item->arg);
1588 cp = (*item->func) (item->want_orig ? orig : r, item->arg);
1589 return cp ? cp : "-";
1592 +---------------------------------------------------------------------------
1593 | Allow RewriteCond and RewriteRule directives to lookup
1594 | variables from other modules.
1595 +---------------------------------------------------------------------------
1596 Index: src/modules/standard/mod_rewrite.c
1597 --- src/modules/standard/mod_rewrite.c 4 Oct 2002 11:50:18 -0000 1.1.1.16
1598 +++ src/modules/standard/mod_rewrite.c 4 Oct 2002 11:54:56 -0000 1.14
1599 @@ -3691,6 +3691,15 @@
1601 #endif /* ndef WIN32 && NETWARE*/
1605 + ap_hook_use("ap::mod_rewrite::lookup_variable",
1606 + AP_HOOK_SIG3(ptr,ptr,ptr),
1607 + AP_HOOK_DECLINE(NULL),
1612 if (result == NULL) {
1613 return ap_pstrdup(r->pool, "");
1616 +---------------------------------------------------------------------------
1617 | Add an EAPI hook to allow other modules to add content to
1618 | the status HTML page.
1619 +---------------------------------------------------------------------------
1620 Index: src/modules/standard/mod_status.c
1621 --- src/modules/standard/mod_status.c 27 Mar 2002 15:23:06 -0000 1.1.1.14
1622 +++ src/modules/standard/mod_status.c 27 Mar 2002 15:30:03 -0000 1.11
1623 @@ -717,6 +754,12 @@
1629 + ap_hook_use("ap::mod_status::display",
1630 + AP_HOOK_SIG4(void,ptr,int,int), AP_HOOK_ALL,
1631 + r, no_table_report, short_report);
1637 +---------------------------------------------------------------------------
1638 | Add hooks to the scheme processing to allow other modules to
1639 | recognize more schemes by intercepting this processing.
1640 +---------------------------------------------------------------------------
1641 Index: src/modules/proxy/mod_proxy.c
1642 --- src/modules/proxy/mod_proxy.c 19 Jun 2002 07:20:27 -0000 1.1.1.12
1643 +++ src/modules/proxy/mod_proxy.c 19 Jun 2002 07:29:09 -0000 1.19
1645 static int proxy_fixup(request_rec *r)
1652 if (r->proxyreq == NOT_PROXY || strncmp(r->filename, "proxy:", 6) != 0)
1654 @@ -225,6 +228,14 @@
1655 url = &r->filename[6];
1657 /* canonicalise each specific scheme */
1659 + if (ap_hook_use("ap::mod_proxy::canon",
1660 + AP_HOOK_SIG3(int,ptr,ptr),
1661 + AP_HOOK_DECLINE(DECLINED),
1662 + &rc, r, url) && rc != DECLINED)
1666 if (strncasecmp(url, "http:", 5) == 0)
1667 return ap_proxy_http_canon(r, url + 5, "http", DEFAULT_HTTP_PORT);
1668 else if (strncasecmp(url, "ftp:", 4) == 0)
1669 @@ -240,9 +251,44 @@
1670 static void proxy_init(server_rec *r, pool *p)
1672 ap_proxy_garbage_init(r, p);
1674 + ap_hook_use("ap::mod_proxy::init",
1675 + AP_HOOK_SIG3(void,ptr,ptr), AP_HOOK_ALL, r, p);
1681 +static void proxy_addmod(module *m)
1683 + /* export: ap_proxy_http_canon() as `ap::mod_proxy::http::canon' */
1684 + ap_hook_configure("ap::mod_proxy::http::canon",
1685 + AP_HOOK_SIG5(int,ptr,ptr,ptr,int), AP_HOOK_TOPMOST);
1686 + ap_hook_register("ap::mod_proxy::http::canon",
1687 + ap_proxy_http_canon, AP_HOOK_NOCTX);
1689 + /* export: ap_proxy_http_handler() as `ap::mod_proxy::http::handler' */
1690 + ap_hook_configure("ap::mod_proxy::http::handler",
1691 + AP_HOOK_SIG6(int,ptr,ptr,ptr,ptr,int), AP_HOOK_TOPMOST);
1692 + ap_hook_register("ap::mod_proxy::http::handler",
1693 + ap_proxy_http_handler, AP_HOOK_NOCTX);
1695 + /* export: ap_proxyerror() as `ap::mod_proxy::error' */
1696 + ap_hook_configure("ap::mod_proxy::error",
1697 + AP_HOOK_SIG3(int,ptr,ptr), AP_HOOK_TOPMOST);
1698 + ap_hook_register("ap::mod_proxy::error",
1699 + ap_proxyerror, AP_HOOK_NOCTX);
1703 +static void proxy_remmod(module *m)
1705 + /* remove the hook references */
1706 + ap_hook_unregister("ap::mod_proxy::http::canon", ap_proxy_http_canon);
1707 + ap_hook_unregister("ap::mod_proxy::http::handler", ap_proxy_http_handler);
1708 + ap_hook_unregister("ap::mod_proxy::error", ap_proxyerror);
1713 /* Send a redirection if the request contains a hostname which is not */
1714 /* fully qualified, i.e. doesn't have a domain name appended. Some proxy */
1715 @@ -374,6 +420,14 @@
1716 * CONNECT is a special method that bypasses the normal proxy
1720 + if (!ap_hook_use("ap::mod_proxy::handler",
1721 + AP_HOOK_SIG7(int,ptr,ptr,ptr,ptr,int,ptr),
1722 + AP_HOOK_DECLINE(DECLINED),
1724 + ents[i].hostname, ents[i].port,
1725 + ents[i].protocol) || rc == DECLINED) {
1727 if (r->method_number == M_CONNECT)
1728 rc = ap_proxy_connect_handler(r, cr, url, ents[i].hostname,
1738 /* an error or success */
1739 if (rc != DECLINED && rc != HTTP_BAD_GATEWAY)
1740 @@ -397,6 +454,14 @@
1743 /* handle the scheme */
1745 + if (ap_hook_use("ap::mod_proxy::handler",
1746 + AP_HOOK_SIG7(int,ptr,ptr,ptr,ptr,int,ptr),
1747 + AP_HOOK_DECLINE(DECLINED),
1749 + NULL, 0, scheme) && rc != DECLINED)
1752 if (r->method_number == M_CONNECT) {
1753 return ap_proxy_connect_handler(r, cr, url, NULL, 0);
1755 @@ -994,4 +1059,10 @@
1756 NULL, /* child_init */
1757 NULL, /* child_exit */
1758 proxy_detect /* post read-request */
1760 + ,proxy_addmod, /* EAPI: add_module */
1761 + proxy_remmod, /* EAPI: remove_module */
1762 + NULL, /* EAPI: rewrite_command */
1763 + NULL /* EAPI: new_connection */
1767 +---------------------------------------------------------------------------
1768 | Add hooks to the HTTP processing to allow other modules
1769 | to enhance it by intercepting this processing.
1770 +---------------------------------------------------------------------------
1771 Index: src/modules/proxy/proxy_http.c
1772 --- src/modules/proxy/proxy_http.c 4 Oct 2002 11:50:16 -0000 1.1.1.15
1773 +++ src/modules/proxy/proxy_http.c 4 Oct 2002 11:54:56 -0000 1.23
1775 const char *datestr, *urlstr;
1776 int result, major, minor;
1777 const char *content_length;
1782 void *sconf = r->server->module_config;
1783 proxy_server_conf *conf =
1784 @@ -191,6 +194,12 @@
1785 return HTTP_BAD_REQUEST;
1787 destport = DEFAULT_HTTP_PORT;
1789 + ap_hook_use("ap::mod_proxy::http::handler::set_destport",
1790 + AP_HOOK_SIG2(int,ptr),
1794 strp = strchr(urlptr, '/');
1796 desthost = ap_pstrdup(p, urlptr);
1797 @@ -228,12 +237,18 @@
1798 err = ap_proxy_host2addr(proxyhost, &server_hp);
1800 return DECLINED; /* try another */
1802 + peer = ap_psprintf(p, "%s:%u", proxyhost, proxyport);
1806 server.sin_port = htons((unsigned short)destport);
1807 err = ap_proxy_host2addr(desthost, &server_hp);
1809 return ap_proxyerror(r, HTTP_INTERNAL_SERVER_ERROR, err);
1811 + peer = ap_psprintf(p, "%s:%u", desthost, destport);
1816 @@ -308,14 +323,42 @@
1817 f = ap_bcreate(p, B_RDWR | B_SOCKET);
1818 ap_bpushfd(f, sock, sock);
1822 + char *errmsg = NULL;
1823 + ap_hook_use("ap::mod_proxy::http::handler::new_connection",
1824 + AP_HOOK_SIG4(ptr,ptr,ptr,ptr),
1825 + AP_HOOK_DECLINE(NULL),
1826 + &errmsg, r, f, peer);
1827 + if (errmsg != NULL)
1828 + return ap_proxyerror(r, HTTP_BAD_GATEWAY, errmsg);
1832 ap_hard_timeout("proxy send", r);
1833 ap_bvputs(f, r->method, " ", proxyhost ? url : urlptr, " HTTP/1.1" CRLF,
1837 + int rc = DECLINED;
1838 + ap_hook_use("ap::mod_proxy::http::handler::write_host_header",
1839 + AP_HOOK_SIG6(int,ptr,ptr,ptr,int,ptr),
1840 + AP_HOOK_DECLINE(DECLINED),
1841 + &rc, r, f, desthost, destport, destportstr);
1842 + if (rc == DECLINED) {
1843 + if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
1844 + ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL);
1846 + ap_bvputs(f, "Host: ", desthost, CRLF, NULL);
1850 /* Send Host: now, adding it to req_hdrs wouldn't be much better */
1851 if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
1852 ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL);
1854 ap_bvputs(f, "Host: ", desthost, CRLF, NULL);
1857 if (conf->viaopt == via_block) {
1858 /* Block all outgoing Via: headers */
1860 +---------------------------------------------------------------------------
1861 | Add EAPI hooks in module structure for APXS generated samples.
1862 +---------------------------------------------------------------------------
1863 Index: src/support/apxs.pl
1864 --- src/support/apxs.pl 19 Jun 2002 07:20:34 -0000 1.1.1.12
1865 +++ src/support/apxs.pl 19 Jun 2002 07:29:09 -0000 1.12
1866 @@ -711,5 +711,11 @@
1867 NULL, /* child_init */
1868 NULL, /* child_exit */
1869 NULL /* [#0] post read-request */
1871 + ,NULL, /* EAPI: add_module */
1872 + NULL, /* EAPI: remove_module */
1873 + NULL, /* EAPI: rewrite_command */
1874 + NULL /* EAPI: new_connection */
1879 +---------------------------------------------------------------------------
1880 | Add the EAPI functions, so the stuff can be built under AIX
1881 | and similar braindead platforms as DSO.
1882 +---------------------------------------------------------------------------
1883 Index: src/support/httpd.exp
1884 --- src/support/httpd.exp 19 Jun 2002 07:20:34 -0000 1.1.1.11
1885 +++ src/support/httpd.exp 19 Jun 2002 07:29:09 -0000 1.13
1886 @@ -427,3 +427,59 @@
1887 XML_SetUnparsedEntityDeclHandler
1889 XML_UseParserAsHandlerArg
1890 +ap_add_config_define
1891 +ap_make_shared_sub_pool
1900 +ap_hook_unregister_I
1935 +ap_mm_core_permission
1940 +ap_mm_core_maxsegsize
1941 +ap_mm_core_align2page
1942 +ap_mm_core_align2word
1943 +ap_mm_lib_error_set
1944 +ap_mm_lib_error_get
1947 +---------------------------------------------------------------------------
1948 | Add the EAPI functions, so the stuff can be built under
1949 | Windows 95 and similar braindead platforms as DDL.
1950 +---------------------------------------------------------------------------
1951 Index: src/ApacheCore.def
1952 --- src/ApacheCore.def 19 Jun 2002 07:20:21 -0000 1.1.1.10
1953 +++ src/ApacheCore.def 19 Jun 2002 07:29:08 -0000 1.14
1954 @@ -447,3 +447,67 @@
1956 ap_get_chunk_size @440
1957 ap_escape_logitem @441
1959 + ; EAPI extended symbols
1960 + ; note; no ID's, so these all bind by name rather than ordinal since
1961 + ; their ordinals would change with symbol changes in the distribution
1962 + ap_add_config_define
1963 + ap_global_ctx DATA
1971 + ap_hook_register_I
1972 + ap_hook_unregister_I
1976 + ap_set_callback_and_alarm
1978 + ap_make_shared_sub_pool
2009 + ap_mm_display_info
2011 + ap_mm_core_permission
2016 + ap_mm_core_align2page
2017 + ap_mm_core_align2word
2018 + ap_mm_lib_error_set
2019 + ap_mm_lib_error_get