]> granicus.if.org Git - apache/blob - docs/manual/expr.xml
add new ldap features, make ap_expr entry more verbose
[apache] / docs / manual / expr.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.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 <manualpage metafile="expr.xml.meta">
24
25   <title>Expressions in Apache HTTP Server</title>
26
27   <summary>
28     <p>Historically, there are several syntax variants for expressions used to express
29         a condition in the different modules of the Apache HTTP Server.
30         There is some ongoing effort to only use a single variant, called <em>ap_expr</em>,
31         for all configuration directives.
32         This document describes the <em>ap_expr</em> expression parser.
33     </p>
34     <p>The <em>ap_expr</em> expression is intended to replace most other
35         expression variants in HTTPD. For example, the deprecated
36         <directive module="mod_ssl">SSLRequire</directive> expressions can be
37         replaced by <a href="mod/mod_authz_core.html#reqexpr">Require expr</a>.
38     </p>
39   </summary>
40
41 <seealso><directive module="core" type="section">If</directive></seealso>
42 <seealso><directive module="core" type="section">ElseIf</directive></seealso>
43 <seealso><directive module="core" type="section">Else</directive></seealso>
44 <seealso><directive module="mod_rewrite">RewriteCond</directive></seealso>
45 <seealso><directive module="mod_setenvif">SetEnvIfExpr</directive></seealso>
46 <seealso><directive module="mod_headers">Header</directive></seealso>
47 <seealso><directive module="mod_headers">RequestHeader</directive></seealso>
48 <seealso><directive module="mod_filter">FilterProvider</directive></seealso>
49 <seealso><a href="mod/mod_authz_core.html#reqexpr">Require expr</a></seealso>
50 <seealso><directive module="mod_ssl">SSLRequire</directive></seealso>
51 <seealso><directive module="mod_log_debug">LogMessage</directive></seealso>
52 <seealso><module>mod_include</module></seealso>
53
54   <section id="grammar">
55     <title>Grammar in Backus–Naur Form notation</title>
56       <p><a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form">Backus–Naur Form</a> (BNF) is a notation
57       technique for context-free grammars, often used to describe the syntax of languages used in computing.
58       </p>
59 <blockquote>
60 <pre>
61 expr        ::= "<strong>true</strong>" | "<strong>false</strong>"
62               | "<strong>!</strong>" expr
63               | expr "<strong>&amp;&amp;</strong>" expr
64               | expr "<strong>||</strong>" expr
65               | "<strong>(</strong>" expr "<strong>)</strong>"
66               | comp
67
68 comp        ::= stringcomp
69               | integercomp
70               | unaryop word
71               | word binaryop word
72               | word "<strong>in</strong>" "<strong>{</strong>" wordlist "<strong>}</strong>"
73               | word "<strong>in</strong>" listfunction
74               | word "<strong>=~</strong>" regex
75               | word "<strong>!~</strong>" regex
76
77
78 stringcomp  ::= word "<strong>==</strong>" word
79               | word "<strong>!=</strong>" word
80               | word "<strong>&lt;</strong>"  word
81               | word "<strong>&lt;=</strong>" word
82               | word "<strong>&gt;</strong>"  word
83               | word "<strong>&gt;=</strong>" word
84
85 integercomp ::= word "<strong>-eq</strong>" word | word "<strong>eq</strong>" word
86               | word "<strong>-ne</strong>" word | word "<strong>ne</strong>" word
87               | word "<strong>-lt</strong>" word | word "<strong>lt</strong>" word
88               | word "<strong>-le</strong>" word | word "<strong>le</strong>" word
89               | word "<strong>-gt</strong>" word | word "<strong>gt</strong>" word
90               | word "<strong>-ge</strong>" word | word "<strong>ge</strong>" word
91
92 wordlist    ::= word
93               | wordlist "<strong>,</strong>" word
94
95 word        ::= word "<strong>.</strong>" word
96               | digit
97               | "<strong>'</strong>" string "<strong>'</strong>"
98               | "<strong>"</strong>" string "<strong>"</strong>"
99               | variable
100               | rebackref
101               | function
102
103 string      ::= stringpart
104               | string stringpart
105
106 stringpart  ::= cstring
107               | variable
108               | rebackref
109
110 cstring     ::= ...
111 digit       ::= [0-9]+
112
113 variable    ::= "<strong>%{</strong>" varname "<strong>}</strong>"
114               | "<strong>%{</strong>" funcname "<strong>:</strong>" funcargs "<strong>}</strong>"
115
116 rebackref   ::= "<strong>$</strong>" [0-9]
117
118 function     ::= funcname "<strong>(</strong>" word "<strong>)</strong>"
119
120 listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
121 </pre>
122 </blockquote>
123
124 </section>
125
126 <section id="vars">
127     <title>Variables</title>
128
129     <p>The expression parser provides a number of variables of the form
130     <code>%{HTTP_HOST}</code>. Note that the value of a variable may depend
131     on the phase of the request processing in which it is evaluated.  For
132     example, an expression used in an <directive>&lt;If &gt;</directive>
133     directive is evaluated before authentication is done. Therefore,
134     <code>%{REMOTE_USER}</code> will not be set in this case.</p>
135
136     <p>The following variables provide the values of the named HTTP request
137     headers. The values of other headers can be obtained witht the
138     <code>req</code> <a href="#functions">function</a>.</p>
139
140     <table border="1" style="zebra">
141     <columnspec><column width="1"/></columnspec>
142
143     <tr><th>Name</th></tr>
144     <tr><td><code>HTTP_ACCEPT</code></td></tr>
145     <tr><td><code>HTTP_FORWARDED</code></td></tr>
146     <tr><td><code>HTTP_HOST</code></td></tr>
147     <tr><td><code>HTTP_PROXY_CONNECTION</code></td></tr>
148     <tr><td><code>HTTP_REFERER</code></td></tr>
149     <tr><td><code>HTTP_USER_AGENT</code></td></tr>
150
151     </table>
152
153     <p>Other request related variables</p>
154
155     <table border="1" style="zebra">
156     <columnspec><column width=".4"/><column width=".6"/></columnspec>
157
158     <tr><th>Name</th><th>Description</th></tr>
159     <tr><td><code>REQUEST_METHOD</code></td>
160         <td>The HTTP method of the incoming request (e.g.
161             <code>GET</code>)</td></tr>
162     <tr><td><code>REQUEST_SCHEME</code></td>
163         <td>The scheme part of the request's URI</td></tr>
164     <tr><td><code>REQUEST_URI</code></td>
165         <td>The path part of the request's URI</td></tr>
166     <tr><td><code>DOCUMENT_URI</code></td>
167         <td>Same as REQUEST_URI</td></tr>
168     <tr><td><code>REQUEST_FILENAME</code></td>
169         <td>The full local filesystem path to the file or script matching the
170             request, if this has already been determined by the server at the
171             time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such
172             as when used in virtual host context, the same value as
173             <code>REQUEST_URI</code> </td></tr>
174     <tr><td><code>SCRIPT_FILENAME</code></td>
175         <td>Same as <code>REQUEST_FILENAME</code></td></tr>
176     <tr><td><code>LAST_MODIFIED</code></td>
177         <td>The date and time of last modification of the file in the format
178             <code>20101231235959</code>, if this has already been determined by
179             the server at the time <code>LAST_MODIFIED</code> is referenced.
180             </td></tr>
181     <tr><td><code>SCRIPT_USER</code></td>
182         <td>The user name of the owner of the script.</td></tr>
183     <tr><td><code>SCRIPT_GROUP</code></td>
184         <td>The group name of the group of the script.</td></tr>
185     <tr><td><code>PATH_INFO</code></td>
186         <td>The trailing path name information, see
187             <directive module="core">AcceptPathInfo</directive></td></tr>
188     <tr><td><code>QUERY_STRING</code></td>
189         <td>The query string of the current request</td></tr>
190     <tr><td><code>IS_SUBREQ</code></td>
191         <td>"<code>true</code>" if the current request is a subrequest,
192             "<code>false</code>" otherwise</td></tr>
193     <tr><td><code>THE_REQUEST</code></td>
194         <td>The complete request line (e.g.,
195             "<code>GET /index.html HTTP/1.1</code>")</td></tr>
196     <tr><td><code>REMOTE_ADDR</code></td>
197         <td>The IP address of the remote host</td></tr>
198     <tr><td><code>REMOTE_HOST</code></td>
199         <td>The host name of the remote host</td></tr>
200     <tr><td><code>REMOTE_USER</code></td>
201         <td>The name of the authenticated user (if any)</td></tr>
202     <tr><td><code>REMOTE_IDENT</code></td>
203         <td>The user name set by <module>mod_ident</module></td></tr>
204     <tr><td><code>SERVER_NAME</code></td>
205         <td>The <directive module="core">ServerName</directive> of
206             the current vhost</td></tr>
207     <tr><td><code>SERVER_PORT</code></td>
208         <td>The server port of the current vhost, see
209             <directive module="core">ServerName</directive></td></tr>
210     <tr><td><code>SERVER_ADMIN</code></td>
211         <td>The <directive module="core">ServerAdmin</directive> of
212             the current vhost</td></tr>
213     <tr><td><code>SERVER_PROTOCOL</code></td>
214         <td>The protocol used by the request</td></tr>
215     <tr><td><code>DOCUMENT_ROOT</code></td>
216         <td>The <directive module="core">DocumentRoot</directive> of
217             the current vhost</td></tr>
218     <tr><td><code>AUTH_TYPE</code></td>
219         <td>The configured <directive module="mod_authn_core">AuthType</directive>
220             (e.g. "<code>basic</code>")</td></tr>
221     <tr><td><code>CONTENT_TYPE</code></td>
222         <td>The content type of the response</td></tr>
223     <tr><td><code>HANDLER</code></td>
224         <td>The name of the <a href="handler.html">handler</a> creating
225             the response</td></tr>
226     <tr><td><code>HTTPS</code></td>
227         <td>"<code>on</code>" if the request uses https,
228             "<code>off</code>" otherwise</td></tr>
229     <tr><td><code>IPV6</code></td>
230         <td>"<code>on</code>" if the connection uses IPv6,
231             "<code>off</code>" otherwise</td></tr>
232     <tr><td><code>REQUEST_STATUS</code></td>
233         <td>The HTTP error status of the request</td></tr>
234     <tr><td><code>REQUEST_LOG_ID</code></td>
235         <td>The error log id of the request (see
236             <directive module="core">ErrorLogFormat</directive>)</td></tr>
237     <tr><td><code>CONN_LOG_ID</code></td>
238         <td>The error log id of the connection (see
239             <directive module="core">ErrorLogFormat</directive>)</td></tr>
240
241     </table>
242
243     <p>Misc variables</p>
244
245     <table border="1" style="zebra">
246     <columnspec><column width=".4"/><column width=".6"/></columnspec>
247
248     <tr><th>Name</th><th>Description</th></tr>
249     <tr><td><code>TIME_YEAR</code></td>
250         <td>The current year (e.g. <code>2010</code>)</td></tr>
251     <tr><td><code>TIME_MON</code></td>
252         <td>The current month (<code>1</code>, ..., <code>12</code>)</td></tr>
253     <tr><td><code>TIME_DAY</code></td>
254         <td>The current day of the month</td></tr>
255     <tr><td><code>TIME_HOUR</code></td>
256         <td>The hour part of the current time
257             (<code>0</code>, ..., <code>23</code>)</td></tr>
258     <tr><td><code>TIME_MIN</code></td>
259         <td>The minute part of the current time </td></tr>
260     <tr><td><code>TIME_SEC</code></td>
261         <td>The second part of the current time </td></tr>
262     <tr><td><code>TIME_WDAY</code></td>
263         <td>The day of the week (starting with <code>0</code>
264             for Sunday)</td></tr>
265     <tr><td><code>TIME</code></td>
266         <td>The date and time in the format <code>20101231235959</code></td></tr>
267     <tr><td><code>SERVER_SOFTWARE</code></td>
268         <td>The server version string</td></tr>
269     <tr><td><code>API_VERSION</code></td>
270         <td>The date of the API version (module magic number)</td></tr>
271     </table>
272
273     <p>Some modules register additional variables, see e.g. <module>mod_ssl</module>.</p>
274
275 </section>
276
277 <section id="binop">
278     <title>Binary operators</title>
279
280     <p>With the exception of some built-in comparison operators, binary
281     operators have the form "<code>-[a-zA-Z][a-zA-Z0-9_]+</code>", i.e. a
282     minus and at least two characters. The name is not case sensitive.
283     Modules may register additional binary operators.</p>
284
285     <section id="comp">
286     <title>Comparison operators</title>
287
288     <table border="1" style="zebra">
289     <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
290
291     <tr><th>Name</th><th>Alternative</th> <th>Description</th></tr>
292     <tr><td><code>==</code></td>
293         <td><code>=</code></td>
294         <td>String equality</td></tr>
295     <tr><td><code>!=</code></td>
296         <td></td>
297         <td>String inequality</td></tr>
298     <tr><td><code>&lt;</code></td>
299         <td></td>
300         <td>String less than</td></tr>
301     <tr><td><code>&lt;=</code></td>
302         <td></td>
303         <td>String less than or equal</td></tr>
304     <tr><td><code>&gt;</code></td>
305         <td></td>
306         <td>String greater than</td></tr>
307     <tr><td><code>&gt;=</code></td>
308         <td></td>
309         <td>String greater than or equal</td></tr>
310     <tr><td><code>-eq</code></td>
311         <td><code>eq</code></td>
312         <td>Integer equality</td></tr>
313     <tr><td><code>-ne</code></td>
314         <td><code>ne</code></td>
315         <td>Integer inequality</td></tr>
316     <tr><td><code>-lt</code></td>
317         <td><code>lt</code></td>
318         <td>Integer less than</td></tr>
319     <tr><td><code>-le</code></td>
320         <td><code>le</code></td>
321         <td>Integer less than or equal</td></tr>
322     <tr><td><code>-gt</code></td>
323         <td><code>gt</code></td>
324         <td>Integer greater than</td></tr>
325     <tr><td><code>-ge</code></td>
326         <td><code>ge</code></td>
327         <td>Integer greater than or equal</td></tr>
328     </table>
329     </section>
330
331     <section id="binaryother">
332     <title>Other binary operators</title>
333
334     <table border="1" style="zebra">
335     <columnspec><column width=".2"/><column width=".8"/></columnspec>
336
337     <tr><th>Name</th><th>Description</th></tr>
338     <tr><td><code>-ipmatch</code></td>
339         <td>IP address matches address/netmask</td></tr>
340     <tr><td><code>-strmatch</code></td>
341         <td>left string matches pattern given by right string (containing
342             wildcards *, ?, [])</td></tr>
343     <tr><td><code>-strcmatch</code></td>
344         <td>same as <code>-strmatch</code>, but case insensitive</td></tr>
345     <tr><td><code>-fnmatch</code></td>
346         <td>same as <code>-strmatch</code>, but slashes are not matched by
347             wildcards</td></tr>
348     </table>
349     </section>
350
351 </section>
352
353 <section id="unnop">
354     <title>Unary operators</title>
355
356     <p>Unary operators take one argument and have the form
357     "<code>-[a-zA-Z]</code>", i.e. a minus and one character.
358     The name <em>is</em> case sensitive.
359     Modules may register additional unary operators.</p>
360
361     <table border="1" style="zebra">
362     <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
363
364     <tr><th>Name</th><th>Description</th><th>Restricted</th></tr>
365     <tr><td><code>-d</code></td>
366         <td>The argument is treated as a filename.
367             True if the file exists and is a directory</td><td>yes</td></tr>
368     <tr><td><code>-e</code></td>
369         <td>The argument is treated as a filename.
370             True if the file (or dir or special) exists</td><td>yes</td></tr>
371     <tr><td><code>-f</code></td>
372         <td>The argument is treated as a filename.
373             True if the file exists and is regular file</td><td>yes</td></tr>
374     <tr><td><code>-L</code></td>
375         <td>The argument is treated as a filename.
376             True if the file exists and is symlink</td><td>yes</td></tr>
377     <tr><td><code>-h</code></td>
378         <td>The argument is treated as a filename.
379             True if the file exists and is symlink
380             (same as <code>-L</code>)</td><td>yes</td></tr>
381     <tr><td><code>-F</code></td>
382         <td>True if string is a valid file, accessible via all the server's
383             currently-configured access controls for that path. This uses an
384             internal subrequest to do the check, so use it with care - it can
385             impact your server's performance!</td><td></td></tr>
386     <tr><td><code>-U</code></td>
387         <td>True if string is a valid URL, accessible via all the server's
388             currently-configured access controls for that path. This uses an
389             internal subrequest to do the check, so use it with care - it can
390             impact your server's performance!</td><td></td></tr>
391     <tr><td><code>-A</code></td>
392         <td>Alias for <code>-U</code></td><td></td></tr>
393     <tr><td><code>-n</code></td>
394         <td>True if string is not empty</td><td></td></tr>
395     <tr><td><code>-z</code></td>
396         <td>True if string is empty</td><td></td></tr>
397     <tr><td><code>-T</code></td>
398         <td>False if string is empty, "<code>0</code>", "<code>off</code>",
399             "<code>false</code>", or "<code>no</code>" (case insensitive).
400             True otherwise.</td><td></td></tr>
401     <tr><td><code>-R</code></td>
402         <td>Same as "<code>%{REMOTE_ADDR} -ipmatch ...</code>", but more efficient
403         </td><td></td></tr>
404     </table>
405
406     <p>The operators marked as "restricted" are not available in some modules
407     like <module>mod_include</module>.</p>
408 </section>
409
410 <section id="functions">
411     <title>Functions</title>
412
413     <p>Normal string-valued functions take one string as argument and return
414     a string. Functions names are not case sensitive.
415     Modules may register additional functions.</p>
416
417     <table border="1" style="zebra">
418     <columnspec><column width=".2"/><column width=".8"/></columnspec>
419
420     <tr><th>Name</th><th>Description</th><th>Restricted</th></tr>
421     <tr><td><code>req</code>, <code>http</code></td>
422         <td>Get HTTP request header</td><td></td></tr>
423     <tr><td><code>resp</code></td>
424         <td>Get HTTP response header</td><td></td></tr>
425     <tr><td><code>reqenv</code></td>
426         <td>Lookup request environment variable</td><td></td></tr>
427     <tr><td><code>osenv</code></td>
428         <td>Lookup operating system environment variable</td><td></td></tr>
429     <tr><td><code>note</code></td>
430         <td>Lookup request note</td><td></td></tr>
431     <tr><td><code>env</code></td>
432         <td>Return first match of <code>note</code>, <code>reqenv</code>,
433             <code>osenv</code></td><td></td></tr>
434     <tr><td><code>tolower</code></td>
435         <td>Convert string to lower case</td><td></td></tr>
436     <tr><td><code>toupper</code></td>
437         <td>Convert string to uppser case</td><td></td></tr>
438     <tr><td><code>escape</code></td>
439         <td>Escape special characters in %hex encoding</td><td></td></tr>
440     <tr><td><code>unescape</code></td>
441         <td>Unescape %hex encoded string, leaving encoded slashes alone;
442             return empty string if %00 is found</td><td></td></tr>
443     <tr><td><code>file</code></td>
444         <td>Read contents from a file</td><td>yes</td></tr>
445     <tr><td><code>filesize</code></td>
446         <td>Return size of a file (or 0 if file does not exist or is not
447             regular file)</td><td>yes</td></tr>
448
449     </table>
450
451     <p>The functions marked as "restricted" are not available in some modules
452     like <module>mod_include</module>.</p>
453
454     <p>In addition to string-valued functions, there are also list-valued functions which
455     take one string as argument and return a wordlist, i.e. a list of strings. The wordlist
456     can be used with the special <code>-in</code> operator.
457     Functions names are not case sensitive.
458     Modules may register additional functions.</p>
459
460     <p>There are no built-in list-valued functions. <module>mod_ssl</module>
461     provides <code>PeerExtList</code>.  See the description of
462     <directive module="mod_ssl">SSLRequire</directive> for details
463     (but <code>PeerExtList</code> is also usable outside
464     of <directive module="mod_ssl">SSLRequire</directive>).</p>
465
466 </section>
467
468 <section id="other">
469     <title>Other</title>
470
471     <table border="1" style="zebra">
472     <columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
473
474     <tr><th>Name</th><th>Alternative</th> <th>Description</th></tr>
475     <tr><td><code>-in</code></td>
476         <td><code>in</code></td>
477         <td>string contained in string list</td></tr>
478     <tr><td><code>/regexp/</code></td>
479         <td><code>m#regexp#</code></td>
480         <td>Regular expression (the second form allows different delimiters than /)</td></tr>
481     <tr><td><code>/regexp/i</code></td>
482         <td><code>m#regexp#i</code></td>
483         <td>Case insensitive regular expression</td></tr>
484     <tr><td><code>$0 ... $9</code></td>
485         <td></td>
486         <td>Regular expression backreferences</td></tr>
487     </table>
488
489     <section id="rebackref">
490         <title>Regular expression backreferences</title>
491         <p>The strings <code>$0</code> ... <code>$9</code> allow to reference
492         the capture groups from a previously executed, successfully
493         matching regular expressions. They can normally only be used in the
494         same expression as the matching regex, but some modules allow special
495         uses.</p>
496     </section>
497
498 </section>
499
500 <section id="sslrequire">
501     <title>Comparison with SSLRequire</title>
502     <p>The <em>ap_expr</em> syntax is mostly a superset of the syntax of the
503     deprecated <directive module="mod_ssl">SSLRequire</directive> directive.
504     The differences are described in <directive
505     module="mod_ssl">SSLRequire</directive>'s documentation.</p>
506 </section>
507
508 </manualpage>