Skip to content

Commit 3fae0e5

Browse files
author
Stefan Fritsch
committed
- add -ipmatch, -str(c)match, -fnmatch, -R operators to ap_expr
- allow lookup function to pre-parse string constant arguments (used for subnet masks so far) - various bug fixes for binary operators - do strdup() for error messages created on the stack to avoid corruption git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1039900 13f79535-47bb-0310-9956-ffa450edef68
1 parent e1316f8 commit 3fae0e5

6 files changed

Lines changed: 195 additions & 67 deletions

File tree

docs/manual/expr.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
218218
minus and at least two characters. The name is not case sensitive.
219219
Modules may register additional binary operators.</p>
220220

221+
<section id="comp">
222+
<title>Comparison operators</title>
223+
221224
<table border="1" style="zebra">
222225
<columnspec><column width=".2"/><column width=".2"/><column width=".6"/></columnspec>
223226

@@ -259,6 +262,27 @@ listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
259262
<td><code>ge</code></td>
260263
<td>Integer greater than or equal</td></tr>
261264
</table>
265+
</section>
266+
267+
<section id="binaryother">
268+
<title>Other binary operators</title>
269+
270+
<table border="1" style="zebra">
271+
<columnspec><column width=".2"/><column width=".8"/></columnspec>
272+
273+
<tr><th>Name</th><th>Description</th></tr>
274+
<tr><td><code>-ipmatch</code></td>
275+
<td>IP address matches address/netmask</td></tr>
276+
<tr><td><code>-strmatch</code></td>
277+
<td>left string matches pattern given by right string (containing
278+
wildcards *, ?, [])</td></tr>
279+
<tr><td><code>-strcmatch</code></td>
280+
<td>same as <code>-strmatch</code>, but case insensitive</td></tr>
281+
<tr><td><code>-fnmatch</code></td>
282+
<td>same as <code>-strmatch</code>, but slashes are not matched by
283+
wildcards</td></tr>
284+
</table>
285+
</section>
262286

263287
</section>
264288

@@ -277,6 +301,9 @@ listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
277301
<td>String is not empty</td></tr>
278302
<tr><td><code>-z</code></td>
279303
<td>String is empty</td></tr>
304+
<tr><td><code>-R</code></td>
305+
<td>Same as "<code>%{REMOTE_ADDR} -ipmatch ...</code>", but more efficient
306+
</td></tr>
280307
</table>
281308

282309
</section>

docs/manual/mod/mod_setenvif.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ for additional examples.
258258
<directivesynopsis>
259259

260260
<name>SetEnvIfExpr</name>
261-
<description>Sets environment variables based on an expression</description>
261+
<description>Sets environment variables based on an ap_expr expression</description>
262262
<syntax>SetEnvIfExpr <em>expr
263263
[!]env-variable</em>[=<em>value</em>]
264264
[[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
@@ -281,11 +281,11 @@ for additional examples.
281281
<p>This would set the environment variable <code>iso_delivered</code>
282282
every time our application attempts to send it via <code>X-Sendfile</code></p>
283283

284-
<p>For a more useful example, consider the <code>Referer</code>
285-
example from above for a site with more than one domain:</p>
284+
<p>A more useful example would be to set the variable rfc1918 if the
285+
remote IP address is a private address according to RFC 1918:</p>
286286

287287
<example>
288-
SetEnvIfExpr "${HTTP_REFERER} in { 'www.example.com','example.com','w2.example3.org' }" intra_site_referral
288+
SetEnvIfExpr "-R '10.0.0.0/8' || -R '172.16.0.0/12' || -R '192.168.0.0/16'" rfc1918
289289
</example>
290290
</usage>
291291

include/ap_expr.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ typedef struct {
5353
* operators)
5454
*/
5555
#define AP_EXPR_FLAGS_SSL_EXPR_COMPAT 1
56-
/** If using the simple ap_expr_exec(), don't add siginificant request headers
57-
* to the Vary response header
58-
*/
56+
/** Don't add siginificant request headers to the Vary response header */
5957
#define AP_EXPR_FLAGS_DONT_VARY 2
6058

6159

@@ -126,6 +124,8 @@ typedef struct {
126124
*
127125
* During parsing, the parser calls the lookup function to resolve a
128126
* name into a function pointer and an opaque context for the function.
127+
* If the argument to a function or operator is constant, the lookup function
128+
* may also parse that argument and store the parsed data in the context.
129129
*
130130
* The default lookup function is the hook 'ap_expr_lookup_default' which just
131131
* calls ap_expr_lookup_default. Modules can use it to make functions and
@@ -204,8 +204,12 @@ typedef struct {
204204
const void **func;
205205
/** where to store the function's context */
206206
const void **data;
207-
/** Where to store the error message (if any) */
207+
/** where to store the error message (if any) */
208208
const char **err;
209+
210+
/** arg for pre-parsing (only if a simple string).
211+
* For binary ops, this is the right argument. */
212+
const char *arg;
209213
} ap_expr_lookup_parms;
210214

211215
/** Function for looking up the provider function for a variable, operator

0 commit comments

Comments
 (0)