]> granicus.if.org Git - apache/commitdiff
Also add the -U and -F operators for doing subrequest lookups to ap_expr.
authorStefan Fritsch <sf@apache.org>
Sat, 14 May 2011 15:12:33 +0000 (15:12 +0000)
committerStefan Fritsch <sf@apache.org>
Sat, 14 May 2011 15:12:33 +0000 (15:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1103126 13f79535-47bb-0310-9956-ffa450edef68

docs/manual/expr.html.en
docs/manual/expr.xml
server/util_expr_eval.c

index f0e9c2077548cd0d237f00c8c2dc55869432153f..f2e0f95cf261b4097a8296d89663dbdac5e8f054 100644 (file)
@@ -319,21 +319,38 @@ listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
 <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>
index bc2604e82c735f4a1dfc3bf32aed111d82cdf819..d61f21dc3f6aedf0168b8f5968ce452f2b6ad73e 100644 (file)
@@ -339,8 +339,9 @@ listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
 <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">
@@ -348,15 +349,31 @@ listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
 
     <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>
index 57a328b18ff7631b5b83f04274848c665e802cee..96c489d781f6d76c9f4b0b05a5cb0756477b74dc 100644 (file)
@@ -22,6 +22,7 @@
 #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"
 
@@ -37,6 +38,8 @@ APR_HOOK_STRUCT(
 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);
@@ -722,14 +725,14 @@ AP_DECLARE(int) ap_expr_exec_re(request_rec *r, const ap_expr_info_t *info,
     *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)
@@ -946,6 +949,49 @@ static int op_file_xbit(ap_expr_eval_ctx_t *ctx, const void *data, const char *a
     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;
@@ -1326,6 +1372,8 @@ static const struct expr_provider_single unary_op_providers[] = {
     { 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 }
 };