View Javadoc

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