From 090830ffc84760fa8431a2f2f646a31980f7a534 Mon Sep 17 00:00:00 2001 From: andersb Date: Thu, 10 Aug 2006 11:48:24 +0000 Subject: [PATCH] Got the requesttime right this time. I am noticing free()'s that are freeing empty variables/pointers. Have to find where is happens. Also noticing IP adresses not set correctly. Still load of debugcode. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@784 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishncsa/varnishncsa.c | 40 ++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/varnish-cache/bin/varnishncsa/varnishncsa.c b/varnish-cache/bin/varnishncsa/varnishncsa.c index e7d75e9d..cc13bd70 100644 --- a/varnish-cache/bin/varnishncsa/varnishncsa.c +++ b/varnish-cache/bin/varnishncsa/varnishncsa.c @@ -42,6 +42,7 @@ struct logline { int df_rfini; // Set to 1 when a ReqServTime has come. unsigned char *df_s; // Datafield for %s, Status unsigned char *df_b; // Datafield for %b, Bytes + struct tm *logline_time; // Datafield for %t }; /* We make a array of pointers to vsb's. Sbuf is a string buffer. @@ -83,6 +84,15 @@ extended_log_format(unsigned char *p, char *w_opt) unsigned char *tmpPtr; int j; + // Used for requesttime. + char *tmpPtra; + char *tmpPtrb; + char *tmpPtrc; + int timesec = 0; // Where we store the utime for request as int. + char temp_time[27]; // Where we store the string we take from the log + time_t req_time; // Timeobject used for making the requesttime. + int i; + u = (p[2] << 8) | p[3]; if (ob[u] == NULL) { ob[u] = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); @@ -91,6 +101,8 @@ extended_log_format(unsigned char *p, char *w_opt) v = 0; w = 0; + i = 0; + j = 0; ll[u].df_rfini = 0; ll[u].df_hfini = 0; @@ -172,6 +184,30 @@ extended_log_format(unsigned char *p, char *w_opt) // We use ReqServTime to find how the time the request was delivered // also to define that a request is finished. + tmpPtra = strdup(p + 4); + temp_time[0] = '\0'; + + for ( tmpPtrb = strtok(tmpPtra," "); tmpPtrb != NULL; tmpPtrb = strtok(NULL, " ")){ + if (i == 1){ + // We have the right time + free(tmpPtra); + tmpPtra = tmpPtrb; + } + //printf("ReqServTime number %d: %s\n", i, tmpPtrb); + + i++; + } + tmpPtrc = strchr(tmpPtra, '.'); + j = strlen(tmpPtrc); // length of timestamp + //printf("j=%d\n", j); + strncpy(temp_time, tmpPtra, j); + temp_time[j] = '\0'; + //printf("inten: %s\n",temp_time); + timesec = atoi(temp_time); + req_time = timesec; + ll[u].logline_time = localtime(&req_time); + strftime (temp_time, 50, "[%d/%b/%Y:%X %z] ", ll[u].logline_time); + ll[u].df_rfini = 1; printf("ReqServTime [%d]\n", u); @@ -224,6 +260,8 @@ extended_log_format(unsigned char *p, char *w_opt) default: + // printf("DEBUG: %s\n", p+4); + break; } @@ -232,7 +270,7 @@ extended_log_format(unsigned char *p, char *w_opt) // We have a ReqServTime. Lets print the logline // and clear variables that are different for each request. - printf("[%d] %s ", u, ll[u].df_h ); + printf("[%d] %s - - %s ", u, ll[u].df_h, temp_time ); vsb_finish(ob[u]); printf("\"%s\"", vsb_data(ob[u])); printf(" %s %s ", ll[u].df_s, ll[u].df_b); -- 2.39.5