mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 19:52:15 -05:00
Add TXT record
This commit is contained in:
parent
f13813186f
commit
b0f8bec1cb
@ -11,6 +11,7 @@ import de.measite.minidns.record.Data;
|
||||
import de.measite.minidns.record.NS;
|
||||
import de.measite.minidns.record.PTR;
|
||||
import de.measite.minidns.record.SRV;
|
||||
import de.measite.minidns.record.TXT;
|
||||
import de.measite.minidns.util.NameUtil;
|
||||
|
||||
/**
|
||||
@ -231,7 +232,11 @@ public class Record {
|
||||
public void parse(DataInputStream dis, byte[] data) throws IOException {
|
||||
this.name = NameUtil.parse(dis, data);
|
||||
this.type = TYPE.getType(dis.readUnsignedShort());
|
||||
this.clazz = CLASS.getClass(dis.readUnsignedShort());
|
||||
int clazzValue = dis.readUnsignedShort();
|
||||
this.clazz = CLASS.getClass(clazzValue);
|
||||
if (this.clazz == null) {
|
||||
System.out.println("Unknown class " + clazzValue);
|
||||
}
|
||||
this.ttl = (((long)dis.readUnsignedShort()) << 32) +
|
||||
dis.readUnsignedShort();
|
||||
int payloadLength = dis.readUnsignedShort();
|
||||
@ -254,6 +259,9 @@ public class Record {
|
||||
case PTR:
|
||||
this.payloadData = new PTR();
|
||||
break;
|
||||
case TXT:
|
||||
this.payloadData = new TXT();
|
||||
break;
|
||||
default:
|
||||
System.out.println("Unparsed type " + type);
|
||||
this.payloadData = null;
|
||||
|
65
src/main/java/de/measite/minidns/record/TXT.java
Normal file
65
src/main/java/de/measite/minidns/record/TXT.java
Normal file
@ -0,0 +1,65 @@
|
||||
package de.measite.minidns.record;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import de.measite.minidns.Record.TYPE;
|
||||
import de.measite.minidns.util.NameUtil;
|
||||
|
||||
/**
|
||||
* TXT record (actually a binary blob with wrappers for text content).
|
||||
*/
|
||||
public class TXT implements Data {
|
||||
|
||||
protected byte[] blob;
|
||||
|
||||
public byte[] getBlob() {
|
||||
return blob;
|
||||
}
|
||||
|
||||
public void setBlob(byte[] blob) {
|
||||
this.blob = blob;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
try {
|
||||
return (new String(blob, "UTF-8")).intern();
|
||||
} catch (Exception e) {
|
||||
/* Can't happen for UTF-8 unless it's really a blob */
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
try {
|
||||
this.blob = text.getBytes("UTF-8");
|
||||
} catch (Exception e) {
|
||||
/* Can't happen, UTF-8 IS supported */
|
||||
throw new RuntimeException("UTF-8 not supported", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
throw new UnsupportedOperationException("Not implemented yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parse(DataInputStream dis, byte[] data, int length)
|
||||
throws IOException
|
||||
{
|
||||
blob = new byte[length];
|
||||
dis.readFully(blob);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TYPE getType() {
|
||||
return TYPE.TXT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\"" + getText() + "\"";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user