View Javadoc

1   // ========================================================================
2   // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.ajp;
15  
16  import org.eclipse.jetty.io.Buffer;
17  import org.eclipse.jetty.io.View;
18  
19  /**
20   * 
21   * 
22   * 
23   */
24  public class Ajp13RequestPacket
25  {
26      public static boolean isEmpty(Buffer _buffer)
27      {
28          return _buffer.length()==0;
29      }
30  
31      public static int getInt(Buffer _buffer)
32      {
33          return ((_buffer.get()&0xFF)<<8)|(_buffer.get()&0xFF);
34      }
35  
36      public static Buffer getString(Buffer _buffer, View tok)
37      {
38          int len=((_buffer.peek()&0xFF)<<8)|(_buffer.peek(_buffer.getIndex()+1)&0xFF);
39          if (len==0xffff)
40          {
41              _buffer.skip(2);
42              return null;
43          }
44          int start=_buffer.getIndex();
45          tok.update(start+2,start+len+2);
46          _buffer.skip(len+3);
47          return tok;
48      }
49  
50      public static byte getByte(Buffer _buffer)
51      {
52          return _buffer.get();
53      }
54  
55      public static boolean getBool(Buffer _buffer)
56      {
57          return _buffer.get()>0;
58      }
59  
60      public static Buffer getMethod(Buffer _buffer)
61      {
62          return Ajp13PacketMethods.CACHE.get(_buffer.get());
63      }
64  
65      public static Buffer getHeaderName(Buffer _buffer, View tok)
66      {
67          int len=((_buffer.peek()&0xFF)<<8)|(_buffer.peek(_buffer.getIndex()+1)&0xFF);
68          if ((0xFF00&len)==0xA000)
69          {
70              _buffer.skip(1);
71              return Ajp13RequestHeaders.CACHE.get(_buffer.get());
72          }
73          int start=_buffer.getIndex();
74          tok.update(start+2,start+len+2);
75          _buffer.skip(len+3);
76          return tok;
77  
78      }
79  
80      public static Buffer get(Buffer buffer, int length)
81      {
82          return buffer.get(length);
83      }
84  
85  }