#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)
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]);
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");
}
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]);
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':
}
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) {
#include <stdio.h>
#include <errno.h>
+#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
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
/*--------------------------------------------------------------------*/
+const char *VSL_tags[256] = {
+#define SLTM(foo) [SLT_##foo] = #foo,
+#include "shmlog_tags.h"
+#undef SLTM
+};
+
+/*--------------------------------------------------------------------*/
+
static int
vsl_shmem_map(void)
{
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);
}
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;
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);
}