On Fri, Aug 24, 2001 at 06:54:31PM -0400, Cliff Woolley wrote: > On Fri, 24 Aug 2001, Greg Stein wrote: > > > Okay... let's back up. I believe that some poor advice may have been given. > > > > For now, let's assume that bPayload *does* have the entire content. Given > > that, there is *no* reason to copy the darn payload into a new brigade. > > > > The whole *idea* of the filters and the brigades is that you modify the > > brigade passed to you, and then pass it on down. Thus, your operation is > > like this: > > Oh, duh, yeah of course. Thanks for clearing the air. =-) I wasn't > thinking from the beginning. I started with the assumption that we had > two brigades and we wanted to combine them or twiddle them in some way > (which filters do all the time), missing the obvious fact that in THIS > case you don't have to do that. Tack some stuff onto the beginning, pass > it down. That's it. Well, anyway, now you (Eric) know what the rules are > if you have a more complicated case. Yeah, I figured I could be more economical and have been shamed into it. I wrote up some docs for filters and buckets (attached) but didn't work this lesson into it. Take a look and see if you think they are useful. I haven't put a lot of polish on them, but they should be a good conversation starter. The documents are written to be peers of http://httpd.apache.org/docs-2.0/developer/hooks.html. > Thanks Greg. :) And thanks from me. -- -eric ([EMAIL PROTECTED]) Feel free to forward this message to any list for any purpose other than email address distribution.Title: Apache 2.0 Filter Functions
Apache HTTP Server Version 2.0Apache Filter FunctionsHTTP requests are read from the network and passed through a series of input filters. Responses are fabricated by generators and passed through a series of output filters. These filters may prepend or append the stream or replace it entirely. Modules and core functions register and enable filters via the filter API (@@@ would like an href to some docs auto-generated from include/util_filter.h if such exist). Registering a filterDuring initialization, modules and core functions register input and output filters using the filter API: void ap_register_input_filter(const char *name, ap_in_filter_func filter_func, ap_filter_type ftype) void ap_register_output_filter(const char *name, ap_out_filter_func filter_func, ap_filter_type ftype)
Calling conventions and contractsFilters may be called repeatedly. Filters store context needed between calls in the ap_filter_t's ctx pointer. Eventually, each filter should call the downstream filters by calling ap_pass_brigade with ap_filter_t's next filter. Example: serving a fileIn the common paradigm, one or more AP_FTYPE_CONTENT filters are passed a brigade by the content generator. For example, from the default_handler which serves file requests: bb = apr_brigade_create(r->pool); e = apr_bucket_file_create(fd, 0, r->finfo.size); APR_BRIGADE_INSERT_HEAD(bb, e); e = apr_bucket_eos_create(); APR_BRIGADE_INSERT_TAIL(bb, e); return ap_pass_brigade(r->output_filters, bb); The next filters executed are those registered as AP_FTYPE_HTTP_HEADER. The ap_http_header_filter function generates a brigade with the response code and mime headers. This brigade is passed to TRANSCODE and CONNECTION filters: ... b2 = apr_brigade_create(r->pool); basic_http_header(r, b2, protocol); ... ap_pass_brigade(f->next, b2); ... ap_http_header_filter removes itself (why?) from the list of filters and calls the downstream filters again with the content brigade: ... ap_remove_output_filter(f); return ap_pass_brigade(f->next, b);Eric Prud'hommeaux, 24th August 2001 Apache HTTP Server Version 2.0 |
Apache HTTP Server Version 2.0Buckets and Bucket BrigadesBuckets provide uniform access to a variety of data sources. Bucket brigades are collections of buckets usually use to represent a block of data. For instance, a bucket brigade may contain buckets of headers allocated from a request pool followed by a bucket representing a local file. A filter can add data before or after this file block without having to copy the the data. apr_brigade_to_iovec makes it easy to pass this scatter-write paradigm through the sockets layer all the way to the ethernet and disk controllers. Table of contentsTypes of bucketsApache provides a set of standard bucket types allowing data collection from a variety of sources:
Bucket virual functionsBuckets implement a set of virtual functions so access and state in different bucket types may be handled uniformly. Following is a list of parameters and a description of each type of bucket followed by the funtion to be used if the bucket does not implement the virtual function:
Note: all of the above except destroy and delete return a apr_status_t. Because some buckets have unimplemented functions, and some do not maintain a length, callers must be prepared to work around these limitations. Using buckets and bucket brigadesThis section will (attempt to) provide an outline of the uses of buckets and a small vocabulary of idioms used to accomplish common tasks. Bucket type and function namesThere are strict naming conventions for the bucket types. The typedef name can be found by prepending the name with "apr_bucket_type_", for example, the pool bucket: b.type = apr_bucket_type_pool The create function, takes the prototype described above, eg: apr_bucket * apr_bucket_pool_create(const char *buf, apr_size_t nbyte, apr_pool_t *pool); The make function, recommended only for bucket implementers, takes a pointer to an apr_bucket plus the prototype described above: apr_bucket * apr_bucket_pool_make(apr_bucket *b, const char *buf, apr_size_t nbyte, apr_pool_t *pool); Each type also has a macro to test type. For brevity and maintenance purposes, it is recommended that you use this macro and not manipulation of the bucket data structure. APR_BUCKET_IS_POOL(bucket) Calling conventions and contractsfilter conventions dictate the use of buckets. Filters that manipulate a brigade may rely on brigade and bucket functions but are expected to deliver a coherent bucket to subsequent filters via Common idioms
Brigade functionsFollowing is a list of the bucket brigade API functions: Brigade creation and destruction
Adding data to brigades
Brigade data consumption
Misc
Brigade macrosFollowing is a set of macros to manipulate and to tests on a bucket brigade. For brevity and maintenance purposes, it is recommended that you use these macros and not manipulation of the bucket and brigade data structures.
Bucket list manipluation macrosBuckets are srclib/apr-util/include/apr_ring.h (see srclib/apr-util/include/apr_ring.h) so a bucket has pointers to previous and next neighbors. Following is a list of macros for manipulating the list features of buckets. For brevity and maintenance purposes, it is recommended that you use these macros and not manipulation of the bucket and brigade data structures.
Apache HTTP Server Version 2.0 |