意外とあっさりできたのでびっくり。
ひな形を作る
apxsをWindowsにインストールするのは大変そうなので、ここだけLinuxで実行。
~/work# apxs -g -n test Creating [DIR] test Creating [FILE] test/Makefile Creating [FILE] test/modules.mk Creating [FILE] test/mod_test.c Creating [FILE] test/.deps ~/work# ll test 合計 20 drwxr-xr-x 2 root root 4096 1月18日 13:28 ./ drwxr-xr-x 3 root root 4096 1月18日 13:28 ../ -rw-r--r-- 1 root root 0 1月18日 13:28 .deps -rw-r--r-- 1 root root 942 1月18日 13:28 Makefile -rw-r--r-- 1 root root 2046 1月18日 13:28 mod_test.c -rw-r--r-- 1 root root 148 1月18日 13:28 modules.mk
mod_test.c
/* ** mod_test.c -- Apache sample test module ** [Autogenerated via ``apxs -n test -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_test.c ** ** Then activate it in Apache's apache2.conf file for instance ** for the URL /test in as follows: ** ** # apache2.conf ** LoadModule test_module modules/mod_test.so ** <Location /test> ** SetHandler test ** </Location> ** ** Then after restarting Apache via ** ** $ apachectl restart ** ** you immediately can request the URL /test and watch for the ** output of this module. This can be achieved for instance via: ** ** $ lynx -mime_header http://localhost/test ** ** 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_test.c */ #include "httpd.h" #include "http_config.h" #include "http_protocol.h" #include "ap_config.h" /* The sample content handler */ static int test_handler(request_rec *r) { if (strcmp(r->handler, "test")) { return DECLINED; } r->content_type = "text/html"; if (!r->header_only) ap_rputs("The sample page from mod_test.c\n", r); return OK; } static void test_register_hooks(apr_pool_t *p) { ap_hook_handler(test_handler, NULL, NULL, APR_HOOK_MIDDLE); } /* Dispatch list for API hooks */ module AP_MODULE_DECLARE_DATA test_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 */ test_register_hooks /* register hooks */ };
ビルド
mod_test.cをWindowsに持ってきて、libhttpd.libにリンクしてビルドする。
(/MTでビルドするか、Apacheの実行時にmsvcr80.dllにパスを通す)