r686 - trunk/varnish-cache/bin/varnishncsa

andersb at projects.linpro.no andersb at projects.linpro.no
Sun Aug 6 00:12:28 CEST 2006


Author: andersb
Date: 2006-08-06 00:12:28 +0200 (Sun, 06 Aug 2006)
New Revision: 686

Modified:
   trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
Log:
Loglines with no IP should no longer appear. That also cleared all lines containing a null. Not sure if my check for IP is to harsly implemented and cleans to much.

Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2006-08-05 21:35:54 UTC (rev 685)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2006-08-05 22:12:28 UTC (rev 686)
@@ -35,7 +35,10 @@
 
 struct logline {
 	char df_h[4 * (3 + 1)]; // Datafield for %h (IP adress)
-	//   int y;
+	// XXX Set to 1 if we have a IP adress. Not sure when to unset.
+	// Know for sure when we have a real SessionClose. Probably
+	// When we clean also. When we have timeout. Are there any more?
+	int w;
 	//   unsigned char *df_l; // Datafield for %l
 	//   unsigned char *df_u; // Datafield for %u
 	struct tm *logline_time; // Datafield for %t
@@ -79,7 +82,7 @@
 static void 
 extended_log_format(unsigned char *p, char *w_opt)
 {
-	unsigned u,v;
+	unsigned u,v,w;
 	int i,j;
 	unsigned char *tmpPtr;
 	char *tmpPtra;
@@ -115,6 +118,7 @@
 	
 	i = 0;
 	v = 0;
+	w = 0;
 
 	switch (p[0]) {
 
@@ -129,6 +133,8 @@
 	        strncpy(ll[u].df_h, p + 4, j);
 		ll[u].df_h[j] = '\0'; // put on a NULL at end of buffer.
 		//printf("New session [%d]: %s \n",u, ll[u].df_h);
+		ll[u].w = 1; // We have IP
+		//printf("w = 1\n");
 
 		break;
 
@@ -191,6 +197,7 @@
 			ll[u].df_R = strdup(p + 4);
 			ll[u].df_R[0] = '-';
 			ll[u].df_R[1] = '\0';
+			cm_R = 1;
 		}
 
 		break;
@@ -226,6 +233,7 @@
 		req_time = timesec;
 		ll[u].logline_time = localtime(&req_time);
 		strftime (temp_time, 50, "[%d/%b/%Y:%X %z] ", ll[u].logline_time);
+		cm_r = 1;
 
 		break;
 
@@ -248,15 +256,17 @@
 	case SLT_SessionClose:
 
 		if (p[1] >= 7 && !strncasecmp((void *)&p[4], "timeout",7)){
+			// XXX what to do with the timeout?
+			// Right now I am gonna just let it pass, and not even clean memory.
 			//printf("Timeout...\n");
+			ll[u].w = 0;
 		}
 		else{
-			
-			
+
+			v = 1; // We are done, clean memory
+			ll[u].w = 0;
 		}
 
-		v = 1; // We are done, clean memory
-		
 		break;
 
 	case SLT_SessionReuse:
@@ -272,6 +282,8 @@
 			j = strlen(p + 4) - strlen(tmpPtr);                // length of IP
 			strncpy(ll[u].df_h, p + 4, j);
 			ll[u].df_h[j] = '\0'; // put on a NULL at end of buffer.
+			ll[u].w = 1; // We have a IP
+			//printf("w = 1\n");
 
 		}
 		
@@ -285,8 +297,13 @@
 		break;
 	}
 
-	// Memorycleaner and stringwriter.
-	if (v) {
+	// Memorycleaner and stringwriter. v is 1 after SLT_SessionClose OR SLT_SessionReuse that
+	// do something useful. w is set when we have a real IP adress, somewhere we are getting
+	// requests without.
+	//
+	// XXX Find out why we don't have IP and get rid of w.
+	//
+	if (v && ll[u].w) {
 	
 		
 
@@ -304,6 +321,10 @@
 			// Clean memory for User-Agent
 			free(ll[u].df_U);
 		}
+		if (cm_r){
+			// Clean memory for Date variables
+			free(tmpPtrb);
+		}
 										
 	}
 	




More information about the varnish-commit mailing list