r5497 - trunk/varnish-cache/bin/varnishncsa

tfheen at varnish-cache.org tfheen at varnish-cache.org
Wed Nov 3 12:07:17 CET 2010


Author: tfheen
Date: 2010-11-03 12:07:17 +0100 (Wed, 03 Nov 2010)
New Revision: 5497

Modified:
   trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
Log:
Reorder format parser

Cleanup to make this code slightly more readable.


Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-11-03 10:49:42 UTC (rev 5496)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-11-03 11:07:17 UTC (rev 5497)
@@ -537,6 +537,16 @@
 		}
 		p++;
 		switch (*p) {
+
+		case 'b':
+			/* %b */
+			fprintf(fo, "%s", lp->df_b ? lp->df_b : "-");
+			break;
+
+		case 'H':
+			fprintf(fo, "%s", lp->df_H);
+			break;
+
 		case 'h':
 			if (!lp->df_h && spec & VSL_S_BACKEND)
 				fprintf(fo, "127.0.0.1");
@@ -547,48 +557,14 @@
 			fprintf(fo, "-");
 			break;
 
-		case 'u':
-			/* %u: decode authorization string */
-			if (lp->df_u != NULL) {
-				char *rubuf;
-				size_t rulen;
-
-				base64_init();
-				rulen = ((strlen(lp->df_u) + 3) * 4) / 3;
-				rubuf = malloc(rulen);
-				assert(rubuf != NULL);
-				base64_decode(rubuf, rulen, lp->df_u);
-				q = strchr(rubuf, ':');
-				if (q != NULL)
-					*q = '\0';
-				fprintf(fo, "%s", rubuf);
-				free(rubuf);
-			} else {
-				fprintf(fo, "-");
-			}
-			break;
-		case 't':
-			/* %t */
-			strftime(tbuf, sizeof tbuf, "[%d/%b/%Y:%T %z]", &lp->df_t);
-			fprintf(fo, "%s", tbuf);
-			break;
-
 		case 'm':
 			fprintf(fo, "%s", lp->df_m);
 			break;
 
-		case 'U':
-			fprintf(fo, "%s", lp->df_U);
-			break;
-
 		case 'q':
 			fprintf(fo, "%s", lp->df_q ? lp->df_q : "");
 			break;
 
-		case 'H':
-			fprintf(fo, "%s", lp->df_H);
-			break;
-
 		case 'r':
 			/*
 			 * Fake "%r".  This would be a lot easier if Varnish
@@ -610,11 +586,37 @@
 			fprintf(fo, "%s", lp->df_s);
 			break;
 
-		case 'b':
-			/* %b */
-			fprintf(fo, "%s", lp->df_b ? lp->df_b : "-");
+		case 't':
+			/* %t */
+			strftime(tbuf, sizeof tbuf, "[%d/%b/%Y:%T %z]", &lp->df_t);
+			fprintf(fo, "%s", tbuf);
 			break;
 
+		case 'U':
+			fprintf(fo, "%s", lp->df_U);
+			break;
+
+		case 'u':
+			/* %u: decode authorization string */
+			if (lp->df_u != NULL) {
+				char *rubuf;
+				size_t rulen;
+
+				base64_init();
+				rulen = ((strlen(lp->df_u) + 3) * 4) / 3;
+				rubuf = malloc(rulen);
+				assert(rubuf != NULL);
+				base64_decode(rubuf, rulen, lp->df_u);
+				q = strchr(rubuf, ':');
+				if (q != NULL)
+					*q = '\0';
+				fprintf(fo, "%s", rubuf);
+				free(rubuf);
+			} else {
+				fprintf(fo, "-");
+			}
+			break;
+
 		case '{':
 			if (strncmp(p, "{Referer}i", 10) == 0) {
 				fprintf(fo, "%s",




More information about the varnish-commit mailing list