01: //========================================================================
02: //Copyright 2006 Mort Bay Consulting Pty. Ltd.
03: //------------------------------------------------------------------------
04: //Licensed under the Apache License, Version 2.0 (the "License");
05: //you may not use this file except in compliance with the License.
06: //You may obtain a copy of the License at
07: //http://www.apache.org/licenses/LICENSE-2.0
08: //Unless required by applicable law or agreed to in writing, software
09: //distributed under the License is distributed on an "AS IS" BASIS,
10: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11: //See the License for the specific language governing permissions and
12: //limitations under the License.
13: //========================================================================
14:
15: package org.mortbay.jetty.ajp;
16:
17: import org.mortbay.io.Buffer;
18: import org.mortbay.io.View;
19:
20: /**
21: * @author Markus Kobler
22: * @author Greg Wilkins
23: * @author Jason Jenkins <jj@aol.net>
24: */
25: public class Ajp13RequestPacket {
26: public static boolean isEmpty(Buffer _buffer) {
27: return _buffer.length() == 0;
28: }
29:
30: public static int getInt(Buffer _buffer) {
31: return ((_buffer.get() & 0xFF) << 8) | (_buffer.get() & 0xFF);
32: }
33:
34: public static Buffer getString(Buffer _buffer, View tok) {
35: int len = ((_buffer.peek() & 0xFF) << 8)
36: | (_buffer.peek(_buffer.getIndex() + 1) & 0xFF);
37: if (len == 0xffff) {
38: _buffer.skip(2);
39: return null;
40: }
41: int start = _buffer.getIndex();
42: tok.update(start + 2, start + len + 2);
43: _buffer.skip(len + 3);
44: return tok;
45: }
46:
47: public static byte getByte(Buffer _buffer) {
48: return _buffer.get();
49: }
50:
51: public static boolean getBool(Buffer _buffer) {
52: return _buffer.get() > 0;
53: }
54:
55: public static Buffer getMethod(Buffer _buffer) {
56: return Ajp13PacketMethods.CACHE.get(_buffer.get());
57: }
58:
59: public static Buffer getHeaderName(Buffer _buffer, View tok) {
60: int len = ((_buffer.peek() & 0xFF) << 8)
61: | (_buffer.peek(_buffer.getIndex() + 1) & 0xFF);
62: if ((0xFF00 & len) == 0xA000) {
63: _buffer.skip(1);
64: return Ajp13RequestHeaders.CACHE.get(_buffer.get());
65: }
66: int start = _buffer.getIndex();
67: tok.update(start + 2, start + len + 2);
68: _buffer.skip(len + 3);
69: return tok;
70:
71: }
72:
73: public static Buffer get(Buffer buffer, int length) {
74: return buffer.get(length);
75: }
76:
77: }
|