Index: mod_headers.c =================================================================== RCS file: /home/cvs/httpd-2.0/modules/metadata/mod_headers.c,v retrieving revision 1.42.2.7 diff -u -r1.42.2.7 mod_headers.c --- mod_headers.c 19 Aug 2004 22:53:13 -0000 1.42.2.7 +++ mod_headers.c 27 Aug 2004 15:17:33 -0000 @@ -70,6 +70,7 @@ #include "apr_hash.h" #define APR_WANT_STRFUNC #include "apr_want.h" +#include "apr_optional.h" #include "httpd.h" #include "http_config.h" @@ -78,6 +79,13 @@ #include "util_filter.h" #include "http_protocol.h" /* ap_hook_insert_error_filter */ +/* mod_ssl.h is not safe for inclusion in 2.0, so duplicate the + * optional function declarations. */ +APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup, + (apr_pool_t *, server_rec *, + conn_rec *, request_rec *, + char *)); + /* format_tag_hash is initialized during pre-config */ static apr_hash_t *format_tag_hash; @@ -134,6 +142,9 @@ module AP_MODULE_DECLARE_DATA headers_module; +/* Pointer to ssl_var_lookup, if available. */ +static APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *header_ssl_lookup = NULL; + /* * Tag formatting functions */ @@ -150,15 +161,49 @@ { return apr_psprintf(r->pool, "t=%" APR_TIME_T_FMT, r->request_time); } + +/* unwrap_header returns HDR with any newlines converted into + * whitespace if necessary. */ +static const char *unwrap_header(apr_pool_t *p, const char *hdr) +{ + if (ap_strchr_c(hdr, APR_ASCII_LF) || ap_strchr_c(hdr, APR_ASCII_CR)) { + char *ptr; + + hdr = ptr = apr_pstrdup(p, hdr); + + do { + if (*ptr == APR_ASCII_LF || *ptr == APR_ASCII_CR) + *ptr = APR_ASCII_BLANK; + } while (*ptr++); + } + return hdr; +} + static const char *header_request_env_var(request_rec *r, char *a) { const char *s = apr_table_get(r->subprocess_env,a); if (s) - return s; + return unwrap_header(r->pool, s); else return "(null)"; } + +static const char *header_request_ssl_var(request_rec *r, char *name) +{ + if (header_ssl_lookup) { + const char *val = header_ssl_lookup(r->pool, r->server, + r->connection, r, name); + if (val && val[0]) + return unwrap_header(r->pool, val); + else + return "(null)"; + } + else { + return "(null)"; + } +} + /* * Config routines */ @@ -591,13 +636,21 @@ register_format_tag_handler(p, "D", (void*) header_request_duration, 0); register_format_tag_handler(p, "t", (void*) header_request_time, 0); register_format_tag_handler(p, "e", (void*) header_request_env_var, 0); + register_format_tag_handler(p, "s", (void*) header_request_ssl_var, 0); + return OK; +} +static int header_post_config(apr_pool_t *pconf, apr_pool_t *plog, + apr_pool_t *ptemp, server_rec *s) +{ + header_ssl_lookup = APR_RETRIEVE_OPTIONAL_FN(ssl_var_lookup); return OK; } static void register_hooks(apr_pool_t *p) { ap_hook_pre_config(header_pre_config,NULL,NULL,APR_HOOK_MIDDLE); + ap_hook_post_config(header_post_config,NULL,NULL,APR_HOOK_MIDDLE); ap_hook_insert_filter(ap_headers_insert_output_filter, NULL, NULL, APR_HOOK_LAST); ap_hook_insert_error_filter(ap_headers_insert_error_filter, NULL, NULL, APR_HOOK_LAST); ap_hook_fixups(ap_headers_fixup, NULL, NULL, APR_HOOK_LAST);