httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1032393 - in /httpd/httpd/trunk: docs/manual/expr.xml server/util_expr_eval.c
Date Sun, 07 Nov 2010 21:09:20 GMT
Author: sf
Date: Sun Nov  7 21:09:19 2010
New Revision: 1032393

URL: http://svn.apache.org/viewvc?rev=1032393&view=rev
Log:
Port "file" function from ssl_expr

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

Modified: httpd/httpd/trunk/docs/manual/expr.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/expr.xml?rev=1032393&r1=1032392&r2=1032393&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/expr.xml (original)
+++ httpd/httpd/trunk/docs/manual/expr.xml Sun Nov  7 21:09:19 2010
@@ -290,7 +290,7 @@ listfunction ::= listfuncname "<strong>(
         <td>Lookup operating system environment variable</td></tr>
     <tr><td><code>env</code></td>
         <td>Lookup request environment variable (XXX: will need to be changed for better
ssl_expr compat)</td></tr>
-    <tr><td><code>lolower</code></td>
+    <tr><td><code>tolower</code></td>
         <td>Convert string to lower case</td></tr>
     <tr><td><code>toupper</code></td>
         <td>Convert string to uppser case</td></tr>
@@ -298,6 +298,8 @@ listfunction ::= listfuncname "<strong>(
         <td>Escape special characters in %hex encoding</td></tr>
     <tr><td><code>unescape</code></td>
         <td>Unescape %hex encoded string, leaving URL-special characters encoded (XXX:
describe better)</td></tr>
+    <tr><td><code>file</code></td>
+        <td>Read contents from a file</td></tr>
     </table>
 
     <p>In addition to string-valued functions, there are also list-valued functions
which

Modified: httpd/httpd/trunk/server/util_expr_eval.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_expr_eval.c?rev=1032393&r1=1032392&r2=1032393&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr_eval.c (original)
+++ httpd/httpd/trunk/server/util_expr_eval.c Sun Nov  7 21:09:19 2010
@@ -749,6 +749,51 @@ static const char *escape_func(ap_expr_e
     return ap_escape_uri(ctx->p, arg);
 }
 
+#define MAX_FILE_SIZE 10*1024*1024
+static const char *file_func(ap_expr_eval_ctx *ctx, const char *name, char *arg)
+{
+    apr_file_t *fp;
+    char *buf;
+    apr_off_t offset;
+    apr_size_t len;
+    apr_finfo_t finfo;
+
+    if (apr_file_open(&fp, arg, APR_READ|APR_BUFFERED,
+                      APR_OS_DEFAULT, ctx->p) != APR_SUCCESS) {
+        *ctx->err = apr_psprintf(ctx->p, "Cannot open file %s", arg);
+        return "";
+    }
+    apr_file_info_get(&finfo, APR_FINFO_SIZE, fp);
+    if (finfo.size > MAX_FILE_SIZE) {
+        *ctx->err = apr_psprintf(ctx->p, "File %s too large", arg);
+        apr_file_close(fp);
+        return "";
+    }
+    len = (apr_size_t)finfo.size;
+    if (len == 0) {
+        apr_file_close(fp);
+        return "";
+    }
+    else {
+        if ((buf = (char *)apr_palloc(ctx->p, sizeof(char)*(len+1))) == NULL) {
+            *ctx->err = "Cannot allocate memory";
+            apr_file_close(fp);
+            return "";
+        }
+        offset = 0;
+        apr_file_seek(fp, APR_SET, &offset);
+        if (apr_file_read(fp, buf, &len) != APR_SUCCESS) {
+            *ctx->err = apr_psprintf(ctx->p, "Cannot read from file %s", arg);
+            apr_file_close(fp);
+            return "";
+        }
+        buf[len] = '\0';
+    }
+    apr_file_close(fp);
+    return buf;
+}
+
+
 static const char *unescape_func(ap_expr_eval_ctx *ctx, const char *name, const char *arg)
 {
     char *result = apr_pstrdup(ctx->p, arg);
@@ -988,6 +1033,7 @@ static const struct expr_provider_single
     { toupper_func, "toupper" },
     { escape_func, "escape" },
     { unescape_func, "unescape" },
+    { file_func, "file" },
     { NULL, NULL}
 };
 /* XXX: base64 encode/decode ? */



Mime
View raw message