From 20fda385b9ce2625ae2ea71d25b192abef6289d7 Mon Sep 17 00:00:00 2001 From: Greg Stein Date: Sat, 5 Aug 2000 09:54:14 +0000 Subject: - remove patch #3 since it has been applied - regenerate patch #2 given ap_ -> apr_ rename and presence of patch #3 - update the README git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@60479 13f79535-47bb-0310-9956-ffa450edef68 --- buckets/README.txt | 9 - buckets/ap_filter.h | 379 ----------------------------------------- buckets/filters.c | 149 ---------------- buckets/greg_patch.txt | 412 +++++++++++++++++++++++++++++---------------- buckets/register_patch.txt | 142 ---------------- buckets/util_filter.c | 146 ---------------- buckets/util_filter.h | 220 ------------------------ 7 files changed, 267 insertions(+), 1190 deletions(-) delete mode 100644 buckets/ap_filter.h delete mode 100644 buckets/filters.c delete mode 100644 buckets/register_patch.txt delete mode 100644 buckets/util_filter.c delete mode 100644 buckets/util_filter.h (limited to 'buckets') diff --git a/buckets/README.txt b/buckets/README.txt index 06a7758b9..393798775 100644 --- a/buckets/README.txt +++ b/buckets/README.txt @@ -41,13 +41,4 @@ Bachelor #1 Bachelor #2 ----------- - ap_filter.h - filters.c greg_patch.txt - -Bachelor #3 -- The combination of #1 and #2 (hopefully) ------------ - - util_filter.h - util_filter.c - register_patch.txt diff --git a/buckets/ap_filter.h b/buckets/ap_filter.h deleted file mode 100644 index 5785b66f9..000000000 --- a/buckets/ap_filter.h +++ /dev/null @@ -1,379 +0,0 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2000 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * nor may "Apache" appear in their name, without prior written - * permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -#ifndef AP_FILTER_H -#define AP_FILTER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef APR_HAVE_STDARG_H -#include -#endif - -#include "httpd.h" -#include "apr.h" - -/* - * FILTER CHAIN - * - * Filters operate using a "chaining" mechanism. The filters are chained - * together into a sequence. When output is generated, it is passed through - * each of the filters on this chain, until it reaches the end (or "bottom") - * and is placed onto the network. - * - * The top of the chain, the code generating the output, is typically called - * a "content generator." The content generator's output is fed into the - * filter chain using the standard Apache output mechanisms: ap_rputs(), - * ap_rprintf(), ap_rwrite(), etc. - * - * Each filter is defined by a callback. This callback takes the output from - * the previous filter (or the content generator if there is no previous - * filter), operates on it, and passes the result to the next filter in the - * chain. This pass-off is performed using the ap_fc_* functions, such as - * ap_fc_puts(), ap_fc_printf(), ap_fc_write(), etc. - * - * When content generation is complete, the system will pass an "end of - * stream" marker into the filter chain. The filters will use this to flush - * out any internal state and to detect incomplete syntax (for example, an - * unterminated SSI directive). - */ - -/* - * BUCKETS - * - * Filtering uses a "bucket" metaphor for holding content to be processed. - * These buckets may contain arbitrary types of data. The selection of the - * type is dependent upon how the "upstream" filter/generator places content - * into the filter chain stream. - * - * For example, if a content generator uses ap_rwrite(), then the data will - * be placed into an AP_BUCKET_PTRLEN bucket. This bucket type contains a - * single pointer/length pair which will refer to the data. - * - * Buckets types are defined around the need to avoid copying the data if - * at all possible. Whatever the "natural" input form is for a piece of - * content, this is modelled within the bucket types. For example, when a - * content generator uses ap_rprintf() or a filter uses ap_fc_printf(), - * the format string and arguments are fed into/down the filter chain as - * just theat: a format string and its arguments. The filter mechanism avoids - * reducing the format/args to a final string for as long as possible. At - * some point, a filter or the output of the chain will combine these to - * produce actual bytes, but it is most optimal to defer this until it is - * truly needed. - * - * See the ap_bucket_type enumeration for the different bucket types which - * are currently defined. - * - * Buckets may also be linked into a list so that they may be passed as - * entire groups of content. The filter may insert/remove/replace the buckets - * within this list before passing the list to the next filter. - */ - -/* forward declare some types */ -typedef struct apr_filter_t apr_filter_t; -typedef struct apr_bucket_t apr_bucket_t; - -/* - * apr_filter_bucket_cb: - * - * This function type is used for filter callbacks. It will be passed a - * pointer to "this" filter, and a "bucket" containing the content to be - * filtered. - * - * In filter->ctx, the callback will find its context. This context is - * provided here, so that a filter may be installed multiple times, each - * receiving its own per-install context pointer. - * - * Callbacks are associated with a filter definition, which is specified - * by name. See ap_register_filter() for setting the association between - * a name for a filter and its associated callback (and other information). - * - * The *bucket structure (and all those referenced by ->next and ->prev) - * should be considered "const". The filter is allowed to modify the - * next/prev to insert/remove/replace elements in the bucket list, but - * the types and values of the individual buckets should not be altered. - */ -typedef void (*apr_filter_bucket_cb)(apr_filter_t *filter, - apr_bucket_t *bucket); - -/* - * ap_filter_type: - * - * Filters have different types/classifications. These are used to group - * and sort the filters to properly sequence their operation. - * - * AP_FTYPE_CONTENT: - * These filters are used to alter the content that is passed through - * them. Examples are SSI or PHP. - * - * AP_FTYPE_CONNECTION: - * These filters will alter the content, but in ways that are more - * strongly associated with the output connection. Examples are - * compression, character recoding, or chunked transfer coding. - * - * It is important to note that these types of filters are not allowed - * in a sub-request. A sub-requests output can certainly be filtered - * by AP_FTYPE_CONTENT filters, but all of the "final processing" is - * determined by the main request. - * - * The types have a particular sort order, which allows us to insert them - * into the filter chain in a determistic order. Within a particular grouping, - * the ordering is equivalent to the order of calls to ap_add_filter(). - */ -typedef enum { - AP_FTYPE_CONTENT, - AP_FTYPE_CONNECTION -} ap_filter_type; - -/* - * apr_filter_t: - * - * This is the request-time context structure for an installed filter (in - * the output filter chain). It provides the callback to use for filtering, - * the request this filter is associated with (which is important when - * an output chain also includes sub-request filters), the context for this - * installed filter, and the filter ordering/chaining fields. - * - * Filter callbacks are free to use ->ctx as they please, to store context - * during the filter process. Generally, this is superior over associating - * the state directly with the request. A callback should not change any of - * the other fields. - */ -struct apr_filter_t { - apr_filter_bucket_cb bucket_cb; - request_rec *r; - - void *ctx; - - ap_filter_type ftype; - apr_filter_t *next; -}; - -/* - * ap_bucket_type: - * - * This enumeration is used to specify what type of bucket is present when - * an apr_bucket_t is provided. - * - * AP_BUCKET_PTRLEN: - * This bucket type defines a simple pointer/length pair for the content. - * The content is NOT necessarily null-terminated. - * - * This type occurs when ap_rwrite(), ap_fc_write(), ap_rputs(), - * ap_fc_puts(), ap_rputc(), or ap_fc_putc() is used by the upstream - * filter/generator. - * - * AP_BUCKET_STRINGS: - * This bucket type defines a set of null-terminated strings. The actual - * representation is through varargs' va_list type. A filter can sequence - * through the arguments using the va_arg() macro (and the "const char *" - * type). The filter should NOT use va_start() or va_end(). When va_arg() - * returns a NULL pointer, the list of strings is complete. - * - * Note that you can only sequence through the strings once, due to the - * definition of va_list. Thus, the first filter to do this sequencing - * must pass the resulting content to the next filter in a new form (the - * bucket cannot simply be passed because ->va is useless). - * - * This type occurs when ap_rvputs(), ap_fc_putstrs, or ap_fc_vputstrs() - * is used by the upstream filter/generator. - * - * AP_BUCKET_PRINTF: - * This bucket type defines a printf-style format and arguments. Similar - * to AP_BUCKET_STRINGS, this type also uses the ->va field to refer to - * the arguments. The format for the printf is stored in ->fmt. - * - * Also similar to AP_BUCKET_STRINGS, the va_start/va_end macros should - * not be used, and ->va should be processed only once. The bucket may - * not be passed after this processing. - * - * This type occurs when ap_rprintf(), ap_vrprintf(), ap_fc_printf(), or - * ap_fc_vprintf() is used by the upstream filter/generator. - * - * AP_BUCKET_FILE: - * This bucket type refers to an open file, from the current position - * and extending for ->flen bytes. Since there are some apr_file_t - * implementations/types that are not seekable, it may be impossible to - * "rewind" the file's current position after reading the contenxt. - * Therefore, it is important to note that once the content has been - * read, it must be passed to the next filter in a different form. - * - * Note: if there is a way to determine whether a file is seekable, then - * it would be legal to fetch the current position, read the contents, - * rewind to the original position, and then pass this bucket/file down - * to the next filter in the output chain. - * - * This type occurs when ap_send_fd(), ap_send_fd_length(), or - * ap_fc_sendfile() are used by the upstream filter/generator. - * - * AP_BUCKET_EOS: - * This bucket signals the end of the content stream. The filter should - * flush any internal state and issue errors if the state specifies that - * and end of stream cannot occur now (e.g. a command directive is - * incomplete). - * - * This type occurs when Apache finalizes a (sub)request, or when an - * upstream filter passes this bucket along. - */ -typedef enum { - AP_BUCKET_PTRLEN, - AP_BUCKET_STRINGS, - AP_BUCKET_PRINTF, - AP_BUCKET_FILE, - AP_BUCKET_EOS -} ap_bucket_type; - -/* - * apr_bucket_t: - * - * The actual bucket definition. The type is determined by the ->type field. - * Which fields are valid/useful in the bucket is determined by the type, - * as noted below and in the comments above for each type. - * - * Buckets are arranged in a doubly-linked list so that a filter may insert, - * remove, or replace elements in a list of buckets. Generally, a filter - * should not change any bucket values other than these link pointers. - */ -struct apr_bucket_t { - ap_bucket_type type; - - const char *buf; /* AP_BUCKET_PTRLEN */ - apr_size_t len; /* AP_BUCKET_PTRLEN */ - - const char *fmt; /* AP_BUCKET_PRINTF */ - va_list va; /* AP_BUCKET_STRINGS, _PRINTF */ - - apr_file_t *file; /* AP_BUCKET_FILE */ - apr_ssize_t flen; /* AP_BUCKET_FILE */ - - apr_bucket_t *next; /* next bucket in list */ - apr_bucket_t *prev; /* previous bucket in list */ -}; - -/* - * FILTER CHAIN OUTPUT FUNCTIONS - * - * These functions are used to deliver output/content down to the next - * filter in the chain. - * - * ap_fc_write(): write a block of bytes - * ap_fc_putc(): write a single character - * ap_fc_puts(): write a null-terminated string - * ap_fc_putstrs(): write a set of null-termianted strings; the end is - * signaled by a NULL parameter - * ap_fc_vputstrs(): same as ap_fc_putstrs(), but where the set of strings - * is defined by a va_list - * ap_fc_printf(): use printf-like semantics for writing a string - * ap_fc_vprintf(): use printf-like semantics, but with a va_list for the args - * ap_fc_sendfile(): send the file contents, from the current file position, - * and extending for "len" bytes; AP_FC_SENDFILE_ALL is - * used to send from current-position to the end-of-file. - * ap_fc_putbucket(): write a bucket into the filter chain - */ -API_EXPORT(void) ap_fc_write(apr_filter_t *filter, const char *buf, - apr_size_t len); -API_EXPORT(void) ap_fc_putc(apr_filter_t *filter, int c); -API_EXPORT(void) ap_fc_puts(apr_filter_t *filter, const char *str); - -API_EXPORT_NONSTD(void) ap_fc_putstrs(apr_filter_t *filter, ...); -API_EXPORT(void) ap_fc_vputstrs(apr_filter_t *filter, va_list va); - -API_EXPORT_NONSTD(void) ap_fc_printf(apr_filter_t *filter, - const char *fmt, ...); -API_EXPORT(void) ap_fc_vprintf(apr_filter_t *filter, - const char *fmt, va_list va); - -API_EXPORT(void) ap_fc_sendfile(apr_filter_t *filter, apr_file_t *file, - apr_ssize_t flen); -#define AP_FC_SENDFILE_ALL ((apr_ssize_t) -1) - -/* note: bucket->next and ->prev may be changed upon return from this */ -API_EXPORT(void) ap_fc_putbucket(apr_filter_t *filter, apr_bucket_t *bucket); - - -/* - * ap_register_filter(): - * - * This function is used to register a filter with the system. After this - * registration is performed, then a filter may be added into the filter - * chain by using ap_add_filter() and simply specifying the name. - * - * The filter's callback and type should be passed. - */ -API_EXPORT(void) ap_register_filter(const char *name, - apr_filter_bucket_cb bucket_cb, - ap_filter_type ftype); - -/* - * ap_add_filter(): - * - * Adds a named filter into the filter chain on the specified request record. - * The filter will be installed with the specified context pointer. - * - * Filters added in this way will always be placed at the end of the filters - * that have the same type (thus, the filters have the same order as the - * calls to ap_add_filter). If the current filter chain contains filters - * from another request, then this filter will be added before those other - * filters. - */ -API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r); - - -#ifdef __cplusplus -} -#endif - -#endif /* !AP_FILTER_H */ diff --git a/buckets/filters.c b/buckets/filters.c deleted file mode 100644 index d4e7a4810..000000000 --- a/buckets/filters.c +++ /dev/null @@ -1,149 +0,0 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2000 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * nor may "Apache" appear in their name, without prior written - * permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -#include "ap_filter.h" - - - -/* - * ap_filter_rec_t: - * - * This (internal) structure is used for recording information about the - * registered filters. It associates a name with the filter's callback - * and filter type. - * - * At the moment, these are simply linked in a chain, so a ->next pointer - * is available. - */ -typedef struct ap_filter_rec_t { - const char *name; - apr_filter_bucket_cb bucket_cb; - ap_filter_type ftype; - - struct ap_filter_rec_t *next; -} ap_filter_rec_t; - -/* ### make this visible for direct manipulation? - ### use a hash table -*/ -static ap_filter_rec_t *registered_filters = NULL; - -/* NOTE: Apache's current design doesn't allow a pool to be passed thu, - so we depend on a global to hold the correct pool -*/ -#define FILTER_POOL ap_global_hook_pool -#include "ap_hooks.h" /* for ap_global_hook_pool */ - -/* -** This macro returns true/false if a given filter should be inserted BEFORE -** another filter. This will happen when one of: 1) there isn't another -** filter; 2) that filter has a higher filter type (class); 3) that filter -** corresponds to a different request. -*/ -#define INSERT_BEFORE(f, before_this) ((before_this) == NULL \ - || (before_this)->ftype > (f)->ftype \ - || (before_this)->r != (f)->r) - - -static apr_status_t filter_cleanup(void *ctx) -{ - registered_filters = NULL; - return APR_SUCCESS; -} - -API_EXPORT(void) ap_register_filter(const char *name, - apr_filter_bucket_cb bucket_cb, - ap_filter_type ftype) -{ - ap_filter_rec_t *frec = apr_palloc(FILTER_POOL, sizeof(*frec)); - - frec->name = name; - frec->bucket_cb = bucket_cb; - frec->ftype = ftype; - - frec->next = registered_filters; - registered_filters = frec; - - apr_register_cleanup(FILTER_POOL, NULL, filter_cleanup, NULL); -} - -API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r) -{ - ap_filter_rec_t *frec = registered_filters; - - for (; frec != NULL; frec = frec->next) { - if (!strcasecmp(name, frec->name)) { - apr_filter_t *f = apr_pcalloc(r->pool, sizeof(*f)); - - f->bucket_cb = frec->bucket_cb; - f->r = r; - f->ctx = ctx; - f->ftype = frec->ftype; - - if (INSERT_BEFORE(f, r->filters)) { - f->next = r->filters; - r->filters = f; - } - else { - apr_filter_t *fscan = r->filters; - while (!INSERT_BEFORE(f, fscan->next)) - fscan = fscan->next; - f->next = fscan->next; - fscan->next = f; - } - - break; - } - } -} diff --git a/buckets/greg_patch.txt b/buckets/greg_patch.txt index 3895633ac..48eb73903 100644 --- a/buckets/greg_patch.txt +++ b/buckets/greg_patch.txt @@ -1,48 +1,244 @@ -Index: include/httpd.h +Index: include/util_filter.h =================================================================== -RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v -retrieving revision 1.64 -diff -u -r1.64 httpd.h ---- include/httpd.h 2000/06/30 21:18:13 1.64 -+++ include/httpd.h 2000/07/12 11:00:55 -@@ -731,7 +731,9 @@ - #ifdef APACHE_XLATE - struct ap_rr_xlate *rrx; - #endif /*APACHE_XLATE*/ -- -+ -+ struct ap_filter_t *filters; -+ - /* Things placed at the end of the record to avoid breaking binary - * compatibility. It would be nice to remember to reorder the entire - * record to improve 64bit alignment the next time we need to break +RCS file: /home/cvs/apache-2.0/src/include/util_filter.h,v +retrieving revision 1.3 +diff -u -r1.3 util_filter.h +--- include/util_filter.h 2000/08/05 04:38:57 1.3 ++++ include/util_filter.h 2000/08/05 09:48:20 +@@ -91,8 +91,40 @@ + * unterminated SSI directive). + */ + +-/* forward declare the filter type */ ++/* ++ * BUCKETS ++ * ++ * Filtering uses a "bucket" metaphor for holding content to be processed. ++ * These buckets may contain arbitrary types of data. The selection of the ++ * type is dependent upon how the "upstream" filter/generator places content ++ * into the filter chain stream. ++ * ++ * For example, if a content generator uses ap_rwrite(), then the data will ++ * be placed into an AP_BUCKET_PTRLEN bucket. This bucket type contains a ++ * single pointer/length pair which will refer to the data. ++ * ++ * Buckets types are defined around the need to avoid copying the data if ++ * at all possible. Whatever the "natural" input form is for a piece of ++ * content, this is modelled within the bucket types. For example, when a ++ * content generator uses ap_rprintf() or a filter uses ap_fc_printf(), ++ * the format string and arguments are fed into/down the filter chain as ++ * just theat: a format string and its arguments. The filter mechanism avoids ++ * reducing the format/args to a final string for as long as possible. At ++ * some point, a filter or the output of the chain will combine these to ++ * produce actual bytes, but it is most optimal to defer this until it is ++ * truly needed. ++ * ++ * See the ap_bucket_type enumeration for the different bucket types which ++ * are currently defined. ++ * ++ * Buckets may also be linked into a list so that they may be passed as ++ * entire groups of content. The filter may insert/remove/replace the buckets ++ * within this list before passing the list to the next filter. ++ */ ++ ++/* forward declare some types */ + typedef struct ap_filter_t ap_filter_t; ++typedef struct ap_bucket_t ap_bucket_t; + + /* + * ap_filter_func: +@@ -114,7 +146,7 @@ + * next/prev to insert/remove/replace elements in the bucket list, but + * the types and values of the individual buckets should not be altered. + */ +-typedef apr_status_t (*ap_filter_func)(); ++typedef void (*ap_filter_func)(ap_filter_t *filter, ap_bucket_t *bucket); + + /* + * ap_filter_type: +@@ -161,12 +193,155 @@ + */ + struct ap_filter_t { + ap_filter_func filter_func; ++ request_rec *r; + + void *ctx; + + ap_filter_type ftype; + ap_filter_t *next; + }; ++ ++/* ++ * ap_bucket_type: ++ * ++ * This enumeration is used to specify what type of bucket is present when ++ * an ap_bucket_t is provided. ++ * ++ * AP_BUCKET_PTRLEN: ++ * This bucket type defines a simple pointer/length pair for the content. ++ * The content is NOT necessarily null-terminated. ++ * ++ * This type occurs when ap_rwrite(), ap_fc_write(), ap_rputs(), ++ * ap_fc_puts(), ap_rputc(), or ap_fc_putc() is used by the upstream ++ * filter/generator. ++ * ++ * AP_BUCKET_STRINGS: ++ * This bucket type defines a set of null-terminated strings. The actual ++ * representation is through varargs' va_list type. A filter can sequence ++ * through the arguments using the va_arg() macro (and the "const char *" ++ * type). The filter should NOT use va_start() or va_end(). When va_arg() ++ * returns a NULL pointer, the list of strings is complete. ++ * ++ * Note that you can only sequence through the strings once, due to the ++ * definition of va_list. Thus, the first filter to do this sequencing ++ * must pass the resulting content to the next filter in a new form (the ++ * bucket cannot simply be passed because ->va is useless). ++ * ++ * This type occurs when ap_rvputs(), ap_fc_putstrs, or ap_fc_vputstrs() ++ * is used by the upstream filter/generator. ++ * ++ * AP_BUCKET_PRINTF: ++ * This bucket type defines a printf-style format and arguments. Similar ++ * to AP_BUCKET_STRINGS, this type also uses the ->va field to refer to ++ * the arguments. The format for the printf is stored in ->fmt. ++ * ++ * Also similar to AP_BUCKET_STRINGS, the va_start/va_end macros should ++ * not be used, and ->va should be processed only once. The bucket may ++ * not be passed after this processing. ++ * ++ * This type occurs when ap_rprintf(), ap_vrprintf(), ap_fc_printf(), or ++ * ap_fc_vprintf() is used by the upstream filter/generator. ++ * ++ * AP_BUCKET_FILE: ++ * This bucket type refers to an open file, from the current position ++ * and extending for ->flen bytes. Since there are some ap_file_t ++ * implementations/types that are not seekable, it may be impossible to ++ * "rewind" the file's current position after reading the contenxt. ++ * Therefore, it is important to note that once the content has been ++ * read, it must be passed to the next filter in a different form. ++ * ++ * Note: if there is a way to determine whether a file is seekable, then ++ * it would be legal to fetch the current position, read the contents, ++ * rewind to the original position, and then pass this bucket/file down ++ * to the next filter in the output chain. ++ * ++ * This type occurs when ap_send_fd(), ap_send_fd_length(), or ++ * ap_fc_sendfile() are used by the upstream filter/generator. ++ * ++ * AP_BUCKET_EOS: ++ * This bucket signals the end of the content stream. The filter should ++ * flush any internal state and issue errors if the state specifies that ++ * and end of stream cannot occur now (e.g. a command directive is ++ * incomplete). ++ * ++ * This type occurs when Apache finalizes a (sub)request, or when an ++ * upstream filter passes this bucket along. ++ */ ++typedef enum { ++ AP_BUCKET_PTRLEN, ++ AP_BUCKET_STRINGS, ++ AP_BUCKET_PRINTF, ++ AP_BUCKET_FILE, ++ AP_BUCKET_EOS ++} ap_bucket_type; ++ ++/* ++ * ap_bucket_t: ++ * ++ * The actual bucket definition. The type is determined by the ->type field. ++ * Which fields are valid/useful in the bucket is determined by the type, ++ * as noted below and in the comments above for each type. ++ * ++ * Buckets are arranged in a doubly-linked list so that a filter may insert, ++ * remove, or replace elements in a list of buckets. Generally, a filter ++ * should not change any bucket values other than these link pointers. ++ */ ++struct ap_bucket_t { ++ ap_bucket_type type; ++ ++ const char *buf; /* AP_BUCKET_PTRLEN */ ++ apr_size_t len; /* AP_BUCKET_PTRLEN */ ++ ++ const char *fmt; /* AP_BUCKET_PRINTF */ ++ va_list va; /* AP_BUCKET_STRINGS, _PRINTF */ ++ ++ apr_file_t *file; /* AP_BUCKET_FILE */ ++ apr_ssize_t flen; /* AP_BUCKET_FILE */ ++ ++ ap_bucket_t *next; /* next bucket in list */ ++ ap_bucket_t *prev; /* previous bucket in list */ ++}; ++ ++/* ++ * FILTER CHAIN OUTPUT FUNCTIONS ++ * ++ * These functions are used to deliver output/content down to the next ++ * filter in the chain. ++ * ++ * ap_fc_write(): write a block of bytes ++ * ap_fc_putc(): write a single character ++ * ap_fc_puts(): write a null-terminated string ++ * ap_fc_putstrs(): write a set of null-termianted strings; the end is ++ * signaled by a NULL parameter ++ * ap_fc_vputstrs(): same as ap_fc_putstrs(), but where the set of strings ++ * is defined by a va_list ++ * ap_fc_printf(): use printf-like semantics for writing a string ++ * ap_fc_vprintf(): use printf-like semantics, but with a va_list for the args ++ * ap_fc_sendfile(): send the file contents, from the current file position, ++ * and extending for "len" bytes; AP_FC_SENDFILE_ALL is ++ * used to send from current-position to the end-of-file. ++ * ap_fc_putbucket(): write a bucket into the filter chain ++ */ ++API_EXPORT(void) ap_fc_write(ap_filter_t *filter, const char *buf, ++ apr_size_t len); ++API_EXPORT(void) ap_fc_putc(ap_filter_t *filter, int c); ++API_EXPORT(void) ap_fc_puts(ap_filter_t *filter, const char *str); ++ ++API_EXPORT_NONSTD(void) ap_fc_putstrs(ap_filter_t *filter, ...); ++API_EXPORT(void) ap_fc_vputstrs(ap_filter_t *filter, va_list va); ++ ++API_EXPORT_NONSTD(void) ap_fc_printf(ap_filter_t *filter, ++ const char *fmt, ...); ++API_EXPORT(void) ap_fc_vprintf(ap_filter_t *filter, ++ const char *fmt, va_list va); ++ ++API_EXPORT(void) ap_fc_sendfile(ap_filter_t *filter, apr_file_t *file, ++ apr_ssize_t flen); ++#define AP_FC_SENDFILE_ALL ((apr_ssize_t) -1) ++ ++/* note: bucket->next and ->prev may be changed upon return from this */ ++API_EXPORT(void) ap_fc_putbucket(ap_filter_t *filter, ap_bucket_t *bucket); ++ + + /* + * ap_register_filter(): Index: main/http_protocol.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v -retrieving revision 1.95 -diff -u -r1.95 http_protocol.c ---- main/http_protocol.c 2000/07/11 03:48:18 1.95 -+++ main/http_protocol.c 2000/07/12 11:01:10 -@@ -77,6 +77,8 @@ +retrieving revision 1.100 +diff -u -r1.100 http_protocol.c +--- main/http_protocol.c 2000/08/02 05:26:48 1.100 ++++ main/http_protocol.c 2000/08/05 09:48:23 +@@ -77,6 +77,7 @@ + * support code... */ #include "util_date.h" /* For parseHTTPdate and BAD_DATE */ #include "util_charset.h" ++#include "util_filter.h" #include "mpm_status.h" -+#include "ap_filter.h" -+ - #ifdef HAVE_STDARG_H + #ifdef APR_HAVE_STDARG_H #include - #endif -@@ -99,6 +101,9 @@ +@@ -100,7 +101,10 @@ ap_bgetopt (r->connection->client, BO_BYTECT, &r->bytes_sent); \ } while (0) +#define DECL_FILTER_HEAD(r, f) \ + ap_filter_t f = { NULL, (r), NULL, 0, (r)->filters } -+ ++ /* if this is the first error, then log an INFO message and shut down the * connection. -@@ -406,6 +411,9 @@ + */ +@@ -407,6 +411,9 @@ API_EXPORT(int) ap_set_content_length(request_rec *r, long clength) { @@ -50,39 +246,24 @@ diff -u -r1.95 http_protocol.c + return 0; + r->clength = clength; - ap_table_setn(r->headers_out, "Content-Length", ap_psprintf(r->pool, "%ld", clength)); + apr_table_setn(r->headers_out, "Content-Length", apr_psprintf(r->pool, "%ld", clength)); return 0; -@@ -1277,8 +1285,17 @@ - rnew->main = (request_rec *) r; - } +@@ -1280,10 +1287,10 @@ -+static void flush_filters(request_rec *r) -+{ + static void end_output_stream(request_rec *r) + { +- /* +- ** ### place holder to tell filters that no more content will be +- ** ### arriving. typically, they will flush any pending content +- */ + DECL_FILTER_HEAD(r, filter); + ap_bucket_t bucket = { AP_BUCKET_EOS }; + + ap_fc_putbucket(&filter, &bucket); -+} -+ - void ap_finalize_sub_req_protocol(request_rec *sub) - { -+ flush_filters(sub); - SET_BYTES_SENT(sub->main); } -@@ -1832,11 +1849,6 @@ - #endif /*APACHE_XLATE*/ - } - --static void flush_filters(request_rec *r) --{ -- /* ### place holder to flush pending content through the filters */ --} -- - /* finalize_request_protocol is called at completion of sending the - * response. It's sole purpose is to send the terminating protocol - * information for any wrappers around the response message body -@@ -2475,107 +2487,88 @@ + void ap_finalize_sub_req_protocol(request_rec *sub) +@@ -2501,107 +2508,88 @@ API_EXPORT(int) ap_rputc(int c, request_rec *r) { @@ -124,8 +305,8 @@ diff -u -r1.95 http_protocol.c API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r) { -- ap_ssize_t n; -- ap_status_t rv; +- apr_ssize_t n; +- apr_status_t rv; + DECL_FILTER_HEAD(r, filter); if (r->connection->aborted) @@ -168,9 +349,9 @@ diff -u -r1.95 http_protocol.c { va_list va; - int n; -+ -+ DECL_FILTER_HEAD(r, filter); ++ DECL_FILTER_HEAD(r, filter); ++ if (r->connection->aborted) return EOF; @@ -214,7 +395,7 @@ diff -u -r1.95 http_protocol.c } API_EXPORT(int) ap_rflush(request_rec *r) -@@ -2589,6 +2582,210 @@ +@@ -2615,6 +2603,210 @@ return 0; } @@ -231,8 +412,8 @@ diff -u -r1.95 http_protocol.c + n = ap_bputc(*bscan->buf, filter->r->connection->client); + } + else { -+ ap_status_t rv; -+ ap_ssize_t written; ++ apr_status_t rv; ++ apr_ssize_t written; + + /* ### should loop to ensure everything is written */ + rv = ap_bwrite(filter->r->connection->client, bscan->buf, @@ -275,7 +456,7 @@ diff -u -r1.95 http_protocol.c +} + +API_EXPORT(void) ap_fc_write(ap_filter_t *filter, const char *buf, -+ ap_size_t len) ++ apr_size_t len) +{ + ap_filter_t *next; + ap_bucket_t bucket = { AP_BUCKET_PTRLEN, buf, len }; @@ -288,7 +469,7 @@ diff -u -r1.95 http_protocol.c + BUFF_filter_callback(filter, &bucket); + } + else { -+ (*next->bucket_cb)(next, &bucket); ++ (*next->filter_func)(next, &bucket); + } +} + @@ -306,7 +487,7 @@ diff -u -r1.95 http_protocol.c + BUFF_filter_callback(filter, &bucket); + } + else { -+ (*next->bucket_cb)(next, &bucket); ++ (*next->filter_func)(next, &bucket); + } +} + @@ -323,7 +504,7 @@ diff -u -r1.95 http_protocol.c + BUFF_filter_callback(filter, &bucket); + } + else { -+ (*next->bucket_cb)(next, &bucket); ++ (*next->filter_func)(next, &bucket); + } +} + @@ -352,7 +533,7 @@ diff -u -r1.95 http_protocol.c + BUFF_filter_callback(filter, &bucket); + } + else { -+ (*next->bucket_cb)(next, &bucket); ++ (*next->filter_func)(next, &bucket); + } +} + @@ -382,12 +563,12 @@ diff -u -r1.95 http_protocol.c + BUFF_filter_callback(filter, &bucket); + } + else { -+ (*next->bucket_cb)(next, &bucket); ++ (*next->filter_func)(next, &bucket); + } +} + -+API_EXPORT(void) ap_fc_sendfile(ap_filter_t *filter, ap_file_t *file, -+ ap_ssize_t flen) ++API_EXPORT(void) ap_fc_sendfile(ap_filter_t *filter, apr_file_t *file, ++ apr_ssize_t flen) +{ + ap_filter_t *next; + ap_bucket_t bucket = { @@ -402,7 +583,7 @@ diff -u -r1.95 http_protocol.c + BUFF_filter_callback(filter, &bucket); + } + else { -+ (*next->bucket_cb)(next, &bucket); ++ (*next->filter_func)(next, &bucket); + } +} + @@ -418,14 +599,14 @@ diff -u -r1.95 http_protocol.c + BUFF_filter_callback(filter, bucket); + } + else { -+ (*next->bucket_cb)(next, bucket); ++ (*next->filter_func)(next, bucket); + } +} + /* We should have named this send_canned_response, since it is used for any * response that can be generated by the server from the request record. * This includes all 204 (no content), 3xx (redirect), 4xx (client error), -@@ -2977,6 +3174,7 @@ +@@ -3003,6 +3195,7 @@ ap_finalize_request_protocol(r); ap_rflush(r); } @@ -433,77 +614,18 @@ diff -u -r1.95 http_protocol.c AP_IMPLEMENT_HOOK_RUN_ALL(int,post_read_request, (request_rec *r),(r),OK,DECLINED) -Index: main/http_request.c -=================================================================== -RCS file: /home/cvs/apache-2.0/src/main/http_request.c,v -retrieving revision 1.35 -diff -u -r1.35 http_request.c ---- main/http_request.c 2000/06/24 17:33:57 1.35 -+++ main/http_request.c 2000/07/12 11:01:23 -@@ -769,6 +769,9 @@ - rnew->htaccess = r->htaccess; - rnew->per_dir_config = r->server->lookup_defaults; - -+ /* start with the same set of output filters */ -+ rnew->filters = r->filters; -+ - ap_set_sub_req_protocol(rnew, r); - - /* would be nicer to pass "method" to ap_set_sub_req_protocol */ -@@ -857,6 +860,9 @@ - rnew->htaccess = r->htaccess; - rnew->chunked = r->chunked; - -+ /* start with the same set of output filters */ -+ rnew->filters = r->filters; -+ - ap_set_sub_req_protocol(rnew, r); - fdir = ap_make_dirstr_parent(rnew->pool, r->filename); - -@@ -960,16 +966,22 @@ - - API_EXPORT(int) ap_run_sub_req(request_rec *r) - { --#ifndef APACHE_XLATE -- int retval = ap_invoke_handler(r); --#else /*APACHE_XLATE*/ -- /* Save the output conversion setting of the caller across subrequests */ - int retval; -- ap_xlate_t *saved_xlate; - -- ap_bgetopt(r->connection->client, BO_WXLATE, &saved_xlate); -- retval = ap_invoke_handler(r); -- ap_bsetopt(r->connection->client, BO_WXLATE, &saved_xlate); -+ /* see comments in process_request_internal() */ -+ ap_run_insert_filter(r); -+ -+#ifndef APACHE_XLATE -+ retval = ap_invoke_handler(r); -+#else /*APACHE_XLATE*/ -+ { -+ /* Save the output conversion setting across subrequests */ -+ ap_xlate_t *saved_xlate; -+ -+ ap_bgetopt(r->connection->client, BO_WXLATE, &saved_xlate); -+ retval = ap_invoke_handler(r); -+ ap_bsetopt(r->connection->client, BO_WXLATE, &saved_xlate); -+ } - #endif /*APACHE_XLATE*/ - ap_finalize_sub_req_protocol(r); - return retval; -Index: main/Makefile.in +Index: main/util_filter.c =================================================================== -RCS file: /home/cvs/apache-2.0/src/main/Makefile.in,v -retrieving revision 1.16 -diff -u -r1.16 Makefile.in ---- main/Makefile.in 2000/07/01 14:14:15 1.16 -+++ main/Makefile.in 2000/07/12 11:01:35 -@@ -8,7 +8,7 @@ - http_protocol.c http_request.c http_vhost.c util.c util_date.c \ - util_script.c util_uri.c util_md5.c util_cfgtree.c util_ebcdic.c \ - rfc1413.c http_connection.c iol_file.c iol_socket.c listen.c \ -- mpm_common.c util_charset.c util_debug.c util_xml.c -+ mpm_common.c util_charset.c util_debug.c util_xml.c filters.c - - include $(top_srcdir)/build/ltlib.mk - +RCS file: /home/cvs/apache-2.0/src/main/util_filter.c,v +retrieving revision 1.3 +diff -u -r1.3 util_filter.c +--- main/util_filter.c 2000/08/05 04:38:58 1.3 ++++ main/util_filter.c 2000/08/05 09:48:23 +@@ -126,6 +126,7 @@ + f->filter_func = frec->filter_func; + f->ctx = ctx; + f->ftype = frec->ftype; ++ f->r = r; + + if (INSERT_BEFORE(f, r->filters)) { + f->next = r->filters; diff --git a/buckets/register_patch.txt b/buckets/register_patch.txt deleted file mode 100644 index 07c1ae41b..000000000 --- a/buckets/register_patch.txt +++ /dev/null @@ -1,142 +0,0 @@ -Index: Makefile.in -=================================================================== -RCS file: /home/cvs/apache-2.0/src/main/Makefile.in,v -retrieving revision 1.16 -diff -u -r1.16 Makefile.in ---- Makefile.in 2000/07/01 14:14:15 1.16 -+++ Makefile.in 2000/07/25 00:42:50 -@@ -8,7 +8,8 @@ - http_protocol.c http_request.c http_vhost.c util.c util_date.c \ - util_script.c util_uri.c util_md5.c util_cfgtree.c util_ebcdic.c \ - rfc1413.c http_connection.c iol_file.c iol_socket.c listen.c \ -- mpm_common.c util_charset.c util_debug.c util_xml.c -+ mpm_common.c util_charset.c util_debug.c util_xml.c \ -+ util_filter.c - - include $(top_srcdir)/build/ltlib.mk - -Index: httpd.h -=================================================================== -RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v -retrieving revision 1.64 -diff -u -r1.64 httpd.h ---- httpd.h 2000/06/30 21:18:13 1.64 -+++ httpd.h 2000/07/25 00:49:52 -@@ -731,7 +731,9 @@ - #ifdef APACHE_XLATE - struct ap_rr_xlate *rrx; - #endif /*APACHE_XLATE*/ -- -+ -+ struct ap_filter_t *filters; -+ - /* Things placed at the end of the record to avoid breaking binary - * compatibility. It would be nice to remember to reorder the entire - * record to improve 64bit alignment the next time we need to break -Index: http_request.c -=================================================================== -RCS file: /home/cvs/apache-2.0/src/main/http_request.c,v -retrieving revision 1.35 -diff -u -r1.35 http_request.c ---- http_request.c 2000/06/24 17:33:57 1.35 -+++ http_request.c 2000/07/25 00:50:35 -@@ -769,6 +769,9 @@ - rnew->htaccess = r->htaccess; - rnew->per_dir_config = r->server->lookup_defaults; - -+ /* start with the same set of output filters */ -+ rnew->filters = r->filters; -+ - ap_set_sub_req_protocol(rnew, r); - - /* would be nicer to pass "method" to ap_set_sub_req_protocol */ -@@ -857,6 +860,9 @@ - rnew->htaccess = r->htaccess; - rnew->chunked = r->chunked; - -+ /* start with the same set of output filters */ -+ rnew->filters = r->filters; -+ - ap_set_sub_req_protocol(rnew, r); - fdir = ap_make_dirstr_parent(rnew->pool, r->filename); - -@@ -960,16 +966,22 @@ - - API_EXPORT(int) ap_run_sub_req(request_rec *r) - { --#ifndef APACHE_XLATE -- int retval = ap_invoke_handler(r); --#else /*APACHE_XLATE*/ -- /* Save the output conversion setting of the caller across subrequests */ - int retval; -- ap_xlate_t *saved_xlate; - -- ap_bgetopt(r->connection->client, BO_WXLATE, &saved_xlate); -- retval = ap_invoke_handler(r); -- ap_bsetopt(r->connection->client, BO_WXLATE, &saved_xlate); -+ /* see comments in process_request_internal() */ -+ ap_run_insert_filter(r); -+ -+#ifndef APACHE_XLATE -+ retval = ap_invoke_handler(r); -+#else /*APACHE_XLATE*/ -+ { -+ /* Save the output conversion setting across subrequests */ -+ ap_xlate_t *saved_xlate; -+ -+ ap_bgetopt(r->connection->client, BO_WXLATE, &saved_xlate); -+ retval = ap_invoke_handler(r); -+ ap_bsetopt(r->connection->client, BO_WXLATE, &saved_xlate); -+ } - #endif /*APACHE_XLATE*/ - ap_finalize_sub_req_protocol(r); - return retval; -Index: http_protocol.c -=================================================================== -RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v -retrieving revision 1.97 -diff -u -r1.97 http_protocol.c ---- http_protocol.c 2000/07/21 19:50:47 1.97 -+++ http_protocol.c 2000/07/25 11:47:14 -@@ -1278,8 +1278,19 @@ - rnew->main = (request_rec *) r; - } - -+static void end_output_stream(request_rec *r) -+{ -+ /* -+ ** ### place holder to tell filters that no more content will be -+ ** ### arriving. typically, they will flush any pending content -+ */ -+} -+ - void ap_finalize_sub_req_protocol(request_rec *sub) - { -+ /* tell the filter chain there is no more content coming */ -+ end_output_stream(sub); -+ - SET_BYTES_SENT(sub->main); - } - -@@ -1833,11 +1844,6 @@ - #endif /*APACHE_XLATE*/ - } - --static void flush_filters(request_rec *r) --{ -- /* ### place holder to flush pending content through the filters */ --} -- - /* finalize_request_protocol is called at completion of sending the - * response. It's sole purpose is to send the terminating protocol - * information for any wrappers around the response message body -@@ -1845,7 +1851,8 @@ - */ - API_EXPORT(void) ap_finalize_request_protocol(request_rec *r) - { -- flush_filters(r); -+ /* tell the filter chain there is no more content coming */ -+ end_output_stream(r); - - if (r->chunked && !r->connection->aborted) { - #ifdef APACHE_XLATE diff --git a/buckets/util_filter.c b/buckets/util_filter.c deleted file mode 100644 index 228491bca..000000000 --- a/buckets/util_filter.c +++ /dev/null @@ -1,146 +0,0 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2000 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * nor may "Apache" appear in their name, without prior written - * permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -#include "util_filter.h" - -/* - * ap_filter_rec_t: - * - * This (internal) structure is used for recording information about the - * registered filters. It associates a name with the filter's callback - * and filter type. - * - * At the moment, these are simply linked in a chain, so a ->next pointer - * is available. - */ -typedef struct ap_filter_rec_t { - const char *name; - apr_filter_func filter_func; - ap_filter_type ftype; - - struct ap_filter_rec_t *next; -} ap_filter_rec_t; - -/* ### make this visible for direct manipulation? - ### use a hash table -*/ -static ap_filter_rec_t *registered_filters = NULL; - -/* NOTE: Apache's current design doesn't allow a pool to be passed thu, - so we depend on a global to hold the correct pool -*/ -#define FILTER_POOL ap_global_hook_pool -#include "ap_hooks.h" /* for ap_global_hook_pool */ - -/* -** This macro returns true/false if a given filter should be inserted BEFORE -** another filter. This will happen when one of: 1) there isn't another -** filter; 2) that filter has a higher filter type (class); 3) that filter -** corresponds to a different request. -*/ -#define INSERT_BEFORE(f, before_this) ((before_this) == NULL \ - || (before_this)->ftype > (f)->ftype) - - -static apr_status_t filter_cleanup(void *ctx) -{ - registered_filters = NULL; - return APR_SUCCESS; -} - -API_EXPORT(void) ap_register_filter(const char *name, - apr_filter_func filter_func, - ap_filter_type ftype) -{ - ap_filter_rec_t *frec = apr_palloc(FILTER_POOL, sizeof(*frec)); - - frec->name = name; - frec->filter_func = filter_func; - frec->ftype = ftype; - - frec->next = registered_filters; - registered_filters = frec; - - apr_register_cleanup(FILTER_POOL, NULL, filter_cleanup, NULL); -} - -API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r) -{ - ap_filter_rec_t *frec = registered_filters; - - for (; frec != NULL; frec = frec->next) { - if (!strcasecmp(name, frec->name)) { - apr_filter_t *f = apr_pcalloc(r->pool, sizeof(*f)); - - f->filter_func = frec->filter_func; - f->ctx = ctx; - f->ftype = frec->ftype; - - if (INSERT_BEFORE(f, r->filters)) { - f->next = r->filters; - r->filters = f; - } - else { - apr_filter_t *fscan = r->filters; - while (!INSERT_BEFORE(f, fscan->next)) - fscan = fscan->next; - f->next = fscan->next; - fscan->next = f; - } - - break; - } - } -} - diff --git a/buckets/util_filter.h b/buckets/util_filter.h deleted file mode 100644 index 1c523abf9..000000000 --- a/buckets/util_filter.h +++ /dev/null @@ -1,220 +0,0 @@ -/* ==================================================================== - * The Apache Software License, Version 1.1 - * - * Copyright (c) 2000 The Apache Software Foundation. All rights - * reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: - * "This product includes software developed by the - * Apache Software Foundation (http://www.apache.org/)." - * Alternately, this acknowledgment may appear in the software itself, - * if and wherever such third-party acknowledgments normally appear. - * - * 4. The names "Apache" and "Apache Software Foundation" must - * not be used to endorse or promote products derived from this - * software without prior written permission. For written - * permission, please contact apache@apache.org. - * - * 5. Products derived from this software may not be called "Apache", - * nor may "Apache" appear in their name, without prior written - * permission of the Apache Software Foundation. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - */ - -#ifndef AP_FILTER_H -#define AP_FILTER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef APR_HAVE_STDARG_H -#include -#endif - -#include "httpd.h" -#include "apr.h" - -/* - * FILTER CHAIN - * - * Filters operate using a "chaining" mechanism. The filters are chained - * together into a sequence. When output is generated, it is passed through - * each of the filters on this chain, until it reaches the end (or "bottom") - * and is placed onto the network. - * - * The top of the chain, the code generating the output, is typically called - * a "content generator." The content generator's output is fed into the - * filter chain using the standard Apache output mechanisms: ap_rputs(), - * ap_rprintf(), ap_rwrite(), etc. - * - * Each filter is defined by a callback. This callback takes the output from - * the previous filter (or the content generator if there is no previous - * filter), operates on it, and passes the result to the next filter in the - * chain. This pass-off is performed using the ap_fc_* functions, such as - * ap_fc_puts(), ap_fc_printf(), ap_fc_write(), etc. - * - * When content generation is complete, the system will pass an "end of - * stream" marker into the filter chain. The filters will use this to flush - * out any internal state and to detect incomplete syntax (for example, an - * unterminated SSI directive). - */ - -/* forward declare the filter type */ -typedef struct apr_filter_t apr_filter_t; - -/* - * apr_filter_func: - * - * This function type is used for filter callbacks. It will be passed a - * pointer to "this" filter, and a "bucket" containing the content to be - * filtered. - * - * In filter->ctx, the callback will find its context. This context is - * provided here, so that a filter may be installed multiple times, each - * receiving its own per-install context pointer. - * - * Callbacks are associated with a filter definition, which is specified - * by name. See ap_register_filter() for setting the association between - * a name for a filter and its associated callback (and other information). - * - * The *bucket structure (and all those referenced by ->next and ->prev) - * should be considered "const". The filter is allowed to modify the - * next/prev to insert/remove/replace elements in the bucket list, but - * the types and values of the individual buckets should not be altered. - */ -typedef apr_status_t (*apr_filter_func)(); - -/* - * ap_filter_type: - * - * Filters have different types/classifications. These are used to group - * and sort the filters to properly sequence their operation. - * - * AP_FTYPE_CONTENT: - * These filters are used to alter the content that is passed through - * them. Examples are SSI or PHP. - * - * AP_FTYPE_CONNECTION: - * These filters will alter the content, but in ways that are more - * strongly associated with the output connection. Examples are - * compression, character recoding, or chunked transfer coding. - * - * It is important to note that these types of filters are not allowed - * in a sub-request. A sub-requests output can certainly be filtered - * by AP_FTYPE_CONTENT filters, but all of the "final processing" is - * determined by the main request. - * - * The types have a particular sort order, which allows us to insert them - * into the filter chain in a determistic order. Within a particular grouping, - * the ordering is equivalent to the order of calls to ap_add_filter(). - */ -typedef enum { - AP_FTYPE_CONTENT, - AP_FTYPE_CONNECTION -} ap_filter_type; - -/* - * apr_filter_t: - * - * This is the request-time context structure for an installed filter (in - * the output filter chain). It provides the callback to use for filtering, - * the request this filter is associated with (which is important when - * an output chain also includes sub-request filters), the context for this - * installed filter, and the filter ordering/chaining fields. - * - * Filter callbacks are free to use ->ctx as they please, to store context - * during the filter process. Generally, this is superior over associating - * the state directly with the request. A callback should not change any of - * the other fields. - */ -struct apr_filter_t { - apr_filter_func filter_func; - - void *ctx; - - ap_filter_type ftype; - apr_filter_t *next; -}; - -/* - * ap_register_filter(): - * - * This function is used to register a filter with the system. After this - * registration is performed, then a filter may be added into the filter - * chain by using ap_add_filter() and simply specifying the name. - * - * The filter's callback and type should be passed. - */ -API_EXPORT(void) ap_register_filter(const char *name, - apr_filter_func filter_func, - ap_filter_type ftype); - -/* - * ap_add_filter(): - * - * Adds a named filter into the filter chain on the specified request record. - * The filter will be installed with the specified context pointer. - * - * Filters added in this way will always be placed at the end of the filters - * that have the same type (thus, the filters have the same order as the - * calls to ap_add_filter). If the current filter chain contains filters - * from another request, then this filter will be added before those other - * filters. - */ -API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r); - - -/* - * Things to do later: - * Add parameters to apr_filter_func type. Those parameters will be something - * like: - * (request_rec *r, apr_filter_t *filter, ap_data_list *the_data) - * obviously, the request_rec is the current request, and the filter - * is the current filter stack. The data_list is a bucket list or - * bucket_brigade, but I am trying to keep this patch neutral. (If this - * comment breaks that, well sorry, but the information must be there - * somewhere. :-) - * - * Add a function like ap_pass_data. This function will basically just - * call the next filter in the chain, until the current filter is NULL. If the - * current filter is NULL, that means that nobody wrote to the network, and - * we have a HUGE bug, so we need to return an error and log it to the - * log file. - */ -#ifdef __cplusplus -} -#endif - -#endif /* !AP_FILTER_H */ -- cgit v1.2.1