2018-03-19 16:31:44 +00:00
|
|
|
// (function (exports) {
|
2017-03-10 02:34:27 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Record type is just any text.
|
2017-10-19 17:50:29 +00:00
|
|
|
// RFC 1035 - 3.3. Standard RRs - <character-string>
|
|
|
|
// RFC 1035 - 3.3.14. TXT RDATA format
|
2017-03-10 02:34:27 +00:00
|
|
|
|
|
|
|
exports.DNS_PACKER_TYPE_TXT = function (ab, dv, total, record) {
|
2017-10-19 17:50:29 +00:00
|
|
|
if ('string' === typeof record.data) {
|
|
|
|
console.warn("[WARN] 'data' should be an array of strings, not a single string");
|
|
|
|
record.data = [ record.data ];
|
|
|
|
}
|
|
|
|
if (!Array.isArray(record.data) || !record.data.length){
|
|
|
|
throw new Error("bad data or no data for TXT record");
|
2017-03-18 17:40:14 +00:00
|
|
|
}
|
2017-03-10 02:34:27 +00:00
|
|
|
|
2017-03-18 17:40:14 +00:00
|
|
|
var txtLen = 0;
|
|
|
|
var rdLenIndex = total;
|
2017-10-19 17:50:29 +00:00
|
|
|
total += 2; // saving space for rdata length
|
2017-03-10 02:34:27 +00:00
|
|
|
|
2017-03-18 17:40:14 +00:00
|
|
|
// RDATA
|
2017-03-23 23:33:55 +00:00
|
|
|
record.data.forEach(function(str){
|
2017-03-10 02:34:27 +00:00
|
|
|
|
2017-10-19 17:50:29 +00:00
|
|
|
if (str.length > 255) {
|
|
|
|
throw new Error("bad TXT string length " + str.length + " (max 255)");
|
|
|
|
}
|
2017-03-10 02:34:27 +00:00
|
|
|
|
2017-10-19 17:50:29 +00:00
|
|
|
// size of this string
|
|
|
|
dv.setUint8(total, str.length, false);
|
2017-03-23 23:33:55 +00:00
|
|
|
total += 1;
|
2017-10-19 17:50:29 +00:00
|
|
|
txtLen += 1;
|
|
|
|
|
|
|
|
str.split('').forEach(function(ch) {
|
|
|
|
|
|
|
|
dv.setUint8(total, ch.charCodeAt(0), false);
|
|
|
|
total += 1;
|
|
|
|
txtLen += 1;
|
2017-09-25 21:57:40 +00:00
|
|
|
|
2017-03-18 17:40:14 +00:00
|
|
|
});
|
|
|
|
});
|
2017-03-10 02:34:27 +00:00
|
|
|
|
2017-10-19 17:50:29 +00:00
|
|
|
dv.setUint16(rdLenIndex, txtLen, false);
|
2017-03-10 02:34:27 +00:00
|
|
|
|
2017-03-18 17:40:14 +00:00
|
|
|
return total;
|
2017-03-10 02:34:27 +00:00
|
|
|
};
|
|
|
|
|
2018-03-19 16:31:44 +00:00
|
|
|
// }('undefined' !== typeof window ? window : exports));
|