Apacheモジュール 1.3から2.2への移植: mod_reqinfo
Apacheモジュール プログラミングガイド の中のサンプルプログラムをApache1.3からApache2.2に書き換えたのでそのときのメモ。
#include "httpd.h" #include "http_config.h" #include "http_protocol.h" #include "http_core.h" #include "ap_config.h" /* The sample content handler */ static int reqinfo_handler(request_rec *r) { if (strcmp(r->handler, "reqinfo")) { return DECLINED; } r->content_type = "text/html"; if (r->header_only) return OK; ap_rputs("<html><body>\n", r); /* リクエストの情報 */ ap_rprintf(r, "REQUEST_METHOD: %s<br>\n", r->method); ap_rprintf(r, "QUERY_STRING: %s<br>\n", r->args ? r->args : ""); ap_rprintf(r, "SCRIPT_NAME: %s<br>\n", r->uri); ap_rprintf(r, "PATH_INFO: %s<br>\n", r->path_info ? r->path_info : ""); ap_rprintf(r, "SCRIPT_FILENAME: %s<br>\n", r->filename); /* リクエストヘッダの情報 */ ap_rprintf(r, "HTTP_USER_AGENT: %s<br>\n", apr_table_get(r->headers_in, "User-Agent") ? apr_table_get(r->headers_in, "User-Agent") : ""); ap_rprintf(r, "HTTP_REFERER: %s<br>\n", apr_table_get(r->headers_in, "Referer") ? apr_table_get(r->headers_in, "Referer") : ""); /* Client/Server間接続の情報 */ ap_rprintf(r, "SERVER_ADDR: %s<br>\n", r->connection->local_ip); ap_rprintf(r, "REMOTE_ADDR: %s<br>\n", r->connection->remote_ip); ap_rprintf(r, "REMOTE_USER: %s<br>\n", r->user ? r->user : ""); /* Serverの設定情報 */ ap_rprintf(r, "DOCUMENT_ROOT: %s<br>\n", ap_document_root(r)); ap_rprintf(r, "SERVER_ADMIN: %s<br>\n", r->server->server_admin); ap_rprintf(r, "SERVER_NAME: %s<br>\n", ap_get_server_name(r)); ap_rprintf(r, "SERVER_PORT: %u<br>\n", ap_get_server_port(r)); ap_rprintf(r, "SERVER_SOFTWARE: %s<br>\n", ap_get_server_version()); ap_rprintf(r, "SERVER_SIGNATURE: %s<br>\n", ap_psignature("", r)); ap_rputs("</body></html>", r); return OK; } static void reqinfo_register_hooks(apr_pool_t *p) { ap_hook_handler(reqinfo_handler, NULL, NULL, APR_HOOK_MIDDLE); } /* Dispatch list for API hooks */ module AP_MODULE_DECLARE_DATA reqinfo_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 */ reqinfo_register_hooks /* register hooks */ };