View Javadoc

1   //========================================================================
2   //Copyright 2006 Mort Bay Consulting Pty. Ltd.
3   //------------------------------------------------------------------------
4   //Licensed under the Apache License, Version 2.0 (the "License");
5   //you may not use this file except in compliance with the License.
6   //You may obtain a copy of the License at
7   //http://www.apache.org/licenses/LICENSE-2.0
8   //Unless required by applicable law or agreed to in writing, software
9   //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  {
27      public static boolean isEmpty(Buffer _buffer)
28      {
29          return _buffer.length()==0;
30      }
31  
32      public static int getInt(Buffer _buffer)
33      {
34          return ((_buffer.get()&0xFF)<<8)|(_buffer.get()&0xFF);
35      }
36  
37      public static Buffer getString(Buffer _buffer, View tok)
38      {
39          int len=((_buffer.peek()&0xFF)<<8)|(_buffer.peek(_buffer.getIndex()+1)&0xFF);
40          if (len==0xffff)
41          {
42              _buffer.skip(2);
43              return null;
44          }
45          int start=_buffer.getIndex();
46          tok.update(start+2,start+len+2);
47          _buffer.skip(len+3);
48          return tok;
49      }
50  
51      public static byte getByte(Buffer _buffer)
52      {
53          return _buffer.get();
54      }
55  
56      public static boolean getBool(Buffer _buffer)
57      {
58          return _buffer.get()>0;
59      }
60  
61      public static Buffer getMethod(Buffer _buffer)
62      {
63          return Ajp13PacketMethods.CACHE.get(_buffer.get());
64      }
65  
66      public static Buffer getHeaderName(Buffer _buffer, View tok)
67      {
68          int len=((_buffer.peek()&0xFF)<<8)|(_buffer.peek(_buffer.getIndex()+1)&0xFF);
69          if ((0xFF00&len)==0xA000)
70          {
71              _buffer.skip(1);
72              return Ajp13RequestHeaders.CACHE.get(_buffer.get());
73          }
74          int start=_buffer.getIndex();
75          tok.update(start+2,start+len+2);
76          _buffer.skip(len+3);
77          return tok;
78  
79      }
80  
81      public static Buffer get(Buffer buffer, int length)
82      {
83          return buffer.get(length);
84      }
85  
86  }