From: Graham Leggett Date: Sun, 17 Mar 2013 12:49:27 +0000 (+0000) Subject: Expression parser: Add the ability to base64 encode and base64 decode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b19513286d299da76863700aea96241256a1f9a4;p=thirdparty%2Fapache%2Fhttpd.git 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 --- diff --git a/docs/manual/expr.xml b/docs/manual/expr.xml index f537e852b3d..51bfbf3d4b8 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 56035dc84c2..4088fc42ae1 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 ? */