Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@www.apache.org Received: (qmail 58168 invoked from network); 19 Jun 2004 04:25:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 19 Jun 2004 04:25:30 -0000 Received: (qmail 82648 invoked by uid 500); 19 Jun 2004 04:25:41 -0000 Delivered-To: apmail-jakarta-tomcat-dev-archive@jakarta.apache.org Received: (qmail 82609 invoked by uid 500); 19 Jun 2004 04:25:41 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 82594 invoked by uid 500); 19 Jun 2004 04:25:41 -0000 Received: (qmail 82591 invoked by uid 99); 19 Jun 2004 04:25:40 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Fri, 18 Jun 2004 21:25:40 -0700 Received: (qmail 58068 invoked by uid 1385); 19 Jun 2004 04:25:14 -0000 Date: 19 Jun 2004 04:25:14 -0000 Message-ID: <20040619042514.58067.qmail@minotaur.apache.org> From: billbarker@apache.org To: jakarta-tomcat-connectors-cvs@apache.org Subject: cvs commit: jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper Mapper.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N billbarker 2004/06/18 21:25:14 Modified: util/java/org/apache/tomcat/util/http/mapper Mapper.java Log: Change to do case-insensitive mapping of the Host. Host names (like all DNS names) are not case-sensitive, so ignore case when mapping. Fix for Bug #29661 Reported By: Fran��ois Jeanmougin francois.jeanmougin@123multimedia.com Revision Changes Path 1.39 +88 -2 jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java Index: Mapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/http/mapper/Mapper.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- Mapper.java 28 May 2004 05:02:08 -0000 1.38 +++ Mapper.java 19 Jun 2004 04:25:14 -0000 1.39 @@ -21,6 +21,7 @@ import org.apache.tomcat.util.buf.CharChunk; import org.apache.tomcat.util.buf.MessageBytes; +import org.apache.tomcat.util.buf.Ascii; import java.util.List; import java.util.ArrayList; @@ -551,8 +552,8 @@ // Virtual host mapping if (mappingData.host == null) { Host[] hosts = this.hosts; - int pos = find(hosts, host); - if ((pos != -1) && (host.equals(hosts[pos].name))) { + int pos = findIgnoreCase(hosts, host); + if ((pos != -1) && (host.equalsIgnoreCase(hosts[pos].name))) { mappingData.host = hosts[pos].object; contexts = hosts[pos].contextList.contexts; nesting = hosts[pos].contextList.nesting; @@ -961,6 +962,61 @@ } + /** + * Find a map elemnt given its name in a sorted array of map elements. + * This will return the index for the closest inferior or equal item in the + * given array. + */ + private static final int findIgnoreCase(MapElement[] map, CharChunk name) { + return findIgnoreCase(map, name, name.getStart(), name.getEnd()); + } + + + /** + * Find a map elemnt given its name in a sorted array of map elements. + * This will return the index for the closest inferior or equal item in the + * given array. + */ + private static final int findIgnoreCase(MapElement[] map, CharChunk name, + int start, int end) { + + int a = 0; + int b = map.length - 1; + + // Special cases: -1 and 0 + if (b == -1) { + return -1; + } + if (compareIgnoreCase(name, start, end, map[0].name) < 0 ) { + return -1; + } + if (b == 0) { + return 0; + } + + int i = 0; + while (true) { + i = (b + a) / 2; + int result = compareIgnoreCase(name, start, end, map[i].name); + if (result == 1) { + a = i; + } else if (result == 0) { + return i; + } else { + b = i; + } + if ((b - a) == 1) { + int result2 = compareIgnoreCase(name, start, end, map[b].name); + if (result2 < 0) { + return a; + } else { + return b; + } + } + } + + } + /** * Find a map elemnt given its name in a sorted array of map elements. @@ -1024,6 +1080,36 @@ if (c[i + start] > compareTo.charAt(i)) { result = 1; } else if (c[i + start] < compareTo.charAt(i)) { + result = -1; + } + } + if (result == 0) { + if (compareTo.length() > (end - start)) { + result = -1; + } else if (compareTo.length() < (end - start)) { + result = 1; + } + } + return result; + } + + + /** + * Compare given char chunk with String ignoring case. + * Return -1, 0 or +1 if inferior, equal, or superior to the String. + */ + private static final int compareIgnoreCase(CharChunk name, int start, int end, + String compareTo) { + int result = 0; + char[] c = name.getBuffer(); + int len = compareTo.length(); + if ((end - start) < len) { + len = end - start; + } + for (int i = 0; (i < len) && (result == 0); i++) { + if (Ascii.toLower(c[i + start]) > Ascii.toLower(compareTo.charAt(i))) { + result = 1; + } else if (Ascii.toLower(c[i + start]) < Ascii.toLower(compareTo.charAt(i))) { result = -1; } } --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org