httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexei Kosut <ako...@organic.com>
Subject patch for <IfModule>
Date Mon, 22 Jul 1996 18:43:25 GMT
Here's a patch that implements something we discusses a month or so ago;
the ability to conditionalize config files based on which modules were
installed. It allows you to do, for example (to use a complex example):

<IfModule dbm_auth_module>
AuthDBMUserFile htpasswd.dbm
</IfModule>
<IfModule !dbm_auth_module>
<IfModule digest_module>
AuthDigestFile htdigest
</IfModule>
<IfModule !digest_module>
AuthUserFile htpasswd
</IfModule>
</IfModule>

Basically, it lets you specifiy a set of directives as being applicatble
only if a certain module is (or is not) installed. And it's, as I've
shown, nestable. I think it'd be useful enough to include in the
distribution.

Here's the patch:

Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.18
diff -c -r1.18 http_core.c
*** http_core.c	1996/06/12 18:14:31	1.18
--- http_core.c	1996/07/22 18:39:47
***************
*** 65,70 ****
--- 65,72 ----
  #include "util_md5.h"
  #include "scoreboard.h"
  
+ extern char *module_names[];
+ 
  /* Server core module... This module provides support for really basic
   * server operations, including options and commands which control the
   * operation of other modules.  Consider this the bureaucracy module.
***************
*** 575,580 ****
--- 577,614 ----
      return NULL;
  }
  
+ char *end_ifmod (cmd_parms *cmd, void *dummy) {
+     return NULL;
+ }
+ 
+ char *start_ifmod (cmd_parms *cmd, void *dummy, char *arg)
+ {
+     char *endp = strrchr (arg, '>');
+     char l[MAX_STRING_LEN];
+     int i, not = (arg[0] == '!');
+     int found = 0;
+     int nest = 1;
+ 
+     if (endp) *endp = '\0';
+     if (not) arg++;
+ 
+     for (i=0; module_names[i]; i++)
+       if (!strcasecmp(arg, module_names[i]))
+ 	found++;
+ 
+     if ((!not && found) || (not && !found))
+       return NULL;
+ 
+     while (nest && !(cfg_getline (l, MAX_STRING_LEN, cmd->infile))) {
+         if (!strncasecmp(l, "<IfModule", 9))
+ 	  nest++;
+ 	if (!strcasecmp(l, "</IfModule>"))
+ 	  nest--;
+     }
+ 
+     return NULL;
+ }
+ 
  /* httpd.conf commands... beginning with the <VirtualHost> business */
  
  char *end_virthost_magic = "</Virtualhost> out of place";
***************
*** 834,839 ****
--- 868,875 ----
  { "KeepAliveTimeout", set_keep_alive_timeout, NULL, RSRC_CONF, TAKE1, "Keep-Alive timeout
duration (sec)"},
  { "KeepAlive", set_keep_alive, NULL, RSRC_CONF, TAKE1, "Maximum Keep-Alive requests per
connection (0 to disable)" },
  { "IdentityCheck", set_idcheck, NULL, RSRC_CONF|ACCESS_CONF, FLAG, NULL },
+ { "<IfModule", start_ifmod, NULL, OR_ALL, RAW_ARGS, NULL },
+ { "</IfModule>", end_ifmod, NULL, OR_ALL, NO_ARGS, NULL },
  { "ContentDigest", set_content_md5, NULL, RSRC_CONF|ACCESS_CONF|OR_AUTHCFG, FLAG, "whether
or not to send a Content-MD5 header with each request" },
  { "CacheNegotiatedDocs", },
  { "StartServers", set_daemons_to_start, NULL, RSRC_CONF, TAKE1, NULL },


-- 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