Commit 007a9085 authored by Tollef Fog Heen's avatar Tollef Fog Heen

Re-enable -b support for varnishncsa

This isn't really functional right now, due to the log record changes,
but it will allow you to specify -b again and you can have a different
format for backend requests than for client requests.
parent e4d79ff8
...@@ -117,7 +117,8 @@ static size_t nll; ...@@ -117,7 +117,8 @@ static size_t nll;
static int m_flag = 0; static int m_flag = 0;
static const char *format; static const char *c_format;
static const char *b_format;
static int static int
isprefix(const char *str, const char *prefix, const char *end, isprefix(const char *str, const char *prefix, const char *end,
...@@ -279,6 +280,8 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, ...@@ -279,6 +280,8 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
const char *ptr, unsigned len) const char *ptr, unsigned len)
{ {
const char *end, *next, *split; const char *end, *next, *split;
struct hdr *h;
size_t l;
assert(spec & VSL_S_BACKEND); assert(spec & VSL_S_BACKEND);
end = ptr + len; end = ptr + len;
...@@ -346,38 +349,36 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, ...@@ -346,38 +349,36 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
trimline(&lp->df_s, ptr, end); trimline(&lp->df_s, ptr, end);
break; break;
case SLT_BerespHeader:
if (!lp->active)
break;
if (isprefix(ptr, "content-length:", end, &next))
trimline(&lp->df_b, next, end);
else if (isprefix(ptr, "date:", end, &next) &&
strptime(next, "%a, %d %b %Y %T", &lp->df_t) == NULL) {
clean_logline(lp);
}
break;
case SLT_BereqHeader: case SLT_BereqHeader:
case SLT_BerespHeader:
if (!lp->active) if (!lp->active)
break; break;
split = memchr(ptr, ':', len); split = memchr(ptr, ':', len);
if (split == NULL) if (split == NULL)
break; break;
if (isprefix(ptr, "authorization:", end, &next) && if (tag == SLT_BerespHeader) {
isprefix(next, "basic", end, &next)) { if (isprefix(ptr, "content-length:", end, &next))
trimline(&lp->df_u, next, end); trimline(&lp->df_b, next, end);
else if (isprefix(ptr, "date:", end, &next) &&
strptime(next, "%a, %d %b %Y %T", &lp->df_t) == NULL) {
clean_logline(lp);
}
} else { } else {
struct hdr *h; if (isprefix(ptr, "authorization:", end, &next) &&
size_t l; isprefix(next, "basic", end, &next)) {
h = calloc(1, sizeof(struct hdr)); trimline(&lp->df_u, next, end);
AN(h); }
AN(split);
l = strlen(split);
trimline(&h->key, ptr, split-1);
trimline(&h->value, split+1, split+l-1);
VTAILQ_INSERT_HEAD(&lp->req_headers, h, list);
} }
break; h = calloc(1, sizeof(struct hdr));
AN(h);
AN(split);
l = strlen(split);
trimline(&h->key, ptr, split-1);
trimline(&h->value, split+1, split+l-1);
if (tag == SLT_BereqHeader)
VTAILQ_INSERT_HEAD(&lp->req_headers, h, list);
else
VTAILQ_INSERT_HEAD(&lp->resp_headers, h, list);
case SLT_BackendReuse: case SLT_BackendReuse:
case SLT_BackendClose: case SLT_BackendClose:
...@@ -585,6 +586,7 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd, ...@@ -585,6 +586,7 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
char *q, tbuf[64]; char *q, tbuf[64];
const char *p; const char *p;
struct vsb *os; struct vsb *os;
const char *format;
/* XXX: Ignore fd's outside 65536 */ /* XXX: Ignore fd's outside 65536 */
if (fd >= 65536) if (fd >= 65536)
...@@ -607,11 +609,12 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd, ...@@ -607,11 +609,12 @@ h_ncsa(void *priv, enum VSL_tag_e tag, unsigned fd,
assert(ll[fd] != NULL); assert(ll[fd] != NULL);
} }
lp = ll[fd]; lp = ll[fd];
if (spec & VSL_S_BACKEND) { if (spec & VSL_S_BACKEND) {
collect_backend(lp, tag, spec, ptr, len); collect_backend(lp, tag, spec, ptr, len);
format = b_format;
} else if (spec & VSL_S_CLIENT) { } else if (spec & VSL_S_CLIENT) {
collect_client(lp, tag, spec, ptr, len); collect_client(lp, tag, spec, ptr, len);
format = c_format;
} else { } else {
/* huh? */ /* huh? */
return (reopen); return (reopen);
...@@ -863,38 +866,45 @@ int ...@@ -863,38 +866,45 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int c; int c;
int a_flag = 0, D_flag = 0, format_flag = 0; int a_flag = 0, D_flag = 0, format_flag = 0, b_flag = 0;
const char *P_arg = NULL; const char *P_arg = NULL;
const char *w_arg = NULL; const char *w_arg = NULL;
struct vpf_fh *pfh = NULL; struct vpf_fh *pfh = NULL;
FILE *of; FILE *of;
format = "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""; c_format = "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"";
b_format = "%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"";
vd = VSM_New(); vd = VSM_New();
while ((c = getopt(argc, argv, VSL_ARGS "aDP:Vw:fF:")) != -1) { while ((c = getopt(argc, argv, VSL_ARGS "aDP:Vw:fF:B:C:")) != -1) {
switch (c) { switch (c) {
case 'a': case 'a':
a_flag = 1; a_flag = 1;
break; break;
case 'f': case 'f':
if (format_flag) {
fprintf(stderr,
"-f and -F can not be combined\n");
exit(1);
}
format = "%{X-Forwarded-For}i %l %u %t \"%r\""
" %s %b \"%{Referer}i\" \"%{User-agent}i\"";
format_flag = 1;
break;
case 'F': case 'F':
if (format_flag) { if (format_flag) {
fprintf(stderr, fprintf(stderr,
"-f and -F can not be combined\n"); "-f, -F, -B or -C can not be combined\n");
exit(1); exit(1);
} }
format_flag = 1; format_flag = 1;
format = optarg; switch (c) {
case 'f':
b_format = c_format =
"%{X-Forwarded-For}i %l %u %t \"%r\""
" %s %b \"%{Referer}i\" \"%{User-agent}i\"";
break;
case 'F':
b_format = c_format = optarg;
break;
case 'B':
b_format = optarg;
break;
case 'C':
c_format = optarg;
break;
}
break; break;
case 'D': case 'D':
D_flag = 1; D_flag = 1;
...@@ -909,8 +919,10 @@ main(int argc, char *argv[]) ...@@ -909,8 +919,10 @@ main(int argc, char *argv[])
w_arg = optarg; w_arg = optarg;
break; break;
case 'b': case 'b':
fprintf(stderr, "-b is not valid for varnishncsa\n"); b_flag = 1;
exit(1); if (VSL_Arg(vd, c, optarg) > 0)
break;
usage();
break; break;
case 'i': case 'i':
fprintf(stderr, "-i is not valid for varnishncsa\n"); fprintf(stderr, "-i is not valid for varnishncsa\n");
...@@ -933,7 +945,8 @@ main(int argc, char *argv[]) ...@@ -933,7 +945,8 @@ main(int argc, char *argv[])
} }
} }
VSL_Arg(vd, 'c', optarg); if (! b_flag)
VSL_Arg(vd, 'c', optarg);
if (VSM_Open(vd)) { if (VSM_Open(vd)) {
fprintf(stderr, "%s\n", VSM_Error(vd)); fprintf(stderr, "%s\n", VSM_Error(vd));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment