httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject mod_browser patch
Date Thu, 15 Aug 1996 21:09:51 GMT
Here's a patch to mod_browser that incorporates some changes that became
neccessary after I looked harder at exactly what people might want to do
with the thing.

It incorporates several changes:

1) It merges correctly, so that a BrowserMatch statement in a virtualhost
entry will add to, not override, the main set.

2) It changes BrowserCase to BrowserNoCase, since some people expressed
confusion as to whether BrowserCase meant case-sensitive or
case-insensitive matching.

3) It allows you to use a tag of "!var" to cancel out a tag of "var" set
in an earlier BrowserMatch statement. For example:

BrowserMatch ^Mozilla/[2-3] javascript
BrowserMatch MSIE !javascript

Anyhow, here's the patch:

Index: mod_browser.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_browser.c,v
retrieving revision 1.1
diff -c -r1.1 mod_browser.c
*** mod_browser.c	1996/08/12 18:59:45	1.1
--- mod_browser.c	1996/08/13 22:26:35
***************
*** 82,87 ****
--- 82,97 ----
      return (void *)new;
  }
  
+ void *merge_browser_config (pool *p, void *basev, void *overridesv)
+ {
+     browser_server_config_rec *a =
+ 	pcalloc(p, sizeof(browser_server_config_rec));
+     browser_server_config_rec *base = basev, *overrides = overridesv;
+ 
+     a->browsers = append_arrays(p, base->browsers, overrides->browsers);
+     return a;
+ }
+ 
  char *add_browser(cmd_parms *cmd, void *dummy, char *name, char *feature)
  {
      browser_server_config_rec *sconf =
***************
*** 97,102 ****
--- 107,113 ----
  	if (!strcmp(b->name, name)) {
  	    var = getword(cmd->pool, &feature, '=');
  	    if (*feature) table_set(b->features, var, feature);
+ 	    else if (*var == '!') table_set(b->features, var + 1, "!");
  	    else table_set(b->features, var, "1");
  	    return NULL;
  	}
***************
*** 113,118 ****
--- 124,130 ----
  
      var = getword(cmd->pool, &feature, '=');
      if (*feature) table_set(new->features, var, feature);
+     else if (*var == '!') table_set(new->features, var + 1, "!");
      else table_set(new->features, var, "1");
  
      return NULL;
***************
*** 121,127 ****
  command_rec browser_module_cmds[] = {
  { "BrowserMatch", add_browser, (void*)0,
      RSRC_CONF, ITERATE2, "A browser regex and a list of variables." },
! { "BrowserCase", add_browser, (void*)REG_ICASE,
      RSRC_CONF, ITERATE2, "a browser regex and a list of variables." },
  { NULL },
  };
--- 133,139 ----
  command_rec browser_module_cmds[] = {
  { "BrowserMatch", add_browser, (void*)0,
      RSRC_CONF, ITERATE2, "A browser regex and a list of variables." },
! { "BrowserNoCase", add_browser, (void*)REG_ICASE,
      RSRC_CONF, ITERATE2, "a browser regex and a list of variables." },
  { NULL },
  };
***************
*** 132,139 ****
      browser_server_config_rec *sconf = get_module_config (s->module_config,
  							  &browser_module);
      browser_entry *entries = (browser_entry *)sconf->browsers->elts;
      char *ua = table_get(r->headers_in, "User-Agent");
!     int i;
  
      if (!ua) return DECLINED;
  
--- 144,152 ----
      browser_server_config_rec *sconf = get_module_config (s->module_config,
  							  &browser_module);
      browser_entry *entries = (browser_entry *)sconf->browsers->elts;
+     table_entry *elts;
      char *ua = table_get(r->headers_in, "User-Agent");
!     int i, j;
  
      if (!ua) return DECLINED;
  
***************
*** 141,148 ****
  	browser_entry *b = &entries[i];
  
  	if (!regexec(b->preg, ua, 0, NULL, 0)) {
! 	    r->subprocess_env = overlay_tables(r->pool, r->subprocess_env,
! 					       b->features);
  	}
      }
  
--- 154,167 ----
  	browser_entry *b = &entries[i];
  
  	if (!regexec(b->preg, ua, 0, NULL, 0)) {
! 	    elts = (table_entry *)b->features->elts;
! 
! 	    for (j = 0; j < b->features->nelts; ++j) {
! 		if (!strcmp(elts[j].val, "!"))
! 		    table_unset(r->subprocess_env, elts[j].key);
! 		else
! 		    table_set(r->subprocess_env, elts[j].key, elts[j].val);
! 	    }
  	}
      }
  
***************
*** 155,161 ****
     NULL,			/* dir config creater */
     NULL,			/* dir merger --- default is to override */
     create_browser_config,	/* server config */
!    NULL,			/* merge server configs */
     browser_module_cmds,		/* command table */
     NULL,			/* handlers */
     NULL,			/* filename translation */
--- 174,180 ----
     NULL,			/* dir config creater */
     NULL,			/* dir merger --- default is to override */
     create_browser_config,	/* server config */
!    merge_browser_config,     	/* merge server configs */
     browser_module_cmds,		/* command table */
     NULL,			/* handlers */
     NULL,			/* filename translation */


-- Alexei Kosut <akosut@organic.com>            The Apache HTTP Server 
   http://www.nueva.pvt.k12.ca.us/~akosut/      http://www.apache.org/


Mime
View raw message