Server after chain support, and minor metrics

This commit is contained in:
Mark Cavage 2011-09-13 14:49:21 -07:00
parent 1e242d840b
commit 0e77b69dc0
2 changed files with 31 additions and 3 deletions

View File

@ -24,6 +24,7 @@ function SearchResponse(options) {
this.attributes = options.attributes ? options.attributes.slice() : [];
this.notAttributes = [];
this.sentEntries = 0;
}
util.inherits(SearchResponse, LDAPResult);
module.exports = SearchResponse;
@ -76,6 +77,7 @@ SearchResponse.prototype.send = function(entry) {
this.log.debug('%s: sending: %j', this.connection.ldap.id, entry.json);
this.connection.write(entry.toBer());
this.sentEntries++;
} catch (e) {
this.log.warn('%s failure to write message %j: %s',
this.connection.ldap.id, this.json, e.toString());

View File

@ -300,6 +300,7 @@ function Server(options) {
c.parser.on('message', function(req) {
req.connection = c;
req.logId = c.ldap.id + '::' + req.messageID;
req.startTime = new Date().getTime();
if (log.isDebugEnabled())
log.debug('%s: message received: req=%j', c.ldap.id, req.json);
@ -325,18 +326,32 @@ function Server(options) {
res.requestDN = req.dn;
var chain = self._getHandlerChain(req);
//.concat(this._postChain || []);
var i = 0;
return function(err) {
function sendError(err) {
res.status = err.code || errors.LDAP_OPERATIONS_ERROR;
res.matchedDN = req.suffix.toString();
res.matchedDN = req.suffix ? req.suffix.toString() : '';
res.errorMessage = err.message || '';
return res.end();
}
if (err)
return sendError(err);
function after() {
if (!self._postChain || !self._postChain.length)
return;
function next() {} // stub out next for the post chain
self._postChain.forEach(function(c) {
c.call(self, req, res, next);
});
}
if (err) {
sendError(err);
return after();
}
try {
var next = arguments.callee;
@ -346,6 +361,7 @@ function Server(options) {
if (req.protocolOp === Protocol.LDAP_REQ_BIND && res.status === 0)
c.ldap.bindDN = req.dn;
return after();
} catch (e) {
if (!e.stack)
e.stack = e.toString();
@ -611,6 +627,16 @@ Server.prototype.unbind = function() {
};
Server.prototype.after = function() {
if (!this._postChain)
this._postChain = [];
var self = this;
mergeFunctionArgs(arguments).forEach(function(h) {
self._postChain.push(h);
});
};
// All these just reexpose the requisite net.Server APIs
Server.prototype.listen = function(port, host, callback) {
if (!port)