目次
背景apache2.0のmodでrequest filterを作ることになったので、その際のメモ。modの要件
httpd.confへの設定参考
www.apache.orgより
おまけ?wmoduleベースでpyukiwiki焼き直しproject?PBG4でも、ThinkPad?でもメモ帳代わりにApache+PyukiWikiを入れて使ってます。 お遊びでmoduleでwikiを作るのもありかなと思ってみました。mod_perlか aprでmoduleを書いてみようかなと。。。
サンプル実装 1とりあえず作ってみた版。これと httpd.confにLoadModule?を書いておけば、 全てのリクエストの呼び出しhookされる。httpd.confへの記述LoadModule magetest_module modules/mod_magetest.so moduleソース/* ** mod_magetest.c -- Apache sample magetest module ** [Autogenerated via ``apxs -n magetest -g''] ** ** To play with this sample module first compile it into a ** DSO file and install it into Apache's modules directory ** by running: ** ** $ apxs -c -i mod_magetest.c ** ** Then activate it in Apache's httpd.conf file for instance ** for the URL /magetest in as follows: ** ** # httpd.conf ** LoadModule magetest_module modules/mod_magetest.so ** <Location /magetest> ** SetHandler magetest ** </Location> ** ** Then after restarting Apache via ** ** $ apachectl restart ** ** you immediately can request the URL /magetest and watch for the ** output of this module. This can be achieved for instance via: ** ** $ lynx -mime_header http://localhost/magetest ** ** The output should be similar to the following one: ** ** HTTP/1.1 200 OK ** Date: Tue, 31 Mar 1998 14:42:22 GMT ** Server: Apache/1.3.4 (Unix) ** Connection: close ** Content-Type: text/html ** ** The sample page from mod_magetest.c */ #include "httpd.h" #include "http_config.h" #include "http_protocol.h" #include "ap_config.h" /* The sample content handler */ static int magetest_handler(request_rec *r) { char *hdr; hdr = apr_table_get(r->headers_in, "X-MAGE-TEST"); if ( hdr ) { return HTTP_FORBIDDEN; } else { // do nothing } return OK; } static void magetest_register_hooks(apr_pool_t *p) { ap_hook_post_read_request(magetest_handler, NULL, NULL, APR_HOOK_MIDDLE); //ap_hook_handler(magetest_handler, NULL, NULL, APR_HOOK_MIDDLE); // この場合、Content Handlerになる。ハンドラ識別名は magetest。 // SetHandlerや SetInputFilterの対象はこの名前にしとくこと。 } /* Dispatch list for API hooks */ module AP_MODULE_DECLARE_DATA magetest_module = { STANDARD20_MODULE_STUFF, NULL, /* create per-dir config structures */ NULL, /* merge per-dir config structures */ NULL, /* create per-server config structures */ NULL, /* merge per-server config structures */ NULL, /* table of config file commands */ magetest_register_hooks /* register hooks */ }; |