node-ldapjs/lib/messages/ext_response.js

93 lines
2.3 KiB
JavaScript
Raw Normal View History

2011-08-04 20:32:01 +00:00
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var assert = require('assert');
var util = require('util');
var LDAPResult = require('./result');
var Protocol = require('../protocol');
///--- API
function ExtendedResponse(options) {
if (options) {
if (typeof (options) !== 'object')
2011-08-04 20:32:01 +00:00
throw new TypeError('options must be an object');
if (options.responseName && typeof (options.responseName) !== 'string')
2011-08-04 20:32:01 +00:00
throw new TypeError('options.responseName must be a string');
if (options.responseValue && typeof (options.responseValue) !== 'string')
2011-08-04 20:32:01 +00:00
throw new TypeError('options.responseValue must be a string');
} else {
options = {};
}
this.responseName = options.responseName || undefined;
this.responseValue = options.responseValue || undefined;
options.protocolOp = Protocol.LDAP_REP_EXTENSION;
LDAPResult.call(this, options);
this.__defineGetter__('name', function () {
2011-08-04 20:32:01 +00:00
return this.responseName;
});
this.__defineGetter__('value', function () {
2011-08-04 20:32:01 +00:00
return this.responseValue;
});
this.__defineSetter__('name', function (name) {
if (typeof (name) !== 'string')
2011-08-04 20:32:01 +00:00
throw new TypeError('name must be a string');
this.responseName = name;
});
this.__defineSetter__('value', function (val) {
if (typeof (val) !== 'string')
2011-08-04 20:32:01 +00:00
throw new TypeError('value must be a string');
this.responseValue = val;
});
}
util.inherits(ExtendedResponse, LDAPResult);
module.exports = ExtendedResponse;
ExtendedResponse.prototype._parse = function (ber) {
2011-08-04 20:32:01 +00:00
assert.ok(ber);
if (!LDAPResult.prototype._parse.call(this, ber))
return false;
if (ber.peek() === 0x8a)
this.responseName = ber.readString(0x8a);
if (ber.peek() === 0x8b)
this.responseValue = ber.readString(0x8b);
return true;
};
ExtendedResponse.prototype._toBer = function (ber) {
2011-08-04 20:32:01 +00:00
assert.ok(ber);
if (!LDAPResult.prototype._toBer.call(this, ber))
return false;
if (this.responseName)
ber.writeString(this.responseName, 0x8a);
if (this.responseValue)
ber.writeString(this.responseValue, 0x8b);
return ber;
};
ExtendedResponse.prototype._json = function (j) {
2011-08-04 20:32:01 +00:00
assert.ok(j);
j = LDAPResult.prototype._json.call(this, j);
j.responseName = this.responseName;
j.responseValue = this.responseValue;
return j;
};