httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@locus.apache.org
Subject cvs commit: apache-2.0/src/modules/standard mod_setenvif.c
Date Tue, 06 Jun 2000 20:41:45 GMT
coar        00/06/06 13:41:45

  Modified:    src/modules/standard mod_setenvif.c
  Log:
  	Bring forward a change from 1.3 (the ability to use SetEnvIf*
  	and BrowserMatch* in .htaccess files).
  
  Revision  Changes    Path
  1.13      +64 -18    apache-2.0/src/modules/standard/mod_setenvif.c
  
  Index: mod_setenvif.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_setenvif.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -u -r1.12 -r1.13
  --- mod_setenvif.c	2000/05/27 22:40:37	1.12
  +++ mod_setenvif.c	2000/06/06 20:41:45	1.13
  @@ -148,7 +148,16 @@
   
   module MODULE_VAR_EXPORT setenvif_module;
   
  -static void *create_setenvif_config(ap_pool_t *p, server_rec *dummy)
  +/*
  + * These routines, the create- and merge-config functions, are called
  + * for both the server-wide and the per-directory contexts.  This is
  + * because the different definitions are used at different times; the
  + * server-wide ones are used in the post-read-request phase, and the
  + * per-directory ones are used during the header-parse phase (after
  + * the URI has been mapped to a file and we have anything from the
  + * .htaccess file and <Directory> and <Files> containers).
  + */
  +static void *create_setenvif_config(ap_pool_t *p)
   {
       sei_cfg_rec *new = (sei_cfg_rec *) ap_palloc(p, sizeof(sei_cfg_rec));
   
  @@ -156,6 +165,16 @@
       return (void *) new;
   }
   
  +static void *create_setenvif_config_svr(ap_pool_t *p, server_rec *dummy)
  +{
  +    return create_setenvif_config(p);
  +}
  +
  +static void *create_setenvif_config_dir(ap_pool_t *p, char *dummy)
  +{
  +    return create_setenvif_config(p);
  +}
  +
   static void *merge_setenvif_config(ap_pool_t *p, void *basev, void *overridesv)
   {
       sei_cfg_rec *a = ap_pcalloc(p, sizeof(sei_cfg_rec));
  @@ -166,24 +185,36 @@
       return a;
   }
   
  -/* any non-NULL magic constant will do... used to indicate if REG_ICASE should
  +/*
  + * any non-NULL magic constant will do... used to indicate if REG_ICASE should
    * be used
    */
   #define ICASE_MAGIC	((void *)(&setenvif_module))
  +#define SEI_MAGIC_HEIRLOOM "setenvif-phase-flag"
   
   static const char *add_setenvif_core(cmd_parms *cmd, void *mconfig,
   				     char *fname, const char *args)
   {
       char *regex;
       const char *feature;
  -    sei_cfg_rec *sconf = ap_get_module_config(cmd->server->module_config,
  -					      &setenvif_module);
  -    sei_entry *new, *entries = (sei_entry *) sconf->conditionals->elts;
  +    sei_cfg_rec *sconf;
  +    sei_entry *new;
  +    sei_entry *entries;
       char *var;
       int i;
       int beenhere = 0;
       unsigned icase;
   
  +    /*
  +     * Determine from our context into which record to put the entry.
  +     * cmd->path == NULL means we're in server-wide context; otherwise,
  +     * we're dealing with a per-directory setting.
  +     */
  +    sconf = (cmd->path != NULL)
  +	? (sei_cfg_rec *) mconfig
  +	: (sei_cfg_rec *) ap_get_module_config(cmd->server->module_config,
  +					       &setenvif_module);
  +    entries = (sei_entry *) sconf->conditionals->elts;
       /* get regex */
       regex = ap_getword_conf(cmd->pool, &args);
       if (!*regex) {
  @@ -205,7 +236,7 @@
   	}
       }
   
  -    /* if the last entry has an idential headername and regex then
  +    /* if the last entry has an identical headername and regex then
        * merge with it
        */
       i = sconf->conditionals->nelts - 1;
  @@ -310,19 +341,27 @@
   static const command_rec setenvif_module_cmds[] =
   {
       { "SetEnvIf", add_setenvif, NULL,
  -      RSRC_CONF, RAW_ARGS, "A header-name, regex and a list of variables." },
  +      OR_FILEINFO, RAW_ARGS, "A header-name, regex and a list of variables." },
       { "SetEnvIfNoCase", add_setenvif, ICASE_MAGIC,
  -      RSRC_CONF, RAW_ARGS, "a header-name, regex and a list of variables." },
  +      OR_FILEINFO, RAW_ARGS, "a header-name, regex and a list of variables." },
       { "BrowserMatch", add_browser, NULL,
  -      RSRC_CONF, RAW_ARGS, "A browser regex and a list of variables." },
  +      OR_FILEINFO, RAW_ARGS, "A browser regex and a list of variables." },
       { "BrowserMatchNoCase", add_browser, ICASE_MAGIC,
  -      RSRC_CONF, RAW_ARGS, "A browser regex and a list of variables." },
  +      OR_FILEINFO, RAW_ARGS, "A browser regex and a list of variables." },
       { NULL },
   };
   
  +/*
  + * This routine gets called at two different points in request processing:
  + * once before the URI has been translated (during the post-read-request
  + * phase) and once after (during the header-parse phase).  We use different
  + * config records for the two different calls to reduce overhead (by not
  + * re-doing the server-wide settings during directory processing), and
  + * signal which call it is by having the earlier one pass a flag to the
  + * later one.
  + */
   static int match_headers(request_rec *r)
   {
  -    server_rec *s = r->server;
       sei_cfg_rec *sconf;
       sei_entry *entries;
       ap_table_entry_t *elts;
  @@ -330,8 +369,15 @@
       int i, j;
       char *last_name;
   
  -    sconf = (sei_cfg_rec *) ap_get_module_config(s->module_config,
  -						 &setenvif_module);
  +    if (ap_table_get(r->notes, SEI_MAGIC_HEIRLOOM) == NULL) {
  +	ap_table_set(r->notes, SEI_MAGIC_HEIRLOOM, "post-read done");
  +	sconf  = (sei_cfg_rec *) ap_get_module_config(r->server->module_config,
  +						      &setenvif_module);
  +    }
  +    else {
  +	sconf = (sei_cfg_rec *) ap_get_module_config(r->per_dir_config,
  +						     &setenvif_module);
  +    }
       entries = (sei_entry *) sconf->conditionals->elts;
       last_name = NULL;
       val = NULL;
  @@ -404,18 +450,18 @@
   
   static void register_hooks(void)
   {
  -    ap_hook_post_read_request(match_headers,NULL,NULL,AP_HOOK_MIDDLE);
  +    ap_hook_header_parser(match_headers, NULL, NULL, AP_HOOK_MIDDLE);
  +    ap_hook_post_read_request(match_headers, NULL, NULL, AP_HOOK_MIDDLE);
   }
   
   module MODULE_VAR_EXPORT setenvif_module =
   {
       STANDARD20_MODULE_STUFF,
  -    NULL,                       /* dir config creater */
  -    NULL,                       /* dir merger --- default is to override */
  -    create_setenvif_config,     /* server config */
  +    create_setenvif_config_dir, /* dir config creater */
  +    merge_setenvif_config,      /* dir merger --- default is to override */
  +    create_setenvif_config_svr, /* server config */
       merge_setenvif_config,      /* merge server configs */
       setenvif_module_cmds,       /* command ap_table_t */
       NULL,                       /* handlers */
       register_hooks		/* register hooks */
   };
  -
  
  
  

Mime
View raw message