2011-12-08 22:54:40 +00:00
|
|
|
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
|
|
|
|
|
2011-12-08 01:02:17 +00:00
|
|
|
var assert = require('assert');
|
2011-12-08 22:54:40 +00:00
|
|
|
var util = require('util');
|
|
|
|
|
2011-12-08 01:02:17 +00:00
|
|
|
var asn1 = require('asn1');
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2011-12-08 01:02:17 +00:00
|
|
|
var Control = require('./control');
|
2011-12-08 22:54:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///--- Globals
|
|
|
|
|
|
|
|
var BerReader = asn1.BerReader;
|
|
|
|
var BerWriter = asn1.BerWriter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///--- API
|
2011-12-08 01:02:17 +00:00
|
|
|
|
|
|
|
function PersistentSearchControl(options) {
|
2011-12-08 22:54:40 +00:00
|
|
|
if (!options)
|
2011-12-08 01:02:17 +00:00
|
|
|
options = {};
|
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
options.type = PersistentSearchControl.OID;
|
2011-12-08 19:22:35 +00:00
|
|
|
if (options.value) {
|
2011-12-08 22:54:40 +00:00
|
|
|
if (Buffer.isBuffer(options.value)) {
|
|
|
|
this.parse(options.value);
|
2012-02-18 08:15:52 +00:00
|
|
|
} else if (typeof (options.value) === 'object') {
|
2011-12-08 22:54:40 +00:00
|
|
|
this._value = options.value;
|
|
|
|
} else {
|
|
|
|
throw new TypeError('options.value must be a Buffer or Object');
|
2011-12-08 19:22:35 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
options.value = null;
|
2011-12-08 01:02:17 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
Control.call(this, options);
|
2011-12-08 01:02:17 +00:00
|
|
|
|
|
|
|
var self = this;
|
2012-02-18 08:15:52 +00:00
|
|
|
this.__defineGetter__('value', function () {
|
2011-12-08 22:54:40 +00:00
|
|
|
return self._value || {};
|
|
|
|
});
|
2011-12-08 01:02:17 +00:00
|
|
|
}
|
2011-12-08 22:54:40 +00:00
|
|
|
util.inherits(PersistentSearchControl, Control);
|
2011-12-08 01:02:17 +00:00
|
|
|
module.exports = PersistentSearchControl;
|
|
|
|
|
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
PersistentSearchControl.prototype.parse = function parse(buffer) {
|
|
|
|
assert.ok(buffer);
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
var ber = new BerReader(buffer);
|
|
|
|
if (ber.readSequence()) {
|
|
|
|
this._value = {
|
|
|
|
changeTypes: ber.readInt(),
|
|
|
|
changesOnly: ber.readBoolean(),
|
|
|
|
returnECs: ber.readBoolean()
|
2011-12-08 19:22:35 +00:00
|
|
|
};
|
2011-12-08 22:54:40 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-12-08 01:02:17 +00:00
|
|
|
};
|
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
PersistentSearchControl.prototype._toBer = function (ber) {
|
2011-12-08 01:02:17 +00:00
|
|
|
assert.ok(ber);
|
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
if (!this._value)
|
|
|
|
return;
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
var writer = new BerWriter();
|
|
|
|
writer.startSequence();
|
|
|
|
writer.writeInt(this.value.changeTypes);
|
|
|
|
writer.writeBoolean(this.value.changesOnly);
|
|
|
|
writer.writeBoolean(this.value.returnECs);
|
|
|
|
writer.endSequence();
|
2011-12-08 01:02:17 +00:00
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
ber.writeBuffer(writer.buffer, 0x04);
|
|
|
|
};
|
2011-12-08 01:02:17 +00:00
|
|
|
|
|
|
|
|
2012-02-18 08:15:52 +00:00
|
|
|
PersistentSearchControl.prototype._json = function (obj) {
|
2011-12-09 21:59:17 +00:00
|
|
|
obj.controlValue = this.value;
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-08 22:54:40 +00:00
|
|
|
PersistentSearchControl.OID = '2.16.840.1.113730.3.4.3';
|