r5529 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl lib/libvmod_std
phk at varnish-cache.org
phk at varnish-cache.org
Tue Nov 9 11:53:57 CET 2010
Author: phk
Date: 2010-11-09 11:53:57 +0100 (Tue, 09 Nov 2010)
New Revision: 5529
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_vrt.c
trunk/varnish-cache/bin/varnishd/flint.lnt
trunk/varnish-cache/bin/varnishtest/tests/m00000.vtc
trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc
trunk/varnish-cache/include/vrt.h
trunk/varnish-cache/lib/libvcl/vcc_action.c
trunk/varnish-cache/lib/libvmod_std/vmod.vcc
trunk/varnish-cache/lib/libvmod_std/vmod_std.c
Log:
Add std.log(STRING_LIST) and std.syslog(INT, STRINGLIST) functions.
They do what you expect.
Remove the native VCL "log" action.
Add generic VRT_StringList() which will build a STRING_LIST into
any sized buffer, so that std.log() can build the string on the stack.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2010-11-09 10:53:57 UTC (rev 5529)
@@ -714,6 +714,7 @@
/* cache_vrt.c */
char *VRT_String(struct ws *ws, const char *h, const char *p, va_list ap);
+char *VRT_StringList(char *d, unsigned dl, const char *p, va_list ap);
/* cache_vrt_esi.c */
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-11-09 10:53:57 UTC (rev 5529)
@@ -142,6 +142,37 @@
/*lint -e{818} ap,hp could be const */
char *
+VRT_StringList(char *d, unsigned dl, const char *p, va_list ap)
+{
+ char *b, *e;
+ unsigned x;
+
+ b = d;
+ e = b + dl;
+ while (p != vrt_magic_string_end && b < e) {
+ if (p != NULL) {
+ x = strlen(p);
+ if (b + x < e)
+ memcpy(b, p, x);
+ b += x;
+ }
+ p = va_arg(ap, const char *);
+ }
+ if (b < e)
+ *b = '\0';
+ b++;
+ if (b > e)
+ return (NULL);
+ else
+ return (b);
+}
+
+/*--------------------------------------------------------------------
+ * XXX: Optimize the single element case ?
+ */
+
+/*lint -e{818} ap,hp could be const */
+char *
VRT_String(struct ws *ws, const char *h, const char *p, va_list ap)
{
char *b, *e;
@@ -159,27 +190,15 @@
*b = ' ';
b++;
}
- while (p != vrt_magic_string_end && b < e) {
- if (p != NULL) {
- x = strlen(p);
- if (b + x < e)
- memcpy(b, p, x);
- b += x;
- }
- p = va_arg(ap, const char *);
- }
- if (b < e)
- *b = '\0';
- b++;
- if (b > e) {
+ b = VRT_StringList(b, e > b ? e - b : 0, p, ap);
+ if (b == NULL || b == e) {
WS_Release(ws, 0);
return (NULL);
- } else {
- e = b;
- b = ws->f;
- WS_Release(ws, e - b);
- return (b);
- }
+ }
+ e = b;
+ b = ws->f;
+ WS_Release(ws, e - b);
+ return (b);
}
/*--------------------------------------------------------------------
@@ -439,15 +458,6 @@
/*--------------------------------------------------------------------*/
void
-VRT_log(struct sess *sp, const char *str)
-{
-
- WSP(sp, SLT_VCL_Log, "%s", str);
-}
-
-/*--------------------------------------------------------------------*/
-
-void
VRT_ban(struct sess *sp, char *cmds, ...)
{
char *a1, *a2, *a3;
Modified: trunk/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishd/flint.lnt 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/bin/varnishd/flint.lnt 2010-11-09 10:53:57 UTC (rev 5529)
@@ -55,6 +55,7 @@
-e459 // unlocked access from func-ptr
-e454 // mutex not released (...ReleaseLocked)
-e457 // unprotected access
+-e835 // A zero has been given as ___ argument to operator '___' (<<)
-e777 // float equality comparison
-e679 // Suspicious Truncation in arithmetic expression combining with pointer
Modified: trunk/varnish-cache/bin/varnishtest/tests/m00000.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/m00000.vtc 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/bin/varnishtest/tests/m00000.vtc 2010-11-09 10:53:57 UTC (rev 5529)
@@ -13,6 +13,8 @@
sub vcl_deliver {
set resp.http.foo = std.toupper(resp.http.foo);
set resp.http.bar = std.tolower(resp.http.bar);
+ std.log("VCL initiated log");
+ std.syslog(8 + 7, "Somebody runs varnishtest");
}
} -start
Modified: trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc 2010-11-09 10:53:57 UTC (rev 5529)
@@ -116,8 +116,3 @@
backend b { .host = "127.0.0.1"; }
sub vcl_error { synthetic if "foo"; }
}
-
-varnish v1 -vcl {
- backend b { .host = "127.0.0.1"; }
- sub vcl_recv { log "FOO"; }
-}
Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/include/vrt.h 2010-11-09 10:53:57 UTC (rev 5529)
@@ -155,7 +155,6 @@
void VRT_ban(struct sess *sp, char *, ...);
void VRT_ban_string(struct sess *sp, const char *);
void VRT_purge(struct sess *sp, double ttl, double grace);
-void VRT_log(struct sess *, const char *msg);
void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *);
Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2010-11-09 10:53:57 UTC (rev 5529)
@@ -385,19 +385,7 @@
}
/*--------------------------------------------------------------------*/
-static void
-parse_log(struct vcc *tl)
-{
- vcc_NextToken(tl);
- Fb(tl, 1, "VRT_log(sp, ");
- vcc_Expr(tl, STRING);
- ERRCHK(tl);
- Fb(tl, 0, ");\n");
-}
-
-/*--------------------------------------------------------------------*/
-
typedef void action_f(struct vcc *tl);
static struct action_table {
@@ -425,7 +413,6 @@
{ "set", parse_set },
{ "synthetic", parse_synthetic },
{ "unset", parse_unset },
- { "log", parse_log },
{ NULL, NULL }
};
Modified: trunk/varnish-cache/lib/libvmod_std/vmod.vcc
===================================================================
--- trunk/varnish-cache/lib/libvmod_std/vmod.vcc 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/lib/libvmod_std/vmod.vcc 2010-11-09 10:53:57 UTC (rev 5529)
@@ -31,3 +31,5 @@
Function STRING tolower(PRIV_VCL, STRING_LIST)
Function VOID set_ip_tos(INT)
Function REAL random(REAL, REAL)
+Function VOID log(STRING_LIST)
+Function VOID syslog(INT, STRING_LIST)
Modified: trunk/varnish-cache/lib/libvmod_std/vmod_std.c
===================================================================
--- trunk/varnish-cache/lib/libvmod_std/vmod_std.c 2010-11-09 10:16:38 UTC (rev 5528)
+++ trunk/varnish-cache/lib/libvmod_std/vmod_std.c 2010-11-09 10:53:57 UTC (rev 5529)
@@ -29,6 +29,7 @@
#include <ctype.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <syslog.h>
#include <netinet/in.h>
#include "vrt.h"
#include "../../bin/varnishd/cache.h"
@@ -133,3 +134,30 @@
a += lo;
return (a);
}
+
+void
+vmod_log(struct sess *sp, const char *fmt, ...)
+{
+ char buf[64*1024], *p;
+ va_list ap;
+
+ va_start(ap, fmt);
+ p = VRT_StringList(buf, sizeof buf, fmt, ap);
+ va_end(ap);
+ if (p != NULL)
+ WSP(sp, SLT_VCL_Log, "%s", buf);
+}
+
+void
+vmod_syslog(struct sess *sp, int fac, const char *fmt, ...)
+{
+ char buf[64*1024], *p;
+ va_list ap;
+
+ (void)sp;
+ va_start(ap, fmt);
+ p = VRT_StringList(buf, sizeof buf, fmt, ap);
+ va_end(ap);
+ if (p != NULL)
+ syslog(fac, "%s", buf);
+}
More information about the varnish-commit
mailing list