649 int embeddedDotInDomain = domain.indexOf('.');
650 if (embeddedDotInDomain == 0)
651 embeddedDotInDomain = domain.indexOf('.', 1);
652 if (!isLocalDomain
653 && (embeddedDotInDomain == -1 ||
654 embeddedDotInDomain == domain.length() - 1))
655 return false;
656
657 // if the host name contains no dot and the domain name
658 // is .local or host.local
659 int firstDotInHost = host.indexOf('.');
660 if (firstDotInHost == -1 &&
661 (isLocalDomain ||
662 domain.equalsIgnoreCase(host + ".local"))) {
663 return true;
664 }
665
666 int domainLength = domain.length();
667 int lengthDiff = host.length() - domainLength;
668 if (lengthDiff == 0) {
669 // if the host name and the domain name are just string-compare euqal
670 return host.equalsIgnoreCase(domain);
671 }
672 else if (lengthDiff > 0) {
673 // need to check H & D component
674 String H = host.substring(0, lengthDiff);
675 String D = host.substring(lengthDiff);
676
677 return (H.indexOf('.') == -1 && D.equalsIgnoreCase(domain));
678 }
679 else if (lengthDiff == -1) {
680 // if domain is actually .host
681 return (domain.charAt(0) == '.' &&
682 host.equalsIgnoreCase(domain.substring(1)));
683 }
684
685 return false;
686 }
687
688 /**
689 * Constructs a cookie header string representation of this cookie,
1114 return s.equalsIgnoreCase(t);
1115 }
1116 return false;
1117 }
1118
1119 private static boolean startsWithIgnoreCase(String s, String start) {
1120 if (s == null || start == null) return false;
1121
1122 if (s.length() >= start.length() &&
1123 start.equalsIgnoreCase(s.substring(0, start.length()))) {
1124 return true;
1125 }
1126
1127 return false;
1128 }
1129
1130 /*
1131 * Split cookie header string according to rfc 2965:
1132 * 1) split where it is a comma;
1133 * 2) but not the comma surrounding by double-quotes, which is the comma
1134 * inside port list or embeded URIs.
1135 *
1136 * @param header
1137 * the cookie header string to split
1138 *
1139 * @return list of strings; never null
1140 */
1141 private static List<String> splitMultiCookies(String header) {
1142 List<String> cookies = new java.util.ArrayList<>();
1143 int quoteCount = 0;
1144 int p, q;
1145
1146 for (p = 0, q = 0; p < header.length(); p++) {
1147 char c = header.charAt(p);
1148 if (c == '"') quoteCount++;
1149 if (c == ',' && (quoteCount % 2 == 0)) {
1150 // it is comma and not surrounding by double-quotes
1151 cookies.add(header.substring(q, p));
1152 q = p + 1;
1153 }
1154 }
|
649 int embeddedDotInDomain = domain.indexOf('.');
650 if (embeddedDotInDomain == 0)
651 embeddedDotInDomain = domain.indexOf('.', 1);
652 if (!isLocalDomain
653 && (embeddedDotInDomain == -1 ||
654 embeddedDotInDomain == domain.length() - 1))
655 return false;
656
657 // if the host name contains no dot and the domain name
658 // is .local or host.local
659 int firstDotInHost = host.indexOf('.');
660 if (firstDotInHost == -1 &&
661 (isLocalDomain ||
662 domain.equalsIgnoreCase(host + ".local"))) {
663 return true;
664 }
665
666 int domainLength = domain.length();
667 int lengthDiff = host.length() - domainLength;
668 if (lengthDiff == 0) {
669 // if the host name and the domain name are just string-compare equal
670 return host.equalsIgnoreCase(domain);
671 }
672 else if (lengthDiff > 0) {
673 // need to check H & D component
674 String H = host.substring(0, lengthDiff);
675 String D = host.substring(lengthDiff);
676
677 return (H.indexOf('.') == -1 && D.equalsIgnoreCase(domain));
678 }
679 else if (lengthDiff == -1) {
680 // if domain is actually .host
681 return (domain.charAt(0) == '.' &&
682 host.equalsIgnoreCase(domain.substring(1)));
683 }
684
685 return false;
686 }
687
688 /**
689 * Constructs a cookie header string representation of this cookie,
1114 return s.equalsIgnoreCase(t);
1115 }
1116 return false;
1117 }
1118
1119 private static boolean startsWithIgnoreCase(String s, String start) {
1120 if (s == null || start == null) return false;
1121
1122 if (s.length() >= start.length() &&
1123 start.equalsIgnoreCase(s.substring(0, start.length()))) {
1124 return true;
1125 }
1126
1127 return false;
1128 }
1129
1130 /*
1131 * Split cookie header string according to rfc 2965:
1132 * 1) split where it is a comma;
1133 * 2) but not the comma surrounding by double-quotes, which is the comma
1134 * inside port list or embedded URIs.
1135 *
1136 * @param header
1137 * the cookie header string to split
1138 *
1139 * @return list of strings; never null
1140 */
1141 private static List<String> splitMultiCookies(String header) {
1142 List<String> cookies = new java.util.ArrayList<>();
1143 int quoteCount = 0;
1144 int p, q;
1145
1146 for (p = 0, q = 0; p < header.length(); p++) {
1147 char c = header.charAt(p);
1148 if (c == '"') quoteCount++;
1149 if (c == ',' && (quoteCount % 2 == 0)) {
1150 // it is comma and not surrounding by double-quotes
1151 cookies.add(header.substring(q, p));
1152 q = p + 1;
1153 }
1154 }
|