1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.jboss.netty.handler.codec.http;
17  
18  import java.util.BitSet;
19  
20  
21  
22  
23  @Deprecated
24  final class CookieUtil {
25  
26      private static final BitSet VALID_COOKIE_VALUE_OCTETS = validCookieValueOctets();
27  
28      private static final BitSet VALID_COOKIE_NAME_OCTETS = validCookieNameOctets(VALID_COOKIE_VALUE_OCTETS);
29  
30      
31      private static BitSet validCookieValueOctets() {
32          BitSet bits = new BitSet(8);
33          for (int i = 35; i < 127; i++) {
34              
35              bits.set(i);
36          }
37          bits.set('"', false);  
38          bits.set(',', false);  
39          bits.set(';', false);  
40          bits.set('\\', false); 
41          return bits;
42      }
43  
44      
45      
46      
47      
48      
49      private static BitSet validCookieNameOctets(BitSet validCookieValueOctets) {
50          BitSet bits = new BitSet(8);
51          bits.or(validCookieValueOctets);
52          bits.set('(', false);
53          bits.set(')', false);
54          bits.set('<', false);
55          bits.set('>', false);
56          bits.set('@', false);
57          bits.set(':', false);
58          bits.set('/', false);
59          bits.set('[', false);
60          bits.set(']', false);
61          bits.set('?', false);
62          bits.set('=', false);
63          bits.set('{', false);
64          bits.set('}', false);
65          bits.set(' ', false);
66          bits.set('\t', false);
67          return bits;
68      }
69  
70      static int firstInvalidCookieNameOctet(CharSequence cs) {
71          return firstInvalidOctet(cs, VALID_COOKIE_NAME_OCTETS);
72      }
73  
74      static int firstInvalidCookieValueOctet(CharSequence cs) {
75          return firstInvalidOctet(cs, VALID_COOKIE_VALUE_OCTETS);
76      }
77  
78      static int firstInvalidOctet(CharSequence cs, BitSet bits) {
79          for (int i = 0; i < cs.length(); i++) {
80              char c = cs.charAt(i);
81              if (!bits.get(c)) {
82                  return i;
83              }
84          }
85          return -1;
86      }
87  
88      static CharSequence unwrapValue(CharSequence cs) {
89          final int len = cs.length();
90          if (len > 0 && cs.charAt(0) == '"') {
91              if (len >= 2 && cs.charAt(len - 1) == '"') {
92                  
93                  return len == 2 ? "" : cs.subSequence(1, len - 1);
94              } else {
95                  return null;
96              }
97          }
98          return cs;
99      }
100 
101     private CookieUtil() {
102         
103     }
104 }