From 2489d87079e0e18da5775da07a8b710d6264f127 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Sat, 5 Dec 2020 17:58:13 -0600 Subject: [PATCH] chore(lint): lint lib/ --- lib/client/client.js | 32 +++++++------- lib/client/message-tracker/id-generator.js | 4 +- lib/server.js | 50 +++++++++++----------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/lib/client/client.js b/lib/client/client.js index 5ee6090..67ed31b 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -418,25 +418,25 @@ Client.prototype.modify = function modify (name, change, controls, callback) { const changes = [] - function changeFromObject (change) { - if (!change.operation && !change.type) { throw new Error('change.operation required') } - if (typeof (change.modification) !== 'object') { throw new Error('change.modification (object) required') } + function changeFromObject (obj) { + if (!obj.operation && !obj.type) { throw new Error('change.operation required') } + if (typeof (obj.modification) !== 'object') { throw new Error('change.modification (object) required') } - if (Object.keys(change.modification).length === 2 && - typeof (change.modification.type) === 'string' && - Array.isArray(change.modification.vals)) { + if (Object.keys(obj.modification).length === 2 && + typeof (obj.modification.type) === 'string' && + Array.isArray(obj.modification.vals)) { // Use modification directly if it's already normalized: changes.push(new Change({ - operation: change.operation || change.type, - modification: change.modification + operation: obj.operation || obj.type, + modification: obj.modification })) } else { // Normalize the modification object - Object.keys(change.modification).forEach(function (k) { + Object.keys(obj.modification).forEach(function (k) { const mod = {} - mod[k] = change.modification[k] + mod[k] = obj.modification[k] changes.push(new Change({ - operation: change.operation || change.type, + operation: obj.operation || obj.type, modification: mod })) }) @@ -679,9 +679,9 @@ Client.prototype.starttls = function starttls (options, return callback(new Error('STARTTLS already in progress or active')) } - function onSend (err, emitter) { - if (err) { - callback(err) + function onSend (sendErr, emitter) { + if (sendErr) { + callback(sendErr) return } /* @@ -850,9 +850,9 @@ Client.prototype.connect = function connect () { } // Initialize socket events and LDAP parser. - function initSocket (url) { + function initSocket (server) { tracker = messageTrackerFactory({ - id: url ? url.href : self.socketPath, + id: server ? server.href : self.socketPath, parser: new Parser({ log: log }) }) diff --git a/lib/client/message-tracker/id-generator.js b/lib/client/message-tracker/id-generator.js index 49423ea..3756314 100644 --- a/lib/client/message-tracker/id-generator.js +++ b/lib/client/message-tracker/id-generator.js @@ -16,8 +16,8 @@ const { MAX_MSGID } = require('../constants') module.exports = function idGeneratorFactory (start = 0) { let currentID = start return function nextID () { - const nextID = currentID + 1 - currentID = (nextID >= MAX_MSGID) ? 1 : nextID + const id = currentID + 1 + currentID = (id >= MAX_MSGID) ? 1 : id return currentID } } diff --git a/lib/server.js b/lib/server.js index 190dede..512c679 100644 --- a/lib/server.js +++ b/lib/server.js @@ -313,28 +313,28 @@ function Server (options) { return c } - function newConnection (c) { - setupConnection(c) - log.trace('new connection from %s', c.ldap.id) + function newConnection (conn) { + setupConnection(conn) + log.trace('new connection from %s', conn.ldap.id) dtrace.fire('server-connection', function () { - return [c.remoteAddress] + return [conn.remoteAddress] }) - c.parser = new Parser({ + conn.parser = new Parser({ log: options.log }) - c.parser.on('message', function (req) { - req.connection = c - req.logId = c.ldap.id + '::' + req.messageID + conn.parser.on('message', function (req) { + req.connection = conn + req.logId = conn.ldap.id + '::' + req.messageID req.startTime = new Date().getTime() - log.debug('%s: message received: req=%j', c.ldap.id, req.json) + log.debug('%s: message received: req=%j', conn.ldap.id, req.json) const res = getResponse(req) if (!res) { log.warn('Unimplemented server method: %s', req.type) - c.destroy() + conn.destroy() return false } @@ -368,7 +368,7 @@ function Server (options) { } } - res.connection = c + res.connection = conn res.logId = req.logId res.requestDN = req.dn @@ -376,10 +376,10 @@ function Server (options) { let i = 0 return (function messageIIFE (err) { - function sendError (err) { - res.status = err.code || errors.LDAP_OPERATIONS_ERROR + function sendError (sendErr) { + res.status = sendErr.code || errors.LDAP_OPERATIONS_ERROR res.matchedDN = req.suffix ? req.suffix.toString() : '' - res.errorMessage = err.message || '' + res.errorMessage = sendErr.message || '' return res.end() } @@ -388,8 +388,8 @@ function Server (options) { function next () {} // stub out next for the post chain - self._postChain.forEach(function (c) { - c.call(self, req, res, next) + self._postChain.forEach(function (cb) { + cb.call(self, req, res, next) }) } @@ -404,7 +404,7 @@ function Server (options) { const next = messageIIFE if (chain.handlers[i]) { return chain.handlers[i++].call(chain.backend, req, res, next) } - if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { c.ldap.bindDN = req.dn } + if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0) { conn.ldap.bindDN = req.dn } return after() } catch (e) { @@ -415,23 +415,23 @@ function Server (options) { }()) }) - c.parser.on('error', function (err, message) { - self.emit('error', new VError(err, 'Parser error for %s', c.ldap.id)) + conn.parser.on('error', function (err, message) { + self.emit('error', new VError(err, 'Parser error for %s', conn.ldap.id)) - if (!message) { return c.destroy() } + if (!message) { return conn.destroy() } const res = getResponse(message) - if (!res) { return c.destroy() } + if (!res) { return conn.destroy() } res.status = 0x02 // protocol error res.errorMessage = err.toString() - return c.end(res.toBer()) + return conn.end(res.toBer()) }) - c.on('data', function (data) { - log.trace('data on %s: %s', c.ldap.id, util.inspect(data)) + conn.on('data', function (data) { + log.trace('data on %s: %s', conn.ldap.id, util.inspect(data)) - c.parser.write(data) + conn.parser.write(data) }) } // end newConnection