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 */ };
面倒くさかったのでキャストで逃げている部分は真似しないように(ぉ