]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_macro.xml
Rebuild
[apache] / docs / manual / mod / mod_macro.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
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
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <modulesynopsis metafile="mod_macro.xml.meta">
24
25 <name>mod_macro</name>
26 <description>Provides macros within apache httpd runtime configuration files</description>
27 <status>Base</status>
28 <sourcefile>mod_macro.c</sourcefile>
29 <identifier>macro_module</identifier>
30
31 <summary>
32
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>
37 </summary>
38
39 <section id="features"><title>Features</title>
40
41 <p>Definition of a macro:</p>
42
43     <ul>
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>'
56          (good practice).</li>
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>
72     </ul>
73
74 <p>Use of a macro:</p>
75
76     <ul>
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
84           escaped.</li>
85     <li> <code>@</code>-prefixed parameters are escaped in quotes.</li>
86     </ul>
87
88 <p>Removal of a macro definition:</p>
89
90    <ul>
91    <li> the macro must be already defined.</li>
92    </ul>
93
94 <highlight language="config">
95 &lt;Macro DirGroup $dir $group&gt;
96   &lt;Directory $dir&gt;
97     require group $group
98   &lt;/Directory&gt;
99 &lt;/Macro&gt;
100
101 Use DirGroup /www/apache/private private
102 Use DirGroup /www/apache/server  admin
103
104 UndefMacro DirGroup
105 </highlight>
106
107 </section>
108
109 <section id="examples"><title>Examples</title>
110
111 <p>A common usage of <module>mod_macro</module> is for the creation of
112 dynamically-generated virtual hosts.</p>
113
114 <highlight language="config">
115 ## Define a VHost Macro for repetitive configurations
116
117 &lt;Macro VHost $host $port $dir&gt;
118   Listen $port
119   &lt;VirtualHost *:$port&gt;
120
121     ServerName $host
122     DocumentRoot $dir
123
124     &lt;Directory $dir&gt;
125       # do something here...
126     &lt;/Directory&gt;
127
128     # limit access to intranet subdir.
129     &lt;Directory $dir/intranet&gt;
130       Require ip 10.0.0.0/8
131     &lt;/Directory&gt;
132   &lt;/VirtualHost&gt;
133 &lt;/Macro&gt;
134
135 ## Use of VHost with different arguments.
136
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
140 </highlight>
141
142 </section>
143
144 <!-- Macro -->
145 <directivesynopsis type="section">
146 <name>Macro</name>
147 <description>Define a configuration file macro</description>
148 <syntax>
149 &lt;Macro <var>name</var> [<var>par1</var> .. <var>parN</var>]&gt;
150 ... &lt;/Macro&gt;</syntax>
151 <contextlist>
152 <context>server config</context>
153 <context>virtual host</context>
154 <context>directory</context>
155 </contextlist>
156
157 <usage>
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.
164     </p>
165
166     <highlight language="config">
167 &lt;Macro LocalAccessPolicy&gt;
168     Require ip 10.2.16.0/24
169 &lt;/Macro&gt;
170
171 &lt;Macro RestrictedAccessPolicy $ipnumbers&gt;
172     Require ip $ipnumbers
173 &lt;/Macro&gt;
174     </highlight>
175 </usage>
176 </directivesynopsis>
177
178 <!-- Use -->
179 <directivesynopsis>
180 <name>Use</name>
181 <description>Use a macro</description>
182 <syntax>Use <var>name</var> [<var>value1</var> ... <var>valueN</var>]
183 </syntax>
184 <contextlist>
185 <context>server config</context>
186 <context>virtual host</context>
187 <context>directory</context>
188 </contextlist>
189
190 <usage>
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>
196
197     <highlight language="config">
198 Use LocalAccessPolicy
199 ...
200 Use RestrictedAccessPolicy "192.54.172.0/24 192.54.148.0/24"
201     </highlight>
202
203     <p>is equivalent, with the macros defined above, to:</p>
204
205     <highlight language="config">
206 Require ip 10.2.16.0/24
207 ...
208 Require ip 192.54.172.0/24 192.54.148.0/24
209     </highlight>
210 </usage>
211
212 </directivesynopsis>
213
214 <!-- UndefMacro -->
215 <directivesynopsis>
216 <name>UndefMacro</name>
217 <description>Undefine a macro</description>
218
219 <syntax>UndefMacro <var>name</var></syntax>
220 <contextlist>
221 <context>server config</context>
222 <context>virtual host</context>
223 <context>directory</context>
224 </contextlist>
225
226 <usage>
227     <p>The <directive>UndefMacro</directive> directive undefines a macro
228     which has been defined before hand.</p>
229
230     <highlight language="config">
231 UndefMacro LocalAccessPolicy
232 UndefMacro RestrictedAccessPolicy
233     </highlight>
234 </usage>
235 </directivesynopsis>
236 </modulesynopsis>