Commit cdd3b7bb authored by Geoff Simmons's avatar Geoff Simmons

varnishevent - added formatter for %u

parent dba10578
......@@ -39,6 +39,7 @@
#include "vas.h"
#include "vsl.h"
#include "miniobj.h"
#include "base64.h"
#define C(spec) ((spec) & VSL_S_CLIENT)
#define B(spec) ((spec) & VSL_S_BACKEND)
......@@ -230,28 +231,6 @@ format_q_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
FORMAT_q(client, RxURL)
FORMAT_q(backend, TxURL)
#if 0
case 'r':
/*
* Fake "%r". This would be a lot easier if Varnish
* normalized the request URL.
*/
VSB_cat(os, lp->df_m ? lp->df_m : "-");
VSB_putc(os, ' ');
if (req_header(lp, "Host")) {
if (strncmp(req_header(lp, "Host"), "http://", 7) != 0)
VSB_cat(os, "http://");
VSB_cat(os, req_header(lp, "Host"));
} else {
VSB_cat(os, "http://localhost");
}
VSB_cat(os, lp->df_U ? lp->df_U : "-");
VSB_cat(os, lp->df_q ? lp->df_q : "");
VSB_putc(os, ' ');
VSB_cat(os, lp->df_H ? lp->df_H : "HTTP/1.0");
break;
#endif
#define FORMAT_r(dir, dx, hx) \
static void \
format_r_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
......@@ -338,28 +317,36 @@ format_U_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
FORMAT_U(client, Rx)
FORMAT_U(backend, Tx)
#if 0
case 'u':
/* %u: decode authorization string */
if (lp->df_u != NULL) {
char *rubuf;
size_t rulen;
VB64_init();
rulen = ((strlen(lp->df_u) + 3) * 4) / 3;
rubuf = malloc(rulen);
assert(rubuf != NULL);
VB64_decode(rubuf, rulen, lp->df_u);
q = strchr(rubuf, ':');
if (q != NULL)
*q = '\0';
VSB_cat(os, rubuf);
free(rubuf);
} else {
VSB_putc(os, '-');
}
break;
#endif
#define FORMAT_u(dir, hx) \
static void \
format_u_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
char **s, size_t *len) \
{ \
(void) name; \
(void) tag; \
record_t *rec; \
\
if ((rec = GET_HDR(ll, hx, "Authorization")) != NULL \
&& strncasecmp(rec->data + strlen("Authorization: "), "Basic", \
strlen("Basic")) == 0) { \
char *c, *auth = get_fld(rec, 3); \
VB64_init(); \
VB64_decode(scratch, config.max_reclen, auth); \
c = strchr(scratch, ':'); \
if (c != NULL) \
*c = '\0'; \
*s = scratch; \
*len = strlen(scratch); \
} \
else { \
strcpy(scratch, "-"); \
*s = scratch; \
*len = 1; \
} \
}
FORMAT_u(client, rx)
FORMAT_u(backend, tx)
#define FORMAT_Xio(dir, io, hx) \
static void \
......@@ -591,28 +578,6 @@ compile_fmt(char *format, compiled_fmt_t *fmt, unsigned spec, char *err)
n++;
break;
#if 0
case 'r':
/*
* Fake "%r". This would be a lot easier if Varnish
* normalized the request URL.
*/
VSB_cat(os, lp->df_m ? lp->df_m : "-");
VSB_putc(os, ' ');
if (req_header(lp, "Host")) {
if (strncmp(req_header(lp, "Host"), "http://", 7) != 0)
VSB_cat(os, "http://");
VSB_cat(os, req_header(lp, "Host"));
} else {
VSB_cat(os, "http://localhost");
}
VSB_cat(os, lp->df_U ? lp->df_U : "-");
VSB_cat(os, lp->df_q ? lp->df_q : "");
VSB_putc(os, ' ');
VSB_cat(os, lp->df_H ? lp->df_H : "HTTP/1.0");
break;
#endif
case 'r':
ADD_FMT(spec, fmt, os, n, format_r, NULL, 0);
ADD_CB_TAG(spec, fmt->tags, RxRequest, TxRequest);
......@@ -647,29 +612,12 @@ compile_fmt(char *format, compiled_fmt_t *fmt, unsigned spec, char *err)
n++;
break;
#if 0
case 'u':
/* %u: decode authorization string */
if (lp->df_u != NULL) {
char *rubuf;
size_t rulen;
VB64_init();
rulen = ((strlen(lp->df_u) + 3) * 4) / 3;
rubuf = malloc(rulen);
assert(rubuf != NULL);
VB64_decode(rubuf, rulen, lp->df_u);
q = strchr(rubuf, ':');
if (q != NULL)
*q = '\0';
VSB_cat(os, rubuf);
free(rubuf);
} else {
VSB_putc(os, '-');
}
ADD_FMT(spec, fmt, os, n, format_u, NULL, 0);
ADD_CB_TAG(spec, fmt->tags, RxHeader, TxHeader);
n++;
break;
#endif
case '{': {
const char *tmp;
char fname[100], type;
......
......@@ -263,7 +263,8 @@ collect(struct logline_t *lp, enum VSL_tag_e tag, unsigned spec,
}
else
rec = &lp->tag[tag2idx[tag]];
CHECK_OBJ_NOTNULL(rec, RECORD_MAGIC);
memcpy(rec->data, ptr, len);
rec->len = len;
}
......
......@@ -51,17 +51,17 @@
#define MAX_VSL_TAG 256
#if 0
#define DEFAULT_CFORMAT \
"%h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
#define ALT_CFORMAT \
"%{X-Forwarded-For}i %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
#endif
#if 0
#define DEFAULT_CFORMAT \
"%h %l %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\""
#define ALT_CFORMAT \
"%{X-Forwarded-For}i %l %t %U %s %b \"%{Referer}i\" \"%{User-agent}i\""
#endif
typedef enum {
DATA_EMPTY = 0,
......
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