Duh! New diff attached. Documentation and tests remaining. Something like
this?
Should we keep hash_data() or rename it to hash_string() or something
similar?
On Mon, Apr 20, 2015 at 7:55 PM, Poul-Henning Kamp <[email protected]>
wrote:
> --------
> In message <[email protected]>, "Poul-Henning Kamp"
> writes:
>
> >In practice we would need to pass a flag to vcc_Expr() saying "I want
> >a FOO but BLOB is also OK" and I have a hard time seeing FOO take
> >any other value than STRING/STRING_LIST.
>
> Actually...
>
> Isn't this where we just add a
>
> std.hash_blob(BLOB)
>
> Function ?
>
>
> --
> Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
> [email protected] | TCP/IP since RFC 956
> FreeBSD committer | BSD since 4.3-tahoe
> Never attribute to malice what can adequately be explained by incompetence.
>
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 8a15757..861679b 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -61,6 +61,7 @@
#include "hash/hash_slinger.h"
#include "vsha256.h"
#include "vtim.h"
+#include "vrt.h"
static const struct hash_slinger *hash;
static struct objhead *private_oh;
@@ -187,6 +188,19 @@ HSH_DeleteObjHead(struct worker *wrk, struct objhead *oh)
}
void
+HSH_AddBlob(struct req *req, const struct vmod_priv *priv)
+{
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ AN(req->sha256ctx);
+ if (priv != NULL) {
+ SHA256_Update(req->sha256ctx, priv->priv, priv->len);
+ VSLb(req->vsl, SLT_Hash, "%.*s", priv->len, priv->priv);
+ } else
+ SHA256_Update(req->sha256ctx, &priv, sizeof priv);
+}
+
+void
HSH_AddString(struct req *req, const char *str)
{
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 63d2502..726cfdc 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -280,6 +280,20 @@ VRT_hashdata(VRT_CTX, const char *str, ...)
HSH_AddString(ctx->req, NULL);
}
+void
+VRT_hashblob(VRT_CTX, const struct vmod_priv *priv)
+{
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+ HSH_AddBlob(ctx->req, priv);
+ /*
+ * Add a 'field-separator' to make it more difficult to
+ * manipulate the hash.
+ */
+ HSH_AddString(ctx->req, NULL);
+}
+
/*--------------------------------------------------------------------*/
double
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index 6f546ff..59acf3c 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -34,6 +34,7 @@ struct objcore;
struct busyobj;
struct worker;
struct object;
+struct vmod_priv;
typedef void hash_init_f(int ac, char * const *av);
typedef void hash_start_f(void);
@@ -67,6 +68,7 @@ enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct objcore **,
int wait_for_busy, int always_insert);
void HSH_Ref(struct objcore *o);
void HSH_Init(const struct hash_slinger *slinger);
+void HSH_AddBlob(struct req *, const struct vmod_priv *);
void HSH_AddString(struct req *, const char *str);
void HSH_Insert(struct worker *, const void *hash, struct objcore *);
void HSH_Purge(struct worker *, struct objhead *, double ttl, double grace,
diff --git a/include/vrt.h b/include/vrt.h
index e034f91..9f23801 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -221,6 +221,7 @@ void VRT_SetHdr(VRT_CTX, const struct gethdr_s *, const char *, ...);
void VRT_handling(VRT_CTX, unsigned hand);
void VRT_hashdata(VRT_CTX, const char *str, ...);
+void VRT_hashblob(VRT_CTX, const struct vmod_priv *);
/* Simple stuff */
int VRT_strcmp(const char *s1, const char *s2);
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index c4f984d..5fed907 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -301,6 +301,21 @@ parse_hash_data(struct vcc *tl)
/*--------------------------------------------------------------------*/
static void
+parse_hash_blob(struct vcc *tl)
+{
+ vcc_NextToken(tl);
+ SkipToken(tl, '(');
+
+ Fb(tl, 1, "VRT_hashblob(ctx,\n ");
+ vcc_Expr(tl, BLOB);
+ ERRCHK(tl);
+ Fb(tl, 1, ");\n");
+ SkipToken(tl, ')');
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
parse_return(struct vcc *tl)
{
int retval = 0;
@@ -413,6 +428,7 @@ static struct action_table {
{ "ban", parse_ban },
{ "call", parse_call },
{ "hash_data", parse_hash_data, VCL_MET_HASH },
+ { "hash_blob", parse_hash_blob, VCL_MET_HASH },
{ "new", parse_new, VCL_MET_INIT},
{ "return", parse_return },
{ "rollback", parse_rollback },
_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev