-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDNSQuestionParserDecorator.java
More file actions
143 lines (126 loc) · 3.55 KB
/
DNSQuestionParserDecorator.java
File metadata and controls
143 lines (126 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
* A decorator for DNSQuestion that parses a byte buffer to create a
* DNSQuestion.
*
* @author Chris Blades
* @version 20/3/10
*/
public class DNSQuestionParserDecorator implements DNSQuestion {
/** The DNSQuestion object this object wraps */
private DNSQuestion question;
/** byte buffer to parse and pass to other objects */
private IndexedArrayList<Byte> bytes;
/**
* Creates a new DNSQuestionParserDecorator with the given byte
* buffer.
*
* @param bytes the byte buffer to parse.
*/
public DNSQuestionParserDecorator(IndexedArrayList<Byte> bytes) {
this.bytes = bytes;
this.question = new DNSQuestionImpl();
}
/**
* Parses the byte buffer to form a DNSQuestion object.
*
*/
public void parse() {
//
// parse question name
//
DNSUrlParserDecorator url = new DNSUrlParserDecorator(bytes);
url.parse();
question.setName(url);
//
// parse question type
//
DNSRecordTypeParserDecorator type =
new DNSRecordTypeParserDecorator(bytes);
type.parse();
question.setType(type);
//
// parse question class
//
DNSRecordClassParserDecorator clss =
new DNSRecordClassParserDecorator(bytes);
clss.parse();
question.setClass(clss);
}
//
// DNSQuestion
//
/**
* Returns the name of the parsed DNSQuestion object.
*
* @return the name of the parsed DNSQuestion object.
*/
public DNSUrl getName() {
return question.getName();
}
/**
* Returns the type of the parsed DNSQuestion object.
*
* @return the type of the parsed DNSQuestion object.
*/
public DNSRecordType getType() {
return question.getType();
}
/**
* Returns the class of the parsed DNSQuestion object.
*
* @return the class of the parsed DNSQuestion object.
*/
public DNSRecordClass getRecordClass() {
return question.getRecordClass();
}
/**
* Sets the name of the parsed DNSQuestion object.
*
* @param name the new name of the parsed DNSQuestion object.
*/
public void setName(DNSUrl name) {
question.setName(name);
}
/**
* Sets the type of the parsed DNSQuestion object.
*
* @param type the new type of the parsed DNSQuestion object.
*/
public void setType(DNSRecordType type) {
question.setType(type);
}
/**
* Sets the DNS class of the parsed DNSQuestion object.
*
* @param recordClass the new class of the parsed DNSQuestion object.
*/
public void setClass(DNSRecordClass recordClass) {
question.setClass(recordClass);
}
/**
* Returns the length of the parsed DNSQuestion object.
*
* @return the length of the parsed DNSQuestion object.
*/
public int getLength() {
return question.getLength();
}
/**
* returns the serialized version of the parsed dnsquestion object.
* can't just return the byte buffer because we don't know what else is in
* it.
*
* @return the serialized version of the parsed dnsquestion object.
*/
public byte[] serialize() {
return question.serialize();
}
/**
* Returns a mapping of the state values of the parsed DNSQuestion object.
*
* @return the state values of the parsed DNSQuestion object.
*/
public Map stateValues() {
return question.stateValues();
}
}