r412 - in trunk/varnish-cache: bin/varnishlog include lib/libvarnishapi
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jul 10 22:27:52 CEST 2006
Author: phk
Date: 2006-07-10 22:27:52 +0200 (Mon, 10 Jul 2006)
New Revision: 412
Modified:
trunk/varnish-cache/bin/varnishlog/varnishlog.c
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
Add tag names array to libvarnishapi, everybody is going to need it.
Implement -i tag[,tag ...] and -x tag[,tag ...] generic arguments.
Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2006-07-10 19:54:33 UTC (rev 411)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2006-07-10 20:27:52 UTC (rev 412)
@@ -16,11 +16,6 @@
#include "shmlog.h"
#include "varnishapi.h"
-static const char *tagnames[] = {
-#define SLTM(foo) [SLT_##foo] = #foo,
-#include "shmlog_tags.h"
-#undef SLTM
-};
static char *
vis_it(unsigned char *p)
@@ -69,7 +64,7 @@
switch (p[0]) {
case SLT_VCL_call:
sbuf_printf(ob[u], "%02x %3d %4d %-12s",
- p[0], p[1], u, tagnames[p[0]]);
+ p[0], p[1], u, VSL_tags[p[0]]);
if (p[1] > 0) {
sbuf_cat(ob[u], " <");
sbuf_bcat(ob[u], p + 4, p[1]);
@@ -106,7 +101,7 @@
else if (p[1] > 4 && !memcmp(p + 4, "TTD:", 4))
break;
sbuf_printf(ob[u], "%02x %3d %4d %-12s",
- p[0], p[1], u, tagnames[p[0]]);
+ p[0], p[1], u, VSL_tags[p[0]]);
if (p[1] > 0)
sbuf_cat(ob[u], vis_it(p));
sbuf_cat(ob[u], "\n");
@@ -153,7 +148,7 @@
}
if (v) {
sbuf_printf(ob[u], "%02x %3d %4d %-12s",
- p[0], p[1], u, tagnames[p[0]]);
+ p[0], p[1], u, VSL_tags[p[0]]);
if (p[1] > 0) {
sbuf_cat(ob[u], " <");
sbuf_bcat(ob[u], p + 4, p[1]);
@@ -210,7 +205,10 @@
vd = VSL_New();
while ((c = getopt(argc, argv, VSL_ARGS "how:")) != -1) {
- if (VSL_Arg(vd, c, optarg))
+ i = VSL_Arg(vd, c, optarg);
+ if (i < 0)
+ exit (1);
+ if (i > 0)
continue;
switch (c) {
case 'h':
@@ -273,7 +271,7 @@
}
u = (p[2] << 8) | p[3];
printf("%02x %3d %4d %-12s",
- p[0], p[1], u, tagnames[p[0]]);
+ p[0], p[1], u, VSL_tags[p[0]]);
if (p[1] > 0) {
if (p[0] != SLT_Debug) {
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2006-07-10 19:54:33 UTC (rev 411)
+++ trunk/varnish-cache/include/varnishapi.h 2006-07-10 20:27:52 UTC (rev 412)
@@ -8,13 +8,14 @@
#define V_DEAD __attribute__ ((noreturn))
/* shmlog.c */
-#define VSL_ARGS "r:"
+#define VSL_ARGS "r:i:x:"
struct VSL_data;
struct VSL_data *VSL_New(void);
int VSL_OpenLog(struct VSL_data *vd);
unsigned char *VSL_NextLog(struct VSL_data *lh);
int VSL_Arg(struct VSL_data *vd, int arg, const char *opt);
struct varnish_stats *VSL_OpenStats(void);
+const char *VSL_tags[256];
/* varnish_debug.c */
Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2006-07-10 19:54:33 UTC (rev 411)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c 2006-07-10 20:27:52 UTC (rev 412)
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <errno.h>
+#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
@@ -18,9 +19,12 @@
unsigned char *logstart;
unsigned char *logend;
unsigned char *ptr;
- char *r_arg;
+
FILE *fi;
unsigned char rbuf[4 + 255 + 1];
+
+ int ix_opt;
+ unsigned char supr[256];
};
#ifndef MAP_HASSEMAPHORE
@@ -32,6 +36,14 @@
/*--------------------------------------------------------------------*/
+const char *VSL_tags[256] = {
+#define SLTM(foo) [SLT_##foo] = #foo,
+#include "shmlog_tags.h"
+#undef SLTM
+};
+
+/*--------------------------------------------------------------------*/
+
static int
vsl_shmem_map(void)
{
@@ -84,22 +96,16 @@
VSL_OpenLog(struct VSL_data *vd)
{
- if (vd->r_arg != NULL) {
- if (!strcmp(vd->r_arg, "-"))
- vd->fi = stdin;
- else
- vd->fi = fopen(vd->r_arg, "r");
- if (vd->fi != NULL)
- return (0);
- perror(vd->r_arg);
- return (1);
- }
+ if (vd->fi != NULL)
+ return (0);
+
if (vsl_shmem_map())
return (1);
+ vd->head = vsl_lh;
vd->logstart = (unsigned char *)vsl_lh + vsl_lh->start;
vd->logend = vd->logstart + vsl_lh->size;
- vd->head = vsl_lh;
+ vd->ptr = vd->logstart;
return (0);
}
@@ -110,21 +116,22 @@
int i;
if (vd->fi != NULL) {
- i = fread(vd->rbuf, 4, 1, vd->fi);
- if (i != 1)
- return (NULL);
- if (vd->rbuf[1] > 0) {
- i = fread(vd->rbuf + 4, vd->rbuf[1], 1, vd->fi);
+ while (1) {
+ i = fread(vd->rbuf, 4, 1, vd->fi);
if (i != 1)
return (NULL);
+ if (vd->rbuf[1] > 0) {
+ i = fread(vd->rbuf + 4, vd->rbuf[1], 1, vd->fi);
+ if (i != 1)
+ return (NULL);
+ }
+ if (!vd->supr[vd->rbuf[0]])
+ return (vd->rbuf);
}
- return (vd->rbuf);
}
p = vd->ptr;
- if (p == NULL)
- p = vd->logstart;
- while (1) {
+ for (p = vd->ptr; ; p = vd->ptr) {
if (*p == SLT_WRAPMARKER) {
p = vd->logstart;
continue;
@@ -134,17 +141,89 @@
return (NULL);
}
vd->ptr = p + p[1] + 4;
- return (p);
+ if (!vd->supr[p[0]])
+ return (p);
}
}
+/*--------------------------------------------------------------------*/
+
+static int
+vsl_r_arg(struct VSL_data *vd, const char *opt)
+{
+
+ if (!strcmp(opt, "-"))
+ vd->fi = stdin;
+ else
+ vd->fi = fopen(opt, "r");
+ if (vd->fi != NULL)
+ return (1);
+ perror(opt);
+ return (-1);
+}
+
+/*--------------------------------------------------------------------*/
+
+static int
+vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg)
+{
+ int i, j, l;
+ const char *b, *e, *p, *q;
+
+ /* If first option is 'i', set all bits for supression */
+ if (arg == 'i' && vd->ix_opt == 0)
+ for (i = 0; i < 256; i++)
+ vd->supr[i] = 1;
+ vd->ix_opt = 1;
+
+ for (b = opt; *b; b = e) {
+ while (isspace(*b))
+ b++;
+ e = strchr(b, ',');
+ if (e == NULL)
+ e = strchr(b, '\0');
+ l = e - b;
+ if (*e == ',')
+ e++;
+ while (isspace(b[l - 1]))
+ l--;
+ for (i = 0; i < 256; i++) {
+ if (VSL_tags[i] == NULL)
+ continue;
+ p = VSL_tags[i];
+ q = b;
+ for (j = 0; j < l; j++)
+ if (tolower(*q++) != tolower(*p++))
+ break;
+ if (j != l)
+ continue;
+
+ if (arg == 'x')
+ vd->supr[i] = 1;
+ else
+ vd->supr[i] = 0;
+ break;
+ }
+ if (i == 256) {
+ fprintf(stderr,
+ "Could not match \"%*.*s\" to any tag\n", l, l, b);
+ return (-1);
+ }
+ }
+ return (1);
+}
+
+/*--------------------------------------------------------------------*/
+
int
VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
{
switch (arg) {
+ case 'i':
+ case 'x':
+ return (vsl_ix_arg(vd, opt, arg));
case 'r':
- vd->r_arg = strdup(opt);
- return (1);
+ return (vsl_r_arg(vd, opt));
default:
return (0);
}
More information about the varnish-commit
mailing list