Hi Michael,

I did something similar to this several years back using inline C:
        https://varnish-cache.org/docs/5.1/users-guide/vcl-inline-c.html 
<https://varnish-cache.org/docs/5.1/users-guide/vcl-inline-c.html>

I’m super-rusty on my C, so ask better minds, but I’d start by doing the if 
check in C and leaving the rest of the logic in VCL. I.e.
strtol() with a base of 16 (see 
http://pubs.opengroup.org/onlinepubs/7908799/xsh/strtol.html 
<http://pubs.opengroup.org/onlinepubs/7908799/xsh/strtol.html>) and then a 
direct check of that against gmtime() - delta (hopefully your unix hex 
timestamps in UTC?). Double-check the input to strtol is safe — this approach 
has untrusted inputs getting run through into C.

-Jeff

> On Apr 13, 2018, at 11:42 AM, Michael Kennedy <mich...@kennedy.ie> wrote:
> 
> Hi,
> 
> I have a URL that contains a Unix hex timestamp (something like 5ace8c5d). 
> The timestamp should be within X minutes of now, and is used as part of an 
> access control mechanism. I want to do something like this:
> 
> if (std.time(req.http.x-hextime, now) < now - 1w) {
> ...
> }
> 
> Is there an efficient way in VCL to either convert Hex to Dec so that this 
> comparison can be done, or some other solution that does not involve changing 
> the data in the URL.
> 
> Thanks,
> 
> Michael
> _______________________________________________
> varnish-misc mailing list
> varnish-misc@varnish-cache.org <mailto:varnish-misc@varnish-cache.org>
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc 
> <https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc>
_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

Reply via email to