add support for RFC 2696 paged results controls

This commit is contained in:
Nathan Rogers 2012-03-26 13:53:30 -05:00
parent 344cac0287
commit fd085c409d
2 changed files with 94 additions and 0 deletions

View File

@ -6,6 +6,7 @@ var Control = require('./control');
var EntryChangeNotificationControl =
require('./entry_change_notification_control');
var PersistentSearchControl = require('./persistent_search_control');
var PagedResultsControl = require('./paged_results_control');
@ -50,6 +51,12 @@ module.exports = {
value: value
});
break;
case PagedResultsControl.OID:
control = new PagedResultsControl({
critical: critical,
value: value
});
break;
default:
control = new Control({
type: type,
@ -64,5 +71,6 @@ module.exports = {
Control: Control,
EntryChangeNotificationControl: EntryChangeNotificationControl,
PagedResultsControl: PagedResultsControl,
PersistentSearchControl: PersistentSearchControl
};

View File

@ -0,0 +1,86 @@
var assert = require('assert');
var util = require('util');
var asn1 = require('asn1');
var Control = require('./control');
///--- Globals
var BerReader = asn1.BerReader;
var BerWriter = asn1.BerWriter;
///--- API
function PagedResultsControl(options) {
if (!options)
options = {};
options.type = PagedResultsControl.OID;
if (options.value) {
if (Buffer.isBuffer(options.value)) {
this.parse(options.value);
} else if (typeof (options.value) === 'object') {
this._value = options.value;
} else {
throw new TypeError('options.value must be a Buffer or Object');
}
options.value = null;
}
Control.call(this, options);
var self = this;
this.__defineGetter__('value', function () {
return self._value || {};
});
}
util.inherits(PagedResultsControl, Control);
module.exports = PagedResultsControl;
PagedResultsControl.prototype.parse = function parse(buffer) {
assert.ok(buffer);
var ber = new BerReader(buffer);
if (ber.readSequence()) {
this._value = {};
this._value.size = ber.readInt();
this._value.cookie = ber.readString(asn1.Ber.OctetString, true);
return true;
}
return false;
};
PagedResultsControl.prototype._toBer = function (ber) {
assert.ok(ber);
if (!this._value)
return;
var writer = new BerWriter();
writer.startSequence();
writer.writeInt(this.value.size);
if(this.value.cookie)
writer.writeBuffer(this.value.cookie, asn1.Ber.OctetString);
else
writer.writeString('');
writer.endSequence();
ber.writeBuffer(writer.buffer, 0x04);
};
PagedResultsControl.prototype._json = function (obj) {
obj.controlValue = this.value;
return obj;
};
PagedResultsControl.OID = '1.2.840.113556.1.4.319';