httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Tromey <tro...@creche.cygnus.com>
Subject AddModule patch
Date Thu, 12 Sep 1996 17:16:22 GMT
Appended are patches that implement AddModule and ClearModule list.
These patches are against the current contents of the cvs repository.
Also included is a patch to core.html to document the new directives.

Here is what the patches do:

* add AddModule and ClearModuleList directives
* Configure generates two new arrays, preloaded_modules and
  preloaded_module_names.
* Configure now generates module_names array in the same order
  as prelinked_modules (really the module name should be stored in
  the module structure, since otherwise mod_dld and mod_info won't
  play well together); a new function is used to look up the module
  name given the module structure
* changes the name of a module from "foo_module" to simply "foo".
  The "_module" extension is redundant and I think it looks more
  natural to write:

	AddModule foo

  instead of

	AddModule foo_module

  Does anyone disagree?  Since this functionality was added for 1.2,
  changing it now will only hurt us...
* Configure now recognizes "%Module" lines in Configuration; these
  lines specify modules which are to be linked in but not activated
  by default.  No such lines are in the Configuration.tmpl by default.

Tom
-- 
tromey@cygnus.com                 Member, League for Programming Freedom

Index: Configuration.tmpl
===================================================================
RCS file: /export/home/cvs/apache/src/Configuration.tmpl,v
retrieving revision 1.35
diff -c -5 -r1.35 Configuration.tmpl
*** Configuration.tmpl	1996/09/08 17:18:43	1.35
--- Configuration.tmpl	1996/09/12 17:04:08
***************
*** 7,17 ****
  
  # The template should only be changed when a new system or module is added,
  # or an existing one modified. This will also most likely require some minor
  # changes to Configure to recognize those changes.
  
! # There are 4 types of lines here:
  
  # '#' comments, distinguished by having a '#' as the first non-blank character
  #
  # Makefile options, such as CC=gcc, etc...
  #
--- 7,17 ----
  
  # The template should only be changed when a new system or module is added,
  # or an existing one modified. This will also most likely require some minor
  # changes to Configure to recognize those changes.
  
! # There are 5 types of lines here:
  
  # '#' comments, distinguished by having a '#' as the first non-blank character
  #
  # Makefile options, such as CC=gcc, etc...
  #
***************
*** 19,29 ****
  # control Configure's behavior as far as how to create Makefile.
  #
  # Module selection lines, distinguished by having 'Module' at the front.
  # These list the configured modules, in priority order (highest priority
  # first).  They're down at the bottom.
! 
  
  ################################################################
  # Makefile configuration
  #
  # These are added to the general flags determined by Configure.
--- 19,33 ----
  # control Configure's behavior as far as how to create Makefile.
  #
  # Module selection lines, distinguished by having 'Module' at the front.
  # These list the configured modules, in priority order (highest priority
  # first).  They're down at the bottom.
! #
! # There is also a special type of Module selection line which uses
! # '%Module' instead of 'Module'.  These modules are compiled into
! # Apache, but not enabled by default.  You can use the AddModule
! # directive to enable such modules.  By default no such modules exist.
  
  ################################################################
  # Makefile configuration
  #
  # These are added to the general flags determined by Configure.
Index: Configure
===================================================================
RCS file: /export/home/cvs/apache/src/Configure,v
retrieving revision 1.16
diff -c -5 -r1.16 Configure
*** Configure	1996/09/08 17:18:45	1.16
--- Configure	1996/09/12 17:04:50
***************
*** 26,89 ****
  sed 's/#.*//' $file | sed '/^[ 	]*$/d' | sed 's/[ 	]*$//' | \
   sed 's/^Rule[ 	]*/##Rule:/' > $tmpfile
  
  # Check for syntax errors...
  
! if egrep -v '^Module[ 	]+[A-Za-z0-9_]+[ 	]+[^ 	]+$' $tmpfile | \
     grep -v = > /dev/null
  then
     echo "Syntax error --- The configuration file is used only to"
     echo "define the list of included modules or to set Makefile"
     echo "options or Configure rules, and I don't see that at all:"
!    egrep -v '^Module[ 	]+[A-Za-z0-9_]+[ 	]+[^ 	]+$' $tmpfile | \
       grep -v =
     exit 1
  fi
  
  # File is OK --- make backup copies of things and then get the new ones:
  
  if [ -f Makefile ] ; then mv Makefile Makefile.bak; fi
  if [ -f modules.c ] ; then mv modules.c modules.c.bak; fi
  
! awk >modules.c <$tmpfile '\
!    BEGIN { modules[n++] = "core_module" } \
!    /^Module/ { modules[n++] = $2 } \
     END { print "/* modules.c --- automatically generated by Apache"; \
           print " * configuration script.  DO NOT HAND EDIT!!!!!"; \
           print " */"; \
           print ""; \
  	 print "#include \"httpd.h\""; \
  	 print "#include \"http_config.h\""; \
           print ""; \
!          for (i = 0; i < n; ++i) { \
!              printf ("extern module %s;\n", modules[i]); \
           } \
           print ""; \
           print "module *prelinked_modules[] = {"; \
           for (i = 0; i < n; ++i) { \
               printf "  &%s,\n", modules[i]; \
           } \
  	 print "  NULL"; \
           print "};"; \
           print "char *module_names[] = {"; \
!          for (i = n-1; i > -1; --i) { \
               printf "  \"%s\",\n", modules[i]; \
           } \
!        print "  NULL"; \
           print "};"; \
!    }'
  
  #
  # Add module set only
  #
  awk >Makefile <$tmpfile '\
     BEGIN { print "# Makefile automatically generated from Makefile.tmpl"; \
  	   print "# and configuration file by Apache config script. "; \
  	   print "# Hand-edited changes will be lost if the config script"; \
  	   print "# is re-run."; \
           } \
!    /^Module/ { modules[n++] = $3 } \
     END { print "MODULES=\\"; \
           for (i = 0; i < n; ++i) { \
               if (i < n-1) printf ("  %s \\\n", modules[i]); \
               else printf ("  %s\n", modules[i]); \
           } \
--- 26,105 ----
  sed 's/#.*//' $file | sed '/^[ 	]*$/d' | sed 's/[ 	]*$//' | \
   sed 's/^Rule[ 	]*/##Rule:/' > $tmpfile
  
  # Check for syntax errors...
  
! if egrep -v '^%?Module[ 	]+[A-Za-z0-9_]+[ 	]+[^ 	]+$' $tmpfile | \
     grep -v = > /dev/null
  then
     echo "Syntax error --- The configuration file is used only to"
     echo "define the list of included modules or to set Makefile"
     echo "options or Configure rules, and I don't see that at all:"
!    egrep -v '^%?Module[ 	]+[A-Za-z0-9_]+[ 	]+[^ 	]+$' $tmpfile | \
       grep -v =
     exit 1
  fi
  
  # File is OK --- make backup copies of things and then get the new ones:
  
  if [ -f Makefile ] ; then mv Makefile Makefile.bak; fi
  if [ -f modules.c ] ; then mv modules.c modules.c.bak; fi
  
! awk <$tmpfile '\
!    BEGIN { modules[n++] = "core_module"; \
!            pmodules[pn++] = "core_module" } \
!    /^Module/ { modules[n++] = $2; \
!                pmodules[pn++] = $2 } \
!    /^%Module/ { pmodules[pn++] = $2 } \
     END { print "/* modules.c --- automatically generated by Apache"; \
           print " * configuration script.  DO NOT HAND EDIT!!!!!"; \
           print " */"; \
           print ""; \
  	 print "#include \"httpd.h\""; \
  	 print "#include \"http_config.h\""; \
           print ""; \
!          for (i = 0; i < pn; ++i) { \
!              printf ("extern module %s;\n", pmodules[i]); \
           } \
           print ""; \
           print "module *prelinked_modules[] = {"; \
           for (i = 0; i < n; ++i) { \
               printf "  &%s,\n", modules[i]; \
           } \
  	 print "  NULL"; \
           print "};"; \
           print "char *module_names[] = {"; \
!          for (i = 0; i < n; ++i) { \
               printf "  \"%s\",\n", modules[i]; \
           } \
!          print "  NULL"; \
!          print "};"; \
!          print ""; \
!          print "module *preloaded_modules[] = {"; \
!          for (i = 0; i < pn; ++i) { \
!              printf "  &%s,\n", pmodules[i]; \
!          } \
! 	 print "  NULL"; \
!          print "};"; \
!          print "char *preloaded_module_names[] = {"; \
!          for (i = 0; i < pn; ++i) { \
!              printf "  \"%s\",\n", pmodules[i]; \
!          } \
!          print "  NULL"; \
           print "};"; \
!    }' | sed -e 's/_module"/"/g' >modules.c
  
  #
  # Add module set only
  #
  awk >Makefile <$tmpfile '\
     BEGIN { print "# Makefile automatically generated from Makefile.tmpl"; \
  	   print "# and configuration file by Apache config script. "; \
  	   print "# Hand-edited changes will be lost if the config script"; \
  	   print "# is re-run."; \
           } \
!    /^%?Module/ { modules[n++] = $3 } \
     END { print "MODULES=\\"; \
           for (i = 0; i < n; ++i) { \
               if (i < n-1) printf ("  %s \\\n", modules[i]); \
               else printf ("  %s\n", modules[i]); \
           } \
Index: http_config.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_config.c,v
retrieving revision 1.22
diff -c -5 -r1.22 http_config.c
*** http_config.c	1996/08/24 14:36:13	1.22
--- http_config.c	1996/09/12 17:05:10
***************
*** 388,397 ****
--- 388,458 ----
          add_module (*m);
  	++m;
      }
  }
  
+ char *find_module_name (module *m)
+ {
+     extern module *preloaded_modules[];
+     extern char *preloaded_module_names[];
+     int i;
+ 
+     for (i = 0; preloaded_modules[i]; ++i) {
+         if (preloaded_modules[i] == m) {
+ 	    return preloaded_module_names[i];
+ 	}
+     }
+     return NULL;
+ }
+ 
+ /*****************************************************************
+  *
+  * Add a named module.  It is not an error for a named module to be
+  * missing; this is just silently ignored.  FIXME?
+  */
+ 
+ void add_named_module (char *name)
+ {
+     extern module *preloaded_modules[];
+     extern char *preloaded_module_names[];
+     int i;
+ 
+     for (i = 0; preloaded_module_names[i]; ++i) {
+         if (strcmp (preloaded_module_names[i], name) == 0) {
+ 	    /* Only add modules that are not already enabled.  */
+ 	    if (preloaded_modules[i]->module_index == 0) {
+ 	        add_module (preloaded_modules[i]);
+ 	    }
+ 	    return;
+ 	}
+     }
+ }
+ 
+ /*****************************************************************
+  *
+  * Clear the internal list of modules, in preparation for starting
+  * over.
+  */
+ 
+ void clear_module_list ()
+ {
+     module **m = &top_module;
+     module **next_m;
+ 
+     while (*m) {
+         (*m)->module_index = 0;
+ 	next_m = &((*m)->next);
+ 	*m = NULL;
+ 	m = next_m;
+     }
+ 
+     num_modules = 0;
+ 
+     /* This is required; so we add it always.  */
+     add_named_module ("core");
+ }
+ 
  /*****************************************************************
   *
   * Resource, access, and .htaccess config files now parsed by a common
   * command loop.
   *
Index: http_config.h
===================================================================
RCS file: /export/home/cvs/apache/src/http_config.h,v
retrieving revision 1.11
diff -c -5 -r1.11 http_config.h
*** http_config.h	1996/08/20 11:50:43	1.11
--- http_config.h	1996/09/12 17:05:34
***************
*** 223,232 ****
--- 223,235 ----
  char *server_root_relative (pool *p, char *fname);
       
  /* Finally, the hook for dynamically loading modules in... */
  
  void add_module (module *m);
+ void add_named_module (char *name);
+ void clear_module_list ();
+ char *find_module_name (module *m);
  
  #ifdef CORE_PRIVATE
  
  /* For http_main.c... */
  
Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.34
diff -c -5 -r1.34 http_core.c
*** http_core.c	1996/08/25 17:46:08	1.34
--- http_core.c	1996/09/12 17:06:04
***************
*** 746,755 ****
--- 746,767 ----
      
      if (errmsg == end_virthost_magic) return NULL;
      return errmsg;
  }
  
+ char *add_module_command (cmd_parms *cmd, void *dummy, char *arg)
+ {
+   add_named_module (arg);
+   return NULL;
+ }
+ 
+ char *clear_module_list_command (cmd_parms *cmd, void *dummy)
+ {
+   clear_module_list ();
+   return NULL;
+ }
+ 
  char *set_server_string_slot (cmd_parms *cmd, void *dummy, char *arg)
  {
      /* This one's pretty generic... */
    
      int offset = (int)cmd->info;
***************
*** 1115,1124 ****
--- 1127,1139 ----
    "'*', a numeric IP address, or the name of a host with a unique IP address"},
  { "Listen", set_listener, NULL, RSRC_CONF, TAKE1,
        "a port number or a numeric IP address and a port number"},
  { "<VirtualHost", virtualhost_section, NULL, RSRC_CONF, RAW_ARGS, NULL },
  { "</VirtualHost>", end_virtualhost_section, NULL, RSRC_CONF, NO_ARGS, NULL },
+ { "AddModule", add_module_command, NULL, RSRC_CONF, ITERATE,
+   "the name of a module" },
+ { "ClearModuleList", clear_module_list_command, NULL, RSRC_CONF, NO_ARGS, NULL },
  { NULL },
  };
  
  /*****************************************************************
   *
Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.66
diff -c -5 -r1.66 http_main.c
*** http_main.c	1996/09/08 17:24:55	1.66
--- http_main.c	1996/09/12 17:06:44
***************
*** 1832,1841 ****
--- 1832,1851 ----
  	*/
      }
  
  } /* standalone_main */
  
+ void show_modules()
+ {
+     extern char *preloaded_module_names[];
+     int t;
+ 
+     printf ("Compiled-in modules:\n");
+     for (t = 0; preloaded_module_names[t]; ++t)
+       printf ("  %s\n", preloaded_module_names[t]);
+ }
+ 
  void show_directives()
      {
      extern module *prelinked_modules[];
      extern char *module_names[];
      command_rec *pc;
***************
*** 1890,1899 ****
--- 1900,1912 ----
            case 'v':
              printf("Server version %s.\n",SERVER_VERSION);
              exit(1);
            case 'h':
  	    show_directives();
+ 	    exit(1);
+ 	  case 'l':
+ 	    show_modules();
  	    exit(1);
  	  case 'X':
  	    ++one_process;	/* Weird debugging mode. */
  	    break;
            case '?':
Index: mod_info.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_info.c,v
retrieving revision 1.3
diff -c -5 -r1.3 mod_info.c
*** mod_info.c	1996/08/20 11:51:13	1.3
--- mod_info.c	1996/09/12 17:06:55
***************
*** 235,246 ****
  }
  
  int display_info(request_rec *r) {
  	module *modp = NULL;
  	char buf[256];
!     extern char *module_names[];
!     char **names = module_names;
  	command_rec *cmd=NULL;
  	handler_rec *hand=NULL;
  	server_rec *serv = r->server;
  	int comma=0;
  	mod_info_config_lines *mod_info_cfg_httpd=NULL;
--- 235,245 ----
  }
  
  int display_info(request_rec *r) {
  	module *modp = NULL;
  	char buf[256];
! 	char *name;
  	command_rec *cmd=NULL;
  	handler_rec *hand=NULL;
  	server_rec *serv = r->server;
  	int comma=0;
  	mod_info_config_lines *mod_info_cfg_httpd=NULL;
***************
*** 277,288 ****
  		mod_info_cfg_srm = mod_info_load_config(r->pool,buf);
  		sprintf(buf,"%s/%s",server_root,serv->access_confname);
  		mod_info_cfg_access = mod_info_load_config(r->pool,buf);
  		if(!r->args) {
  			rputs("<tt><a href=\"#server\">Server Settings</a>, ",r);
! 			for(modp = top_module, names=module_names; modp; modp = modp->next, names++) {
! 				sprintf(buf,"<a href=\"#%s\">%s</a>",*names,*names);
  				rputs(buf, r);
  				if(modp->next) rputs(", ",r);
  			}
  			rputs("</tt><hr>",r);
  
--- 276,288 ----
  		mod_info_cfg_srm = mod_info_load_config(r->pool,buf);
  		sprintf(buf,"%s/%s",server_root,serv->access_confname);
  		mod_info_cfg_access = mod_info_load_config(r->pool,buf);
  		if(!r->args) {
  			rputs("<tt><a href=\"#server\">Server Settings</a>, ",r);
! 			for(modp = top_module; modp; modp = modp->next) {
! 			        name=find_module_name (modp);
! 				sprintf(buf,"<a href=\"#%s\">%s</a>",name,name);
  				rputs(buf, r);
  				if(modp->next) rputs(", ",r);
  			}
  			rputs("</tt><hr>",r);
  
***************
*** 312,324 ****
  			rputs(buf,r);
  			sprintf(buf,"<strong>Scoreboard File:</strong> <tt>%s</tt><br>\n",scoreboard_fname);
  			rputs(buf,r);
  		}
  		rputs("<hr><dl>",r);
! 		for(modp = top_module, names=module_names; modp; modp = modp->next, names++) {
! 			if(!r->args || !strcasecmp(*names,r->args)) {	
! 				sprintf(buf,"<dt><a name=\"%s\"><strong>Module Name:</strong>
<font size=+1><tt>%s</tt></a></font>\n",*names,*names);
  				rputs(buf,r);
  				rputs("<dt><strong>Content-types affected:</strong>",r);	
  				hand = modp->handlers;
  				if(hand) {
  					while(hand) {
--- 312,325 ----
  			rputs(buf,r);
  			sprintf(buf,"<strong>Scoreboard File:</strong> <tt>%s</tt><br>\n",scoreboard_fname);
  			rputs(buf,r);
  		}
  		rputs("<hr><dl>",r);
! 		for(modp = top_module; modp; modp = modp->next) {
! 		        name=find_module_name (modp);
! 			if(!r->args || !strcasecmp(name,r->args)) {	
! 				sprintf(buf,"<dt><a name=\"%s\"><strong>Module Name:</strong>
<font size=+1><tt>%s</tt></a></font>\n",name,name);
  				rputs(buf,r);
  				rputs("<dt><strong>Content-types affected:</strong>",r);	
  				hand = modp->handlers;
  				if(hand) {
  					while(hand) {
***************
*** 392,403 ****
  				if(r->args) break;
  			}
  		}
  		if(!modp && r->args && strcasecmp(r->args,"server")) rputs("<b>No
such module</b>\n",r);
  	} else {
! 		for(modp = top_module; modp; modp = modp->next, names++) {
! 			rputs(*names,r);
  			if(modp->next) rputs("<br>",r);
  		}	
  	}	
  	rputs("</dl></body></html>\n",r);
  	/* Done, turn off timeout, close file and return */
--- 393,405 ----
  				if(r->args) break;
  			}
  		}
  		if(!modp && r->args && strcasecmp(r->args,"server")) rputs("<b>No
such module</b>\n",r);
  	} else {
! 		for(modp = top_module; modp; modp = modp->next) {
! 		        name=find_module_name (modp);
! 			rputs(name,r);
  			if(modp->next) rputs("<br>",r);
  		}	
  	}	
  	rputs("</dl></body></html>\n",r);
  	/* Done, turn off timeout, close file and return */


Index: core.html
===================================================================
RCS file: /rel/cvsfiles/devo/apache/doc/core.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -c -5 -r1.5 -r1.6
*** core.html	1996/09/09 17:56:36	1.5
--- core.html	1996/09/11 21:28:01	1.6
***************
*** 15,28 ****
--- 15,30 ----
  
  <!--%hypertext -->
  <ul>
  <li><A HREF="#accessconfig">AccessConfig</A>
  <li><A HREF="#accessfilename">AccessFileName</A>
+ <li><A HREF="#addmodule">AddModule</A>
  <li><A HREF="#allowoverride">AllowOverride</A>
  <li><A HREF="#authname">AuthName</A>
  <li><A HREF="#authtype">AuthType</A>
  <li><A HREF="#bindaddress">BindAdress</A>
+ <li><A HREF="#clearmodulelist">ClearModuleList</A>
  <li><A HREF="#defaulttype">DefaultType</A>
  <li><A HREF="#directory">&lt;Directory&gt;</A>
  <li><A HREF="#documentroot">DocumentRoot</A>
  <li><A HREF="#errordocument">ErrorDocument</A>
  <li><A HREF="#errorlog">ErrorLog</A>
***************
*** 91,100 ****
--- 93,115 ----
  <blockquote><code>
  &lt;Directory /&gt;<br>
  AllowOverride None<br>
  &lt;/Directory&gt;</code></blockquote><p><hr>
  
+ <A name="addmodule"><h2>AddModule directive</h2></A>
+ <!--%plaintext &lt;?INDEX {\tt AddModule} directive&gt; -->
+ <strong>Syntax:</strong> AddModule <em>module module ...</em><br>
+ <strong>Context:</strong> server config<br>
+ <strong>Status:</strong> core<p>
+ 
+ The server can modules compiled in which are not actively in use.
+ This directive can be used to enable the use of those modules.  The
+ server comes with a pre-loaded list of active modules; this list can
+ be cleared with the <A HREF="#clearmodulelist">ClearModuleList</A>
+ directive.
+ 
+ 
  <A name="allowoverride"><h2>AllowOverride directive</h2></A>
  <!--%plaintext &lt;?INDEX {\tt AllowOverride} directive&gt; -->
  <strong>Syntax:</strong> AllowOverride <em>override override ...</em><br>
  <strong>Default:</strong> <code>AllowOverride All</code><br>
  <strong>Context:</strong> directory<br>
***************
*** 209,218 ****
--- 224,243 ----
  <A HREF="virtual-host.html">virtual hosts</A> instead of using
  <A HREF="#virtualhost">&lt;VirtualHost&gt;</A> sections.<p><hr>
  
  <p><strong>See Also:</strong>
  <a href="bind.html">Setting which addresses and ports Apache uses</a></p>
+ 
+ <A name="clearmodulelist"><h2>ClearModuleList directive</h2></A>
+ <!--%plaintext &lt;?INDEX {\tt ClearModuleList} directive&gt; -->
+ <strong>Syntax:</strong> ClearModuleList<br>
+ <strong>Context:</strong> server config<br>
+ <strong>Status:</strong> core<p>
+ 
+ The server comes with a built-in list of active modules.  This
+ directive clears the list.  It is assumed that the list will then be
+ repopulated using the <A HREF="#addmodule">AddModule</A> directive.
  
  <A name="defaulttype"><h2>DefaultType directive</h2></A>
  <!--%plaintext &lt;?INDEX {\tt DefaultType} directive&gt; -->
  <strong>Syntax:</strong> DefaultType <em>mime-type</em><br>
  <strong>Default:</strong> <code>DefaultType text/html</code><br>

Mime
View raw message