From cc78b3134b0756387897f194a20da199c08f7603 Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Sun, 17 Mar 2013 12:49:27 +0000 Subject: [PATCH] Expression parser: Add the ability to base64 encode and base64 decode strings within the parser. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1457437 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/expr.xml | 5 +++++ server/util_expr_eval.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/manual/expr.xml b/docs/manual/expr.xml index f537e852b3..51bfbf3d4b 100644 --- a/docs/manual/expr.xml +++ b/docs/manual/expr.xml @@ -472,6 +472,11 @@ listfunction ::= listfuncname "(" word ")" unescape Unescape %hex encoded string, leaving encoded slashes alone; return empty string if %00 is found + base64 + Encode the string using base64 encoding + unbase64 + Decode base64 encoded string, return truncated string if 0x00 is + found file Read contents from a fileyes filesize diff --git a/server/util_expr_eval.c b/server/util_expr_eval.c index 56035dc84c..4088fc42ae 100644 --- a/server/util_expr_eval.c +++ b/server/util_expr_eval.c @@ -1019,6 +1019,18 @@ static const char *escape_func(ap_expr_eval_ctx_t *ctx, const void *data, return ap_escape_uri(ctx->p, arg); } +static const char *base64_func(ap_expr_eval_ctx_t *ctx, const void *data, + const char *arg) +{ + return ap_pbase64encode(ctx->p, (char *)arg); +} + +static const char *unbase64_func(ap_expr_eval_ctx_t *ctx, const void *data, + const char *arg) +{ + return ap_pbase64decode(ctx->p, arg); +} + #define MAX_FILE_SIZE 10*1024*1024 static const char *file_func(ap_expr_eval_ctx_t *ctx, const void *data, char *arg) @@ -1598,6 +1610,8 @@ static const struct expr_provider_single string_func_providers[] = { { unescape_func, "unescape", NULL, 0 }, { file_func, "file", NULL, 1 }, { filesize_func, "filesize", NULL, 1 }, + { base64_func, "base64", NULL, 0 }, + { unbase64_func, "unbase64", NULL, 0 }, { NULL, NULL, NULL} }; /* XXX: base64 encode/decode ? */ -- 2.40.0