| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
package javax.jmdns.impl; |
| 6 |
|
|
| 7 |
|
import java.io.ByteArrayOutputStream; |
| 8 |
|
import java.io.DataOutputStream; |
| 9 |
|
import java.io.IOException; |
| 10 |
|
import java.util.Collections; |
| 11 |
|
import java.util.Map; |
| 12 |
|
|
| 13 |
|
import javax.jmdns.ServiceInfo.Fields; |
| 14 |
|
import javax.jmdns.impl.constants.DNSRecordClass; |
| 15 |
|
import javax.jmdns.impl.constants.DNSRecordType; |
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
@author |
| 21 |
|
|
|
|
|
| 56.7% |
Uncovered Elements: 52 (120) |
Complexity: 41 |
Complexity Density: 0.63 |
|
| 22 |
|
public abstract class DNSEntry { |
| 23 |
|
|
| 24 |
|
private final String _key; |
| 25 |
|
|
| 26 |
|
private final String _name; |
| 27 |
|
|
| 28 |
|
private final String _type; |
| 29 |
|
|
| 30 |
|
private final DNSRecordType _recordType; |
| 31 |
|
|
| 32 |
|
private final DNSRecordClass _dnsClass; |
| 33 |
|
|
| 34 |
|
private final boolean _unique; |
| 35 |
|
|
| 36 |
|
final Map<Fields, String> _qualifiedNameMap; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 41 |
2597
|
DNSEntry(String name, DNSRecordType type, DNSRecordClass recordClass, boolean unique) {... |
| 42 |
2639
|
_name = name; |
| 43 |
|
|
| 44 |
2636
|
_recordType = type; |
| 45 |
2624
|
_dnsClass = recordClass; |
| 46 |
2640
|
_unique = unique; |
| 47 |
2627
|
_qualifiedNameMap = ServiceInfoImpl.decodeQualifiedNameMapForType(this.getName()); |
| 48 |
2641
|
String domain = _qualifiedNameMap.get(Fields.Domain); |
| 49 |
2640
|
String protocol = _qualifiedNameMap.get(Fields.Protocol); |
| 50 |
2648
|
String application = _qualifiedNameMap.get(Fields.Application); |
| 51 |
2649
|
String instance = _qualifiedNameMap.get(Fields.Instance).toLowerCase(); |
| 52 |
2643
|
_type = (application.length() > 0 ? "_" + application + "." : "") + (protocol.length() > 0 ? "_" + protocol + "." : "") + domain + "."; |
| 53 |
2650
|
_key = ((instance.length() > 0 ? instance + "." : "") + _type).toLowerCase(); |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
@see |
| 59 |
|
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 60 |
106
|
@Override... |
| 61 |
|
public boolean equals(Object obj) { |
| 62 |
107
|
boolean result = false; |
| 63 |
106
|
if (obj instanceof DNSEntry) { |
| 64 |
108
|
DNSEntry other = (DNSEntry) obj; |
| 65 |
108
|
result = this.getKey().equals(other.getKey()) && this.getRecordType().equals(other.getRecordType()) && this.getRecordClass() == other.getRecordClass(); |
| 66 |
|
} |
| 67 |
108
|
return result; |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
@param |
| 74 |
|
@return |
| 75 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 76 |
963
|
public boolean isSameEntry(DNSEntry entry) {... |
| 77 |
968
|
return this.getKey().equals(entry.getKey()) && this.getRecordType().equals(entry.getRecordType()) && ((DNSRecordClass.CLASS_ANY == entry.getRecordClass()) || this.getRecordClass().equals(entry.getRecordClass())); |
| 78 |
|
} |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
@param |
| 84 |
|
@return |
| 85 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
503
|
public boolean sameSubtype(DNSEntry other) {... |
| 87 |
508
|
return this.getSubtype().equals(other.getSubtype()); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
@return |
| 94 |
|
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 95 |
1015
|
public String getSubtype() {... |
| 96 |
1029
|
String subtype = this.getQualifiedNameMap().get(Fields.Subtype); |
| 97 |
1018
|
return (subtype != null ? subtype : ""); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
@return |
| 104 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 105 |
5762
|
public String getName() {... |
| 106 |
5781
|
return (_name != null ? _name : ""); |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
@return |
| 111 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 112 |
16
|
public String getType() {... |
| 113 |
16
|
return (_type != null ? _type : ""); |
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@return |
| 120 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 121 |
4125
|
public String getKey() {... |
| 122 |
4131
|
return (_key != null ? _key : ""); |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@return |
| 127 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 128 |
9386
|
public DNSRecordType getRecordType() {... |
| 129 |
9374
|
return (_recordType != null ? _recordType : DNSRecordType.TYPE_IGNORE); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
@return |
| 134 |
|
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 135 |
4736
|
public DNSRecordClass getRecordClass() {... |
| 136 |
4737
|
return (_dnsClass != null ? _dnsClass : DNSRecordClass.CLASS_UNKNOWN); |
| 137 |
|
} |
| 138 |
|
|
| 139 |
|
|
| 140 |
|
@return |
| 141 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 142 |
2458
|
public boolean isUnique() {... |
| 143 |
2465
|
return _unique; |
| 144 |
|
} |
| 145 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 146 |
1282
|
public Map<Fields, String> getQualifiedNameMap() {... |
| 147 |
1292
|
return Collections.unmodifiableMap(_qualifiedNameMap); |
| 148 |
|
} |
| 149 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 150 |
1020
|
public boolean isServicesDiscoveryMetaQuery() {... |
| 151 |
1032
|
return _qualifiedNameMap.get(Fields.Application).equals("dns-sd") && _qualifiedNameMap.get(Fields.Instance).equals("_services"); |
| 152 |
|
} |
| 153 |
|
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 154 |
848
|
public boolean isDomainDiscoveryQuery() {... |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
855
|
if (_qualifiedNameMap.get(Fields.Application).equals("dns-sd")) { |
| 162 |
0
|
String name = _qualifiedNameMap.get(Fields.Instance); |
| 163 |
0
|
return "b".equals(name) || "db".equals(name) || "r".equals(name) || "dr".equals(name) || "lb".equals(name); |
| 164 |
|
} |
| 165 |
857
|
return false; |
| 166 |
|
} |
| 167 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 168 |
151
|
public boolean isReverseLookup() {... |
| 169 |
151
|
return this.isV4ReverseLookup() || this.isV6ReverseLookup(); |
| 170 |
|
} |
| 171 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 172 |
150
|
public boolean isV4ReverseLookup() {... |
| 173 |
152
|
return _qualifiedNameMap.get(Fields.Domain).endsWith("in-addr.arpa"); |
| 174 |
|
} |
| 175 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 176 |
143
|
public boolean isV6ReverseLookup() {... |
| 177 |
143
|
return _qualifiedNameMap.get(Fields.Domain).endsWith("ip6.arpa"); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
@param |
| 184 |
|
|
| 185 |
|
@return |
| 186 |
|
|
| 187 |
|
public abstract boolean isStale(long now); |
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
|
| 192 |
|
@param |
| 193 |
|
|
| 194 |
|
@return |
| 195 |
|
|
| 196 |
|
public abstract boolean isExpired(long now); |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
|
| 200 |
|
|
| 201 |
|
@param |
| 202 |
|
@return |
| 203 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 204 |
24
|
public boolean isSameRecordClass(DNSEntry entry) {... |
| 205 |
24
|
return (entry != null) && (entry.getRecordClass() == this.getRecordClass()); |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
| 210 |
|
|
| 211 |
|
@param |
| 212 |
|
@return |
| 213 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 214 |
0
|
public boolean isSameType(DNSEntry entry) {... |
| 215 |
0
|
return (entry != null) && (entry.getRecordType() == this.getRecordType()); |
| 216 |
|
} |
| 217 |
|
|
| 218 |
|
|
| 219 |
|
@param |
| 220 |
|
@exception |
| 221 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 222 |
0
|
protected void toByteArray(DataOutputStream dout) throws IOException {... |
| 223 |
0
|
dout.write(this.getName().getBytes("UTF8")); |
| 224 |
0
|
dout.writeShort(this.getRecordType().indexValue()); |
| 225 |
0
|
dout.writeShort(this.getRecordClass().indexValue()); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
@return |
| 232 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 233 |
0
|
protected byte[] toByteArray() {... |
| 234 |
0
|
try { |
| 235 |
0
|
ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
| 236 |
0
|
DataOutputStream dout = new DataOutputStream(bout); |
| 237 |
0
|
this.toByteArray(dout); |
| 238 |
0
|
dout.close(); |
| 239 |
0
|
return bout.toByteArray(); |
| 240 |
|
} catch (IOException e) { |
| 241 |
0
|
throw new InternalError(); |
| 242 |
|
} |
| 243 |
|
} |
| 244 |
|
|
| 245 |
|
|
| 246 |
|
|
| 247 |
|
|
| 248 |
|
@param |
| 249 |
|
@return |
| 250 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 251 |
0
|
public int compareTo(DNSEntry that) {... |
| 252 |
0
|
byte[] thisBytes = this.toByteArray(); |
| 253 |
0
|
byte[] thatBytes = that.toByteArray(); |
| 254 |
0
|
for (int i = 0, n = Math.min(thisBytes.length, thatBytes.length); i < n; i++) { |
| 255 |
0
|
if (thisBytes[i] > thatBytes[i]) { |
| 256 |
0
|
return 1; |
| 257 |
0
|
} else if (thisBytes[i] < thatBytes[i]) { |
| 258 |
0
|
return -1; |
| 259 |
|
} |
| 260 |
|
} |
| 261 |
0
|
return thisBytes.length - thatBytes.length; |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 267 |
123
|
@Override... |
| 268 |
|
public int hashCode() { |
| 269 |
123
|
return this.getKey().hashCode() + this.getRecordType().indexValue() + this.getRecordClass().indexValue(); |
| 270 |
|
} |
| 271 |
|
|
| 272 |
|
|
| 273 |
|
|
| 274 |
|
@see |
| 275 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
| 276 |
0
|
@Override... |
| 277 |
|
public String toString() { |
| 278 |
0
|
StringBuilder aLog = new StringBuilder(200); |
| 279 |
0
|
aLog.append("[" + this.getClass().getSimpleName() + "@" + System.identityHashCode(this)); |
| 280 |
0
|
aLog.append(" type: " + this.getRecordType()); |
| 281 |
0
|
aLog.append(", class: " + this.getRecordClass()); |
| 282 |
0
|
aLog.append((_unique ? "-unique," : ",")); |
| 283 |
0
|
aLog.append(" name: " + _name); |
| 284 |
0
|
this.toString(aLog); |
| 285 |
0
|
aLog.append("]"); |
| 286 |
0
|
return aLog.toString(); |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
|
| 290 |
|
@param |
| 291 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 292 |
0
|
protected void toString(StringBuilder aLog) {... |
| 293 |
|
|
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
} |