2011-08-04 20:32:01 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2015-10-31 17:28:25 +00:00
|
|
|
var assert = require('assert-plus');
|
2011-08-04 20:32:01 +00:00
|
|
|
var util = require('util');
|
|
|
|
|
|
|
|
var LDAPMessage = require('./message');
|
|
|
|
var Protocol = require('../protocol');
|
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
|
|
|
|
|
|
|
function ExtendedRequest(options) {
|
2015-10-31 17:28:25 +00:00
|
|
|
options = options || {};
|
|
|
|
assert.object(options);
|
|
|
|
assert.optionalString(options.requestName);
|
|
|
|
if (options.requestValue &&
|
|
|
|
!(Buffer.isBuffer(options.requestValue) ||
|
|
|
|
typeof (options.requestValue) === 'string')) {
|
|
|
|
throw new TypeError('options.requestValue must be a buffer or a string');
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-08-27 12:04:45 +00:00
|
|
|
|
|
|
|
if(Buffer.isBuffer(this.requestValue)) {
|
|
|
|
this.requestValueBuffer = this.requestValue;
|
|
|
|
} else {
|
2019-08-27 18:17:33 +00:00
|
|
|
this.requestValueBuffer = Buffer.from(this.requestValue || '', 'utf8');
|
2019-08-27 12:04:45 +00:00
|
|
|
}
|
2011-08-04 20:32:01 +00:00
|
|
|
}
|
|
|
|
util.inherits(ExtendedRequest, LDAPMessage);
|
2015-10-31 17:28:25 +00:00
|
|
|
Object.defineProperties(ExtendedRequest.prototype, {
|
|
|
|
type: {
|
|
|
|
get: function getType() { return 'ExtendedRequest'; },
|
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
_dn: {
|
|
|
|
get: function getDN() { return this.requestName; },
|
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
get: function getName() { return this.requestName; },
|
|
|
|
set: function setName(val) {
|
|
|
|
assert.string(val);
|
|
|
|
this.requestName = val;
|
|
|
|
},
|
|
|
|
configurable: false
|
|
|
|
},
|
|
|
|
value: {
|
|
|
|
get: function getValue() { return this.requestValue; },
|
|
|
|
set: function setValue(val) {
|
|
|
|
if (!(Buffer.isBuffer(val) || typeof (val) === 'string'))
|
|
|
|
throw new TypeError('value must be a buffer or a string');
|
|
|
|
|
2019-08-27 12:04:45 +00:00
|
|
|
if(Buffer.isBuffer(val)) {
|
|
|
|
this.requestValueBuffer = val;
|
|
|
|
} else {
|
2019-08-27 18:17:33 +00:00
|
|
|
this.requestValueBuffer = Buffer.from(val, 'utf8');
|
2019-08-27 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-31 17:28:25 +00:00
|
|
|
this.requestValue = val;
|
|
|
|
},
|
|
|
|
configurable: false
|
2019-08-27 12:04:45 +00:00
|
|
|
},
|
|
|
|
valueBuffer: {
|
|
|
|
get: function getValueBuffer() {
|
|
|
|
return this.requestValueBuffer;
|
|
|
|
},
|
|
|
|
set: function setValueBuffer(val) {
|
|
|
|
if(!Buffer.isBuffer(val))
|
|
|
|
throw new TypeError('valueBuffer must be a buffer');
|
|
|
|
|
|
|
|
this.value = val;
|
|
|
|
},
|
|
|
|
configurable: false
|
2015-10-31 17:28:25 +00:00
|
|
|
}
|
|
|
|
});
|
2011-08-04 20:32:01 +00:00
|
|
|
|
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);
|
2019-08-27 12:04:45 +00:00
|
|
|
if (ber.peek() === 0x81) {
|
|
|
|
this.requestValueBuffer = ber.readString(0x81, true);
|
|
|
|
this.requestValue = this.requestValueBuffer.toString('utf8');
|
|
|
|
}
|
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;
|
|
|
|
};
|
2015-10-31 17:28:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
///--- Exports
|
|
|
|
|
|
|
|
module.exports = ExtendedRequest;
|