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 LDAPMessage = require('./message');
|
|
|
|
var Protocol = require('../protocol');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function ExtendedRequest(options) {
|
|
|
|
if (options) {
|
2012-02-18 08:15:52 +00:00
|
|
|
if (typeof (options) !== 'object')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options must be an object');
|
2012-02-18 08:15:52 +00:00
|
|
|
if (options.requestName && typeof (options.requestName) !== 'string')
|
2011-08-04 20:32:01 +00:00
|
|
|
throw new TypeError('options.requestName must be a string');
|
2014-01-17 17:52:26 +00:00
|
|
|
if (options.requestValue && !(Buffer.isBuffer(options.requestValue) ||
|
|
|
|
typeof (options.requestValue) === 'string'))
|
2014-01-03 12:47:42 +00:00
|
|
|
throw new TypeError('options.requestValue must be a buffer or a string');
|
2011-08-04 20:32:01 +00:00
|
|
|
} else {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
options.protocolOp = Protocol.LDAP_REQ_EXTENSION;
|
|
|
|
LDAPMessage.call(this, options);
|
|
|
|
|
|
|
|
this.requestName = options.requestName || '';
|
2014-01-17 17:52:26 +00:00
|
|
|
this.requestValue = options.requestValue;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineGetter__('type', function () { return 'ExtendedRequest'; });
|
|
|
|
this.__defineGetter__('_dn', function () { return this.requestName; });
|
|
|
|
this.__defineGetter__('name', function () {
|
2011-08-04 20:32:01 +00:00
|
|
|
return this.requestName;
|
|
|
|
});
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineGetter__('value', function () {
|
2011-08-04 20:32:01 +00:00
|
|
|
return this.requestValue;
|
|
|
|
});
|
2012-02-18 08:15:52 +00:00
|
|
|
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.requestName = name;
|
|
|
|
});
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineSetter__('value', function (val) {
|
2014-01-03 12:47:42 +00:00
|
|
|
if (!(Buffer.isBuffer(val) || typeof (val) === 'string'))
|
|
|
|
throw new TypeError('value must be a buffer or a string');
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
this.requestValue = val;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
util.inherits(ExtendedRequest, LDAPMessage);
|
|
|
|
module.exports = ExtendedRequest;
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ExtendedRequest.prototype._parse = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
this.requestName = ber.readString(0x80);
|
|
|
|
if (ber.peek() === 0x81)
|
2014-01-03 12:47:42 +00:00
|
|
|
try {
|
|
|
|
this.requestValue = ber.readString(0x81);
|
|
|
|
} catch (e) {
|
|
|
|
this.requestValue = ber.readBuffer(0x81);
|
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ExtendedRequest.prototype._toBer = function (ber) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
|
|
|
ber.writeString(this.requestName, 0x80);
|
2015-04-26 03:36:36 +00:00
|
|
|
if (Buffer.isBuffer(this.requestValue)) {
|
2014-01-03 12:47:42 +00:00
|
|
|
ber.writeBuffer(this.requestValue, 0x81);
|
2015-04-26 03:36:36 +00:00
|
|
|
} else if (typeof (this.requestValue) === 'string') {
|
2011-08-04 20:32:01 +00:00
|
|
|
ber.writeString(this.requestValue, 0x81);
|
2014-01-17 17:52:26 +00:00
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
return ber;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
ExtendedRequest.prototype._json = function (j) {
|
2011-08-04 20:32:01 +00:00
|
|
|
assert.ok(j);
|
|
|
|
|
|
|
|
j.requestName = this.requestName;
|
2014-01-17 17:52:26 +00:00
|
|
|
j.requestValue = (Buffer.isBuffer(this.requestValue)) ?
|
|
|
|
this.requestValue.toString('hex') : this.requestValue;
|
2011-08-04 20:32:01 +00:00
|
|
|
|
|
|
|
return j;
|
|
|
|
};
|