<h2><a name="unnop" id="unnop">Unary operators</a></h2>
- <p>Unary operators have the form "<code>-[a-zA-Z]</code>", i.e. a
- minus and one character. The name <em>is</em> case sensitive.
+ <p>Unary operators take one argument and have the form
+ "<code>-[a-zA-Z]</code>", i.e. a minus and one character.
+ The name <em>is</em> case sensitive.
Modules may register additional unary operators.</p>
<table class="bordered"><tr class="header"><th>Name</th><th>Description</th></tr>
<tr><td><code>-d</code></td>
- <td>True if file exists and is a directory</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is a directory</td></tr>
<tr class="odd"><td><code>-e</code></td>
- <td>True if file (or dir or special) exists</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file (or dir or special) exists</td></tr>
<tr><td><code>-f</code></td>
- <td>True if file exists and is regular file</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is regular file</td></tr>
<tr class="odd"><td><code>-L</code></td>
- <td>True if file exists and is symlink</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is symlink</td></tr>
<tr><td><code>-h</code></td>
- <td>True if file exists and is symlink (same as <code>-L</code>)</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is symlink
+ (same as <code>-L</code>)</td></tr>
+<tr class="odd"><td><code>-F</code></td>
+ <td>True if string is a valid file, accessible via all the server's
+ currently-configured access controls for that path. This uses an
+ internal subrequest to do the check, so use it with care - it can
+ impact your server's performance!</td></tr>
+<tr><td><code>-U</code></td>
+ <td>True if string is a valid URL, accessible via all the server's
+ currently-configured access controls for that path. This uses an
+ internal subrequest to do the check, so use it with care - it can
+ impact your server's performance!</td></tr>
<tr class="odd"><td><code>-n</code></td>
<td>True if string is not empty</td></tr>
<tr><td><code>-z</code></td>
<section id="unnop">
<title>Unary operators</title>
- <p>Unary operators have the form "<code>-[a-zA-Z]</code>", i.e. a
- minus and one character. The name <em>is</em> case sensitive.
+ <p>Unary operators take one argument and have the form
+ "<code>-[a-zA-Z]</code>", i.e. a minus and one character.
+ The name <em>is</em> case sensitive.
Modules may register additional unary operators.</p>
<table border="1" style="zebra">
<tr><th>Name</th><th>Description</th></tr>
<tr><td><code>-d</code></td>
- <td>True if file exists and is a directory</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is a directory</td></tr>
<tr><td><code>-e</code></td>
- <td>True if file (or dir or special) exists</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file (or dir or special) exists</td></tr>
<tr><td><code>-f</code></td>
- <td>True if file exists and is regular file</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is regular file</td></tr>
<tr><td><code>-L</code></td>
- <td>True if file exists and is symlink</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is symlink</td></tr>
<tr><td><code>-h</code></td>
- <td>True if file exists and is symlink (same as <code>-L</code>)</td></tr>
+ <td>The argument is treated as a filename.
+ True if the file exists and is symlink
+ (same as <code>-L</code>)</td></tr>
+ <tr><td><code>-F</code></td>
+ <td>True if string is a valid file, accessible via all the server's
+ currently-configured access controls for that path. This uses an
+ internal subrequest to do the check, so use it with care - it can
+ impact your server's performance!</td></tr>
+ <tr><td><code>-U</code></td>
+ <td>True if string is a valid URL, accessible via all the server's
+ currently-configured access controls for that path. This uses an
+ internal subrequest to do the check, so use it with care - it can
+ impact your server's performance!</td></tr>
<tr><td><code>-n</code></td>
<td>True if string is not empty</td></tr>
<tr><td><code>-z</code></td>
#include "http_log.h"
#include "http_core.h"
#include "http_protocol.h"
+#include "http_request.h"
#include "ap_provider.h"
#include "util_expr_private.h"
AP_IMPLEMENT_HOOK_RUN_FIRST(int, expr_lookup, (ap_expr_lookup_parms *parms),
(parms), DECLINED)
+#define LOG_MARK(info) __FILE__, __LINE__, (info)->module_index
+
static const char *ap_expr_eval_string_func(ap_expr_eval_ctx_t *ctx,
const ap_expr_t *info,
const ap_expr_t *args);
*err = NULL;
rc = ap_expr_eval(&ctx, info->root_node);
if (*err != NULL) {
- ap_log_rerror(__FILE__, __LINE__, info->module_index, APLOG_ERR, 0,
- r, "Evaluation of expression from %s:%d failed: %s",
+ ap_log_rerror(LOG_MARK(info), APLOG_ERR, 0, r,
+ "Evaluation of expression from %s:%d failed: %s",
info->filename, info->line_number, *err);
return -1;
} else {
rc = rc ? 1 : 0;
- ap_log_rerror(__FILE__, __LINE__, info->module_index, APLOG_TRACE4, 0,
- r, "Evaluation of expression from %s:%d gave: %d",
+ ap_log_rerror(LOG_MARK(info), APLOG_TRACE4, 0, r,
+ "Evaluation of expression from %s:%d gave: %d",
info->filename, info->line_number, rc);
if (vary_this)
return 0;
}
+static int op_url_subr(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
+{
+ int rc = 0;
+ request_rec *rsub, *r = ctx->r;
+ if (!r)
+ return 0;
+ /* avoid some infinite recursions */
+ if (r->main && r->main->uri && r->uri && strcmp(r->main->uri, r->uri) == 0)
+ return 0;
+
+ rsub = ap_sub_req_lookup_uri(arg, r, NULL);
+ if (rsub->status < 400) {
+ rc = 1;
+ }
+ ap_log_rerror(LOG_MARK(ctx->info), APLOG_TRACE5, 0, r,
+ "Subrequest for -U %s at %s:%d gave status: %d",
+ arg, ctx->info->filename, ctx->info->line_number,
+ rsub->status);
+ ap_destroy_sub_req(rsub);
+ return rc;
+}
+
+static int op_file_subr(ap_expr_eval_ctx_t *ctx, const void *data, const char *arg)
+{
+ int rc = 0;
+ apr_finfo_t sb;
+ request_rec *rsub, *r = ctx->r;
+ if (!r)
+ return 0;
+ rsub = ap_sub_req_lookup_file(arg, r, NULL);
+ if (rsub->status < 300 &&
+ /* double-check that file exists since default result is 200 */
+ apr_stat(&sb, rsub->filename, APR_FINFO_MIN, ctx->p) == APR_SUCCESS) {
+ rc = 1;
+ }
+ ap_log_rerror(LOG_MARK(ctx->info), APLOG_TRACE5, 0, r,
+ "Subrequest for -F %s at %s:%d gave status: %d",
+ arg, ctx->info->filename, ctx->info->line_number,
+ rsub->status);
+ ap_destroy_sub_req(rsub);
+ return rc;
+}
+
APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
static APR_OPTIONAL_FN_TYPE(ssl_is_https) *is_https = NULL;
{ op_file_link, "L", NULL },
{ op_file_link, "h", NULL },
{ op_file_xbit, "x", NULL },
+ { op_file_subr, "F", NULL },
+ { op_url_subr, "U", NULL },
{ NULL, NULL, NULL }
};