httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1457450 - in /httpd/httpd/trunk: docs/manual/expr.xml server/util_expr_eval.c
Date Sun, 17 Mar 2013 13:52:58 GMT
Author: minfrin
Date: Sun Mar 17 13:52:58 2013
New Revision: 1457450

URL: http://svn.apache.org/r1457450
Log:
Expression parser: Add the ability to apply a SHA1 hash to strings within
the parser.

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=1457450&r1=1457449&r2=1457450&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/expr.xml (original)
+++ httpd/httpd/trunk/docs/manual/expr.xml Sun Mar 17 13:52:58 2013
@@ -477,6 +477,9 @@ listfunction ::= listfuncname "<strong>(
     <tr><td><code>unbase64</code></td>
         <td>Decode base64 encoded string, return truncated string if 0x00 is
             found</td><td></td></tr>
+    <tr><td><code>sha1</code></td>
+        <td>Hash the string using SHA1, then encode the hash with base64
+            encoding</td><td></td></tr>
     <tr><td><code>file</code></td>
         <td>Read contents from a file</td><td>yes</td></tr>
     <tr><td><code>filesize</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=1457450&r1=1457449&r2=1457450&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_expr_eval.c (original)
+++ httpd/httpd/trunk/server/util_expr_eval.c Sun Mar 17 13:52:58 2013
@@ -28,6 +28,8 @@
 
 #include "apr_lib.h"
 #include "apr_fnmatch.h"
+#include "apr_base64.h"
+#include "apr_sha1.h"
 
 #include <limits.h>     /* for INT_MAX */
 
@@ -1031,6 +1033,25 @@ static const char *unbase64_func(ap_expr
     return ap_pbase64decode(ctx->p, arg);
 }
 
+static const char *sha1_func(ap_expr_eval_ctx_t *ctx, const void *data,
+                               const char *arg)
+{
+    int l;
+    apr_sha1_ctx_t context;
+    apr_byte_t digest[APR_SHA1_DIGESTSIZE];
+    char *out = apr_palloc(ctx->p, 28);
+
+    apr_sha1_init(&context);
+    apr_sha1_update(&context, arg, strlen(arg));
+    apr_sha1_final(digest, &context);
+
+    /* SHA1 hash is always 20 chars */
+    l = apr_base64_encode_binary(out, digest, sizeof(digest));
+    out[l] = '\0';
+
+    return out;
+}
+
 #define MAX_FILE_SIZE 10*1024*1024
 static const char *file_func(ap_expr_eval_ctx_t *ctx, const void *data,
                              char *arg)
@@ -1612,6 +1633,7 @@ static const struct expr_provider_single
     { filesize_func,        "filesize",       NULL, 1 },
     { base64_func,          "base64",         NULL, 0 },
     { unbase64_func,        "unbase64",       NULL, 0 },
+    { sha1_func,            "sha1",           NULL, 0 },
     { NULL, NULL, NULL}
 };
 /* XXX: base64 encode/decode ? */



Mime
View raw message