From ba968c68979532b832826b21845e22d11f3e629b Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 10 Jul 2007 19:59:39 +0000 Subject: [PATCH] Add conversion from IP to string format to allow things like: set bereq.http.HeyYou = client.ip " asked for " req.url; git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1663 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_vrt.c | 16 ++++++++++++++++ varnish-cache/include/vrt.h | 1 + varnish-cache/lib/libvcl/vcc_fixed_token.c | 1 + varnish-cache/lib/libvcl/vcc_string.c | 3 +++ 4 files changed, 21 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 4edcbea8..9e56ccb3 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -472,3 +472,19 @@ VRT_r_obj_lastuse(struct sess *sp) clock_gettime(CLOCK_MONOTONIC, &now); return (now.tv_sec - sp->obj->lru_stamp); } + +/*--------------------------------------------------------------------*/ + +char * +VRT_IP_string(struct sess *sp, struct sockaddr *sa) +{ + char h[64], p[8], *q; + + TCP_name(sa, sa->sa_len, h, sizeof h, p, sizeof p); + q = WS_Alloc(sp->http->ws, strlen(h) + strlen(p) + 2); + AN(q); + strcpy(q, h); + strcat(q, ":"); + strcat(q, p); + return (q); +} diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 7f284681..7f559a49 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -85,6 +85,7 @@ void VRT_alloc_backends(struct VCL_conf *cp); void VRT_free_backends(struct VCL_conf *cp); void VRT_fini_backend(struct backend *be); +char *VRT_IP_string(struct sess *sp, struct sockaddr *sa); #define VRT_done(sp, hand) \ do { \ diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 0625384e..ad67b895 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -441,6 +441,7 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "void VRT_free_backends(struct VCL_conf *cp);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *be);\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "#define VRT_done(sp, hand) \\\n"); vsb_cat(sb, " do { \\\n"); diff --git a/varnish-cache/lib/libvcl/vcc_string.c b/varnish-cache/lib/libvcl/vcc_string.c index bc891437..ec7723d4 100644 --- a/varnish-cache/lib/libvcl/vcc_string.c +++ b/varnish-cache/lib/libvcl/vcc_string.c @@ -66,6 +66,9 @@ vcc_StringVal(struct tokenlist *tl) case STRING: Fb(tl, 0, "%s", vp->rname); break; + case IP: + Fb(tl, 0, "VRT_IP_string(sp, %s)", vp->rname); + break; default: vsb_printf(tl->sb, "String representation of '%s' not implemented yet.\n", -- 2.39.5