1 | | /* | | 1 | | /* |
2 | | * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpRequestLine.java,v 1.5 2001/07/22 20 :25: 07 pier Exp $ | | 2 | | * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/http/HttpRequestLine.java,v 1.6 2002/03/18 07:15:40 remm Exp $ |
3 | | * $Revision: 1.5 $ | | 3 | | * $Revision: 1.6 $ |
4 | | * $Date: 2001/07/22 20 :25: 07 $ | | 4 | | * $Date: 2002/03/18 07:15:40 $ |
5 | | * | | 5 | | * |
6 | | * ==================================================================== | | 6 | | * ==================================================================== |
7 | | * | | 7 | | * |
8 | | * The Apache Software License, Version 1.1 | | 8 | | * The Apache Software License, Version 1.1 |
9 | | * | | 9 | | * |
10 | | * Copyright (c) 1999 The Apache Software Foundation. All rights | | 10 | | * Copyright (c) 1999 The Apache Software Foundation. All rights |
11 | | * reserved. | | 11 | | * reserved. |
12 | | * | | 12 | | * |
13 | | * Redistribution and use in source and binary forms, with or without | | 13 | | * Redistribution and use in source and binary forms, with or without |
14 | | * modification, are permitted provided that the following conditions | | 14 | | * modification, are permitted provided that the following conditions |
15 | | * are met: | | 15 | | * are met: |
16 | | * | | 16 | | * |
17 | | * 1. Redistributions of source code must retain the above copyright | | 17 | | * 1. Redistributions of source code must retain the above copyright |
18 | | * notice, this list of conditions and the following disclaimer. | | 18 | | * notice, this list of conditions and the following disclaimer. |
19 | | * | | 19 | | * |
20 | | * 2. Redistributions in binary form must reproduce the above copyright | | 20 | | * 2. Redistributions in binary form must reproduce the above copyright |
21 | | * notice, this list of conditions and the following disclaimer in | | 21 | | * notice, this list of conditions and the following disclaimer in |
22 | | * the documentation and/or other materials provided with the | | 22 | | * the documentation and/or other materials provided with the |
23 | | * distribution. | | 23 | | * distribution. |
24 | | * | | 24 | | * |
25 | | * 3. The end-user documentation included with the redistribution, if | | 25 | | * 3. The end-user documentation included with the redistribution, if |
26 | | * any, must include the following acknowlegement: | | 26 | | * any, must include the following acknowlegement: |
27 | | * "This product includes software developed by the | | 27 | | * "This product includes software developed by the |
28 | | * Apache Software Foundation (http://www.apache.org/)." | | 28 | | * Apache Software Foundation (http://www.apache.org/)." |
29 | | * Alternately, this acknowlegement may appear in the software itself, | | 29 | | * Alternately, this acknowlegement may appear in the software itself, |
30 | | * if and wherever such third-party acknowlegements normally appear. | | 30 | | * if and wherever such third-party acknowlegements normally appear. |
31 | | * | | 31 | | * |
32 | | * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software | | 32 | | * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software |
33 | | * Foundation" must not be used to endorse or promote products derived | | 33 | | * Foundation" must not be used to endorse or promote products derived |
34 | | * from this software without prior written permission. For written | | 34 | | * from this software without prior written permission. For written |
35 | | * permission, please contact apache@apache.org. | | 35 | | * permission, please contact apache@apache.org. |
36 | | * | | 36 | | * |
37 | | * 5. Products derived from this software may not be called "Apache" | | 37 | | * 5. Products derived from this software may not be called "Apache" |
38 | | * nor may "Apache" appear in their names without prior written | | 38 | | * nor may "Apache" appear in their names without prior written |
39 | | * permission of the Apache Group. | | 39 | | * permission of the Apache Group. |
40 | | * | | 40 | | * |
41 | | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | | 41 | | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED |
42 | | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 42 | | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
43 | | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | 43 | | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
44 | | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | | 44 | | * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR |
45 | | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | | 45 | | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
46 | | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | | 46 | | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
47 | | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | | 47 | | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
48 | | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | | 48 | | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
49 | | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 49 | | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
50 | | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | | 50 | | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
51 | | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 51 | | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
52 | | * SUCH DAMAGE. | | 52 | | * SUCH DAMAGE. |
53 | | * ==================================================================== | | 53 | | * ==================================================================== |
54 | | * | | 54 | | * |
55 | | * This software consists of voluntary contributions made by many | | 55 | | * This software consists of voluntary contributions made by many |
56 | | * individuals on behalf of the Apache Software Foundation. For more | | 56 | | * individuals on behalf of the Apache Software Foundation. For more |
57 | | * information on the Apache Software Foundation, please see | | 57 | | * information on the Apache Software Foundation, please see |
58 | | * <http://www.apache.org/>. | | 58 | | * <http://www.apache.org/>. |
59 | | * | | 59 | | * |
60 | | * [Additional notices, if required by prior licensing conditions] | | 60 | | * [Additional notices, if required by prior licensing conditions] |
61 | | * | | 61 | | * |
62 | | */ | | 62 | | */ |
63 | | | | 63 | | |
64 | | | | 64 | | |
65 | | package org.apache.catalina.connector.http; | | 65 | | package org.apache.catalina.connector.http; |
66 | | | | 66 | | |
67 | | | | 67 | | |
68 | | import java.io.IOException; | | 68 | | import java.io.IOException; |
69 | | import java.net.InetAddress; | | 69 | | import java.net.InetAddress; |
70 | | import javax.servlet.ServletInputStream; | | 70 | | import javax.servlet.ServletInputStream; |
71 | | import org.apache.catalina.connector.HttpRequestBase; | | 71 | | import org.apache.catalina.connector.HttpRequestBase; |
72 | | | | 72 | | |
73 | | | | 73 | | |
74 | | /** | | 74 | | /** |
75 | | * HTTP request line enum type. | | 75 | | * HTTP request line enum type. |
76 | | * | | 76 | | * |
77 | | * @author Remy Maucherat | | 77 | | * @author Remy Maucherat |
78 | | * @version $Revision: 1.5 $ $Date: 2001/07/22 20 :25: 07 $ | | 78 | | * @version $Revision: 1.6 $ $Date: 2002/03/18 07:15:40 $ |
| | | | 79 | | * @deprecated |
79 | | */ | | 80 | | */ |
80 | | | | 81 | | |
81 | | final class HttpRequestLine { | | 82 | | final class HttpRequestLine { |
82 | | | | 83 | | |
83 | | | | 84 | | |
84 | | // -------------------------------------------------------------- Constants | | 85 | | // -------------------------------------------------------------- Constants |
85 | | | | 86 | | |
86 | | | | 87 | | |
87 | | public static final int INITIAL_METHOD_SIZE = 8; | | 88 | | public static final int INITIAL_METHOD_SIZE = 8; |
88 | | public static final int INITIAL_URI_SIZE = 64; | | 89 | | public static final int INITIAL_URI_SIZE = 64; |
89 | | public static final int INITIAL_PROTOCOL_SIZE = 8; | | 90 | | public static final int INITIAL_PROTOCOL_SIZE = 8; |
90 | | public static final int MAX_METHOD_SIZE = 1024; | | 91 | | public static final int MAX_METHOD_SIZE = 1024; |
91 | | public static final int MAX_URI_SIZE = 32768; | | 92 | | public static final int MAX_URI_SIZE = 32768; |
92 | | public static final int MAX_PROTOCOL_SIZE = 1024; | | 93 | | public static final int MAX_PROTOCOL_SIZE = 1024; |
93 | | | | 94 | | |
94 | | | | 95 | | |
95 | | // ----------------------------------------------------------- Constructors | | 96 | | // ----------------------------------------------------------- Constructors |
96 | | | | 97 | | |
97 | | | | 98 | | |
98 | | public HttpRequestLine() { | | 99 | | public HttpRequestLine() { |
99 | | | | 100 | | |
100 | | this(new char[INITIAL_METHOD_SIZE], 0, new char[INITIAL_URI_SIZE], 0, | | 101 | | this(new char[INITIAL_METHOD_SIZE], 0, new char[INITIAL_URI_SIZE], 0, |
101 | | new char[INITIAL_PROTOCOL_SIZE], 0); | | 102 | | new char[INITIAL_PROTOCOL_SIZE], 0); |
102 | | | | 103 | | |
103 | | } | | 104 | | } |
104 | | | | 105 | | |
105 | | | | 106 | | |
106 | | public HttpRequestLine(char[] method, int methodEnd, | | 107 | | public HttpRequestLine(char[] method, int methodEnd, |
107 | | char[] uri, int uriEnd, | | 108 | | char[] uri, int uriEnd, |
108 | | char[] protocol, int protocolEnd) { | | 109 | | char[] protocol, int protocolEnd) { |
109 | | | | 110 | | |
110 | | this.method = method; | | 111 | | this.method = method; |
111 | | this.methodEnd = methodEnd; | | 112 | | this.methodEnd = methodEnd; |
112 | | this.uri = uri; | | 113 | | this.uri = uri; |
113 | | this.uriEnd = uriEnd; | | 114 | | this.uriEnd = uriEnd; |
114 | | this.protocol = protocol; | | 115 | | this.protocol = protocol; |
115 | | this.protocolEnd = protocolEnd; | | 116 | | this.protocolEnd = protocolEnd; |
116 | | | | 117 | | |
117 | | } | | 118 | | } |
118 | | | | 119 | | |
119 | | | | 120 | | |
120 | | // ----------------------------------------------------- Instance Variables | | 121 | | // ----------------------------------------------------- Instance Variables |
121 | | | | 122 | | |
122 | | | | 123 | | |
123 | | public char[] method; | | 124 | | public char[] method; |
124 | | public int methodEnd; | | 125 | | public int methodEnd; |
125 | | public char[] uri; | | 126 | | public char[] uri; |
126 | | public int uriEnd; | | 127 | | public int uriEnd; |
127 | | public char[] protocol; | | 128 | | public char[] protocol; |
128 | | public int protocolEnd; | | 129 | | public int protocolEnd; |
129 | | | | 130 | | |
130 | | | | 131 | | |
131 | | // ------------------------------------------------------------- Properties | | 132 | | // ------------------------------------------------------------- Properties |
132 | | | | 133 | | |
133 | | | | 134 | | |
134 | | // --------------------------------------------------------- Public Methods | | 135 | | // --------------------------------------------------------- Public Methods |
135 | | | | 136 | | |
136 | | | | 137 | | |
137 | | /** | | 138 | | /** |
138 | | * Release all object references, and initialize instance variables, in | | 139 | | * Release all object references, and initialize instance variables, in |
139 | | * preparation for reuse of this object. | | 140 | | * preparation for reuse of this object. |
140 | | */ | | 141 | | */ |
141 | | public void recycle() { | | 142 | | public void recycle() { |
142 | | | | 143 | | |
143 | | methodEnd = 0; | | 144 | | methodEnd = 0; |
144 | | uriEnd = 0; | | 145 | | uriEnd = 0; |
145 | | protocolEnd = 0; | | 146 | | protocolEnd = 0; |
146 | | | | 147 | | |
147 | | } | | 148 | | } |
148 | | | | 149 | | |
149 | | | | 150 | | |
150 | | /** | | 151 | | /** |
151 | | * Test if the uri includes the given char array. | | 152 | | * Test if the uri includes the given char array. |
152 | | */ | | 153 | | */ |
153 | | public int indexOf(char[] buf) { | | 154 | | public int indexOf(char[] buf) { |
154 | | return indexOf(buf, buf.length); | | 155 | | return indexOf(buf, buf.length); |
155 | | } | | 156 | | } |
156 | | | | 157 | | |
157 | | | | 158 | | |
158 | | /** | | 159 | | /** |
159 | | * Test if the value of the header includes the given char array. | | 160 | | * Test if the value of the header includes the given char array. |
160 | | */ | | 161 | | */ |
161 | | public int indexOf(char[] buf, int end) { | | 162 | | public int indexOf(char[] buf, int end) { |
162 | | char firstChar = buf[0]; | | 163 | | char firstChar = buf[0]; |
163 | | int pos = 0; | | 164 | | int pos = 0; |
164 | | while (pos < uriEnd) { | | 165 | | while (pos < uriEnd) { |
165 | | pos = indexOf(firstChar, pos); | | 166 | | pos = indexOf(firstChar, pos); |
166 | | if (pos == -1) | | 167 | | if (pos == -1) |
167 | | return -1; | | 168 | | return -1; |
168 | | if ((uriEnd - pos) < end) | | 169 | | if ((uriEnd - pos) < end) |
169 | | return -1; | | 170 | | return -1; |
170 | | for (int i = 0; i < end; i++) { | | 171 | | for (int i = 0; i < end; i++) { |
171 | | if (uri[i + pos] != buf[i]) | | 172 | | if (uri[i + pos] != buf[i]) |
172 | | break; | | 173 | | break; |
173 | | if (i == (end-1)) | | 174 | | if (i == (end-1)) |
174 | | return pos; | | 175 | | return pos; |
175 | | } | | 176 | | } |
176 | | pos++; | | 177 | | pos++; |
177 | | } | | 178 | | } |
178 | | return -1; | | 179 | | return -1; |
179 | | } | | 180 | | } |
180 | | | | 181 | | |
181 | | | | 182 | | |
182 | | /** | | 183 | | /** |
183 | | * Test if the value of the header includes the given string. | | 184 | | * Test if the value of the header includes the given string. |
184 | | */ | | 185 | | */ |
185 | | public int indexOf(String str) { | | 186 | | public int indexOf(String str) { |
186 | | return indexOf(str.toCharArray(), str.length()); | | 187 | | return indexOf(str.toCharArray(), str.length()); |
187 | | } | | 188 | | } |
188 | | | | 189 | | |
189 | | | | 190 | | |
190 | | /** | | 191 | | /** |
191 | | * Returns the index of a character in the value. | | 192 | | * Returns the index of a character in the value. |
192 | | */ | | 193 | | */ |
193 | | public int indexOf(char c, int start) { | | 194 | | public int indexOf(char c, int start) { |
194 | | for (int i=start; i<uriEnd; i++) { | | 195 | | for (int i=start; i<uriEnd; i++) { |
195 | | if (uri[i] == c) | | 196 | | if (uri[i] == c) |
196 | | return i; | | 197 | | return i; |
197 | | } | | 198 | | } |
198 | | return -1; | | 199 | | return -1; |
199 | | } | | 200 | | } |
200 | | | | 201 | | |
201 | | | | 202 | | |
202 | | // --------------------------------------------------------- Object Methods | | 203 | | // --------------------------------------------------------- Object Methods |
203 | | | | 204 | | |
204 | | | | 205 | | |
205 | | public int hashCode() { | | 206 | | public int hashCode() { |
206 | | // FIXME | | 207 | | // FIXME |
207 | | return 0; | | 208 | | return 0; |
208 | | } | | 209 | | } |
209 | | | | 210 | | |
210 | | | | 211 | | |
211 | | public boolean equals(Object obj) { | | 212 | | public boolean equals(Object obj) { |
212 | | return false; | | 213 | | return false; |
213 | | } | | 214 | | } |
214 | | | | 215 | | |
215 | | | | 216 | | |
216 | | } | | 217 | | } |