Skip to content

Commit e53688a

Browse files
author
bwelling
committed
Change the internal representation of empty records (that is,
records in the question section of a message or meta-records used in dynamic update). git-svn-id: http://svn.code.sf.net/p/dnsjava/code/trunk@1417 c76caeb1-94fd-44dd-870f-0c9d92034fc1
1 parent d96e3e4 commit e53688a

4 files changed

Lines changed: 60 additions & 36 deletions

File tree

Changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
4/16/2005
2+
- Change the internal representation of empty records (that is,
3+
records in the question section of a message or meta-records
4+
used in dynamic update).
5+
16
4/3/2005
27
- Change the Cache from being periodically cleaned to being
38
size-bounded. (based on a patch from several years ago

org/xbill/DNS/EmptyRecord.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 1999-2004 Brian Wellington ([email protected])
2+
3+
package org.xbill.DNS;
4+
5+
import java.io.*;
6+
7+
/**
8+
* A class implementing Records with no data; that is, records used in
9+
* the question section of messages and meta-records in dynamic update.
10+
*
11+
* @author Brian Wellington
12+
*/
13+
14+
class EmptyRecord extends Record {
15+
16+
EmptyRecord() {}
17+
18+
Record
19+
getObject() {
20+
return new EmptyRecord();
21+
}
22+
23+
void
24+
rrFromWire(DNSInput in) throws IOException {
25+
}
26+
27+
void
28+
rdataFromString(Tokenizer st, Name origin) throws IOException {
29+
}
30+
31+
String
32+
rrToString() {
33+
return "";
34+
}
35+
36+
void
37+
rrToWire(DNSOutput out, Compression c, boolean canonical) {
38+
}
39+
40+
}

org/xbill/DNS/Record.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public abstract class Record implements Cloneable, Comparable {
2020
protected Name name;
2121
protected int type, dclass;
2222
protected long ttl;
23-
private boolean empty;
2423

2524
private static final Record [] knownRecords = new Record[256];
2625
private static final Record unknownRecord = new UNKRecord();
@@ -82,9 +81,12 @@ public abstract class Record implements Cloneable, Comparable {
8281
}
8382

8483
private static final Record
85-
getEmptyRecord(Name name, int type, int dclass, long ttl) {
86-
Record rec = getTypedObject(type);
87-
rec = rec.getObject();
84+
getEmptyRecord(Name name, int type, int dclass, long ttl, boolean hasData) {
85+
Record rec;
86+
if (hasData)
87+
rec = getTypedObject(type).getObject();
88+
else
89+
rec = new EmptyRecord();
8890
rec.name = name;
8991
rec.type = type;
9092
rec.dclass = dclass;
@@ -104,17 +106,14 @@ public abstract class Record implements Cloneable, Comparable {
104106
{
105107
Record rec;
106108
int recstart;
107-
rec = getEmptyRecord(name, type, dclass, ttl);
109+
rec = getEmptyRecord(name, type, dclass, ttl, in != null);
108110
if (in != null) {
109111
if (in.remaining() < length)
110112
throw new WireParseException("truncated record");
111113
in.setActive(length);
112-
} else
113-
rec.empty = true;
114114

115-
rec.rrFromWire(in);
115+
rec.rrFromWire(in);
116116

117-
if (in != null) {
118117
if (in.remaining() > 0)
119118
throw new WireParseException("invalid record length");
120119
in.clearActive();
@@ -183,9 +182,7 @@ public abstract class Record implements Cloneable, Comparable {
183182
DClass.check(dclass);
184183
TTL.check(ttl);
185184

186-
Record rec = getEmptyRecord(name, type, dclass, ttl);
187-
rec.empty = true;
188-
return rec;
185+
return getEmptyRecord(name, type, dclass, ttl, false);
189186
}
190187

191188
/**
@@ -249,8 +246,7 @@ public abstract class Record implements Cloneable, Comparable {
249246
out.writeU32(ttl);
250247
int lengthPosition = out.current();
251248
out.writeU16(0); /* until we know better */
252-
if (!empty)
253-
rrToWire(out, c, false);
249+
rrToWire(out, c, false);
254250
int rrlength = out.current() - lengthPosition - 2;
255251
out.save();
256252
out.jump(lengthPosition);
@@ -280,8 +276,7 @@ public abstract class Record implements Cloneable, Comparable {
280276
}
281277
int lengthPosition = out.current();
282278
out.writeU16(0); /* until we know better */
283-
if (!empty)
284-
rrToWire(out, null, true);
279+
rrToWire(out, null, true);
285280
int rrlength = out.current() - lengthPosition - 2;
286281
out.save();
287282
out.jump(lengthPosition);
@@ -315,8 +310,6 @@ public abstract class Record implements Cloneable, Comparable {
315310
*/
316311
public byte []
317312
rdataToWireCanonical() {
318-
if (empty)
319-
return new byte[0];
320313
DNSOutput out = new DNSOutput();
321314
rrToWire(out, null, true);
322315
return out.toByteArray();
@@ -332,8 +325,6 @@ public abstract class Record implements Cloneable, Comparable {
332325
*/
333326
public String
334327
rdataToString() {
335-
if (empty)
336-
return "";
337328
return rrToString();
338329
}
339330

@@ -359,9 +350,10 @@ public abstract class Record implements Cloneable, Comparable {
359350
sb.append("\t");
360351
}
361352
sb.append(Type.string(type));
362-
if (!empty) {
353+
String rdata = rrToString();
354+
if (!rdata.equals("")) {
363355
sb.append("\t");
364-
sb.append(rrToString());
356+
sb.append(rdata);
365357
}
366358
return sb.toString();
367359
}
@@ -509,7 +501,7 @@ else if (array[i] == '\\') {
509501
return newRecord(name, type, dclass, ttl, length, in);
510502
}
511503
st.unget();
512-
rec = getEmptyRecord(name, type, dclass, ttl);
504+
rec = getEmptyRecord(name, type, dclass, ttl, true);
513505
rec.rdataFromString(st, origin);
514506
t = st.get();
515507
if (t.type != Tokenizer.EOL && t.type != Tokenizer.EOF) {
@@ -607,10 +599,6 @@ else if (array[i] == '\\') {
607599
Record r = (Record) arg;
608600
if (type != r.type || dclass != r.dclass || !name.equals(r.name))
609601
return false;
610-
if (empty && r.empty)
611-
return true;
612-
else if (empty || r.empty)
613-
return false;
614602
byte [] array1 = rdataToWireCanonical();
615603
byte [] array2 = r.rdataToWireCanonical();
616604
return Arrays.equals(array1, array2);
@@ -695,12 +683,6 @@ else if (empty || r.empty)
695683
n = type - arg.type;
696684
if (n != 0)
697685
return (n);
698-
if (empty && arg.empty)
699-
return 0;
700-
else if (empty)
701-
return -1;
702-
else if (arg.empty)
703-
return 1;
704686
byte [] rdata1 = rdataToWireCanonical();
705687
byte [] rdata2 = arg.rdataToWireCanonical();
706688
for (int i = 0; i < rdata1.length && i < rdata2.length; i++) {

update.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ else if (operation.equals("date")) {
227227
catch (TextParseException tpe) {
228228
System.out.println(tpe.getMessage());
229229
}
230-
catch (NullPointerException npe) {
231-
System.out.println("Parse error");
232-
}
233230
catch (InterruptedIOException iioe) {
234231
System.out.println("Operation timed out");
235232
}

0 commit comments

Comments
 (0)