1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.protocol.localhandler.packet;
22
23 import openr66.protocol.exception.OpenR66ProtocolPacketException;
24
25 import org.jboss.netty.buffer.ChannelBuffer;
26 import org.jboss.netty.buffer.ChannelBuffers;
27
28
29
30
31
32
33
34
35 public class InformationPacket extends AbstractLocalPacket {
36
37 public static enum ASKENUM {
38 ASKEXIST, ASKMLSDETAIL, ASKLIST, ASKMLSLIST;
39 }
40
41 private final String rulename;
42
43 private final byte requestedInfo;
44
45 private final String filename;
46
47
48
49
50
51
52
53
54
55 public static InformationPacket createFromBuffer(int headerLength,
56 int middleLength, int endLength, ChannelBuffer buf)
57 throws OpenR66ProtocolPacketException {
58 if (headerLength - 1 <= 0) {
59 throw new OpenR66ProtocolPacketException("Not enough data");
60 }
61 if (middleLength != 1) {
62 throw new OpenR66ProtocolPacketException("Not enough data");
63 }
64 final byte[] bheader = new byte[headerLength - 1];
65 final byte[] bend = new byte[endLength];
66 if (headerLength - 1 > 0) {
67 buf.readBytes(bheader);
68 }
69 byte request = buf.readByte();
70 if (endLength > 0) {
71 buf.readBytes(bend);
72 }
73 final String sheader = new String(bheader);
74 final String send = new String(bend);
75 return new InformationPacket(sheader, request, send);
76 }
77
78
79
80
81
82
83 public InformationPacket(String rulename, byte request, String filename) {
84 this.rulename = rulename;
85 this.requestedInfo = request;
86 this.filename = filename;
87 }
88
89
90
91
92
93
94 @Override
95 public void createEnd() {
96 if (filename != null) {
97 end = ChannelBuffers.wrappedBuffer(filename.getBytes());
98 }
99 }
100
101
102
103
104
105
106
107 @Override
108 public void createHeader() throws OpenR66ProtocolPacketException {
109 if (rulename == null) {
110 throw new OpenR66ProtocolPacketException("Not enough data");
111 }
112 header = ChannelBuffers.wrappedBuffer(rulename.getBytes());
113 }
114
115
116
117
118
119
120
121 @Override
122 public void createMiddle() {
123 byte[] newbytes = {
124 requestedInfo };
125 middle = ChannelBuffers.wrappedBuffer(newbytes);
126 }
127
128 @Override
129 public byte getType() {
130 return LocalPacketFactory.INFORMATIONPACKET;
131 }
132
133
134
135
136
137
138 @Override
139 public String toString() {
140 return "InformationPacket: " + requestedInfo + " " + rulename+" "+filename;
141 }
142
143
144
145
146 public byte getRequest() {
147 return requestedInfo;
148 }
149
150
151
152
153 public String getRulename() {
154 return rulename;
155 }
156
157
158
159
160 public String getFilename() {
161 if (filename != null) {
162 return filename;
163 } else {
164 return "";
165 }
166 }
167 }