<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>
<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
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);
{ toupper_func, "toupper" },
{ escape_func, "escape" },
{ unescape_func, "unescape" },
+ { file_func, "file" },
{ NULL, NULL}
};
/* XXX: base64 encode/decode ? */