Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement URI record #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ var
WRITE_SOA = consts.NAME_TO_QTYPE.SOA,
WRITE_OPT = consts.NAME_TO_QTYPE.OPT,
WRITE_NAPTR = consts.NAME_TO_QTYPE.NAPTR,
WRITE_TLSA = consts.NAME_TO_QTYPE.TLSA;
WRITE_TLSA = consts.NAME_TO_QTYPE.TLSA,
WRITE_URI = consts.NAME_TO_QTYPE.URI;

function writeHeader(buff, packet) {
assert(packet.header, 'Packet requires "header"');
Expand Down Expand Up @@ -362,6 +363,18 @@ function writeTlsa(buff, val) {
return WRITE_RESOURCE_DONE;
}

// URI: https://tools.ietf.org/html/draft-faltstrom-uri
function writeUri(buff, val) {
assertUndefined(val.priority, 'URI record requires "priority"');
assertUndefined(val.weight, 'URI record requires "weight"');
assertUndefined(val.target, 'URI record requires "target"');
buff.writeUInt16BE(val.priority & 0xFFFF);
buff.writeUInt16BE(val.weight & 0xFFFF);
buff.write(val.target);
return WRITE_RESOURCE_DONE;
}


function makeEdns(packet) {
packet.edns = {
name: '',
Expand Down Expand Up @@ -481,6 +494,9 @@ Packet.write = function(buff, packet) {
case WRITE_TLSA:
state = writeTlsa(buff, val);
break;
case WRITE_URI:
state = writeUri(buff, val);
break;
case WRITE_END:
return buff.tell();
default:
Expand Down Expand Up @@ -658,6 +674,13 @@ function parseOpt(val, msg, rdata, packet) {
return PARSE_RESOURCE_DONE;
}

function parseUri(val, msg, rdata) {
val.priority = msg.readUInt16BE();
val.weight = msg.readUInt16BE();
val.target = msg.slice(rdata.len - 4).toString('utf8');
return PARSE_RESOURCE_DONE;
}

var
PARSE_HEADER = 100000,
PARSE_QUESTION = 100001,
Expand All @@ -677,8 +700,9 @@ var
PARSE_NAPTR = consts.NAME_TO_QTYPE.NAPTR,
PARSE_OPT = consts.NAME_TO_QTYPE.OPT,
PARSE_SPF = consts.NAME_TO_QTYPE.SPF,
PARSE_TLSA = consts.NAME_TO_QTYPE.TLSA;

PARSE_TLSA = consts.NAME_TO_QTYPE.TLSA,
PARSE_URI = consts.NAME_TO_QTYPE.URI;


Packet.parse = function(msg) {
var state,
Expand Down Expand Up @@ -767,6 +791,9 @@ Packet.parse = function(msg) {
case PARSE_TLSA:
state = parseTlsa(val, msg, rdata);
break;
case PARSE_URI:
state = parseUri(val, msg, rdata);
break;
case PARSE_END:
return packet;
default:
Expand Down
Binary file added test/fixtures/single.draft-faltstrom-uri.uk.uri.bin
Binary file not shown.
28 changes: 28 additions & 0 deletions test/fixtures/single.draft-faltstrom-uri.uk.uri.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ header:
{ id: 8294,
qr: 1,
opcode: 0,
aa: 0,
tc: 0,
rd: 1,
ra: 1,
res1: 0,
res2: 0,
res3: 0,
rcode: 0 },
question: [ { name: 'single.draft-faltstrom-uri.uk', type: 256, class: 1 } ],
answer:
[{
name: 'single.draft-faltstrom-uri.uk',
type: 256,
class: 1,
ttl: 126,
priority: 42,
weight: 69,
target: 'http://tools.ietf.org/html/draft-faltstrom-uri'
} ],
authority: [],
additional: [],
edns_options: [],
payload: undefined,
}