httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1103126 - in /httpd/httpd/trunk: docs/manual/expr.html.en docs/manual/expr.xml server/util_expr_eval.c
Date Sat, 14 May 2011 15:12:34 GMT
Author: sf
Date: Sat May 14 15:12:33 2011
New Revision: 1103126

URL: http://svn.apache.org/viewvc?rev=1103126&view=rev
Log:
Also add the -U and -F operators for doing subrequest lookups to ap_expr.

Modified:
    httpd/httpd/trunk/docs/manual/expr.html.en
    httpd/httpd/trunk/docs/manual/expr.xml
    httpd/httpd/trunk/server/util_expr_eval.c

Modified: httpd/httpd/trunk/docs/manual/expr.html.en
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/expr.html.en?rev=1103126&r1=1103125&r2=1103126&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/expr.html.en (original)
+++ httpd/httpd/trunk/docs/manual/expr.html.en Sat May 14 15:12:33 2011
@@ -319,21 +319,38 @@ listfunction ::= listfuncname "<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>

Modified: httpd/httpd/trunk/docs/manual/expr.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/expr.xml?rev=1103126&r1=1103125&r2=1103126&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/expr.xml (original)
+++ httpd/httpd/trunk/docs/manual/expr.xml Sat May 14 15:12:33 2011
@@ -339,8 +339,9 @@ listfunction ::= listfuncname "<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>(
 
     <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>

Modified: httpd/httpd/trunk/server/util_expr_eval.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_expr_eval.c?rev=1103126&r1=1103125&r2=1103126&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr_eval.c (original)
+++ httpd/httpd/trunk/server/util_expr_eval.c Sat May 14 15:12:33 2011
@@ -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_
     *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
     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
     { 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 }
 };
 



Mime
View raw message