2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_macro.xml.meta">
25 <name>mod_macro</name>
26 <description>Provides macros within apache httpd runtime configuration files</description>
28 <sourcefile>mod_macro.c</sourcefile>
29 <identifier>macro_module</identifier>
33 <p>This modules provides macros within apache httpd runtime configuration files.
34 These macros may have parameters. They are expanded when used (parameters are
35 substituted by their values given as an argument), and the result is
36 processed normally.</p>
39 <section id="features"><title>Features</title>
41 <p>Definition of a macro:</p>
44 <li> macro definition within a <directive type="section">Macro</directive> section, following
45 the httpd configuration style.</li>
46 <li> user defined names for the macro and its parameters.</li>
47 <li> macro names are case-insensitive, like httpd directives.</li>
48 <li> macro parameter names are case sensitive.</li>
49 <li> macro parameters must have distinct names.</li>
50 <li> error on empty parameter names.</li>
51 <li> redefining a macro generates a warning.</li>
52 <li> macro definitions can be nested... (but what for?)</li>
53 <li> warn about unused macro parameters.</li>
54 <li> warn about macro parameter names which prefix one another.</li>
55 <li> warn if a parameter is not prefixed by any of '<code>$%@</code>'
57 <li> the available prefixes help deal with interactions with other
58 directives such as <directive module="core">Define</directive>.</li>
59 <li> tip: it may be useful to define a macro parameter with surrounding
60 braces, say <code>${foo}</code> so that the name can appear with
61 surrounding characters such as <code>bla${foo}bla</code>.</li>
62 <li> warn about empty macro contents.</li>
63 <li> warns if sections are not properly nested within a macro.
64 (if it is detected so).</li>
65 <li> the lexical scope of macro parameters is restricted to the macro text,
66 it is not forwarded to includes for instance.</li>
67 <li> arbitrary contents in macros.
68 <p>It means you can put perl sections or whatever you like in a macro.
69 No assumption is made about the lexical structure (quotes, spaces or
70 whatever) within the macro contents but to expect a set of
71 backslash-continued independent lines.</p></li>
74 <p>Use of a macro:</p>
77 <li> number of arguments must match the definition.</li>
78 <li> all occurences of macro parameters are substituted by their values.</li>
79 <li> in case of conflicts, the longest parameter name is chosen.</li>
80 <li> macro expansion recursion is detected and stopped (error).</li>
81 <li> warn about empty arguments when used.</li>
82 <li> on errors, try to describe precisely where the error occured.</li>
83 <li> <code>$</code> and <code>%</code>-prefixed parameters are not
85 <li> <code>@</code>-prefixed parameters are escaped in quotes.</li>
88 <p>Removal of a macro definition:</p>
91 <li> the macro must be already defined.</li>
94 <highlight language="config">
95 <Macro DirGroup $dir $group>
96 <Directory $dir>
101 Use DirGroup /www/apache/private private
102 Use DirGroup /www/apache/server admin
109 <section id="examples"><title>Examples</title>
111 <p>A common usage of <module>mod_macro</module> is for the creation of
112 dynamically-generated virtual hosts.</p>
114 <highlight language="config">
115 ## Define a VHost Macro for repetitive configurations
117 <Macro VHost $host $port $dir>
119 <VirtualHost *:$port>
124 <Directory $dir>
125 # do something here...
128 # limit access to intranet subdir.
129 <Directory $dir/intranet>
130 Require ip 10.0.0.0/8
135 ## Use of VHost with different arguments.
137 Use VHost www.apache.org 80 /vhosts/apache/htdocs
138 Use VHost example.org 8080 /vhosts/example/htdocs
139 Use VHost www.example.fr 1234 /vhosts/example.fr/htdocs
145 <directivesynopsis type="section">
147 <description>Define a configuration file macro</description>
149 <Macro <var>name</var> [<var>par1</var> .. <var>parN</var>]>
150 ... </Macro></syntax>
152 <context>server config</context>
153 <context>virtual host</context>
154 <context>directory</context>
158 <p>The <directive>Macro</directive> directive controls the definition of
159 a macro within the server runtime configuration files.
160 The first argument is the name of the macro.
161 Other arguments are parameters to the macro. It is good practice to prefix
162 parameter names with any of '<code>$%@</code>', and not macro names
163 with such characters.
166 <highlight language="config">
167 <Macro LocalAccessPolicy>
168 Require ip 10.2.16.0/24
171 <Macro RestrictedAccessPolicy $ipnumbers>
172 Require ip $ipnumbers
181 <description>Use a macro</description>
182 <syntax>Use <var>name</var> [<var>value1</var> ... <var>valueN</var>]
185 <context>server config</context>
186 <context>virtual host</context>
187 <context>directory</context>
191 <p>The <directive>Use</directive> directive controls the use of a macro.
192 The specified macro is expanded. It must be given the same number of
193 arguments than in the macro definition. The provided values are
194 associated to their corresponding initial parameters and are substituted
195 before processing.</p>
197 <highlight language="config">
198 Use LocalAccessPolicy
200 Use RestrictedAccessPolicy "192.54.172.0/24 192.54.148.0/24"
203 <p>is equivalent, with the macros defined above, to:</p>
205 <highlight language="config">
206 Require ip 10.2.16.0/24
208 Require ip 192.54.172.0/24 192.54.148.0/24
216 <name>UndefMacro</name>
217 <description>Undefine a macro</description>
219 <syntax>UndefMacro <var>name</var></syntax>
221 <context>server config</context>
222 <context>virtual host</context>
223 <context>directory</context>
227 <p>The <directive>UndefMacro</directive> directive undefines a macro
228 which has been defined before hand.</p>
230 <highlight language="config">
231 UndefMacro LocalAccessPolicy
232 UndefMacro RestrictedAccessPolicy