Apacheモジュール(2.2系統用)
久々に技術系っぽい話題。。。なのですが、内容は全然ヘタれ系で恐縮です。
ものすごーく以前の話ですが(1・2)、2年くらい軽く放置してたら(サボってたら)ツケが回ってきたようで、ここ数日間で本丸対応(移植)を急ぐハメになってしまいました。_| ̄|○
移植の手順はApache1.3系統とApache2.2系統のソースをgrepしまくって対比を見つつ、以下のファイルを参考がてらに進行していきました。
/usr/local/src/httpd-2.2.11/include/httpd.h /usr/local/src/httpd-2.2.11/include/httpd_log.h /usr/local/src/httpd-2.2.11/modules/aaa/mod_auth_basic.c /usr/local/src/httpd-2.2.11/modules/experimental/mod_example.c /usr/local/src/httpd-2.2.11/modules/metadata/mod_usertrack.c /usr/local/src/httpd-2.2.11/modules/metadata/mod_unique_id.c /usr/local/src/httpd-2.2.11/modules/metadata/mod_mime_magic.c /usr/local/src/httpd-2.2.11/modules/proxy/mod_proxy_balancer.c
行き詰ったキーワードでググってみたりと、主にこの辺(1・2・3・4・5・6)のページを参考にさせてもらいました。このような有益な情報を公開していただき感謝です。
hookの仕方が結構変わっていて、そこに気づくまでが一番ハマったのですが、それ以外は比較的スムーズに移植できました。
っていうか、先にマニュアル等々は目を通しておけよな!って感じでした。相変わらず体当たりしまくりで、全然成長していない自分に脱帽です。効率悪スギ。_| ̄|○
mod_example.cの中身(void x_register_hooks関数)を見ていただけると分かりますが、hook登録用の関数が沢山用意されているので、目的の位置で関数を登録すればよい。。。と。今回の場合はap_hook_access_checker関数を使えば目的は達成できました。後は関数のプレフィックスを「ap_」から「apr_」に変えた程度。
結局、関係者全員で協議した結果、本丸対応をしなくても良くなったのですが、個人的には色々と勉強になりました。特にaprのライブラリは(もうちょっと)深追いしてみようか。。。という気になりました。
で、昔に作った練習用モジュールの存在を思い出したので、復習がてら移植を行ってみました。
以前と比べたら「apache モジュール 作成」で検索結果に該当したページの充実ぶりが良い感じです。。。っていうか、Apacheモジュールなんて(ネタ的には)今更な感じもしますけどね。24周遅れで(ようやく)到達です。(w
mod_datetimelimit22(2.2系統用)
元ネタはコチラ。
この練習用モジュールを Apache 2.2 で利用できるよう移植してみました。
ただ、劣化移植なのでマルチスレッド環境で動かす場合は(別途)考慮が必要です。
ソースを掲載すると長くなるので差分ダケ。分かりやすいように少しだけ改変していますが、何が変わったかは容易に判断できるかと思いますので参考程度に、ということで。
--- mod_datetimelimit13.c 2009-06-08 16:29:39.314327000 +0900 +++ mod_datetimelimit22.c 2009-06-08 16:29:39.481327000 +0900 @@ -39,14 +40,14 @@ char *end_location_softbank; } datetimelimit_config; -module MODULE_VAR_EXPORT datetimelimit_module; +module AP_MODULE_DECLARE_DATA datetimelimit_module; /************************************************************************** define of main function **************************************************************************/ -static void *datetimelimit_cdir_config( pool *pool, char *path ) +static void *datetimelimit_cdir_config( apr_pool_t *pool, char *path ) { - datetimelimit_config *cfg = (datetimelimit_config *)ap_pcalloc( pool, sizeof( datetimelimit_config ) ); + datetimelimit_config *cfg = (datetimelimit_config *)apr_pcalloc( pool, sizeof( datetimelimit_config ) ); cfg->start_location_pc = NULL; cfg->start_location_docomo = NULL; @@ -65,7 +66,7 @@ } /*************************************************************************/ -static const char *set_datetimelimit_start_location_pc( cmd_parms *parms, void *myconfig, char *Buffer ) +static const char *set_datetimelimit_start_location_pc( cmd_parms *parms, void *myconfig, const char *Buffer ) { datetimelimit_config *cfg = (datetimelimit_config *)myconfig; @@ -79,13 +80,13 @@ return "duplicate entry for DateTimeLimitStartLocationURL_PC."; } - cfg->start_location_pc = ap_pstrdup( parms->pool, Buffer ); + cfg->start_location_pc = (char *)apr_pstrdup( parms->pool, Buffer ); return NULL; } /*************************************************************************/ -static const char *set_datetimelimit_start_location_docomo( cmd_parms *parms, void *myconfig, char *Buffer ) +static const char *set_datetimelimit_start_location_docomo( cmd_parms *parms, void *myconfig, const char *Buffer ) { datetimelimit_config *cfg = (datetimelimit_config *)myconfig; @@ -311,12 +312,11 @@ int Result; Result = 0; - - agent = ap_table_get( rec->headers_in, "User-Agent" ); + agent = apr_table_get( rec->headers_in, "User-Agent" ); @@ -574,7 +601,7 @@ } } - ap_table_setn( rec->headers_out, "Location", url ); + apr_table_setn( rec->headers_out, "Location", url ); return HTTP_MOVED_TEMPORARILY; } @@ -674,12 +729,12 @@ **************************************************************************/ static int datetimelimit_is_digit( const char *Buffer ) { - if( !ap_isdigit( *Buffer ) ) + if( !apr_isdigit( *Buffer ) ) { return 0; } - while( ap_isdigit( *( ++Buffer ) ) ) + while( apr_isdigit( *( ++Buffer ) ) ) { } @@ -689,53 +744,47 @@ /************************************************************************** Dispatch list for API hooks **************************************************************************/ -static command_rec datetimelimit_cmds[] = +static const command_rec datetimelimit_cmds[] = { - { "DateTimeLimitLocationStartURL_PC", set_datetimelimit_start_location_pc, NULL, OR_LIMIT, TAKE1, - "specify location start URL for PC" }, - { "DateTimeLimitLocationStartURL_DOCOMO", set_datetimelimit_start_location_docomo, NULL, OR_LIMIT, TAKE1, - "specify location start URL for DOCOMO" }, - { "DateTimeLimitLocationStartURL_EZWEB", set_datetimelimit_start_location_ezweb, NULL, OR_LIMIT, TAKE1, - "specify location start URL for EZWEB" }, - { "DateTimeLimitLocationStartURL_SOFTBANK", set_datetimelimit_start_location_softbank, NULL, OR_LIMIT, TAKE1, - "specify location start URL for SOFTBANK" }, - { "DateTimeLimitLocationEndURL_PC", set_datetimelimit_end_location_pc, NULL, OR_LIMIT, TAKE1, - "specify location end URL for PC" }, - { "DateTimeLimitLocationEndURL_DOCOMO", set_datetimelimit_end_location_docomo, NULL, OR_LIMIT, TAKE1, - "specify location end URL for DOCOMO" }, - { "DateTimeLimitLocationEndURL_EZWEB", set_datetimelimit_end_location_ezweb, NULL, OR_LIMIT, TAKE1, - "specify location end URL for EZWEB" }, - { "DateTimeLimitLocationEndURL_SOFTBANK", set_datetimelimit_end_location_softbank, NULL, OR_LIMIT, TAKE1, - "specify location end URL for SOFTBANK" }, - { "DateTimeLimitStartDate", set_datetimelimit_start_date, NULL, OR_LIMIT, TAKE1, - "specify start DATE" }, - { "DateTimeLimitStartTime", set_datetimelimit_start_time, NULL, OR_LIMIT, TAKE1, - "specify start TIME" }, - { "DateTimeLimitEndDate", set_datetimelimit_end_date, NULL, OR_LIMIT, TAKE1, - "specify start DATE" }, - { "DateTimeLimitEndTime", set_datetimelimit_end_time, NULL, OR_LIMIT, TAKE1, - "specify start TIME" }, + AP_INIT_TAKE1( "DateTimeLimitLocationStartURL_PC", set_datetimelimit_start_location_pc, + NULL, OR_LIMIT, "specify location start URL for PC" ), + AP_INIT_TAKE1( "DateTimeLimitLocationStartURL_DOCOMO", set_datetimelimit_start_location_docomo, + NULL, OR_LIMIT, "specify location start URL for DOCOMO" ), + AP_INIT_TAKE1( "DateTimeLimitLocationStartURL_EZWEB", set_datetimelimit_start_location_ezweb, + NULL, OR_LIMIT, "specify location start URL for EZWEB" ), + AP_INIT_TAKE1( "DateTimeLimitLocationStartURL_SOFTBANK", set_datetimelimit_start_location_softbank, + NULL, OR_LIMIT, "specify location start URL for SOFTBANK" ), + AP_INIT_TAKE1( "DateTimeLimitLocationEndURL_PC", set_datetimelimit_end_location_pc, + NULL, OR_LIMIT, "specify location end URL for PC" ), + AP_INIT_TAKE1( "DateTimeLimitLocationEndURL_DOCOMO", set_datetimelimit_end_location_docomo, + NULL, OR_LIMIT, "specify location end URL for DOCOMO" ), + AP_INIT_TAKE1( "DateTimeLimitLocationEndURL_EZWEB", set_datetimelimit_end_location_ezweb, + NULL, OR_LIMIT, "specify location end URL for EZWEB" ), + AP_INIT_TAKE1( "DateTimeLimitLocationEndURL_SOFTBANK", set_datetimelimit_end_location_softbank, + NULL, OR_LIMIT, "specify location end URL for SOFTBANK" ), + AP_INIT_TAKE1( "DateTimeLimitStartDate", set_datetimelimit_start_date, + NULL, OR_LIMIT, "specify start DATE" ), + AP_INIT_TAKE1( "DateTimeLimitStartTime", set_datetimelimit_start_time, + NULL, OR_LIMIT, "specify start TIME" ), + AP_INIT_TAKE1( "DateTimeLimitEndDate", set_datetimelimit_end_date, + NULL, OR_LIMIT, "specify start DATE" ), + AP_INIT_TAKE1( "DateTimeLimitEndTime", set_datetimelimit_end_time, + NULL, OR_LIMIT, "specify start TIME" ), { NULL } }; -module MODULE_VAR_EXPORT datetimelimit_module = { - STANDARD_MODULE_STUFF, - NULL, /* module initializer */ - datetimelimit_cdir_config, /* create per-dir config structures */ - NULL, /* merge per-dir config structures */ - NULL, /* create per-server config structures */ - NULL, /* merge per-server config structures */ - datetimelimit_cmds, /* table of config file commands */ - NULL, /* [#8] MIME-typed-dispatched handlers */ - NULL, /* [#1] URI to filename translation */ - NULL, /* [#4] validate user id from request */ - NULL, /* [#5] check if the user is ok _here_ */ - datetimelimit_is_check, /* [#3] check access by host address */ - NULL, /* [#6] determine MIME type */ - NULL, /* [#7] pre-run fixups */ - NULL, /* [#9] log a transaction */ - NULL, /* [#2] header parser */ - NULL, /* child_init */ - NULL, /* child_exit */ - NULL /* [#0] post read-request */ +static void datetimelimit_register_hooks(apr_pool_t *p) +{ + ap_hook_access_checker(datetimelimit_is_check, NULL, NULL, APR_HOOK_MIDDLE); +} + +module AP_MODULE_DECLARE_DATA datetimelimit_module = { + STANDARD20_MODULE_STUFF, + datetimelimit_cdir_config, /* create per-dir config structures */ + NULL, /* merge per-dir config structures */ + NULL, /* create per-server config structures */ + NULL, /* merge per-server config structures */ + datetimelimit_cmds, /* table of config file commands */ + datetimelimit_register_hooks /* register hooks */ };
面倒くさかったのでキャストで逃げている部分は真似しないように(ぉ
mod_maintenance22(2.2系統用)
元ネタはコチラ。
この練習用モジュールを Apache 2.2 で利用できるよう移植してみました。
ただ、劣化移植なのでマルチスレッド環境で動かす場合は(別途)考慮が必要です。
ソースを掲載すると長くなるので差分ダケ。分かりやすいように少しだけ改変していますが、何が変わったかは容易に判断できるかと思いますので参考程度に、ということで。
--- mod_maintenance13.c 2009-06-08 16:29:39.681740000 +0900 +++ mod_maintenance22.c 2009-06-08 16:29:39.885240000 +0900 @@ -34,14 +35,14 @@ long week; } maintenance_config; -module MODULE_VAR_EXPORT maintenance_module; +module AP_MODULE_DECLARE_DATA maintenance_module; /************************************************************************** define of main function **************************************************************************/ -static void *maintenance_cdir_config( pool *pool, char *path ) +static void *maintenance_cdir_config( apr_pool_t *pool, char *path ) { - maintenance_config *cfg = (maintenance_config *)ap_pcalloc( pool, sizeof( maintenance_config ) ); + maintenance_config *cfg = (maintenance_config *)apr_pcalloc( pool, sizeof( maintenance_config ) ); cfg->location_pc = NULL; cfg->location_docomo = NULL; @@ -55,7 +56,7 @@ } /*************************************************************************/ -static const char *set_maintenance_location_pc( cmd_parms *parms, void *myconfig, char *Buffer ) +static const char *set_maintenance_location_pc( cmd_parms *parms, void *myconfig, const char *Buffer ) { maintenance_config *cfg = (maintenance_config *)myconfig; @@ -69,13 +70,13 @@ return "duplicate entry for MaintenanceStartLocationURL_PC."; } - cfg->location_pc = ap_pstrdup( parms->pool, Buffer ); + cfg->location_pc = (char *)apr_pstrdup( parms->pool, Buffer ); return NULL; } /*************************************************************************/ -static const char *set_maintenance_location_docomo( cmd_parms *parms, void *myconfig, char *Buffer ) +static const char *set_maintenance_location_docomo( cmd_parms *parms, void *myconfig, const char *Buffer ) { maintenance_config *cfg = (maintenance_config *)myconfig; @@ -233,8 +234,7 @@ int Result; Result = 0; - - agent = ap_table_get( rec->headers_in, "User-Agent" ); + agent = apr_table_get( rec->headers_in, "User-Agent" ); if( strncmp( agent, "DoCoMo", 6 ) == 0 ) { @@ -409,7 +408,7 @@ } } - ap_table_setn( rec->headers_out, "Location", url ); + apr_table_setn( rec->headers_out, "Location", url ); return HTTP_MOVED_TEMPORARILY; } @@ -421,12 +420,12 @@ **************************************************************************/ static int maintenance_is_digit( const char *Buffer ) { - if( !ap_isdigit( *Buffer ) ) + if( !apr_isdigit( *Buffer ) ) { return 0; } - while( ap_isdigit( *( ++Buffer ) ) ) + while( apr_isdigit( *( ++Buffer ) ) ) { } @@ -438,41 +437,35 @@ **************************************************************************/ static command_rec maintenance_cmds[] = { - { "MaintenanceLocationURL_PC", set_maintenance_location_pc, NULL, OR_LIMIT, TAKE1, - "specify location start URL for PC" }, - { "MaintenanceLocationURL_DOCOMO", set_maintenance_location_docomo, NULL, OR_LIMIT, TAKE1, - "specify location start URL for DOCOMO" }, - { "MaintenanceLocationURL_EZWEB", set_maintenance_location_ezweb, NULL, OR_LIMIT, TAKE1, - "specify location start URL for EZWEB" }, - { "MaintenanceLocationURL_SOFTBANK", set_maintenance_location_softbank, NULL, OR_LIMIT, TAKE1, - "specify location start URL for SOFTBANK" }, - { "MaintenanceStartTime", set_maintenance_start_time, NULL, OR_LIMIT, TAKE1, - "specify start TIME" }, - { "MaintenanceEndTime", set_maintenance_end_time, NULL, OR_LIMIT, TAKE1, - "specify start TIME" }, - { "MaintenanceWeek", set_maintenance_week, NULL, OR_LIMIT, TAKE1, - "specify Maintenance Week(Sun or Mon or Tue or Wed or Thu or Fri or Sat)" }, - { NULL } + AP_INIT_TAKE1( "MaintenanceLocationURL_PC", set_maintenance_location_pc, + NULL, OR_LIMIT, "specify location start URL for PC" ), + AP_INIT_TAKE1( "MaintenanceLocationURL_DOCOMO", set_maintenance_location_docomo, + NULL, OR_LIMIT, "specify location start URL for DOCOMO" ), + AP_INIT_TAKE1( "MaintenanceLocationURL_EZWEB", set_maintenance_location_ezweb, + NULL, OR_LIMIT, "specify location start URL for EZWEB" ), + AP_INIT_TAKE1( "MaintenanceLocationURL_SOFTBANK", set_maintenance_location_softbank, + NULL, OR_LIMIT, "specify location start URL for SOFTBANK" ), + AP_INIT_TAKE1( "MaintenanceStartTime", set_maintenance_start_time, + NULL, OR_LIMIT, "specify start TIME" ), + AP_INIT_TAKE1( "MaintenanceEndTime", set_maintenance_end_time, + NULL, OR_LIMIT, "specify start TIME" ), + AP_INIT_TAKE1( "MaintenanceWeek", set_maintenance_week, + NULL, OR_LIMIT, "specify Maintenance Week(Sun or Mon or Tue or Wed or Thu or Fri or Sat)" ), + { NULL } }; -module MODULE_VAR_EXPORT maintenance_module = { - STANDARD_MODULE_STUFF, - NULL, /* module initializer */ - maintenance_cdir_config, /* create per-dir config structures */ - NULL, /* merge per-dir config structures */ - NULL, /* create per-server config structures */ - NULL, /* merge per-server config structures */ - maintenance_cmds, /* table of config file commands */ - NULL, /* [#8] MIME-typed-dispatched handlers */ - NULL, /* [#1] URI to filename translation */ - NULL, /* [#4] validate user id from request */ - NULL, /* [#5] check if the user is ok _here_ */ - maintenance_is_check, /* [#3] check access by host address */ - NULL, /* [#6] determine MIME type */ - NULL, /* [#7] pre-run fixups */ - NULL, /* [#9] log a transaction */ - NULL, /* [#2] header parser */ - NULL, /* child_init */ - NULL, /* child_exit */ - NULL /* [#0] post read-request */ +static void maintenance_register_hooks(apr_pool_t *p) +{ + ap_hook_access_checker(maintenance_is_check, NULL, NULL, APR_HOOK_MIDDLE); +} + +module AP_MODULE_DECLARE_DATA maintenance_module = { + STANDARD20_MODULE_STUFF, + maintenance_cdir_config, /* create per-dir config structures */ + NULL, /* merge per-dir config structures */ + NULL, /* create per-server config structures */ + NULL, /* merge per-server config structures */ + maintenance_cmds, /* table of config file commands */ + maintenance_register_hooks /* register hooks */ };
面倒くさかったのでキャストで逃げている部分は真似しないように(ぉ
5.2.10RC2 coming soon...?
RC2が準備中。
5.2.10RC1から5.2.10RC2までの修正状況は以下の通り。
RC2なのに「leak」とか「crash」が(結構)目につくのが気になるね。
それにしても「RC2 not final」。。。って、終わってくれないほうが全然嬉しいんだけどね。
--- /repository/php-src/NEWS 2009/05/27 13:47:32 1.2027.2.547.2.1525 +++ /repository/php-src/NEWS 2009/06/11 12:12:43 1.2027.2.547.2.1553 @@ -1,5 +1,45 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| +11 Jun 2009, PHP 5.2.10RC2 +- Updated timezone database to version 2009.9 (2009i) (Derick) +- Added "ignore_errors" option to http fopen wrapper. (David Zulke, Sara) + +- Fixed bug #48518 (curl crashes when writing into invalid file handle). (Tony) +- Fixed bug #48469 (ldap_get_entries() leaks memory on empty search results). + (Patrick) +- Fixed bug #48456 (CPPFLAGS not restored properly in phpize.m4). + (Jani, spisek at kerio dot com) +- Fixed bug #48448 (Compile failure under IRIX 6.5.30 building cast.c). + (Kalle) +- Fixed bug #48434 (Improve memory_get_usage() accuracy). (Arnaud) +- Fixed bug #48416 (Force a cache limit in ereg() to stop excessive memory usage). + (Scott) +- Fixed bug #48409 (Crash when exception is thrown while passing function + arguments). (Arnaud) +- Fixed bug #48378 (exif_read_data() segfaults on certain corrupted .jpeg + files). (Pierre) +- Fixed bug #48359 (Script hangs on snmprealwalk if OID is not + increasing). (Ilia, simonov at gmail dot com) +- Fixed bug #48273 (snmp*_real_walk() returns SNMP errors as values). + (Ilia, lytboris at gmail dot com) +- Fixed bug #48247 (Crash on errors during startup). (Stas) +- Fixed bug #47836 (array operator [] inconsistency when the array has + PHP_INT_MAX index value). (Matt) +- Fixed bug #47042 (cgi sapi is incorrectly removing SCRIPT_FILENAME). + (Sriram Natarajan, David Soria Parra) +- Fixed bug #46386 (Digest authentication with SOAP module fails against MSSQL + SOAP services). (Ilia, lordelph at gmail dot com) +- Fixed bug #46109 (Memory leak when mysqli::init() is called multiple times). + (Andrey) +- Fixed bug #44827 (define() is missing error checks for class constants). + (Ilia) +- Fixed bug #44214 (Crash using preg_replace_callback() and global variables). + (Nuno, Scott) +- Fixed bug #42143 (The constant NAN is reported as 0 on Windows) + (Kanwaljeet Singla, Venkat Raman Don) + + + 27 May 2009, PHP 5.2.10RC1 - Updated timezone database to version 2009.8 (2009h) (Derick)