1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
package javax.jmdns.impl; |
6 |
|
|
7 |
|
import java.net.InetAddress; |
8 |
|
import java.util.Set; |
9 |
|
import java.util.logging.Level; |
10 |
|
import java.util.logging.Logger; |
11 |
|
|
12 |
|
import javax.jmdns.ServiceInfo; |
13 |
|
import javax.jmdns.ServiceInfo.Fields; |
14 |
|
import javax.jmdns.impl.JmDNSImpl.ServiceTypeEntry; |
15 |
|
import javax.jmdns.impl.constants.DNSConstants; |
16 |
|
import javax.jmdns.impl.constants.DNSRecordClass; |
17 |
|
import javax.jmdns.impl.constants.DNSRecordType; |
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
@author |
23 |
|
|
|
|
| 48.9% |
Uncovered Elements: 23 (45) |
Complexity: 22 |
Complexity Density: 0.73 |
|
24 |
|
public class DNSQuestion extends DNSEntry { |
25 |
|
private static Logger logger = Logger.getLogger(DNSQuestion.class.getName()); |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.67 |
|
30 |
|
private static class DNS4Address extends DNSQuestion { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
31 |
0
|
DNS4Address(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
32 |
0
|
super(name, type, recordClass, unique); |
33 |
|
} |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
35 |
0
|
@Override... |
36 |
|
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) { |
37 |
0
|
DNSRecord answer = jmDNSImpl.getLocalHost().getDNSAddressRecord(this.getRecordType(), DNSRecordClass.UNIQUE, DNSConstants.DNS_TTL); |
38 |
0
|
if (answer != null) { |
39 |
0
|
answers.add(answer); |
40 |
|
} |
41 |
|
} |
42 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
43 |
0
|
@Override... |
44 |
|
public boolean iAmTheOnlyOne(JmDNSImpl jmDNSImpl) { |
45 |
0
|
String name = this.getName().toLowerCase(); |
46 |
0
|
return jmDNSImpl.getLocalHost().getName().equals(name) || jmDNSImpl.getServices().keySet().contains(name); |
47 |
|
} |
48 |
|
|
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.67 |
|
54 |
|
private static class DNS6Address extends DNSQuestion { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0
|
DNS6Address(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
56 |
0
|
super(name, type, recordClass, unique); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
59 |
0
|
@Override... |
60 |
|
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) { |
61 |
0
|
DNSRecord answer = jmDNSImpl.getLocalHost().getDNSAddressRecord(this.getRecordType(), DNSRecordClass.UNIQUE, DNSConstants.DNS_TTL); |
62 |
0
|
if (answer != null) { |
63 |
0
|
answers.add(answer); |
64 |
|
} |
65 |
|
} |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
67 |
0
|
@Override... |
68 |
|
public boolean iAmTheOnlyOne(JmDNSImpl jmDNSImpl) { |
69 |
0
|
String name = this.getName().toLowerCase(); |
70 |
0
|
return jmDNSImpl.getLocalHost().getName().equals(name) || jmDNSImpl.getServices().keySet().contains(name); |
71 |
|
} |
72 |
|
|
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
|
private static class HostInformation extends DNSQuestion { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
0
|
HostInformation(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
80 |
0
|
super(name, type, recordClass, unique); |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
|
|
| 30.6% |
Uncovered Elements: 25 (36) |
Complexity: 11 |
Complexity Density: 0.61 |
|
87 |
|
private static class Pointer extends DNSQuestion { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
207
|
Pointer(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
89 |
205
|
super(name, type, recordClass, unique); |
90 |
|
} |
91 |
|
|
|
|
| 24.2% |
Uncovered Elements: 25 (33) |
Complexity: 10 |
Complexity Density: 0.59 |
|
92 |
45
|
@Override... |
93 |
|
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) { |
94 |
|
|
95 |
45
|
for (ServiceInfo serviceInfo : jmDNSImpl.getServices().values()) { |
96 |
30
|
this.addAnswersForServiceInfo(jmDNSImpl, answers, (ServiceInfoImpl) serviceInfo); |
97 |
|
} |
98 |
45
|
if (this.isServicesDiscoveryMetaQuery()) { |
99 |
0
|
for (String serviceType : jmDNSImpl.getServiceTypes().keySet()) { |
100 |
0
|
ServiceTypeEntry typeEntry = jmDNSImpl.getServiceTypes().get(serviceType); |
101 |
0
|
answers.add(new DNSRecord.Pointer("_services._dns-sd._udp.local.", DNSRecordClass.CLASS_IN, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL, typeEntry.getType())); |
102 |
|
} |
103 |
45
|
} else if (this.isReverseLookup()) { |
104 |
0
|
String ipValue = this.getQualifiedNameMap().get(Fields.Instance); |
105 |
0
|
if ((ipValue != null) && (ipValue.length() > 0)) { |
106 |
0
|
InetAddress address = jmDNSImpl.getLocalHost().getInetAddress(); |
107 |
0
|
String hostIPAddress = (address != null ? address.getHostAddress() : ""); |
108 |
0
|
if (ipValue.equalsIgnoreCase(hostIPAddress)) { |
109 |
0
|
if (this.isV4ReverseLookup()) { |
110 |
0
|
answers.add(jmDNSImpl.getLocalHost().getDNSReverseAddressRecord(DNSRecordType.TYPE_A, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL)); |
111 |
|
} |
112 |
0
|
if (this.isV6ReverseLookup()) { |
113 |
0
|
answers.add(jmDNSImpl.getLocalHost().getDNSReverseAddressRecord(DNSRecordType.TYPE_AAAA, DNSRecordClass.NOT_UNIQUE, DNSConstants.DNS_TTL)); |
114 |
|
} |
115 |
|
} |
116 |
|
} |
117 |
45
|
} else if (this.isDomainDiscoveryQuery()) { |
118 |
|
|
119 |
|
} |
120 |
|
} |
121 |
|
|
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.42 |
|
127 |
|
private static class Service extends DNSQuestion { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
0
|
Service(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
129 |
0
|
super(name, type, recordClass, unique); |
130 |
|
} |
131 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
132 |
0
|
@Override... |
133 |
|
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) { |
134 |
0
|
String loname = this.getName().toLowerCase(); |
135 |
0
|
if (jmDNSImpl.getLocalHost().getName().equalsIgnoreCase(loname)) { |
136 |
|
|
137 |
0
|
answers.addAll(jmDNSImpl.getLocalHost().answers(this.isUnique(), DNSConstants.DNS_TTL)); |
138 |
0
|
return; |
139 |
|
} |
140 |
|
|
141 |
0
|
if (jmDNSImpl.getServiceTypes().containsKey(loname)) { |
142 |
0
|
DNSQuestion question = new Pointer(this.getName(), DNSRecordType.TYPE_PTR, this.getRecordClass(), this.isUnique()); |
143 |
0
|
question.addAnswers(jmDNSImpl, answers); |
144 |
0
|
return; |
145 |
|
} |
146 |
|
|
147 |
0
|
this.addAnswersForServiceInfo(jmDNSImpl, answers, (ServiceInfoImpl) jmDNSImpl.getServices().get(loname)); |
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
150 |
0
|
@Override... |
151 |
|
public boolean iAmTheOnlyOne(JmDNSImpl jmDNSImpl) { |
152 |
0
|
String name = this.getName().toLowerCase(); |
153 |
0
|
return jmDNSImpl.getLocalHost().getName().equals(name) || jmDNSImpl.getServices().keySet().contains(name); |
154 |
|
} |
155 |
|
|
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.75 |
|
161 |
|
private static class Text extends DNSQuestion { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
0
|
Text(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
163 |
0
|
super(name, type, recordClass, unique); |
164 |
|
} |
165 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
0
|
@Override... |
167 |
|
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) { |
168 |
0
|
this.addAnswersForServiceInfo(jmDNSImpl, answers, (ServiceInfoImpl) jmDNSImpl.getServices().get(this.getName().toLowerCase())); |
169 |
|
} |
170 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
171 |
0
|
@Override... |
172 |
|
public boolean iAmTheOnlyOne(JmDNSImpl jmDNSImpl) { |
173 |
0
|
String name = this.getName().toLowerCase(); |
174 |
0
|
return jmDNSImpl.getLocalHost().getName().equals(name) || jmDNSImpl.getServices().keySet().contains(name); |
175 |
|
} |
176 |
|
|
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
|
|
| 81% |
Uncovered Elements: 4 (21) |
Complexity: 6 |
Complexity Density: 0.46 |
|
182 |
|
private static class AllRecords extends DNSQuestion { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
183 |
393
|
AllRecords(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
184 |
389
|
super(name, type, recordClass, unique); |
185 |
|
} |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
24
|
@Override... |
188 |
|
public boolean isSameType(DNSEntry entry) { |
189 |
|
|
190 |
24
|
return (entry != null); |
191 |
|
} |
192 |
|
|
|
|
| 69.2% |
Uncovered Elements: 4 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
193 |
98
|
@Override... |
194 |
|
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) { |
195 |
98
|
String loname = this.getName().toLowerCase(); |
196 |
98
|
if (jmDNSImpl.getLocalHost().getName().equalsIgnoreCase(loname)) { |
197 |
|
|
198 |
3
|
answers.addAll(jmDNSImpl.getLocalHost().answers(this.isUnique(), DNSConstants.DNS_TTL)); |
199 |
3
|
return; |
200 |
|
} |
201 |
|
|
202 |
95
|
if (jmDNSImpl.getServiceTypes().containsKey(loname)) { |
203 |
0
|
DNSQuestion question = new Pointer(this.getName(), DNSRecordType.TYPE_PTR, this.getRecordClass(), this.isUnique()); |
204 |
0
|
question.addAnswers(jmDNSImpl, answers); |
205 |
0
|
return; |
206 |
|
} |
207 |
|
|
208 |
95
|
this.addAnswersForServiceInfo(jmDNSImpl, answers, (ServiceInfoImpl) jmDNSImpl.getServices().get(loname)); |
209 |
|
} |
210 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
211 |
206
|
@Override... |
212 |
|
public boolean iAmTheOnlyOne(JmDNSImpl jmDNSImpl) { |
213 |
214
|
String name = this.getName().toLowerCase(); |
214 |
221
|
return jmDNSImpl.getLocalHost().getName().equals(name) || jmDNSImpl.getServices().keySet().contains(name); |
215 |
|
} |
216 |
|
|
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
602
|
DNSQuestion(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
220 |
598
|
super(name, type, recordClass, unique); |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
@param |
227 |
|
|
228 |
|
@param |
229 |
|
|
230 |
|
@param |
231 |
|
|
232 |
|
@param |
233 |
|
|
234 |
|
@return |
235 |
|
|
|
|
| 26.3% |
Uncovered Elements: 14 (19) |
Complexity: 9 |
Complexity Density: 0.47 |
|
236 |
588
|
public static DNSQuestion newQuestion(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
237 |
601
|
switch (type) { |
238 |
0
|
case TYPE_A: |
239 |
0
|
return new DNS4Address(name, type, recordClass, unique); |
240 |
0
|
case TYPE_A6: |
241 |
0
|
return new DNS6Address(name, type, recordClass, unique); |
242 |
0
|
case TYPE_AAAA: |
243 |
0
|
return new DNS6Address(name, type, recordClass, unique); |
244 |
383
|
case TYPE_ANY: |
245 |
389
|
return new AllRecords(name, type, recordClass, unique); |
246 |
0
|
case TYPE_HINFO: |
247 |
0
|
return new HostInformation(name, type, recordClass, unique); |
248 |
202
|
case TYPE_PTR: |
249 |
207
|
return new Pointer(name, type, recordClass, unique); |
250 |
0
|
case TYPE_SRV: |
251 |
0
|
return new Service(name, type, recordClass, unique); |
252 |
0
|
case TYPE_TXT: |
253 |
0
|
return new Text(name, type, recordClass, unique); |
254 |
0
|
default: |
255 |
0
|
return new DNSQuestion(name, type, recordClass, unique); |
256 |
|
} |
257 |
|
} |
258 |
|
|
259 |
|
|
260 |
|
|
261 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
262 |
24
|
boolean answeredBy(DNSEntry rec) {... |
263 |
24
|
return this.isSameRecordClass(rec) && this.isSameType(rec) && this.getName().equals(rec.getName()); |
264 |
|
} |
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
269 |
|
@param |
270 |
|
|
271 |
|
@param |
272 |
|
|
273 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
274 |
0
|
public void addAnswers(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers) {... |
275 |
|
|
276 |
|
} |
277 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 6 |
Complexity Density: 1 |
|
278 |
125
|
protected void addAnswersForServiceInfo(JmDNSImpl jmDNSImpl, Set<DNSRecord> answers, ServiceInfoImpl info) {... |
279 |
125
|
if ((info != null) && info.isAnnounced()) { |
280 |
30
|
if (this.getName().equalsIgnoreCase(info.getQualifiedName()) || this.getName().equalsIgnoreCase(info.getType())) { |
281 |
30
|
answers.addAll(jmDNSImpl.getLocalHost().answers(DNSRecordClass.UNIQUE, DNSConstants.DNS_TTL)); |
282 |
30
|
answers.addAll(info.answers(DNSRecordClass.UNIQUE, DNSConstants.DNS_TTL, jmDNSImpl.getLocalHost())); |
283 |
|
} |
284 |
30
|
if (logger.isLoggable(Level.FINER)) { |
285 |
0
|
logger.finer(jmDNSImpl.getName() + " DNSQuestion(" + this.getName() + ").addAnswersForServiceInfo(): info: " + info + "\n" + answers); |
286 |
|
} |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
@see |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
294 |
0
|
@Override... |
295 |
|
public boolean isStale(long now) { |
296 |
0
|
return false; |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
@see |
302 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
303 |
0
|
@Override... |
304 |
|
public boolean isExpired(long now) { |
305 |
0
|
return false; |
306 |
|
} |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
@param |
312 |
|
|
313 |
|
@return |
314 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
315 |
119
|
public boolean iAmTheOnlyOne(JmDNSImpl jmDNSImpl) {... |
316 |
128
|
return false; |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
@see |
322 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
323 |
0
|
@Override... |
324 |
|
public void toString(StringBuilder aLog) { |
325 |
|
|
326 |
|
} |
327 |
|
|
328 |
|
} |