src/lib/udc.c 1.8

1.8 2009/02/11 01:36:51 kent
Cgi-encoding file names in cache dir.
Index: src/lib/udc.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/udc.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -b -B -U 4 -r1.7 -r1.8
--- src/lib/udc.c	9 Feb 2009 04:33:23 -0000	1.7
+++ src/lib/udc.c	11 Feb 2009 01:36:51 -0000	1.8
@@ -27,8 +27,9 @@
 #include "bits.h"
 #include "portable.h"
 #include "sig.h"
 #include "net.h"
+#include "cheapcgi.h"
 #include "udc.h"
 
 #define udcBlockSize (8*1024)
 /* All fetch requests are rounded up to block size. */
@@ -513,8 +514,27 @@
 
 udcBitmapClose(&bits);
 }
 
+static char *cgiEncodeExceptDirs(char *input)
+/* CGI-encode every char in input except for the / chars. */
+{
+struct dyString *dy = dyStringNew(strlen(input)+16);
+char *s, *e;
+
+for (s = input; s != NULL; s = e)
+    {
+    e = strchr(s, '/');
+    if (e != NULL)
+	*e++ = 0;
+    char *encoded = cgiEncode(s);
+    dyStringAppend(dy, encoded);
+    if (e != NULL)
+        dyStringAppendC(dy, '/');
+    freeMem(encoded);
+    }
+return dyStringCannibalize(&dy);
+}
 
 struct udcFile *udcFileMayOpen(char *url, char *cacheDir)
 /* Open up a cached file.  Return NULL if file doesn't exist. */
 {
@@ -530,13 +550,14 @@
     protocol = cloneStringZ(url, colonPos);
     afterProtocol = url + colonPos + 1;
     while (afterProtocol[0] == '/')
        afterProtocol += 1;
+    afterProtocol = cgiEncodeExceptDirs(afterProtocol);
     }
 else
     {
     protocol = cloneString("transparent");
-    afterProtocol = url;
+    afterProtocol = cloneString(url);
     isTransparent = TRUE;
     }
 prot = udcProtocolNew(protocol);
 
@@ -586,8 +607,9 @@
     /* Figure out a little bit about the extent of the good cached data if any. */
     setInitialCachedDataBounds(file);
     file->fSparse = mustOpen(file->sparseFileName, "rb+");
     }
+freeMem(afterProtocol);
 return file;
 }
 
 struct udcFile *udcFileOpen(char *url, char *cacheDir)