Apache 2.0のfilterを調べる

最終目標

Apacheがクライアントに対して送信(出力)したContentを自作モジュールから参照したい。

filter?

Apache 2.0に実装されたfilterを使用すればこれが実現できそうだ。ということでいろいろ調べています。
まずは公式ドキュメントを読み始めるも意味がよくわからん。
How filters work in Apache 2.0 - Apache HTTP Server(英語)


filterには protocol filter と resource filter の2種類があるようだ。
んで、多分目的のものは resource filter かな?。


勝手なイメージだが filter関数をフックしておくと何かのタイミングで Apacheの中の人が呼び出してくれるのだろう。


mod_deflateが filter を使っているっぽいのでソースを見てみる(Apache本体のソースに付属しています。)

フィルタ関数?のインターフェース

apr_bucket_brigadeって何???

static apr_status_t deflate_out_filter(ap_filter_t *f,
                                       apr_bucket_brigade *bb)
{
    apr_bucket *e;
    request_rec *r = f->r;
    deflate_ctx *ctx = f->ctx;

ap_filter_t

struct ap_filter_t {
    /** The internal representation of this filter.  This includes
     *  the filter's name, type, and the actual function pointer.
     */
    ap_filter_rec_t *frec;

    /** A place to store any data associated with the current filter */
    void *ctx;

    /** The next filter in the chain */
    ap_filter_t *next;

    /** The request_rec associated with the current filter.  If a sub-request
     *  adds filters, then the sub-request is the request associated with the
     *  filter.
     */
    request_rec *r;

    /** The conn_rec associated with the current filter.  This is analogous
     *  to the request_rec, except that it is used for input filtering.
     */
    conn_rec *c;
;}

filter chainというのがあるんだな。↑の英語ドキュメントでもstack云々が書かれていたな。

filterの登録

これは予想通り。

static void register_hooks(apr_pool_t *p)
{
    ap_register_output_filter(deflateFilterName, deflate_out_filter, NULL,
                              AP_FTYPE_CONTENT_SET);
    ap_register_input_filter(deflateFilterName, deflate_in_filter, NULL,
                              AP_FTYPE_CONTENT_SET);
}

apr_bucket_brigade

これはなんだろう。継続調査で。

資料になりそうなもの

http://qb5.2ch.net/test/read.cgi/operate/1105909861/
MODULE.JP - POSTされたデータをInput Filterで検査する


というかこの手の話題では、必ず小山さんのサイトが出てくるのがかっこいいな。
実はOSC2005で一度お会いしてお話したのですが、サインもらっておけばよかったかな。。