changeset 197:bb4ed821d06e

Servlet version 1.18b6 - small fixes to the mapping code (really works now)
author robcast
date Tue, 23 Dec 2003 17:26:45 +0100
parents 8125a068af80
children d6a3b6aaa203
files servlet/src/digilib/io/AliasingDocuDirCache.java servlet/src/digilib/io/DocuDirCache.java servlet/src/digilib/io/FileOps.java servlet/src/digilib/servlet/DigilibRequest.java servlet/src/digilib/servlet/Scaler.java
diffstat 5 files changed, 38 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/io/AliasingDocuDirCache.java	Mon Dec 08 16:50:59 2003 +0100
+++ b/servlet/src/digilib/io/AliasingDocuDirCache.java	Tue Dec 23 17:26:45 2003 +0100
@@ -58,7 +58,7 @@
 			throw new FileOpException("ERROR loading mapping file: " + e);
 		}
 		if (pathMap == null) {
-			throw new FileOpException("ERROR unable to load mapping file!");
+			throw new FileOpException("ERROR: unable to load mapping file!");
 		}
 
 		/*
@@ -70,6 +70,7 @@
 			String dir = (String) pathMap.get(link);
 			DocuDirectory destDir = new DocuDirectory(dir, this);
 			if (destDir.isValid()) {
+				logger.debug("Aliasing dir: "+link);
 				// add the alias name
 				putName(link, destDir);
 				// add the real dir
@@ -85,7 +86,7 @@
 	 */
 	public void putName(String name, DocuDirectory newdir) {
 		if (map.containsKey(name)) {
-			logger.warn("Baah, duplicate key in AliasingDocuDirCache.put!");
+			logger.warn("Duplicate key in AliasingDocuDirCache.put -- ignored!");
 		} else {
 			map.put(name, newdir);
 		}
--- a/servlet/src/digilib/io/DocuDirCache.java	Mon Dec 08 16:50:59 2003 +0100
+++ b/servlet/src/digilib/io/DocuDirCache.java	Tue Dec 23 17:26:45 2003 +0100
@@ -92,7 +92,7 @@
 	public void put(DocuDirectory newdir) {
 		String s = newdir.getDirName();
 		if (map.containsKey(s)) {
-			logger.warn("Baah, duplicate key in DocuDirCache.put!");
+			logger.warn("Duplicate key in DocuDirCache.put -- ignoring!");
 		} else {
 			map.put(s, newdir);
 			numFiles += newdir.size();
--- a/servlet/src/digilib/io/FileOps.java	Mon Dec 08 16:50:59 2003 +0100
+++ b/servlet/src/digilib/io/FileOps.java	Tue Dec 23 17:26:45 2003 +0100
@@ -178,6 +178,32 @@
 		return "";
 	}
 
+	/** Normalize a path name.
+	 * 
+	 * Removes leading and trailing slashes. Returns null if there is other
+	 * unwanted stuff in the path name. 
+	 * 
+	 * @param pathname
+	 * @return
+	 */
+	public static String normalName(String pathname) {
+		// upper-dir references are unwanted
+		if (pathname.indexOf("../") >= 0) {
+			return null;
+		}
+		int a = 0;
+		int e = pathname.length();
+		// leading and trailing "/" are removed
+		if (pathname.startsWith("/")) {
+			a++;
+		}
+		if (pathname.endsWith("/")) {
+			e--; 
+		}
+		return pathname.substring(a, e);
+	}
+	
+	
 	/**
 	 * FileFilter for image types (helper class for getFile)
 	 */
--- a/servlet/src/digilib/servlet/DigilibRequest.java	Mon Dec 08 16:50:59 2003 +0100
+++ b/servlet/src/digilib/servlet/DigilibRequest.java	Tue Dec 23 17:26:45 2003 +0100
@@ -26,7 +26,6 @@
 
 package digilib.servlet;
 
-import java.io.File;
 import java.io.StringReader;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -50,6 +49,7 @@
 import com.hp.hpl.mesa.rdf.jena.model.StmtIterator;
 
 import digilib.image.DocuImage;
+import digilib.io.FileOps;
 
 /** Class holding the parameters of a digilib user request.
  * The parameters are mostly named like the servlet parameters:<br>
@@ -466,18 +466,14 @@
 	/** The image file path to be accessed.
 	 * 
 	 * The mage file path is assembled from the servlets RequestPath and
-	 * Parameter fn. The file path never starts with a directory separator.
+	 * Parameter fn and normalized.
 	 * 
 	 * @return String the effective filepath.
 	 */
 	public String getFilePath() {
 		String s = getAsString("request.path");
 		s += getAsString("fn");
-		if (s.startsWith(File.separator)) {
-			return s.substring(1);
-		} else {
-			return s;
-		}
+		return FileOps.normalName(s);
 	}
 
 	/* Property getter and setter */
--- a/servlet/src/digilib/servlet/Scaler.java	Mon Dec 08 16:50:59 2003 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Tue Dec 23 17:26:45 2003 +0100
@@ -59,7 +59,7 @@
 public class Scaler extends HttpServlet {
 
 	// digilib servlet version (for all components)
-	public static final String dlVersion = "1.18b5";
+	public static final String dlVersion = "1.18b6";
 
 	// logger for accounting requests
 	Logger accountlog = Logger.getLogger("account.request");
@@ -765,7 +765,7 @@
 
 		} // end of "big" try
 		catch (IOException e) {
-			logger.fatal("ERROR: File IO Error: ", e);
+			logger.fatal("ERROR: File IO Error: "+e);
 			try {
 				if (errorMsgHtml) {
 					ServletOps.htmlMessage(
@@ -777,7 +777,7 @@
 			} catch (FileOpException ex) {
 			} // so we don't get a loop
 		} catch (AuthOpException e) {
-			logger.fatal("ERROR: Authorization error: ", e);
+			logger.fatal("ERROR: Authorization error: "+e);
 			try {
 				if (errorMsgHtml) {
 					ServletOps.htmlMessage(
@@ -789,7 +789,7 @@
 			} catch (FileOpException ex) {
 			} // so we don't get a loop
 		} catch (ImageOpException e) {
-			logger.fatal("ERROR: Image Error: ", e);
+			logger.fatal("ERROR: Image Error: "+e);
 			try {
 				if (errorMsgHtml) {
 					ServletOps.htmlMessage(
@@ -802,7 +802,7 @@
 			} // so we don't get a loop
 		} catch (RuntimeException e) {
 			// JAI likes to throw RuntimeExceptions ;-(
-			logger.fatal("ERROR: Other Image Error: ", e);
+			logger.fatal("ERROR: Other Image Error: "+e);
 			try {
 				if (errorMsgHtml) {
 					ServletOps.htmlMessage(