httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject cvs commit: httpd-2.0/modules/metadata mod_headers.c
Date Sat, 28 Feb 2004 21:44:30 GMT
jorton      2004/02/28 13:44:30

  Modified:    modules/metadata mod_headers.c
  Log:
  Add 's' format tag to mod_headers to allow access to mod_ssl variables
  without the overhead of SSLOptions +StdEnvVars/+ExportCertData; also
  ensure that any multi-line envvars are unwrapped onto a single line.
  
  * modules/metadata/mod_headers.c (header_request_ssl_var, unwrap_header,
  header_post_config): New functions.
  (header_pre_config): Register the 's' tag type.
  (register_hooks): Add the post_config hook.
  
  PR: 23223
  
  Revision  Changes    Path
  1.50      +48 -1     httpd-2.0/modules/metadata/mod_headers.c
  
  Index: mod_headers.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/metadata/mod_headers.c,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -w -d -u -r1.49 -r1.50
  --- mod_headers.c	9 Feb 2004 20:29:21 -0000	1.49
  +++ mod_headers.c	28 Feb 2004 21:44:30 -0000	1.50
  @@ -78,6 +78,8 @@
   #include "util_filter.h"
   #include "http_protocol.h"
   
  +#include "mod_ssl.h" /* for the ssl_var_lookup optional function defn */
  +
   /* format_tag_hash is initialized during pre-config */
   static apr_hash_t *format_tag_hash;
   
  @@ -133,6 +135,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
    */
  @@ -149,15 +154,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
    */
  @@ -668,7 +707,14 @@
       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;
   }
   
  @@ -679,6 +725,7 @@
       ap_register_output_filter("FIXUP_HEADERS_ERR", ap_headers_error_filter,
                                 NULL, AP_FTYPE_CONTENT_SET);
       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);
  
  
  

Mime
View raw message