Skip to content

Commit

Permalink
Include vhost in page request
Browse files Browse the repository at this point in the history
  • Loading branch information
simark committed Aug 28, 2013
1 parent d4016d7 commit 0ff83b8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
26 changes: 24 additions & 2 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/*
* "_XOPEN_SOURCE" is required for the GNU libc to export "strptime(3)"
* correctly.
* correctly.
*/
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
Expand Down Expand Up @@ -182,6 +182,7 @@ init_log_item (GLog * logger)
log->agent = NULL;
log->date = NULL;
log->host = NULL;
log->vhost = NULL;
log->ref = NULL;
log->req = NULL;
log->status = NULL;
Expand All @@ -200,6 +201,8 @@ free_logger (GLogItem * log)
free (log->date);
if (log->host != NULL)
free (log->host);
if (log->vhost != NULL)
free (log->vhost);
if (log->ref != NULL)
free (log->ref);
if (log->req != NULL)
Expand Down Expand Up @@ -365,7 +368,7 @@ process_host_agents (char *host, char *agent)
memcpy (tmp, ptr_value, len1);
tmp[len1] = '|';
/*
* NUL-terminated
* NUL-terminated
*/
memcpy (tmp + len1 + 1, a, len2 + 1);
} else
Expand Down Expand Up @@ -687,6 +690,12 @@ parse_format (GLogItem * log, const char *fmt, const char *date_format,
free (tkn);
break;
/* everything else skip it */
case 'v':
tkn = parse_string (&str, p[1]);
if (tkn == NULL)
tkn = alloc_string("???");
log->vhost = tkn;
break;
default:
if ((pch = strchr (str, p[1])) != NULL)
str += pch - str;
Expand Down Expand Up @@ -748,6 +757,19 @@ process_log (GLog * logger, char *line, int test)
return 0;
}

if (log->vhost != NULL) {
char *req = log->req;
char *vhost = log->vhost;
char *new_req;

int len = strlen(req) + strlen(vhost) + 1;
new_req = xmalloc(len);
strcpy(new_req, vhost);
strcpy(new_req + strlen(vhost), req);
log->req = new_req;
free(req);
}

convert_date (buf, log->date, conf.date_format, "%Y%m%d", DATE_LEN);
if (buf == NULL)
return 0;
Expand Down
1 change: 1 addition & 0 deletions parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct GLogItem_
char *agent;
char *date;
char *host;
char *vhost;
char *ref;
char *req;
char *status;
Expand Down
2 changes: 1 addition & 1 deletion settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static GPreConfLog logs = {
"%h %^[%d:%^] \"%r\" %s %b \"%R\" \"%u\"", /* CLF */
"%h %^[%d:%^] \"%r\" %s %b", /* CLF w/ VHost */
"%^:%^ %h %^[%d:%^] \"%r\" %s %b \"%R\" \"%u\"", /* NCSA */
"%^:%^ %h %^[%d:%^] \"%r\" %s %b", /* NCSA w/ VHost */
"%v:%^ %h %^[%d:%^] \"%r\" %s %b", /* NCSA w/ VHost */
"%d %^ %h %^ %^ %^ %^ %r %^ %s %b %^ %^ %u %R", /* W3C */
"%d %^ %^ %b %h %^ %^ %r %s %R %u %^" /* CloudFront */
};
Expand Down

0 comments on commit 0ff83b8

Please sign in to comment.