Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
query.questions.forEach(function (question) {
var type = question.type
var name = question.name
// generate the answers section
var answers = type === 'ANY'
? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
: self._recordsFor(name, type)
if (answers.length === 0) return
// generate the additionals section
var additionals = []
if (type !== 'ANY') {
answers.forEach(function (answer) {
if (answer.type !== 'PTR') return
additionals = additionals
.concat(self._recordsFor(answer.data, 'SRV'))
.concat(self._recordsFor(answer.data, 'TXT'))
})
// to populate the A and AAAA records, we need to get a set of unique
// targets from the SRV record
function teardown (server, services, cb) {
if (!Array.isArray(services)) services = [services]
services = services.filter(function (service) {
return service._activated // ignore services not currently starting or started
})
var records = flatten.depth(services.map(function (service) {
service._activated = false
var records = service._records()
records.forEach(function (record) {
record.ttl = 0 // prepare goodbye message
})
return records
}), 1)
if (records.length === 0) return cb && cb()
server.unregister(records)
// send goodbye message
server.mdns.respond(records, function () {
services.forEach(function (service) {
service.published = false
query.questions.forEach(function (question) {
var type = question.type
var name = question.name
// generate the answers section
var answers = type === 'ANY'
? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
: self._recordsFor(name, type)
if (answers.length === 0) return
// generate the additionals section
var additionals = []
if (type !== 'ANY') {
answers.forEach(function (answer) {
if (answer.type !== 'PTR') return
additionals = additionals
.concat(self._recordsFor(answer.data, 'SRV'))
.concat(self._recordsFor(answer.data, 'TXT'))
})
}
self.mdns.respond({ answers: answers, additionals: additionals }, function (err) {
function teardown (server, services, cb) {
if (!Array.isArray(services)) services = [services]
services = services.filter(function (service) {
return service._activated // ignore services not currently starting or started
})
var records = flatten.depth(services.map(function (service) {
service._activated = false
var records = service._records()
records.forEach(function (record) {
record.ttl = 0 // prepare goodbye message
})
return records
}), 1)
if (records.length === 0) return cb && cb()
server.unregister(records)
// send goodbye message
server.mdns.respond(records, function () {
services.forEach(function (service) {
service.published = false
query.questions.forEach(function (question) {
var type = question.type
var name = question.name
// generate the answers section
var answers = type === 'ANY'
? flatten.depth(Object.keys(self.registry).map(self._recordsFor.bind(self, name)), 1)
: self._recordsFor(name, type)
if (answers.length === 0) return
// generate the additionals section
var additionals = []
if (type !== 'ANY') {
answers.forEach(function (answer) {
if (answer.type !== 'PTR') return
additionals = additionals
.concat(self._recordsFor(answer.data, 'SRV'))
.concat(self._recordsFor(answer.data, 'TXT'))
})
// to populate the A and AAAA records, we need to get a set of unique
// targets from the SRV record
Server.prototype._recordsFor = function (name, type) {
var self = this
type = type ? [type] : Object.keys(this.registry)
return flatten.depth(type.map(function (type) {
if (!(type in self.registry)) return []
if (name) {
return self.registry[type].filter(function (record) {
var _name = ~name.indexOf('.') ? record.name : record.name.split('.')[0]
return dnsEqual(_name, name)
})
} else {
return self.registry[type]
}
}), 1)
}
async function run(argv /*: Array */, options /*: RunOptions */ = {}) {
const filesLists /*: Array> */ = argv.map(spec => glob(spec))
const files /*: Array */ = flatten(filesLists, 1)
const results /*: Array */ = await Promise.all(
files.map(file => {
return runFile(file, options)
})
)
const all = results
const fixeds = results.filter(res => res.status === 'fixed')
const errors = results.filter(res => res.status === 'error')
const oks = results.filter(res => res.status === 'ok')
if (all.length === oks.length) {
return { code: 0, summary: `${all.length} files OK`, messages: [] }
} else {
let isSuccess = options.fix && errors.length === 0
const filenames = fixeds.concat(errors).map(res => res.document.path)