load parsers correctly

This commit is contained in:
AJ ONeal 2017-02-17 19:38:47 -07:00
parent 113187e68a
commit 55876e2df2
8 changed files with 12 additions and 9 deletions

View File

@ -22,12 +22,15 @@ exports.DNS_RDATA_PARSE = function (ab, packet, record) {
} }
try { try {
parser = exports['DNS_TYPE_' + record.typeName] parser = exports['DNS_PARSER_TYPE_' + record.typeName]
|| require('./parser/type.' + record.typeName.toLowerCase())['DNS_PARSER_TYPE_' + record.typeName]; || require('./parser/type.' + record.typeName.toLowerCase())['DNS_PARSER_TYPE_' + record.typeName];
} }
catch (e) { /*console.error(e)*/ } catch (e) { /*console.error(e)*/ }
if (!parser) { if (!parser) {
if (require) {
require('./parser/type.' + record.typeName.toLowerCase());
}
throw new Error("Parser for DNS Type " + record.typeName + " could not be loaded." throw new Error("Parser for DNS Type " + record.typeName + " could not be loaded."
+ " Did you include <script src=\"parser/type." + record.typeName.toLowerCase() + ".js\"></script> ?" + " Did you include <script src=\"parser/type." + record.typeName.toLowerCase() + ".js\"></script> ?"
+ " (or perhaps we plan to implement it and haven't yet - in which case please open an issue)" + " (or perhaps we plan to implement it and haven't yet - in which case please open an issue)"

View File

@ -9,7 +9,7 @@
// (meaning text that will be represented as a period-separated // (meaning text that will be represented as a period-separated
// domain name, i.e. www.google.com) then you will need to use // domain name, i.e. www.google.com) then you will need to use
// `unpackLabels`, which has compression pointer support // `unpackLabels`, which has compression pointer support
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
// The parser receives exactly 3 parameters as follows: // The parser receives exactly 3 parameters as follows:
// //

View File

@ -5,7 +5,7 @@
// Canonical name which may lie outside the current zone. // Canonical name which may lie outside the current zone.
// Canonical simply means the expected or real name. // Canonical simply means the expected or real name.
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
exports.DNS_PARSER_TYPE_CNAME = function (ab, packet, record) { exports.DNS_PARSER_TYPE_CNAME = function (ab, packet, record) {
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
return record; return record;

View File

@ -9,7 +9,7 @@
// May be a label, pointer or any combination // May be a label, pointer or any combination
// ab is arrayBuffer, packet is Object, Record is Object // ab is arrayBuffer, packet is Object, Record is Object
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
exports.DNS_PARSER_TYPE_MX = function (ab, packet, record) { exports.DNS_PARSER_TYPE_MX = function (ab, packet, record) {
var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength); var rdataAb = ab.slice(record.rdstart, record.rdstart + record.rdlength);

View File

@ -4,7 +4,7 @@
// Comes in variable lengths. It is the name of the primary Master for the Domain. // Comes in variable lengths. It is the name of the primary Master for the Domain.
// For example 'ns1.example.com' // For example 'ns1.example.com'
// It may be a label, pointer or any combination // It may be a label, pointer or any combination
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
exports.DNS_PARSER_TYPE_NS = function (ab , packet, record) { exports.DNS_PARSER_TYPE_NS = function (ab , packet, record) {

View File

@ -9,7 +9,7 @@
// ame ttl class rr name // ame ttl class rr name
// 15 IN PTR www.example.com. // 15 IN PTR www.example.com.
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
exports.DNS_PARSER_TYPE_PTR = function (ab, pack, record) { exports.DNS_PARSER_TYPE_PTR = function (ab, pack, record) {
record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name; record.data = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }).name;
return record; return record;

View File

@ -4,7 +4,7 @@
// SRV identifies the host(s) that will support a particular service. It // SRV identifies the host(s) that will support a particular service. It
// is a general purpose RR to discover any service. // is a general purpose RR to discover any service.
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
exports.DNS_PARSER_TYPE_SRV = function (ab, packet, record) { exports.DNS_PARSER_TYPE_SRV = function (ab, packet, record) {

View File

@ -5,9 +5,9 @@
// with a host or other name, such as a human readable information about a server // with a host or other name, such as a human readable information about a server
// network, data center, and other accounting information. // network, data center, and other accounting information.
var unpackLabels = exports.DNS_UNPACK_LABELS || require('./dns.unpack-labels.js').DNS_UNPACK_LABELS; var unpackLabels = exports.DNS_UNPACK_LABELS || require('../dns.unpack-labels.js').DNS_UNPACK_LABELS;
exports.DNS_TYPE_TXT = function (ab, packet, record) { exports.DNS_PARSER_TYPE_TXT = function (ab, packet, record) {
var labels = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' }); var labels = unpackLabels(new Uint8Array(ab), record.rdstart, { byteLength: 0, cpcount: 0, labels: [], name: '' });
record.data = [ labels.name ]; record.data = [ labels.name ];